@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,217 @@
|
|
|
1
|
+
// Input log panes (src/panes/inputlog.js): the pure part. A pane records what is wired into it (an action map's
|
|
2
|
+
// actions, a device pane's keyboard, pointer or gamepad, any small value) as an input log (src/input/log.js), and
|
|
3
|
+
// replays a log on the canvas transport with a timeline. The canvas side (the clock, the recorder, the runs) is
|
|
4
|
+
// src/model/input-log-hub.js; the body is src/ui/input-log-pane.js. No DOM, no clock: it runs under node --test.
|
|
5
|
+
//
|
|
6
|
+
// The pane's settings (`inputLog`), saved with the canvas:
|
|
7
|
+
//
|
|
8
|
+
// { mode: "live" | "replay", fps, loop, log?, keyboard? }
|
|
9
|
+
//
|
|
10
|
+
// mode live: its value is what is wired in now (and what a recording takes); replay: its value is the log's
|
|
11
|
+
// sample at the playhead
|
|
12
|
+
// fps the frames per second a recording counts in (1 to 120, default 30); a replay plays the log at its own
|
|
13
|
+
// loop a replay starts again at frame 0 when it reaches the end
|
|
14
|
+
// log the recorded (or imported) input log
|
|
15
|
+
// keyboard the log was recorded from a keyboard (a keyboard device pane upstream, or keys in what was wired):
|
|
16
|
+
// it stays out of share links, like a device pane's keyboard recordings (#688)
|
|
17
|
+
//
|
|
18
|
+
// The pane's value, the same shape in both modes (an action map's value with the rest of a sample beside it):
|
|
19
|
+
//
|
|
20
|
+
// { frame, t, actions: { jump: { down, pressed, released, value }, move: { x, y } }, pressed: [names], released: [names],
|
|
21
|
+
// keys: { down, pressed, released }, pointer: { … }, pads: [ … ], values: { name: value } }
|
|
22
|
+
//
|
|
23
|
+
// A recording keeps an action's held state only (`down` and `value`, an axis's `value`, a vector's `x` and `y`): the
|
|
24
|
+
// edges (`pressed`, `released`) are worked out again from frame to frame, so a button pressed in frame 10 is pressed
|
|
25
|
+
// in that frame and no other, however long the log holds it. The value of frame f is a function of the log and f
|
|
26
|
+
// alone, so the same log gives the same values, run after run.
|
|
27
|
+
import { inputLogReader, normalizeSample, sampleFromDevices, emptySample, isInputLog, INPUT_LOG_LIMITS } from "./log.js";
|
|
28
|
+
|
|
29
|
+
export const INPUT_LOG_MODES = ["live", "replay"];
|
|
30
|
+
export const FPS_RANGE = [1, 120];
|
|
31
|
+
/** What one recording may take: ten minutes, 20,000 entries, and a log of at most 1 MB of JSON (it is saved with the canvas). */
|
|
32
|
+
export const RECORD_LIMITS = Object.freeze({ seconds: 600, entries: 20000, chars: 1000000 });
|
|
33
|
+
|
|
34
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
35
|
+
const own = (o, k) => Object.hasOwn(o, k);
|
|
36
|
+
|
|
37
|
+
/** Why `log` can't be an input log pane's log (a sentence), or "". */
|
|
38
|
+
export function logProblem(log) {
|
|
39
|
+
try {
|
|
40
|
+
inputLogReader(log);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return error.message;
|
|
43
|
+
}
|
|
44
|
+
let text;
|
|
45
|
+
try {
|
|
46
|
+
text = JSON.stringify(log);
|
|
47
|
+
} catch {
|
|
48
|
+
return "the log is not JSON";
|
|
49
|
+
}
|
|
50
|
+
if (text.length > RECORD_LIMITS.chars) return `a pane keeps a log of at most ${RECORD_LIMITS.chars / 1000000} MB of JSON (this one is ${(text.length / 1000000).toFixed(1)} MB): keep it in a file`;
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** What is wrong with an input log pane's settings (a sentence), or "". */
|
|
55
|
+
export function inputLogProblem(raw) {
|
|
56
|
+
if (!isObject(raw)) return "inputLog is { mode, fps, loop, log?, keyboard? }";
|
|
57
|
+
const extra = Object.keys(raw).find((k) => !["mode", "fps", "loop", "log", "keyboard"].includes(k));
|
|
58
|
+
if (extra) return `"${extra}" isn't a setting of an input log pane (mode, fps, loop, log, keyboard)`;
|
|
59
|
+
if (raw.mode !== undefined && !INPUT_LOG_MODES.includes(raw.mode)) return `mode is ${INPUT_LOG_MODES.join(" or ")}`;
|
|
60
|
+
if (raw.fps !== undefined && !(Number.isInteger(raw.fps) && raw.fps >= FPS_RANGE[0] && raw.fps <= FPS_RANGE[1])) return `fps is a whole number from ${FPS_RANGE[0]} to ${FPS_RANGE[1]}`;
|
|
61
|
+
for (const k of ["loop", "keyboard"]) if (raw[k] !== undefined && typeof raw[k] !== "boolean") return `${k} is true or false`;
|
|
62
|
+
if (raw.log !== undefined && raw.log !== null) {
|
|
63
|
+
const why = logProblem(raw.log);
|
|
64
|
+
if (why) return why;
|
|
65
|
+
}
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The settings in a fixed shape, with what is wrong left out (a log that isn't one is dropped: the pane says it has none). */
|
|
70
|
+
export function inputLogSettings(raw) {
|
|
71
|
+
const r = isObject(raw) ? raw : {};
|
|
72
|
+
const out = {
|
|
73
|
+
mode: INPUT_LOG_MODES.includes(r.mode) ? r.mode : "live",
|
|
74
|
+
fps: Number.isInteger(r.fps) && r.fps >= FPS_RANGE[0] && r.fps <= FPS_RANGE[1] ? r.fps : 30,
|
|
75
|
+
loop: r.loop === true,
|
|
76
|
+
};
|
|
77
|
+
if (r.log !== undefined && r.log !== null && !logProblem(r.log)) out.log = r.log;
|
|
78
|
+
if (r.keyboard === true) out.keyboard = true;
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const defaultInputLog = () => ({ mode: "live", fps: 30, loop: false });
|
|
83
|
+
|
|
84
|
+
/** Does the log hold keys a person typed (its pane says it was recorded from a keyboard, or it has key entries)? Such a log stays out of share links. */
|
|
85
|
+
export function isKeyboardLog(raw) {
|
|
86
|
+
if (!isObject(raw)) return false;
|
|
87
|
+
if (raw.keyboard === true) return true;
|
|
88
|
+
const deltas = isObject(raw.log) && Array.isArray(raw.log.deltas) ? raw.log.deltas : [];
|
|
89
|
+
return deltas.some((e) => Array.isArray(e) && isObject(e[1]) && ((Array.isArray(e[1].kd) && e[1].kd.length > 0) || own(e[1], "kp") || own(e[1], "kr")));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ── reading what is wired in ──────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
const isActionMapValue = (v) => isObject(v) && isObject(v.actions) && Array.isArray(v.pressed) && Array.isArray(v.released);
|
|
95
|
+
const isKeyboard = (v) => isObject(v) && Array.isArray(v.held);
|
|
96
|
+
const isPointer = (v) => isObject(v) && typeof v.x === "number" && typeof v.y === "number" && own(v, "buttons");
|
|
97
|
+
const isGamepad = (v) => isObject(v) && Array.isArray(v.axes) && Array.isArray(v.buttons);
|
|
98
|
+
|
|
99
|
+
/** An action map's actions without their edges: what is held (`down`, `value`, `x`, `y`), the part a log keeps. */
|
|
100
|
+
export function heldActions(actions) {
|
|
101
|
+
const out = {};
|
|
102
|
+
if (!isObject(actions)) return out;
|
|
103
|
+
for (const [name, v] of Object.entries(actions)) {
|
|
104
|
+
if (name === "__proto__") continue;
|
|
105
|
+
if (isObject(v)) {
|
|
106
|
+
const { pressed, released, ...rest } = v;
|
|
107
|
+
out[name] = rest;
|
|
108
|
+
} else out[name] = v;
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Sort the wired values (by input name) into the parts of a sample: action maps' actions (held state only), a
|
|
115
|
+
* keyboard (`{ held }`), a pointer (`{ x, y, buttons }`), gamepads (`{ axes, buttons }`), and anything else as a
|
|
116
|
+
* named value. An input log wired in is left out (a log is not input). Returns `{ actions, keyboard, pointer,
|
|
117
|
+
* gamepads, values, keyboardRead }`.
|
|
118
|
+
*/
|
|
119
|
+
export function sortInputs(inputs) {
|
|
120
|
+
const out = { actions: {}, keyboard: null, pointer: null, gamepads: [], values: {}, keyboardRead: false };
|
|
121
|
+
for (const [name, v] of Object.entries(isObject(inputs) ? inputs : {})) {
|
|
122
|
+
if (isInputLog(v)) continue;
|
|
123
|
+
if (isActionMapValue(v)) Object.assign(out.actions, heldActions(v.actions));
|
|
124
|
+
else if (isKeyboard(v)) {
|
|
125
|
+
out.keyboard ??= v;
|
|
126
|
+
out.keyboardRead = true;
|
|
127
|
+
} else if (isGamepad(v)) out.gamepads.push(v);
|
|
128
|
+
else if (isPointer(v)) out.pointer ??= v;
|
|
129
|
+
else if (v !== undefined) out.values[name] = v;
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The sample of what is wired in now, with `prev` (the sample before) for the keys and buttons that went up or down. */
|
|
135
|
+
export function liveSample(inputs, prev = null) {
|
|
136
|
+
const s = sortInputs(inputs);
|
|
137
|
+
return sampleFromDevices({ keyboard: s.keyboard, pointer: s.pointer, gamepads: s.gamepads, actions: s.actions, values: s.values }, prev);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ── the value ─────────────────────────────────────────────────────────────
|
|
141
|
+
|
|
142
|
+
const down = (v) => isObject(v) && v.down === true;
|
|
143
|
+
const isButton = (v) => isObject(v) && own(v, "down");
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The pane's value for `sample`, `before` being the sample of the frame before it (or of the run before, live):
|
|
147
|
+
* every button action with its edges, the names that were pressed and released, and the rest of the sample.
|
|
148
|
+
* `frame` and `fps` place it in time (`frame: null` when it is not in a log: live and not recording).
|
|
149
|
+
*/
|
|
150
|
+
export function frameValue(sample, before = emptySample(), { frame = null, fps = 30 } = {}) {
|
|
151
|
+
const s = normalizeSample(sample);
|
|
152
|
+
const b = normalizeSample(before);
|
|
153
|
+
const actions = {};
|
|
154
|
+
const pressed = [];
|
|
155
|
+
const released = [];
|
|
156
|
+
for (const [name, v] of Object.entries(s.actions)) {
|
|
157
|
+
if (isButton(v)) {
|
|
158
|
+
const was = down(b.actions[name]);
|
|
159
|
+
const is = down(v);
|
|
160
|
+
actions[name] = { ...v, down: is, pressed: is && !was, released: !is && was };
|
|
161
|
+
if (is && !was) pressed.push(name);
|
|
162
|
+
if (!is && was) released.push(name);
|
|
163
|
+
} else actions[name] = v;
|
|
164
|
+
}
|
|
165
|
+
for (const [name, v] of Object.entries(b.actions)) if (!own(s.actions, name) && down(v)) released.push(name); // an action that went away while held comes up
|
|
166
|
+
return {
|
|
167
|
+
frame,
|
|
168
|
+
t: frame === null ? null : Math.round((frame / fps) * 1000) / 1000,
|
|
169
|
+
actions,
|
|
170
|
+
pressed,
|
|
171
|
+
released,
|
|
172
|
+
keys: s.keys,
|
|
173
|
+
pointer: s.pointer,
|
|
174
|
+
pads: s.pads,
|
|
175
|
+
values: s.values,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The value of frame `frame` of a log (its reader): the same for the same log and frame, every time. */
|
|
180
|
+
export function valueAt(reader, frame) {
|
|
181
|
+
const f = Math.max(0, Math.min(Math.max(0, reader.frames - 1), Math.floor(Number(frame) || 0)));
|
|
182
|
+
return frameValue(reader.at(f), f > 0 ? reader.at(f - 1) : emptySample(), { frame: f, fps: reader.fps });
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The events a value sends: `pressed` and `released`, `{ action }` each, in that order. */
|
|
186
|
+
export const valueEvents = (value) => [...value.pressed.map((action) => ({ name: "pressed", payload: { action } })), ...value.released.map((action) => ({ name: "released", payload: { action } }))];
|
|
187
|
+
|
|
188
|
+
/** The frames of a log where its input changes (its entries), in order. */
|
|
189
|
+
export const entryFrames = (reader) => reader.log.deltas.map((e) => e[0]).filter((f) => f < reader.frames);
|
|
190
|
+
|
|
191
|
+
/** The first frame after `after` where the log's input changes, or null. */
|
|
192
|
+
export function nextEntry(reader, after) {
|
|
193
|
+
for (const [f] of reader.log.deltas) if (f > after && f < reader.frames) return f;
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Every value a whole replay publishes, in order: frame 0, then each frame where the input changes. What playing a
|
|
199
|
+
* log from the start delivers, and so what the panes it feeds see (`test/input-log-pane.test.mjs` checks the canvas
|
|
200
|
+
* against it).
|
|
201
|
+
*/
|
|
202
|
+
export function replayValues(log) {
|
|
203
|
+
const reader = inputLogReader(log);
|
|
204
|
+
if (!reader.frames) return [];
|
|
205
|
+
const frames = [0, ...entryFrames(reader).filter((f) => f > 0)];
|
|
206
|
+
return frames.map((f) => valueAt(reader, f));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** The settings in words: "replay, 4.0 s (120 frames at 30 fps)…" or "live, nothing recorded". */
|
|
210
|
+
export function describeInputLog(raw) {
|
|
211
|
+
const s = inputLogSettings(raw);
|
|
212
|
+
if (!s.log) return `${s.mode}, nothing recorded`;
|
|
213
|
+
const r = inputLogReader(s.log);
|
|
214
|
+
return `${s.mode}, ${(r.frames / r.fps).toFixed(1)} s (${r.frames} frames at ${r.fps} fps, ${r.log.deltas.length} changes)${s.loop ? ", loops" : ""}${isKeyboardLog(s) ? ", keyboard" : ""}`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { INPUT_LOG_LIMITS };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Replaying an input log into a simulation without a browser: the state at frame n, its hash, the first
|
|
2
|
+
// frame two runs differ, and the hash checks a log carries. Pure (no DOM, no clock): the same engine
|
|
3
|
+
// (createSimulation) and wrapper (compileSimulation) a render pane's simulation steps with, so frame n
|
|
4
|
+
// here is frame n there.
|
|
5
|
+
//
|
|
6
|
+
// A hash is 16 hex digits of the state (src/sim/drive.js hashBytes over a canonical text of it). A state
|
|
7
|
+
// hash is a property of the code, the seed, the fps and the input, and of the JavaScript engine's own
|
|
8
|
+
// floating point: it is the same on the same machine and browser or Node, and nothing promises it
|
|
9
|
+
// across them (Math.sin and friends may differ in the last bit). The pixel hash of a picture is the frame
|
|
10
|
+
// hash (src/render/frame.js), likewise same-machine.
|
|
11
|
+
import { inputLogReader } from "./log.js";
|
|
12
|
+
import { simulate } from "../sim/compile.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The canonical text of a value, for hashing: object keys sorted (order doesn't matter to an object),
|
|
16
|
+
* Map and Set entries and arrays in order (it does), numbers exactly (-0, NaN and Infinity told apart),
|
|
17
|
+
* typed arrays with their kind, cycles as back references. With `hash` true: the 64-bit hash (two FNV-1a
|
|
18
|
+
* lanes, as hashBytes in src/sim/drive.js) of that text's UTF-8 bytes as 16 hex digits instead.
|
|
19
|
+
* Self-contained: sent to the sandbox as source text.
|
|
20
|
+
*/
|
|
21
|
+
export function canonicalState(value, hash = false) {
|
|
22
|
+
const seen = new Map();
|
|
23
|
+
const walk = (v) => {
|
|
24
|
+
if (v === undefined) return "u";
|
|
25
|
+
if (v === null) return "n";
|
|
26
|
+
const t = typeof v;
|
|
27
|
+
if (t === "boolean") return v ? "t" : "f";
|
|
28
|
+
if (t === "number") return Object.is(v, -0) ? "-0" : String(v);
|
|
29
|
+
if (t === "bigint") return `${v}b`;
|
|
30
|
+
if (t === "string") return JSON.stringify(v);
|
|
31
|
+
if (t === "function") return "fn";
|
|
32
|
+
if (t === "symbol") return `sym:${String(v)}`;
|
|
33
|
+
if (seen.has(v)) return `@${seen.get(v)}`;
|
|
34
|
+
seen.set(v, seen.size);
|
|
35
|
+
if (Array.isArray(v)) return `[${v.map(walk).join(",")}]`;
|
|
36
|
+
if (ArrayBuffer.isView(v)) return `${v.constructor.name}(${Array.from(new Uint8Array(v.buffer, v.byteOffset, v.byteLength)).join(",")})`;
|
|
37
|
+
if (v instanceof ArrayBuffer) return `ArrayBuffer(${Array.from(new Uint8Array(v)).join(",")})`;
|
|
38
|
+
if (v instanceof Date) return `date:${Number.isNaN(v.getTime()) ? "NaN" : v.toISOString()}`;
|
|
39
|
+
if (v instanceof Map) return `map{${Array.from(v, ([k, x]) => `${walk(k)}=>${walk(x)}`).join(",")}}`;
|
|
40
|
+
if (v instanceof Set) return `set{${Array.from(v, walk).join(",")}}`;
|
|
41
|
+
return `{${Object.keys(v)
|
|
42
|
+
.sort()
|
|
43
|
+
.map((k) => `${JSON.stringify(k)}:${walk(v[k])}`)
|
|
44
|
+
.join(",")}}`;
|
|
45
|
+
};
|
|
46
|
+
const text = walk(value);
|
|
47
|
+
if (!hash) return text;
|
|
48
|
+
const bytes = new TextEncoder().encode(text);
|
|
49
|
+
let a = 0x811c9dc5;
|
|
50
|
+
let b = 0x9747b28c;
|
|
51
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
52
|
+
const c = bytes[i];
|
|
53
|
+
a = Math.imul(a ^ c, 0x01000193);
|
|
54
|
+
b = Math.imul(b ^ c, 0x85ebca6b);
|
|
55
|
+
b ^= b >>> 13;
|
|
56
|
+
}
|
|
57
|
+
return (a >>> 0).toString(16).padStart(8, "0") + (b >>> 0).toString(16).padStart(8, "0");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The hash of a state: 16 hex digits of its canonical text (same text, same hash; src/sim/drive.js hashBytes is the scheme). */
|
|
61
|
+
export const hashState = (value) => canonicalState(value, true);
|
|
62
|
+
|
|
63
|
+
/** Why a log can't be replayed into a pane with this fps and seed, in words, or null when it can. */
|
|
64
|
+
export const replayProblem = (log, options = {}) => inputLogReader(log).problem(options);
|
|
65
|
+
|
|
66
|
+
const wholeFrame = (n, what) => {
|
|
67
|
+
if (!Number.isSafeInteger(n) || n < 0) throw new Error(`${what} must be a whole number of 0 or more (got ${n})`);
|
|
68
|
+
return n;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Play `log` into the simulation `code` (a render pane's simulation code, as src/sim/compile.js takes it)
|
|
73
|
+
* up to frame `to` (default the log's last frame) and hash the state. Frame 0 is `init(seed)`; each later
|
|
74
|
+
* frame is one `step(state, dt, inputs, sample)` with that frame's sample.
|
|
75
|
+
*
|
|
76
|
+
* Gives `{ fps, seed, to, hashes, final, states }`: `hashes[f]` the hash of frame `f` for each `f` that is a multiple of
|
|
77
|
+
* `every` (and the last frame always); `final` is `{ frame, hash, state }`; `states` is a Map of the
|
|
78
|
+
* states (cloned) at the frames in `capture`. `inputs`: the wired values of the pane; `env`: width, height,
|
|
79
|
+
* duration and dpr (fps comes from the log). `seed`: use this instead of the log's (a replay under another seed).
|
|
80
|
+
*/
|
|
81
|
+
export function replayLog({ code, log, inputs = {}, env = {}, to, every = 1, capture = [], seed } = {}) {
|
|
82
|
+
const reader = inputLogReader(log);
|
|
83
|
+
const last = to === undefined ? Math.max(0, reader.frames - 1) : wholeFrame(to, "the frame");
|
|
84
|
+
const step = Math.max(1, Math.floor(Number(every)) || 1);
|
|
85
|
+
const sim = simulate({
|
|
86
|
+
code,
|
|
87
|
+
seed: seed ?? reader.seed,
|
|
88
|
+
fps: reader.fps,
|
|
89
|
+
inputs,
|
|
90
|
+
env,
|
|
91
|
+
inputAt: (frame) => reader.at(frame),
|
|
92
|
+
checkpoints: { every: Number.MAX_SAFE_INTEGER, max: 1 },
|
|
93
|
+
maxSeekSteps: Number.MAX_SAFE_INTEGER,
|
|
94
|
+
});
|
|
95
|
+
const want = new Set(capture);
|
|
96
|
+
const hashes = {};
|
|
97
|
+
const states = new Map();
|
|
98
|
+
let state;
|
|
99
|
+
for (let f = 0; f <= last; f++) {
|
|
100
|
+
state = sim.seek(f);
|
|
101
|
+
if (f % step === 0 || f === last) hashes[f] = hashState(state);
|
|
102
|
+
if (want.has(f)) states.set(f, structuredClone(state));
|
|
103
|
+
}
|
|
104
|
+
return { fps: reader.fps, seed: seed ?? reader.seed, to: last, hashes, final: { frame: last, hash: hashes[last], state }, states };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The hash of the state at frame `frame` when `log` is replayed into `code`. */
|
|
108
|
+
export function hashAt(options, frame) {
|
|
109
|
+
return replayLog({ ...options, to: frame, every: Number.MAX_SAFE_INTEGER, capture: [] }).final.hash;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Walk two values and say where they first differ: `{ path, a, b }` (a path like `balls.0.x`; `a` and `b` the
|
|
114
|
+
* values as short canonical text), or null. `canon` is canonicalState (a parameter so that the function's source
|
|
115
|
+
* runs on its own in the sandbox, given it).
|
|
116
|
+
*/
|
|
117
|
+
export function firstStateDifference(a, b, canon = canonicalState) {
|
|
118
|
+
const short = (v) => {
|
|
119
|
+
const text = canon(v);
|
|
120
|
+
return text.length > 120 ? `${text.slice(0, 119)}…` : text;
|
|
121
|
+
};
|
|
122
|
+
const walk = (x, y, path) => {
|
|
123
|
+
if (canon(x) === canon(y)) return null;
|
|
124
|
+
const plain = (v) => v !== null && typeof v === "object" && !ArrayBuffer.isView(v) && !(v instanceof Date);
|
|
125
|
+
if (plain(x) && plain(y) && Array.isArray(x) === Array.isArray(y) && !(x instanceof Map) && !(y instanceof Map) && !(x instanceof Set) && !(y instanceof Set)) {
|
|
126
|
+
const keys = Array.isArray(x) ? Array.from({ length: Math.max(x.length, y.length) }, (_, i) => String(i)) : [...new Set([...Object.keys(x), ...Object.keys(y)])].sort();
|
|
127
|
+
for (const k of keys) {
|
|
128
|
+
const found = walk(x[k], y[k], path ? `${path}.${k}` : k);
|
|
129
|
+
if (found) return found;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { path, a: short(x), b: short(y) };
|
|
133
|
+
};
|
|
134
|
+
return walk(a, b, "");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The first frame two replays differ: `{ same: true }` or `{ same: false, frame, a, b }`, `a` and `b` the
|
|
139
|
+
* hashes there. `a` and `b` are `replayLog` results (hashed every frame to compare every frame; with `every`
|
|
140
|
+
* above 1 the answer is the first hashed frame that differs). When one run is shorter and the rest agree,
|
|
141
|
+
* `frame` is the first frame only the longer has, with `lengthDiffers`.
|
|
142
|
+
*/
|
|
143
|
+
export function diffRuns(a, b) {
|
|
144
|
+
const frames = [...new Set([...Object.keys(a.hashes), ...Object.keys(b.hashes)].map(Number))].sort((x, y) => x - y);
|
|
145
|
+
for (const f of frames) {
|
|
146
|
+
const ha = a.hashes[f];
|
|
147
|
+
const hb = b.hashes[f];
|
|
148
|
+
if (ha !== undefined && hb !== undefined && ha !== hb) return { same: false, frame: f, a: ha, b: hb };
|
|
149
|
+
}
|
|
150
|
+
if (a.to !== b.to) {
|
|
151
|
+
const f = Math.min(a.to, b.to) + 1;
|
|
152
|
+
return { same: false, frame: f, a: a.hashes[f] ?? null, b: b.hashes[f] ?? null, lengthDiffers: true };
|
|
153
|
+
}
|
|
154
|
+
return { same: true };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Replay two logs into the same code and find the first frame their states differ, and where in the
|
|
159
|
+
* state: `{ same: true, frames }`, or `{ same: false, frame, a, b, where: { path, a, b } | null }`.
|
|
160
|
+
*/
|
|
161
|
+
export function compareLogs({ code, a, b, inputs = {}, env = {}, to, seed } = {}) {
|
|
162
|
+
const base = { code, inputs, env, every: 1, seed };
|
|
163
|
+
const frames = to ?? Math.max(inputLogReader(a).frames, inputLogReader(b).frames) - 1;
|
|
164
|
+
const ra = replayLog({ ...base, log: a, to: frames });
|
|
165
|
+
const rb = replayLog({ ...base, log: b, to: frames });
|
|
166
|
+
const d = diffRuns(ra, rb);
|
|
167
|
+
if (d.same) return { same: true, frames: frames + 1 };
|
|
168
|
+
const at = replayLogStates(base, a, b, d.frame);
|
|
169
|
+
return { same: false, frame: d.frame, a: d.a, b: d.b, where: at };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function replayLogStates(base, a, b, frame) {
|
|
173
|
+
const sa = replayLog({ ...base, log: a, to: frame, every: Number.MAX_SAFE_INTEGER, capture: [frame] }).states.get(frame);
|
|
174
|
+
const sb = replayLog({ ...base, log: b, to: frame, every: Number.MAX_SAFE_INTEGER, capture: [frame] }).states.get(frame);
|
|
175
|
+
return firstStateDifference(sa, sb);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Check the state hashes a log carries: replays to the last one and compares each. Pixel checks are for a
|
|
180
|
+
* browser (the render pane's frame hash) and come back `skipped`. Gives `[{ frame, kind, expected, actual,
|
|
181
|
+
* ok }]`, `ok` null for a skipped one.
|
|
182
|
+
*/
|
|
183
|
+
export function verifyChecks({ code, log, inputs = {}, env = {}, seed } = {}) {
|
|
184
|
+
const reader = inputLogReader(log);
|
|
185
|
+
const state = reader.checks.filter((c) => c.kind === "state");
|
|
186
|
+
const results = [];
|
|
187
|
+
const hashes = state.length ? replayLog({ code, log, inputs, env, to: Math.max(...state.map((c) => c.frame)), every: 1, seed }).hashes : {};
|
|
188
|
+
for (const c of reader.checks) {
|
|
189
|
+
if (c.kind === "pixel") results.push({ frame: c.frame, kind: c.kind, expected: c.hash, actual: null, ok: null, note: "a pixel hash is read from the picture in a browser" });
|
|
190
|
+
else results.push({ frame: c.frame, kind: c.kind, expected: c.hash, actual: hashes[c.frame], ok: hashes[c.frame] === c.hash });
|
|
191
|
+
}
|
|
192
|
+
return results;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The log with a state hash check at each of `frames` (what a replay gives now), replacing earlier ones at those frames. */
|
|
196
|
+
export function withStateChecks({ code, log, frames, inputs = {}, env = {}, seed }) {
|
|
197
|
+
const reader = inputLogReader(log);
|
|
198
|
+
const want = [...new Set(frames.map((f) => wholeFrame(f, "a check's frame")))].sort((x, y) => x - y);
|
|
199
|
+
const out = structuredClone(reader.log);
|
|
200
|
+
const kept = (out.checks ?? []).filter((c) => !(c.kind === "state" && want.includes(c.frame)));
|
|
201
|
+
if (want.length) {
|
|
202
|
+
const run = replayLog({ code, log, inputs, env, to: want[want.length - 1], every: 1, seed });
|
|
203
|
+
for (const f of want) kept.push({ frame: f, kind: "state", hash: run.hashes[f] });
|
|
204
|
+
}
|
|
205
|
+
kept.sort((x, y) => x.frame - y.frame || (x.kind < y.kind ? -1 : 1));
|
|
206
|
+
if (kept.length) out.checks = kept;
|
|
207
|
+
else delete out.checks;
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*! mallory jth: @johnhenry/jth-compiler@0.1.1, @johnhenry/jth-eval@0.1.0, @johnhenry/jth-html@0.1.0, @johnhenry/jth-runtime@0.1.1, @johnhenry/jth-stdlib@0.1.1, @johnhenry/jth-types@0.1.0 (MIT), bundled into one module by scripts/build-jth-vendor.mjs. Do not edit. */
|
|
2
|
+
var Z=Symbol.for("jth.html.element"),Q=Symbol.for("jth.html.text"),ee=Symbol.for("jth.html.raw"),te=Symbol.for("jth.html.fragment");function J(e,t={},r=[]){return{_type:Z,tag:e,attrs:t,children:r}}function _e(e){return{_type:Q,value:String(e)}}function Me(e){return{_type:ee,value:String(e)}}function re(e=[]){return{_type:te,children:e}}var Xt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);function $e(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function zt(e){let t="";for(let[r,n]of Object.entries(e))n!==!1&&(n===!0?t+=` ${r}`:t+=` ${r}="${$e(String(n))}"`);return t}function V(e){let t=e;if(t._type===Q)return $e(t.value);if(t._type===ee)return t.value;if(t._type===te)return t.children.map(V).join("");if(t._type===Z){let r=zt(t.attrs);if(Xt.has(t.tag))return`<${t.tag}${r}>`;let n=t.children.map(V).join("");return`<${t.tag}${r}>${n}</${t.tag}>`}return String(e)}var u=Object.freeze({NUMBER:"NUMBER",STRING:"STRING",BOOLEAN:"BOOLEAN",NULL:"NULL",UNDEFINED:"UNDEFINED",IDENTIFIER:"IDENTIFIER",OPERATOR:"OPERATOR",DEFINITION:"DEFINITION",VALUE_DEFINITION:"VALUE_DEFINITION",IMPORT:"IMPORT",EXPORT:"EXPORT",BLOCK_OPEN:"BLOCK_OPEN",OBJECT_OPEN:"OBJECT_OPEN",OBJECT_CLOSE:"OBJECT_CLOSE",ARRAY_OPEN:"ARRAY_OPEN",ARRAY_CLOSE:"ARRAY_CLOSE",PAREN_OPEN:"PAREN_OPEN",PAREN_CLOSE:"PAREN_CLOSE",INLINE_JS:"INLINE_JS",SEMICOLON:"SEMICOLON",COMMENT:"COMMENT",EOF:"EOF"});function ne(e,t,r,n){return{type:e,value:t,line:r,column:n}}function oe(e){return{type:"Program",body:e}}function ie(e,t,r){return{type:"NumberLiteral",value:e,line:t,column:r}}function ae(e,t,r){return{type:"StringLiteral",value:e,line:t,column:r}}function se(e,t,r){return{type:"BooleanLiteral",value:e,line:t,column:r}}function le(e,t){return{type:"NullLiteral",value:null,line:e,column:t}}function ue(e,t){return{type:"UndefinedLiteral",value:void 0,line:e,column:t}}function F(e,t,r,n){return{type:"OperatorCall",name:e,args:t||[],line:r,column:n}}function pe(e,t,r){return{type:"ArrayLiteral",elements:e,line:t,column:r}}function ce(e,t,r){return{type:"BlockLiteral",body:e,line:t,column:r}}function fe(e,t,r){return{type:"JSObjectLiteral",properties:e,line:t,column:r}}function he(e,t,r){return{type:"InlineJSExpression",code:e,line:t,column:r}}function me(e,t,r){return{type:"Definition",name:e,line:t,column:r}}function de(e,t,r){return{type:"ValueDefinition",name:e,line:t,column:r}}function ye(e,t,r,n){return{type:"Import",path:e,bindings:t,line:r,column:n}}function ve(e,t,r){return{type:"Export",names:e,line:t,column:r}}function ge(e){return{type:"Statement",expressions:e}}var H=class extends Error{line;column;constructor(e,t,r){super(e),this.name="JthError",this.line=t??null,this.column=r??null}},I=class extends H{constructor(e,t,r){super(e,t,r),this.name="JthLexerError"}},S=class extends H{constructor(e,t,r){super(e,t,r),this.name="JthParserError"}},v=class extends H{code;constructor(e,t,r,n){super(e,t,r),this.name="JthRuntimeError",this.code=n??null}},$=class Pe extends v{expected;actual;operator;constructor(t,r,n){super(Pe.describe(t.expected,t.actual,t.operator??null),r,n,"STACK_UNDERFLOW"),this.name="StackUnderflowError",this.expected=t.expected,this.actual=t.actual,this.operator=t.operator??null}static describe(t,r,n){return`Stack underflow${n?` in "${n}"`:""}: needed ${t} item(s), stack has ${r}`}withOperator(t){return this.operator===null&&(this.operator=t,this.message=Pe.describe(this.expected,this.actual,t)),this}};var k=class ct{#e=[];_condStack;_sink;push(...t){this.#e.push(...t)}pop(){if(this.#e.length===0)throw new $({expected:1,actual:0});return this.#e.pop()}popN(t){if(this.#e.length<t)throw new $({expected:t,actual:this.#e.length});let r=[];for(let n=0;n<t;n++)r.unshift(this.#e.pop());return r}peek(){return this.#e[this.#e.length-1]}peekN(t){return this.#e.slice(-t)}get length(){return this.#e.length}toArray(){return[...this.#e]}clear(){this.#e.length=0}isEmpty(){return this.#e.length===0}swap(){let t=this.#e.length;if(t<2)throw new $({expected:2,actual:t});let r=this.#e[t-1];this.#e[t-1]=this.#e[t-2],this.#e[t-2]=r}dup(){if(this.#e.length===0)throw new $({expected:1,actual:0});this.#e.push(this.#e[this.#e.length-1])}child(){let t=new ct;return t._sink=this._sink,t}clone(){let t=this.child();return t.push(...this.#e),t}[Symbol.iterator](){return this.#e[Symbol.iterator]()}};function a(e){return function(t){let r=function(n){let o=n.popN(e),l=t(...o);if(l&&typeof l.then=="function")return l.then(s=>{Array.isArray(s)&&n.push(...s)});Array.isArray(l)&&n.push(...l)};return r._arity=e,r._name=t.name||void 0,r}}function N(e){let t=function(r){let n=r.toArray();r.clear();let o=e(...n);if(o&&typeof o.then=="function")return o.then(l=>{Array.isArray(l)&&r.push(...l)});Array.isArray(o)&&r.push(...o)};return t._arity=1/0,t._name=e.name||void 0,t}function Zt(e,t){let r=e.length,n=t.length,o=Array.from({length:n+1},(l,s)=>s);for(let l=1;l<=r;l++){let s=o[0];o[0]=l;for(let p=1;p<=n;p++){let d=o[p];o[p]=Math.min(o[p]+1,o[p-1]+1,s+(e[l-1]===t[p-1]?0:1)),s=d}}return o[n]}function Qt(e){let t,r=3;for(let n of P.keys()){let o=Zt(e,n);o<r&&(r=o,t=n)}return t}var Je=new WeakMap;function Y(e,t){typeof e=="function"&&!Je.has(e)&&Je.set(e,t)}function Ce(e){return typeof e=="function"?Je.get(e):void 0}var U=new Map,De=new Map,ft=new WeakMap;function er(e,t){if(t!==void 0)return t;let r=e._arity;return r===1/0?"variadic":typeof r=="number"?r:"varies"}var P=new Map,we=[],g={set(e,t,r){if(P.set(e,t),Y(t,e),r){let n={name:e,arity:er(t,r.arity),description:r.description};U.set(e,n),ft.has(t)||ft.set(t,n)}else U.delete(e)},info(e){return P.has(e)?U.get(e):void 0},infos(){return[...P.keys()].flatMap(e=>{let t=U.get(e);return t?[t]:[]})},dynamicInfos(){return[...De.values()]},get(e){if(P.has(e))return P.get(e);for(let{pattern:t,factory:r}of we)if(t.test(e)){let n=r(e,t);return Y(n,e),n}},resolve(e){let t=g.get(e);if(!t){let r=Qt(e),n=r?` (did you mean "${r}"?)`:"";throw new v(`Unknown operator: ${e}${n}`,void 0,void 0,"UNKNOWN_OPERATOR")}return t},has(e){return g.get(e)!==void 0},names(){return[...P.keys()]},dynamicPatterns(){return we.map(e=>e.pattern)},remove(e){return U.delete(e),P.delete(e)},clear(){P.clear(),U.clear(),De.clear(),we.length=0},setDynamic(e,t,r){we.push({pattern:e,factory:t}),r&&De.set(e.source,r)}};var ht=new WeakMap;function C(e,t){let r=(...n)=>e(...n);return ht.set(r,{...Ee(e),...t}),r}function Ee(e){return ht.get(e)||{}}var j=null;function dt(e,t,r){let n=t[r];if(typeof n!="function")return e.push(n),r;let o=Ee(n);if(o.skip!==void 0){let p=o.skip===-1?t.length-r-1:o.skip;for(let d=0;d<p&&r+1<t.length;d++)e.push(t[++r])}if(o.delay!==void 0&&o.delay>0)return t.splice(r+1,0,C(n,{...o,delay:o.delay-1})),r;let l=[];if(o.limit!==void 0&&o.limit>=0){let p=e.toArray();e.clear(),o.limit<p.length&&(l=p.splice(0,p.length-o.limit)),e.push(...p)}let s;try{s=n(e)}catch(p){throw mt(p,n),p}return s&&typeof s.then=="function"?(j={promise:s.then(void 0,d=>{throw mt(d,n),d}),fn:n,meta:o,saved:l},r):(je(e,t,r,n,o,l),r)}function mt(e,t){if(e instanceof $&&e.operator===null){let r=Ce(t);r!==void 0&&e.withOperator(r)}}function je(e,t,r,n,o,l){if(l.length){let s=e.toArray();e.clear(),e.push(...l,...s)}if(o.persist!==void 0&&o.persist!==0){let s=o.persist===-1?-1:o.persist-1;t.splice(r+1,0,C(n,{...o,persist:s}))}if(o.rewind!==void 0){let s=o.rewind===-1?e.length:o.rewind;for(let p=0;p<s&&e.length>0;p++)t.splice(r+1,0,e.pop())}}function D(e,t){let r=[...t];for(let n=0;n<r.length;n++)if(n=dt(e,r,n),j){let o=j;return j=null,rr(e,r,n,o)}return e}async function rr(e,t,r,n){await n.promise,je(e,t,r,n.fn,n.meta,n.saved);for(let o=r+1;o<t.length;o++)if(o=dt(e,t,o),j){let l=j;j=null,await l.promise,je(e,t,o,l.fn,l.meta,l.saved)}return e}var Oe=class{#e;run(t,r,...n){let o=this.#e;this.#e=t;try{return r(...n)}finally{this.#e=o}}getStore(){return this.#e}};var yt=new Oe;function nr(...e){let t=yt.getStore();t?t(e.map(String).join(" ")):console.log(...e)}function vt(e,t){return yt.run(e,t)}function Be(e,...t){let r=e._sink;r?r(t.map(String).join(" ")):nr(...t)}var Fe=e=>{let t=e.pop(),r=e.pop(),n=new k,o=typeof r=="function"?r(n):void 0;if(o&&typeof o.then=="function")return o.then(()=>{e.push(J(t,{},n.toArray()))});e.push(J(t,{},n.toArray()))},Ue=a(1)(e=>[_e(e)]),We=a(1)(e=>[Me(e)]),qe=e=>{let t=e.pop(),r=new k,n=typeof t=="function"?t(r):void 0;if(n&&typeof n.then=="function")return n.then(()=>{e.push(re(r.toArray()))});e.push(re(r.toArray()))},Ve=a(1)(e=>[J(e,{},[])]),He=a(2)((e,t)=>[{...e,attrs:{...e.attrs,...t}}]),Ye=a(1)(e=>[V(e)]);var or=new Set(["h-tag","h-text","h-raw","h-frag","h-void","h-attrs","h-render"]);function Ne(){g.set("h-tag",Fe,{description:'Build an element: `#[ ... ] "div" h-tag` runs the block on a fresh stack and uses its output as the children.',arity:2}),g.set("h-text",Ue,{description:"Make an escaped text node.",arity:1}),g.set("h-raw",We,{description:"Make a raw (UNESCAPED) HTML node. Never feed it untrusted input.",arity:1}),g.set("h-frag",qe,{description:"Collect a block's output into a fragment node (no wrapping element).",arity:1}),g.set("h-void",Ve,{description:"Make an empty element (no children), e.g. br or img, from a tag name.",arity:1}),g.set("h-attrs",He,{description:"Merge an attributes object onto an element.",arity:2}),g.set("h-render",Ye,{description:"Render a node tree to an HTML string.",arity:1}),g.setDynamic(/^h-([a-z][a-z0-9]*)$/,(e,t)=>{if(or.has(e))return;let r=t.exec(e);if(!r)return;let n=r[1];return o=>{let l=o.pop(),s=new k,p=typeof l=="function"?l(s):void 0;if(p&&typeof p.then=="function")return p.then(()=>{o.push(J(n,{},s.toArray()))});o.push(J(n,{},s.toArray()))}},{syntax:"h-<tag>",arity:1,description:"Shorthand for a block then a tag name then h-tag: `#[ ... ] h-div` builds a <div> with the block's output as children."})}Ne();var Se=class{#e=new Map;#r=[];#t=null;constructor(e={}){e.allowlist&&(this.#t=e.allowlist)}set(e,t){this.#e.set(e,t),Y(t,e)}get(e){if(this.#e.has(e))return this.#e.get(e);for(let{pattern:t,factory:r}of this.#r)if(t.test(e))return r(e,t);if(!(this.#t&&!this.#t.has(e)))return g.get(e)}resolve(e){let t=this.get(e);if(!t)throw this.#t&&!this.#t.has(e)&&g.has(e)?new v(`Operator not allowed in sandbox: ${e}`,void 0,void 0,"OP_NOT_ALLOWED"):new v(`Unknown operator: ${e}`,void 0,void 0,"UNKNOWN_OPERATOR");return t}has(e){return this.get(e)!==void 0}remove(e){return this.#e.delete(e)}setDynamic(e,t){this.#r.push({pattern:e,factory:t})}clear(){this.#e.clear(),this.#r.length=0}};var ir=new Set(["+","-","*","/","=","<",">","$",".","%","~","&","|","^","!","?"]),ar=["<<-","->>","<=>","==","!=","<=",">=","**","$$","%%","~~","++","--","&&","||","..."],sr=new Set(["\u03A3","\u03A0","\u221A","\xF7","\u22C5","\u2205","\u0305"]);function lr(e){return sr.has(e)}function W(e){return e>="0"&&e<="9"}function gt(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"}function be(e){return gt(e)||e==="_"}function Ae(e){return gt(e)||W(e)||e==="-"||e==="_"}function Ke(e){return e===" "||e===" "||e==="\r"||e===`
|
|
3
|
+
`}function K(e){return ir.has(e)}function xe(e){let t=[],r=0,n=1,o=1;function l(m=0){return e[r+m]}function s(){return e[r]}function p(){let m=e[r];return r++,m===`
|
|
4
|
+
`?(n++,o=1):o++,m}function d(m,h,f,y){t.push(ne(m,h,f,y))}function E(){if(t.length===0)return!0;let h=t[t.length-1].type;return h===u.OPERATOR||h===u.SEMICOLON||h===u.BLOCK_OPEN||h===u.OBJECT_OPEN||h===u.ARRAY_OPEN||h===u.PAREN_OPEN||h===u.COMMENT||h===u.DEFINITION||h===u.VALUE_DEFINITION||h===u.IMPORT||h===u.EXPORT}function O(m,h){let f="";if(s()==="-"&&(f+=p()),s()==="0"&&(l(1)==="x"||l(1)==="X")){let x=m,T=h;f+=p(),f+=p();let ut=0;for(;r<e.length&&/[0-9a-fA-F]/.test(s());)f+=p(),ut++;if(ut===0)throw new I(`Invalid hex literal: expected at least one hex digit after "${f}"`,x,T);let pt=parseInt(f,16);if(r<e.length&&!Ke(s())&&(K(s())||be(s())))return A(String(pt),m,h);d(u.NUMBER,pt,m,h);return}for(;r<e.length&&W(s());)f+=p();if(r<e.length&&s()==="."&&r+1<e.length&&W(l(1)))for(f+=p();r<e.length&&W(s());)f+=p();let y=parseFloat(f);if(r<e.length&&!Ke(s())&&s()!==";"&&s()!=="}"&&s()!=="]"&&s()!==")"&&(K(s())||be(s())))return A(f,m,h);d(u.NUMBER,y,m,h)}function A(m,h,f){let y="";if(K(s()))for(;r<e.length&&K(s());)y+=p();else if(be(s()))for(;r<e.length&&Ae(s());)y+=p();d(u.OPERATOR,m+y,h,f)}function _(m,h,f){p();let y="";for(;r<e.length&&s()!==m;)if(s()==="\\"){if(p(),r>=e.length)throw new I("Unterminated string escape",n,o);let x=p();switch(x){case"n":y+=`
|
|
5
|
+
`;break;case"t":y+=" ";break;case"r":y+="\r";break;case"\\":y+="\\";break;case"'":y+="'";break;case'"':y+='"';break;case"`":y+="`";break;default:y+="\\"+x;break}}else{if(s()===`
|
|
6
|
+
`&&m!=="`")throw new I("Unterminated string",h,f);y+=p()}if(r>=e.length)throw new I("Unterminated string",h,f);p(),d(u.STRING,y,h,f)}function R(m,h){let f="";for(;r<e.length&&Ae(s());)f+=p();r<e.length&&s()==="?"&&(f+=p()),f==="true"?d(u.BOOLEAN,!0,m,h):f==="false"?d(u.BOOLEAN,!1,m,h):f==="null"?d(u.NULL,null,m,h):f==="undefined"?d(u.UNDEFINED,void 0,m,h):d(u.IDENTIFIER,f,m,h)}function b(m,h){for(let y of ar)if(e.startsWith(y,r)){for(let x=0;x<y.length;x++)p();d(u.OPERATOR,y,m,h);return}let f=p();d(u.OPERATOR,f,m,h)}function q(m,h){let f="";for(;r<e.length&&s()==="*";)f+=p();d(u.OPERATOR,f,m,h)}function c(m,h){let f=0,y="",x=null;for(;r<e.length;){let T=s();if(x){if(T==="\\"){y+=p(),r<e.length&&(y+=p());continue}T===x&&(x=null),y+=p();continue}if(T==="'"||T==='"'||T==="`"){x=T,y+=p();continue}if(T==="/"&&l(1)==="/"){for(;r<e.length&&s()!==`
|
|
7
|
+
`;)y+=p();continue}if(T==="(")f++,y+=p();else if(T===")"){if(f--,y+=p(),f===0)break}else y+=p()}if(f!==0||x)throw new I("Unterminated inline JS expression",m,h);d(u.INLINE_JS,y,m,h)}function w(m,h){p(),p();let f="";for(r<e.length&&s()===" "&&p();r<e.length&&s()!==`
|
|
8
|
+
`;)f+=p();d(u.COMMENT,f,m,h)}function B(m,h){p();let f="";for(r<e.length&&s()===" "&&p();r<e.length&&s()!==`
|
|
9
|
+
`;)f+=p();d(u.COMMENT,f,m,h)}function Gt(m,h){if(p(),r<e.length&&s()===":"){p();let f="";for(;r<e.length&&Ae(s());)f+=p();if(f==="import")d(u.IMPORT,"import",m,h);else if(f==="export")d(u.EXPORT,"export",m,h);else if(f.length>0)r<e.length&&s()==="?"&&(f+=p()),d(u.VALUE_DEFINITION,f,m,h);else throw new I("Expected identifier after '::'",m,h)}else{let f="";for(;r<e.length&&Ae(s());)f+=p();if(r<e.length&&s()==="?"&&(f+=p()),f.length===0)throw new I("Expected identifier after ':'",m,h);d(u.DEFINITION,f,m,h)}}for(;r<e.length;){let m=s(),h=n,f=o;if(Ke(m)){p();continue}if(m==="/"&&l(1)==="/"){w(h,f);continue}if(m===";"){p(),d(u.SEMICOLON,";",h,f);continue}if(m==='"'||m==="'"||m==="`"){_(m,h,f);continue}if(m==="#"&&l(1)==="["){p(),p(),d(u.BLOCK_OPEN,"#[",h,f);continue}if(m==="#"){B(h,f);continue}if(m==="{"){p(),d(u.OBJECT_OPEN,"{",h,f);continue}if(m==="}"){p(),d(u.OBJECT_CLOSE,"}",h,f);continue}if(m==="["){p(),d(u.ARRAY_OPEN,"[",h,f);continue}if(m==="]"){p(),d(u.ARRAY_CLOSE,"]",h,f);continue}if(m==="("){if(l(1)==="("){c(h,f);continue}p(),d(u.PAREN_OPEN,"(",h,f);continue}if(m===")"){p(),d(u.PAREN_CLOSE,")",h,f);continue}if(m===":"){Gt(h,f);continue}if(m==="-"&&r+1<e.length&&W(l(1))&&E()){O(h,f);continue}if(W(m)){O(h,f);continue}if(m==="*"){q(h,f);continue}if(K(m)){b(h,f);continue}if(lr(m)){p(),d(u.OPERATOR,m,h,f);continue}if(be(m)){R(h,f);continue}throw new I(`Unexpected character: '${m}'`,h,f)}return d(u.EOF,null,n,o),t}var wt=500;function Re(e){let t=0,r=0;function n(){return e[t]}function o(){return e[t++]}function l(c){let w=n();if(!w||w.type!==c){let B=w?`${w.type} "${w.value}"`:"end of input";throw new S(`Expected ${c} but found ${B}`,w?.line,w?.column)}return o()}function s(){let c=[];for(;n().type!==u.EOF;){if(n().type===u.COMMENT){o();continue}if(n().type===u.SEMICOLON){o();continue}c.push(p())}return oe(c)}function p(){let c=[];for(;n().type!==u.SEMICOLON&&n().type!==u.EOF&&n().type!==u.COMMENT;)c.push(d());return n().type===u.SEMICOLON&&o(),n().type===u.COMMENT&&o(),ge(c)}function d(){if(r++,r>wt){let c=n();throw new S(`Maximum expression nesting depth (${wt}) exceeded`,c?.line,c?.column)}try{return E()}finally{r--}}function E(){let c=n();switch(c.type){case u.NUMBER:return o(),ie(c.value,c.line,c.column);case u.STRING:return o(),ae(c.value,c.line,c.column);case u.BOOLEAN:return o(),se(c.value,c.line,c.column);case u.NULL:return o(),le(c.line,c.column);case u.UNDEFINED:return o(),ue(c.line,c.column);case u.OPERATOR:return o(),F(c.value,[],c.line,c.column);case u.IDENTIFIER:return O();case u.BLOCK_OPEN:return A();case u.ARRAY_OPEN:return _();case u.OBJECT_OPEN:return R();case u.INLINE_JS:return o(),he(c.value,c.line,c.column);case u.DEFINITION:return o(),me(c.value,c.line,c.column);case u.VALUE_DEFINITION:return o(),de(c.value,c.line,c.column);case u.IMPORT:return b();case u.EXPORT:return q();default:throw new S(`Unexpected token: ${c.type} "${c.value}"`,c.line,c.column)}}function O(){let c=o();if(n().type===u.PAREN_OPEN){o();let w=[];for(;n().type!==u.PAREN_CLOSE;){if(n().type===u.EOF)throw new S("Unterminated configured operator arguments",c.line,c.column);w.push(d())}return o(),F(c.value,w,c.line,c.column)}return F(c.value,[],c.line,c.column)}function A(){let c=o(),w=[];for(;n().type!==u.ARRAY_CLOSE;){if(n().type===u.EOF)throw new S("Unterminated block",c.line,c.column);if(n().type===u.SEMICOLON){o();continue}if(n().type===u.COMMENT){o();continue}w.push(d())}return o(),ce(w,c.line,c.column)}function _(){let c=o(),w=[];for(;n().type!==u.ARRAY_CLOSE;){if(n().type===u.EOF)throw new S("Unterminated array",c.line,c.column);if(n().type===u.SEMICOLON){o();continue}if(n().type===u.COMMENT){o();continue}w.push(d())}return o(),pe(w,c.line,c.column)}function R(){let c=o(),w=[];for(;n().type!==u.OBJECT_CLOSE;){if(n().type===u.EOF)throw new S("Unterminated object literal",c.line,c.column);if(n().type===u.SEMICOLON){o();continue}if(n().type===u.COMMENT){o();continue}w.push(d())}return o(),fe(w,c.line,c.column)}function b(){let c=o(),w=null;if(n().type===u.STRING)w=o().value;else throw new S("Expected string path after ::import",n().line,n().column);let B=[];if(n().type===u.OBJECT_OPEN){for(o();n().type!==u.OBJECT_CLOSE;){if(n().type===u.EOF)throw new S("Unterminated import bindings",c.line,c.column);if(n().type===u.IDENTIFIER)B.push(o().value);else throw new S(`Expected identifier in import bindings, got ${n().type}`,n().line,n().column)}o()}return ye(w,B,c.line,c.column)}function q(){let c=o(),w=[];for(;n().type!==u.SEMICOLON&&n().type!==u.EOF&&n().type!==u.COMMENT;)if(n().type===u.IDENTIFIER)w.push(o().value);else throw new S(`Expected identifier in export, got ${n().type}`,n().line,n().column);return ve(w,c.line,c.column)}return s()}var pr=new Set(["break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","import","in","instanceof","new","null","return","super","switch","this","throw","true","try","typeof","var","void","while","with","yield","let","static","await","implements","interface","package","private","protected","public","arguments","eval"]);function Ge(e){for(let t of e)if(t&&typeof t.line=="number")return{line:t.line,column:typeof t.column=="number"?t.column:0};return null}function Xe(e,t){return t?`try { ${e} } catch (e) { if (e && typeof e === "object" && e.line == null) { e.line = ${t.line}; e.column = ${t.column}; } throw e; }`:e}function Ie(e){return e.replace(/-/g,"_").replace(/\?$/,"_p")}var G=!1,Te;function ze(e,t={}){let{preamble:r=!0,forbidInlineJS:n=!1,resolveImportPath:o}=t;G=n,Te=o;try{return cr(e,r)}finally{G=!1,Te=void 0}}function cr(e,t){let r=[];t&&(r.push('import { Stack, processN, registry } from "@johnhenry/jth-runtime";'),r.push('import "@johnhenry/jth-stdlib";'),r.push("const stack = new Stack();"),r.push(`if (import.meta.main === true && typeof process !== "undefined" && typeof process.on === "function") {
|
|
10
|
+
process.on("uncaughtException", (err) => {
|
|
11
|
+
if (err && typeof err.name === "string" && err.name.startsWith("Jth") && err.line != null) {
|
|
12
|
+
console.error(\`\${err.name} at \${err.line}:\${err.column ?? 0}: \${err.message}\`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
throw err;
|
|
16
|
+
});
|
|
17
|
+
}`));for(let n of e.body){let o=fr(n);o&&r.push(o)}return r.join(`
|
|
18
|
+
`)}function fr(e){let t=e.expressions;if(!t||t.length===0)return"";if(t.length===1){if(t[0].type==="Import")return yr(t[0]);if(t[0].type==="Export")return vr(t[0])}let r=t[t.length-1];if(r.type==="Definition")return mr(r.name,t.slice(0,-1),r.line,r.column);if(r.type==="ValueDefinition")return dr(r.name,t.slice(0,-1),r.line,r.column);let n=t.map(L);return Xe(`await processN(stack, [${n.join(", ")}]);`,Ge(t))}function L(e){switch(e.type){case"NumberLiteral":return Object.is(e.value,-0)?"-0":String(e.value);case"StringLiteral":return JSON.stringify(e.value);case"BooleanLiteral":return String(e.value);case"NullLiteral":return"null";case"UndefinedLiteral":return"undefined";case"OperatorCall":return e.args.length>0?`((s) => { ${e.args.map(r=>`s.push(${L(r)});`).join(" ")} return registry.resolve(${JSON.stringify(e.name)})(s); })`:`registry.resolve(${JSON.stringify(e.name)})`;case"BlockLiteral":return`((s) => { s.push(${`(s) => processN(s, [${e.body.map(L).join(", ")}])`}); })`;case"ArrayLiteral":return`[${e.elements.map(L).join(", ")}]`;case"JSObjectLiteral":return hr(e.properties,e.line,e.column);case"InlineJSExpression":if(G)throw new v("Inline JS ((...)) is not allowed in sandbox mode",e?.line,e?.column,"OP_NOT_ALLOWED");return e.code;case"Definition":return`((s) => { registry.set(${JSON.stringify(e.name)}, s.pop()); })`;case"ValueDefinition":if(G)throw new v("::name value-definitions are not allowed in sandbox mode",e?.line,e?.column,"OP_NOT_ALLOWED");return`((s) => { globalThis[${JSON.stringify(e.name)}] = s.pop(); })`;default:throw new v(`Unknown AST node type in codegen: ${e.type}`,e?.line,e?.column,"UNKNOWN_NODE")}}function hr(e,t,r){if(e.length>0&&e[0].key!==void 0)return`({${e.map(o=>`[${typeof o.key=="string"?JSON.stringify(o.key):L(o.key)}]: ${L(o.value)}`).join(", ")}})`;if(e.length%2===0){let n=[];for(let o=0;o<e.length;o+=2){let l=L(e[o]),s=L(e[o+1]);n.push(`[${l}]: ${s}`)}return`({${n.join(", ")}})`}throw new S(`Object literal { ... } requires an even number of key/value expressions (got ${e.length})`,t,r)}function Et(e,t,r,n){if(pr.has(e))throw new S(`Definition name "${t}" compiles to the reserved JS word "${e}" and cannot be used as a :name/::name definition`,r,n)}function mr(e,t,r,n){let o=Ie(e);if(Et(o,e,r,n),t.length===1&&t[0].type==="BlockLiteral"){let d=`(s) => processN(s, [${t[0].body.map(L).join(", ")}])`;return`const ${o} = ${d};
|
|
19
|
+
registry.set(${JSON.stringify(e)}, ${o});`}if(t.length===0)return`const ${o} = stack.pop();
|
|
20
|
+
registry.set(${JSON.stringify(e)}, ${o});`;let l=t.map(L);return`${Xe(`await processN(stack, [${l.join(", ")}]);`,Ge(t))}
|
|
21
|
+
const ${o} = stack.pop();
|
|
22
|
+
registry.set(${JSON.stringify(e)}, ${o});`}function dr(e,t,r,n){if(G)throw new v("::name value-definitions are not allowed in sandbox mode",r,n,"OP_NOT_ALLOWED");let o=Ie(e);if(Et(o,e,r,n),t.length>0){let l=t.map(L);return`${Xe(`await processN(stack, [${l.join(", ")}]);`,Ge(t))}
|
|
23
|
+
const ${o} = stack.pop();`}return`const ${o} = stack.pop();`}function yr(e){let t=e.path;return t.endsWith(".jth")&&(t=t.slice(0,-4)+".mjs"),Te&&(t.startsWith("./")||t.startsWith("../"))&&(t=Te(t)),e.bindings&&e.bindings.length>0?`import { ${e.bindings.map(n=>{let o=Ie(n);return o!==n?`${JSON.stringify(n)} as ${o}`:n}).join(", ")} } from ${JSON.stringify(t)};`:`import ${JSON.stringify(t)};`}function vr(e){return!e.names||e.names.length===0?"":`export { ${e.names.map(r=>{let n=Ie(r);return n!==r?`${n} as ${JSON.stringify(r)}`:r}).join(", ")} };`}function ke(e,t={}){let r=xe(e),n=Re(r);return ze(n,t)}async function Ze(e,t={}){let{registry:r=g,stack:n=new k,timeoutMs:o=0,captureLog:l=!1,forbidInlineJS:s=!1}=t,p=ke(e,{preamble:!1,forbidInlineJS:s}),d=new Function("stack","processN","registry",`return (async () => {
|
|
24
|
+
${p}
|
|
25
|
+
})();`),E=[],O=b=>{E.push(b)},A=n._sink;l&&(n._sink=O);let _;try{_=l?vt(O,()=>d(n,D,r)):d(n,D,r)}catch(b){throw l&&(n._sink=A),b}if(l){let b=()=>{n._sink=A};_.then(b,b)}o>0?await Promise.race([_,new Promise((b,q)=>setTimeout(()=>q(new Error(`Evaluation timed out after ${o}ms`)),o))]):await _;let R=n.toArray();return{stack:n,value:R.length>0?R[R.length-1]:void 0,output:E.join(`
|
|
26
|
+
`)}}var gr={noop:["Do nothing."],"\u2205":["Do nothing (alias of noop)."],clear:["Remove every item from the stack.","variadic"],"...":["Spread an array onto the stack as individual items."],spread:["Spread an array onto the stack as individual items (alias of ...)."],drop:["Remove the top item."],keepN:["Keep only the bottom N items, dropping the rest. Written keepN(N); N is taken from the stack.",1],retrieve:["Replace the stack with the single item I positions below the top (0 = top). Written retrieve(I).",1],dig:["Pull the Nth item from the top up to the top. Written dig(N).",1],bury:["Move the top item N positions down. Written bury(N).",1],dupe:["Duplicate the top item.",1],dup:["Duplicate the top item (alias of dupe).",1],copy:["Duplicate the entire stack.","variadic"],swap:["Swap the top two items.",2],reverse:["Reverse the whole stack.","variadic"],count:["Push the current stack depth.",0],depth:["Push the current stack depth (alias of count).",0],collect:["Collect every stack item into a single array."],peek:["Print the top item to the console without consuming it.",1],"peek-all":["Print every stack item to the console without consuming them.","variadic"],apply:["Pop a block and execute it against the stack."],exec:["Pop a block and execute it against the stack (alias of apply)."],over:["Copy the second item to the top."],rot:["Rotate the third item to the top."],"+":["Add two numbers."],"-":["Subtract the top number from the one below it."],"*":["Multiply two numbers."],"\u22C5":["Multiply two numbers (alias of *)."],"/":["Divide the lower number by the top number."],"\xF7":["Divide the lower number by the top number (alias of /)."],"**":["Raise the lower number to the power of the top number."],"%":["Modulo (result takes the sign of the divisor)."],"%%":["Remainder (result takes the sign of the dividend)."],"++":["Increment by one."],"--":["Decrement by one."],\u03A3:["Sum every stack item."],\u03A0:["Multiply every stack item together."],abs:["Absolute value."],"|\u{1D465}|":["Absolute value (alias of abs)."],"\u221A":["Square root (alias of sqrt)."],sqrt:["Square root."],floor:["Round down to an integer."],ceil:["Round up to an integer."],round:["Round to the nearest integer."],trunc:["Drop the fractional part."],log:["Natural logarithm."],min:["Smallest of every stack item."],max:["Largest of every stack item."],plus:["Add two numbers (alias of +)."],minus:["Subtract the top number from the one below it (alias of -)."],mul:["Multiply two numbers (alias of *)."],div:["Divide the lower number by the top number (alias of /)."],mod:["Modulo (alias of %)."],pow:["Exponentiation (alias of **)."],"=":["Strict equality."],"==":["Loose equality."],"<":["True if the lower item is less than the top item."],"<=":["True if the lower item is less than or equal to the top item."],">":["True if the lower item is greater than the top item."],">=":["True if the lower item is greater than or equal to the top item."],"<=>":["Three-way comparison: -1, 0 or 1."],"eq?":["Strict equality (alias of =)."],"ne?":["Not equal (alias of !=)."],"!=":["Not equal."],"lt?":["Less than (alias of <)."],"le?":["Less than or equal (alias of <=)."],"gt?":["Greater than (alias of >)."],"ge?":["Greater than or equal (alias of >=)."],"&&":["Logical AND."],"||":["Logical OR."],xor:["Exclusive OR."],nand:["Logical NOT AND."],nor:["Logical NOT OR."],"~~":["Logical NOT."],not:["Logical NOT (alias of ~~)."],if:["Conditional: run a block when the condition is truthy (optionally with an else block).","varies"],elseif:["Chain another conditional onto a preceding if.","varies"],else:["Default branch of a conditional chain.","varies"],when:["Pop a condition; keep the value below it only if the condition is truthy.",2],"drop-when":["Pop a condition; drop the value below it if the condition is truthy.",2],"keep-if":["Keep the value if the condition is truthy."],"drop-if":["Drop the value if the condition is truthy."],times:["Run a block N times.","varies"],while:["Run a body block while a condition block yields truthy.","varies"],until:["Run a body block until a condition block yields truthy.","varies"],break:["Exit the current loop.",0],try:["Run a block; on error push the Error instead of propagating.","varies"],throw:["Throw the top item as an error."],"error?":["True if the top item is an Error."],len:["Length of a string or array."],upper:["Uppercase a string."],lower:["Lowercase a string."],trim:["Trim surrounding whitespace."],strcat:["Concatenate two strings."],strseq:["Concatenate two strings in reverse order."],startsWith:["True if the string starts with the given prefix."],endsWith:["True if the string ends with the given suffix."],indexOf:["Index of a substring (or -1)."],"starts?":["True if the string starts with the given prefix (alias of startsWith)."],"ends?":["True if the string ends with the given suffix (alias of endsWith)."],"index-of":["Index of a substring (alias of indexOf)."],typeof:["Push the type name of the top item."],"number?":["True if the top item is a number."],"string?":["True if the top item is a string."],"array?":["True if the top item is an array."],"nil?":["True if the top item is null or undefined."],"function?":["True if the top item is a function or block."],"empty?":["True if the string or array is empty."],"contains?":["True if the array or string contains the element."],"into-json":["Stringify a value to JSON."],"from-json":["Parse a JSON string."],"into-lines":["Join an array of strings with newlines."],"from-lines":["Split a string on newlines into an array."],"to-json":["Parse a JSON string (legacy alias of from-json)."],"to-lines":["Split a string on newlines (legacy alias of from-lines)."],push:["Append an item to an array."],pop:["Remove the last element of an array; push the array and the element."],shift:["Remove the first element of an array; push the array and the element."],unshift:["Prepend an item to an array."],suppose:["Add an item to an array or Set."],flatten:["Flatten nested arrays among all stack items into a flat sequence of items."],map:["Apply a block to each element of an array, collecting the results.","varies"],filter:["Keep the elements of an array for which a block yields truthy.","varies"],reduce:["Fold an array with a block and an initial value.","varies"],fold:["Fold an array with a block and an initial value (alias of reduce).","varies"],bend:["Unfold an array from a seed, a predicate block and a step block.","varies"],keys:["Keys of an object."],values:["Values of an object."],entries:["[key, value] pairs of an object."],merge:["Merge two objects."],record:["Build an object from stack items taken as value/key pairs."],each:["Apply a block to each stack item.","varies"],fanout:["Run a value through several blocks, pushing every result.","varies"],zip:["Pair up the elements of two arrays."],compose:["Combine two blocks into one pipeline block."],_:["Await the promise on top of the stack and push its resolved value.",1],__:["Await every promise on the stack (Promise.all).","variadic"],$:["Execute a block (legacy alias of apply).","varies"],$$:["Execute a block and spread its result.","varies"],"<<-":["Rewind: move every stack item back into the processing queue.","varies"],"->>":["Skip: push every remaining queue item as a value instead of running it.","varies"],next:["Advance an iterator and push its next value."],iter:["Create an iterator from an iterable."],"..":["Exhaust an iterator into an array."],fibonacci:["Fibonacci step: given a b, push b a a+b."],x\u0304:["Arithmetic mean of the stack (alias of mean)."],mean:["Arithmetic mean of every stack item."],median:["Median of every stack item."],mode:["Most frequent stack item."],modes:["Array of all most-frequent stack items."]},Qe={arithmetic:{syntax:"N+ N- N* N/ N% N**",arity:1,description:"Number-prefixed arithmetic: `N op x` applies the operator with N as the left operand (3+ adds 3). Suffix n for BigInt (3n+)."},log:{syntax:"Nlog",arity:1,description:"Logarithm of x in base N (10log)."},hyperop:{syntax:"*** **** ...",arity:2,description:"Hyperoperations: *** is tetration, **** pentation, and so on."}};function nt(e){return e===null?"null":Array.isArray(e)?"array":typeof e}var Ot=a(0)(()=>[]),wr=e=>{e.clear()},Nt=a(1)(e=>Array.isArray(e)?e:[e]),Er=a(1)(()=>[]),Or=e=>t=>{let r=t.toArray();t.clear(),t.push(...r.slice(0,e))};var Nr=e=>{let t=e.toArray();e.push(...t)},jt=e=>{e.dup()},Sr=(e=0)=>t=>{let r=t.toArray(),n=r[r.length-1-e];t.clear(),t.push(n)},br=(e=1)=>t=>{let r=t.toArray();if(r.length<2)return;let n=e<0?~e:r.length+~e;if(n>=0&&n<r.length){let[o]=r.splice(n,1);r.push(o),t.clear(),t.push(...r)}},Ar=(e=1)=>t=>{let r=t.toArray();if(r.length<2)return;let n=e<0?~e:r.length+~e;if(n>=0&&n<r.length){let o=r.pop();r.splice(n,0,o),t.clear(),t.push(...r)}};var xr=e=>{e.swap()};var Rr=e=>{let t=e.toArray().reverse();e.clear(),e.push(...t)},Bt=e=>{e.push(e.length)},Tr=N((...e)=>[e]),Ir=e=>{Be(e,e.peek())},kr=e=>{Be(e,...e.toArray())};var Ft=e=>{let t=e.pop();if(typeof t!="function")throw new v(`apply: top of stack is not a function/block (got ${nt(t)})`,void 0,void 0,"TYPE_ERROR");return t(e)},Lr=Ft,_r=jt,Mr=Bt,$r=a(2)((e,t)=>[e,t,e]),Pr=a(3)((e,t,r)=>[t,r,e]),St=a(2)((e,t)=>[e+t]),bt=a(2)((e,t)=>[e-t]),et=a(2)((e,t)=>[e*t]),tt=a(2)((e,t)=>[e/t]),Ut=a(2)((e,t)=>[e**t]),At=a(2)((e,t)=>[(e%t+t)%t]),Dr=a(2)((e,t)=>[e%t]),Jr=a(1)(e=>[e+1]),Cr=a(1)(e=>[e-1]),jr=N((...e)=>[e.reduce((t,r)=>t+r,0)]),Br=N((...e)=>[e.reduce((t,r)=>t*r,1)]),xt=a(1)(e=>[Math.abs(e)]),Rt=a(1)(e=>[Math.sqrt(e)]),Fr=a(1)(e=>[Math.floor(e)]),Ur=a(1)(e=>[Math.ceil(e)]),Wr=a(1)(e=>[Math.round(e)]),qr=a(1)(e=>[Math.trunc(e)]),Vr=a(1)(e=>[Math.log(e)]),Hr=N((...e)=>[Math.min(...e)]),Yr=N((...e)=>[Math.max(...e)]),Kr=et,Gr=tt,Xr=Ut,Tt=a(2)((e,t)=>[e===t]),zr=a(2)((e,t)=>[e==t]),It=a(2)((e,t)=>[e!==t]),kt=a(2)((e,t)=>[e<t]),Lt=a(2)((e,t)=>[e<=t]),_t=a(2)((e,t)=>[e>t]),Mt=a(2)((e,t)=>[e>=t]),Zr=a(2)((e,t)=>[e===t?0:e>t?-1:1]),Qr=a(2)((e,t)=>[e&&t]),en=a(2)((e,t)=>[e||t]),tn=a(2)((e,t)=>[!!(e^t)]),rn=a(2)((e,t)=>[!(e&&t)]),nn=a(2)((e,t)=>[!(e||t)]),$t=a(1)(e=>[!e]);function ot(e){return e._condStack||(e._condStack=[]),e._condStack}var on=e=>{let t=e.pop(),r=e.pop();if(typeof e.peek()=="function"){let o=e.pop(),l=t?r:o;typeof l=="function"&&l(e)}else{let o=ot(e);t?(o.push(!0),typeof r=="function"&&r(e)):o.push(!1)}},an=e=>{let t=e.pop(),r=e.pop(),n=ot(e);n.length===0||n[n.length-1]||t&&(n[n.length-1]=!0,typeof r=="function"&&r(e))},sn=e=>{let t=e.pop(),r=ot(e);if(r.length===0)return;r.pop()||typeof t=="function"&&t(e)},ln=e=>{e.pop()||e.pop()},un=e=>{e.pop()&&e.pop()},pn=a(2)((e,t)=>t?[e]:[]),cn=a(2)((e,t)=>t?[]:[e]),fn=e=>{let t=e.pop(),r=e.pop(),n,o;typeof t=="number"&&typeof r=="function"?(n=t,o=r):typeof t=="function"&&typeof r=="number"?(n=r,o=t):(n=t,o=r);for(let l=0;l<n;l++)typeof o=="function"&&o(e)},it=class extends Error{constructor(){super("break"),this.name="BreakSignal"}},hn=e=>{throw new it},X=1e6,mn=e=>{let t=e.pop(),r=e.pop();for(let n=0;n<X&&(typeof r=="function"&&r(e),!!e.pop());n++)try{typeof t=="function"&&t(e)}catch(l){if(l instanceof it)break;throw l}},dn=e=>{let t=e.pop(),r=e.pop();for(let n=0;n<X&&(typeof r=="function"&&r(e),!e.pop());n++)try{typeof t=="function"&&t(e)}catch(l){if(l instanceof it)break;throw l}},yn=e=>{let t=e.pop(),r=e.length;try{typeof t=="function"&&t(e)}catch(n){let o=e.length-r;o>0&&e.popN(o),e.push(n instanceof Error?n:new Error(String(n)))}},vn=a(1)(e=>{throw new v(String(e),void 0,void 0,"USER_THROW")}),gn=a(1)(e=>[e instanceof Error]),wn=a(1)(e=>[e.length]);var Pt=a(2)((e,t)=>[e.startsWith(t)]),Dt=a(2)((e,t)=>[e.endsWith(t)]),En=a(1)(e=>[e.toUpperCase()]),On=a(1)(e=>[e.toLowerCase()]),Nn=a(1)(e=>[e.trim()]);var Jt=a(2)((e,t)=>[e.indexOf(t)]),Sn=a(2)((e,t)=>[`${e}${t}`]),bn=a(2)((e,t)=>[`${t}${e}`]);var An=a(1)(e=>[typeof e]),xn=a(1)(e=>[typeof e=="number"]),Rn=a(1)(e=>[typeof e=="string"]),Tn=a(1)(e=>[Array.isArray(e)]),In=a(1)(e=>[e==null]),kn=a(1)(e=>[typeof e=="function"]),Ln=a(1)(e=>e==null?[!0]:typeof e=="string"||Array.isArray(e)?[e.length===0]:typeof e=="object"?[Object.keys(e).length===0]:[!1]),_n=a(2)((e,t)=>Array.isArray(e)?[e.includes(t)]:typeof e=="string"?[e.includes(t)]:[!1]),Mn=a(1)(e=>[JSON.stringify(e)]),Wt=a(1)(e=>[JSON.parse(e)]),$n=Wt,Pn=a(1)(e=>[Array.isArray(e)?e.join(`
|
|
27
|
+
`):String(e)]),qt=a(1)(e=>[String(e).split(`
|
|
28
|
+
`)]),Dn=qt;function at(e,t){if(typeof e!="function")throw new v(`${t}: expected a block/function on top of the stack (got ${nt(e)})`,void 0,void 0,"TYPE_ERROR")}function st(e,t){if(!Array.isArray(e))throw new v(`${t}: expected an array (got ${nt(e)})`,void 0,void 0,"TYPE_ERROR")}var Jn=a(2)((e,t)=>Array.isArray(e)?(e.push(t),[e]):[e,t]),Cn=a(1)(e=>{if(Array.isArray(e)){let t=e.pop();return[e,t]}return[e]}),jn=a(1)(e=>{if(Array.isArray(e)){let t=e.shift();return[e,t]}return[e]}),Bn=a(2)((e,t)=>Array.isArray(e)?(e.unshift(t),[e]):[e,t]),Fn=a(2)((e,t)=>Array.isArray(e)?(e.push(t),[e]):e instanceof Set?(e.add(t),[e]):e instanceof Map?(e.set(t,t),[e]):[e,t]),Un=N((...e)=>{let t=[],r=n=>{for(let o of n)Array.isArray(o)?r(o):t.push(o)};return r(e),t}),M=(e,t,...r)=>{let n=e.child();return n.push(...r),typeof t!="function"?n:D(n,[t])},z=e=>!!e&&typeof e.then=="function",Wn=e=>{let t=e.pop(),r=e.pop();at(t,"map"),st(r,"map");let n=[];for(let o=0;o<r.length;o++){let l=M(e,t,r[o]);if(z(l))return(async()=>{for(n.push((await l).pop()),o++;o<r.length;o++)n.push((await M(e,t,r[o])).pop());e.push(n)})();n.push(l.pop())}e.push(n)},qn=e=>{let t=e.pop(),r=e.pop();at(t,"filter"),st(r,"filter");let n=[];for(let o=0;o<r.length;o++){let l=M(e,t,r[o]);if(z(l))return(async()=>{for((await l).pop()&&n.push(r[o]),o++;o<r.length;o++)(await M(e,t,r[o])).pop()&&n.push(r[o]);e.push(n)})();l.pop()&&n.push(r[o])}e.push(n)},Vt=e=>{let t=e.pop(),r=e.pop(),n=e.pop();at(t,"reduce"),st(n,"reduce");let o=r;for(let l=0;l<n.length;l++){let s=M(e,t,o,n[l]);if(z(s))return(async()=>{for(o=(await s).pop(),l++;l<n.length;l++)o=(await M(e,t,o,n[l])).pop();e.push(o)})();o=s.pop()}e.push(o)},Vn=Vt,Hn=e=>{let t=e.pop(),r=e.pop(),n=e.pop(),o=[],l=()=>new v(`bend exceeded ${X} iterations (non-terminating predicate?)`,void 0,void 0,"ITERATION_LIMIT"),s=E=>{let O=E.pop(),A=E.pop();o.push(A),n=O},p=async(E,O,A)=>{for(;;){if(O==="predicate"){if(!(await E).pop())break;O="step",E=Promise.resolve(M(e,t,n));continue}if(s(await E),A++>=X)throw l();O="predicate",E=Promise.resolve(M(e,r,n))}e.push(o)},d=0;for(;;){if(d++>=X)throw l();let E=M(e,r,n);if(z(E))return p(E,"predicate",d);if(!E.pop())break;let O=M(e,t,n);if(z(O))return p(O,"step",d);s(O)}e.push(o)};var Yn=a(1)(e=>[Object.keys(e)]),Kn=a(1)(e=>[Object.values(e)]),Gn=a(1)(e=>[Object.entries(e)]),Xn=a(2)((e,t)=>[{...e,...t}]);var zn=N((...e)=>{if(e.length%2!==0)throw new v(`record requires even number of args (got ${e.length})`,void 0,void 0,"RECORD_ODD_ARGS");let t={};for(let r=0;r<e.length;r+=2)t[e[r+1]]=e[r];return[t]}),Zn=a(2)((e,t)=>{let r=Math.min(e.length,t.length);return[Array.from({length:r},(n,o)=>[e[o],t[o]])]}),Qn=a(2)((e,t)=>[r=>{e(r),t(r)}]),eo=e=>{let t=e.pop(),r=e.toArray();e.clear();for(let n of r){let o=e.child();o.push(n),typeof t=="function"&&t(o),e.push(...o.toArray())}},to=e=>{let t=e.toArray();e.clear();let r=[],n=t.length-1;for(;n>=0&&typeof t[n]=="function";)r.unshift(t[n]),n--;let o=n>=0?t[n]:void 0;for(let l=0;l<n;l++)e.push(t[l]);for(let l of r){let s=e.child();s.push(o),l(s),e.push(...s.toArray())}},ro=e=>{let t=e.pop();if(t&&typeof t.then=="function")return t.then(r=>{e.push(r)});e.push(t)},no=async e=>{let t=e.toArray();e.clear();let r=await Promise.all(t);e.push(...r)},oo=e=>{let t=e.pop();if(typeof t=="function"){let r=t(e);if(r&&typeof r.then=="function")return r}},io=e=>{let t=e.pop();if(Array.isArray(t))return D(e,t)},ao=a(1)(e=>{if(!e?.next)return[e];let{done:t,value:r}=e.next();return t?[e]:[e,r]});var so=a(1)(e=>e&&typeof e[Symbol.iterator]=="function"?[e[Symbol.iterator]()]:[e]),lo=a(1)(e=>e&&e[Symbol.iterator]?[[...e]]:[e]),uo=a(2)((e,t)=>[t,e,t+e]),Ct=N((...e)=>[e.reduce((t,r)=>t+r,0)/e.length]),po=N((...e)=>{let t=[...e].sort((n,o)=>n-o),r=Math.floor(t.length/2);return t.length%2?[t[r]]:[(t[r-1]+t[r])/2]}),co=N((...e)=>{let t=new Map,r=0;for(let n of e){let o=(t.get(n)||0)+1;t.set(n,o),o>r&&(r=o)}return[[...t].find(([,n])=>n===r)[0]]}),fo=N((...e)=>{let t=new Map,r=0;for(let n of e){let o=(t.get(n)||0)+1;t.set(n,o),o>r&&(r=o)}return[[...t].filter(([,n])=>n===r).map(([n])=>n)]}),wa=N((...e)=>{let t=e.reduce((r,n)=>r+n,0)/e.length;return[e.reduce((r,n)=>r+(n-t)**2,0)/e.length]}),Ea=N((...e)=>{let t=e.reduce((r,n)=>r+n,0)/e.length;return[e.reduce((r,n)=>r+(n-t)**2,0)/(e.length-1)]}),Oa=N((...e)=>{let t=e.reduce((r,n)=>r+n,0)/e.length;return[Math.sqrt(e.reduce((r,n)=>r+(n-t)**2,0)/e.length)]}),Na=N((...e)=>{let t=e.reduce((r,n)=>r+n,0)/e.length;return[Math.sqrt(e.reduce((r,n)=>r+(n-t)**2,0)/(e.length-1))]});function ho(){g.setDynamic(/^([+-]?(?:\d*\.)?\d+)(n?)([+\-*/÷⋅%]|\*{2}|%{2})$/,(e,t)=>{let[,r,n,o]=t.exec(e),l=n?BigInt(r):Number(r);switch(o){case"+":return a(1)(s=>[l+s]);case"-":return a(1)(s=>[l-s]);case"*":case"\u22C5":return a(1)(s=>[l*s]);case"/":case"\xF7":return a(1)(s=>[l/s]);case"%":return a(1)(s=>[(l%s+s)%s]);case"**":return a(1)(s=>[l**s]);case"%%":return a(1)(s=>[l%s])}},Qe.arithmetic),g.setDynamic(/^([+-]?(?:\d*\.)?\d+)log$/,(e,t)=>{let[,r]=t.exec(e);return a(1)(n=>[Math.log(n)/Math.log(Number(r))])},Qe.log)}var rt=(e,t,r)=>{if(e<0n||t<0n||r<0n)throw new v("Non-negative integers only",void 0,void 0,"HYPEROP_DOMAIN");if(e===0n)return t+1n;if(e===1n)return t+r;if(e===2n)return t*r;if(e===3n)return t**r;if(t===0n)return r%2n===0n?1n:0n;if(t===1n||r===0n)return 1n;if(r===1n)return t;if(t===2n&&r===2n)return 4n;let n=t;for(let o=1n;o<r;o++)n=rt(e-1n,t,n);return n},mo=e=>(t,r=0n)=>{if([e,t,r].every(n=>typeof n=="bigint"))return rt(e,t,r);if([e,t,r].every(n=>Number.isInteger(n)))try{return Number(rt(BigInt(e),BigInt(t),BigInt(r)))}catch{return 1/0}throw new v("All arguments must be integers or BigInts",void 0,void 0,"HYPEROP_DOMAIN")};function yo(){g.setDynamic(/^\*{3,}$/,e=>{let t=mo(e.length+1);return a(2)((r,n)=>[t(r,n)])},Qe.hyperop)}var Ht=new Set;function Yt(){return[...Ht]}function i(e,t){Ht.add(e);let r=gr[e];g.set(e,t,r?{description:r[0],arity:r[1]}:void 0)}function Le(e){return t=>e(t.pop())(t)}function vo(){i("noop",Ot),i("\u2205",Ot),i("clear",wr),i("...",Nt),i("spread",Nt),i("drop",Er),i("keepN",Le(Or)),i("retrieve",Le(Sr)),i("dig",Le(br)),i("bury",Le(Ar)),i("dupe",jt),i("dup",_r),i("copy",Nr),i("swap",xr),i("reverse",Rr),i("count",Bt),i("depth",Mr),i("collect",Tr),i("peek",Ir),i("peek-all",kr),i("apply",Ft),i("exec",Lr),i("over",$r),i("rot",Pr),i("+",St),i("-",bt),i("*",et),i("\u22C5",et),i("/",tt),i("\xF7",tt),i("**",Ut),i("%",At),i("%%",Dr),i("++",Jr),i("--",Cr),i("\u03A3",jr),i("\u03A0",Br),i("abs",xt),i("|\u{1D465}|",xt),i("\u221A",Rt),i("sqrt",Rt),i("floor",Fr),i("ceil",Ur),i("round",Wr),i("trunc",qr),i("log",Vr),i("min",Hr),i("max",Yr),i("plus",St),i("minus",bt),i("mul",Kr),i("div",Gr),i("mod",At),i("pow",Xr),i("=",Tt),i("==",zr),i("<",kt),i("<=",Lt),i(">",_t),i(">=",Mt),i("<=>",Zr),i("eq?",Tt),i("ne?",It),i("!=",It),i("lt?",kt),i("le?",Lt),i("gt?",_t),i("ge?",Mt),i("&&",Qr),i("||",en),i("xor",tn),i("nand",rn),i("nor",nn),i("~~",$t),i("not",$t),i("if",on),i("elseif",an),i("else",sn),i("when",ln),i("drop-when",un),i("keep-if",pn),i("drop-if",cn),i("times",fn),i("while",mn),i("until",dn),i("break",hn),i("try",yn),i("throw",vn),i("error?",gn),i("len",wn),i("upper",En),i("lower",On),i("trim",Nn),i("strcat",Sn),i("strseq",bn),i("startsWith",Pt),i("endsWith",Dt),i("indexOf",Jt),i("starts?",Pt),i("ends?",Dt),i("index-of",Jt),i("typeof",An),i("number?",xn),i("string?",Rn),i("array?",Tn),i("nil?",In),i("function?",kn),i("empty?",Ln),i("contains?",_n),i("into-json",Mn),i("from-json",$n),i("into-lines",Pn),i("from-lines",Dn),i("to-json",Wt),i("to-lines",qt),i("push",Jn),i("pop",Cn),i("shift",jn),i("unshift",Bn),i("suppose",Fn),i("flatten",Un),i("map",Wn),i("filter",qn),i("reduce",Vt),i("fold",Vn),i("bend",Hn),i("keys",Yn),i("values",Kn),i("entries",Gn),i("merge",Xn),i("record",zn),i("each",eo),i("fanout",to),i("zip",Zn),i("compose",Qn),i("_",ro),i("__",no),i("$",oo),i("$$",io),i("<<-",C(()=>{},{rewind:-1})),i("->>",C(()=>{},{skip:-1})),i("next",ao),i("iter",so),i("..",lo),i("fibonacci",uo),i("x\u0304",Ct),i("mean",Ct),i("median",po),i("mode",co),i("modes",fo),ho(),yo()}vo();var go=new Set(["peek","peek-all"]);async function Kt(e,t={}){let{values:r={},operators:n={},stack:o=[],timeout:l=5e3,sandbox:s=!1,captureOutput:p=!0}=t,d=lt(s),E=new Se({allowlist:d});for(let[R,b]of Object.entries(r))E.set(R,a(0)(()=>[b]));for(let[R,b]of Object.entries(n))E.set(R,b);let O=new k;o.length>0&&O.push(...o);let{value:A,output:_}=await Ze(e,{stack:O,registry:E,timeoutMs:l,captureLog:p,forbidInlineJS:s!==!1});return{value:A,stack:O.toArray(),output:_}}function lt(e){if(e===!1)return null;if(e===!0)return new Set;if(e==="restricted"){let t=new Set(g.names()),r=new Set;for(let n of Yt())t.has(n)&&!go.has(n)&&r.add(n);return r}if(Array.isArray(e))return new Set(e);throw new v(`Invalid sandbox option: ${wo(e)}. Expected false, true, "restricted", or an array of operator names.`,void 0,void 0,"INVALID_SANDBOX")}function wo(e){try{return typeof e=="string"?JSON.stringify(e):String(JSON.stringify(e)??e)}catch{return typeof e}}Ne();export{Se as ScopedRegistry,k as Stack,lt as buildAllowlist,Kt as evalJth,xe as lex,Re as parse,D as processN,g as registry,ke as transform};
|