@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,808 @@
|
|
|
1
|
+
// Record lineage: which input records an output record came from, kept
|
|
2
|
+
// beside a table, never inside it. A plugin of the table helper (docs/tables.md):
|
|
3
|
+
// loaded as the module "mallory:table/lineage" (src/runtime/sources.js), installed
|
|
4
|
+
// with `install(table)` as `table.lineage`. Self-contained: no imports, no network,
|
|
5
|
+
// no storage, no eval.
|
|
6
|
+
//
|
|
7
|
+
// THE CONTRACT (one for the core operations, `validate` and `sql`)
|
|
8
|
+
//
|
|
9
|
+
// An operation run with `trace: true` returns `origin`, one entry per output row:
|
|
10
|
+
// `{ rows: [input positions] }`, `{ left: [..], right: [..] }` for a join,
|
|
11
|
+
// `{ <table>: [..] }` for SQL. One parent, two parents (a join), many parents (a
|
|
12
|
+
// group, a pivot, SQL aggregates) and many children (explode, split) are all the
|
|
13
|
+
// same shape: a list of positions per input, and a row several outputs name is
|
|
14
|
+
// one of their ancestors each. At most `maxLinks` per input; what was left out is
|
|
15
|
+
// counted in `$.truncated`. `$.unknown` marks a row nobody could account for.
|
|
16
|
+
// The rows that did NOT make it into the output are in `exclusions`, with a
|
|
17
|
+
// reason each ("filtered", "rejected", "review", "dropped", "unmatched").
|
|
18
|
+
//
|
|
19
|
+
// `table.lineage.extend(previous, result, { op })` turns that into a NODE and
|
|
20
|
+
// chains it onto the lineage of the table the operation read. A node is plain
|
|
21
|
+
// JSON (so it travels over a wire as an ordinary value), bounded (`maxRecords`
|
|
22
|
+
// rows of ancestry per step, `maxNodes` steps in all, both labelled when they
|
|
23
|
+
// cut) and lives BESIDE the rows: it is never a field of a row, so a table's
|
|
24
|
+
// JSON, its equality and its export are the table's own unless someone asks for
|
|
25
|
+
// `table.lineage.bundle(rows, node)`.
|
|
26
|
+
//
|
|
27
|
+
// Arbitrary code does not get lineage by position. `declare(rows, links)` takes
|
|
28
|
+
// the links the code states, one per output row; `unknown(rows)` says there are
|
|
29
|
+
// none; and a table whose lineage does not describe it (a different row count)
|
|
30
|
+
// is labelled unknown, never matched up by guess.
|
|
31
|
+
//
|
|
32
|
+
// `trace(node, index)` walks one output row back to the source rows (steps in
|
|
33
|
+
// between, where ancestry was unknown or cut), `fate(node, source, position)`
|
|
34
|
+
// walks a source row forward (which outputs, or where and why it was excluded),
|
|
35
|
+
// and `inspect(value)` is the bounded summary the pane's lineage view shows.
|
|
36
|
+
|
|
37
|
+
export function install(t) {
|
|
38
|
+
const { TableError, LINEAGE_META: META, DEFAULT_MAX_LINKS, callable } = t;
|
|
39
|
+
|
|
40
|
+
const FORMAT = "mallory-table-lineage";
|
|
41
|
+
const TRACE_FORMAT = "mallory-table-trace";
|
|
42
|
+
const BUNDLE_FORMAT = "mallory-table-with-lineage";
|
|
43
|
+
const DEFAULTS = { maxRecords: 10_000, maxNodes: 100, maxLinks: DEFAULT_MAX_LINKS, maxVisited: 1000 };
|
|
44
|
+
|
|
45
|
+
const bad = (message) => new TableError("bad-option", `lineage: ${message}`);
|
|
46
|
+
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
47
|
+
const isNode = (v) => isObj(v) && v.format === FORMAT;
|
|
48
|
+
/** Lineage is off: nothing, false, or a map of inputs none of which has any. */
|
|
49
|
+
const off = (p) => p === undefined || p === null || p === false || (isObj(p) && !isNode(p) && Object.values(p).every((v) => v === undefined || v === null || v === false));
|
|
50
|
+
const count = (n) => (Number.isInteger(n) && n >= 0 ? n : 0);
|
|
51
|
+
|
|
52
|
+
function bound(name, value, fallback, max) {
|
|
53
|
+
if (value === undefined) return fallback;
|
|
54
|
+
if (!Number.isInteger(value) || value < 1 || value > max) throw bad(`${name} should be a whole number from 1 to ${max}, not ${JSON.stringify(value)}.`);
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A node without the document header (only the root of a chain carries it). */
|
|
59
|
+
const bare = (node) => {
|
|
60
|
+
const { format: _f, version: _v, ...rest } = node;
|
|
61
|
+
return rest;
|
|
62
|
+
};
|
|
63
|
+
const root = (node) => ({ format: FORMAT, version: 1, ...node });
|
|
64
|
+
/** A step's path: the input names from the output down to it ("" is the output step), so two steps with one name stay apart (#457). */
|
|
65
|
+
const stepPath = (path, key) => (path ? `${path}/${encodeURIComponent(key)}` : encodeURIComponent(key));
|
|
66
|
+
|
|
67
|
+
/** A source table: where a chain starts. */
|
|
68
|
+
function source(name, rows) {
|
|
69
|
+
if (typeof name !== "string" || !name) throw bad("a source needs a name.");
|
|
70
|
+
return root({ kind: "source", name, rows: Array.isArray(rows) ? rows.length : count(rows) });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Steps in a node and everything under it, counting those an earlier cut already hid. */
|
|
74
|
+
const stepsIn = (n) => (n.kind === "source" ? (typeof n.cut === "number" ? n.cut : 0) : 1 + Object.values(n.inputs ?? {}).reduce((a, c) => a + stepsIn(c), 0));
|
|
75
|
+
const hiddenIn = (n) => (n.kind === "source" ? (typeof n.cut === "number" ? n.cut : 0) : Object.values(n.inputs ?? {}).reduce((a, c) => a + hiddenIn(c), 0));
|
|
76
|
+
|
|
77
|
+
/** Keep at most `budget` steps (nearest the output first); what is deeper becomes a source labelled `cut` with the number of steps it hides. */
|
|
78
|
+
function prune(node, budget) {
|
|
79
|
+
const left = { n: budget };
|
|
80
|
+
const go = (n) => {
|
|
81
|
+
if (n.kind === "source" || !n.inputs) return n;
|
|
82
|
+
left.n--;
|
|
83
|
+
const inputs = {};
|
|
84
|
+
for (const [key, child] of Object.entries(n.inputs)) {
|
|
85
|
+
if (child.kind !== "source" && left.n <= 0) inputs[key] = { kind: "source", name: `(earlier steps of ${child.name ?? key})`, rows: child.rows, cut: stepsIn(child) };
|
|
86
|
+
else inputs[key] = go(child);
|
|
87
|
+
}
|
|
88
|
+
return { ...n, inputs };
|
|
89
|
+
};
|
|
90
|
+
return go(node);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* What `prev` stands for as the lineage of each named input: a lineage node (the one input
|
|
95
|
+
* `names[0]`), `{ name: node }` for several, `true` (start a chain here: each input a source),
|
|
96
|
+
* or nothing (lineage is off: null).
|
|
97
|
+
*/
|
|
98
|
+
function inputsOf(prev, names, sizes, label, called) {
|
|
99
|
+
if (off(prev)) return null;
|
|
100
|
+
const out = {};
|
|
101
|
+
for (const [k, name] of names.entries()) {
|
|
102
|
+
let child;
|
|
103
|
+
if (prev === true) child = undefined;
|
|
104
|
+
else if (isNode(prev)) child = k === 0 ? bare(prev) : undefined;
|
|
105
|
+
else if (isObj(prev)) child = prev[name] === undefined || prev[name] === null || prev[name] === false || prev[name] === true ? undefined : bare(prev[name]);
|
|
106
|
+
else throw bad(`the lineage of "${name}" should be a lineage node (what an earlier step made), true, or null.`);
|
|
107
|
+
if (child && (!isObj(child) || !child.kind)) throw bad(`the lineage of "${name}" is not a lineage node.`);
|
|
108
|
+
const size = sizes?.[k];
|
|
109
|
+
if (!child) child = { kind: "source", name: called?.[name] ?? (names.length === 1 ? label : `${label}:${name}`), rows: count(size) };
|
|
110
|
+
else if (size !== undefined && child.rows !== size) {
|
|
111
|
+
// It describes another table: say so rather than line rows up by position.
|
|
112
|
+
child = { kind: "source", name: child.name, rows: size, mismatch: `its lineage described ${child.rows} rows but the table has ${size}` };
|
|
113
|
+
}
|
|
114
|
+
out[name] = child;
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The inputs a step read: those its origin entries name, and those `prev` has lineage for. */
|
|
120
|
+
function* namesOf(prev, origin, ctx) {
|
|
121
|
+
const names = new Set();
|
|
122
|
+
for (const e of origin) {
|
|
123
|
+
if (ctx.tick()) yield;
|
|
124
|
+
for (const k of Object.keys(e ?? {})) if (k !== META) names.add(k);
|
|
125
|
+
}
|
|
126
|
+
if (isObj(prev) && !isNode(prev)) for (const k of Object.keys(prev)) names.add(k);
|
|
127
|
+
return names.size ? [...names] : ["rows"];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const sizesOf = (input, names) => {
|
|
131
|
+
if (input === undefined) return undefined;
|
|
132
|
+
if (names.length === 1 && Array.isArray(input)) return [input.length];
|
|
133
|
+
return names.map((n) => (Array.isArray(input?.[n]) ? input[n].length : undefined));
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
function finishNode(node, inputs, opts) {
|
|
137
|
+
const maxNodes = bound("maxNodes", opts.maxNodes, DEFAULTS.maxNodes, 1000);
|
|
138
|
+
const out = prune({ kind: "step", ...node, inputs }, maxNodes);
|
|
139
|
+
const hidden = hiddenIn(out);
|
|
140
|
+
return root({ ...out, ...(hidden ? { cut: { steps: hidden } } : {}) });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The lineage of an operation's result, chained onto `prev`. Run the operation with `trace: true`.
|
|
145
|
+
* previous the lineage of the table(s) it read: a node, `{ left, right }` / `{ <table>: node }`,
|
|
146
|
+
* `true` (this is where the chain starts) or null/undefined (lineage off: returns null)
|
|
147
|
+
* op, label the step's name; `input` the rows it read (`{ left, right }` for a join, `{ <table>: rows }`
|
|
148
|
+
* for SQL), so a lineage that describes another table is labelled unknown
|
|
149
|
+
* inputs the input names (default: those the origin entries name, `["rows"]` for most operations)
|
|
150
|
+
* source, sources the name of the source table a chain starts at: one name, or `{ right: "customers" }` per input
|
|
151
|
+
*/
|
|
152
|
+
function* extendRun(ctx, prev, result, opts = {}) {
|
|
153
|
+
if (!isObj(result) || !Array.isArray(result.rows)) throw bad("extend takes an operation's result ({ rows, origin }).");
|
|
154
|
+
if (off(prev)) return null;
|
|
155
|
+
if (!Array.isArray(result.origin)) throw bad(`the ${opts.op ?? "operation"} result has no origin: run it with { trace: true }.`);
|
|
156
|
+
const maxRecords = bound("maxRecords", opts.maxRecords, DEFAULTS.maxRecords, 1_000_000);
|
|
157
|
+
const names = opts.inputs ?? (yield* namesOf(prev, result.origin, ctx));
|
|
158
|
+
const inputs = inputsOf(prev, names, sizesOf(opts.input, names), opts.source ?? "input", opts.sources);
|
|
159
|
+
const kept = Math.min(result.origin.length, maxRecords);
|
|
160
|
+
const node = {
|
|
161
|
+
name: opts.label ?? opts.op ?? "step",
|
|
162
|
+
...(opts.op ? { op: opts.op } : {}),
|
|
163
|
+
rows: result.rows.length,
|
|
164
|
+
kept,
|
|
165
|
+
origin: kept === result.origin.length ? result.origin : result.origin.slice(0, kept),
|
|
166
|
+
...(kept < result.rows.length ? { truncated: { records: result.rows.length - kept } } : {}),
|
|
167
|
+
...(result.exclusions?.length ? { exclusions: result.exclusions } : {}),
|
|
168
|
+
};
|
|
169
|
+
return finishNode(node, inputs, opts);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Check that declared links point at rows the input has, and that each is a list of whole positions. */
|
|
173
|
+
function cleanLink(link, at, names, sizes) {
|
|
174
|
+
if (link === null || link === undefined || link === false) return { [META]: { unknown: true } };
|
|
175
|
+
const entry = Array.isArray(link) ? { [names[0]]: link } : link;
|
|
176
|
+
if (!isObj(entry)) throw bad(`links[${at}] should be a list of input row positions, an object of lists (${names.map((n) => `${n}: [..]`).join(", ")}), or null for "unknown".`);
|
|
177
|
+
const out = {};
|
|
178
|
+
for (const [key, list] of Object.entries(entry)) {
|
|
179
|
+
if (key === META) {
|
|
180
|
+
if (list && list.unknown) out[META] = { ...out[META], unknown: true };
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const k = names.indexOf(key);
|
|
184
|
+
if (k < 0) throw bad(`links[${at}] names the input "${key}"; this step has ${names.map((n) => `"${n}"`).join(", ")}.`);
|
|
185
|
+
if (!Array.isArray(list)) throw bad(`links[${at}].${key} should be a list of row positions.`);
|
|
186
|
+
for (const p of list) {
|
|
187
|
+
if (!Number.isInteger(p) || p < 0) throw bad(`links[${at}].${key} has ${JSON.stringify(p)}: a position is a whole number from 0.`);
|
|
188
|
+
if (sizes?.[k] !== undefined && p >= sizes[k]) throw bad(`links[${at}].${key} names row ${p} but the input has ${sizes[k]} rows.`);
|
|
189
|
+
}
|
|
190
|
+
out[key] = list.length > DEFAULTS.maxLinks ? list.slice(0, DEFAULTS.maxLinks) : list;
|
|
191
|
+
if (list.length > DEFAULTS.maxLinks) out[META] = { ...out[META], truncated: { ...out[META]?.truncated, [key]: list.length - DEFAULTS.maxLinks } };
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Lineage that code states for itself: `links[i]` is output row `i`'s parents, a list of positions
|
|
198
|
+
* in the input (`[0, 3]`), an object for several inputs (`{ left: [1], right: [4] }`), or null when
|
|
199
|
+
* it is not known. One link per row, or it throws: ancestry is never guessed by position.
|
|
200
|
+
*/
|
|
201
|
+
function* declareRun(ctx, prev, rows, links, opts = {}) {
|
|
202
|
+
if (off(prev)) return null;
|
|
203
|
+
if (!Array.isArray(rows)) throw bad("declare takes the output rows.");
|
|
204
|
+
if (!Array.isArray(links) || links.length !== rows.length) throw bad(`declare needs one link per output row: ${rows.length} rows, ${Array.isArray(links) ? links.length : "no"} links. Use lineage.unknown(...) when the code can't say.`);
|
|
205
|
+
const names = opts.inputs ?? (yield* namesOf(prev, links.filter(isObj).filter((l) => !Array.isArray(l)), ctx));
|
|
206
|
+
const sizes = sizesOf(opts.input, names);
|
|
207
|
+
const inputs = inputsOf(prev, names, sizes, opts.source ?? "input", opts.sources);
|
|
208
|
+
const maxRecords = bound("maxRecords", opts.maxRecords, DEFAULTS.maxRecords, 1_000_000);
|
|
209
|
+
const sz = names.map((n) => inputs[n].rows);
|
|
210
|
+
const kept = Math.min(rows.length, maxRecords);
|
|
211
|
+
const origin = [];
|
|
212
|
+
for (let i = 0; i < kept; i++) {
|
|
213
|
+
if (ctx.tick()) yield;
|
|
214
|
+
origin.push(cleanLink(links[i], i, names, sz));
|
|
215
|
+
}
|
|
216
|
+
const exclusions = cleanExclusions(opts.exclusions, names, sz);
|
|
217
|
+
return finishNode({ name: opts.label ?? "declared", op: opts.op ?? "declared", rows: rows.length, kept, origin, ...(kept < rows.length ? { truncated: { records: rows.length - kept } } : {}), ...(exclusions.length ? { exclusions } : {}) }, inputs, opts);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const MAX_EXCLUDED = 1000; // positions listed per reason, like the operations' own
|
|
221
|
+
|
|
222
|
+
/** Exclusions that code states (or `track` finds): { input, kind, reason, rows, count? }, each checked against the input's row count. */
|
|
223
|
+
function cleanExclusions(list, names, sizes) {
|
|
224
|
+
if (list === undefined || list === null) return [];
|
|
225
|
+
if (!Array.isArray(list)) throw bad("exclusions is a list of { input, kind, reason, rows }.");
|
|
226
|
+
return list.map((e, at) => {
|
|
227
|
+
if (!isObj(e) || typeof e.reason !== "string" || !Array.isArray(e.rows)) throw bad(`exclusions[${at}] needs a reason (text) and rows (a list of positions).`);
|
|
228
|
+
const input = e.input ?? names[0];
|
|
229
|
+
const k = names.indexOf(input);
|
|
230
|
+
if (k < 0) throw bad(`exclusions[${at}] names the input "${input}"; this step has ${names.map((n) => `"${n}"`).join(", ")}.`);
|
|
231
|
+
for (const p of e.rows) if (!Number.isInteger(p) || p < 0 || (sizes?.[k] !== undefined && p >= sizes[k])) throw bad(`exclusions[${at}] has ${JSON.stringify(p)}: a position is a whole number inside the input.`);
|
|
232
|
+
const rows = e.rows.length > MAX_EXCLUDED ? e.rows.slice(0, MAX_EXCLUDED) : e.rows;
|
|
233
|
+
return { input, kind: typeof e.kind === "string" ? e.kind : "dropped", reason: e.reason, rows, count: Number.isInteger(e.count) && e.count >= rows.length ? e.count : e.rows.length };
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Lineage that is found, not stated: an output row that IS one of the input rows (the same object, not an
|
|
239
|
+
* equal copy) has that row as its ancestor, exactly. A row the code made anew has no known ancestry, and an input
|
|
240
|
+
* row no output row is, is not claimed as dropped when the code did not account for every output row: it is unknown.
|
|
241
|
+
* `input` is the rows the code read (`{ name: rows }` for several); nothing is matched by position or by value.
|
|
242
|
+
*/
|
|
243
|
+
function* trackRun(ctx, prev, input, rows, opts = {}) {
|
|
244
|
+
if (off(prev)) return null;
|
|
245
|
+
if (!Array.isArray(rows)) throw bad("track takes the output rows.");
|
|
246
|
+
const tables = Array.isArray(input) ? { [opts.inputs?.[0] ?? "rows"]: input } : input;
|
|
247
|
+
if (!isObj(tables) || !Object.values(tables).every(Array.isArray)) throw bad("track takes the input rows (a list), or { name: rows } for several inputs.");
|
|
248
|
+
const names = opts.inputs ?? Object.keys(tables);
|
|
249
|
+
const maps = [];
|
|
250
|
+
for (const n of names) {
|
|
251
|
+
const m = new Map();
|
|
252
|
+
const list = tables[n] ?? [];
|
|
253
|
+
for (let i = 0; i < list.length; i++) {
|
|
254
|
+
if (ctx.tick()) yield;
|
|
255
|
+
const r = list[i];
|
|
256
|
+
if (r !== null && typeof r === "object") {
|
|
257
|
+
const at = m.get(r);
|
|
258
|
+
if (at) at.push(i);
|
|
259
|
+
else m.set(r, [i]);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
maps.push(m);
|
|
263
|
+
}
|
|
264
|
+
const used = names.map(() => new Set());
|
|
265
|
+
const links = [];
|
|
266
|
+
let matched = 0;
|
|
267
|
+
for (let i = 0; i < rows.length; i++) {
|
|
268
|
+
if (ctx.tick()) yield;
|
|
269
|
+
const r = rows[i];
|
|
270
|
+
let link = null;
|
|
271
|
+
if (r !== null && typeof r === "object") {
|
|
272
|
+
const entry = {};
|
|
273
|
+
names.forEach((n, k) => {
|
|
274
|
+
const at = maps[k].get(r);
|
|
275
|
+
if (!at) return;
|
|
276
|
+
entry[n] = at;
|
|
277
|
+
for (const p of at) used[k].add(p);
|
|
278
|
+
});
|
|
279
|
+
if (Object.keys(entry).length) link = entry;
|
|
280
|
+
}
|
|
281
|
+
if (link) matched++;
|
|
282
|
+
links.push(link);
|
|
283
|
+
}
|
|
284
|
+
const label = opts.label ?? "tracked";
|
|
285
|
+
if (rows.length && !matched) {
|
|
286
|
+
const inputs = inputsOf(prev, names, sizesOf(tables, names), opts.source ?? "input", opts.sources);
|
|
287
|
+
return finishNode({ name: label, op: opts.op ?? "tracked", rows: rows.length, unknown: "no output row is one of the input rows themselves (copies and new rows can't be matched to their inputs)" }, inputs, opts);
|
|
288
|
+
}
|
|
289
|
+
const exclusions = [];
|
|
290
|
+
for (const [k, n] of names.entries()) {
|
|
291
|
+
const list = tables[n] ?? [];
|
|
292
|
+
const out = [];
|
|
293
|
+
let total = 0;
|
|
294
|
+
for (let i = 0; i < list.length; i++) {
|
|
295
|
+
if (ctx.tick()) yield;
|
|
296
|
+
if (used[k].has(i)) continue;
|
|
297
|
+
total++;
|
|
298
|
+
if (out.length < MAX_EXCLUDED) out.push(i);
|
|
299
|
+
}
|
|
300
|
+
if (total) exclusions.push({ input: n, kind: "dropped", reason: "no output row is this very row (the code left it out, or returned a copy of it)", rows: out, count: total });
|
|
301
|
+
}
|
|
302
|
+
return yield* declareRun(ctx, prev, rows, links, { ...opts, inputs: names, input: tables, op: opts.op ?? "tracked", label, exclusions });
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** The rows of arbitrary code, said to have no known ancestry (`reason` says why). */
|
|
306
|
+
function unknown(prev, rows, opts = {}) {
|
|
307
|
+
if (off(prev)) return null;
|
|
308
|
+
if (!Array.isArray(rows)) throw bad("unknown takes the output rows.");
|
|
309
|
+
const names = opts.inputs ?? (isObj(prev) && !isNode(prev) && Object.keys(prev).length ? Object.keys(prev) : ["rows"]);
|
|
310
|
+
const inputs = inputsOf(prev, names, sizesOf(opts.input, names), opts.source ?? "input", opts.sources);
|
|
311
|
+
return finishNode({ name: opts.label ?? "unknown", op: opts.op ?? "code", rows: rows.length, unknown: opts.reason ?? "arbitrary code: it didn't say which input rows each output row came from" }, inputs, opts);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// ── walking a chain ─────────────────────────────────────────────────────────
|
|
315
|
+
|
|
316
|
+
const addAll = (set, list, cap) => {
|
|
317
|
+
for (const p of list) if (set.size < cap || set.has(p)) set.add(p);
|
|
318
|
+
return list.length;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* One output row traced back to the source rows. `{ output, steps, sources, unknown, exact, bounds }`:
|
|
323
|
+
* `steps` from the output down (`name`, `path`, `op`, the `rows` of that step involved, `unavailable` rows it
|
|
324
|
+
* has no ancestry for), `sources` the original rows by source name (`truncated` counts those left
|
|
325
|
+
* out), `unknown` the places where ancestry was not known and why. `exact` is false when anything was cut.
|
|
326
|
+
*/
|
|
327
|
+
function* traceRun(ctx, node, index, opts = {}) {
|
|
328
|
+
if (!isNode(node)) throw bad("trace takes a lineage node.");
|
|
329
|
+
if (!Number.isInteger(index) || index < 0) throw bad(`the row to trace is a whole position from 0, not ${JSON.stringify(index)}.`);
|
|
330
|
+
const maxLinks = bound("maxLinks", opts.maxLinks, DEFAULTS.maxLinks, 10_000);
|
|
331
|
+
const maxVisited = bound("maxVisited", opts.maxVisited, DEFAULTS.maxVisited, 1_000_000);
|
|
332
|
+
const out = { format: TRACE_FORMAT, output: { name: node.name, index, of: node.rows }, steps: [], sources: [], unknown: [], exact: true, bounds: { maxLinks, maxVisited } };
|
|
333
|
+
if (index >= node.rows) throw bad(`the output has ${node.rows} rows; there is no row ${index}.`);
|
|
334
|
+
let visited = 0;
|
|
335
|
+
const inexact = () => (out.exact = false);
|
|
336
|
+
const sourceFor = (name) => {
|
|
337
|
+
let s = out.sources.find((x) => x.name === name);
|
|
338
|
+
if (!s) out.sources.push((s = { name, rows: [], truncated: 0 }));
|
|
339
|
+
return s;
|
|
340
|
+
};
|
|
341
|
+
const walk = function* (n, positions, depth, truncatedHere = 0, path = "") {
|
|
342
|
+
if (n.kind === "source") {
|
|
343
|
+
const s = sourceFor(n.name);
|
|
344
|
+
const have = new Set(s.rows);
|
|
345
|
+
for (const p of positions) {
|
|
346
|
+
if (ctx.tick()) yield;
|
|
347
|
+
if (have.has(p)) continue;
|
|
348
|
+
if (s.rows.length >= maxLinks) {
|
|
349
|
+
s.truncated++;
|
|
350
|
+
inexact();
|
|
351
|
+
} else {
|
|
352
|
+
s.rows.push(p);
|
|
353
|
+
have.add(p);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
s.truncated += truncatedHere;
|
|
357
|
+
if (truncatedHere) inexact();
|
|
358
|
+
if (n.mismatch) out.unknown.push({ name: n.name, reason: n.mismatch, rows: positions.slice(0, maxLinks) });
|
|
359
|
+
if (n.cut) {
|
|
360
|
+
out.unknown.push({ name: n.name, reason: `${n.cut} earlier step${n.cut === 1 ? " was" : "s were"} cut (the chain is longer than maxNodes)`, rows: positions.slice(0, maxLinks) });
|
|
361
|
+
inexact();
|
|
362
|
+
}
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
const shown = positions.slice(0, maxLinks);
|
|
366
|
+
const step = { name: n.name, path, ...(n.op ? { op: n.op } : {}), depth, rows: shown, ...(positions.length > shown.length ? { truncated: positions.length - shown.length } : {}) };
|
|
367
|
+
out.steps.push(step);
|
|
368
|
+
if (positions.length > shown.length) inexact();
|
|
369
|
+
if (n.unknown) {
|
|
370
|
+
out.unknown.push({ name: n.name, reason: n.unknown, rows: shown });
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const next = new Map(); // input name -> { set, cut }
|
|
374
|
+
for (const p of shown) {
|
|
375
|
+
if (ctx.tick()) yield;
|
|
376
|
+
if (++visited > maxVisited) {
|
|
377
|
+
inexact();
|
|
378
|
+
out.bounds.stopped = true;
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
if (p >= n.kept) {
|
|
382
|
+
(step.unavailable ??= []).push(p);
|
|
383
|
+
inexact();
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
const entry = n.origin[p];
|
|
387
|
+
if (entry[META]?.unknown) {
|
|
388
|
+
(step.unknownRows ??= []).push(p);
|
|
389
|
+
out.unknown.push({ name: n.name, reason: "this row's ancestry was declared unknown", rows: [p] });
|
|
390
|
+
}
|
|
391
|
+
for (const key of Object.keys(entry)) {
|
|
392
|
+
if (key === META) continue;
|
|
393
|
+
let g = next.get(key);
|
|
394
|
+
if (!g) next.set(key, (g = { set: new Set(), cut: 0 }));
|
|
395
|
+
addAll(g.set, entry[key], Infinity);
|
|
396
|
+
g.cut += entry[META]?.truncated?.[key] ?? 0;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
for (const [key, g] of next) {
|
|
400
|
+
const child = n.inputs?.[key];
|
|
401
|
+
if (!child) {
|
|
402
|
+
out.unknown.push({ name: n.name, reason: `no lineage for the input "${key}"`, rows: [...g.set].slice(0, maxLinks) });
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
yield* walk(child, [...g.set], depth + 1, g.cut, stepPath(path, key));
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
yield* walk(node, [index], 0);
|
|
409
|
+
return out;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Where a source row went: `{ source, position, status, outputs, exclusion?, exact }`, `status` being
|
|
414
|
+
* "kept" (`outputs`: the positions in the final table), "excluded" (`exclusion`: the step, kind and
|
|
415
|
+
* reason), "unknown" (ancestry was not known somewhere on the way) or "unreachable" (no such source).
|
|
416
|
+
*/
|
|
417
|
+
function* fateRun(ctx, node, sourceName, position, opts = {}) {
|
|
418
|
+
if (!isNode(node)) throw bad("fate takes a lineage node.");
|
|
419
|
+
if (!Number.isInteger(position) || position < 0) throw bad(`the source row is a whole position from 0, not ${JSON.stringify(position)}.`);
|
|
420
|
+
const maxOut = bound("maxLinks", opts.maxLinks, DEFAULTS.maxLinks, 10_000);
|
|
421
|
+
let exact = true;
|
|
422
|
+
let found = false;
|
|
423
|
+
let exclusion;
|
|
424
|
+
let unknownSeen;
|
|
425
|
+
const go = function* (n) {
|
|
426
|
+
if (n.kind === "source") {
|
|
427
|
+
if (n.name !== sourceName) return new Set();
|
|
428
|
+
found = true;
|
|
429
|
+
return position < n.rows ? new Set([position]) : new Set();
|
|
430
|
+
}
|
|
431
|
+
const per = [];
|
|
432
|
+
for (const [key, child] of Object.entries(n.inputs ?? {})) per.push([key, yield* go(child)]);
|
|
433
|
+
if (n.unknown) {
|
|
434
|
+
if (per.some(([, s]) => s.size)) unknownSeen ??= { at: n.name, reason: n.unknown };
|
|
435
|
+
return new Set();
|
|
436
|
+
}
|
|
437
|
+
const present = new Set();
|
|
438
|
+
let any = false;
|
|
439
|
+
for (const [key, s] of per) {
|
|
440
|
+
if (!s.size) continue;
|
|
441
|
+
any = true;
|
|
442
|
+
for (let i = 0; i < n.kept; i++) {
|
|
443
|
+
if (ctx.tick()) yield;
|
|
444
|
+
const entry = n.origin[i];
|
|
445
|
+
if (entry[META]?.unknown) {
|
|
446
|
+
unknownSeen ??= { at: n.name, reason: "some rows' ancestry was declared unknown" };
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (entry[key]?.some((p) => s.has(p))) present.add(i);
|
|
450
|
+
}
|
|
451
|
+
if (n.truncated || n.origin.some((e) => e[META]?.truncated?.[key])) exact = false; // one native pass
|
|
452
|
+
}
|
|
453
|
+
if (any && !present.size) {
|
|
454
|
+
for (const [key, s] of per) {
|
|
455
|
+
if (!s.size) continue;
|
|
456
|
+
const why = (n.exclusions ?? []).find((e) => e.input === key && e.rows.some((p) => s.has(p)));
|
|
457
|
+
exclusion ??= why
|
|
458
|
+
? { at: n.name, ...(n.op ? { op: n.op } : {}), kind: why.kind, reason: why.reason, ...(why.rule ? { rule: why.rule } : {}), ...(why.code ? { code: why.code } : {}) }
|
|
459
|
+
: { at: n.name, ...(n.op ? { op: n.op } : {}), kind: "dropped", reason: "it is not in the result, and no reason was recorded (the list of excluded rows is bounded)" };
|
|
460
|
+
if (!why) exact = false;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return any ? present : new Set();
|
|
464
|
+
};
|
|
465
|
+
const outputs = yield* go(node);
|
|
466
|
+
const result = { source: sourceName, position, outputs: [...outputs].slice(0, maxOut), ...(outputs.size > maxOut ? { count: outputs.size } : {}), exact };
|
|
467
|
+
if (!found) return { ...result, status: "unreachable", exact: true, reason: `no source called "${sourceName}" (or row ${position}) in this lineage` };
|
|
468
|
+
if (outputs.size) return { ...result, status: "kept" };
|
|
469
|
+
if (unknownSeen) return { ...result, status: "unknown", unknown: unknownSeen, exact: false };
|
|
470
|
+
return { ...result, status: "excluded", ...(exclusion ? { exclusion } : {}) };
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** The steps of a node, nearest the output first, without the per-row ancestry: ids and counts only. */
|
|
474
|
+
function summary(node) {
|
|
475
|
+
if (!isNode(node)) throw bad("summary takes a lineage node.");
|
|
476
|
+
const steps = [];
|
|
477
|
+
const sources = [];
|
|
478
|
+
const go = (n, depth, path) => {
|
|
479
|
+
if (n.kind === "source") {
|
|
480
|
+
sources.push({ name: n.name, rows: n.rows, ...(n.mismatch ? { mismatch: n.mismatch } : {}), ...(n.cut ? { cut: true } : {}) });
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
steps.push({
|
|
484
|
+
name: n.name,
|
|
485
|
+
path,
|
|
486
|
+
...(n.op ? { op: n.op } : {}),
|
|
487
|
+
depth,
|
|
488
|
+
rows: n.rows,
|
|
489
|
+
kept: n.kept ?? 0,
|
|
490
|
+
inputs: Object.keys(n.inputs ?? {}),
|
|
491
|
+
...(n.unknown ? { unknown: n.unknown } : {}),
|
|
492
|
+
...(n.truncated ? { truncated: n.truncated } : {}),
|
|
493
|
+
...(n.exclusions?.length ? { exclusions: n.exclusions.map((e) => ({ input: e.input, kind: e.kind, reason: e.reason, count: e.count, ...(e.rule ? { rule: e.rule } : {}) })) } : {}),
|
|
494
|
+
});
|
|
495
|
+
for (const [key, c] of Object.entries(n.inputs ?? {})) go(c, depth + 1, stepPath(path, key));
|
|
496
|
+
};
|
|
497
|
+
go(node, 0, "");
|
|
498
|
+
return { steps, sources, ...(node.cut ? { cut: node.cut } : {}) };
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/** The positions of source `sourceName` that some row of the output came from (one pass over the chain, no per-row walks). */
|
|
502
|
+
function keptPositions(node, sourceName) {
|
|
503
|
+
const memo = new Map();
|
|
504
|
+
// For a source: { all: rows }; for a step: Map(output position -> Set(source positions)); null when none of `sourceName` is under it.
|
|
505
|
+
const sets = (n) => {
|
|
506
|
+
if (memo.has(n)) return memo.get(n);
|
|
507
|
+
let out = null;
|
|
508
|
+
if (n.kind === "source") out = n.name === sourceName ? { all: n.rows } : null;
|
|
509
|
+
else if (!n.unknown) {
|
|
510
|
+
const kids = Object.fromEntries(Object.entries(n.inputs ?? {}).map(([key, child]) => [key, sets(child)]));
|
|
511
|
+
out = new Map();
|
|
512
|
+
for (let i = 0; i < n.kept; i++) {
|
|
513
|
+
const entry = n.origin[i];
|
|
514
|
+
if (entry[META]?.unknown) continue;
|
|
515
|
+
const acc = new Set();
|
|
516
|
+
for (const key of Object.keys(entry)) {
|
|
517
|
+
const kid = kids[key];
|
|
518
|
+
if (key === META || !kid) continue;
|
|
519
|
+
for (const p of entry[key]) {
|
|
520
|
+
if (kid.all !== undefined) {
|
|
521
|
+
if (p < kid.all) acc.add(p);
|
|
522
|
+
} else for (const q of kid.get(p) ?? []) acc.add(q);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (acc.size) out.set(i, acc);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
memo.set(n, out);
|
|
529
|
+
return out;
|
|
530
|
+
};
|
|
531
|
+
const top = sets(node);
|
|
532
|
+
const kept = new Set();
|
|
533
|
+
if (top && top.all === undefined) for (const set of top.values()) for (const p of set) kept.add(p);
|
|
534
|
+
return kept;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Where the original rows went (the forward view): for each source in the chain, the fate of its first `limit` rows that
|
|
539
|
+
* reached the output and of its first `limit` that did not, in position order. `{ name, rows, kept, notKept, items: [fate] }`,
|
|
540
|
+
* each fate being `fate()`'s answer without the source name (`position`, `status`, `outputs`, `exclusion?`, `exact`).
|
|
541
|
+
*/
|
|
542
|
+
function* forwardOf(ctx, node, limit, opts) {
|
|
543
|
+
const out = [];
|
|
544
|
+
const seen = new Set();
|
|
545
|
+
for (const src of summary(node).sources) {
|
|
546
|
+
if (seen.has(src.name)) continue;
|
|
547
|
+
seen.add(src.name);
|
|
548
|
+
const kept = keptPositions(node, src.name);
|
|
549
|
+
const positions = [];
|
|
550
|
+
let keptShown = 0;
|
|
551
|
+
let leftShown = 0;
|
|
552
|
+
for (let p = 0; p < src.rows && (keptShown < limit || leftShown < limit); p++) {
|
|
553
|
+
if (kept.has(p) ? keptShown++ < limit : leftShown++ < limit) positions.push(p);
|
|
554
|
+
}
|
|
555
|
+
const items = [];
|
|
556
|
+
for (const p of positions) {
|
|
557
|
+
if (ctx.tick()) yield;
|
|
558
|
+
const { source: _s, ...rest } = yield* fateRun(ctx, node, src.name, p, opts);
|
|
559
|
+
items.push({ ...rest, outputs: rest.outputs.slice(0, 20), ...(rest.outputs.length > 20 || rest.count ? { count: rest.count ?? rest.outputs.length } : {}) });
|
|
560
|
+
}
|
|
561
|
+
const keptRows = [...kept].filter((p) => p < src.rows).length;
|
|
562
|
+
out.push({ name: src.name, rows: src.rows, kept: keptRows, notKept: src.rows - keptRows, items });
|
|
563
|
+
}
|
|
564
|
+
return out;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* What the lineage view shows of a value, bounded and split by what retention governs:
|
|
569
|
+
* ids steps, counts and the traces of the first `shown` output rows (positions and names only)
|
|
570
|
+
* payload the rows themselves: those output rows and, when `sources` are given, the ancestors; with `steps`
|
|
571
|
+
* ({ [step path]: rows }, or tables the caller found by name) the rows of the steps in between too
|
|
572
|
+
* ids.forward where the original rows went (`forwardOf`): the first `forward` (default 50) that reached the output
|
|
573
|
+
* and the first that did not, per source, each with its fate and the reason it was left out
|
|
574
|
+
* The value is `{ rows, lineage, sources? }`, or a lineage node. `payload` is the part a run log's
|
|
575
|
+
* retention policy may withhold.
|
|
576
|
+
*/
|
|
577
|
+
function* inspectRun(ctx, value, opts = {}) {
|
|
578
|
+
const node = isNode(value) ? value : isNode(value?.lineage) ? value.lineage : undefined;
|
|
579
|
+
if (!node) return { unavailable: "the value has no lineage (a pane's `lineage` output, or { rows, lineage })" };
|
|
580
|
+
const shown = bound("shown", opts.shown, 50, 1000);
|
|
581
|
+
const ancestorRows = bound("ancestorRows", opts.ancestorRows, 20, 1000);
|
|
582
|
+
const forwardLimit = bound("forward", opts.forward, 50, 1000);
|
|
583
|
+
const rows = Array.isArray(value?.rows) ? value.rows : undefined;
|
|
584
|
+
// The original tables: those the value gives (`sources`), else those the caller found (opts.tables: the pane's inputs, by name).
|
|
585
|
+
const tables = isObj(value?.sources) || isObj(opts.tables) ? { ...(isObj(opts.tables) ? opts.tables : {}), ...(isObj(value?.sources) ? value.sources : {}) } : undefined;
|
|
586
|
+
// Rows of the steps in between, by the step's path (#457: the input names from the output down, `summary(node).steps[i].path`):
|
|
587
|
+
// those the value gives (`steps`), else those the caller found (`opts.steps`; `opts.tables`, the pane's inputs by name, are the
|
|
588
|
+
// first level). A step name works as a key too, while only one step has it: two steps named alike would share one table.
|
|
589
|
+
const given = isObj(value?.steps) || isObj(opts.steps) || isObj(opts.tables) ? { ...(isObj(opts.tables) ? opts.tables : {}), ...(isObj(opts.steps) ? opts.steps : {}), ...(isObj(value?.steps) ? value.steps : {}) } : undefined;
|
|
590
|
+
const named = new Map();
|
|
591
|
+
for (const st of summary(node).steps) named.set(st.name, (named.get(st.name) ?? 0) + 1);
|
|
592
|
+
const middleFor = (st) => {
|
|
593
|
+
if (!given || st.depth === 0) return undefined;
|
|
594
|
+
if (Array.isArray(given[st.path])) return given[st.path];
|
|
595
|
+
return named.get(st.name) === 1 && Array.isArray(given[st.name]) ? given[st.name] : undefined;
|
|
596
|
+
};
|
|
597
|
+
const middle = given;
|
|
598
|
+
const traces = [];
|
|
599
|
+
const payload = { output: {}, sources: {}, steps: {} };
|
|
600
|
+
const n = Math.min(node.rows, shown);
|
|
601
|
+
for (let i = 0; i < n; i++) {
|
|
602
|
+
if (ctx.tick()) yield;
|
|
603
|
+
const tr = yield* traceRun(ctx, node, i, opts);
|
|
604
|
+
traces.push(tr);
|
|
605
|
+
if (rows && i < rows.length) payload.output[i] = rows[i];
|
|
606
|
+
if (tables) {
|
|
607
|
+
for (const s of tr.sources) {
|
|
608
|
+
const table = tables[s.name];
|
|
609
|
+
if (!Array.isArray(table)) continue;
|
|
610
|
+
for (const p of s.rows.slice(0, ancestorRows)) if (p < table.length) (payload.sources[s.name] ??= {})[p] = table[p];
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
if (middle) {
|
|
614
|
+
for (const step of tr.steps) {
|
|
615
|
+
const rowsOf = middleFor(step);
|
|
616
|
+
if (!rowsOf) continue;
|
|
617
|
+
for (const p of step.rows.slice(0, ancestorRows)) if (p < rowsOf.length) (payload.steps[step.path] ??= {})[p] = rowsOf[p];
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const forward = yield* forwardOf(ctx, node, forwardLimit, opts);
|
|
622
|
+
if (tables) {
|
|
623
|
+
for (const f of forward) {
|
|
624
|
+
const table = tables[f.name];
|
|
625
|
+
if (Array.isArray(table)) for (const item of f.items) if (item.position < table.length) (payload.sources[f.name] ??= {})[item.position] = table[item.position];
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return { ids: { ...summary(node), output: { name: node.name, rows: node.rows, shown: n }, traces, forward }, payload };
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// ── a node that is saved (a nested lineage, any number of steps deep) ───────────
|
|
632
|
+
//
|
|
633
|
+
// `pack(node)` is the form for a document that outlives the run (a saved canvas's data, a file, an export):
|
|
634
|
+
// versioned, with each list of positions stored as differences (a long run of neighbouring rows is a row of 1s),
|
|
635
|
+
// and checked again by `unpack`, which trusts nothing in it: every size is bounded, every position a whole
|
|
636
|
+
// number inside its table, and the nesting no deeper than `maxNodes`. A node unpacks to exactly what was packed.
|
|
637
|
+
|
|
638
|
+
const PACKED_FORMAT = "mallory-table-lineage-packed";
|
|
639
|
+
const SAVED_NODES = 1000;
|
|
640
|
+
const deltas = (list) => {
|
|
641
|
+
let last = 0;
|
|
642
|
+
return list.map((p) => {
|
|
643
|
+
const d = p - last;
|
|
644
|
+
last = p;
|
|
645
|
+
return d;
|
|
646
|
+
});
|
|
647
|
+
};
|
|
648
|
+
const undelta = (list, what, limit) => {
|
|
649
|
+
if (!Array.isArray(list) || list.length > limit) throw bad(`${what} should be a list of at most ${limit} numbers.`);
|
|
650
|
+
let at = 0;
|
|
651
|
+
return list.map((d) => {
|
|
652
|
+
if (!Number.isInteger(d)) throw bad(`${what} has ${JSON.stringify(d)}: a difference is a whole number.`);
|
|
653
|
+
at += d;
|
|
654
|
+
if (at < 0) throw bad(`${what} names a row before the first.`);
|
|
655
|
+
return at;
|
|
656
|
+
});
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
function pack(node) {
|
|
660
|
+
if (!isNode(node)) throw bad("pack takes a lineage node.");
|
|
661
|
+
const go = (n) => {
|
|
662
|
+
if (n.kind === "source") return { ...n };
|
|
663
|
+
const { origin, exclusions, inputs, ...rest } = n;
|
|
664
|
+
return {
|
|
665
|
+
...rest,
|
|
666
|
+
...(origin ? { origin: origin.map((e) => Object.fromEntries(Object.entries(e).map(([k, v]) => [k, k === META ? v : deltas(v)]))) } : {}),
|
|
667
|
+
...(exclusions ? { exclusions: exclusions.map((e) => ({ ...e, rows: deltas(e.rows) })) } : {}),
|
|
668
|
+
...(inputs ? { inputs: Object.fromEntries(Object.entries(inputs).map(([k, v]) => [k, go(v)])) } : {}),
|
|
669
|
+
};
|
|
670
|
+
};
|
|
671
|
+
const { format: _f, version: _v, ...rest } = node;
|
|
672
|
+
return { format: PACKED_FORMAT, version: 1, node: go(rest) };
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function unpack(packed, opts = {}) {
|
|
676
|
+
if (!isObj(packed) || packed.format !== PACKED_FORMAT) throw bad(`unpack takes a ${PACKED_FORMAT} document.`);
|
|
677
|
+
if (packed.version !== 1) throw bad(`this packed lineage is version ${JSON.stringify(packed.version)}; only version 1 is known.`);
|
|
678
|
+
const maxDepth = bound("maxNodes", opts.maxNodes, DEFAULTS.maxNodes, SAVED_NODES);
|
|
679
|
+
const maxLinks = DEFAULTS.maxLinks;
|
|
680
|
+
const state = { nodes: 0 };
|
|
681
|
+
const text = (v, what) => {
|
|
682
|
+
if (typeof v !== "string" || v.length > 500) throw bad(`${what} should be text of at most 500 characters.`);
|
|
683
|
+
return v;
|
|
684
|
+
};
|
|
685
|
+
const whole = (v, what) => {
|
|
686
|
+
if (!Number.isInteger(v) || v < 0 || v > 1e9) throw bad(`${what} should be a whole number from 0.`);
|
|
687
|
+
return v;
|
|
688
|
+
};
|
|
689
|
+
const go = (n, depth) => {
|
|
690
|
+
if (!isObj(n)) throw bad("a step of the packed lineage is not an object.");
|
|
691
|
+
if (depth > maxDepth || ++state.nodes > SAVED_NODES) throw bad(`the packed lineage has more than ${maxDepth} steps in a chain or ${SAVED_NODES} in all.`);
|
|
692
|
+
const name = text(n.name, "a step's name");
|
|
693
|
+
if (n.kind === "source") {
|
|
694
|
+
return { kind: "source", name, rows: whole(n.rows, `source ${name}'s rows`), ...(typeof n.mismatch === "string" ? { mismatch: text(n.mismatch, "mismatch") } : {}), ...(n.cut !== undefined ? { cut: whole(n.cut, "cut") } : {}) };
|
|
695
|
+
}
|
|
696
|
+
if (n.kind !== "step") throw bad(`a step has kind "step" or "source", not ${JSON.stringify(n.kind)}.`);
|
|
697
|
+
const rows = whole(n.rows, `step ${name}'s rows`);
|
|
698
|
+
const out = { kind: "step", name, ...(n.op !== undefined ? { op: text(n.op, "op") } : {}), rows };
|
|
699
|
+
const inputs = {};
|
|
700
|
+
if (n.inputs !== undefined) {
|
|
701
|
+
if (!isObj(n.inputs)) throw bad(`step ${name}'s inputs should be an object.`);
|
|
702
|
+
for (const [key, child] of Object.entries(n.inputs)) {
|
|
703
|
+
if (key === "__proto__") throw bad("an input can't be called __proto__.");
|
|
704
|
+
inputs[key] = go(child, depth + 1);
|
|
705
|
+
}
|
|
706
|
+
out.inputs = inputs;
|
|
707
|
+
}
|
|
708
|
+
if (n.unknown !== undefined) out.unknown = text(n.unknown, "unknown");
|
|
709
|
+
if (n.kept !== undefined) out.kept = whole(n.kept, `step ${name}'s kept`);
|
|
710
|
+
if (n.origin !== undefined) {
|
|
711
|
+
if (!Array.isArray(n.origin) || n.origin.length > Math.min(rows, DEFAULTS.maxRecords)) throw bad(`step ${name}'s origin should be a list of at most ${Math.min(rows, DEFAULTS.maxRecords)} entries.`);
|
|
712
|
+
if (out.kept !== undefined && out.kept !== n.origin.length) throw bad(`step ${name} keeps ${out.kept} rows but lists ${n.origin.length}.`);
|
|
713
|
+
out.origin = n.origin.map((e, i) => {
|
|
714
|
+
if (!isObj(e)) throw bad(`step ${name}'s origin[${i}] should be an object.`);
|
|
715
|
+
const entry = {};
|
|
716
|
+
for (const [key, list] of Object.entries(e)) {
|
|
717
|
+
if (key === "__proto__") throw bad("an input can't be called __proto__.");
|
|
718
|
+
if (key === META) {
|
|
719
|
+
if (!isObj(list)) throw bad(`step ${name}'s origin[${i}] has odd metadata.`);
|
|
720
|
+
entry[META] = JSON.parse(JSON.stringify(list));
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
723
|
+
if (!(key in inputs)) throw bad(`step ${name}'s origin[${i}] names the input "${key}", which the step does not have.`);
|
|
724
|
+
const positions = undelta(list, `step ${name}'s origin[${i}].${key}`, maxLinks);
|
|
725
|
+
for (const p of positions) if (p >= inputs[key].rows) throw bad(`step ${name}'s origin[${i}].${key} names row ${p} but the input has ${inputs[key].rows} rows.`);
|
|
726
|
+
entry[key] = positions;
|
|
727
|
+
}
|
|
728
|
+
return entry;
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
if (n.truncated !== undefined) {
|
|
732
|
+
if (!isObj(n.truncated)) throw bad(`step ${name}'s truncated should be an object.`);
|
|
733
|
+
out.truncated = Object.fromEntries(Object.entries(n.truncated).map(([k, v]) => [k, whole(v, "a truncated count")]));
|
|
734
|
+
}
|
|
735
|
+
if (n.exclusions !== undefined) {
|
|
736
|
+
if (!Array.isArray(n.exclusions) || n.exclusions.length > 200) throw bad(`step ${name}'s exclusions should be a list of at most 200.`);
|
|
737
|
+
out.exclusions = n.exclusions.map((e, i) => {
|
|
738
|
+
if (!isObj(e)) throw bad(`step ${name}'s exclusions[${i}] should be an object.`);
|
|
739
|
+
const input = text(e.input, "an exclusion's input");
|
|
740
|
+
if (!(input in inputs)) throw bad(`step ${name}'s exclusions[${i}] names the input "${input}", which the step does not have.`);
|
|
741
|
+
const list = undelta(e.rows, `step ${name}'s exclusions[${i}].rows`, MAX_EXCLUDED);
|
|
742
|
+
for (const p of list) if (p >= inputs[input].rows) throw bad(`step ${name}'s exclusions[${i}] names row ${p} but the input has ${inputs[input].rows} rows.`);
|
|
743
|
+
return { input, kind: text(e.kind, "an exclusion's kind"), reason: text(e.reason, "an exclusion's reason"), ...(typeof e.code === "string" ? { code: text(e.code, "code") } : {}), ...(typeof e.rule === "string" ? { rule: text(e.rule, "rule") } : {}), rows: list, count: whole(e.count, "an exclusion's count") };
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
if (n.cut !== undefined) {
|
|
747
|
+
if (!isObj(n.cut)) throw bad(`step ${name}'s cut should be an object.`);
|
|
748
|
+
out.cut = { steps: whole(n.cut.steps, "cut.steps") };
|
|
749
|
+
}
|
|
750
|
+
return out;
|
|
751
|
+
};
|
|
752
|
+
return root(go(packed.node, 1));
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/** The table with its lineage in one document, for an export that asked for it. The table's own JSON never carries lineage. `{ pack: true }`: the lineage in its saved form (`pack`). */
|
|
756
|
+
function bundle(rows, node, opts = {}) {
|
|
757
|
+
if (!Array.isArray(rows)) throw bad("bundle takes the rows.");
|
|
758
|
+
if (!isNode(node)) throw bad("bundle takes a lineage node.");
|
|
759
|
+
return { format: BUNDLE_FORMAT, version: 1, rows, lineage: opts.pack ? pack(node) : node };
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** Read a bundle back: `{ rows, lineage }` with the lineage a node (a packed one is unpacked and checked, a plain one must be a node). */
|
|
763
|
+
function unbundle(doc) {
|
|
764
|
+
if (!isObj(doc) || doc.format !== BUNDLE_FORMAT) throw bad(`unbundle takes a ${BUNDLE_FORMAT} document.`);
|
|
765
|
+
if (!Array.isArray(doc.rows)) throw bad("the bundle has no rows.");
|
|
766
|
+
const lineage = isObj(doc.lineage) && doc.lineage.format === PACKED_FORMAT ? unpack(doc.lineage) : doc.lineage;
|
|
767
|
+
if (!isNode(lineage)) throw bad("the bundle's lineage is not a lineage node.");
|
|
768
|
+
return { rows: doc.rows, lineage };
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// ── both entry points ────────────────────────────────────────────────
|
|
772
|
+
//
|
|
773
|
+
// `table.lineage.extend(...)` and the rest run to their end; `table.lineage.async.extend(...)` is the same
|
|
774
|
+
// code in slices (`sliceMs`), stopping on `opts.signal` and `opts.limits.maxMs` with a TableError "aborted" /
|
|
775
|
+
// "limit", so walking or chaining a big table's lineage can't hold the Worker. The sync call also sees an
|
|
776
|
+
// aborted signal at its next check. `positional` is how many arguments come before `opts`.
|
|
777
|
+
const entry = (name, positional, run) => {
|
|
778
|
+
const call = callable(`lineage.${name}`, function* ({ args, opts }, _options, ctx) {
|
|
779
|
+
return yield* run(ctx, ...args, opts);
|
|
780
|
+
}, { prepare: () => {}, done: (_ctx, result) => result, register: false });
|
|
781
|
+
// The run's own options (signal, limits, sliceMs) are the shared ones; maxLinks and the rest are lineage's, checked here.
|
|
782
|
+
const split = (all) => {
|
|
783
|
+
const opts = all[positional] ?? {};
|
|
784
|
+
return { args: all.slice(0, positional), opts, shared: { signal: opts.signal, limits: opts.limits, sliceMs: opts.sliceMs } };
|
|
785
|
+
};
|
|
786
|
+
return {
|
|
787
|
+
sync: (...all) => {
|
|
788
|
+
const { opts, args, shared } = split(all);
|
|
789
|
+
return call.sync({ args, opts }, shared);
|
|
790
|
+
},
|
|
791
|
+
async: (...all) => {
|
|
792
|
+
const { opts, args, shared } = split(all);
|
|
793
|
+
return call.async({ args, opts }, shared);
|
|
794
|
+
},
|
|
795
|
+
};
|
|
796
|
+
};
|
|
797
|
+
const e = {
|
|
798
|
+
extend: entry("extend", 2, extendRun),
|
|
799
|
+
declare: entry("declare", 3, declareRun),
|
|
800
|
+
track: entry("track", 3, trackRun),
|
|
801
|
+
trace: entry("trace", 2, traceRun),
|
|
802
|
+
fate: entry("fate", 3, fateRun),
|
|
803
|
+
inspect: entry("inspect", 1, inspectRun),
|
|
804
|
+
};
|
|
805
|
+
const sync = Object.fromEntries(Object.entries(e).map(([name, v]) => [name, v.sync]));
|
|
806
|
+
const asynchronous = Object.freeze(Object.fromEntries(Object.entries(e).map(([name, v]) => [name, v.async])));
|
|
807
|
+
t.lineage = Object.freeze({ FORMAT, source, ...sync, unknown, summary, bundle, unbundle, pack, unpack, isNode, async: asynchronous, defaults: Object.freeze({ ...DEFAULTS }) });
|
|
808
|
+
}
|