@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,1033 @@
|
|
|
1
|
+
// The run log (n8n's executions): every canvas run, with what each
|
|
2
|
+
// pane took in, what it produced, its error, console lines, timing and skip
|
|
3
|
+
// reason, so "why did this pane produce X three edits ago?" still has an
|
|
4
|
+
// answer after the next keystroke.
|
|
5
|
+
//
|
|
6
|
+
// A canvas run is a burst of activity (as in src/model/history.js): from a
|
|
7
|
+
// pane starting while nothing ran until everything settled again.
|
|
8
|
+
//
|
|
9
|
+
// run = { id, seq, cause, startedAt, endedAt, start, end, status, steps }
|
|
10
|
+
// cause: "edit tip", "input price", "state count", "run-all", "timer poll", "agent mallory_update_pane", …
|
|
11
|
+
// status: the worst outcome of its steps (error, then skipped, then done)
|
|
12
|
+
// step = { pane, name, type, runId, version, start, startedAt, ms, status,
|
|
13
|
+
// inputs: [{ name, source, port?, sourceVersion, preview? }], // what it read (the source's output then; `port`: a named output of it;
|
|
14
|
+
// // a setter wire, { name, source, port: "set", setter: its state pane's name })
|
|
15
|
+
// output?: { preview, json?, tooBig?, notJSON?, pinned? }, // a depth-limited preview; the full JSON when small enough
|
|
16
|
+
// error?: { name, message, line, stack }, skip?: { reason, source },
|
|
17
|
+
// logs?: [{ level, text }], each?: { count, done, failed, items, notes },
|
|
18
|
+
// changes?: { list: [{ op, key, at?, to? }…], count }, // a state pane's run after keyed setters
|
|
19
|
+
// event?: { input, name, at, source, preview? }, // a reader's run: the event it ran for
|
|
20
|
+
// attempts?, fallback?, caught?, // error policies: tries taken, the fallback's error, catch panes that caught it
|
|
21
|
+
// waits?: { breakpoint?, pacing?, retry? }, // ms of the step spent waiting, not working (src/model/cost.js)
|
|
22
|
+
// restored?, // its value was put back after a sandbox restart, without running its code
|
|
23
|
+
// cold?, // its first run since the sandbox started (the Worker's boot and the code's first compile are in its time; src/model/cost.js)
|
|
24
|
+
// live?: { count, values: [preview…], ended? }, // a live pane's run: its values, the last LIVE_VALUES of them
|
|
25
|
+
// reruns?, // a pane that read a live pane: how many times it ran in that live run (the step is its last)
|
|
26
|
+
// repeat?: { instances, created, kept, removed, moved, reran, … }, // a repeater's run: what the change did
|
|
27
|
+
// steps? } // steps: a subgraph's inner panes, nested (a repeater's: its instances' that ran, `instance` their key)
|
|
28
|
+
// A live pane's run is one entry however many values it makes: each
|
|
29
|
+
// value updates its step (count, last values, output) and the runs it
|
|
30
|
+
// causes downstream join that entry (one step per pane, its latest), which
|
|
31
|
+
// moves to the end of the log while it goes on (`live: { panes }` on the run).
|
|
32
|
+
// The canvas transport's pause and play are entries too, with no
|
|
33
|
+
// steps (`mark: true`, cause "⏸ paused live sources", …); a step's runs
|
|
34
|
+
// have the cause "step".
|
|
35
|
+
// A run made elsewhere and added with adopt() (a canvas test, an evaluation
|
|
36
|
+
// row: they run in the Tests dialog's own sandbox) also has
|
|
37
|
+
// origin: { test, row? }; its cause is "test <name>" ("… · row 3").
|
|
38
|
+
//
|
|
39
|
+
// Kept in memory (the last RUNLOG_CONFIG.limit runs per canvas), never in the
|
|
40
|
+
// canvas, its file or its link; src/model/runlog-store.js keeps them in this
|
|
41
|
+
// browser when the person turns that on. Fed from dataflow's state changes
|
|
42
|
+
// (Canvas's onChange), like RunRecorder. Pure apart from what `facts` reads
|
|
43
|
+
// from the canvas, so it runs under node --test.
|
|
44
|
+
import { isPinnable } from "./pin.js";
|
|
45
|
+
import { LIVE_VALUES } from "./live.js";
|
|
46
|
+
import { showKey } from "../runtime/keys.js";
|
|
47
|
+
import { contextStep, contextName, sharedName } from "./context.js";
|
|
48
|
+
import { createTurns } from "./turns.js";
|
|
49
|
+
import { applyToStep, applyToRun, combine, wantsJSON, whyNoValue, because } from "./retention.js";
|
|
50
|
+
|
|
51
|
+
/** What the page's settings change (src/ui/runs-panel.js); the headless runner keeps the defaults. */
|
|
52
|
+
export const RUNLOG_CONFIG = {
|
|
53
|
+
limit: 20, // canvas runs kept per canvas
|
|
54
|
+
fullValues: true, // keep each value's full JSON when it is small enough
|
|
55
|
+
maxBytes: 64 * 1024, // …this small (its JSON text)
|
|
56
|
+
checkpointBytes: 256 * 1024, // a failed-item recovery checkpoint's values and payloads, in all (its JSON text; src/model/recovery.js)
|
|
57
|
+
maxPreviewEntries: 5000, // values whose preview says they are bigger than this aren't exported at all
|
|
58
|
+
maxMediaBytes: 8 * 1024 * 1024, // media values this small are kept (in memory only) for run view
|
|
59
|
+
testRuns: 200, // runs kept per test (an evaluation's first rows)
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The app-wide part of every pane's capture policy (src/model/retention.js):
|
|
64
|
+
* no full values at all when the option is off. A pane's and a canvas's own
|
|
65
|
+
* policies come on top (the strictest wins).
|
|
66
|
+
*/
|
|
67
|
+
export const configPolicy = () => (RUNLOG_CONFIG.fullValues ? undefined : { maxBytes: 0 });
|
|
68
|
+
|
|
69
|
+
/** The capture policy for pane `id` of `canvas` (its subgraph panes' too), in a canvas's own retention or the app-wide one. */
|
|
70
|
+
export function retentionOf(canvas, id) {
|
|
71
|
+
const root = canvas?.root ?? canvas;
|
|
72
|
+
const key = `${canvas?.prefix ?? ""}${id}`;
|
|
73
|
+
const policy = root?.retention ? root.retention.policyOf(key) : configPolicy();
|
|
74
|
+
return retainsSummary(canvas, id) ? combine(policy, { mode: "summary" }) : policy;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Is pane `pane` marked to keep only summaries of its values in the run log (`retain: "summary"`)? Anything but unset is read as "summary": a damaged mark never loosens. */
|
|
78
|
+
const marked = (pane) => pane?.retain !== undefined && pane.retain !== null && pane.retain !== false;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Does the pane marked `retain: "summary"` cover pane `id`: the marked pane itself, and the panes of the same
|
|
82
|
+
* canvas that read it directly (a wire from it that carries its value, not a setter wire). Nothing is inferred beyond
|
|
83
|
+
* that: a pane that reads a reader is not covered. Only what the run log keeps changes, never a value.
|
|
84
|
+
*/
|
|
85
|
+
export function retainsSummary(canvas, id) {
|
|
86
|
+
const pane = canvas?.panes?.get(id);
|
|
87
|
+
if (!pane) return false;
|
|
88
|
+
if (marked(pane)) return true;
|
|
89
|
+
for (const input of pane.inputs ?? []) {
|
|
90
|
+
if (!input) continue;
|
|
91
|
+
const home = canvas.inputHome(input);
|
|
92
|
+
if (home.setter) continue;
|
|
93
|
+
// A pane that was deleted stays in `panes` (undo brings it back) but no longer feeds anything.
|
|
94
|
+
if (home.node !== undefined && home.node !== id && canvas.attached?.has(home.node) !== false && marked(canvas.panes.get(home.node))) return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// What belongs to a canvas run is decided by causality first, so a loaded machine can't split one run in two:
|
|
100
|
+
// a start while a step or a pane's output (a hidden node, see hidden()) is still running, or in the same task as
|
|
101
|
+
// the run's last settle (dependents start a microtask later; src/model/turns.js), joins it. Only after that is a
|
|
102
|
+
// start RUN_GAP_MS after the last settle a run of its own. A cause hint names the next run when it was given in the
|
|
103
|
+
// same task as it starts, or less than HINT_MS before.
|
|
104
|
+
export const RUN_GAP_MS = 50;
|
|
105
|
+
const HINT_MS = 2000;
|
|
106
|
+
const MAX_LOGS = 50;
|
|
107
|
+
const MAX_CELLS = 200;
|
|
108
|
+
export const MAX_INSTANCES = 50; // a repeater's instances whose steps a run keeps
|
|
109
|
+
|
|
110
|
+
const configPolicyOf = () => configPolicy();
|
|
111
|
+
|
|
112
|
+
const SEVERITY = { error: 3, skipped: 2, done: 1 };
|
|
113
|
+
|
|
114
|
+
/** The worst outcome of a run's steps: "error", "skipped", "done" (or "cancelled" when nothing settled, "running"). */
|
|
115
|
+
export function runStatus(run) {
|
|
116
|
+
if (run.end === undefined) return "running";
|
|
117
|
+
let worst;
|
|
118
|
+
for (const s of run.steps) if (SEVERITY[s.status] && (!worst || SEVERITY[s.status] > SEVERITY[worst])) worst = s.status;
|
|
119
|
+
return worst ?? "cancelled";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** ✓ / ✗ / skipped counts. */
|
|
123
|
+
export function runCounts(run) {
|
|
124
|
+
const out = { done: 0, error: 0, skipped: 0, panes: 0 };
|
|
125
|
+
const seen = new Set();
|
|
126
|
+
for (const s of run.steps) {
|
|
127
|
+
if (out[s.status] !== undefined) out[s.status]++;
|
|
128
|
+
seen.add(s.pane);
|
|
129
|
+
}
|
|
130
|
+
out.panes = seen.size;
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const errorInfo = (e) => (e && typeof e === "object" ? { name: e.name ?? "Error", message: e.message ?? String(e), ...(e.line ? { line: e.line } : {}), ...(e.stack ? { stack: String(e.stack).slice(0, 4000) } : {}) } : { name: "Error", message: String(e) });
|
|
135
|
+
|
|
136
|
+
/** Media a value holds (the Worker's `mediaFound`), when its bytes are small enough to keep (RUNLOG_CONFIG.maxMediaBytes). */
|
|
137
|
+
function keptMedia(found) {
|
|
138
|
+
if (!found?.items?.length) return undefined;
|
|
139
|
+
const bytes = found.items.reduce((n, i) => n + (Number(i.value?.blob?.size) || 0), 0);
|
|
140
|
+
return bytes <= RUNLOG_CONFIG.maxMediaBytes ? found : undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export class RunLog {
|
|
144
|
+
/**
|
|
145
|
+
* @param {{ limit?: () => number, gapMs?: number, now?: () => number, clock?: () => number,
|
|
146
|
+
* facts?: { start?: (id: string, state: object) => object, settle?: (id: string, state: object, step: object) => object,
|
|
147
|
+
* capture?: (id: string, state: object, step: object) => Promise<object | undefined> },
|
|
148
|
+
* isRunning?: (id: string, runId: number) => boolean, afterTask?: (fn: () => void) => void }} [options]
|
|
149
|
+
* `facts.start` describes a pane as it starts (its inputs), `facts.settle` as it ends (logs, for-each,
|
|
150
|
+
* nested steps); `facts.capture` reads what comes after: late console lines (`logs`) and the full value
|
|
151
|
+
* (the rest, merged into `step.output`; usually from the run's own reply, see fullValue).
|
|
152
|
+
* `afterTask(fn)` runs fn once the current task is over (src/model/turns.js; tests pass their own).
|
|
153
|
+
* `retention(paneId)` is the pane's capture policy (src/model/retention.js): what of its payload a step keeps.
|
|
154
|
+
*/
|
|
155
|
+
constructor({ limit = () => RUNLOG_CONFIG.limit, gapMs = RUN_GAP_MS, now = () => globalThis.performance?.now?.() ?? Date.now(), clock = () => Date.now(), facts = {}, isRunning, afterTask, retention = configPolicyOf } = {}) {
|
|
156
|
+
Object.assign(this, { limitOf: limit, gapMs, now, clock, facts, isRunning, retention });
|
|
157
|
+
this.seqOf = new WeakMap(); // step -> the number of the run it belongs to (a sampled log keeps the payload of every Nth run)
|
|
158
|
+
this.secrets = new WeakMap(); // step -> the text of the values its policy redacted, to scrub out of text that comes later
|
|
159
|
+
this.turns = createTurns(afterTask);
|
|
160
|
+
this.quietTurn = undefined; // the task in which the last run's steps all settled
|
|
161
|
+
this.hiddenRuns = new Map(); // hidden node id -> its run in flight (hidden())
|
|
162
|
+
this.runs = []; // oldest first
|
|
163
|
+
this.open = new Map(); // pane id -> its step in flight
|
|
164
|
+
this.seq = 0;
|
|
165
|
+
this.lastSettled = -Infinity;
|
|
166
|
+
this.pending = undefined; // { cause, strong, at, turn }: what the next run is called
|
|
167
|
+
this.captures = new Set(); // full-value reads in flight
|
|
168
|
+
this.liveSteps = new Map(); // pane id -> { step, run }: the step of its live run
|
|
169
|
+
this.liveWave = undefined; // the run a live value's downstream runs join
|
|
170
|
+
this.listeners = new Set();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Name what starts the next run ("edit tip", "run-all", "agent mallory_run_all"). A strong hint (an agent's) isn't replaced by a weak one. */
|
|
174
|
+
hint(cause, { strong = false } = {}) {
|
|
175
|
+
if (this.#hinted() && this.pending.strong && !strong) return;
|
|
176
|
+
this.pending = { cause: String(cause), strong, at: this.clock(), turn: this.turns.mark() };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* A node the log doesn't list, fed like observe(): a pane's named output (src/model/ports.js). It runs after its
|
|
181
|
+
* pane settles and before what reads it starts, so while it runs (and in the task it settles in) the run goes on.
|
|
182
|
+
*/
|
|
183
|
+
hidden(id, state) {
|
|
184
|
+
if (state?.status === "running") this.hiddenRuns.set(id, state.runId);
|
|
185
|
+
else if (this.hiddenRuns.delete(id)) {
|
|
186
|
+
this.lastSettled = Math.max(this.lastSettled, this.now());
|
|
187
|
+
this.quietTurn = this.turns.mark();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Feed one state change (`state` as dataflow reports it). */
|
|
192
|
+
observe(id, state) {
|
|
193
|
+
if (!state) return;
|
|
194
|
+
const t = this.now();
|
|
195
|
+
const open = this.open.get(id);
|
|
196
|
+
if (state.status === "running") {
|
|
197
|
+
if (open?.runId === state.runId) return;
|
|
198
|
+
if (open) this.#close(open, "superseded", t);
|
|
199
|
+
this.#prune(t);
|
|
200
|
+
this.#start(id, state, t);
|
|
201
|
+
} else if (open) {
|
|
202
|
+
const settled = (state.status === "done" || state.status === "error" || state.status === "skipped") && state.runId === open.runId;
|
|
203
|
+
if (settled) this.#settle(open, state);
|
|
204
|
+
if (settled && state.live) this.#liveStart(open, state);
|
|
205
|
+
this.#close(open, settled ? state.status : "cancelled", t);
|
|
206
|
+
} else if (this.liveSteps.get(id)?.step.runId === state.runId) {
|
|
207
|
+
// A live run's next value, or its end.
|
|
208
|
+
// A last settle (an error, or an empty end) after the values still says what happened.
|
|
209
|
+
if (state.live || state.version !== this.liveSteps.get(id).step.version) this.#liveValue(id, state, t);
|
|
210
|
+
if (!state.live) this.#liveEnd(id);
|
|
211
|
+
} else if (state.status === "skipped" && state.skip?.source && state.skip.source !== id) {
|
|
212
|
+
// A skip that spread from an input: nothing ran, but the run should say so.
|
|
213
|
+
const run = this.#current(t);
|
|
214
|
+
if (!run) return;
|
|
215
|
+
const step = this.#step(id, state, t, run);
|
|
216
|
+
step.skip = { reason: state.skip.reason === undefined ? undefined : String(state.skip.reason), source: state.skip.source };
|
|
217
|
+
step.status = "skipped";
|
|
218
|
+
step.ms = 0;
|
|
219
|
+
step.version = state.version;
|
|
220
|
+
if (this.open.size === 0) {
|
|
221
|
+
// The run had ended (the skip spread as its source settled): it ends again, with this step.
|
|
222
|
+
run.end = Math.max(this.lastSettled, t);
|
|
223
|
+
run.endedAt = this.clock();
|
|
224
|
+
run.status = runStatus(run);
|
|
225
|
+
this.#notify("run-end", run);
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.#notify("step", id);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Time pane `id`'s run `runId` spent waiting inside its step, apart from working (src/model/cost.js): stopped at a
|
|
235
|
+
* breakpoint, a debounce or throttle delay, a retry's back-off. Kept as `step.waits[kind]` (ms), a summary retention
|
|
236
|
+
* keeps. Nothing when that step is not the one open now.
|
|
237
|
+
*/
|
|
238
|
+
noteWait(id, runId, kind, ms) {
|
|
239
|
+
const step = this.open.get(id) ?? this.liveSteps.get(id)?.step;
|
|
240
|
+
if (!step || step.runId !== runId || !(ms > 0)) return;
|
|
241
|
+
step.waits = { ...step.waits, [kind]: Math.round(((step.waits?.[kind] ?? 0) + ms) * 10) / 10 };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Runs, newest first. */
|
|
245
|
+
list() {
|
|
246
|
+
return [...this.runs].reverse();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** A run by id (or its position: 1 = the newest). */
|
|
250
|
+
get(ref) {
|
|
251
|
+
if (typeof ref === "number") return Number.isInteger(ref) && ref > 0 ? this.runs[this.runs.length - ref] : undefined;
|
|
252
|
+
return this.runs.find((r) => r.id === ref);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** The canvas's most recent run (it may still be going); runs added with adopt() don't count. */
|
|
256
|
+
last() {
|
|
257
|
+
for (let i = this.runs.length - 1; i >= 0; i--) if (!this.runs[i].origin && !this.runs[i].mark) return this.runs[i];
|
|
258
|
+
return undefined;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** The run that pane `pane`'s run `runId` belonged to (the canvas's own runs: a test's run ids are another canvas's). */
|
|
262
|
+
runFor(pane, runId) {
|
|
263
|
+
for (let i = this.runs.length - 1; i >= 0; i--) if (!this.runs[i].origin && this.runs[i].steps.some((s) => s.pane === pane && s.runId === runId)) return this.runs[i];
|
|
264
|
+
return undefined;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** A pane's output with this version, from whichever of the canvas's runs made it (inputs reference outputs this way). */
|
|
268
|
+
outputOf(pane, version) {
|
|
269
|
+
for (let i = this.runs.length - 1; i >= 0; i--) {
|
|
270
|
+
if (this.runs[i].origin) continue;
|
|
271
|
+
const step = this.runs[i].steps.find((s) => s.pane === pane && s.version === version && s.status === "done");
|
|
272
|
+
if (step) return step.output;
|
|
273
|
+
}
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Is anything running, or a full value still being read? */
|
|
278
|
+
get busy() {
|
|
279
|
+
return this.open.size > 0 || this.captures.size > 0;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Wait until the full values of the runs so far have been read. */
|
|
283
|
+
async flush() {
|
|
284
|
+
while (this.captures.size) await Promise.allSettled([...this.captures]);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Put runs back (kept in this browser): they count as older than anything run since. */
|
|
288
|
+
load(runs = []) {
|
|
289
|
+
const known = new Set(this.runs.map((r) => r.id));
|
|
290
|
+
const old = runs.filter((r) => r && Array.isArray(r.steps) && !known.has(r.id)).map((r) => ({ ...r, stored: true }));
|
|
291
|
+
for (const run of old) this.#retainRun(run); // whatever was kept, today's rules apply again
|
|
292
|
+
this.runs = [...old, ...this.runs].sort((a, b) => (a.startedAt ?? 0) - (b.startedAt ?? 0));
|
|
293
|
+
this.seq = Math.max(this.seq, ...this.runs.map((r) => r.seq ?? 0));
|
|
294
|
+
this.#trim();
|
|
295
|
+
this.#notify("load");
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Add runs made elsewhere, in runJSON form: a canvas test's or an evaluation
|
|
300
|
+
* row's run in the Tests dialog's sandbox (their pane ids are this canvas's).
|
|
301
|
+
* They get ids in this log and `origin: { test, row? }`; the earlier runs of
|
|
302
|
+
* the same test go, and at most RUNLOG_CONFIG.testRuns of them are kept (the
|
|
303
|
+
* first ones). They don't count towards the canvas's own runs' limit.
|
|
304
|
+
* Returns the runs added, in the order given (undefined for one left out).
|
|
305
|
+
*/
|
|
306
|
+
adopt(runs, { test } = {}) {
|
|
307
|
+
const keep = this.runs.filter((r) => !(test !== undefined && r.origin?.test === test));
|
|
308
|
+
const max = Math.max(0, Number(RUNLOG_CONFIG.testRuns) || 0);
|
|
309
|
+
const added = runs.map((json, i) => {
|
|
310
|
+
if (!json || !Array.isArray(json.steps) || i >= max) return undefined;
|
|
311
|
+
const run = runFromJSON(json);
|
|
312
|
+
this.#retainRun(run); // a test's sandbox knew nothing of this canvas's policies
|
|
313
|
+
run.seq = ++this.seq;
|
|
314
|
+
run.id = `${this.clock().toString(36)}-${run.seq}`;
|
|
315
|
+
run.origin = { ...(json.origin ?? {}), ...(test !== undefined ? { test } : {}) };
|
|
316
|
+
run.status = runStatus(run);
|
|
317
|
+
return run;
|
|
318
|
+
});
|
|
319
|
+
this.runs.splice(0, this.runs.length, ...[...keep, ...added.filter(Boolean)].sort((a, b) => (a.startedAt ?? 0) - (b.startedAt ?? 0)));
|
|
320
|
+
this.#notify("load");
|
|
321
|
+
return added;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* An entry that isn't a run but belongs in the log's timeline: the canvas
|
|
326
|
+
* transport's pause and play. It has no steps, and nothing joins it.
|
|
327
|
+
*/
|
|
328
|
+
mark(cause) {
|
|
329
|
+
const t = this.now();
|
|
330
|
+
const at = this.clock();
|
|
331
|
+
const seq = ++this.seq;
|
|
332
|
+
const run = { id: `${at.toString(36)}-${seq}`, seq, cause: String(cause), mark: true, start: t, end: t, startedAt: at, endedAt: at, status: "done", steps: [] };
|
|
333
|
+
this.runs.push(run);
|
|
334
|
+
this.#trim();
|
|
335
|
+
this.#notify("run-end", run);
|
|
336
|
+
return run;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Apply the current capture policies (and the age limits) to every step kept:
|
|
341
|
+
* payloads that must no longer be kept are purged, summaries stay. It only
|
|
342
|
+
* removes. Returns whether anything was kept that has changed (run ids).
|
|
343
|
+
*/
|
|
344
|
+
reapply() {
|
|
345
|
+
const changed = [];
|
|
346
|
+
for (const run of this.runs) {
|
|
347
|
+
const before = JSON.stringify(run.steps);
|
|
348
|
+
this.#retainRun(run);
|
|
349
|
+
if (JSON.stringify(run.steps) !== before) {
|
|
350
|
+
changed.push(run.id);
|
|
351
|
+
delete run.json; // a copy loaded from the browser's store
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (changed.length) this.#notify("retention", changed);
|
|
355
|
+
return changed;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Purge every value kept so far (previews, values, console lines, error text) and keep the summaries: the person asked. Returns the steps changed. */
|
|
359
|
+
purge() {
|
|
360
|
+
let steps = 0;
|
|
361
|
+
const walk = (list) => {
|
|
362
|
+
for (const step of list ?? []) {
|
|
363
|
+
if ((step.output && Object.keys(step.output).some((k) => k !== "withheld" && k !== "pinned")) || step.logs || step.inputs?.some((i) => i.preview)) steps++;
|
|
364
|
+
applyToStep(step, { mode: "summary", dropText: true, purged: "purged" });
|
|
365
|
+
walk(step.steps);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
for (const run of this.runs) {
|
|
369
|
+
walk(run.steps);
|
|
370
|
+
delete run.json;
|
|
371
|
+
}
|
|
372
|
+
this.#notify("retention", this.runs.map((r) => r.id));
|
|
373
|
+
return steps;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Forget every run (palette and panel: "Clear run log"). */
|
|
377
|
+
clear() {
|
|
378
|
+
this.runs = [];
|
|
379
|
+
this.#notify("clear");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** Forget a pane (deleted): its step in flight is cancelled, its live run ends. */
|
|
383
|
+
forget(id) {
|
|
384
|
+
const open = this.open.get(id);
|
|
385
|
+
if (open) this.#close(open, "cancelled", this.now());
|
|
386
|
+
this.#liveEnd(id);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** Listen: fn(kind, detail) for "step", "run-start", "run-end", "load", "clear", "capture". Returns an unsubscribe function. */
|
|
390
|
+
subscribe(fn) {
|
|
391
|
+
this.listeners.add(fn);
|
|
392
|
+
return () => this.listeners.delete(fn);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// ── internals ────────────────────────────────────────────────────────────
|
|
396
|
+
|
|
397
|
+
#current(t) {
|
|
398
|
+
if (this.runs.findLast((r) => !r.origin)?.mark) return undefined; // after a pause or play, what runs is a run of its own
|
|
399
|
+
const last = this.last();
|
|
400
|
+
if (last && (last.end === undefined || this.#continues(t))) return last;
|
|
401
|
+
return undefined;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Was a cause hint given for what starts now (in this task, or less than HINT_MS ago)? */
|
|
405
|
+
#hinted() {
|
|
406
|
+
return Boolean(this.pending) && (this.turns.current(this.pending.turn) || this.clock() - this.pending.at < HINT_MS);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** Does a start now (nothing of the log's open) still belong to the last run? Causes first, then the gap. */
|
|
410
|
+
#continues(t) {
|
|
411
|
+
if (this.turns.current(this.quietTurn)) return true; // the same task as its last settle: a dependent starting
|
|
412
|
+
for (const [id, runId] of this.hiddenRuns) {
|
|
413
|
+
if (!this.isRunning || this.isRunning(id, runId)) return true; // a pane's output still being made
|
|
414
|
+
this.hiddenRuns.delete(id); // its end was never seen (deleted)
|
|
415
|
+
}
|
|
416
|
+
return t - this.lastSettled <= this.gapMs;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
#newRun(t) {
|
|
420
|
+
const hint = this.#hinted() ? this.pending.cause : "rerun";
|
|
421
|
+
this.pending = undefined;
|
|
422
|
+
const seq = ++this.seq;
|
|
423
|
+
const run = { id: `${this.clock().toString(36)}-${seq}`, seq, cause: hint, start: t, startedAt: this.clock(), end: undefined, endedAt: undefined, status: "running", steps: [] };
|
|
424
|
+
this.runs.push(run);
|
|
425
|
+
this.#trim();
|
|
426
|
+
this.#notify("run-start", run);
|
|
427
|
+
return run;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** The canvas's own runs beyond the limit go, oldest first (adopted runs have their own: adopt()). */
|
|
431
|
+
#trim() {
|
|
432
|
+
const limit = Math.max(1, Number(this.limitOf?.()) || RUNLOG_CONFIG.limit);
|
|
433
|
+
let drop = this.runs.filter((r) => !r.origin).length - limit;
|
|
434
|
+
if (drop <= 0) return;
|
|
435
|
+
const kept = this.runs.filter((r) => r.origin || drop-- <= 0);
|
|
436
|
+
this.runs.splice(0, this.runs.length, ...kept);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** Apply a pane's capture policy to a step (and again as more of it arrives: logs, the full value). */
|
|
440
|
+
#retain(step, { now } = {}) {
|
|
441
|
+
applyToStep(step, this.retention(step.pane), { secrets: this.#secretsOf(step), now, seq: this.seqOf.get(step) });
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
#secretsOf(step) {
|
|
445
|
+
let secrets = this.secrets.get(step);
|
|
446
|
+
if (!secrets) this.secrets.set(step, (secrets = new Set()));
|
|
447
|
+
return secrets;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
#retainRun(run) {
|
|
451
|
+
const walk = (steps) => {
|
|
452
|
+
for (const step of steps ?? []) {
|
|
453
|
+
this.seqOf.set(step, run.seq);
|
|
454
|
+
this.#retainInputs(step); // a source pane's policy limits the inputs that read it
|
|
455
|
+
this.#retain(step);
|
|
456
|
+
walk(step.steps);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
walk(run.steps);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** An input's preview is the source's output: the source pane's policy limits it too. */
|
|
463
|
+
#retainInputs(step) {
|
|
464
|
+
for (const input of step.inputs ?? []) {
|
|
465
|
+
if (!input.preview || input.setter !== undefined) continue;
|
|
466
|
+
const source = String(input.source).split("#")[0];
|
|
467
|
+
const policy = combine(this.retention(source), input.inner ? this.retention(String(input.inner).split("#")[0]) : undefined);
|
|
468
|
+
if (policy) applyToStep({ inputs: [input] }, policy, { secrets: this.#secretsOf(step), seq: this.seqOf.get(step) });
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
#step(id, state, t, run) {
|
|
473
|
+
const step = { pane: id, runId: state.runId, version: undefined, start: t, startedAt: this.clock(), ms: undefined, status: "running", inputs: [] };
|
|
474
|
+
try {
|
|
475
|
+
Object.assign(step, this.facts.start?.(id, state) ?? {});
|
|
476
|
+
} catch (error) {
|
|
477
|
+
globalThis.reportError?.(error);
|
|
478
|
+
}
|
|
479
|
+
this.seqOf.set(step, run.seq);
|
|
480
|
+
this.#retainInputs(step);
|
|
481
|
+
this.#retain(step);
|
|
482
|
+
run.steps.push(step);
|
|
483
|
+
if (run.end !== undefined) run.end = undefined;
|
|
484
|
+
run.status = "running";
|
|
485
|
+
return step;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
#start(id, state, t) {
|
|
489
|
+
this.#liveEnd(id); // a new run of a live pane: its live run is over
|
|
490
|
+
// Within the gap after a run settled, a start still belongs to it (dependents start a microtask later),
|
|
491
|
+
// unless something new was asked for meanwhile (a fresh hint: an edit, run-all, an agent's tool).
|
|
492
|
+
const asked = this.#hinted();
|
|
493
|
+
// A live value's downstream runs join the live run's entry, one step per pane (its latest).
|
|
494
|
+
const wave = !asked && this.liveWave && this.runs.includes(this.liveWave) ? this.liveWave : undefined;
|
|
495
|
+
let run = wave ?? (this.open.size > 0 || (!asked && this.#continues(t)) ? this.last() : undefined);
|
|
496
|
+
if (!run) run = this.#newRun(t);
|
|
497
|
+
let reruns;
|
|
498
|
+
if (wave) {
|
|
499
|
+
const before = wave.steps.findIndex((s) => s.pane === id && s.status !== "running");
|
|
500
|
+
if (before >= 0) {
|
|
501
|
+
reruns = (wave.steps[before].reruns ?? 1) + 1;
|
|
502
|
+
wave.steps.splice(before, 1);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
const step = this.#step(id, state, t, run);
|
|
506
|
+
if (reruns) step.reruns = reruns;
|
|
507
|
+
step.run = run.id;
|
|
508
|
+
this.open.set(id, step);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
#settle(step, state, { capture = true } = {}) {
|
|
512
|
+
step.version = state.version;
|
|
513
|
+
if (state.status === "error") step.error = errorInfo(state.error);
|
|
514
|
+
else if (state.status === "skipped") step.skip = { reason: state.skip?.reason === undefined ? undefined : String(state.skip.reason), source: state.skip?.source ?? step.pane };
|
|
515
|
+
else {
|
|
516
|
+
const r = state.result ?? {};
|
|
517
|
+
step.output = { ...(r.preview ? { preview: r.preview } : {}), ...(r.pinned ? { pinned: true } : {}), ...(r.html !== undefined ? { html: String(r.html).slice(0, 20000) } : {}) };
|
|
518
|
+
// For run view's table and plot views (the Worker made it, at most 500 rows), and media small enough to keep (in memory only).
|
|
519
|
+
if (r.table) Object.assign(step.output, { table: r.table }, r.rowClick ? { rowClick: true } : {}); // rowClick: shown as a table in the auto view
|
|
520
|
+
if (r.profile) step.output.profile = r.profile; // the profile view's statistics: aggregates and a few examples, small
|
|
521
|
+
// The lineage view: `ids` (steps, counts, positions, names) are a summary of the run and stay on the step;
|
|
522
|
+
// `payload` (the rows themselves) is a value and lives in the output, where a retention policy can withhold it.
|
|
523
|
+
if (r.lineage) {
|
|
524
|
+
if (r.lineage.unavailable) step.lineage = { unavailable: r.lineage.unavailable };
|
|
525
|
+
else {
|
|
526
|
+
step.lineage = r.lineage.ids;
|
|
527
|
+
if (r.lineage.payload) step.output.lineagePayload = r.lineage.payload;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
const media = keptMedia(r.mediaFound);
|
|
531
|
+
if (media) step.output.media = media;
|
|
532
|
+
}
|
|
533
|
+
// Error policies (src/model/errors.js): how many tries it took, and a value that is the policy's fallback.
|
|
534
|
+
const attempts = state.result?.attempts ?? Math.max(state.error?.attempts ?? 0, state.error?.runAttempts ?? 0);
|
|
535
|
+
if (attempts > 1) step.attempts = attempts;
|
|
536
|
+
if (state.status === "done" && state.result?.fallback) step.fallback = String(state.result.fallback.message ?? state.result.fallback);
|
|
537
|
+
if (state.status === "done" && state.result?.restored) step.restored = true; // put back after a sandbox restart, its code didn't run
|
|
538
|
+
try {
|
|
539
|
+
Object.assign(step, this.facts.settle?.(step.pane, state, step) ?? {});
|
|
540
|
+
} catch (error) {
|
|
541
|
+
globalThis.reportError?.(error);
|
|
542
|
+
}
|
|
543
|
+
this.#retain(step);
|
|
544
|
+
if (this.facts.capture && capture) this.#capture(step, state);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** Afterwards: console lines that arrive after the result, and the full value. */
|
|
548
|
+
#capture(step, state) {
|
|
549
|
+
const reading = Promise.resolve()
|
|
550
|
+
.then(() => this.facts.capture(step.pane, state, step))
|
|
551
|
+
.then((extra) => {
|
|
552
|
+
if (!extra) return;
|
|
553
|
+
const { logs, each, ...output } = extra;
|
|
554
|
+
if (logs) step.logs = logs;
|
|
555
|
+
if (each && step.each) Object.assign(step.each, each);
|
|
556
|
+
if (Object.keys(output).length) Object.assign((step.output ??= {}), output);
|
|
557
|
+
this.#retain(step); // the console lines and the full value that came late
|
|
558
|
+
})
|
|
559
|
+
.catch(() => {})
|
|
560
|
+
.finally(() => {
|
|
561
|
+
this.captures.delete(reading);
|
|
562
|
+
this.#notify("capture", step);
|
|
563
|
+
});
|
|
564
|
+
this.captures.add(reading);
|
|
565
|
+
return reading;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// ── live runs ──
|
|
569
|
+
|
|
570
|
+
/** A pane's run went live with its first value: its step counts the values from now on. */
|
|
571
|
+
#liveStart(step, state) {
|
|
572
|
+
step.live = { count: 1, values: step.output?.preview ? [step.output.preview] : [] };
|
|
573
|
+
const run = this.runs.find((r) => r.id === step.run);
|
|
574
|
+
if (run) run.live = { panes: [...new Set([...(run.live?.panes ?? []), step.pane])] };
|
|
575
|
+
this.liveSteps.set(step.pane, { step, run });
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/** Another value of a live run: its step shows the latest (and keeps the last few), and what it causes joins its entry. */
|
|
579
|
+
#liveValue(id, state, t) {
|
|
580
|
+
const { step, run } = this.liveSteps.get(id);
|
|
581
|
+
this.#settle(step, state, { capture: false });
|
|
582
|
+
// The full value: one read at a time per live step, the latest value's (a read is a Worker round trip).
|
|
583
|
+
if (step.live.reading) step.live.again = state;
|
|
584
|
+
else this.#liveCapture(step, state);
|
|
585
|
+
step.status = state.status;
|
|
586
|
+
step.ms = t - step.start;
|
|
587
|
+
if (state.status !== "error") step.live.count++;
|
|
588
|
+
const preview = state.status === "done" ? state.result?.preview : undefined;
|
|
589
|
+
if (preview) step.live.values = [...step.live.values, preview].slice(-LIVE_VALUES);
|
|
590
|
+
if (!run || !this.runs.includes(run)) return;
|
|
591
|
+
// The live run is the newest thing happening: it moves to the end (so the limit never drops it while it goes on).
|
|
592
|
+
this.runs.splice(this.runs.indexOf(run), 1);
|
|
593
|
+
this.runs.push(run);
|
|
594
|
+
run.status = runStatus(run);
|
|
595
|
+
this.liveWave = run;
|
|
596
|
+
this.#notify("step", id);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
#liveCapture(step, state) {
|
|
600
|
+
step.live.reading = true;
|
|
601
|
+
this.#capture(step, state).finally(() => {
|
|
602
|
+
delete step.live.reading;
|
|
603
|
+
const next = step.live.again;
|
|
604
|
+
delete step.live.again;
|
|
605
|
+
if (next && next.version === step.version) this.#liveCapture(step, next);
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** A live run ended (a new run, its generator finished, it was closed or deleted). */
|
|
610
|
+
#liveEnd(id) {
|
|
611
|
+
const live = this.liveSteps.get(id);
|
|
612
|
+
if (!live) return;
|
|
613
|
+
this.liveSteps.delete(id);
|
|
614
|
+
live.step.live.ended = true;
|
|
615
|
+
if (this.liveWave === live.run) this.liveWave = undefined;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
#close(step, status, t, settledAt = t, { pruned = false } = {}) {
|
|
619
|
+
step.status = status;
|
|
620
|
+
step.ms = t - step.start;
|
|
621
|
+
if (this.open.get(step.pane) === step) this.open.delete(step.pane);
|
|
622
|
+
if (this.open.size === 0) {
|
|
623
|
+
this.liveWave = undefined; // a live value's wave is over
|
|
624
|
+
this.lastSettled = Math.max(this.lastSettled, settledAt);
|
|
625
|
+
if (!pruned) this.quietTurn = this.turns.mark(); // a pruned step's end wasn't in this task
|
|
626
|
+
const run = this.runs.find((r) => r.id === step.run);
|
|
627
|
+
if (run) {
|
|
628
|
+
run.end = settledAt;
|
|
629
|
+
run.endedAt = this.clock();
|
|
630
|
+
run.status = runStatus(run);
|
|
631
|
+
this.#notify("run-end", run);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
#prune(t) {
|
|
637
|
+
if (!this.isRunning) return;
|
|
638
|
+
for (const step of [...this.open.values()]) if (!this.isRunning(step.pane, step.runId)) this.#close(step, "cancelled", t, step.start, { pruned: true });
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
#notify(kind, detail) {
|
|
642
|
+
for (const fn of this.listeners) {
|
|
643
|
+
try {
|
|
644
|
+
fn(kind, detail);
|
|
645
|
+
} catch (error) {
|
|
646
|
+
globalThis.reportError?.(error);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// ── what the canvas tells the log ──────────────────────────────────────────
|
|
653
|
+
|
|
654
|
+
const coldSeen = new WeakMap(); // the canvas that owns a pane's code -> { generation, seen: Set of pane keys }
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Is this the first run of pane `id` since the sandbox started (or was replaced)? Yes once per generation of the shared
|
|
658
|
+
* sandbox (`runtime.generation`). A repeater's instances share their template's panes: the first instance's run is the
|
|
659
|
+
* cold one, so a thousand instances are one cold start, not a thousand.
|
|
660
|
+
*/
|
|
661
|
+
function firstSinceStart(canvas, id) {
|
|
662
|
+
const instance = canvas.instanceOf;
|
|
663
|
+
const owner = instance ? canvas.parent : canvas;
|
|
664
|
+
if (!owner) return false;
|
|
665
|
+
const key = instance ? `${instance.pane}/${id}` : String(id);
|
|
666
|
+
const generation = canvas.runtime?.generation ?? 0;
|
|
667
|
+
let seen = coldSeen.get(owner);
|
|
668
|
+
if (!seen || seen.generation !== generation) coldSeen.set(owner, (seen = { generation, seen: new Set() }));
|
|
669
|
+
if (seen.seen.has(key)) return false;
|
|
670
|
+
seen.seen.add(key);
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* The `facts` a Canvas gives its RunLog: a pane's inputs as it starts (the
|
|
676
|
+
* version of each source it reads, and that output's preview), its console
|
|
677
|
+
* lines, for-each cells and a subgraph's inner steps as it ends, and its full
|
|
678
|
+
* JSON afterwards (RUNLOG_CONFIG).
|
|
679
|
+
*/
|
|
680
|
+
export function canvasFacts(canvas) {
|
|
681
|
+
return {
|
|
682
|
+
start(id) {
|
|
683
|
+
const pane = canvas.panes.get(id);
|
|
684
|
+
if (!pane) return contextStep(canvas, id) ?? {}; // a context read from above: its value, and where it came from
|
|
685
|
+
return {
|
|
686
|
+
name: pane.name || "",
|
|
687
|
+
type: pane.type,
|
|
688
|
+
...(pane.pin ? { pinnedPane: true } : {}),
|
|
689
|
+
...(sharedName(pane) ? { shares: sharedName(pane) } : {}), // a state pane shared as a context: its writes are this pane's runs
|
|
690
|
+
inputs: (pane.inputs ?? []).map((input) => {
|
|
691
|
+
const { node, setter } = canvas.inputHome(input);
|
|
692
|
+
// A setter wire: it carries the setter, not a value; the run log says which state it writes.
|
|
693
|
+
if (setter) return { name: input.name, source: node, port: input.output ?? "set", setter: setter.pane?.name || setter.key || "?", ...(setter.context ? { context: setter.context } : {}) };
|
|
694
|
+
const state = canvas.flow.get(node); // the run of the source pane it read (an output's value is in `preview`)
|
|
695
|
+
const preview = canvas.inputState(input).result?.preview;
|
|
696
|
+
return { name: input.name, source: node, ...(node !== input.source ? { inner: input.source } : {}), ...(input.output ? { port: input.output } : {}), ...(contextName(input.source) !== undefined ? { context: contextName(input.source) } : {}), sourceVersion: state?.version ?? 0, ...(preview ? { preview } : {}) };
|
|
697
|
+
}),
|
|
698
|
+
};
|
|
699
|
+
},
|
|
700
|
+
settle(id, state, step) {
|
|
701
|
+
const out = { ...(canvas.events?.stepFacts(id, state.runId) ?? {}) }; // the event a reader's run was for
|
|
702
|
+
// Its code ran (not skipped, pinned or put back after a restart): is this the first time since the sandbox started?
|
|
703
|
+
if ((state.status === "done" || state.status === "error") && !state.result?.restored && !step.pinnedPane && canvas.panes.has(id) && firstSinceStart(canvas, id)) out.cold = true;
|
|
704
|
+
// An agent pane's fork: the run it continued from (its run id), the trace step it forked at, whether that step was edited.
|
|
705
|
+
if (state.result?.fork) out.fork = { of: state.result.fork.of, at: state.result.fork.at, edited: Boolean(state.result.fork.edited) };
|
|
706
|
+
const logs = logsOf(canvas, id);
|
|
707
|
+
if (logs) out.logs = logs;
|
|
708
|
+
const progress = canvas.progress.get(id)?.value;
|
|
709
|
+
if (progress && !progress.repeat && (progress.runId === undefined || progress.runId === state.runId)) {
|
|
710
|
+
out.each = { count: progress.count, ...(progress.total !== undefined ? { total: progress.total } : {}), done: progress.done, failed: progress.failed, ...(progress.keyed ? { keyed: true, reused: progress.reused } : {}), ...(progress.note ? { note: progress.note } : {}), ...(progress.retry ? { retry: progress.retry } : {}), items: (progress.items ?? []).slice(0, MAX_CELLS), notes: (progress.notes ?? []).slice(0, MAX_CELLS) };
|
|
711
|
+
}
|
|
712
|
+
// A state pane's keyed changes that made this value: [{ op, key, at?, to? }…] (the newest), and how many in all.
|
|
713
|
+
if (Array.isArray(state.result?.changes)) out.changes = { list: state.result.changes, count: state.result.changeCount ?? state.result.changes.length };
|
|
714
|
+
// Catch panes (src/panes/catch.js) that caught this run's failure.
|
|
715
|
+
const caughtBy = [...(canvas.caught?.entries() ?? [])].filter(([, events]) => events.some((e) => e.pane === id && e.runId === state.runId)).map(([cid]) => canvas.panes.get(cid)?.name || cid);
|
|
716
|
+
if (caughtBy.length) out.caught = caughtBy;
|
|
717
|
+
const inner = canvas.subgraphs?.get(id);
|
|
718
|
+
if (inner?.runLog) {
|
|
719
|
+
const steps = inner.runLog.runs.flatMap((r) => r.steps).filter((s) => s.start >= step.start - 1 && s.status !== "superseded" && s.status !== "cancelled");
|
|
720
|
+
if (steps.length) out.steps = steps.map(ownCopy);
|
|
721
|
+
}
|
|
722
|
+
// A repeater: what the change did, and the steps of the instances that ran (named by key), the first
|
|
723
|
+
// MAX_INSTANCES of them, from the repeater's one run log of its instances (repeater.js repeaterLog).
|
|
724
|
+
const rep = canvas.repeaters?.get(id);
|
|
725
|
+
if (rep) {
|
|
726
|
+
const repeat = state.result?.repeat ?? state.error?.repeat;
|
|
727
|
+
if (repeat) out.repeat = repeat;
|
|
728
|
+
const ran = new Map(); // instance segment -> its steps, in the order the instances started
|
|
729
|
+
for (const run of rep.runLog?.runs ?? []) {
|
|
730
|
+
for (const s of run.steps) {
|
|
731
|
+
if (s.start < step.start - 1 || s.status === "superseded" || s.status === "cancelled") continue;
|
|
732
|
+
const cut = s.pane.indexOf("/");
|
|
733
|
+
const seg = s.pane.slice(0, cut);
|
|
734
|
+
if (!ran.has(seg)) ran.set(seg, []);
|
|
735
|
+
ran.get(seg).push({ ...ownCopy(s), pane: s.pane.slice(cut + 1) });
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
const steps = [];
|
|
739
|
+
let instances = 0;
|
|
740
|
+
for (const [seg, list] of ran) {
|
|
741
|
+
const inst = rep.instances.get(seg);
|
|
742
|
+
if (!inst) continue;
|
|
743
|
+
if (++instances > MAX_INSTANCES) break;
|
|
744
|
+
const label = inst.key == null ? `#${inst.index}` : showKey(inst.key);
|
|
745
|
+
steps.push(...list.map((s) => ({ ...s, name: `${label} › ${s.name || s.pane}`, instance: label })));
|
|
746
|
+
}
|
|
747
|
+
if (steps.length) out.steps = [...(out.steps ?? []), ...steps];
|
|
748
|
+
if (instances > MAX_INSTANCES || rep.tracedMore) out.moreInstances = true;
|
|
749
|
+
}
|
|
750
|
+
return out;
|
|
751
|
+
},
|
|
752
|
+
async capture(id, state, step) {
|
|
753
|
+
const same = () => canvas.flow.get(id)?.runId === state.runId; // it hasn't started again
|
|
754
|
+
// A repeater's instance keeps previews, not full values: hundreds of them would each cost a read in the Worker.
|
|
755
|
+
// …nor one whose policy keeps no whole value (src/model/retention.js): it is not even read from the Worker.
|
|
756
|
+
const value = state.status === "done" && !canvas.instanceOf && wantsJSON(retentionOf(canvas, id), RUNLOG_CONFIG.maxBytes) ? await fullValue(canvas, id, state, step) : undefined;
|
|
757
|
+
if (!same()) return value;
|
|
758
|
+
const logs = logsOf(canvas, id);
|
|
759
|
+
// A failed keyed for-each run's recovery checkpoint: in the step's `each`, under the same retention rules.
|
|
760
|
+
const recovery = state.status === "error" ? canvas.takeCheckpoint?.(id, state.runId) : undefined;
|
|
761
|
+
return logs || value || recovery ? { ...(logs ? { logs } : {}), ...value, ...(recovery ? { each: recovery } : {}) } : undefined;
|
|
762
|
+
},
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* A step copied for another log: the outer run log's step of a subgraph or repeater lists the inner log's steps, and a
|
|
768
|
+
* shallow copy would leave their inputs, output, logs and error shared, so a change to one log (or its retention) would
|
|
769
|
+
* show in the other.
|
|
770
|
+
*/
|
|
771
|
+
function ownCopy(step) {
|
|
772
|
+
try {
|
|
773
|
+
return structuredClone(step);
|
|
774
|
+
} catch {
|
|
775
|
+
return { ...step }; // not plain data (nothing that records a step makes this)
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/** A pane's console lines now (they are cleared when it starts again). */
|
|
780
|
+
function logsOf(canvas, id) {
|
|
781
|
+
const logs = canvas.logs.get(id)?.value;
|
|
782
|
+
return logs?.length ? logs.slice(-MAX_LOGS).map((l) => ({ level: l.level, text: String(l.text).slice(0, 2000) })) : undefined;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* What a canvas's runs ask the Worker for with each pane's value (
|
|
787
|
+
* src/runtime/runtime.js withRun): the full value's limits, or undefined when
|
|
788
|
+
* this canvas's run log keeps no full values (fullValue's conditions).
|
|
789
|
+
*/
|
|
790
|
+
export function fullValueRequest(canvas, id) {
|
|
791
|
+
if (!RUNLOG_CONFIG.fullValues || !canvas.runtime?.exportValue || canvas.instanceOf) return undefined;
|
|
792
|
+
// A pane whose policy keeps no whole value (src/model/retention.js) never has it sent to the page for the run log.
|
|
793
|
+
const maxBytes = id === undefined ? RUNLOG_CONFIG.maxBytes : wantsJSON(retentionOf(canvas, id), RUNLOG_CONFIG.maxBytes);
|
|
794
|
+
if (!maxBytes) return undefined;
|
|
795
|
+
return { maxBytes, maxPreviewEntries: RUNLOG_CONFIG.maxPreviewEntries };
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
const notJSON = (message) => ({ notJSON: String(message).replace(/^This value can't be written as JSON: (it contains )?/, "").replace(/\.$/, "") });
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* A pane's full value as JSON (RUNLOG_CONFIG): `{ json }`, `{ tooBig }` or `{ notJSON }`.
|
|
802
|
+
* It came back with the run's value when the call that stored it could carry
|
|
803
|
+
* it (`canvas.takeCaptured`), else it is read from the Worker now (a
|
|
804
|
+
* round trip; the value of that run only).
|
|
805
|
+
*/
|
|
806
|
+
async function fullValue(canvas, id, state, step) {
|
|
807
|
+
if (!RUNLOG_CONFIG.fullValues || !canvas.runtime?.exportValue) return undefined;
|
|
808
|
+
const preview = state.result?.preview;
|
|
809
|
+
// Don't make the Worker write out what is plainly too big.
|
|
810
|
+
if (preview?.type === "string" && preview.size > RUNLOG_CONFIG.maxBytes) return { tooBig: preview.size + 2 };
|
|
811
|
+
if (typeof preview?.size === "number" && preview.size > RUNLOG_CONFIG.maxPreviewEntries) return { tooBig: true };
|
|
812
|
+
let out = canvas.takeCaptured?.(id, state.runId); // that run's value, read as it was stored
|
|
813
|
+
if (out?.error !== undefined) return notJSON(out.error);
|
|
814
|
+
// Kept for a restart it may be longer than the run log keeps.
|
|
815
|
+
if (typeof out?.text === "string" && out.text.length > RUNLOG_CONFIG.maxBytes) return { tooBig: out.text.length };
|
|
816
|
+
if (!out) {
|
|
817
|
+
try {
|
|
818
|
+
out = await canvas.runtime.exportValue(canvas.homeOf(id).key, "json", { runId: state.runId, maxBytes: RUNLOG_CONFIG.maxBytes });
|
|
819
|
+
} catch (error) {
|
|
820
|
+
return notJSON(error?.message ?? error);
|
|
821
|
+
}
|
|
822
|
+
if (canvas.flow.get(id)?.version !== step.version || !out || out.stale) return undefined; // it ran again meanwhile
|
|
823
|
+
}
|
|
824
|
+
if (out.tooBig) return { tooBig: out.tooBig };
|
|
825
|
+
try {
|
|
826
|
+
return { json: JSON.parse(out.text) };
|
|
827
|
+
} catch {
|
|
828
|
+
return undefined;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// ── reading a run ──────────────────────────────────────────────────────────
|
|
833
|
+
|
|
834
|
+
/** Every step of a run, a subgraph's inner steps after it (`depth` and `parent` say where). */
|
|
835
|
+
export function flatSteps(steps, depth = 0, parent, out = [], trail = []) {
|
|
836
|
+
for (const s of steps ?? []) {
|
|
837
|
+
// `trail`: the steps above it, from the root canvas's pane down (the path to a pane inside a subgraph or a repeater's instance).
|
|
838
|
+
out.push({ ...s, depth, ...(parent ? { parent } : {}), ...(trail.length ? { trail } : {}) });
|
|
839
|
+
if (s.steps?.length) flatSteps(s.steps, depth + 1, s.pane, out, [...trail, { pane: s.pane, ...(s.instance !== undefined ? { instance: s.instance } : {}) }]);
|
|
840
|
+
}
|
|
841
|
+
return out;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/** A pane's settled step in a run (its last one), if it ran. */
|
|
845
|
+
export function stepOf(run, pane) {
|
|
846
|
+
const steps = run?.steps.filter((s) => s.pane === pane && s.status !== "superseded" && s.status !== "cancelled") ?? [];
|
|
847
|
+
return steps[steps.length - 1];
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** A run as plain JSON (a download, a JSONL line, the browser's store): what it holds, without live references. */
|
|
851
|
+
export function runJSON(run, { label, now } = {}) {
|
|
852
|
+
const step = (s) => ({
|
|
853
|
+
pane: s.pane,
|
|
854
|
+
...(s.name !== undefined ? { name: s.instance ? s.name : (label?.(s.pane) ?? s.name) } : {}),
|
|
855
|
+
...(s.instance ? { instance: s.instance } : {}), // a repeater's instance: its key
|
|
856
|
+
...(s.type ? { type: s.type } : {}),
|
|
857
|
+
runId: s.runId,
|
|
858
|
+
...(s.version !== undefined ? { version: s.version } : {}),
|
|
859
|
+
startedAt: s.startedAt,
|
|
860
|
+
offsetMs: round(s.start - run.start),
|
|
861
|
+
ms: round(s.ms),
|
|
862
|
+
status: s.status,
|
|
863
|
+
inputs: (s.inputs ?? []).map((i) => (i.setter !== undefined ? { name: i.name, source: i.source, port: i.port, setter: i.setter } : { name: i.name, source: i.source, ...(i.port ? { port: i.port } : {}), sourceVersion: i.sourceVersion, ...(i.preview ? { preview: i.preview } : {}), ...(i.retention ? { retention: i.retention } : {}) })), // a setter wire: which state it writes
|
|
864
|
+
...(s.retention ? { retention: s.retention } : {}), // the capture policy it was recorded under (src/model/retention.js)
|
|
865
|
+
...(s.logsWithheld ? { logsWithheld: s.logsWithheld } : {}),
|
|
866
|
+
...(s.output ? { output: outputJSON(s.output) } : {}),
|
|
867
|
+
...(s.lineage ? { lineage: s.lineage } : {}), // the lineage view's ids: a summary (which rows), not their contents
|
|
868
|
+
...(s.error ? { error: s.error } : {}),
|
|
869
|
+
...(s.skip ? { skip: s.skip } : {}),
|
|
870
|
+
...(s.logs ? { logs: s.logs } : {}),
|
|
871
|
+
...(s.each ? { each: s.each } : {}),
|
|
872
|
+
...(s.repeat ? { repeat: s.repeat } : {}),
|
|
873
|
+
...(s.changes ? { changes: s.changes } : {}),
|
|
874
|
+
...(s.event ? { event: s.event } : {}),
|
|
875
|
+
...(s.attempts ? { attempts: s.attempts } : {}),
|
|
876
|
+
...(s.fallback !== undefined ? { fallback: s.fallback } : {}),
|
|
877
|
+
...(s.fork ? { fork: s.fork } : {}),
|
|
878
|
+
...(s.restored ? { restored: true } : {}),
|
|
879
|
+
...(s.cold ? { cold: true } : {}),
|
|
880
|
+
...(s.waits ? { waits: s.waits } : {}), // ms spent waiting inside the step (a breakpoint, pacing, a retry's back-off)
|
|
881
|
+
...(s.caught ? { caught: s.caught } : {}),
|
|
882
|
+
...(s.live ? { live: { count: s.live.count, values: s.live.values, ...(s.live.ended ? { ended: true } : {}) } } : {}),
|
|
883
|
+
...(s.reruns ? { reruns: s.reruns } : {}),
|
|
884
|
+
...(s.steps?.length ? { steps: s.steps.map(step) } : {}),
|
|
885
|
+
});
|
|
886
|
+
const json = JSON.parse(
|
|
887
|
+
JSON.stringify({ id: run.id, seq: run.seq, cause: run.cause, ...(run.mark ? { mark: true } : {}), ...(run.origin ? { origin: run.origin } : {}), ...(run.live ? { live: run.live } : {}), startedAt: run.startedAt, endedAt: run.endedAt, ms: run.end === undefined ? undefined : round(run.end - run.start), status: run.status, counts: runCounts(run), steps: run.steps.map(step) }),
|
|
888
|
+
);
|
|
889
|
+
// The second line of defence (src/model/retention.js): whatever is written out, downloaded, logged or handed to an
|
|
890
|
+
// agent is held to the policy each step was recorded under again, whatever put it there.
|
|
891
|
+
return applyToRun(json, undefined, { now });
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/** A step's output as JSON: media (Blobs) stay in memory, and a table only when the full value wasn't kept (run view makes it from the JSON). */
|
|
895
|
+
function outputJSON(output) {
|
|
896
|
+
const { media, table, ...rest } = output;
|
|
897
|
+
return { ...rest, ...(table && !("json" in output) ? { table } : {}), ...(media ? { mediaInfo: media.items.map((i) => ({ path: i.path, kind: i.value?.$media, type: i.value?.blob?.type, size: i.value?.blob?.size })) } : {}) };
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* One run from several (runJSON form, oldest first): a test's or an
|
|
902
|
+
* evaluation row's runs in its sandbox (usually one, more when something
|
|
903
|
+
* started again after a pause), with its steps' offsets from the first's start.
|
|
904
|
+
*/
|
|
905
|
+
export function mergeRuns(runs, { cause, origin } = {}) {
|
|
906
|
+
const list = (runs ?? []).filter((r) => r && Array.isArray(r.steps));
|
|
907
|
+
if (!list.length) return undefined;
|
|
908
|
+
const t0 = Math.min(...list.map((r) => r.startedAt ?? 0));
|
|
909
|
+
const shift = (r) => (r.startedAt ?? t0) - t0;
|
|
910
|
+
const steps = list.flatMap((r) => r.steps.map((s) => ({ ...s, offsetMs: (s.offsetMs ?? 0) + shift(r) })));
|
|
911
|
+
const ms = Math.max(...list.map((r) => shift(r) + (r.ms ?? 0)));
|
|
912
|
+
const run = runFromJSON({ id: list[0].id, seq: list[0].seq, cause: cause ?? list[0].cause, ...(origin ? { origin } : {}), startedAt: t0, endedAt: Math.max(...list.map((r) => r.endedAt ?? 0)) || undefined, ms, steps });
|
|
913
|
+
run.status = runStatus(run);
|
|
914
|
+
return runJSON(run);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/** Rebuild a run kept as JSON (runJSON) into the in-memory shape (times relative to 0). */
|
|
918
|
+
export function runFromJSON(json) {
|
|
919
|
+
const step = (s) => ({ ...s, start: s.offsetMs ?? 0, ...(s.steps ? { steps: s.steps.map(step) } : {}) });
|
|
920
|
+
return { ...json, start: 0, end: json.ms ?? 0, steps: (json.steps ?? []).map(step) };
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
const round = (ms) => (Number.isFinite(ms) ? Math.round(ms * 10) / 10 : undefined);
|
|
924
|
+
|
|
925
|
+
/** Runs as JSON Lines: one canvas run per line (`mallory run --log`). `extra` is merged into each line (a test's name). */
|
|
926
|
+
export function toJSONL(runs, extra = {}, options) {
|
|
927
|
+
return runs.map((r) => JSON.stringify({ ...extra, ...runJSON(r, options) })).join("\n") + (runs.length ? "\n" : "");
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Runs already in JSON form (runJSON, or what the browser's store holds) as JSON Lines, oldest first: one object per line, a trailing newline, nothing for an empty list.
|
|
932
|
+
* The page's "download every run" (src/ui/runs-panel.js); the same shape as `mallory run --log` writes, so `mallory cost` and any line-wise tool read it.
|
|
933
|
+
*/
|
|
934
|
+
export const jsonLines = (jsons) => jsons.map((j) => JSON.stringify(j)).join("\n") + (jsons.length ? "\n" : "");
|
|
935
|
+
|
|
936
|
+
// ── comparing two runs ─────────────────────────────────────────────────────
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* The differences between two JSON values, as `{ path, kind, before?, after? }`
|
|
940
|
+
* (kind "added", "removed" or "changed"), at most `max` of them.
|
|
941
|
+
*/
|
|
942
|
+
export function jsonDiff(a, b, { max = 200 } = {}) {
|
|
943
|
+
const out = [];
|
|
944
|
+
const member = (path, key) => (typeof key === "number" ? `${path}[${key}]` : /^[A-Za-z_$][\w$]*$/.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`);
|
|
945
|
+
const walk = (x, y, path, depth = 0) => {
|
|
946
|
+
if (out.length >= max) return;
|
|
947
|
+
if (Object.is(x, y)) return;
|
|
948
|
+
if (depth > 64) return void out.push({ path: path || "(value)", kind: "changed", note: "deeper than 64 levels: not compared" }); // no stack overflow on a value nested to the limit (#950 F7)
|
|
949
|
+
const bothObjects = x && y && typeof x === "object" && typeof y === "object" && Array.isArray(x) === Array.isArray(y);
|
|
950
|
+
if (!bothObjects) return void out.push({ path: path || "(value)", kind: "changed", before: x, after: y });
|
|
951
|
+
const keys = Array.isArray(x) ? [...Array(Math.max(x.length, y.length)).keys()] : [...new Set([...Object.keys(x), ...Object.keys(y)])];
|
|
952
|
+
for (const k of keys) {
|
|
953
|
+
const p = member(path, k);
|
|
954
|
+
const inX = Array.isArray(x) ? k < x.length : Object.hasOwn(x, k);
|
|
955
|
+
const inY = Array.isArray(y) ? k < y.length : Object.hasOwn(y, k);
|
|
956
|
+
if (inX && !inY) out.push({ path: p, kind: "removed", before: x[k] });
|
|
957
|
+
else if (!inX && inY) out.push({ path: p, kind: "added", after: y[k] });
|
|
958
|
+
else walk(x[k], y[k], p, depth + 1);
|
|
959
|
+
if (out.length >= max) return;
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
walk(a, b, "");
|
|
963
|
+
return out;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// ── acting on a run ────────────────────────────────────────────────────────
|
|
967
|
+
|
|
968
|
+
/** The panes a run's values can pin: named panes (or `ids`) whose full value it kept, or that it skipped by themselves. */
|
|
969
|
+
export function pinnableSteps(run, { ids, sourcesOnly = false, panes } = {}) {
|
|
970
|
+
const out = [];
|
|
971
|
+
for (const pane of new Set((run?.steps ?? []).map((s) => s.pane))) {
|
|
972
|
+
const s = stepOf(run, pane);
|
|
973
|
+
if (!s || (s.status !== "done" && !(s.status === "skipped" && s.skip?.source === s.pane))) continue;
|
|
974
|
+
if (s.type && !isPinnable(s.type)) continue;
|
|
975
|
+
if (ids?.length && !ids.includes(pane)) continue;
|
|
976
|
+
if (sourcesOnly && !ids?.length && (s.inputs?.length ?? 0) > 0) continue;
|
|
977
|
+
if (panes && !panes.has(pane)) continue;
|
|
978
|
+
if (s.status === "done" && !(s.output && "json" in s.output)) continue;
|
|
979
|
+
out.push(s);
|
|
980
|
+
}
|
|
981
|
+
return out;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* The panes pinnableSteps leaves out only because the run didn't keep their
|
|
986
|
+
* value, with why (`{ pane, reason }`): a pane's policy (summary only,
|
|
987
|
+
* redacted), the retention time, the size limit. For "disabled, because …".
|
|
988
|
+
*/
|
|
989
|
+
export function pinBlockers(run, { ids, sourcesOnly = false, panes } = {}) {
|
|
990
|
+
const out = [];
|
|
991
|
+
for (const pane of new Set((run?.steps ?? []).map((s) => s.pane))) {
|
|
992
|
+
const s = stepOf(run, pane);
|
|
993
|
+
if (!s || s.status !== "done") continue;
|
|
994
|
+
if (s.type && !isPinnable(s.type)) continue;
|
|
995
|
+
if (ids?.length && !ids.includes(pane)) continue;
|
|
996
|
+
if (sourcesOnly && !ids?.length && (s.inputs?.length ?? 0) > 0) continue;
|
|
997
|
+
if (panes && !panes.has(pane)) continue;
|
|
998
|
+
if (s.output && "json" in s.output) continue;
|
|
999
|
+
out.push({ pane, reason: whyNoValue(s) });
|
|
1000
|
+
}
|
|
1001
|
+
return out;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* A canvas test from a run (`save as canvas test`): the input panes' values in
|
|
1006
|
+
* that run become `inputs`, and panes `expect`'s values become what to expect
|
|
1007
|
+
* (their full JSON, or their type when the run didn't keep it).
|
|
1008
|
+
*/
|
|
1009
|
+
export function testFromRun(run, { name, panes, expect }) {
|
|
1010
|
+
const inputs = {};
|
|
1011
|
+
const values = {};
|
|
1012
|
+
for (const s of run.steps) {
|
|
1013
|
+
const pane = panes.get(s.pane);
|
|
1014
|
+
if (!pane?.name || s.status !== "done") continue;
|
|
1015
|
+
if (pane.type === "input" && s.output && "json" in s.output) inputs[pane.name] = s.output.json;
|
|
1016
|
+
else if (pane.type === "input" && s.output?.withheld) throw new Error(because("A test from this run", "saved", `the value of the input ${pane.name} wasn't kept: ${whyNoValue(s)}`));
|
|
1017
|
+
}
|
|
1018
|
+
const out = {};
|
|
1019
|
+
for (const id of expect) {
|
|
1020
|
+
const pane = panes.get(id);
|
|
1021
|
+
const s = stepOf(run, id);
|
|
1022
|
+
if (!pane?.name) throw new Error("Only named panes can be checked by a test.");
|
|
1023
|
+
if (!s || s.status !== "done") throw new Error(`${pane.name} has no value in that run${s ? ` (${s.status})` : ""}.`);
|
|
1024
|
+
if (s.output?.withheld) throw new Error(because(`${pane.name} in that run`, "checked by a test", `its value wasn't kept, because ${whyNoValue(s)}`));
|
|
1025
|
+
if (s.output && "json" in s.output) values[pane.name] = s.output.json;
|
|
1026
|
+
else out[pane.name] = { type: s.output?.preview?.type ?? "object" };
|
|
1027
|
+
}
|
|
1028
|
+
return { name, inputs, expect: { ...Object.fromEntries(Object.entries(values).map(([k, v]) => [k, isMatcherLike(v) ? { equals: v } : v])), ...out } };
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// A plain value that looks like a matcher (src/tests/matchers.js isMatcher) is checked with { equals }.
|
|
1032
|
+
const MATCHER_KEYS = ["approx", "matches", "contains", "type", "equals", "deepEqual"];
|
|
1033
|
+
const isMatcherLike = (v) => v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).some((k) => MATCHER_KEYS.includes(k));
|