@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,150 @@
|
|
|
1
|
+
// Shader passes, the pure part: the Common tab and Buffer A to D that sit beside a shader's Image pass, the way
|
|
2
|
+
// Shadertoy's tabs do. Nothing here touches WebGL or the DOM; the frame (src/shader/frame.js) draws the passes.
|
|
3
|
+
//
|
|
4
|
+
// A multipass shader is the pane's usual `code` (the Image pass) plus
|
|
5
|
+
//
|
|
6
|
+
// common: "…" GLSL put in front of every pass (functions, constants, structs)
|
|
7
|
+
// buffers: [{ name: "A", code, channels?, format? }] up to four, A to D, each drawn into a texture of its own
|
|
8
|
+
//
|
|
9
|
+
// The passes run in order, Buffer A first and Image last, once per frame. Each pass has channels of its own (the
|
|
10
|
+
// pane's `channels` are the Image pass's): a channel `{ name, buffer: "B" }` reads Buffer B's texture. A buffer that is
|
|
11
|
+
// read by a pass drawn before it, or by itself, is read as it was at the end of the previous frame, and a buffer read by
|
|
12
|
+
// a pass drawn after it is read as it is this frame, so a buffer reading itself is a feedback loop, as in Shadertoy.
|
|
13
|
+
// Buffers are float (RGBA16F, where the GPU can draw to a float texture) unless `format: "byte"` says RGBA8.
|
|
14
|
+
import { BUFFER_NAMES } from "./common.js";
|
|
15
|
+
import { checkChannels, normalizeChannels } from "./channels.js";
|
|
16
|
+
|
|
17
|
+
export { BUFFER_NAMES };
|
|
18
|
+
/** float is RGBA16F (filterable wherever float buffers draw), float32 is RGBA32F (exact, but filtered only where the GPU filters 32-bit floats), byte is RGBA8. */
|
|
19
|
+
export const BUFFER_FORMATS = ["float", "float32", "byte"];
|
|
20
|
+
export const PASS_LIMITS = {
|
|
21
|
+
maxBuffers: BUFFER_NAMES.length,
|
|
22
|
+
maxBufferBytes: 64 * 1024 * 1024, // all the buffers' textures together (each has two: one is drawn into while the other is read)
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Which pass the pane's picture and value come from: the Image pass, or one of the buffers. */
|
|
26
|
+
export const OUTPUTS = ["image", ...BUFFER_NAMES];
|
|
27
|
+
|
|
28
|
+
const BUFFER_KEYS = ["name", "code", "channels", "format"];
|
|
29
|
+
|
|
30
|
+
/** A new buffer's code: it keeps what it drew last frame and fades it, so it shows something at once and says what to change. */
|
|
31
|
+
export const BUFFER_TEMPLATE = "// Buffer pass: drawn into a texture other passes read through a channel { buffer: \"A\" }.\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n fragColor = vec4(fragCoord / u_resolution, 0.5 + 0.5 * sin(u_time), 1.0);\n}";
|
|
32
|
+
|
|
33
|
+
const label = (name) => `Buffer ${name}`;
|
|
34
|
+
|
|
35
|
+
/** The name of a pass in words: "Common", "Buffer A", "Image". */
|
|
36
|
+
export const passLabel = (id) => (id === "common" ? "Common" : id === "image" ? "Image" : label(id));
|
|
37
|
+
|
|
38
|
+
/** The problems with the Common code as written. `[{ pass: "common", message }]`. */
|
|
39
|
+
export function checkCommon(common, { maxSource = 65536 } = {}) {
|
|
40
|
+
if (common === undefined || common === null) return [];
|
|
41
|
+
if (typeof common !== "string") return [{ pass: "common", message: "common must be GLSL source text (a string)" }];
|
|
42
|
+
if (common.length > maxSource) return [{ pass: "common", message: `common is over ${maxSource} characters` }];
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The problems with a buffer list as written: `[{ index, pass, message }]`, none when it is fine. `uniforms` are the names the
|
|
48
|
+
* pane's uniforms use (a channel may not share one).
|
|
49
|
+
*/
|
|
50
|
+
export function checkBuffers(list, { uniforms = [], maxSource = 65536 } = {}) {
|
|
51
|
+
if (list === undefined || list === null) return [];
|
|
52
|
+
if (!Array.isArray(list)) return [{ index: -1, pass: "image", message: "buffers must be a list of { name, code, channels?, format? }" }];
|
|
53
|
+
const problems = [];
|
|
54
|
+
if (list.length > PASS_LIMITS.maxBuffers) problems.push({ index: -1, pass: "image", message: `at most ${PASS_LIMITS.maxBuffers} buffers (${BUFFER_NAMES.join(", ")}); there are ${list.length}` });
|
|
55
|
+
const declared = new Set(list.map((b) => b?.name).filter((n) => BUFFER_NAMES.includes(n)));
|
|
56
|
+
const seen = new Set();
|
|
57
|
+
list.forEach((b, index) => {
|
|
58
|
+
const name = typeof b?.name === "string" ? b.name : "";
|
|
59
|
+
const pass = BUFFER_NAMES.includes(name) ? name : "image";
|
|
60
|
+
// `channel` problems leave the buffer itself usable (normalizeBuffers drops only the bad channels).
|
|
61
|
+
const add = (message, channel = false) => problems.push({ index, pass, channel, message: `${BUFFER_NAMES.includes(name) ? label(name) : `buffer #${index + 1}`}: ${message}` });
|
|
62
|
+
if (!b || typeof b !== "object" || Array.isArray(b)) return add("must be an object { name, code, … }");
|
|
63
|
+
if (!BUFFER_NAMES.includes(name)) return add(`name must be one of ${BUFFER_NAMES.join(", ")}`);
|
|
64
|
+
if (seen.has(name)) add("declared twice");
|
|
65
|
+
seen.add(name);
|
|
66
|
+
for (const key of Object.keys(b)) if (!BUFFER_KEYS.includes(key)) add(`${key} is not a setting (${BUFFER_KEYS.join(", ")})`);
|
|
67
|
+
if (typeof b.code !== "string") add("code must be GLSL source text (a string)");
|
|
68
|
+
else if (b.code.length > maxSource) add(`code is over ${maxSource} characters`);
|
|
69
|
+
if (b.format !== undefined && !BUFFER_FORMATS.includes(b.format)) add(`format must be one of ${BUFFER_FORMATS.join(", ")}`);
|
|
70
|
+
for (const p of checkChannels(b.channels, { uniforms })) add(p.message, true);
|
|
71
|
+
if (Array.isArray(b.channels)) {
|
|
72
|
+
for (const c of b.channels) if (c && typeof c === "object" && c.buffer !== undefined && BUFFER_NAMES.includes(c.buffer) && !declared.has(c.buffer)) add(`channel ${c.name} reads ${label(c.buffer)}, which this shader doesn't have`, true);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return problems;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The Image pass's channels against the buffers: a channel may only read a buffer that exists. `[{ index, pass: "image", message }]`. */
|
|
79
|
+
export function checkImageBuffers(channels, buffers) {
|
|
80
|
+
const declared = new Set((Array.isArray(buffers) ? buffers : []).map((b) => b?.name));
|
|
81
|
+
const problems = [];
|
|
82
|
+
(Array.isArray(channels) ? channels : []).forEach((c, index) => {
|
|
83
|
+
if (c && typeof c === "object" && BUFFER_NAMES.includes(c.buffer) && !declared.has(c.buffer)) problems.push({ index, pass: "image", message: `channel ${c.name} reads ${label(c.buffer)}, which this shader doesn't have` });
|
|
84
|
+
});
|
|
85
|
+
return problems;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The buffers with defaults filled in, invalid ones left out, in the order they run (A first). `[{ name, code, channels, format }]`. */
|
|
89
|
+
export function normalizeBuffers(list, { uniforms = [] } = {}) {
|
|
90
|
+
const bad = new Set(checkBuffers(list, { uniforms }).filter((p) => !p.channel).map((p) => p.index));
|
|
91
|
+
const seen = new Set();
|
|
92
|
+
const out = [];
|
|
93
|
+
(Array.isArray(list) ? list : []).forEach((b, i) => {
|
|
94
|
+
if (bad.has(i) || !b || seen.has(b.name)) return;
|
|
95
|
+
seen.add(b.name);
|
|
96
|
+
out.push({ name: b.name, code: String(b.code ?? ""), channels: normalizeChannels(b.channels, { uniforms }), format: BUFFER_FORMATS.includes(b.format) ? b.format : "float" });
|
|
97
|
+
});
|
|
98
|
+
return out.sort((a, b) => BUFFER_NAMES.indexOf(a.name) - BUFFER_NAMES.indexOf(b.name));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The pane's passes as data: `{ common, buffers }` (normalized, in running order). */
|
|
102
|
+
export function passesOf(pane = {}, { uniforms = [] } = {}) {
|
|
103
|
+
const common = typeof pane.common === "string" ? pane.common : "";
|
|
104
|
+
return { common, buffers: normalizeBuffers(pane.buffers, { uniforms }) };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Does the shader have any pass besides Image? */
|
|
108
|
+
export const isMultipass = (pane = {}) => (typeof pane.common === "string" && pane.common.trim() !== "") || (Array.isArray(pane.buffers) && pane.buffers.length > 0);
|
|
109
|
+
|
|
110
|
+
/** The passes in the order they are drawn: `[{ id, tab, code, channels, format? }]` ending with the Image. `image` is the Image pass's `{ code, channels }`. */
|
|
111
|
+
export function orderedPasses(buffers, image) {
|
|
112
|
+
return [...buffers.map((b) => ({ id: b.name, tab: label(b.name), kind: "buffer", code: b.code, channels: b.channels, format: b.format })), { id: "image", tab: "Image", kind: "image", code: image.code, channels: image.channels }];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Does reaching frame n need frames 0…n stepped in order? Yes when anything is carried from one frame to the next: the Image
|
|
117
|
+
* pass's own previous frame (`feedback`), or a buffer read by itself or by a pass drawn before it (it is read as the last frame
|
|
118
|
+
* left it). A shader whose buffers are each read only by passes drawn after them is a function of t and frame, drawn once.
|
|
119
|
+
*/
|
|
120
|
+
export function isStateful(buffers, { feedback = false } = {}) {
|
|
121
|
+
if (feedback) return true;
|
|
122
|
+
return buffers.some((b, i) => b.channels.some((c) => c.buffer && buffers.findIndex((x) => x.name === c.buffer) >= i));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The texture memory the buffers take: two textures each (one is drawn into while the other is read), 8 bytes a pixel as float, 16 as float32, 4 as bytes. */
|
|
126
|
+
export function bufferBytes(buffers, width, height, { float = true } = {}) {
|
|
127
|
+
return buffers.reduce((n, b) => n + 2 * width * height * (!float || b.format === "byte" ? 4 : b.format === "float32" ? 16 : 8), 0);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** `{ bytes, limit, text }`: the buffer memory for this size, in words ("3 buffers, 14.1 MB of 256 MB"). */
|
|
131
|
+
export function bufferMemory(buffers, width, height, options) {
|
|
132
|
+
const bytes = bufferBytes(buffers, width, height, options);
|
|
133
|
+
const mb = (n) => `${Math.round((n / 1048576) * 10) / 10} MB`;
|
|
134
|
+
return { bytes, limit: PASS_LIMITS.maxBufferBytes, text: buffers.length ? `${buffers.length} buffer${buffers.length === 1 ? "" : "s"}, ${mb(bytes)} of the ${mb(PASS_LIMITS.maxBufferBytes)} they may take` : "" };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Problems when the buffers would take more memory than they may. */
|
|
138
|
+
export function bufferMemoryProblems(buffers, width, height, options) {
|
|
139
|
+
const { bytes, limit } = bufferMemory(buffers, width, height, options);
|
|
140
|
+
if (bytes <= limit) return [];
|
|
141
|
+
return [`the buffers would take ${Math.round(bytes / 1048576)} MB at ${width}×${height}, over the ${Math.round(limit / 1048576)} MB they may take together: make the picture smaller, use format "byte" for a buffer, or drop one`];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Where `shader.output` points: a problem when it names a buffer the shader doesn't have. */
|
|
145
|
+
export function checkOutput(output, buffers) {
|
|
146
|
+
if (output === undefined || output === null || output === "image") return [];
|
|
147
|
+
if (!BUFFER_NAMES.includes(output)) return [];
|
|
148
|
+
const declared = (Array.isArray(buffers) ? buffers : []).some((b) => b?.name === output);
|
|
149
|
+
return declared ? [] : [{ pass: "image", message: `shader.output is ${label(output)}, which this shader doesn't have` }];
|
|
150
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Shadertoy in and out, the pure part. Nothing here fetches anything: a shader comes in as text a person pasted or
|
|
2
|
+
// a JSON file they picked (shadertoy.com's own export, or what this module writes), and goes out the same way.
|
|
3
|
+
//
|
|
4
|
+
// The Image tab becomes the pane's code, the Common tab its Common (put in front of every pass), and Buffer A-D their own buffers
|
|
5
|
+
// (float, as Shadertoy's are) with their channels, a channel that reads a buffer being { buffer }. Sound and cubemap tabs are
|
|
6
|
+
// named in the notes and not imported. Each texture channel becomes a channel called iChannel<n> with its filter, wrap and
|
|
7
|
+
// vflip; the picture a texture channel used is not fetched, so its row says to wire an image pane in.
|
|
8
|
+
import { shadertoyTabs } from "./model.js";
|
|
9
|
+
import { describe } from "./common.js";
|
|
10
|
+
import { BUFFER_NAMES, passLabel } from "./passes.js";
|
|
11
|
+
|
|
12
|
+
const FILTERS = ["nearest", "linear", "mipmap"];
|
|
13
|
+
const WRAPS = ["clamp", "repeat"];
|
|
14
|
+
const KINDS = { texture: "a texture", cubemap: "a cubemap", volume: "a 3D texture", video: "a video", webcam: "the webcam", mic: "the microphone", music: "music", musicstream: "a music stream", keyboard: "the keyboard", buffer: "a buffer", misc: "a misc input" };
|
|
15
|
+
|
|
16
|
+
const truthy = (v) => v === true || v === "true";
|
|
17
|
+
|
|
18
|
+
/** Parse what was pasted: JSON when it starts like JSON, else GLSL source. `{ shader }` (a Shadertoy object), `{ source }` or `{ problem }`. */
|
|
19
|
+
function read(input) {
|
|
20
|
+
if (input && typeof input === "object") return { json: input };
|
|
21
|
+
const text = String(input ?? "").replace(/^/, "").trim();
|
|
22
|
+
if (!text) return { problem: "there is nothing to import: paste a Shadertoy's source (its Image tab) or the JSON it exports" };
|
|
23
|
+
if (/^[{[]/.test(text)) {
|
|
24
|
+
try {
|
|
25
|
+
return { json: JSON.parse(text) };
|
|
26
|
+
} catch (error) {
|
|
27
|
+
return { problem: `that looks like JSON but doesn't parse (${error.message})` };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { source: text };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The letter a buffer pass is called: "Buffer B" is B; an unnamed one takes the next free letter. */
|
|
34
|
+
function bufferLetters(passes, notes) {
|
|
35
|
+
const taken = new Set();
|
|
36
|
+
const out = new Map();
|
|
37
|
+
const named = (p) => /buffer\s*([a-d])\b/i.exec(String(p?.name ?? ""))?.[1]?.toUpperCase();
|
|
38
|
+
for (const p of passes) {
|
|
39
|
+
const letter = named(p);
|
|
40
|
+
if (letter && !taken.has(letter)) {
|
|
41
|
+
taken.add(letter);
|
|
42
|
+
out.set(p, letter);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const p of passes) {
|
|
46
|
+
if (out.has(p)) continue;
|
|
47
|
+
const free = BUFFER_NAMES.find((l) => !taken.has(l));
|
|
48
|
+
if (!free) {
|
|
49
|
+
notes.push(`${String(p?.name ?? "") || "a buffer"}: a shader has at most ${BUFFER_NAMES.length} buffers (${BUFFER_NAMES[0]} to ${BUFFER_NAMES.at(-1)}), so this one is not imported`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
taken.add(free);
|
|
53
|
+
out.set(p, free);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Turn a pasted Shadertoy into a shader pane's fields. `input` is GLSL (the Image tab's source), a JSON string or an object:
|
|
60
|
+
* shadertoy.com's export (`{ Shader: { info, renderpass } }`, or the shader alone, or a list holding one).
|
|
61
|
+
* `{ code, common, buffers, channels, name?, notes }` or `{ problem }`. `notes` say what was left out and what to wire.
|
|
62
|
+
*/
|
|
63
|
+
export function importShadertoy(input) {
|
|
64
|
+
const got = read(input);
|
|
65
|
+
if (got.problem) return { problem: got.problem };
|
|
66
|
+
const notes = [];
|
|
67
|
+
if (got.source !== undefined) {
|
|
68
|
+
const code = got.source.replace(/\r\n?/g, "\n");
|
|
69
|
+
if (!/\bmainImage\b/.test(code) && !/\bvoid\s+main\s*\(/.test(code)) notes.push("the source has no mainImage: a shader needs void mainImage(out vec4 fragColor, in vec2 fragCoord)");
|
|
70
|
+
return { code, common: "", buffers: [], channels: [], notes };
|
|
71
|
+
}
|
|
72
|
+
let root = got.json;
|
|
73
|
+
if (Array.isArray(root)) {
|
|
74
|
+
if (root.length > 1) notes.push(`the file holds ${root.length} shaders: the first was imported`);
|
|
75
|
+
root = root[0];
|
|
76
|
+
}
|
|
77
|
+
if (root && typeof root === "object" && root.Error) return { problem: `Shadertoy's answer was an error: ${describe(root.Error)}` };
|
|
78
|
+
const shader = root && typeof root === "object" ? (root.Shader ?? root.shader ?? root) : null;
|
|
79
|
+
const passes = Array.isArray(shader?.renderpass) ? shader.renderpass : null;
|
|
80
|
+
if (!passes) return { problem: "that JSON has no renderpass list: it isn't a Shadertoy export" };
|
|
81
|
+
const nameOf = (p) => String(p?.name ?? "");
|
|
82
|
+
const typeOf = (p) => String(p?.type ?? "").toLowerCase();
|
|
83
|
+
const image = passes.find((p) => typeOf(p) === "image") ?? passes.find((p) => /^image$/i.test(nameOf(p)));
|
|
84
|
+
if (!image || typeof image.code !== "string") return { problem: "that Shadertoy has no Image pass with code" };
|
|
85
|
+
const commonPass = passes.find((p) => typeOf(p) === "common" || /^common$/i.test(nameOf(p)));
|
|
86
|
+
const bufferPasses = passes.filter((p) => p !== image && p !== commonPass && typeOf(p) === "buffer");
|
|
87
|
+
for (const p of passes.filter((q) => q !== image && q !== commonPass && !bufferPasses.includes(q))) {
|
|
88
|
+
const kind = typeOf(p);
|
|
89
|
+
notes.push(`${nameOf(p) || kind || "a pass"}: ${kind === "sound" ? "sound passes are not imported" : kind === "cubemap" ? "cubemap passes are not imported" : "not imported"}`);
|
|
90
|
+
}
|
|
91
|
+
const letters = bufferLetters(bufferPasses, notes);
|
|
92
|
+
// A reader names a buffer by the id of its output; older files name the picture instead (buffer00.png is Buffer A).
|
|
93
|
+
const byId = new Map();
|
|
94
|
+
for (const [p, letter] of letters) for (const o of Array.isArray(p.outputs) ? p.outputs : []) if (o?.id !== undefined) byId.set(String(o.id), letter);
|
|
95
|
+
const letterOf = (i) => byId.get(String(i.id)) ?? (/buffer0([0-3])/.exec(String(i.src ?? ""))?.[1] !== undefined ? BUFFER_NAMES[Number(/buffer0([0-3])/.exec(String(i.src))[1])] : undefined);
|
|
96
|
+
|
|
97
|
+
/** The channels of one pass: `{ channels, notes }`, the notes prefixed with the pass's name when it is not the Image. */
|
|
98
|
+
const channelsOf = (pass, prefix) => {
|
|
99
|
+
const channels = [];
|
|
100
|
+
const say = (text) => notes.push(`${prefix}${text}`);
|
|
101
|
+
const inputs = (Array.isArray(pass.inputs) ? pass.inputs : []).filter((i) => i && Number.isInteger(Number(i.channel))).sort((a, b) => Number(a.channel) - Number(b.channel));
|
|
102
|
+
for (const input of inputs) {
|
|
103
|
+
const n = Number(input.channel);
|
|
104
|
+
const name = `iChannel${n}`;
|
|
105
|
+
const kind = String(input.ctype ?? input.type ?? "texture").toLowerCase();
|
|
106
|
+
const sampler = input.sampler && typeof input.sampler === "object" ? input.sampler : {};
|
|
107
|
+
const filter = FILTERS.includes(sampler.filter) ? sampler.filter : "linear";
|
|
108
|
+
const wrap = WRAPS.includes(sampler.wrap) ? sampler.wrap : "clamp";
|
|
109
|
+
if (kind === "buffer") {
|
|
110
|
+
const letter = letterOf(input);
|
|
111
|
+
if (!letter || ![...letters.values()].includes(letter)) {
|
|
112
|
+
say(`${name}: a buffer input that names no buffer pass in this file, so it reads opaque black`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (sampler.wrap !== undefined && !WRAPS.includes(sampler.wrap)) say(`${name}: wrap ${describe(sampler.wrap)} is not clamp or repeat, so it is clamp`);
|
|
116
|
+
channels.push({ name, buffer: letter, filter, wrap });
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
// Keyboard, music, video, webcam and microphone inputs become channels of their kind: the row says what to wire in. The
|
|
120
|
+
// webcam and the microphone read a device pane's capture live (a frame, or Shadertoy's 512×2 mic texture, for each frame
|
|
121
|
+
// drawn); a recording of either works too (wire a video or an audio pane in).
|
|
122
|
+
if (kind === "keyboard") {
|
|
123
|
+
channels.push({ name, filter: "nearest", wrap: "clamp", as: "numbers" });
|
|
124
|
+
say(`${name}: the keyboard: wire a keyboard device pane named ${name} in (or set its from); it reads Shadertoy's 256×3 keyboard texture`);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (kind === "mic") {
|
|
128
|
+
channels.push({ name, filter, wrap, as: "audio", live: true });
|
|
129
|
+
say(`${name}: the microphone: wire a microphone device pane named ${name} in (or set its from); once you press its Start, the shader reads Shadertoy's 512×2 spectrum and waveform texture from it for each frame it draws (an audio pane's WAV or a recording works too, at the shader's time)`);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (kind === "music" || kind === "musicstream") {
|
|
133
|
+
channels.push({ name, filter, wrap, as: "audio" });
|
|
134
|
+
say(`${name}: ${KINDS[kind]}: wire an audio pane (its WAV, or a recording) named ${name} in; it reads Shadertoy's 512×2 FFT and waveform texture at the shader's time`);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (kind === "webcam") {
|
|
138
|
+
const vflip = sampler.vflip === undefined ? true : truthy(sampler.vflip);
|
|
139
|
+
channels.push({ name, filter, wrap, vflip, live: true });
|
|
140
|
+
say(`${name}: the webcam: wire a camera device pane named ${name} in (or set its from); once you press its Start, the shader reads its frames live, one for each frame it draws (a recording of the camera works too, as a video)`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (kind === "video") {
|
|
144
|
+
const vflip = sampler.vflip === undefined ? true : truthy(sampler.vflip);
|
|
145
|
+
channels.push({ name, filter, wrap, vflip, as: "video" });
|
|
146
|
+
say(`${name}: ${KINDS[kind]}: wire a video (a media pane, or a recording) named ${name} in`);
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (kind !== "texture") {
|
|
150
|
+
say(`${name}: ${KINDS[kind] ?? `a ${kind} input`} is not supported yet, so it reads opaque black`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (sampler.wrap !== undefined && !WRAPS.includes(sampler.wrap)) say(`${name}: wrap ${describe(sampler.wrap)} is not clamp or repeat, so it is clamp`);
|
|
154
|
+
const vflip = sampler.vflip === undefined ? true : truthy(sampler.vflip);
|
|
155
|
+
channels.push({ name, filter, wrap, vflip });
|
|
156
|
+
const src = typeof input.src === "string" && input.src ? input.src : "";
|
|
157
|
+
say(`${name}: ${src ? `the texture ${src.slice(0, 80)} is not fetched` : "a texture"}: wire an image pane named ${name} in (or set its from)`);
|
|
158
|
+
if (truthy(sampler.srgb)) say(`${name}: Shadertoy read it as sRGB; the texture is read as it is`);
|
|
159
|
+
}
|
|
160
|
+
return channels;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const buffers = [...letters]
|
|
164
|
+
.sort((a, b) => BUFFER_NAMES.indexOf(a[1]) - BUFFER_NAMES.indexOf(b[1]))
|
|
165
|
+
.map(([p, letter]) => ({ name: letter, code: String(p.code ?? "").replace(/\r\n?/g, "\n"), channels: channelsOf(p, `${passLabel(letter)}: `), format: "float" }));
|
|
166
|
+
if (buffers.length) notes.push(`${buffers.length === 1 ? "the buffer is" : "the buffers are"} float (RGBA16F where the GPU can draw to a float texture, else 8 bits a channel), as Shadertoy's are`);
|
|
167
|
+
const channels = channelsOf(image, "");
|
|
168
|
+
const common = commonPass && typeof commonPass.code === "string" ? String(commonPass.code).replace(/\r\n?/g, "\n").replace(/\s+$/, "") : "";
|
|
169
|
+
return { code: String(image.code).replace(/\r\n?/g, "\n"), common, buffers, channels, name: typeof shader?.info?.name === "string" && shader.info.name.trim() ? shader.info.name.trim() : undefined, notes };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const BUFFER_IDS = { A: "257", B: "258", C: "259", D: "260" };
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The shader as shadertoy.com's JSON: an Image pass whose code is the Shadertoy variant (exportShadertoy) and whose inputs are
|
|
176
|
+
* the channels in the slots they sit in, with their filter, wrap and vflip; with buffers, a Common pass and a pass per buffer,
|
|
177
|
+
* each buffer's output id named by the inputs that read it. importShadertoy reads it back.
|
|
178
|
+
*/
|
|
179
|
+
export function exportShadertoyJson(pane, { name } = {}) {
|
|
180
|
+
const { multi, tabs } = shadertoyTabs(pane);
|
|
181
|
+
const inputOf = (s) =>
|
|
182
|
+
s.buffer
|
|
183
|
+
? { id: BUFFER_IDS[s.buffer], src: `/media/previz/buffer0${"ABCD".indexOf(s.buffer)}.png`, ctype: "buffer", channel: s.slot, sampler: { filter: s.filter, wrap: s.wrap, vflip: "false", srgb: "false", internal: "byte" }, published: 1 }
|
|
184
|
+
: { id: "", src: "", ctype: "texture", channel: s.slot, sampler: { filter: s.filter, wrap: s.wrap, vflip: String(s.vflip), srgb: "false", internal: "byte" }, published: 1 };
|
|
185
|
+
const renderpass = tabs.map((tab) => {
|
|
186
|
+
if (tab.id === "common") return { inputs: [], outputs: [], code: tab.code, name: "Common", description: "", type: "common" };
|
|
187
|
+
if (tab.id === "image") return { inputs: tab.slots.map(inputOf), outputs: [{ id: "4dfGRr", channel: 0 }], code: tab.code, name: "Image", description: "", type: "image" };
|
|
188
|
+
return { inputs: tab.slots.map(inputOf), outputs: [{ id: BUFFER_IDS[tab.id], channel: 0 }], code: tab.code, name: passLabel(tab.id), description: "", type: "buffer" };
|
|
189
|
+
});
|
|
190
|
+
void multi;
|
|
191
|
+
return {
|
|
192
|
+
Shader: {
|
|
193
|
+
ver: "0.1",
|
|
194
|
+
info: { id: "", date: "0", viewed: 0, name: name || "mallory shader", username: "", description: "", likes: 0, published: 0, flags: 0, usePreview: 0, tags: [] },
|
|
195
|
+
renderpass,
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
package/src/shell/hub.js
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// The shell panes of a canvas on the page (src/panes/shell.js, src/ui/shell-pane.js; docs/guide/settings-and-storage.md "Shell pane"): each pane's sessions, what they show, and running a line.
|
|
2
|
+
// A line is run by the sandbox Worker in clsh (runtime.shell -> src/runtime/worker/99-shell.js) over this canvas's own folder, through the page broker and the person's grant; the hub
|
|
3
|
+
// holds NO file system and opens none. A pane's value says where the shell stands (its session, folder, last exit code and how many lines it ran), never what a line printed.
|
|
4
|
+
// Only the person types into it: a run, a wire, a share link and an agent never run a line (a machine's tool state does, through its own gated path, src/machine/shell-tool.js).
|
|
5
|
+
import { signal } from "@johnhenry/signalle";
|
|
6
|
+
import { complete, incomplete, COMMANDS } from "../clsh/clsh.js";
|
|
7
|
+
import { boundTranscript, cleanName, exportSession, exportName, FORMAT_FLAGS, HISTORY_MAX, LINE_MAX, SESSIONS_PER_PANE, newSessionId } from "../model/shell-pane.js";
|
|
8
|
+
|
|
9
|
+
const hubs = new Set();
|
|
10
|
+
export function shellHubOf(canvas, options) {
|
|
11
|
+
canvas.shellHub ??= new ShellHub(canvas, options);
|
|
12
|
+
return canvas.shellHub;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const blankState = () => ({ cwd: "/", vars: {}, exported: [], last: 0 });
|
|
16
|
+
|
|
17
|
+
export class ShellHub {
|
|
18
|
+
/** @param {object} canvas @param {{ runtime?: object, sessions?: object, keep?: () => boolean, now?: () => number, views?: (canvas: object) => object }} [options] */
|
|
19
|
+
constructor(canvas, { runtime, sessions, keep = () => false, now = () => Date.now(), views } = {}) {
|
|
20
|
+
this.canvas = canvas;
|
|
21
|
+
this.views = views; // the read-only snapshot a line may print (src/shell/views.js): `cost`, `mcp`, `rpc`
|
|
22
|
+
this.runtime = runtime;
|
|
23
|
+
this.sessions = sessions;
|
|
24
|
+
this.keep = keep;
|
|
25
|
+
this.now = now;
|
|
26
|
+
this.panes = new Map(); // pane id -> { list: [session], active, busy, count, notice }
|
|
27
|
+
/** Bumped on every change, so pane bodies follow along. */
|
|
28
|
+
this.version = signal(0);
|
|
29
|
+
hubs.add(this);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#bump() {
|
|
33
|
+
this.version.value += 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#pane(id) {
|
|
37
|
+
let p = this.panes.get(id);
|
|
38
|
+
if (!p) {
|
|
39
|
+
p = { list: [], active: 0, busy: false, count: 0, loaded: false, notice: "", lastExit: 0 };
|
|
40
|
+
this.panes.set(id, p);
|
|
41
|
+
}
|
|
42
|
+
return p;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#fresh(name) {
|
|
46
|
+
return { id: newSessionId(), name, created: this.now(), updated: this.now(), state: blankState(), history: [], transcript: [] };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#root() {
|
|
50
|
+
return this.canvas.root ?? this.canvas;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The pane's sessions: the kept ones (when the person keeps them) and, always, one to type in. */
|
|
54
|
+
async load(id) {
|
|
55
|
+
const p = this.#pane(id);
|
|
56
|
+
if (p.loaded) return p;
|
|
57
|
+
p.loaded = true;
|
|
58
|
+
const kept = this.keep() && this.sessions ? await this.sessions.list({ canvas: this.#root().id, pane: id }).catch(() => []) : [];
|
|
59
|
+
p.list = kept.length ? kept.map((s) => ({ ...s })) : [this.#fresh("session 1")];
|
|
60
|
+
p.active = 0;
|
|
61
|
+
this.#bump();
|
|
62
|
+
return p;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
current(id) {
|
|
66
|
+
const p = this.#pane(id);
|
|
67
|
+
if (!p.list.length) p.list = [this.#fresh("session 1")];
|
|
68
|
+
return p.list[Math.min(p.active, p.list.length - 1)];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
status(id) {
|
|
72
|
+
const p = this.#pane(id);
|
|
73
|
+
const s = this.current(id);
|
|
74
|
+
return { name: s.name, cwd: s.state.cwd, busy: p.busy, count: p.count, last: s.state.last, sessions: p.list.map((x) => ({ id: x.id, name: x.name })), active: Math.min(p.active, p.list.length - 1), notice: p.notice, kept: this.keep() };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The pane's value: where the shell stands, never output. */
|
|
78
|
+
value(id) {
|
|
79
|
+
const p = this.#pane(id);
|
|
80
|
+
const s = this.current(id);
|
|
81
|
+
return { session: s.name, cwd: s.state.cwd, exit: s.state.last, commands: p.count };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#changed(id) {
|
|
85
|
+
this.#bump();
|
|
86
|
+
const c = this.canvas;
|
|
87
|
+
if (c.disposed || !c.attached?.has(id) || c.trusted?.value === false) return;
|
|
88
|
+
c.hint?.(`shell ${c.panes.get(id)?.name || id}`);
|
|
89
|
+
c.flow?.run(id);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async #persist(id) {
|
|
93
|
+
if (!this.keep() || !this.sessions) return;
|
|
94
|
+
const s = this.current(id);
|
|
95
|
+
const r = await this.sessions.save({ ...s, canvas: this.#root().id, pane: id });
|
|
96
|
+
const p = this.#pane(id);
|
|
97
|
+
p.notice = r.ok ? "" : r.message;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Whether the session is part-way through a command (an open quote, block or here-document): the next line continues it. */
|
|
101
|
+
hasPending(id) {
|
|
102
|
+
return Boolean(this.current(id).pending);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Drop a command that was waiting for its next line (Ctrl+C). */
|
|
106
|
+
cancelPending(id) {
|
|
107
|
+
const s = this.current(id);
|
|
108
|
+
if (!s.pending) return false;
|
|
109
|
+
s.pending = "";
|
|
110
|
+
this.#bump();
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Run one line the person typed: shows it, runs it in the Worker, shows what came back. Resolves to `{ code }`, or `{ more: true }` when the command is not finished and waits for its next line. */
|
|
115
|
+
async exec(id, line) {
|
|
116
|
+
const p = await this.load(id);
|
|
117
|
+
const text = String(line ?? "").slice(0, LINE_MAX);
|
|
118
|
+
const s = this.current(id);
|
|
119
|
+
if (!text.trim() && !s.pending) return { code: 0 };
|
|
120
|
+
if (p.busy) return { code: 1, busy: true };
|
|
121
|
+
const more = Boolean(s.pending);
|
|
122
|
+
if (text.trim()) s.history = [...s.history, text].slice(-HISTORY_MAX);
|
|
123
|
+
s.transcript = boundTranscript([...s.transcript, { kind: "cmd", text, cwd: s.state.cwd, ...(more ? { more: true } : {}) }]);
|
|
124
|
+
const full = more ? `${s.pending}\n${text}` : text;
|
|
125
|
+
if (full.length > LINE_MAX) {
|
|
126
|
+
s.pending = "";
|
|
127
|
+
const out = [{ kind: "err", text: `clsh: a command is at most ${LINE_MAX} characters; start it again\n` }];
|
|
128
|
+
s.transcript = boundTranscript([...s.transcript, ...out]);
|
|
129
|
+
this.#bump();
|
|
130
|
+
return { code: 2, out };
|
|
131
|
+
}
|
|
132
|
+
if (incomplete(full)) {
|
|
133
|
+
s.pending = full;
|
|
134
|
+
this.#bump();
|
|
135
|
+
return { code: 0, more: true, out: [] };
|
|
136
|
+
}
|
|
137
|
+
s.pending = "";
|
|
138
|
+
p.busy = true;
|
|
139
|
+
p.notice = "";
|
|
140
|
+
this.#bump();
|
|
141
|
+
const pane = this.canvas.panes.get(id);
|
|
142
|
+
const names = (pane?.inputs ?? []).map((i) => i.name);
|
|
143
|
+
const sources = (pane?.inputs ?? []).map((i) => i.source);
|
|
144
|
+
let reply;
|
|
145
|
+
try {
|
|
146
|
+
if (!this.runtime?.shell) throw new Error("this page has no sandbox to run it in");
|
|
147
|
+
let views;
|
|
148
|
+
try {
|
|
149
|
+
views = this.views?.(this.canvas);
|
|
150
|
+
} catch {}
|
|
151
|
+
reply = await this.runtime.shell({ id, request: { line: full, state: s.state, mode: "person", history: s.history, ...(views ? { views } : {}) }, sources, names });
|
|
152
|
+
} catch (error) {
|
|
153
|
+
reply = { chunks: [{ s: "err", text: `clsh: ${error?.message ?? String(error)}\n` }], code: 1, state: s.state, effects: [] };
|
|
154
|
+
}
|
|
155
|
+
p.busy = false;
|
|
156
|
+
p.count += 1;
|
|
157
|
+
s.state = reply.state ?? s.state;
|
|
158
|
+
s.updated = this.now();
|
|
159
|
+
const out = (reply.chunks ?? []).map((c) => ({ kind: c.s === "err" ? "err" : "out", text: String(c.text) }));
|
|
160
|
+
for (const e of reply.effects ?? []) {
|
|
161
|
+
if (e.type === "clear") s.transcript = [];
|
|
162
|
+
else if (e.type === "session") {
|
|
163
|
+
const said = await this.#sessionEffect(id, e.op, e.args ?? []);
|
|
164
|
+
if (said) out.push({ kind: "out", text: `${said}\n` });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const cur = this.current(id);
|
|
168
|
+
cur.transcript = boundTranscript([...cur.transcript, ...out]);
|
|
169
|
+
await this.#persist(id);
|
|
170
|
+
this.#changed(id);
|
|
171
|
+
return { code: reply.code ?? 0, out };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** `clawser session ...`: the person's own shell managing its sessions. Returns a line to show, or "". */
|
|
175
|
+
async #sessionEffect(id, op, args) {
|
|
176
|
+
const p = this.#pane(id);
|
|
177
|
+
const name = cleanName(args.filter((a) => !a.startsWith("-")).join(" "));
|
|
178
|
+
if (op === "list") return p.list.map((s, i) => `${i === p.active ? "*" : " "} ${s.name}`).join("\n");
|
|
179
|
+
if (op === "new") return (this.newSession(id, name), `new session: ${this.current(id).name}`);
|
|
180
|
+
if (op === "switch") return this.switchTo(id, name) ? `switched to ${name}` : `no session named "${name}"`;
|
|
181
|
+
if (op === "rename") return name ? (this.rename(id, name), `renamed to ${this.current(id).name}`) : "clawser session rename: a name is needed";
|
|
182
|
+
if (op === "delete") return (await this.removeSession(id, name || this.current(id).name)) ? `deleted ${name || "this session"}` : `no session named "${name}"`;
|
|
183
|
+
if (op === "fork") return (this.fork(id, name), `forked into ${this.current(id).name}`);
|
|
184
|
+
if (op === "save") {
|
|
185
|
+
await this.#persist(id);
|
|
186
|
+
return this.keep() ? (p.notice || "saved") : "sessions are not kept: switch on 'keep shell sessions in this browser' in settings, terminal";
|
|
187
|
+
}
|
|
188
|
+
if (op === "export") {
|
|
189
|
+
const flag = args.find((a) => FORMAT_FLAGS[a]);
|
|
190
|
+
return this.#offer(id, FORMAT_FLAGS[flag] ?? "text");
|
|
191
|
+
}
|
|
192
|
+
return "";
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#offer(id, format) {
|
|
196
|
+
const s = this.current(id);
|
|
197
|
+
this.pendingDownload = { name: exportName(s, format), text: exportSession(s, format) };
|
|
198
|
+
this.#bump();
|
|
199
|
+
return `exporting ${this.pendingDownload.name}`;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
newSession(id, name = "") {
|
|
203
|
+
const p = this.#pane(id);
|
|
204
|
+
if (p.list.length >= SESSIONS_PER_PANE) return false;
|
|
205
|
+
const s = this.#fresh(cleanName(name) || `session ${p.list.length + 1}`);
|
|
206
|
+
p.list.unshift(s);
|
|
207
|
+
p.active = 0;
|
|
208
|
+
this.#bump();
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
fork(id, name = "") {
|
|
213
|
+
const p = this.#pane(id);
|
|
214
|
+
if (p.list.length >= SESSIONS_PER_PANE) return false;
|
|
215
|
+
const from = this.current(id);
|
|
216
|
+
const s = { ...this.#fresh(cleanName(name) || `${from.name} (fork)`), state: JSON.parse(JSON.stringify(from.state)), history: [...from.history], transcript: [...from.transcript] };
|
|
217
|
+
p.list.unshift(s);
|
|
218
|
+
p.active = 0;
|
|
219
|
+
this.#bump();
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
switchTo(id, nameOrIndex) {
|
|
224
|
+
const p = this.#pane(id);
|
|
225
|
+
const i = typeof nameOrIndex === "number" ? nameOrIndex : p.list.findIndex((s) => s.name === nameOrIndex);
|
|
226
|
+
if (i < 0 || i >= p.list.length) return false;
|
|
227
|
+
p.active = i;
|
|
228
|
+
this.#bump();
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async rename(id, name) {
|
|
233
|
+
const s = this.current(id);
|
|
234
|
+
s.name = cleanName(name) || s.name;
|
|
235
|
+
this.#changed(id);
|
|
236
|
+
await this.#persist(id);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async removeSession(id, name) {
|
|
240
|
+
const p = this.#pane(id);
|
|
241
|
+
const i = p.list.findIndex((s) => s.name === name);
|
|
242
|
+
if (i < 0) return false;
|
|
243
|
+
const [gone] = p.list.splice(i, 1);
|
|
244
|
+
if (!p.list.length) p.list = [this.#fresh("session 1")];
|
|
245
|
+
p.active = Math.min(p.active, p.list.length - 1);
|
|
246
|
+
if (this.sessions) await this.sessions.remove(gone.id).catch(() => {});
|
|
247
|
+
this.#changed(id);
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** The export of the current session, as `{ name, text }`. */
|
|
252
|
+
exported(id, format = "text") {
|
|
253
|
+
const s = this.current(id);
|
|
254
|
+
return { name: exportName(s, format), text: exportSession(s, format) };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
takeDownload() {
|
|
258
|
+
const d = this.pendingDownload;
|
|
259
|
+
this.pendingDownload = null;
|
|
260
|
+
return d;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Completions for the line at `cursor`, listing folders through the page broker (a refusal is no candidates, and the permission bar asks as for any read). */
|
|
264
|
+
async complete(id, line, cursor) {
|
|
265
|
+
const s = this.current(id);
|
|
266
|
+
const broker = this.#root().filesBroker;
|
|
267
|
+
const list = async (dir) => {
|
|
268
|
+
if (!broker) return [];
|
|
269
|
+
const a = await broker(id, "list", { own: true, path: dir });
|
|
270
|
+
return a?.ok ? a.value.map((e) => ({ name: e.name, type: e.type })) : [];
|
|
271
|
+
};
|
|
272
|
+
return complete(line, cursor, { list, cwd: s.state.cwd, vars: Object.keys(s.state.vars), funcs: Object.keys(s.state.funcs ?? {}) });
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
history(id) {
|
|
276
|
+
return [...this.current(id).history];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** The pane was removed: its sessions in this browser go too. */
|
|
280
|
+
forget(id) {
|
|
281
|
+
this.panes.delete(id);
|
|
282
|
+
this.sessions?.forget({ canvas: this.#root().id, pane: id }).catch?.(() => {});
|
|
283
|
+
this.#bump();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export const SHELL_COMMANDS = COMMANDS;
|