@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,163 @@
|
|
|
1
|
+
// The one list of the sandbox's own modules: the files the Worker (and mallory's frames) get as TEXT.
|
|
2
|
+
// Pure data, imports nothing. Two readers build the same `sources` tree from it (buildSources below):
|
|
3
|
+
// - the page, from src/runtime/sandbox-imports.js, which is GENERATED from this list
|
|
4
|
+
// (`node scripts/gen-sandbox-sources.mjs`; test/sandbox-modules.test.mjs fails when it is stale),
|
|
5
|
+
// as Vite `?raw` imports (static, or `import()` for `lazy` ones, which keep a chunk of their own);
|
|
6
|
+
// - Node, from disk (src/headless/node.js).
|
|
7
|
+
// To add a sandbox module: add its entry here, then run the generator. Nothing else lists these files.
|
|
8
|
+
//
|
|
9
|
+
// An entry: `{ name, group?, path | pkg, lazy?, partOf? }`.
|
|
10
|
+
// name, group where it sits in `sources`: `sources[name]`, or `sources[group][name]`.
|
|
11
|
+
// path a file under src/ ("media/wav.js"); `pkg`: a package export ("@johnhenry/inspectable/serialize").
|
|
12
|
+
// lazy fetched only on demand: a function giving the text (a chunk of its own on the page).
|
|
13
|
+
// partOf not exposed itself; its text is one of another entry's inputs (the iteration `push` module).
|
|
14
|
+
// parts (instead of path) several files joined, in order, into one text.
|
|
15
|
+
// push the entry is the transducers' module, joined from the `partOf: "push"` entries (iteration-push.js).
|
|
16
|
+
// Order is kept: `table`'s plugins install in it, and `media`'s are defined in it.
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The sandbox Worker's script, as ordered parts (src/runtime/worker/): joined, in this order and with nothing between, into the
|
|
20
|
+
* one text the Worker evaluates. They share ONE scope (andbox wraps the text in a single async function), so a part may use what an
|
|
21
|
+
* earlier part declared at its top level, and a `const`/`class`/`let` is usable only from code that runs after its line:
|
|
22
|
+
* declare a thing in the same part as, or an earlier part than, the top-level code that uses it. A part imports nothing.
|
|
23
|
+
* The order is fixed by test/sandbox-modules.test.mjs: change it there too.
|
|
24
|
+
*/
|
|
25
|
+
export const WORKER_PARTS = [
|
|
26
|
+
"runtime/worker/00-prelude.js",
|
|
27
|
+
"runtime/worker/10-helpers.js",
|
|
28
|
+
"runtime/worker/20-io.js",
|
|
29
|
+
"runtime/worker/30-previews.js",
|
|
30
|
+
"runtime/worker/40-profile-lineage.js",
|
|
31
|
+
"runtime/worker/50-own-worker.js",
|
|
32
|
+
"runtime/worker/60-timers.js",
|
|
33
|
+
"runtime/worker/70-state-keyed.js",
|
|
34
|
+
"runtime/worker/80-each-compile-generators.js",
|
|
35
|
+
"runtime/worker/90-events-operators.js",
|
|
36
|
+
"runtime/worker/95-agents-batches.js",
|
|
37
|
+
"runtime/worker/96-plot.js",
|
|
38
|
+
"runtime/worker/97-calc.js",
|
|
39
|
+
"runtime/worker/98-geometry.js",
|
|
40
|
+
"runtime/worker/99-graph.js",
|
|
41
|
+
"runtime/worker/99-shell.js",
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
export const SANDBOX_MODULES = [
|
|
45
|
+
{ name: "runtime", parts: WORKER_PARTS },
|
|
46
|
+
{ name: "keys", path: "runtime/keys.js" },
|
|
47
|
+
{ name: "tween", path: "runtime/tween.js" },
|
|
48
|
+
{ name: "time", path: "model/nl-time.js" },
|
|
49
|
+
{ name: "calendar", path: "calendar/vendor.js", lazy: true }, // src/model/calendar.js with @johnhenry/temporals (scripts/build-calendar-vendor.mjs)
|
|
50
|
+
{ name: "jth", path: "jth/vendor.js", lazy: true }, // @johnhenry/jth-eval and its packages (scripts/build-jth-vendor.mjs)
|
|
51
|
+
{ name: "aimatey", path: "aimatey/vendor.js", lazy: true }, // Aimatey's router, middleware and patterns (scripts/build-aimatey-vendor.mjs)
|
|
52
|
+
{ name: "exact", path: "exact/vendor.js", lazy: true }, // src/exact/source.js with @johnhenry/math (scripts/build-exact-vendor.mjs)
|
|
53
|
+
{ name: "smf", path: "smf-helper/vendor.js", lazy: true }, // src/smf-helper/source.js: the app's MIDI codec and score mapping (scripts/build-smf-vendor.mjs)
|
|
54
|
+
{ name: "plot", path: "plot/vendor.js", lazy: true }, // src/plot/source.js with @johnhenry/math-sample and @johnhenry/math (scripts/build-plot-vendor.mjs)
|
|
55
|
+
{ name: "mathplus", pkg: "@johnhenry/math-plus-web/bundle", lazy: true }, // the math-plus family in one self-contained bundle (fft, signal, image, tensor... sharing one Tensor class): `mathplus` in pane code
|
|
56
|
+
{ name: "geometry", path: "geometry/model.js" }, // the geometry construction maths (src/geometry/model.js), shared with the page
|
|
57
|
+
{ name: "graph", path: "graph/model.js" }, // the graph pane's maths (src/graph/model.js), shared with the page
|
|
58
|
+
{ name: "clsh", path: "clsh/clsh.js" }, // the shell language (src/clsh/clsh.js), shared with the page; the Worker runs a shell pane's lines in it (src/runtime/worker/99-shell.js)
|
|
59
|
+
{ name: "units", path: "units/units.js" },
|
|
60
|
+
{ name: "spring", path: "runtime/spring.js" },
|
|
61
|
+
{ name: "fixed", path: "sim/fixed.js" },
|
|
62
|
+
{ name: "midi", path: "runtime/midi-input.js" },
|
|
63
|
+
{ name: "narrative", path: "narrative/narrative.js" },
|
|
64
|
+
{ name: "tilemap", path: "tilemap/tilemap.js" },
|
|
65
|
+
{ name: "files", path: "files/files.js" },
|
|
66
|
+
{ name: "inspectable", pkg: "@johnhenry/inspectable/serialize" },
|
|
67
|
+
{ name: "exporter", path: "export/value.js" },
|
|
68
|
+
{ name: "decodeFrame", path: "media/decode-frame.js", lazy: true }, // runs in the decoding frame (src/ui/decode-frame.js), never in the Worker: fetched only when a sound needs decoding
|
|
69
|
+
{ group: "media", name: "contract", path: "media/contract.js" },
|
|
70
|
+
{ group: "media", name: "wav", path: "media/wav.js" },
|
|
71
|
+
{ group: "media", name: "wav-encoder", path: "audio/wav.js" }, // one WAV encoder, shared with audio panes
|
|
72
|
+
{ group: "media", name: "zzfx", path: "audio/zzfx.js" }, // the ZzFX generator, shared with audio panes
|
|
73
|
+
{ group: "media", name: "png", path: "media/png.js" },
|
|
74
|
+
{ group: "media", name: "mime", path: "media/mime.js" },
|
|
75
|
+
{ group: "media", name: "metadata", path: "media/metadata.js" },
|
|
76
|
+
{ group: "media", name: "animated", path: "media/animated.js" },
|
|
77
|
+
{ group: "media", name: "ffmpeg", path: "media/ffmpeg.js" },
|
|
78
|
+
{ group: "media", name: "helpers", path: "media/helpers.js" },
|
|
79
|
+
{ group: "table", name: "core", path: "table/table.js" },
|
|
80
|
+
{ group: "table", name: "safe-regex", path: "model/safe-regex.js" }, // before `sql`, `json-schema` and `quality`, which run people's patterns on it (issue #953)
|
|
81
|
+
{ group: "table", name: "sql", path: "table/table-sql.js" },
|
|
82
|
+
{ group: "table", name: "stats", path: "table/table-stats.js" },
|
|
83
|
+
{ group: "table", name: "json-schema", path: "model/json-schema.js" }, // before `quality`, which uses it
|
|
84
|
+
{ group: "table", name: "quality", path: "table/table-quality.js" },
|
|
85
|
+
{ group: "table", name: "schema", path: "table/table-schema.js" },
|
|
86
|
+
{ group: "table", name: "lineage", path: "table/table-lineage.js" },
|
|
87
|
+
{ group: "table", name: "geo", path: "table/table-geo.js" },
|
|
88
|
+
{ name: "docs", path: "documents/documents.js" },
|
|
89
|
+
{ name: "assets", path: "packages/asset-values.js" },
|
|
90
|
+
{ group: "bytes", name: "core", path: "bytes/bytes.js" },
|
|
91
|
+
{ group: "bytes", name: "framers", path: "serial/framers.js" },
|
|
92
|
+
{ name: "tensor", path: "tensor/tensor.js" },
|
|
93
|
+
{ name: "wasm", path: "runtime/wasm-fuel.js" },
|
|
94
|
+
{ name: "frame", path: "frame/frame.js" }, // its library is the lazy codec lib "dataframe"
|
|
95
|
+
{ group: "codec", name: "core", path: "codec/core.js" },
|
|
96
|
+
{ group: "iteration", name: "async-channel", pkg: "@johnhenry/iteration/async-channel" },
|
|
97
|
+
{ group: "iteration", name: "channel-decorators", pkg: "@johnhenry/iteration/channel-decorators" },
|
|
98
|
+
{ group: "iteration", name: "abort", pkg: "@johnhenry/iteration/abort" },
|
|
99
|
+
{ group: "iteration", name: "iterator-tools", pkg: "@johnhenry/iteration/iterator-tools", partOf: "push" },
|
|
100
|
+
{ group: "iteration", name: "transduce", pkg: "@johnhenry/iteration/transduce", partOf: "push" },
|
|
101
|
+
{ group: "iteration", name: "transducers", pkg: "@johnhenry/iteration/transducers", partOf: "push" },
|
|
102
|
+
{ group: "iteration", name: "push", push: true }, // the transducers for wire operators, joined into one module
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The codec pane's libraries, each fetched only when a canvas needs it (`sources.codec.libs(name)`): a file, or `as`
|
|
107
|
+
* (the text of another entry, `group.name`: the struct format is the `bytes` helper's struct, defined again under the libraries' names).
|
|
108
|
+
* `dataframe` is not a codec: the `dataframe` helper's library, loaded the same lazy way when pane code names it.
|
|
109
|
+
*/
|
|
110
|
+
export const CODEC_LIBS = {
|
|
111
|
+
msgpack: { path: "codec/vendor/msgpack.js" },
|
|
112
|
+
cbor: { path: "codec/vendor/cbor.js" },
|
|
113
|
+
protobuf: { path: "codec/vendor/protobuf.js" },
|
|
114
|
+
avro: { path: "codec/vendor/avro.js" },
|
|
115
|
+
struct: { as: "bytes.core" },
|
|
116
|
+
flatbuffers: { path: "codec/vendor/flatbuffers.js" },
|
|
117
|
+
capnp: { path: "codec/capnp.js" }, // not vendored: mallory's own Cap'n Proto reader and writer
|
|
118
|
+
dataframe: { path: "frame/vendor.js" },
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** The id of an entry's text in a reader's table (`group.name`, or `name`). */
|
|
122
|
+
export const moduleId = (entry) => (entry.group ? `${entry.group}.${entry.name}` : entry.name);
|
|
123
|
+
|
|
124
|
+
/** The id of a codec library's text. */
|
|
125
|
+
export const codecLibId = (name) => `codec.libs.${name}`;
|
|
126
|
+
|
|
127
|
+
/** The id of one of an entry's `parts`. */
|
|
128
|
+
export const partId = (entry, i) => `${moduleId(entry)}#${i}`;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The `sources` tree (what createRuntime takes) from the manifest. `text(id, entry)` gives the text of a module, or for a lazy
|
|
132
|
+
* one (`entry.lazy`) a function that gives it (a promise or the text); `join(pushTexts)` is pushModule (src/runtime/iteration-push.js).
|
|
133
|
+
*/
|
|
134
|
+
export function buildSources(text, pushModule, pushFiles) {
|
|
135
|
+
const out = {};
|
|
136
|
+
const part = {};
|
|
137
|
+
for (const entry of SANDBOX_MODULES) {
|
|
138
|
+
const id = moduleId(entry);
|
|
139
|
+
if (entry.partOf) {
|
|
140
|
+
part[entry.name] = text(id, entry);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
let value;
|
|
144
|
+
if (entry.push) {
|
|
145
|
+
value = pushModule(Object.fromEntries(pushFiles.map((n) => [n, part[n] ?? out.iteration[n]])));
|
|
146
|
+
} else if (entry.parts) {
|
|
147
|
+
value = entry.parts.map((_, i) => text(partId(entry, i), { path: entry.parts[i] })).join("");
|
|
148
|
+
} else value = text(id, entry);
|
|
149
|
+
if (entry.group) (out[entry.group] ??= {})[entry.name] = value;
|
|
150
|
+
else out[entry.name] = value;
|
|
151
|
+
}
|
|
152
|
+
const libs = async (name) => {
|
|
153
|
+
const lib = CODEC_LIBS[name];
|
|
154
|
+
if (!lib) throw new TypeError(`no codec library "${name}"`);
|
|
155
|
+
if (lib.as) {
|
|
156
|
+
const [group, key] = lib.as.split(".");
|
|
157
|
+
return out[group][key];
|
|
158
|
+
}
|
|
159
|
+
return text(codecLibId(name), { ...lib, lazy: true })();
|
|
160
|
+
};
|
|
161
|
+
(out.codec ??= {}).libs = libs;
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
// Springs: a damped spring that chases a target, keeps its own
|
|
2
|
+
// position and velocity, and can be retargeted or released with a velocity
|
|
3
|
+
// mid-flight. The arithmetic of a gesture that lets go (a fling, a settle) for
|
|
4
|
+
// widget values (src/model/spring-player.js) and the preset morph position
|
|
5
|
+
// (src/model/preset-player.js). Pane code gets it as `spring` (the Worker
|
|
6
|
+
// loads this file as the module "mallory:spring", src/runtime/sources.js);
|
|
7
|
+
// the page imports it too (tests, the players).
|
|
8
|
+
//
|
|
9
|
+
// THE MODEL is the physical one (Origami's Spring Animation patch names its
|
|
10
|
+
// coefficients tension and friction; they are `stiffness` and `damping`):
|
|
11
|
+
//
|
|
12
|
+
// mass * x'' = -stiffness * (x - target) - damping * x'
|
|
13
|
+
//
|
|
14
|
+
// with `stiffness` (force per unit of distance), `damping` (force per unit of
|
|
15
|
+
// speed) and `mass`. The defaults (170, 18, 1) are a lively spring with a
|
|
16
|
+
// small overshoot (damping ratio 0.69, about 5%; there is none from
|
|
17
|
+
// `2 * sqrt(stiffness * mass)`, 26.1 here): make `damping` smaller for more
|
|
18
|
+
// bounce, larger for none. Units are the value's own: a position in widget
|
|
19
|
+
// units, a velocity in units per second.
|
|
20
|
+
//
|
|
21
|
+
// DETERMINISM. The spring is integrated with a FIXED time step
|
|
22
|
+
// (STEP_MS = 1000 / 240 ms, semi-implicit Euler) however it is driven: a
|
|
23
|
+
// frame of any length, a step of the transport, a headless loop. `advance(ms)`
|
|
24
|
+
// adds the time to a carry and takes as many whole steps as fit, so the same
|
|
25
|
+
// total time gives the same state however it was cut into frames (the tests
|
|
26
|
+
// compare). Nothing here reads a clock, a timer or `Math.random`.
|
|
27
|
+
//
|
|
28
|
+
// REST. The spring is settled when it is within `restDelta` of the target and
|
|
29
|
+
// slower than `restSpeed`; it then snaps to the target exactly with velocity 0
|
|
30
|
+
// and stops moving. A damping of 0 would never settle, so it is refused.
|
|
31
|
+
//
|
|
32
|
+
// LIMITS give clear errors rather than hang: coefficients must be finite and
|
|
33
|
+
// positive and stable at the fixed step (springProblem), `advance` refuses
|
|
34
|
+
// more than MAX_ADVANCE_MS at once, and `settle` refuses to run past
|
|
35
|
+
// MAX_SETTLE_MS (a spring too weak to settle by then says so).
|
|
36
|
+
//
|
|
37
|
+
// A spring is one number or several (an XY pad is two): the position, target
|
|
38
|
+
// and velocity are numbers or arrays of numbers. `bounds` (per component
|
|
39
|
+
// { min, max }) makes the ends walls: a position that reaches one stops there
|
|
40
|
+
// and its velocity into the wall is lost, so a value never leaves its range.
|
|
41
|
+
//
|
|
42
|
+
// Self-contained and pure (no imports): it runs in the Worker, on the page and
|
|
43
|
+
// under node --test.
|
|
44
|
+
|
|
45
|
+
/** The fixed integration step (ms): 240 steps a second. */
|
|
46
|
+
export const STEP_MS = 1000 / 240;
|
|
47
|
+
const DT = STEP_MS / 1000;
|
|
48
|
+
|
|
49
|
+
/** The most `advance` takes at once (ms). A longer wait is a mistake (or a tab that slept), not a frame. */
|
|
50
|
+
export const MAX_ADVANCE_MS = 10000;
|
|
51
|
+
/** The longest `settle` integrates before it says the spring doesn't settle (ms). */
|
|
52
|
+
export const MAX_SETTLE_MS = 60000;
|
|
53
|
+
|
|
54
|
+
export const SPRING_DEFAULTS = Object.freeze({ stiffness: 170, damping: 18, mass: 1 });
|
|
55
|
+
const LIMITS = Object.freeze({ stiffness: [0, 1e5], damping: [0, 1e4], mass: [0, 1e3] });
|
|
56
|
+
/** Stability at the fixed step: sqrt(stiffness / mass) * dt and damping / mass * dt stay at or under 1. */
|
|
57
|
+
const MAX_OMEGA = 1 / DT; // 240 rad/s: stiffness / mass at most 57,600
|
|
58
|
+
const MAX_RATE = 1 / DT; // damping / mass at most 240
|
|
59
|
+
|
|
60
|
+
const isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
61
|
+
|
|
62
|
+
/** Why these coefficients aren't a spring (a sentence), or "". Missing ones take the defaults. */
|
|
63
|
+
export function springProblem(options = {}) {
|
|
64
|
+
if (options === null || typeof options !== "object" || Array.isArray(options)) return "a spring is { stiffness, damping, mass }";
|
|
65
|
+
const extra = Object.keys(options).find((k) => !["stiffness", "damping", "mass", "restDelta", "restSpeed"].includes(k));
|
|
66
|
+
if (extra) return `${extra} isn't a spring setting (stiffness, damping, mass)`;
|
|
67
|
+
for (const key of ["stiffness", "damping", "mass"]) {
|
|
68
|
+
const v = options[key];
|
|
69
|
+
if (v === undefined) continue;
|
|
70
|
+
const [lo, hi] = LIMITS[key];
|
|
71
|
+
if (!isNum(v) || !(v > lo) || v > hi) return `${key} is a number above ${lo} and at most ${hi}`;
|
|
72
|
+
}
|
|
73
|
+
for (const key of ["restDelta", "restSpeed"]) if (options[key] !== undefined && !(isNum(options[key]) && options[key] > 0)) return `${key} is a number above 0`;
|
|
74
|
+
const { stiffness, damping, mass } = { ...SPRING_DEFAULTS, ...options };
|
|
75
|
+
if (stiffness / mass > MAX_OMEGA * MAX_OMEGA) return `stiffness ${stiffness} is too stiff for mass ${mass}: stiffness / mass is at most ${MAX_OMEGA * MAX_OMEGA} (the fixed time step can't follow a faster spring)`;
|
|
76
|
+
if (damping / mass > MAX_RATE) return `damping ${damping} is too strong for mass ${mass}: damping / mass is at most ${MAX_RATE}`;
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The spring as a record with every coefficient filled in; throws the sentence springProblem gives. */
|
|
81
|
+
export function springOf(options = {}) {
|
|
82
|
+
const spec = options === true || options === undefined || options === null ? {} : options;
|
|
83
|
+
const problem = springProblem(spec);
|
|
84
|
+
if (problem) throw new Error(`Spring: ${problem}.`);
|
|
85
|
+
return { ...SPRING_DEFAULTS, ...spec };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const list = (v) => (Array.isArray(v) ? v : [v]);
|
|
89
|
+
|
|
90
|
+
export class Spring {
|
|
91
|
+
/**
|
|
92
|
+
* @param {object} options { stiffness, damping, mass, restDelta, restSpeed, bounds }
|
|
93
|
+
* @param {{ position: number|number[], target?: number|number[], velocity?: number|number[] }} state
|
|
94
|
+
*/
|
|
95
|
+
constructor(options = {}, { position, target = position, velocity } = {}) {
|
|
96
|
+
const { bounds, ...coefficients } = options ?? {};
|
|
97
|
+
this.options = { restDelta: 0.001, restSpeed: 0.01, ...springOf(coefficients) };
|
|
98
|
+
this.scalar = !Array.isArray(position);
|
|
99
|
+
const x = list(position);
|
|
100
|
+
if (!x.length || !x.every(isNum)) throw new Error("Spring: position is a number, or an array of numbers.");
|
|
101
|
+
this.x = [...x];
|
|
102
|
+
this.v = this.#vector(velocity, "velocity", 0);
|
|
103
|
+
this.t = this.#vector(target, "target");
|
|
104
|
+
this.bounds = bounds ? this.#bounds(bounds) : null;
|
|
105
|
+
this.carry = 0;
|
|
106
|
+
this.elapsed = 0; // ms integrated
|
|
107
|
+
this.steps = 0;
|
|
108
|
+
this.settled = false;
|
|
109
|
+
this.#clamp();
|
|
110
|
+
this.#rest();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#vector(v, what, fill) {
|
|
114
|
+
if ((v === undefined && fill !== undefined) || v === 0) return this.x.map(() => 0);
|
|
115
|
+
const a = list(v);
|
|
116
|
+
if (a.length !== this.x.length || !a.every(isNum)) throw new Error(`Spring: ${what} is ${this.scalar ? "a number" : `${this.x.length} numbers`}.`);
|
|
117
|
+
return [...a];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#bounds(bounds) {
|
|
121
|
+
const per = Array.isArray(bounds) ? bounds : this.x.map(() => bounds);
|
|
122
|
+
if (per.length !== this.x.length || !per.every((b) => b && isNum(b.min) && isNum(b.max) && b.max > b.min)) throw new Error("Spring: bounds is { min, max } (max above min), one per component.");
|
|
123
|
+
return per.map((b) => ({ min: b.min, max: b.max }));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#out(a) {
|
|
127
|
+
return this.scalar ? a[0] : [...a];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get position() {
|
|
131
|
+
return this.#out(this.x);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
get velocity() {
|
|
135
|
+
return this.#out(this.v);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get target() {
|
|
139
|
+
return this.#out(this.t);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#clamp() {
|
|
143
|
+
if (!this.bounds) return;
|
|
144
|
+
this.bounds.forEach((b, i) => {
|
|
145
|
+
if (this.x[i] <= b.min) ((this.x[i] = b.min), (this.v[i] = Math.max(0, this.v[i])));
|
|
146
|
+
else if (this.x[i] >= b.max) ((this.x[i] = b.max), (this.v[i] = Math.min(0, this.v[i])));
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#rest() {
|
|
151
|
+
const { restDelta, restSpeed } = this.options;
|
|
152
|
+
this.settled = this.x.every((x, i) => Math.abs(x - this.t[i]) <= restDelta && Math.abs(this.v[i]) <= restSpeed);
|
|
153
|
+
if (this.settled) {
|
|
154
|
+
this.x = [...this.t];
|
|
155
|
+
this.v = this.x.map(() => 0);
|
|
156
|
+
this.carry = 0;
|
|
157
|
+
this.#clamp();
|
|
158
|
+
}
|
|
159
|
+
return this.settled;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Chase a new target from where the spring is: the position AND the velocity
|
|
164
|
+
* carry over, so there is no jump (an interruption is smooth). `velocity`
|
|
165
|
+
* replaces the velocity (a gesture's release); leave it out to keep the spring's.
|
|
166
|
+
* A target outside `bounds` is held at the wall.
|
|
167
|
+
*/
|
|
168
|
+
retarget(target, { velocity } = {}) {
|
|
169
|
+
const t = this.#vector(target, "target");
|
|
170
|
+
this.t = this.bounds ? t.map((v, i) => Math.min(this.bounds[i].max, Math.max(this.bounds[i].min, v))) : t;
|
|
171
|
+
if (velocity !== undefined) this.v = this.#vector(velocity, "velocity");
|
|
172
|
+
this.settled = false;
|
|
173
|
+
this.carry = 0;
|
|
174
|
+
this.#clamp();
|
|
175
|
+
this.#rest();
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Integrate `ms` of time (whole fixed steps; the rest waits in the carry).
|
|
181
|
+
* Returns { position, velocity, settled, steps }. Throws for a time that is
|
|
182
|
+
* not a number from 0 to MAX_ADVANCE_MS.
|
|
183
|
+
*/
|
|
184
|
+
advance(ms) {
|
|
185
|
+
if (!isNum(ms) || ms < 0) throw new Error(`Spring: advance(ms) takes a time of 0 or more milliseconds, not ${ms}.`);
|
|
186
|
+
if (ms > MAX_ADVANCE_MS) throw new Error(`Spring: ${Math.round(ms)} ms is more than the ${MAX_ADVANCE_MS} ms one advance may integrate (cut it into frames, or use settle()).`);
|
|
187
|
+
let taken = 0;
|
|
188
|
+
if (!this.settled) {
|
|
189
|
+
this.carry += ms;
|
|
190
|
+
const { stiffness, damping, mass } = this.options;
|
|
191
|
+
while (this.carry >= STEP_MS - 1e-9) {
|
|
192
|
+
this.carry -= STEP_MS;
|
|
193
|
+
for (let i = 0; i < this.x.length; i++) {
|
|
194
|
+
const a = (-stiffness * (this.x[i] - this.t[i]) - damping * this.v[i]) / mass;
|
|
195
|
+
this.v[i] += a * DT;
|
|
196
|
+
this.x[i] += this.v[i] * DT;
|
|
197
|
+
}
|
|
198
|
+
this.#clamp();
|
|
199
|
+
taken++;
|
|
200
|
+
this.elapsed += STEP_MS;
|
|
201
|
+
if (this.#rest()) break;
|
|
202
|
+
}
|
|
203
|
+
this.steps += taken;
|
|
204
|
+
}
|
|
205
|
+
return { position: this.position, velocity: this.velocity, settled: this.settled, steps: taken };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Run to rest, headless: the same steps a page's frames take. Returns
|
|
210
|
+
* { position, elapsed (ms), steps }. Throws when the spring is still moving
|
|
211
|
+
* after `maxMs` (default MAX_SETTLE_MS).
|
|
212
|
+
*/
|
|
213
|
+
settle(maxMs = MAX_SETTLE_MS) {
|
|
214
|
+
if (!isNum(maxMs) || maxMs <= 0) throw new Error("Spring: settle(maxMs) takes a time above 0.");
|
|
215
|
+
const start = this.elapsed;
|
|
216
|
+
const startSteps = this.steps;
|
|
217
|
+
while (!this.settled) {
|
|
218
|
+
if (this.elapsed - start >= maxMs) throw new Error(`Spring: still moving after ${Math.round(maxMs)} ms (stiffness ${this.options.stiffness}, damping ${this.options.damping}, mass ${this.options.mass}): it doesn't settle in that time.`);
|
|
219
|
+
this.advance(STEP_MS);
|
|
220
|
+
}
|
|
221
|
+
return { position: this.position, elapsed: this.elapsed - start, steps: this.steps - startSteps };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The velocity a gesture let go with: `samples` are { t (ms), v (number or
|
|
227
|
+
* array) } in time order, and `at` the time of the release. Uses the samples
|
|
228
|
+
* of the last `windowMs`; a pointer that stopped (the last sample older than
|
|
229
|
+
* `staleMs` before the release) lets go at rest. Returns a velocity per second
|
|
230
|
+
* (a number, or an array like the samples), 0 for fewer than two samples.
|
|
231
|
+
*/
|
|
232
|
+
export function releaseVelocity(samples, at, { windowMs = 100, staleMs = 80 } = {}) {
|
|
233
|
+
const last = samples.at(-1);
|
|
234
|
+
if (!last) return 0;
|
|
235
|
+
const scalar = !Array.isArray(last.v);
|
|
236
|
+
const zero = scalar ? 0 : last.v.map(() => 0);
|
|
237
|
+
if (at - last.t > staleMs) return zero;
|
|
238
|
+
const recent = samples.filter((s) => last.t - s.t <= windowMs);
|
|
239
|
+
const first = recent[0];
|
|
240
|
+
const dt = (last.t - first.t) / 1000;
|
|
241
|
+
if (!(dt > 0)) return zero;
|
|
242
|
+
const a = list(first.v);
|
|
243
|
+
const b = list(last.v);
|
|
244
|
+
const v = b.map((x, i) => (x - a[i]) / dt);
|
|
245
|
+
return scalar ? v[0] : v;
|
|
246
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Strict mode (#591): an eval pane's code run in QuickJS-ng compiled to WebAssembly (andbox's
|
|
2
|
+
// `mode: 'wasm'`) instead of the sandbox Worker's own JavaScript engine. The engine has no fetch,
|
|
3
|
+
// no timers, no import() of URLs and no process: `host.call` is its only way out, and mallory
|
|
4
|
+
// gives it no capabilities, so a strict pane can only compute. Its budget is counted, not timed:
|
|
5
|
+
// `fuel` is the engine's interrupt polls (about one per 10,000 VM operations), so the same code with
|
|
6
|
+
// the same inputs uses the same fuel, and a runaway loop stops at the same count, on every run and
|
|
7
|
+
// on every machine ("stopped: out of fuel at N").
|
|
8
|
+
//
|
|
9
|
+
// What crosses: JSON only. Its inputs are read out of the shared sandbox as JSON (an input that
|
|
10
|
+
// doesn't come back exactly from JSON, a Map or a function say, is refused, naming it), and its value
|
|
11
|
+
// comes back as JSON and is stored in the shared sandbox like any pane's (so readers, previews,
|
|
12
|
+
// exports, the cut-off, the run log and a restart's put-back work as usual).
|
|
13
|
+
//
|
|
14
|
+
// What it has (docs/guide/frames-and-code.md, "Strict mode (QuickJS-WASM)"): the language, JSON, Math (with a seeded
|
|
15
|
+
// Math.random), `fixed` (src/sim/fixed.js), `rng(seed)` and `sim({ init, step, … })`
|
|
16
|
+
// (src/sim/checkpoints.js), and console. Date.now(), new Date() and performance.now() throw: a
|
|
17
|
+
// strict run never reads the clock.
|
|
18
|
+
//
|
|
19
|
+
// Pure, no DOM: the page and Node (src/headless/node.js) both use it. The engine itself is made by
|
|
20
|
+
// the caller (createStrictRunner's `createSandbox` options): the page serves it from its own bundle
|
|
21
|
+
// (src/runtime/strict-engine.js), Node finds the installed packages.
|
|
22
|
+
import { createFixed } from "../sim/fixed.js";
|
|
23
|
+
import { createCheckpointStore, createSimulation, createRng } from "../sim/checkpoints.js";
|
|
24
|
+
|
|
25
|
+
/** The settings of a strict pane, with their defaults and ranges (`seed` is a number or a short text). */
|
|
26
|
+
export const STRICT_DEFAULTS = Object.freeze({ fuel: 10000, memoryBytes: 32 * 1024 * 1024, stackBytes: 256 * 1024, deadlineMs: 15000, seed: 1 });
|
|
27
|
+
export const STRICT_LIMITS = Object.freeze({
|
|
28
|
+
fuel: [1, 10_000_000],
|
|
29
|
+
memoryBytes: [1024 * 1024, 512 * 1024 * 1024],
|
|
30
|
+
stackBytes: [16 * 1024, 4 * 1024 * 1024],
|
|
31
|
+
deadlineMs: [100, 600_000],
|
|
32
|
+
});
|
|
33
|
+
const KEYS = [...Object.keys(STRICT_LIMITS), "seed"];
|
|
34
|
+
/** The fuel budgets a person picks from (the pane menu's Strict fuel); agents give any in range. */
|
|
35
|
+
export const STRICT_FUEL_STEPS = Object.freeze([1000, 10000, 100000, 1000000]);
|
|
36
|
+
/** The largest input (all of them, as JSON) a strict run takes. */
|
|
37
|
+
export const STRICT_MAX_INPUT = 16 * 1024 * 1024;
|
|
38
|
+
/** The error code a run that used all its fuel fails with. */
|
|
39
|
+
export const STRICT_FUEL_CODE = "fuel-exhausted";
|
|
40
|
+
|
|
41
|
+
/** Is pane `pane` strict? An eval pane with a `strict` object. */
|
|
42
|
+
export const isStrict = (pane) => pane?.type === "eval" && Boolean(pane.strict) && typeof pane.strict === "object" && !Array.isArray(pane.strict);
|
|
43
|
+
|
|
44
|
+
/** Problems with a `strict` setting as written (`prefix` names it). Absent is fine; `{}` is on with the defaults. */
|
|
45
|
+
export function strictProblems(value, prefix = "strict") {
|
|
46
|
+
if (value === undefined || value === null) return [];
|
|
47
|
+
if (typeof value !== "object" || Array.isArray(value)) return [`${prefix} must be an object { fuel, memoryBytes, stackBytes, deadlineMs, seed } (every key optional)`];
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const key of Object.keys(value)) {
|
|
50
|
+
if (!KEYS.includes(key)) {
|
|
51
|
+
out.push(`${prefix}.${key} is not a setting (${KEYS.join(", ")})`);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const v = value[key];
|
|
55
|
+
if (key === "seed") {
|
|
56
|
+
const ok = (typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= 0xffffffff) || (typeof v === "string" && v.length <= 64);
|
|
57
|
+
if (!ok) out.push(`${prefix}.seed must be a whole number from 0 to 4294967295 or a text of at most 64 characters`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const [lo, hi] = STRICT_LIMITS[key];
|
|
61
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < lo || v > hi) out.push(`${prefix}.${key} must be a whole number from ${lo} to ${hi}`);
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A pane's strict settings with the defaults filled in: `{ fuel, memoryBytes, stackBytes, deadlineMs, seed }`. */
|
|
67
|
+
export function strictConfig(pane) {
|
|
68
|
+
const given = isStrict(pane) ? pane.strict : {};
|
|
69
|
+
const out = { ...STRICT_DEFAULTS };
|
|
70
|
+
for (const key of KEYS) if (given[key] !== undefined && !strictProblems({ [key]: given[key] }).length) out[key] = given[key];
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Why pane `pane` can't run strict (a setting strict mode has no room for), or "". Strict code is a
|
|
76
|
+
* plain computation: its inputs in, one JSON value out.
|
|
77
|
+
*/
|
|
78
|
+
export function strictPaneProblem(pane) {
|
|
79
|
+
const problems = strictProblems(pane.strict);
|
|
80
|
+
if (problems.length) return `${problems.join("; ")}.`;
|
|
81
|
+
const off = "Turn strict mode off for that (its menu: Strict (QuickJS-WASM)), or move that part to a pane of its own.";
|
|
82
|
+
if (pane.mode === "jth") return `a jth program can't run in strict mode: strict code is JavaScript. ${off}`;
|
|
83
|
+
if (pane.each?.on) return `"For each item" can't run in strict mode: give the strict pane the whole array and loop in its code. ${off}`;
|
|
84
|
+
if (pane.ownWorker) return `"Run in its own Worker" and strict mode are two ways to isolate a pane: pick one. ${off}`;
|
|
85
|
+
if (pane.receive?.channel) return `a strict pane can't receive on a channel: it reads only its inputs. ${off}`;
|
|
86
|
+
if (pane.switch || pane.split) return `a ${pane.switch ? "switch" : "weighted split"} sends on named outputs, which strict code can't: it returns one value. ${off}`;
|
|
87
|
+
if (pane.live === "resume" || /\byield\b/.test(String(pane.code ?? ""))) return `a live pane (yield) can't run in strict mode: strict code returns one value. ${off}`;
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The error a strict run that used all its fuel fails with: "stopped: out of fuel at N", the same N on every run. */
|
|
92
|
+
export class StrictFuelError extends Error {
|
|
93
|
+
constructor(used, limit) {
|
|
94
|
+
super(`stopped: out of fuel at ${used} (its fuel is ${limit}). Strict code is counted, not timed: the same code with the same inputs stops here on every run. Raise strict.fuel, or end the loop.`);
|
|
95
|
+
this.name = "FuelExhaustedError";
|
|
96
|
+
this.code = STRICT_FUEL_CODE;
|
|
97
|
+
this.fuelUsed = used;
|
|
98
|
+
this.fuelLimit = limit;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ── the guest: what strict code sees, as text run inside QuickJS ──────────
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The prelude every strict run starts with (a fresh QuickJS context each time): the deterministic
|
|
106
|
+
* helpers, a seeded Math.random, and a clock that refuses to be read. Self-contained functions only
|
|
107
|
+
* (each is shipped as its own text, as the render frame ships them).
|
|
108
|
+
*/
|
|
109
|
+
export function strictPrelude(seed = STRICT_DEFAULTS.seed) {
|
|
110
|
+
return `const structuredClone = (v) => (v === undefined ? undefined : JSON.parse(JSON.stringify(v)));
|
|
111
|
+
const createFixed = (${createFixed.toString()});
|
|
112
|
+
const createRng = (${createRng.toString()});
|
|
113
|
+
const createCheckpointStore = (${createCheckpointStore.toString()});
|
|
114
|
+
const createSimulation = (${createSimulation.toString()});
|
|
115
|
+
const fixed = createFixed();
|
|
116
|
+
const rng = (seed = 1) => createRng(seed);
|
|
117
|
+
const sim = ({ init, step, dt = 1 / 60, seed = 1, inputs = {}, checkpoints = {}, maxSeekSteps } = {}) => {
|
|
118
|
+
if (typeof init !== "function" || typeof step !== "function") throw new TypeError("sim({ init, step }): init(seed) makes frame 0's state and step(state, dt, inputs) the next one");
|
|
119
|
+
const store = createCheckpointStore({ every: checkpoints.every ?? 30, max: checkpoints.max ?? 64, maxBytes: checkpoints.maxBytes ?? 8388608 });
|
|
120
|
+
return createSimulation({ init, step, dt, seed, inputs, store, ...(maxSeekSteps ? { maxSeekSteps } : {}) });
|
|
121
|
+
};
|
|
122
|
+
{
|
|
123
|
+
const seeded = createRng(${JSON.stringify(seed)});
|
|
124
|
+
Math.random = () => seeded();
|
|
125
|
+
const refuse = (what) => () => { throw new Error(what + " isn't available in strict mode: a strict run never reads the clock, so it gives the same answer every time (pass a time in as an input)"); };
|
|
126
|
+
const RealDate = Date;
|
|
127
|
+
const StrictDate = function Date(...args) {
|
|
128
|
+
if (!new.target) refuse("Date()")();
|
|
129
|
+
if (!args.length) refuse("new Date()")();
|
|
130
|
+
return new RealDate(...args);
|
|
131
|
+
};
|
|
132
|
+
StrictDate.prototype = RealDate.prototype;
|
|
133
|
+
StrictDate.UTC = RealDate.UTC;
|
|
134
|
+
StrictDate.parse = RealDate.parse;
|
|
135
|
+
StrictDate.now = refuse("Date.now()");
|
|
136
|
+
globalThis.Date = StrictDate;
|
|
137
|
+
globalThis.performance = { now: refuse("performance.now()") };
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The program a strict run evaluates: the prelude, then the pane's code (`body`: a function body,
|
|
144
|
+
* as compile.js paneBody makes it) as an async function whose parameters are its inputs, called with
|
|
145
|
+
* the inputs parsed from `inputsText` (JSON of `{ name: value }`).
|
|
146
|
+
*/
|
|
147
|
+
export function strictProgram({ body, names = [], inputsText = "{}", seed }) {
|
|
148
|
+
const params = names.join(", ");
|
|
149
|
+
const args = names.map((n) => `__inputs[${JSON.stringify(n)}]`).join(", ");
|
|
150
|
+
return `${strictPrelude(seed)}const __inputs = JSON.parse(${JSON.stringify(inputsText)});
|
|
151
|
+
return await (async (${params}) => {
|
|
152
|
+
${body}
|
|
153
|
+
})(${args});`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The strict engine for a runtime: one andbox `mode: 'wasm'` sandbox, made on first use, that runs
|
|
158
|
+
* strict panes one at a time (they share one thread anyway, and one at a time each run's fuel count
|
|
159
|
+
* is its own). `options()` gives createSandbox's options (sync or async: the page loads its engine
|
|
160
|
+
* first); `createSandbox` is andbox's. `run` resolves `{ value, fuelUsed }` or rejects with the
|
|
161
|
+
* code's error, a StrictFuelError, or andbox's MemoryLimitError / TimeoutError (deadlineMs).
|
|
162
|
+
*/
|
|
163
|
+
export function createStrictRunner({ createSandbox, options = () => ({}), onConsole } = {}) {
|
|
164
|
+
let sandbox = null;
|
|
165
|
+
let queue = Promise.resolve();
|
|
166
|
+
let disposed = false;
|
|
167
|
+
const make = () =>
|
|
168
|
+
(sandbox ??= Promise.resolve(options()).then((given) =>
|
|
169
|
+
createSandbox({
|
|
170
|
+
...given,
|
|
171
|
+
mode: "wasm",
|
|
172
|
+
onConsole(level, ...args) {
|
|
173
|
+
onConsole?.(typeof this?.consoleId === "string" ? this.consoleId : null, level, args);
|
|
174
|
+
},
|
|
175
|
+
}),
|
|
176
|
+
)).catch((error) => {
|
|
177
|
+
sandbox = null; // the next run tries again
|
|
178
|
+
throw new Error(`strict mode isn't available here: ${error?.message ?? error}`);
|
|
179
|
+
});
|
|
180
|
+
async function once({ pane, body, names, inputsText, limits }) {
|
|
181
|
+
if (disposed) throw new Error("the sandbox was closed");
|
|
182
|
+
const box = await make();
|
|
183
|
+
const code = strictProgram({ body, names, inputsText, seed: limits.seed });
|
|
184
|
+
try {
|
|
185
|
+
const value = await box.evaluate(code, { fuel: limits.fuel, memoryBytes: limits.memoryBytes, stackBytes: limits.stackBytes, deadlineMs: limits.deadlineMs, timeoutMs: limits.deadlineMs, ...(pane != null ? { consoleId: String(pane) } : {}) });
|
|
186
|
+
return { value, fuelUsed: box.stats?.().fuelUsed ?? 0 };
|
|
187
|
+
} catch (error) {
|
|
188
|
+
if (error?.code === "ERR_ANDBOX_FUEL_EXHAUSTED") {
|
|
189
|
+
const used = Number(/after (\d+)/.exec(error.message)?.[1]) || box.stats?.().fuelUsed || limits.fuel + 1;
|
|
190
|
+
throw new StrictFuelError(used, limits.fuel);
|
|
191
|
+
}
|
|
192
|
+
if (error?.code === "ERR_ANDBOX_MEMORY_LIMIT") throw Object.assign(new Error(`stopped: out of memory (strict.memoryBytes is ${limits.memoryBytes}): ${error.message}`), { name: "MemoryLimitError", code: "memory-limit" });
|
|
193
|
+
if (error?.code === "ERR_ANDBOX_DEADLINE" || error?.name === "TimeoutError") throw Object.assign(new Error(`stopped: past its deadline of ${limits.deadlineMs} ms (strict.deadlineMs; a deadline is wall-clock time, so unlike fuel it can stop at a different place each run)`), { name: "TimeoutError", code: "deadline" });
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
/** Run one strict pane's code (see strictProgram); queued behind the strict runs before it. */
|
|
199
|
+
run(args) {
|
|
200
|
+
const done = queue.then(() => once(args));
|
|
201
|
+
queue = done.catch(() => {});
|
|
202
|
+
return done;
|
|
203
|
+
},
|
|
204
|
+
/** Whether the engine has been made (a strict pane has run). */
|
|
205
|
+
get started() {
|
|
206
|
+
return sandbox !== null;
|
|
207
|
+
},
|
|
208
|
+
dispose() {
|
|
209
|
+
disposed = true;
|
|
210
|
+
const was = sandbox;
|
|
211
|
+
sandbox = null;
|
|
212
|
+
return was?.then((box) => box.dispose?.()).catch(() => {});
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|