@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,445 @@
|
|
|
1
|
+
// Canvas diff: what changed between two canvas docs (the .mallory.json shape),
|
|
2
|
+
// pane by pane. Pure, no DOM: the History panel, the "Compare with my copy"
|
|
3
|
+
// review of a shared canvas, `mallory diff` and the WebMCP version tools all use
|
|
4
|
+
// it.
|
|
5
|
+
//
|
|
6
|
+
// diffCanvases(before, after) ->
|
|
7
|
+
// { same, summary: { added, deleted, changed, moved, same },
|
|
8
|
+
// canvas: [{ field, before, after }], // name, tests, any other canvas-level field
|
|
9
|
+
// groups: [{ id, name, status: "added" | "deleted" | "changed", changes: [{ field, before, after }] }],
|
|
10
|
+
// // groups (frames, src/model/groups.js), by id; panes as names
|
|
11
|
+
// panes: [{ id, beforeId?, type, name, status, matchedBy?, moved?, changes: [...] }] }
|
|
12
|
+
//
|
|
13
|
+
// Panes are matched by id; a pane deleted and made again (a new id with the
|
|
14
|
+
// same type and name) is matched by name. Each pane is "added", "deleted",
|
|
15
|
+
// "moved" (only its rect changed), "changed" or "same". A change is one of
|
|
16
|
+
// { field: "code" | "text", kind: "lines", lines, added, removed } (a line diff)
|
|
17
|
+
// { field: "inputs", kind: "wires", wires: [{ op: "add" | "remove" | "rename" | "port", ... }] }
|
|
18
|
+
// (a wire is its source and the output it reads, if any;
|
|
19
|
+
// "port": its type, convert or description changed;
|
|
20
|
+
// "route": how it is drawn changed: before/after are the saved route, undefined for the default curve)
|
|
21
|
+
// { field: "outputs", kind: "outputs", outputs: [{ op: "add" | "remove" | "change", name, before?, after? }] }
|
|
22
|
+
// { field: "type" | "name", kind: "type" | "name", before, after }
|
|
23
|
+
// { field: "graph", kind: "graph", diff } (a subgraph's inner canvas, diffed the same way)
|
|
24
|
+
// { field: "channels", kind: "channels", channels: [{ op: "add" | "remove", what: "receives" | "sends", channel, consume?, scope? }] }
|
|
25
|
+
// (named event channels, its receive setting, what its code sends on)
|
|
26
|
+
// { field: "id", kind: "id", before, after } (matched by name)
|
|
27
|
+
// { field, kind: "setting", before, after } (every other field: view, autorun, each, widget, …)
|
|
28
|
+
// { field: "rect", kind: "geometry", before, after }
|
|
29
|
+
|
|
30
|
+
import { describeOperators } from "./wire-ops.js";
|
|
31
|
+
import { cleanRoute, styleOf, clearanceOf, anchorOf, DEFAULT_CLEARANCE } from "./wire-route.js";
|
|
32
|
+
import { lockChanges, lockEntryText } from "./import-lock.js";
|
|
33
|
+
import { channelChanges, channelFacts, channelText } from "./channels.js";
|
|
34
|
+
|
|
35
|
+
/** Fields that are the pane's place, not its content. */
|
|
36
|
+
const GEOMETRY = new Set(["rect", "width"]);
|
|
37
|
+
/** Fields diffed line by line. */
|
|
38
|
+
const LINES = new Set(["code", "text"]);
|
|
39
|
+
/** Canvas-level fields that aren't content: identity, trust, the view, bookkeeping. */
|
|
40
|
+
const CANVAS_IGNORED = new Set(["format", "version", "id", "trusted", "viewport", "panes", "lineage", "example", "groups", "workspaces", "activeWorkspace"]);
|
|
41
|
+
|
|
42
|
+
/** JSON with sorted keys, so equal values compare equal whatever order their keys were set in. */
|
|
43
|
+
export function canonical(value) {
|
|
44
|
+
if (value === undefined) return "null";
|
|
45
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
46
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
47
|
+
return `{${Object.keys(value)
|
|
48
|
+
.filter((k) => value[k] !== undefined)
|
|
49
|
+
.sort()
|
|
50
|
+
.map((k) => `${JSON.stringify(k)}:${canonical(value[k])}`)
|
|
51
|
+
.join(",")}}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const equal = (a, b) => canonical(a) === canonical(b);
|
|
55
|
+
const panesOf = (doc) => (Array.isArray(doc?.panes) ? doc.panes : []);
|
|
56
|
+
const innerPanes = (pane) => (Array.isArray(pane?.graph?.panes) ? pane.graph.panes : []);
|
|
57
|
+
|
|
58
|
+
/** A pane for people: `eval "total"`, or a text pane's first words. */
|
|
59
|
+
export function paneLabel(pane) {
|
|
60
|
+
if (!pane) return "pane";
|
|
61
|
+
if (pane.name) return `${pane.type} "${pane.name}"`;
|
|
62
|
+
const first = String(pane.text ?? pane.code ?? "").trim().split("\n")[0];
|
|
63
|
+
return first ? `${pane.type} "${first.length > 32 ? `${first.slice(0, 31)}…` : first}"` : `${pane.type} ${pane.id}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ── line diff ──────────────────────────────────────────────────────────────
|
|
67
|
+
|
|
68
|
+
/** Past this many cells the middle of a diff is shown as removed-then-added (no LCS). */
|
|
69
|
+
const MAX_CELLS = 4_000_000;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A line diff: `[{ op: " " | "-" | "+", text, a?, b? }]`, `a` and `b` the
|
|
73
|
+
* 1-based line numbers in the old and the new text. Deletions come before
|
|
74
|
+
* additions within a change.
|
|
75
|
+
*/
|
|
76
|
+
export function lineDiff(before = "", after = "") {
|
|
77
|
+
const A = String(before ?? "").split("\n");
|
|
78
|
+
const B = String(after ?? "").split("\n");
|
|
79
|
+
const ops = [];
|
|
80
|
+
let start = 0;
|
|
81
|
+
while (start < A.length && start < B.length && A[start] === B[start]) start++;
|
|
82
|
+
let endA = A.length;
|
|
83
|
+
let endB = B.length;
|
|
84
|
+
while (endA > start && endB > start && A[endA - 1] === B[endB - 1]) endA--, endB--;
|
|
85
|
+
for (let i = 0; i < start; i++) ops.push({ op: " ", text: A[i], a: i + 1, b: i + 1 });
|
|
86
|
+
const n = endA - start;
|
|
87
|
+
const m = endB - start;
|
|
88
|
+
if (n * m > MAX_CELLS) {
|
|
89
|
+
for (let i = start; i < endA; i++) ops.push({ op: "-", text: A[i], a: i + 1 });
|
|
90
|
+
for (let j = start; j < endB; j++) ops.push({ op: "+", text: B[j], b: j + 1 });
|
|
91
|
+
} else if (n || m) {
|
|
92
|
+
// L[i][j]: the longest common subsequence of A[start+i..] and B[start+j..].
|
|
93
|
+
const w = m + 1;
|
|
94
|
+
const L = new Uint32Array((n + 1) * w);
|
|
95
|
+
for (let i = n - 1; i >= 0; i--) {
|
|
96
|
+
for (let j = m - 1; j >= 0; j--) {
|
|
97
|
+
L[i * w + j] = A[start + i] === B[start + j] ? L[(i + 1) * w + j + 1] + 1 : Math.max(L[(i + 1) * w + j], L[i * w + j + 1]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
let i = 0;
|
|
101
|
+
let j = 0;
|
|
102
|
+
while (i < n || j < m) {
|
|
103
|
+
if (i < n && j < m && A[start + i] === B[start + j]) {
|
|
104
|
+
ops.push({ op: " ", text: A[start + i], a: start + i + 1, b: start + j + 1 });
|
|
105
|
+
i++, j++;
|
|
106
|
+
} else if (j >= m || (i < n && L[(i + 1) * w + j] >= L[i * w + j + 1])) {
|
|
107
|
+
ops.push({ op: "-", text: A[start + i], a: start + i + 1 });
|
|
108
|
+
i++;
|
|
109
|
+
} else {
|
|
110
|
+
ops.push({ op: "+", text: B[start + j], b: start + j + 1 });
|
|
111
|
+
j++;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (let i = endA, j = endB; i < A.length; i++, j++) ops.push({ op: " ", text: A[i], a: i + 1, b: j + 1 });
|
|
116
|
+
return ops;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A line diff as unified-diff lines (`@@ -1,3 +1,4 @@`, then ` `, `-` and `+` lines) with `context` lines around each change. */
|
|
120
|
+
export function unifiedDiff(ops, { context = 3 } = {}) {
|
|
121
|
+
const changed = ops.map((o, i) => (o.op === " " ? -1 : i)).filter((i) => i >= 0);
|
|
122
|
+
if (!changed.length) return [];
|
|
123
|
+
// Group changes whose context overlaps into hunks.
|
|
124
|
+
const hunks = [];
|
|
125
|
+
for (const i of changed) {
|
|
126
|
+
const last = hunks[hunks.length - 1];
|
|
127
|
+
if (last && i - last.end <= context * 2 + 1) last.end = i;
|
|
128
|
+
else hunks.push({ start: i, end: i });
|
|
129
|
+
}
|
|
130
|
+
const out = [];
|
|
131
|
+
for (const { start, end } of hunks) {
|
|
132
|
+
const from = Math.max(0, start - context);
|
|
133
|
+
const to = Math.min(ops.length - 1, end + context);
|
|
134
|
+
const slice = ops.slice(from, to + 1);
|
|
135
|
+
const aLines = slice.filter((o) => o.op !== "+");
|
|
136
|
+
const bLines = slice.filter((o) => o.op !== "-");
|
|
137
|
+
// An empty side starts at the line before the hunk, as diff -u writes it.
|
|
138
|
+
const aStart = aLines[0]?.a ?? (ops.slice(0, from).filter((o) => o.op !== "+").pop()?.a ?? 0);
|
|
139
|
+
const bStart = bLines[0]?.b ?? (ops.slice(0, from).filter((o) => o.op !== "-").pop()?.b ?? 0);
|
|
140
|
+
out.push(`@@ -${aStart},${aLines.length} +${bStart},${bLines.length} @@`);
|
|
141
|
+
for (const o of slice) out.push(`${o.op}${o.text}`);
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A line diff as side-by-side rows: `[{ left?, right? }]`, each side
|
|
148
|
+
* `{ no, text, op }`. A run of removed lines faces the run of added lines
|
|
149
|
+
* that replaced it.
|
|
150
|
+
*/
|
|
151
|
+
export function sideBySide(ops) {
|
|
152
|
+
const rows = [];
|
|
153
|
+
let dels = [];
|
|
154
|
+
let adds = [];
|
|
155
|
+
const flush = () => {
|
|
156
|
+
for (let k = 0; k < Math.max(dels.length, adds.length); k++) {
|
|
157
|
+
rows.push({ left: dels[k] && { no: dels[k].a, text: dels[k].text, op: "-" }, right: adds[k] && { no: adds[k].b, text: adds[k].text, op: "+" } });
|
|
158
|
+
}
|
|
159
|
+
dels = [];
|
|
160
|
+
adds = [];
|
|
161
|
+
};
|
|
162
|
+
for (const o of ops) {
|
|
163
|
+
if (o.op === "-") dels.push(o);
|
|
164
|
+
else if (o.op === "+") adds.push(o);
|
|
165
|
+
else {
|
|
166
|
+
flush();
|
|
167
|
+
rows.push({ left: { no: o.a, text: o.text, op: " " }, right: { no: o.b, text: o.text, op: " " } });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
flush();
|
|
171
|
+
return rows;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ── canvases ───────────────────────────────────────────────────────────────
|
|
175
|
+
|
|
176
|
+
/** What changed between two canvas docs (see the top of this file). */
|
|
177
|
+
export function diffCanvases(before, after) {
|
|
178
|
+
const panes = diffPanes(panesOf(before), panesOf(after));
|
|
179
|
+
const canvas = canvasChanges(before ?? {}, after ?? {});
|
|
180
|
+
const summary = summarize(panes);
|
|
181
|
+
const groups = groupChanges(before ?? {}, after ?? {});
|
|
182
|
+
return { same: !canvas.length && !groups.length && panes.every((p) => p.status === "same"), summary, canvas, groups, panes };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** What changed in the groups (frames): matched by id; their panes named, as people know them. */
|
|
186
|
+
function groupChanges(a, b) {
|
|
187
|
+
const list = (doc) => (Array.isArray(doc.groups) ? doc.groups : []);
|
|
188
|
+
const names = new Map([...panesOf(a), ...panesOf(b)].map((p) => [p.id, p.name || p.id]));
|
|
189
|
+
const shown = (g) => ({ ...g, panes: (g.panes ?? []).map((id) => names.get(id) ?? id) });
|
|
190
|
+
const before = new Map(list(a).map((g) => [g.id, shown(g)]));
|
|
191
|
+
const after = new Map(list(b).map((g) => [g.id, shown(g)]));
|
|
192
|
+
const out = [];
|
|
193
|
+
for (const [id, g] of after) {
|
|
194
|
+
const was = before.get(id);
|
|
195
|
+
if (!was) out.push({ id, name: g.name ?? "", status: "added", changes: [], group: g });
|
|
196
|
+
else {
|
|
197
|
+
const changes = [...new Set([...Object.keys(was), ...Object.keys(g)])].filter((k) => k !== "id" && !equal(was[k], g[k])).sort().map((field) => ({ field, before: was[field], after: g[field] }));
|
|
198
|
+
if (changes.length) out.push({ id, name: g.name ?? "", status: "changed", changes, group: g });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (const [id, g] of before) if (!after.has(id)) out.push({ id, name: g.name ?? "", status: "deleted", changes: [], group: g });
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function canvasChanges(a, b) {
|
|
206
|
+
const keys = [...new Set([...Object.keys(a), ...Object.keys(b)])].filter((k) => !CANVAS_IGNORED.has(k)).sort((x, y) => (x === "name" ? -1 : y === "name" ? 1 : x.localeCompare(y)));
|
|
207
|
+
return keys.filter((k) => !equal(a[k], b[k])).flatMap((field) => (field === "imports" ? importChanges(a.imports, b.imports) : [{ field, before: a[field], after: b[field] }]));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The import lock (src/model/import-lock.js), one change per spec: "imports d3@7: 7.8.0 (esm.sh) → 7.9.0 (esm.sh)". */
|
|
211
|
+
function importChanges(before, after) {
|
|
212
|
+
return lockChanges(before ?? {}, after ?? {}).map((c) => ({ field: `imports ${c.key}`, before: c.before && lockEntryText(c.before), after: c.after && lockEntryText(c.after) }));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function summarize(panes) {
|
|
216
|
+
const summary = { added: 0, deleted: 0, changed: 0, moved: 0, same: 0 };
|
|
217
|
+
for (const p of panes) summary[p.status]++;
|
|
218
|
+
return summary;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Diff two lists of panes (a canvas's, or a subgraph's inner ones). */
|
|
222
|
+
export function diffPanes(before, after) {
|
|
223
|
+
const A = new Map(before.map((p) => [p.id, p]));
|
|
224
|
+
const B = new Map(after.map((p) => [p.id, p]));
|
|
225
|
+
// A pane deleted and made again: a new id, the same type and name.
|
|
226
|
+
const gone = new Map();
|
|
227
|
+
for (const p of before) {
|
|
228
|
+
if (B.has(p.id) || !p.name) continue;
|
|
229
|
+
const key = `${p.type}\0${p.name}`;
|
|
230
|
+
if (!gone.has(key)) gone.set(key, []);
|
|
231
|
+
gone.get(key).push(p);
|
|
232
|
+
}
|
|
233
|
+
const renamed = new Map(); // old id -> new id
|
|
234
|
+
const matchOf = new Map(); // new id -> the old pane it matches
|
|
235
|
+
for (const p of after) {
|
|
236
|
+
if (A.has(p.id)) {
|
|
237
|
+
matchOf.set(p.id, A.get(p.id));
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const old = p.name ? gone.get(`${p.type}\0${p.name}`)?.shift() : undefined;
|
|
241
|
+
if (old) {
|
|
242
|
+
renamed.set(old.id, p.id);
|
|
243
|
+
matchOf.set(p.id, old);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const ctx = { before: A, after: B, renamed };
|
|
247
|
+
const out = after.map((b) => {
|
|
248
|
+
const a = matchOf.get(b.id);
|
|
249
|
+
if (!a) return { id: b.id, type: b.type, name: b.name ?? "", status: "added", changes: [], pane: b };
|
|
250
|
+
return comparePanes(a, b, ctx);
|
|
251
|
+
});
|
|
252
|
+
const matched = new Set([...matchOf.values()].map((p) => p.id));
|
|
253
|
+
for (const a of before) if (!matched.has(a.id)) out.push({ id: a.id, type: a.type, name: a.name ?? "", status: "deleted", changes: [], pane: a });
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function comparePanes(a, b, ctx) {
|
|
258
|
+
const changes = [];
|
|
259
|
+
if (a.id !== b.id) changes.push({ field: "id", kind: "id", before: a.id, after: b.id });
|
|
260
|
+
if (a.type !== b.type) changes.push({ field: "type", kind: "type", before: a.type, after: b.type });
|
|
261
|
+
if ((a.name ?? "") !== (b.name ?? "")) changes.push({ field: "name", kind: "name", before: a.name ?? "", after: b.name ?? "" });
|
|
262
|
+
for (const field of LINES) {
|
|
263
|
+
if ((a[field] ?? "") === (b[field] ?? "")) continue;
|
|
264
|
+
const lines = lineDiff(a[field] ?? "", b[field] ?? "");
|
|
265
|
+
changes.push({ field, kind: "lines", before: a[field] ?? "", after: b[field] ?? "", lines, added: lines.filter((l) => l.op === "+").length, removed: lines.filter((l) => l.op === "-").length });
|
|
266
|
+
}
|
|
267
|
+
const wires = wireChanges(a.inputs ?? [], b.inputs ?? [], ctx);
|
|
268
|
+
if (wires.length) changes.push({ field: "inputs", kind: "wires", wires });
|
|
269
|
+
const outputs = outputChanges(a.outputs ?? [], b.outputs ?? []);
|
|
270
|
+
if (outputs.length) changes.push({ field: "outputs", kind: "outputs", outputs });
|
|
271
|
+
// Named event channels: what it receives and what its code sends on, as facts (its code's lines show the rest).
|
|
272
|
+
const channels = channelChanges(a, b);
|
|
273
|
+
if (channels.length) changes.push({ field: "channels", kind: "channels", channels });
|
|
274
|
+
if (a.type === "subgraph" || b.type === "subgraph") {
|
|
275
|
+
const diff = diffCanvases({ panes: innerPanes(a), groups: a.graph?.groups }, { panes: innerPanes(b), groups: b.graph?.groups });
|
|
276
|
+
if (!diff.same) changes.push({ field: "graph", kind: "graph", diff });
|
|
277
|
+
}
|
|
278
|
+
const skip = new Set(["id", "type", "name", "inputs", "outputs", "graph", ...LINES, ...GEOMETRY, ...(channels.some((c) => c.what === "receives") ? ["receive"] : [])]);
|
|
279
|
+
const keys = [...new Set([...Object.keys(a), ...Object.keys(b)])].filter((k) => !skip.has(k)).sort();
|
|
280
|
+
for (const field of keys) if (!equal(a[field], b[field])) changes.push({ field, kind: "setting", before: a[field], after: b[field] });
|
|
281
|
+
const moved = !equal(rectOf(a), rectOf(b));
|
|
282
|
+
const status = changes.length ? "changed" : moved ? "moved" : "same";
|
|
283
|
+
if (moved) changes.push({ field: "rect", kind: "geometry", before: rectOf(a), after: rectOf(b) });
|
|
284
|
+
return { id: b.id, ...(a.id !== b.id ? { beforeId: a.id, matchedBy: "name" } : {}), type: b.type, name: b.name ?? "", status, ...(moved && status === "changed" ? { moved: true } : {}), changes, pane: b, previous: a };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const rectOf = (p) => {
|
|
288
|
+
const r = p.rect ?? {};
|
|
289
|
+
return { x: r.x ?? 0, y: r.y ?? 0, width: r.width ?? p.width ?? 0, height: r.height ?? 0 };
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/** A wire's port fields (src/model/ports.js) that aren't its source: what an input expects. */
|
|
293
|
+
const PORT_FIELDS = ["type", "convert", "description", "operators"];
|
|
294
|
+
|
|
295
|
+
/** A wire's route as saved (src/model/wire-route.js cleanRoute), so equal routes compare equal; undefined for the default curve. */
|
|
296
|
+
const routeOf = (i) => (i.route === undefined ? undefined : cleanRoute(i.route) ?? i.route);
|
|
297
|
+
|
|
298
|
+
/** A route in words: `curve`, `orthogonal, 2 waypoints, clearance 8`. */
|
|
299
|
+
export function routeWords(route) {
|
|
300
|
+
if (!route) return "curve";
|
|
301
|
+
const n = route.waypoints?.length ?? 0;
|
|
302
|
+
return [styleOf(route), n && `${n} waypoint${n === 1 ? "" : "s"}`, styleOf(route) === "orthogonal" && clearanceOf(route) !== DEFAULT_CLEARANCE && `clearance ${clearanceOf(route)}`].filter(Boolean).join(", ") + (anchorOf(route) ? ` moving with the ${anchorOf(route) === "source" ? "source" : "reading"} pane` : "");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function wireChanges(before, after, { before: A, after: B, renamed }) {
|
|
306
|
+
const source = (s) => renamed.get(s) ?? s;
|
|
307
|
+
// A wire is its source pane and the output of it it reads (format 3), if any.
|
|
308
|
+
const key = (src, i) => (i.output ? `${src}#${i.output}` : src);
|
|
309
|
+
// A context read from above (src/model/context.js): "context tabs".
|
|
310
|
+
const from = (id, map, output) => (String(id).startsWith("context:") ? `context ${String(id).slice("context:".length)}` : `${map.get(id)?.name || id}${output ? `.${output}` : ""}`);
|
|
311
|
+
const old = new Map(before.map((i) => [key(source(i.source), i), i]));
|
|
312
|
+
const now = new Map(after.map((i) => [key(i.source, i), i]));
|
|
313
|
+
const port = (i) => Object.fromEntries(PORT_FIELDS.filter((f) => i[f] !== undefined).map((f) => [f, i[f]]));
|
|
314
|
+
const out = [];
|
|
315
|
+
for (const [k, i] of now) {
|
|
316
|
+
const was = old.get(k);
|
|
317
|
+
const extra = i.output ? { output: i.output } : {};
|
|
318
|
+
if (!was) out.push({ op: "add", name: i.name, source: i.source, ...extra, from: from(i.source, B, i.output), ...(Object.keys(port(i)).length ? { port: port(i) } : {}), ...(routeOf(i) ? { route: routeOf(i) } : {}) });
|
|
319
|
+
else {
|
|
320
|
+
if (was.name !== i.name) out.push({ op: "rename", before: was.name, after: i.name, source: i.source, ...extra, from: from(i.source, B, i.output) });
|
|
321
|
+
if (!equal(port(was), port(i))) out.push({ op: "port", name: i.name, source: i.source, ...extra, from: from(i.source, B, i.output), before: port(was), after: port(i) });
|
|
322
|
+
if (!equal(routeOf(was), routeOf(i))) out.push({ op: "route", name: i.name, source: i.source, ...extra, from: from(i.source, B, i.output), before: routeOf(was), after: routeOf(i) });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
for (const [k, i] of old) if (!now.has(k)) out.push({ op: "remove", name: i.name, source: i.source, ...(i.output ? { output: i.output } : {}), from: from(i.source, A, i.output) });
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Declared outputs added, removed or changed (their type or description), by name. */
|
|
330
|
+
function outputChanges(before, after) {
|
|
331
|
+
const old = new Map(before.map((o) => [o.name, o]));
|
|
332
|
+
const now = new Map(after.map((o) => [o.name, o]));
|
|
333
|
+
const out = [];
|
|
334
|
+
for (const [name, o] of now) {
|
|
335
|
+
if (!old.has(name)) out.push({ op: "add", name, after: o });
|
|
336
|
+
else if (!equal(old.get(name), o)) out.push({ op: "change", name, before: old.get(name), after: o });
|
|
337
|
+
}
|
|
338
|
+
for (const [name, o] of old) if (!now.has(name)) out.push({ op: "remove", name, before: o });
|
|
339
|
+
return out;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** A port's fields in words: `: number (convert) "the price"`. */
|
|
343
|
+
const portWords = (p = {}) => `${p.type !== undefined ? `: ${typeof p.type === "string" ? p.type : "schema"}` : ""}${p.convert ? " (convert)" : ""}${p.description ? ` ${JSON.stringify(p.description)}` : ""}${p.operators?.length ? ` | ${describeOperators(p.operators)}` : ""}`;
|
|
344
|
+
|
|
345
|
+
/** One channel change in words: `+ receives "reset"`, `− sends "done" (parent)`. */
|
|
346
|
+
export const channelChangeText = (c) => `${c.op === "add" ? "+" : "−"} ${channelText(c)}`;
|
|
347
|
+
|
|
348
|
+
/** One output change in words: `+ output small: number`. */
|
|
349
|
+
export function outputText(o) {
|
|
350
|
+
if (o.op === "add") return `+ output ${o.name}${portWords(o.after)}`;
|
|
351
|
+
if (o.op === "remove") return `− output ${o.name}`;
|
|
352
|
+
return `~ output ${o.name}${portWords(o.before) || " (untyped)"} → ${portWords(o.after) || "(untyped)"}`;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ── words ──────────────────────────────────────────────────────────────────
|
|
356
|
+
|
|
357
|
+
/** `+3 ~2 −1 ↔1 panes`, or "no changes". */
|
|
358
|
+
export function summaryText(summary, { canvas = 0 } = {}) {
|
|
359
|
+
const parts = [summary.added && `+${summary.added}`, summary.changed && `~${summary.changed}`, summary.deleted && `−${summary.deleted}`, summary.moved && `↔${summary.moved}`].filter(Boolean);
|
|
360
|
+
if (!parts.length) return canvas ? `canvas settings changed` : "no changes";
|
|
361
|
+
const total = summary.added + summary.changed + summary.deleted + summary.moved;
|
|
362
|
+
return `${parts.join(" ")} pane${total === 1 ? "" : "s"}${canvas ? " + canvas" : ""}`;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** A value for a one-line description: JSON, cut short. */
|
|
366
|
+
export function short(value, max = 80) {
|
|
367
|
+
const text = value === undefined ? "(none)" : typeof value === "string" ? JSON.stringify(value) : JSON.stringify(value);
|
|
368
|
+
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** One wire change in words: `+ input rate ← rate`. */
|
|
372
|
+
export function wireText(w) {
|
|
373
|
+
if (w.op === "add") return `+ input ${w.name}${portWords(w.port)} ← ${w.from}${w.route ? `, ${routeWords(w.route)}` : ""}`;
|
|
374
|
+
if (w.op === "route") return `~ input ${w.name} route: ${routeWords(w.before)} → ${routeWords(w.after)} (← ${w.from})`;
|
|
375
|
+
if (w.op === "remove") return `− input ${w.name} ← ${w.from}`;
|
|
376
|
+
if (w.op === "port") return `~ input ${w.name}${portWords(w.before) || " (untyped)"} → ${portWords(w.after).replace(/^: /, "") || "(untyped)"} (← ${w.from})`;
|
|
377
|
+
return `~ input ${w.before} → ${w.after} (← ${w.from})`;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const MARK = { added: "+", deleted: "-", changed: "~", moved: ">" };
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* A diff as readable text (the CLI's output, and what agents get): one block
|
|
384
|
+
* per pane that isn't the same, code as unified diffs, subgraphs indented.
|
|
385
|
+
*/
|
|
386
|
+
export function formatDiff(diff, { context = 3, indent = "" } = {}) {
|
|
387
|
+
const out = [];
|
|
388
|
+
for (const c of diff.canvas ?? []) out.push(`${indent}canvas ${c.field}: ${short(c.before)} → ${short(c.after)}`);
|
|
389
|
+
for (const g of diff.groups ?? []) {
|
|
390
|
+
if (g.status === "changed") for (const c of g.changes) out.push(`${indent}~ group "${g.name}" ${c.field}: ${short(c.before)} → ${short(c.after)}`);
|
|
391
|
+
else out.push(`${indent}${MARK[g.status]} group "${g.name}" ${g.status} (${(g.group.panes ?? []).join(", ")})`);
|
|
392
|
+
}
|
|
393
|
+
for (const p of diff.panes) {
|
|
394
|
+
if (p.status === "same") continue;
|
|
395
|
+
const label = paneLabel(p.pane);
|
|
396
|
+
out.push(`${indent}${MARK[p.status]} ${p.status === "changed" && p.moved ? "changed and moved" : p.status} ${label}${p.matchedBy ? ` (was ${p.beforeId})` : ""}`);
|
|
397
|
+
if (p.status === "added" || p.status === "deleted") {
|
|
398
|
+
const body = p.pane.code ?? p.pane.text;
|
|
399
|
+
if (typeof body === "string" && body) for (const line of body.split("\n")) out.push(`${indent} ${p.status === "added" ? "+" : "-"}${line}`);
|
|
400
|
+
for (const f of channelFacts(p.pane)) out.push(`${indent} ${p.status === "added" ? "+" : "−"} ${channelText(f)}`);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
for (const c of p.changes) {
|
|
404
|
+
if (c.kind === "lines") {
|
|
405
|
+
out.push(`${indent} ${c.field}:`);
|
|
406
|
+
for (const line of unifiedDiff(c.lines, { context })) out.push(`${indent} ${line}`);
|
|
407
|
+
} else if (c.kind === "wires") {
|
|
408
|
+
for (const w of c.wires) out.push(`${indent} ${wireText(w)}`);
|
|
409
|
+
} else if (c.kind === "outputs") {
|
|
410
|
+
for (const o of c.outputs) out.push(`${indent} ${outputText(o)}`);
|
|
411
|
+
} else if (c.kind === "channels") {
|
|
412
|
+
for (const ch of c.channels) out.push(`${indent} ${channelChangeText(ch)}`);
|
|
413
|
+
} else if (c.kind === "graph") {
|
|
414
|
+
out.push(`${indent} inside (${summaryText(c.diff.summary)}):`);
|
|
415
|
+
out.push(...formatDiff(c.diff, { context, indent: `${indent} ` }).split("\n").filter(Boolean));
|
|
416
|
+
} else if (c.kind === "geometry") {
|
|
417
|
+
out.push(`${indent} moved: ${c.before.x},${c.before.y} → ${c.after.x},${c.after.y}${c.before.width !== c.after.width || c.before.height !== c.after.height ? ` (size ${c.before.width}×${c.before.height || "auto"} → ${c.after.width}×${c.after.height || "auto"})` : ""}`);
|
|
418
|
+
} else if (c.field === "context") {
|
|
419
|
+
out.push(`${indent} shares context: ${short(c.before)} → ${short(c.after)}`); // a state pane shared with the subgraphs below
|
|
420
|
+
} else {
|
|
421
|
+
out.push(`${indent} ${c.field}: ${short(c.before)} → ${short(c.after)}`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return out.join("\n");
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** A diff for agents and `mallory diff --json`: plain data, without the pane bodies the diff keeps for its views. */
|
|
429
|
+
export function diffJSON(diff) {
|
|
430
|
+
return {
|
|
431
|
+
same: diff.same,
|
|
432
|
+
summary: diff.summary,
|
|
433
|
+
canvas: diff.canvas,
|
|
434
|
+
groups: (diff.groups ?? []).map(({ group, ...g }) => (g.status === "changed" ? g : { ...g, panes: group.panes })),
|
|
435
|
+
panes: diff.panes
|
|
436
|
+
.filter((p) => p.status !== "same")
|
|
437
|
+
.map(({ pane, previous, changes, ...p }) => ({
|
|
438
|
+
...p,
|
|
439
|
+
...(p.status === "added" ? { content: pane } : p.status === "deleted" ? { content: pane } : {}),
|
|
440
|
+
changes: changes.map((c) =>
|
|
441
|
+
c.kind === "lines" ? { field: c.field, kind: c.kind, added: c.added, removed: c.removed, diff: unifiedDiff(c.lines).join("\n") } : c.kind === "graph" ? { field: c.field, kind: c.kind, diff: diffJSON(c.diff) } : c,
|
|
442
|
+
),
|
|
443
|
+
})),
|
|
444
|
+
};
|
|
445
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// One way to fire an event: `emit.event(name, payload)`, in every pane
|
|
2
|
+
// that can fire one (eval panes, DOM panes, render and audio panes, html
|
|
3
|
+
// pages' scripts, live runs, a pane in its own Worker). `event` is only ever
|
|
4
|
+
// the event a reader received (`{ name, payload, at, source, input }`), and
|
|
5
|
+
// undefined when a run isn't for one.
|
|
6
|
+
//
|
|
7
|
+
// Before a DOM pane fired with `event(name, payload)`. This migration
|
|
8
|
+
// rewrites those calls to `emit.event(name, payload)`, on every way a canvas
|
|
9
|
+
// comes in (the same ones as src/model/explicit-setters.js: open, import,
|
|
10
|
+
// files in every format, share links, versions, agents, headless runs,
|
|
11
|
+
// subgraphs, repeaters' templates, library canvases as they run, paste and
|
|
12
|
+
// packages). Only a call where `event` is mallory's firing function is rewritten:
|
|
13
|
+
//
|
|
14
|
+
// - the code is read as tokens (src/model/infer-outputs.js): strings,
|
|
15
|
+
// comments, template text and regular expressions don't count, and neither
|
|
16
|
+
// does a property (`emit.event(…)`, `x.event(…)`) or the code's own `event`
|
|
17
|
+
// (a parameter, a `const`, a destructured name; an input named `event`);
|
|
18
|
+
// - a pane whose code reads `event` as a value anywhere (`event.payload`,
|
|
19
|
+
// `if (event)`, passing it on) is left as it is: it is new code, where
|
|
20
|
+
// `event` is the received event; a call there fails with the error below;
|
|
21
|
+
// - when `emit` is the code's own where a call is, the pane is left too.
|
|
22
|
+
//
|
|
23
|
+
// Idempotent: `emit.event(` is a property, so a second pass finds nothing. A
|
|
24
|
+
// call it leaves fails at run time with an error that names the fix
|
|
25
|
+
// (firingHint).
|
|
26
|
+
//
|
|
27
|
+
// Renaming an event output (Outputs…, mallory_update_pane renameOutputs) also
|
|
28
|
+
// renames it in the pane's `emit.event("old", …)` calls (renameFired): a
|
|
29
|
+
// string literal first argument only.
|
|
30
|
+
//
|
|
31
|
+
// Pure: no DOM, no canvas. It runs under node --test.
|
|
32
|
+
import { tokenize, structure, bindings, is, isWord } from "./infer-outputs.js";
|
|
33
|
+
import { trait } from "../panes/registry.js";
|
|
34
|
+
|
|
35
|
+
/** The code's own bindings of `name` (token ranges), or everything when an input has that name. */
|
|
36
|
+
function own(toks, match, parent, name, inputNames) {
|
|
37
|
+
if (inputNames.includes(name)) return [{ from: 0, to: toks.length }];
|
|
38
|
+
return bindings(toks, match, parent, name);
|
|
39
|
+
}
|
|
40
|
+
const inside = (ranges, k) => ranges.some((r) => k >= r.from && k <= r.to);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* How `code` uses `event`: `{ calls, reads, emitOwn }`. `calls`: the offsets of
|
|
44
|
+
* the `event` of each call where it is mallory's (`event(…)`, `event?.(…)`);
|
|
45
|
+
* `reads`: it is used as a value somewhere (mallory's, not the code's own);
|
|
46
|
+
* `emitOwn`: one of those calls is where `emit` is the code's own.
|
|
47
|
+
*/
|
|
48
|
+
export function eventUses(code, { inputNames = [] } = {}) {
|
|
49
|
+
const text = String(code ?? "");
|
|
50
|
+
const out = { calls: [], reads: false, emitOwn: false };
|
|
51
|
+
if (!text.includes("event")) return out;
|
|
52
|
+
const toks = tokenize(text);
|
|
53
|
+
const { match, parent } = structure(toks);
|
|
54
|
+
const hidden = own(toks, match, parent, "event", inputNames);
|
|
55
|
+
let emitHidden;
|
|
56
|
+
toks.forEach((tok, k) => {
|
|
57
|
+
if (!isWord(tok, "event")) return;
|
|
58
|
+
const prev = toks[k - 1];
|
|
59
|
+
const next = toks[k + 1];
|
|
60
|
+
if (is(prev, ".") || is(prev, "?.")) return; // a property: emit.event, x.event
|
|
61
|
+
if (is(next, ":") && (is(prev, "{") || is(prev, ","))) return; // a key: { event: … }
|
|
62
|
+
if (inside(hidden, k)) return; // the code's own (a parameter, a const, an input)
|
|
63
|
+
if (prev?.t === "id" && ["const", "let", "var", "function", "class"].includes(prev.v)) return;
|
|
64
|
+
if (is(next, "(") || (is(next, "?.") && is(toks[k + 2], "("))) {
|
|
65
|
+
out.calls.push(tok.at);
|
|
66
|
+
emitHidden ??= own(toks, match, parent, "emit", inputNames);
|
|
67
|
+
if (inside(emitHidden, k)) out.emitOwn = true;
|
|
68
|
+
} else out.reads = true;
|
|
69
|
+
});
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Pane code with its firing calls `event(…)` rewritten to `emit.event(…)`:
|
|
75
|
+
* `{ code, calls }` (`calls`: how many), or `{ code, calls: 0, left }` when it
|
|
76
|
+
* is left as it is (`left`: why, when it has calls).
|
|
77
|
+
*/
|
|
78
|
+
export function emitEventCode(code, { inputNames = [] } = {}) {
|
|
79
|
+
const text = String(code ?? "");
|
|
80
|
+
const uses = eventUses(text, { inputNames });
|
|
81
|
+
if (!uses.calls.length) return { code: text, calls: 0 };
|
|
82
|
+
if (uses.reads) return { code: text, calls: 0, left: "its code also reads `event` as the event it received" };
|
|
83
|
+
if (uses.emitOwn) return { code: text, calls: 0, left: "its code has an `emit` of its own" };
|
|
84
|
+
let next = text;
|
|
85
|
+
for (const at of [...uses.calls].reverse()) next = `${next.slice(0, at)}emit.${next.slice(at)}`;
|
|
86
|
+
return { code: next, calls: uses.calls.length };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Does pane content fire with `event(…)` (a type whose code did before its record's `firedWithEvent`)? */
|
|
90
|
+
const firedWithEvent = (pane) => trait(pane?.type, "firedWithEvent") && typeof pane.code === "string";
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Rewrite the firing calls in `panes`, in place (and in subgraph panes' graphs
|
|
94
|
+
* and repeaters' templates). `only`: the ids at this level to look at (all when
|
|
95
|
+
* left out). Returns what it changed: `[{ pane, calls }]` (`pane`: a path of
|
|
96
|
+
* names), and what it left: `[{ pane, left }]` in `left`.
|
|
97
|
+
*/
|
|
98
|
+
export function emitEvents(panes, { only, path = "", left = [] } = {}) {
|
|
99
|
+
const changed = [];
|
|
100
|
+
if (!Array.isArray(panes)) return changed;
|
|
101
|
+
for (const pane of panes) {
|
|
102
|
+
if (!pane || typeof pane !== "object") continue;
|
|
103
|
+
const here = `${path}${pane.name || pane.id}`;
|
|
104
|
+
if ((!only || only.has(pane.id)) && firedWithEvent(pane)) {
|
|
105
|
+
const inputNames = Array.isArray(pane.inputs) ? pane.inputs.map((i) => i?.name).filter(Boolean) : [];
|
|
106
|
+
const out = emitEventCode(pane.code, { inputNames });
|
|
107
|
+
if (out.calls) {
|
|
108
|
+
pane.code = out.code;
|
|
109
|
+
changed.push({ pane: here, calls: out.calls });
|
|
110
|
+
} else if (out.left) left.push({ pane: here, left: out.left });
|
|
111
|
+
}
|
|
112
|
+
if (pane.type === "subgraph") {
|
|
113
|
+
if (pane.graph?.panes) changed.push(...emitEvents(pane.graph.panes, { path: `${here}/`, left }));
|
|
114
|
+
for (const t of Object.values(pane.each?.templates ?? {})) if (t?.graph?.panes) changed.push(...emitEvents(t.graph.panes, { path: `${here}/`, left }));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return changed;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A canvas doc with its panes' firing calls rewritten: `{ doc, changed }`,
|
|
122
|
+
* `doc` a copy when something changed (the same object otherwise). Its
|
|
123
|
+
* library's entries are left as they are (their hashes are what links compare
|
|
124
|
+
* to find updates): a library canvas is migrated when a Canvas is made from it.
|
|
125
|
+
*/
|
|
126
|
+
export function emitEventsDoc(doc) {
|
|
127
|
+
if (!doc || !Array.isArray(doc.panes) || !JSON.stringify(doc.panes).includes("event")) return { doc, changed: [] };
|
|
128
|
+
const copy = structuredClone(doc);
|
|
129
|
+
const changed = emitEvents(copy.panes);
|
|
130
|
+
return changed.length ? { doc: copy, changed } : { doc, changed };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** What the migration did, in words, for a note. */
|
|
134
|
+
export function emitEventsNote(changed) {
|
|
135
|
+
const listed = changed.slice(0, 6).map((c) => `${c.pane} (${c.calls} call${c.calls === 1 ? "" : "s"})`);
|
|
136
|
+
return `Events fired with emit.event: ${listed.join(", ")}${changed.length > listed.length ? `, and ${changed.length - listed.length} more` : ""}. A DOM pane's event(name, payload) is now emit.event(name, payload), as in every other pane; \`event\` is only the event a pane received.`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The fix for a call to `event(…)` as a function, said in an error: the message with it added, or "" when the message isn't about that. */
|
|
140
|
+
export function firingHint(message) {
|
|
141
|
+
const text = String(message ?? "");
|
|
142
|
+
if (!/(?<![\w$.])event is not a function|'event' is undefined|\bevent is undefined\b/.test(text) || text.includes("emit.event")) return "";
|
|
143
|
+
return `${text}: events are fired with emit.event("name", payload) now; \`event\` is only the event this pane received (undefined when its run isn't for one)`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** A literal's text for `name`, quoted like `raw` (its first character) when it can be. */
|
|
147
|
+
const quoted = (name, quote) => (quote === "'" && !/['\\\n]/.test(name) ? `'${name}'` : quote === "`" && !/[`\\$\n]/.test(name) ? `\`${name}\`` : JSON.stringify(name));
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* `code` with event names renamed in its `emit.event("old", …)` calls (a string
|
|
151
|
+
* literal first argument, where `emit` is mallory's): `renames` is `{ old: new }`,
|
|
152
|
+
* all at once (two names may swap). Returns `{ code, calls }`.
|
|
153
|
+
*/
|
|
154
|
+
export function renameFired(code, renames, { inputNames = [] } = {}) {
|
|
155
|
+
const text = String(code ?? "");
|
|
156
|
+
const pairs = Object.entries(renames ?? {}).filter(([from, to]) => typeof to === "string" && to && from !== to);
|
|
157
|
+
if (!pairs.length || !text.includes("emit") || !pairs.some(([from]) => text.includes(from))) return { code: text, calls: 0 };
|
|
158
|
+
const map = new Map(pairs);
|
|
159
|
+
const toks = tokenize(text);
|
|
160
|
+
const { match, parent } = structure(toks);
|
|
161
|
+
const hidden = own(toks, match, parent, "emit", inputNames);
|
|
162
|
+
const edits = [];
|
|
163
|
+
toks.forEach((tok, k) => {
|
|
164
|
+
if (!isWord(tok, "emit") || is(toks[k - 1], ".") || is(toks[k - 1], "?.") || inside(hidden, k)) return;
|
|
165
|
+
if (!is(toks[k + 1], ".") || !isWord(toks[k + 2], "event") || !is(toks[k + 3], "(")) return;
|
|
166
|
+
const arg = toks[k + 4];
|
|
167
|
+
if (!map.has(arg?.v) || !(is(toks[k + 5], ",") || is(toks[k + 5], ")"))) return;
|
|
168
|
+
const from = arg.v;
|
|
169
|
+
let end;
|
|
170
|
+
if (arg.t === "str" && !arg.unfinished) end = arg.to;
|
|
171
|
+
else if (arg.t === "tpl" && arg.whole && !arg.unfinished) end = arg.at + from.length + 2;
|
|
172
|
+
else return;
|
|
173
|
+
if (text.slice(arg.at + 1, end - 1) !== from) return; // escapes in the literal: left as it is
|
|
174
|
+
edits.push({ at: arg.at, end, text: quoted(map.get(from), text[arg.at]) });
|
|
175
|
+
});
|
|
176
|
+
let next = text;
|
|
177
|
+
for (const e of edits.reverse()) next = `${next.slice(0, e.at)}${e.text}${next.slice(e.end)}`;
|
|
178
|
+
return { code: next, calls: edits.length };
|
|
179
|
+
}
|