@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,853 @@
|
|
|
1
|
+
// `mallory machine ...` (waves L-J and 4c; LTM-CLI-01..05, 07, LTM-YAML-03, 08..11): a machine pane from the terminal.
|
|
2
|
+
// mallory machine validate <canvas> [--pane name] check the definition(s) and say what is wrong
|
|
3
|
+
// mallory machine step|run <canvas> [--pane name] [provider/approval flags] [--steps n] [--json] [--trace file] [--otlp file]
|
|
4
|
+
// mallory machine init <template> [-o file] [--id id] [--force] a new canvas holding a starter machine
|
|
5
|
+
// mallory machine fork|diff|merge ... definitions: a copy with provenance, changed paths, a three-way merge
|
|
6
|
+
// mallory machine trace inspect|replay|fork|resume|tree|diff ... trace files
|
|
7
|
+
// mallory machine bench|suite|report ... the canvas's own tests and evaluations, headless
|
|
8
|
+
// mallory machine import|export|lint|otel|serve ...
|
|
9
|
+
// `step` is a terminal stepper on the headless runner: it drives the pane's machine with recorded replies (or the random walk), offline. On a TTY it
|
|
10
|
+
// waits for you (Enter steps, r runs on, q quits); with --steps, --run or no TTY it is scriptable: one line per step, or one JSON object per trace
|
|
11
|
+
// event with --json, and the exit status says how the run ended (0 a terminal state or HALT, 1 any other halt, 2 usage). A model that needs a key or a
|
|
12
|
+
// network is not run here (use mallory run); a gated state is denied unless you pass --approve, because with nobody to ask the run fails closed.
|
|
13
|
+
import { readFile, writeFile, readdir, stat, access } from "node:fs/promises";
|
|
14
|
+
import { createInterface } from "node:readline";
|
|
15
|
+
import { basename, dirname, join } from "node:path";
|
|
16
|
+
import { importCanvas, exportCanvas, formatForName } from "../formats/registry.js";
|
|
17
|
+
import { compile } from "../machine/tape.js";
|
|
18
|
+
import { createDriver } from "../machine/drive.js";
|
|
19
|
+
import { makeProposer } from "../machine/propose.js";
|
|
20
|
+
import { randomPropose } from "../machine/random.js";
|
|
21
|
+
import { providerIdentity, serializeTrace, parseTrace, replayTrace, inspectTrace, continueFrom, diffRuns } from "../machine/trace.js";
|
|
22
|
+
import { otlpText } from "../machine/otel.js";
|
|
23
|
+
import { importLlmtm, exportLlmtm, safeImportedPane } from "../machine/llmtm.js";
|
|
24
|
+
import { lintMachine, lintText } from "../machine/lint.js";
|
|
25
|
+
import { diffMachines, mergeMachines, forkMachine } from "../machine/diff.js";
|
|
26
|
+
import { TEMPLATE_NAMES, templateList, scaffold } from "../machine/templates.js";
|
|
27
|
+
import { currentFormat } from "../model/legacy-viaframe.js";
|
|
28
|
+
|
|
29
|
+
export const MACHINE_HELP = `mallory machine: a machine pane from the terminal.
|
|
30
|
+
|
|
31
|
+
Usage:
|
|
32
|
+
mallory machine validate <canvas> [--pane name]
|
|
33
|
+
check the definition (every machine pane without --pane); exit 1 when it can't run
|
|
34
|
+
mallory machine step <canvas> [options] step or run a machine pane offline
|
|
35
|
+
mallory machine run <canvas> [options] run a machine pane to a halt (step --run)
|
|
36
|
+
mallory machine init <template> [-o file] [--id id] [--title text] [--force]
|
|
37
|
+
a new canvas with a starter machine (${TEMPLATE_NAMES.join(", ")})
|
|
38
|
+
mallory machine fork <canvas> <dest> [--pane name] [--id id] [--note text] [--force]
|
|
39
|
+
a copy of the machine under a new id, with a provenance note
|
|
40
|
+
mallory machine diff <a> <b> [--pane name] [--json]
|
|
41
|
+
the changed paths between two machines (states, prompts, tape, schema)
|
|
42
|
+
mallory machine merge <base> <ours> <theirs> [--pane name] [-o out] [--json]
|
|
43
|
+
a three-way merge; any conflict is listed and nothing is written
|
|
44
|
+
mallory machine trace <command> ... trace files (mallory machine trace --help)
|
|
45
|
+
mallory machine bench <canvas> [--test name] [--out results.json]
|
|
46
|
+
run the canvas's tests and evaluations headless
|
|
47
|
+
mallory machine suite <canvas|dir> ... bench every canvas (a directory: its canvases that have tests)
|
|
48
|
+
mallory machine report <results.json> ... read bench results back, as text
|
|
49
|
+
mallory machine serve <canvas> [options] mallory serve (a machine canvas is served like any other)
|
|
50
|
+
mallory machine import <llmtm.yaml> [files] [-o out.mallory.json]
|
|
51
|
+
read a llmtm/v1 machine (name its prompt packs and children after it)
|
|
52
|
+
mallory machine export <canvas> [--pane name] [-o file.yaml]
|
|
53
|
+
write a machine pane as llmtm/v1
|
|
54
|
+
mallory machine lint <canvas> [--pane name] advice on the definition
|
|
55
|
+
mallory machine otel <trace.jsonl> [-o out.json]
|
|
56
|
+
a trace file as OpenTelemetry spans (OTLP JSON; a file, nothing is sent)
|
|
57
|
+
|
|
58
|
+
step and run options:
|
|
59
|
+
--pane name The machine pane (needed when the canvas has more than one).
|
|
60
|
+
--steps n Take n steps and stop. --run: go to a halt. With neither, step on a TTY: Enter steps, r runs on, q quits; run goes to a halt.
|
|
61
|
+
--random seed Use the random-walk provider with this seed instead of the pane's recorded replies. --mock: the same with seed 0.
|
|
62
|
+
--script file Replay a JSON list of proposals ({ action, move, nextState }) or recorded replies instead of the pane's own.
|
|
63
|
+
--provider name recorded (the default for a recorded pane) or random. A provider that needs a key or a network is not run here.
|
|
64
|
+
--set-cell id=text | id@file
|
|
65
|
+
Put text in a tape cell before the run starts (repeatable); checked against the cell's limits.
|
|
66
|
+
--approve Approve every gated proposal (--approve-all is the same). --deny: deny them (the default: a gated state halts with kind approval).
|
|
67
|
+
--park-approvals
|
|
68
|
+
Park a gated proposal instead of denying it (needs --trace); continue with mallory machine trace resume <canvas> <trace> --approve.
|
|
69
|
+
--json One JSON object per trace event on stdout.
|
|
70
|
+
--trace file Write the trace (JSON Lines, redacted) here. --otlp file: as OpenTelemetry spans.
|
|
71
|
+
Exit status: 0 terminal state or the machine's own HALT, 1 any other halt, 2 usage.
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
export const TRACE_HELP = `mallory machine trace: trace files of a machine run.
|
|
75
|
+
|
|
76
|
+
Usage:
|
|
77
|
+
mallory machine trace inspect <trace.jsonl> [--json] steps, rejections, approvals, cost, how it ended
|
|
78
|
+
mallory machine trace replay <canvas> <trace.jsonl> [--pane name] [--step n] [--json]
|
|
79
|
+
the run frame by frame on its definition, no model asked
|
|
80
|
+
mallory machine trace fork <canvas> <trace.jsonl> --at n [--edit cell=text] [--proposal file.json] [--trace out] [run options]
|
|
81
|
+
continue a run from frame n (0 is the start) with one cell or the next proposal changed
|
|
82
|
+
mallory machine trace resume <canvas> <trace.jsonl> [--at n] [--approve | --deny] [--trace out] [run options]
|
|
83
|
+
go on with a run that stopped or was parked (from its last frame)
|
|
84
|
+
mallory machine trace tree <dir> [--json] the forks and resumes among the traces in a directory
|
|
85
|
+
mallory machine trace diff <canvas> <a.jsonl> <b.jsonl> [--pane name] [--json]
|
|
86
|
+
two runs by step and by tape
|
|
87
|
+
|
|
88
|
+
fork and resume take the run options of mallory machine run (--run, --steps, --random, --script, --approve...). A trace made on another
|
|
89
|
+
definition than the canvas's is refused (the header holds the definition's hash).
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
const UsageError = class extends Error {};
|
|
93
|
+
/** A machine pane is read from its definition, not its type name. */
|
|
94
|
+
const isMachinePane = (p) => Boolean(p?.machine && typeof p.machine === "object" && !Array.isArray(p.machine));
|
|
95
|
+
|
|
96
|
+
const VALUE_FLAGS = new Set(["--pane", "--steps", "--random", "--trace", "--otlp", "-o", "--output", "--script", "--provider", "--id", "--title", "--note", "--at", "--edit", "--proposal", "--test", "--out", "--step", "--set-cell"]);
|
|
97
|
+
const REPEAT_FLAGS = new Set(["--edit", "--test", "--set-cell"]);
|
|
98
|
+
// Flags llmtm's run takes that would put a key on a command line or reach a network: named so the refusal can say why, and their values are not echoed.
|
|
99
|
+
const NETWORK_FLAGS = new Set(["--ollama", "--anthropic", "--ai-matey", "--external-provider", "--model", "--base-url", "--api-key", "--timeout-ms", "--hub", "--cf-access-client-id", "--cf-access-client-secret"]);
|
|
100
|
+
const NETWORK_VALUE = new Set(["--ai-matey", "--external-provider", "--model", "--base-url", "--api-key", "--timeout-ms", "--hub", "--cf-access-client-id", "--cf-access-client-secret"]);
|
|
101
|
+
|
|
102
|
+
function parse(argv) {
|
|
103
|
+
const o = { args: [], flags: {} };
|
|
104
|
+
for (let i = 0; i < argv.length; i++) {
|
|
105
|
+
const a = argv[i];
|
|
106
|
+
if (a === "--help" || a === "-h") o.help = true;
|
|
107
|
+
else if (VALUE_FLAGS.has(a)) {
|
|
108
|
+
if (i + 1 >= argv.length) throw new UsageError(`${a} needs a value`);
|
|
109
|
+
const key = a === "--output" ? "-o" : a;
|
|
110
|
+
if (REPEAT_FLAGS.has(key)) (o.flags[key] ??= []).push(argv[++i]);
|
|
111
|
+
else o.flags[key] = argv[++i];
|
|
112
|
+
} else if (NETWORK_VALUE.has(a)) {
|
|
113
|
+
o.flags[a] = true;
|
|
114
|
+
i++; // its value is never read or echoed
|
|
115
|
+
} else if (a.startsWith("--")) o.flags[a] = true;
|
|
116
|
+
else o.args.push(a);
|
|
117
|
+
}
|
|
118
|
+
return o;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function loadCanvas(file) {
|
|
122
|
+
let text;
|
|
123
|
+
try {
|
|
124
|
+
text = await readFile(file, "utf8");
|
|
125
|
+
} catch (error) {
|
|
126
|
+
throw new UsageError(`can't read ${file}: ${error.code === "ENOENT" ? "no such file" : error.message}`);
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
return importCanvas(text, { name: file }).doc;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
throw new UsageError(`${file}: ${error.message}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function pick(doc, name) {
|
|
136
|
+
const machines = (doc.panes ?? []).filter(isMachinePane);
|
|
137
|
+
if (name) {
|
|
138
|
+
const p = machines.find((x) => x.name === name || x.id === name);
|
|
139
|
+
if (!p) throw new UsageError(`no machine pane "${name}" (${machines.map((x) => x.name || x.id).join(", ") || "none"})`);
|
|
140
|
+
return p;
|
|
141
|
+
}
|
|
142
|
+
if (machines.length !== 1) throw new UsageError(machines.length ? `name the pane with --pane: ${machines.map((x) => x.name || x.id).join(", ")}` : "this canvas has no machine pane");
|
|
143
|
+
return machines[0];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** A canvas file written in the format its name says (JSON when it says none); an existing file is kept unless --force. */
|
|
147
|
+
async function writeCanvasFile(file, doc, { force = false } = {}) {
|
|
148
|
+
if (!force) {
|
|
149
|
+
const exists = await access(file).then(() => true, () => false);
|
|
150
|
+
if (exists) throw new UsageError(`${file} exists (pass --force to overwrite it)`);
|
|
151
|
+
}
|
|
152
|
+
const format = formatForName(file);
|
|
153
|
+
await writeFile(file, exportCanvas(doc, format?.id ?? "json").text);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const line = (e) => (e.type === "step_committed" ? `step ${e.step}: ${e.proposal.action.kind}${e.proposal.action.text !== undefined ? ` ${JSON.stringify(e.proposal.action.text)}` : ""} -> ${e.after.state}, head ${e.after.head}${e.routedBy ? ` (routed by ${e.routedBy})` : ""}` : e.type === "proposal_rejected" ? `refused (${e.tier}): ${e.reason}` : e.type === "halt" ? `halt (${e.kind}): ${e.reason}` : e.type === "run_meta" ? null : e.type === "tool_call" || e.type === "submachine_run" ? `${e.type === "tool_call" ? "tool" : "submachine"} ${e.tool ?? e.machine}: ${e.outcome}` : e.type.replaceAll("_", " "));
|
|
157
|
+
|
|
158
|
+
// ── validate (LTM-CLI-01) ──
|
|
159
|
+
|
|
160
|
+
async function validateMain(o, { stdout, stderr }) {
|
|
161
|
+
const file = o.args[0];
|
|
162
|
+
if (!file) throw new UsageError("usage: mallory machine validate <canvas>");
|
|
163
|
+
// A canvas whose machine pane is unsound is refused by the importer; for validate that refusal is the answer, not a usage error.
|
|
164
|
+
const text = await readFile(file, "utf8").catch((error) => {
|
|
165
|
+
throw new UsageError(`can't read ${file}: ${error.code === "ENOENT" ? "no such file" : error.message}`);
|
|
166
|
+
});
|
|
167
|
+
let doc;
|
|
168
|
+
try {
|
|
169
|
+
doc = importCanvas(text, { name: file }).doc;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
stderr(`FAILED: ${file} can't be loaded.\n ${error.message}`);
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
174
|
+
const panes = o.flags["--pane"] ? [pick(doc, o.flags["--pane"])] : (doc.panes ?? []).filter(isMachinePane);
|
|
175
|
+
if (!panes.length) throw new UsageError("this canvas has no machine pane");
|
|
176
|
+
const { paneProblems } = await import("../machine/session.js");
|
|
177
|
+
let failed = 0;
|
|
178
|
+
for (const pane of panes) {
|
|
179
|
+
const name = pane.name || pane.id;
|
|
180
|
+
const problems = paneProblems(pane);
|
|
181
|
+
if (problems.length) {
|
|
182
|
+
failed++;
|
|
183
|
+
stderr(`FAILED: ${file}: machine ${name} can't run.`);
|
|
184
|
+
for (const p of problems) stderr(` ${p}`);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const c = compile(pane.machine, { protect: pane.lockedCells });
|
|
188
|
+
stdout(`OK: ${file}: machine ${name} is a sound definition.`);
|
|
189
|
+
stdout(` machine id: ${c.id}${c.title ? ` (${c.title})` : ""}`);
|
|
190
|
+
stdout(` initial state: ${c.initial}`);
|
|
191
|
+
stdout(` states: ${Object.keys(c.states).length} (${Object.keys(c.states).join(", ")}); halting: ${c.halting.join(", ")}`);
|
|
192
|
+
stdout(` tape: ${c.cells.length} cell${c.cells.length === 1 ? "" : "s"} (head at ${c.tape.head}), ${c.tape.mode} / ${c.tape.boundary}`);
|
|
193
|
+
const findings = lintMachine(pane.machine, { protect: pane.lockedCells });
|
|
194
|
+
stdout(` lint: ${findings.length ? `${findings.length} finding${findings.length === 1 ? "" : "s"} (mallory machine lint)` : "no findings"}`);
|
|
195
|
+
}
|
|
196
|
+
return failed ? 1 : 0;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ── run and step (LTM-CLI-02) ──
|
|
200
|
+
|
|
201
|
+
function refuseNetwork(o) {
|
|
202
|
+
const asked = Object.keys(o.flags).filter((f) => NETWORK_FLAGS.has(f));
|
|
203
|
+
if (asked.length) throw new UsageError(`${asked.join(", ")}: a model that needs a key or a network is not run from the terminal, and a key is never taken on a command line. Step offline with --random <seed>, --mock, --script <file> or a recorded pane, or run the canvas with mallory run`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The replies a `--script` file holds: a list of proposals ({ action, move, nextState }) or of recorded replies ({ calls }). */
|
|
207
|
+
async function scriptReplies(file) {
|
|
208
|
+
let list;
|
|
209
|
+
try {
|
|
210
|
+
list = JSON.parse(await readFile(file, "utf8"));
|
|
211
|
+
} catch (error) {
|
|
212
|
+
throw new UsageError(`--script ${file}: ${error.code === "ENOENT" ? "no such file" : error.message}`);
|
|
213
|
+
}
|
|
214
|
+
if (!Array.isArray(list) || !list.length || list.length > 10_000) throw new UsageError(`--script ${file}: a JSON list of proposals, at least one`);
|
|
215
|
+
return list.map((x, i) => {
|
|
216
|
+
if (x && typeof x === "object" && Array.isArray(x.calls)) return x;
|
|
217
|
+
if (x && typeof x === "object" && x.action && typeof x.action === "object") return { calls: [{ name: "propose", args: x }] };
|
|
218
|
+
throw new UsageError(`--script ${file}: entry ${i + 1} is neither a proposal { action, move, nextState } nor a recorded reply { calls }`);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** `--set-cell id=text` or `id@file`, as the `inject` map a run starts from. */
|
|
223
|
+
async function injectFrom(o, base) {
|
|
224
|
+
const out = { ...(base ?? {}) };
|
|
225
|
+
for (const spec of o.flags["--set-cell"] ?? []) {
|
|
226
|
+
const m = /^([^=@]+)([=@])([\s\S]*)$/.exec(spec);
|
|
227
|
+
if (!m) throw new UsageError(`--set-cell ${spec}: use id=text or id@file`);
|
|
228
|
+
out[m[1]] = m[2] === "=" ? m[3] : await readFile(m[3], "utf8").catch((e) => {
|
|
229
|
+
throw new UsageError(`--set-cell ${m[1]}@${m[3]}: ${e.code === "ENOENT" ? "no such file" : e.message}`);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return Object.keys(out).length ? out : undefined;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** What a run of the pane needs, read once: the compiled machine, the settings, the provider (`replyOffset` replies already used), the gate answer. */
|
|
236
|
+
async function prepare(o, doc, pane, { replyOffset = 0 } = {}) {
|
|
237
|
+
refuseNetwork(o);
|
|
238
|
+
const { settingsOf, paneProblems } = await import("../machine/session.js");
|
|
239
|
+
const bad = paneProblems(pane);
|
|
240
|
+
if (bad.length) throw new UsageError(`the machine can't run: ${bad.slice(0, 3).join("; ")}`);
|
|
241
|
+
const s = settingsOf(pane);
|
|
242
|
+
const wanted = o.flags["--provider"];
|
|
243
|
+
if (wanted !== undefined && !["recorded", "random", "mock"].includes(wanted)) throw new UsageError(`--provider ${JSON.stringify(wanted)}: a model that needs a key or a network is not run from the terminal. Use recorded or random (--mock)`);
|
|
244
|
+
const random = o.flags["--random"] !== undefined || o.flags["--mock"] === true || wanted === "random" || wanted === "mock";
|
|
245
|
+
const seedText = o.flags["--random"] !== undefined ? o.flags["--random"] : "0";
|
|
246
|
+
const seed = Number(seedText);
|
|
247
|
+
if (random && !(Number.isInteger(seed) && seed >= 0 && String(seedText).trim() !== "")) throw new UsageError("--random takes a whole number seed");
|
|
248
|
+
const script = o.flags["--script"] !== undefined ? await scriptReplies(o.flags["--script"]) : undefined;
|
|
249
|
+
if (random && script) throw new UsageError("--script and the random walk both choose the provider; pass one");
|
|
250
|
+
const kind = random ? "random" : s.kind;
|
|
251
|
+
if (kind !== "recorded" && kind !== "random") throw new UsageError(`this pane's model is ${kind}: ${kind === "pane" ? "it is a pane wired into the canvas, which the terminal stepper does not run" : "it needs a key or a network, which the terminal does not use"}. Run it with mallory run, or step it offline with --random <seed>, --script <file> or a recorded provider`);
|
|
252
|
+
let propose;
|
|
253
|
+
let replies = script ?? pane.replies;
|
|
254
|
+
if (random) propose = randomPropose({ seed });
|
|
255
|
+
else {
|
|
256
|
+
const { createProvider } = await import("../agent/providers.js");
|
|
257
|
+
const provider = createProvider("recorded", { recorded: replyOffset > 0 && Array.isArray(replies) ? replies.slice(replyOffset) : replies, scope: `${doc.id}|${pane.id}` });
|
|
258
|
+
propose = makeProposer(() => provider);
|
|
259
|
+
}
|
|
260
|
+
const approve = o.flags["--approve"] === true || o.flags["--approve-all"] === true;
|
|
261
|
+
const deny = o.flags["--deny"] === true;
|
|
262
|
+
const park = o.flags["--park-approvals"] === true;
|
|
263
|
+
if (approve && deny) throw new UsageError("--approve and --deny both answer a gated proposal; pass one");
|
|
264
|
+
if (park && (approve || deny)) throw new UsageError("--park-approvals keeps a gated proposal for later; it doesn't go with --approve or --deny");
|
|
265
|
+
if (park && !o.flags["--trace"]) throw new UsageError("--park-approvals needs --trace: the trace file is what mallory machine trace resume continues");
|
|
266
|
+
const gate = approve ? { decision: "approve" } : deny ? { decision: "deny" } : park ? { decision: "park" } : { decision: "none", reason: "a gated proposal and nobody to ask: pass --approve to approve every one, --deny to refuse, or --park-approvals to keep it for later" };
|
|
267
|
+
const llm = random ? { provider: "random", seed } : script ? { provider: "recorded" } : pane.llm ?? { provider: "recorded" };
|
|
268
|
+
return { c: compile(pane.machine, { protect: s.protect }), s, propose, gate, llm, replies, random, seed, script };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const tapeLines = (driver) => driver.current.tape.cells.map((x, i) => `${i === driver.current.tape.head ? ">" : " "}${x.id}[${x.kind}] ${JSON.stringify(x.content)}`).join("\n");
|
|
272
|
+
|
|
273
|
+
function makeDriver(o, prep, pane, { stdout, extra = {} }) {
|
|
274
|
+
const { s, c } = prep;
|
|
275
|
+
return createDriver(c, {
|
|
276
|
+
limits: s.limits,
|
|
277
|
+
restart: s.restart,
|
|
278
|
+
inject: extra.inject ?? s.inject,
|
|
279
|
+
header: { run: `cli-${Date.now().toString(36)}`, provider: providerIdentity(prep.llm, prep.replies), settings: { policy: s.policy, gate: s.gate, ...(s.noApproval.length ? { noApproval: s.noApproval } : {}), canAsk: s.canAsk, restart: s.restart ?? null, parkMs: s.parkMs, limits: { ...s.limits, price: s.limits.price ?? null } } },
|
|
280
|
+
env: {
|
|
281
|
+
propose: prep.propose,
|
|
282
|
+
policy: s.policy,
|
|
283
|
+
gate: s.gate,
|
|
284
|
+
noApproval: s.noApproval,
|
|
285
|
+
approvalTimeoutMs: s.approvalTimeoutMs || undefined,
|
|
286
|
+
canAsk: false,
|
|
287
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
288
|
+
approve: async () => ({ ...prep.gate }),
|
|
289
|
+
},
|
|
290
|
+
onEvent: (e) => {
|
|
291
|
+
if (o.flags["--json"]) stdout(JSON.stringify(e));
|
|
292
|
+
else {
|
|
293
|
+
const text = line(e);
|
|
294
|
+
if (text) stdout(text);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
...extra.driver,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Drive to the end the flags ask for, print the closing lines, write the trace files; the exit status. */
|
|
302
|
+
async function execute(o, { stdout, stderr, stdin = process.stdin, isTTY = Boolean(process.stdin.isTTY) }, driver, { interactive } = {}) {
|
|
303
|
+
const limit = o.flags["--steps"] !== undefined ? Number(o.flags["--steps"]) : undefined;
|
|
304
|
+
if (limit !== undefined && !(Number.isInteger(limit) && limit >= 1)) throw new UsageError("--steps takes a whole number from 1");
|
|
305
|
+
driver.begin();
|
|
306
|
+
if (o.flags["--run"]) await driver.run();
|
|
307
|
+
else if (limit !== undefined) for (let n = 0; n < limit && !driver.current.halted; n++) await driver.step();
|
|
308
|
+
else if (interactive && isTTY) {
|
|
309
|
+
const rl = createInterface({ input: stdin, output: process.stdout });
|
|
310
|
+
// The input ending (Ctrl-D, a closed pipe) is a quit, never a hang.
|
|
311
|
+
const ask = () => new Promise((r) => {
|
|
312
|
+
rl.once("close", () => r("q"));
|
|
313
|
+
rl.question("[enter] step, r run, t tape, q quit > ", r);
|
|
314
|
+
});
|
|
315
|
+
for (;;) {
|
|
316
|
+
if (driver.current.halted) break;
|
|
317
|
+
const a = String(await ask()).trim();
|
|
318
|
+
if (a === "q") break;
|
|
319
|
+
if (a === "r") await driver.run();
|
|
320
|
+
else if (a === "t") stdout(tapeLines(driver));
|
|
321
|
+
else await driver.step();
|
|
322
|
+
}
|
|
323
|
+
rl.close();
|
|
324
|
+
} else await driver.run();
|
|
325
|
+
const r = driver.current;
|
|
326
|
+
if (!o.flags["--json"]) stdout(`${tapeLines(driver)}\nstate ${r.state}, step ${r.step}${r.halted ? `, halted (${r.haltKind}): ${r.haltReason}` : ", not halted"}`);
|
|
327
|
+
for (const [flag, make] of [["--trace", (ev) => serializeTrace(ev)], ["--otlp", (ev) => otlpText(ev, { startMs: Date.now() })]]) {
|
|
328
|
+
if (o.flags[flag]) {
|
|
329
|
+
await writeFile(o.flags[flag], make(driver.events));
|
|
330
|
+
stderr(`mallory: wrote ${o.flags[flag]}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (r.halted && r.haltKind === "parked" && o.flags["--trace"]) stderr(`mallory: parked, waiting for a person. Continue with: mallory machine trace resume <canvas> ${o.flags["--trace"]} --approve (or --deny)`);
|
|
334
|
+
return !r.halted ? 0 : r.haltKind === "terminal" || r.haltKind === "halt" ? 0 : 1;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async function stepMain(o, io, { run = false } = {}) {
|
|
338
|
+
const file = o.args[0];
|
|
339
|
+
if (!file) throw new UsageError(`usage: mallory machine ${run ? "run" : "step"} <canvas>`);
|
|
340
|
+
const doc = await loadCanvas(file);
|
|
341
|
+
const pane = pick(doc, o.flags["--pane"]);
|
|
342
|
+
const prep = await prepare(o, doc, pane);
|
|
343
|
+
let inject;
|
|
344
|
+
try {
|
|
345
|
+
inject = await injectFrom(o, prep.s.inject);
|
|
346
|
+
const driver = makeDriver(o, prep, pane, { stdout: io.stdout, extra: { inject } });
|
|
347
|
+
return await execute(o, io, driver, { interactive: !run });
|
|
348
|
+
} catch (error) {
|
|
349
|
+
if (error instanceof UsageError) throw error;
|
|
350
|
+
if (inject !== undefined && /cell|inject|content/i.test(error.message)) throw new UsageError(`--set-cell: ${error.message}`);
|
|
351
|
+
throw error;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async function importMain(o, { stdout, stderr }) {
|
|
356
|
+
const [file, ...rest] = o.args;
|
|
357
|
+
if (!file) throw new UsageError("usage: mallory machine import <llmtm.yaml> [pack or child files...]");
|
|
358
|
+
const files = {};
|
|
359
|
+
for (const extra of [file, ...rest]) files[basename(extra)] = await readFile(extra, "utf8").catch((e) => {
|
|
360
|
+
throw new UsageError(`can't read ${extra}: ${e.message}`);
|
|
361
|
+
});
|
|
362
|
+
// Files the machine names that sit beside it are found without being listed.
|
|
363
|
+
const withNeighbours = async (text, dir) => {
|
|
364
|
+
for (const m of text.matchAll(/(?:^|\s)-?\s*(?:machine:\s*)?["']?(\.{1,2}\/[\w./-]+\.ya?ml)["']?/gm)) {
|
|
365
|
+
const name = basename(m[1]);
|
|
366
|
+
if (files[name] === undefined) {
|
|
367
|
+
try {
|
|
368
|
+
files[name] = await readFile(join(dir, m[1]), "utf8");
|
|
369
|
+
await withNeighbours(files[name], dirname(join(dir, m[1])));
|
|
370
|
+
} catch {
|
|
371
|
+
/* reported by the importer as a missing file */
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
await withNeighbours(files[basename(file)], dirname(file));
|
|
377
|
+
const r = importLlmtm(files[basename(file)], { files, name: file });
|
|
378
|
+
for (const n of r.notes) stderr(`mallory: ${n}`);
|
|
379
|
+
if (!r.ok) {
|
|
380
|
+
for (const p of r.problems) stderr(`mallory: ${file}: ${p}`);
|
|
381
|
+
return 1;
|
|
382
|
+
}
|
|
383
|
+
const panes = [];
|
|
384
|
+
let y = 0;
|
|
385
|
+
const add = (res, name) => {
|
|
386
|
+
const inputs = [];
|
|
387
|
+
for (const child of res.children ?? []) inputs.push({ name: child.name, source: add({ pane: child.pane, children: child.children ?? [] }, child.name) });
|
|
388
|
+
const id = `m${panes.length + 1}`;
|
|
389
|
+
// The same strip the page's import applies (S3): a file does not loosen the person's guards.
|
|
390
|
+
const safe = safeImportedPane(res.pane);
|
|
391
|
+
for (const n of safe.notes) stderr(`mallory: ${res.pane.machine.id}: ${n}`);
|
|
392
|
+
panes.push({ id, type: "machine", name: name ?? res.pane.machine.title ?? res.pane.machine.id, rect: { x: 0, y: (y += 700) - 700, width: 560 }, inputs, ...safe.pane });
|
|
393
|
+
return id;
|
|
394
|
+
};
|
|
395
|
+
add(r, r.pane.machine.id);
|
|
396
|
+
const canvas = { format: "mallory-canvas", version: 2, id: `llmtm-${r.pane.machine.id}`, name: r.pane.machine.title || r.pane.machine.id, panes };
|
|
397
|
+
const text = `${JSON.stringify(canvas, null, 2)}\n`;
|
|
398
|
+
if (o.flags["-o"]) {
|
|
399
|
+
await writeFile(o.flags["-o"], text);
|
|
400
|
+
stderr(`mallory: wrote ${o.flags["-o"]}`);
|
|
401
|
+
} else stdout(text.trimEnd());
|
|
402
|
+
return 0;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async function exportMain(o, { stdout, stderr }) {
|
|
406
|
+
const doc = await loadCanvas(o.args[0] ?? "");
|
|
407
|
+
const pane = pick(doc, o.flags["--pane"]);
|
|
408
|
+
const collect = (p) => (p.inputs ?? []).flatMap((i) => {
|
|
409
|
+
const src = doc.panes.find((x) => x.id === i.source);
|
|
410
|
+
return isMachinePane(src) ? [{ name: i.name, pane: src, children: collect(src) }] : [];
|
|
411
|
+
});
|
|
412
|
+
const out = exportLlmtm(pane, { children: collect(pane) });
|
|
413
|
+
if (!out.ok) {
|
|
414
|
+
for (const p of out.problems) stderr(`mallory: ${p}`);
|
|
415
|
+
return 1;
|
|
416
|
+
}
|
|
417
|
+
if (o.flags["-o"]) {
|
|
418
|
+
await writeFile(o.flags["-o"], out.text);
|
|
419
|
+
for (const [name, text] of Object.entries(out.files)) await writeFile(join(dirname(o.flags["-o"]), name), text);
|
|
420
|
+
stderr(`mallory: wrote ${o.flags["-o"]}${Object.keys(out.files).length ? ` and ${Object.keys(out.files).length} child file(s)` : ""}`);
|
|
421
|
+
} else stdout(out.text.trimEnd());
|
|
422
|
+
return 0;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
async function otelMain(o, { stdout, stderr }) {
|
|
426
|
+
if (!o.args[0]) throw new UsageError("usage: mallory machine otel <trace.jsonl>");
|
|
427
|
+
const text = await readFile(o.args[0], "utf8").catch((e) => {
|
|
428
|
+
throw new UsageError(`can't read ${o.args[0]}: ${e.message}`);
|
|
429
|
+
});
|
|
430
|
+
const { parseTrace } = await import("../machine/trace.js");
|
|
431
|
+
const read = parseTrace(text);
|
|
432
|
+
if (read.problems.length && !read.events.length) throw new UsageError(`${o.args[0]}: ${read.problems[0]}`);
|
|
433
|
+
const out = otlpText(read.events, { startMs: Date.now() });
|
|
434
|
+
if (o.flags["-o"]) {
|
|
435
|
+
await writeFile(o.flags["-o"], out);
|
|
436
|
+
stderr(`mallory: wrote ${o.flags["-o"]}`);
|
|
437
|
+
} else stdout(out.trimEnd());
|
|
438
|
+
return 0;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ── init, fork, diff, merge (LTM-YAML-08..11, LTM-CLI-05) ──
|
|
442
|
+
|
|
443
|
+
async function initMain(o, { stdout, stderr }) {
|
|
444
|
+
const name = o.args[0];
|
|
445
|
+
if (!name) {
|
|
446
|
+
for (const t of templateList()) stdout(`${t.name.padEnd(16)} ${t.summary}`);
|
|
447
|
+
return 0;
|
|
448
|
+
}
|
|
449
|
+
let s;
|
|
450
|
+
try {
|
|
451
|
+
s = scaffold(name, { id: o.flags["--id"], title: o.flags["--title"] });
|
|
452
|
+
} catch (error) {
|
|
453
|
+
throw new UsageError(error.message);
|
|
454
|
+
}
|
|
455
|
+
const doc = {
|
|
456
|
+
format: "mallory-canvas",
|
|
457
|
+
version: 2,
|
|
458
|
+
id: s.machine.id,
|
|
459
|
+
name: s.machine.title || s.machine.id,
|
|
460
|
+
panes: [{ id: "m", type: "machine", name: "machine", rect: { x: 0, y: 0, width: 560 }, inputs: [], llm: s.llm, capSteps: s.capSteps, machine: s.machine, replies: s.replies }],
|
|
461
|
+
};
|
|
462
|
+
const out = o.flags["-o"] ?? `${s.machine.id}.mallory.json`;
|
|
463
|
+
await writeCanvasFile(out, doc, { force: o.flags["--force"] === true });
|
|
464
|
+
stderr(`mallory: wrote ${out} (template ${name})`);
|
|
465
|
+
stdout(`Next: mallory machine validate ${out} then mallory machine run ${out}`);
|
|
466
|
+
return 0;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async function forkMain(o, { stdout, stderr }) {
|
|
470
|
+
const [file, dest] = o.args;
|
|
471
|
+
if (!file || !dest) throw new UsageError("usage: mallory machine fork <canvas> <dest> [--id id] [--note text]");
|
|
472
|
+
const doc = await loadCanvas(file);
|
|
473
|
+
const pane = pick(doc, o.flags["--pane"]);
|
|
474
|
+
let machine;
|
|
475
|
+
try {
|
|
476
|
+
machine = forkMachine(pane.machine, { id: o.flags["--id"], note: o.flags["--note"] });
|
|
477
|
+
} catch (error) {
|
|
478
|
+
throw new UsageError(error.message);
|
|
479
|
+
}
|
|
480
|
+
// The fork keeps the pane's settings (model, recorded replies, caps) and none of its wiring: it is a new canvas with one machine.
|
|
481
|
+
const { inputs: _inputs, rect: _rect, ...rest } = structuredClone(pane);
|
|
482
|
+
const forked = { format: "mallory-canvas", version: 2, id: machine.id, name: machine.title || machine.id, panes: [{ ...rest, inputs: [], rect: { x: 0, y: 0, width: 560 }, machine }] };
|
|
483
|
+
await writeCanvasFile(dest, forked, { force: o.flags["--force"] === true });
|
|
484
|
+
stderr(`mallory: wrote ${dest} (${machine.id}, forked from ${pane.machine.id ?? "machine"})`);
|
|
485
|
+
stdout(machine.description.split("\n").at(-1));
|
|
486
|
+
return 0;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const shown = (v) => (v === undefined ? "" : JSON.stringify(v));
|
|
490
|
+
|
|
491
|
+
async function twoMachines(o, names) {
|
|
492
|
+
const docs = await Promise.all(names.map((f) => loadCanvas(f)));
|
|
493
|
+
return docs.map((d) => pick(d, o.flags["--pane"]));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
async function diffDefMain(o, { stdout }) {
|
|
497
|
+
const [a, b] = o.args;
|
|
498
|
+
if (!a || !b) throw new UsageError("usage: mallory machine diff <a> <b>");
|
|
499
|
+
const [pa, pb] = await twoMachines(o, [a, b]);
|
|
500
|
+
const changes = diffMachines(pa.machine, pb.machine);
|
|
501
|
+
if (o.flags["--json"]) stdout(JSON.stringify({ changes }, null, 2));
|
|
502
|
+
else if (!changes.length) stdout("no differences");
|
|
503
|
+
else for (const c of changes) stdout(`${c.kind === "added" ? "+" : c.kind === "removed" ? "-" : "~"} ${c.path}${c.kind === "changed" ? `: ${shown(c.before)} -> ${shown(c.after)}` : c.kind === "added" ? `: ${shown(c.after)}` : ""}`);
|
|
504
|
+
return changes.length ? 1 : 0;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
async function mergeMain(o, { stdout, stderr }) {
|
|
508
|
+
const [b, ours, theirs] = o.args;
|
|
509
|
+
if (!b || !ours || !theirs) throw new UsageError("usage: mallory machine merge <base> <ours> <theirs> [-o out]");
|
|
510
|
+
const [pb, po, pt] = await twoMachines(o, [b, ours, theirs]);
|
|
511
|
+
const r = mergeMachines(pb.machine, po.machine, pt.machine);
|
|
512
|
+
if (o.flags["--json"]) stdout(JSON.stringify({ ok: r.ok, conflicts: r.conflicts, changes: r.changes, ...(r.ok ? { merged: r.merged } : {}) }, null, 2));
|
|
513
|
+
if (!r.ok) {
|
|
514
|
+
if (!o.flags["--json"]) {
|
|
515
|
+
for (const c of r.conflicts) stdout(`conflict (${c.type}) ${c.path}${c.message ? `: ${c.message}` : `: base ${shown(c.base) || "(none)"}, ours ${shown(c.ours) || "(removed)"}, theirs ${shown(c.theirs) || "(removed)"}`}`);
|
|
516
|
+
}
|
|
517
|
+
stderr(`mallory: ${r.conflicts.length} conflict${r.conflicts.length === 1 ? "" : "s"}; nothing was written. Resolve them in one of the files and merge again.`);
|
|
518
|
+
return 1;
|
|
519
|
+
}
|
|
520
|
+
const doc = await loadCanvas(ours);
|
|
521
|
+
const pane = pick(doc, o.flags["--pane"]);
|
|
522
|
+
pane.machine = r.merged;
|
|
523
|
+
if (o.flags["-o"]) {
|
|
524
|
+
await writeCanvasFile(o.flags["-o"], doc, { force: true });
|
|
525
|
+
stderr(`mallory: wrote ${o.flags["-o"]} (${r.changes.theirs} change${r.changes.theirs === 1 ? "" : "s"} of theirs, ${r.changes.ours} of ours)`);
|
|
526
|
+
} else if (!o.flags["--json"]) stdout(`merged cleanly: ${r.changes.ours} change${r.changes.ours === 1 ? "" : "s"} of ours and ${r.changes.theirs} of theirs (pass -o to write it)`);
|
|
527
|
+
return 0;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// ── trace files (LTM-CLI-03) ──
|
|
531
|
+
|
|
532
|
+
async function readTrace(file) {
|
|
533
|
+
const text = await readFile(file, "utf8").catch((e) => {
|
|
534
|
+
throw new UsageError(`can't read ${file}: ${e.code === "ENOENT" ? "no such file" : e.message}`);
|
|
535
|
+
});
|
|
536
|
+
const read = parseTrace(text);
|
|
537
|
+
if (read.problems.length && !read.events.length) throw new UsageError(`${file}: ${read.problems[0]}`);
|
|
538
|
+
return read;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/** The canvas's machine and a trace read for it: `{ pane, c, events, doc }`. */
|
|
542
|
+
async function canvasAndTrace(o, canvasFile, traceFile) {
|
|
543
|
+
if (!canvasFile || !traceFile) throw new UsageError("name the canvas the trace was recorded from, then the trace");
|
|
544
|
+
const doc = await loadCanvas(canvasFile);
|
|
545
|
+
const pane = pick(doc, o.flags["--pane"]);
|
|
546
|
+
const { settingsOf, paneProblems } = await import("../machine/session.js");
|
|
547
|
+
const bad = paneProblems(pane);
|
|
548
|
+
if (bad.length) throw new UsageError(`the machine can't run: ${bad.slice(0, 3).join("; ")}`);
|
|
549
|
+
const read = await readTrace(traceFile);
|
|
550
|
+
return { doc, pane, events: read.events, problems: read.problems, c: compile(pane.machine, { protect: settingsOf(pane).protect } ) };
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
async function traceInspect(o, { stdout }) {
|
|
554
|
+
if (!o.args[0]) throw new UsageError("usage: mallory machine trace inspect <trace.jsonl>");
|
|
555
|
+
const read = await readTrace(o.args[0]);
|
|
556
|
+
const sum = inspectTrace(read.events);
|
|
557
|
+
if (o.flags["--json"]) {
|
|
558
|
+
stdout(JSON.stringify({ ...sum, problems: read.problems }, null, 2));
|
|
559
|
+
return 0;
|
|
560
|
+
}
|
|
561
|
+
stdout(`run ${sum.run ?? "?"} of machine ${sum.machine ?? "?"}${sum.parent ? ` (${sum.parent.resumed ? "resumes" : "forks"} ${sum.parent.run} at frame ${sum.parent.at})` : ""}`);
|
|
562
|
+
stdout(`definition ${sum.definition ?? "?"}`);
|
|
563
|
+
stdout(`${sum.steps} step${sum.steps === 1 ? "" : "s"}, ${sum.rejections} refused, ${sum.approvals} approval${sum.approvals === 1 ? "" : "s"} (${sum.denied} denied), ${sum.personEdits} edit${sum.personEdits === 1 ? "" : "s"}, ${sum.resumes} resume${sum.resumes === 1 ? "" : "s"}, ${sum.restarts} restart${sum.restarts === 1 ? "" : "s"}`);
|
|
564
|
+
stdout(`${sum.modelCalls} model call${sum.modelCalls === 1 ? "" : "s"}, ${sum.inputTokens} tokens in, ${sum.outputTokens} out, cost ${sum.cost}`);
|
|
565
|
+
stdout(`ended: ${sum.ended ? `${sum.ended.kind}: ${sum.ended.reason}` : "not recorded"}`);
|
|
566
|
+
for (const e of read.events) {
|
|
567
|
+
const text = line(e);
|
|
568
|
+
if (text) stdout(` ${text}`);
|
|
569
|
+
}
|
|
570
|
+
for (const p of read.problems) stdout(`problem: ${p}`);
|
|
571
|
+
return 0;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
async function traceReplay(o, { stdout }) {
|
|
575
|
+
const { c, events } = await canvasAndTrace(o, o.args[0], o.args[1]);
|
|
576
|
+
const r = replayTrace(c, events);
|
|
577
|
+
const only = o.flags["--step"] !== undefined ? Number(o.flags["--step"]) : undefined;
|
|
578
|
+
if (only !== undefined && !(Number.isInteger(only) && only >= 0 && only < r.frames.length)) throw new UsageError(`--step takes a frame from 0 to ${Math.max(0, r.frames.length - 1)}`);
|
|
579
|
+
const frames = only === undefined ? r.frames : [r.frames[only]];
|
|
580
|
+
if (o.flags["--json"]) stdout(JSON.stringify({ definitionMatches: r.definitionMatches, problems: r.problems, frames }, null, 2));
|
|
581
|
+
else {
|
|
582
|
+
if (!r.definitionMatches) stdout("note: the trace was recorded on a different definition than this canvas's (the hashes differ)");
|
|
583
|
+
for (const f of frames) {
|
|
584
|
+
stdout(`frame ${f.index} (${f.label}): state ${f.state}, head ${f.head}, step ${f.step}${f.halted ? ", the run ends here" : ""}${f.changed?.length ? `; changed ${f.changed.map((x) => (typeof x === "string" ? x : x.id ?? JSON.stringify(x))).join(", ")}` : ""}`);
|
|
585
|
+
if (only !== undefined) for (const [i, cell] of f.tape.entries()) stdout(` ${i === f.head ? ">" : " "}${cell.id}[${cell.kind}] ${JSON.stringify(cell.content)}`);
|
|
586
|
+
}
|
|
587
|
+
for (const p of r.problems) stdout(`problem: ${p}`);
|
|
588
|
+
}
|
|
589
|
+
return r.problems.length ? 1 : 0;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
async function traceContinue(o, io, { resume }) {
|
|
593
|
+
const { doc, pane, events, c } = await canvasAndTrace(o, o.args[0], o.args[1]);
|
|
594
|
+
const replay = replayTrace(c, events);
|
|
595
|
+
const atFlag = o.flags["--at"];
|
|
596
|
+
let at = atFlag === undefined ? (resume ? replay.frames.length - 1 : undefined) : Number(atFlag);
|
|
597
|
+
if (at === undefined || !Number.isInteger(at)) throw new UsageError(resume ? "--at takes a frame number" : "fork needs --at <frame> (0 is the start of the run)");
|
|
598
|
+
let edit;
|
|
599
|
+
const edits = o.flags["--edit"] ?? [];
|
|
600
|
+
if (edits.length > 1) throw new UsageError("--edit takes one cell: --edit cell=text");
|
|
601
|
+
if (edits.length) {
|
|
602
|
+
const m = /^([^=]+)=([\s\S]*)$/.exec(edits[0]);
|
|
603
|
+
if (!m) throw new UsageError("--edit takes cell=text");
|
|
604
|
+
edit = { cell: m[1], content: m[2] };
|
|
605
|
+
}
|
|
606
|
+
let proposal;
|
|
607
|
+
if (o.flags["--proposal"] !== undefined) {
|
|
608
|
+
try {
|
|
609
|
+
proposal = JSON.parse(await readFile(o.flags["--proposal"], "utf8"));
|
|
610
|
+
} catch (error) {
|
|
611
|
+
throw new UsageError(`--proposal ${o.flags["--proposal"]}: ${error.code === "ENOENT" ? "no such file" : error.message}`);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
if (resume && (edit || proposal)) throw new UsageError("resume goes on as it was; to change a cell or the next proposal, fork");
|
|
615
|
+
let k;
|
|
616
|
+
try {
|
|
617
|
+
k = continueFrom(c, events, at, { edit, proposal, resume, why: resume ? "continued from the terminal" : undefined });
|
|
618
|
+
} catch (error) {
|
|
619
|
+
throw new UsageError(error.message);
|
|
620
|
+
}
|
|
621
|
+
const prep = await prepare(o, doc, pane, { replyOffset: k.replyOffset });
|
|
622
|
+
const inject = await injectFrom(o, k.inject);
|
|
623
|
+
const driver = makeDriver(o, prep, pane, {
|
|
624
|
+
stdout: io.stdout,
|
|
625
|
+
extra: { inject, driver: { from: { run: k.run, ...(resume ? { usage: k.usage } : {}) }, continuation: { events: k.events, parent: k.parent }, nextProposal: k.nextProposal } },
|
|
626
|
+
});
|
|
627
|
+
const goes = o.flags["--run"] || o.flags["--steps"] !== undefined;
|
|
628
|
+
if (!goes && !o.flags["--trace"]) throw new UsageError(`${resume ? "resume" : "fork"} needs something to do: --run, --steps n, or --trace <file> to write the ${resume ? "continued" : "forked"} trace`);
|
|
629
|
+
if (!goes) {
|
|
630
|
+
driver.begin();
|
|
631
|
+
await writeFile(o.flags["--trace"], serializeTrace(driver.events));
|
|
632
|
+
io.stderr(`mallory: wrote ${o.flags["--trace"]} (${driver.events.length} events, at frame ${at} of ${events[0]?.run ?? "the run"})`);
|
|
633
|
+
return 0;
|
|
634
|
+
}
|
|
635
|
+
return await execute({ ...o, flags: { ...o.flags, "--run": o.flags["--run"] } }, io, driver, { interactive: false });
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
async function traceTree(o, { stdout }) {
|
|
639
|
+
const dir = o.args[0] ?? ".";
|
|
640
|
+
const names = (await readdir(dir).catch((e) => {
|
|
641
|
+
throw new UsageError(`can't read ${dir}: ${e.message}`);
|
|
642
|
+
})).filter((n) => n.endsWith(".jsonl")).sort();
|
|
643
|
+
const runs = [];
|
|
644
|
+
for (const n of names) {
|
|
645
|
+
const text = await readFile(join(dir, n), "utf8").catch(() => "");
|
|
646
|
+
const read = parseTrace(text);
|
|
647
|
+
const h = read.events[0];
|
|
648
|
+
if (!h || h.type !== "run_meta" || !h.run) continue;
|
|
649
|
+
const sum = inspectTrace(read.events);
|
|
650
|
+
runs.push({ file: n, run: h.run, machine: h.machine, parent: h.parent?.run, at: h.parent?.at, resumed: Boolean(h.parent?.resumed), steps: sum.steps, ended: sum.ended?.kind ?? "not recorded", children: [] });
|
|
651
|
+
}
|
|
652
|
+
const byRun = new Map(runs.map((r) => [r.run, r]));
|
|
653
|
+
const roots = [];
|
|
654
|
+
for (const r of runs) {
|
|
655
|
+
const p = r.parent ? byRun.get(r.parent) : undefined;
|
|
656
|
+
if (p && p !== r) p.children.push(r);
|
|
657
|
+
else roots.push(r);
|
|
658
|
+
}
|
|
659
|
+
if (o.flags["--json"]) {
|
|
660
|
+
stdout(JSON.stringify({ roots }, null, 2));
|
|
661
|
+
return 0;
|
|
662
|
+
}
|
|
663
|
+
if (!roots.length) stdout(`no machine traces in ${dir}`);
|
|
664
|
+
const print = (r, depth) => {
|
|
665
|
+
stdout(`${" ".repeat(depth)}${depth ? (r.resumed ? "resumes at " : "forks at ") + `frame ${r.at}: ` : ""}${r.file} (${r.machine}, ${r.steps} step${r.steps === 1 ? "" : "s"}, ${r.ended})`);
|
|
666
|
+
for (const c of r.children) print(c, depth + 1);
|
|
667
|
+
};
|
|
668
|
+
for (const r of roots) print(r, 0);
|
|
669
|
+
return 0;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
async function traceDiff(o, { stdout }) {
|
|
673
|
+
const [canvas, fa, fb] = o.args;
|
|
674
|
+
if (!canvas || !fa || !fb) throw new UsageError("usage: mallory machine trace diff <canvas> <a.jsonl> <b.jsonl>");
|
|
675
|
+
const x = await canvasAndTrace(o, canvas, fa);
|
|
676
|
+
const read = await readTrace(fb);
|
|
677
|
+
const d = diffRuns(x.c, { events: x.events }, { events: read.events });
|
|
678
|
+
if (o.flags["--json"]) stdout(JSON.stringify(d, null, 2));
|
|
679
|
+
else {
|
|
680
|
+
stdout(d.identical ? "the runs are identical" : `the runs differ: ${d.shared} step${d.shared === 1 ? "" : "s"} in common`);
|
|
681
|
+
if (!d.definitions.same) stdout("note: the runs were recorded on different definitions");
|
|
682
|
+
if (d.firstDivergent) {
|
|
683
|
+
stdout(`first divergence at step ${d.firstDivergent.step}: ${d.firstDivergent.why}`);
|
|
684
|
+
stdout(` a: ${d.firstDivergent.a ?? "(ended)"}`);
|
|
685
|
+
stdout(` b: ${d.firstDivergent.b ?? "(ended)"}`);
|
|
686
|
+
}
|
|
687
|
+
for (const row of d.table.filter((t) => t.changed)) stdout(`${row.metric}: ${row.a} -> ${row.b}`);
|
|
688
|
+
for (const t of d.tape.final) stdout(`tape ${t.kind} ${t.id}${t.field ? `.${t.field}` : ""}: ${shown(t.before)}${t.kind === "changed" ? ` -> ${shown(t.after)}` : t.kind === "added" ? shown(t.after) : ""}`);
|
|
689
|
+
for (const p of d.problems) stdout(`problem: ${p}`);
|
|
690
|
+
}
|
|
691
|
+
return d.identical ? 0 : 1;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
async function traceMain(argv, io) {
|
|
695
|
+
const [sub, ...rest] = argv;
|
|
696
|
+
const o = parse(rest);
|
|
697
|
+
if (!sub || sub === "--help" || sub === "-h" || o.help) {
|
|
698
|
+
io.stdout(TRACE_HELP.trimEnd());
|
|
699
|
+
return sub ? 0 : 2;
|
|
700
|
+
}
|
|
701
|
+
if (sub === "inspect") return await traceInspect(o, io);
|
|
702
|
+
if (sub === "replay") return await traceReplay(o, io);
|
|
703
|
+
if (sub === "fork") return await traceContinue(o, io, { resume: false });
|
|
704
|
+
if (sub === "resume") return await traceContinue(o, io, { resume: true });
|
|
705
|
+
if (sub === "tree") return await traceTree(o, io);
|
|
706
|
+
if (sub === "diff") return await traceDiff(o, io);
|
|
707
|
+
throw new UsageError(`unknown trace command "${sub}" (inspect, replay, fork, resume, tree, diff)`);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// ── bench, suite, report (LTM-CLI-04): the canvas's own tests and evaluations, headless ──
|
|
711
|
+
|
|
712
|
+
const CANVAS_EXT = /\.mallory\.(json|ya?ml|md)$/i;
|
|
713
|
+
|
|
714
|
+
/** Run `mallory test` on one canvas and read its JSON report: `{ file, code, report?, error? }`. */
|
|
715
|
+
async function benchOne(file, tests, io) {
|
|
716
|
+
const { main } = await import("./cli.js");
|
|
717
|
+
const out = [];
|
|
718
|
+
const err = [];
|
|
719
|
+
const argv = ["test", file, "--json", ...tests.flatMap((t) => ["--test", t])];
|
|
720
|
+
const code = await main(argv, { ...io, stdout: (t) => out.push(t), stderr: (t) => err.push(t) });
|
|
721
|
+
let report;
|
|
722
|
+
try {
|
|
723
|
+
report = JSON.parse(out.join("\n"));
|
|
724
|
+
} catch {
|
|
725
|
+
/* a usage error prints no report */
|
|
726
|
+
}
|
|
727
|
+
return { file, code, ...(report ? { report } : {}), ...(err.length ? { error: err.join("\n") } : {}) };
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
function benchLines(r, stdout) {
|
|
731
|
+
if (!r.report) {
|
|
732
|
+
stdout(`${r.code === 2 ? "skipped" : "error"} ${r.file}${r.error ? `: ${r.error.split("\n")[0]}` : ""}`);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
stdout(`${r.report.pass ? "PASS" : "FAIL"} ${r.file}: ${r.report.passed} passed, ${r.report.failed} failed`);
|
|
736
|
+
for (const t of r.report.results ?? []) {
|
|
737
|
+
stdout(` ${t.pass ? "✓" : "✗"} ${t.name}`);
|
|
738
|
+
if (!t.pass) {
|
|
739
|
+
if (t.error) stdout(` ${t.error}`);
|
|
740
|
+
for (const c of t.checks ?? []) if (!c.pass) stdout(` ${c.pane}: ${c.message}`);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
async function benchMain(o, io, { files, summary = files.length > 1 }) {
|
|
746
|
+
const results = [];
|
|
747
|
+
for (const f of files) results.push(await benchOne(f, o.flags["--test"] ?? [], io));
|
|
748
|
+
for (const r of results) benchLines(r, io.stdout);
|
|
749
|
+
const ran = results.filter((r) => r.report);
|
|
750
|
+
const failed = results.filter((r) => r.code === 1 || (r.code !== 0 && r.code !== 2 && !r.report));
|
|
751
|
+
const hard = results.filter((r) => r.code === 2 && files.length === 1);
|
|
752
|
+
if (summary) io.stdout(`${ran.length} of ${files.length} canvas${files.length === 1 ? "" : "es"} ran: ${ran.filter((r) => r.report.pass).length} passed, ${ran.filter((r) => !r.report.pass).length} failed`);
|
|
753
|
+
if (o.flags["-o"] || o.flags["--out"]) {
|
|
754
|
+
const out = o.flags["--out"] ?? o.flags["-o"];
|
|
755
|
+
await writeFile(out, `${JSON.stringify({ format: "mallory-machine-bench", version: 1, results: results.map(({ file, code, report, error }) => ({ file, code, ...(report ? { report } : {}), ...(error ? { error } : {}) })) }, null, 2)}\n`);
|
|
756
|
+
io.stderr(`mallory: wrote ${out}`);
|
|
757
|
+
}
|
|
758
|
+
return failed.length ? 1 : hard.length ? 2 : 0;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
async function canvasesIn(dir) {
|
|
762
|
+
const names = (await readdir(dir)).filter((n) => CANVAS_EXT.test(n)).sort();
|
|
763
|
+
return names.map((n) => join(dir, n));
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
async function suiteMain(o, io) {
|
|
767
|
+
if (!o.args.length) throw new UsageError("usage: mallory machine suite <canvas|dir> ...");
|
|
768
|
+
const files = [];
|
|
769
|
+
for (const a of o.args) {
|
|
770
|
+
const st = await stat(a).catch(() => null);
|
|
771
|
+
if (!st) throw new UsageError(`can't read ${a}: no such file`);
|
|
772
|
+
if (st.isDirectory()) files.push(...(await canvasesIn(a)));
|
|
773
|
+
else files.push(a);
|
|
774
|
+
}
|
|
775
|
+
// Only canvases that hold a machine pane and tests are part of a machine suite.
|
|
776
|
+
const mine = [];
|
|
777
|
+
for (const f of files) {
|
|
778
|
+
try {
|
|
779
|
+
const doc = importCanvas(await readFile(f, "utf8"), { name: f }).doc;
|
|
780
|
+
if ((doc.panes ?? []).some(isMachinePane) && doc.tests?.length) mine.push(f);
|
|
781
|
+
} catch {
|
|
782
|
+
/* not a canvas */
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (!mine.length) throw new UsageError("no canvas with a machine pane and tests in that list");
|
|
786
|
+
return await benchMain(o, io, { files: mine, summary: true });
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
async function reportMain(o, { stdout }) {
|
|
790
|
+
if (!o.args.length) throw new UsageError("usage: mallory machine report <results.json> ...");
|
|
791
|
+
let bad = 0;
|
|
792
|
+
for (const f of o.args) {
|
|
793
|
+
let data;
|
|
794
|
+
try {
|
|
795
|
+
data = JSON.parse(await readFile(f, "utf8"));
|
|
796
|
+
} catch (error) {
|
|
797
|
+
throw new UsageError(`can't read ${f}: ${error.code === "ENOENT" ? "no such file" : error.message}`);
|
|
798
|
+
}
|
|
799
|
+
if (currentFormat(data?.format) !== "mallory-machine-bench" || !Array.isArray(data.results)) throw new UsageError(`${f}: not a bench result file (mallory machine bench --out)`);
|
|
800
|
+
stdout(`${basename(f)}: ${data.results.length} canvas${data.results.length === 1 ? "" : "es"}`);
|
|
801
|
+
for (const r of data.results) {
|
|
802
|
+
benchLines(r, (t) => stdout(` ${t}`));
|
|
803
|
+
if (r.report && !r.report.pass) bad++;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return bad ? 1 : 0;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/** `mallory machine <step|run|validate|...> ...`; resolves the exit status. */
|
|
810
|
+
export async function machineMain(argv, io = {}) {
|
|
811
|
+
const stdout = io.stdout ?? ((t) => process.stdout.write(`${t}\n`));
|
|
812
|
+
const stderr = io.stderr ?? ((t) => process.stderr.write(`${t}\n`));
|
|
813
|
+
try {
|
|
814
|
+
const [sub, ...rest] = argv;
|
|
815
|
+
const o = parse(rest);
|
|
816
|
+
if (!sub || sub === "--help" || sub === "-h" || (o.help && sub !== "trace")) {
|
|
817
|
+
stdout(MACHINE_HELP.trimEnd());
|
|
818
|
+
return sub ? 0 : 2;
|
|
819
|
+
}
|
|
820
|
+
const ctx = { ...io, stdout, stderr };
|
|
821
|
+
if (sub === "step") return await stepMain(o, ctx);
|
|
822
|
+
if (sub === "run") return await stepMain(o, ctx, { run: true });
|
|
823
|
+
if (sub === "validate") return await validateMain(o, ctx);
|
|
824
|
+
if (sub === "init") return await initMain(o, ctx);
|
|
825
|
+
if (sub === "fork") return await forkMain(o, ctx);
|
|
826
|
+
if (sub === "diff") return await diffDefMain(o, ctx);
|
|
827
|
+
if (sub === "merge") return await mergeMain(o, ctx);
|
|
828
|
+
if (sub === "trace") return await traceMain(rest, ctx);
|
|
829
|
+
if (sub === "bench") {
|
|
830
|
+
if (!o.args[0]) throw new UsageError("usage: mallory machine bench <canvas> [--test name] [--out results.json]");
|
|
831
|
+
return await benchMain(o, ctx, { files: [o.args[0]] });
|
|
832
|
+
}
|
|
833
|
+
if (sub === "suite") return await suiteMain(o, ctx);
|
|
834
|
+
if (sub === "report") return await reportMain(o, ctx);
|
|
835
|
+
if (sub === "serve") return await (await import("./serve-cli.js")).serveMain(rest, ctx);
|
|
836
|
+
if (sub === "import") return await importMain(o, ctx);
|
|
837
|
+
if (sub === "export") return await exportMain(o, ctx);
|
|
838
|
+
if (sub === "otel") return await otelMain(o, ctx);
|
|
839
|
+
if (sub === "lint") {
|
|
840
|
+
const doc = await loadCanvas(o.args[0] ?? "");
|
|
841
|
+
const pane = pick(doc, o.flags["--pane"]);
|
|
842
|
+
const found = lintText(lintMachine(pane.machine, { protect: pane.lockedCells }));
|
|
843
|
+
for (const f of found) stdout(f);
|
|
844
|
+
if (!found.length) stdout("no findings");
|
|
845
|
+
return 0;
|
|
846
|
+
}
|
|
847
|
+
throw new UsageError(`unknown machine command "${sub}" (validate, step, run, init, fork, diff, merge, trace, bench, suite, report, serve, import, export, lint, otel)`);
|
|
848
|
+
} catch (error) {
|
|
849
|
+
if (!(error instanceof UsageError)) throw error;
|
|
850
|
+
stderr(`mallory: ${error.message}\nRun mallory machine --help for usage.`);
|
|
851
|
+
return 2;
|
|
852
|
+
}
|
|
853
|
+
}
|