@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,715 @@
|
|
|
1
|
+
// A canvas's terminal connections: one wsh client (src/wsh/connect.js) per
|
|
2
|
+
// terminal pane (src/panes/terminal.js), opened only by the PERSON's click on
|
|
3
|
+
// the pane (Connect, Resume): running the pane never connects, so a canvas
|
|
4
|
+
// that opens, reruns or is run by an agent starts nothing. Kept on the canvas
|
|
5
|
+
// as `canvas.terminalHub` (hubOf), in this page's memory only: the screen,
|
|
6
|
+
// the session, its resume token and the client go with the page.
|
|
7
|
+
//
|
|
8
|
+
// - pty mode (a real server with node-pty): one pty session; what it sends
|
|
9
|
+
// goes to the pane's screen (./screen.js), the keys typed in the pane go
|
|
10
|
+
// to it, and the pane's size is its size. Detach leaves it running on the
|
|
11
|
+
// server (wsh's `sessions` option) and keeps the resume token here; Resume
|
|
12
|
+
// connects again and replays only the output this page hasn't seen. A
|
|
13
|
+
// connection that drops keeps the token too.
|
|
14
|
+
// - exec mode (the demo host, or a server with exec but no pty): the pane
|
|
15
|
+
// edits a line locally and runs each one as its own exec session, its
|
|
16
|
+
// output and exit code on the screen.
|
|
17
|
+
//
|
|
18
|
+
// - companion mode (`companion:wsh-lab`, #388): the same exec line editor,
|
|
19
|
+
// over the page's own socket to the companion's wsh lab (src/wsh/connect.js).
|
|
20
|
+
//
|
|
21
|
+
// Files (#388): Send and Receive move one file over the session's file
|
|
22
|
+
// channel (wsh's upload/download), within the server's file root (the wsh
|
|
23
|
+
// lab's `files/` folder in the companion's state directory, or the root a
|
|
24
|
+
// server you run sets). The path is checked here first (src/wsh/transfer.js),
|
|
25
|
+
// and the person answers once per direction for each connection before the
|
|
26
|
+
// first file goes that way (`answerTransfer`); a new connection asks again.
|
|
27
|
+
//
|
|
28
|
+
// Recording (#388): wsh's SessionRecorder notes what the screen is sent (and
|
|
29
|
+
// the size), timed, from Record to Stop; what is typed goes in only when the
|
|
30
|
+
// person ticks "include input" (a password is typed too). The hub's own echo
|
|
31
|
+
// of a typed line is input as well, so it is left out with it. A stopped
|
|
32
|
+
// recording is an asciicast v2 file to save, and goes in the pane's value
|
|
33
|
+
// only when the person puts it there ("Put the recording in the pane's value").
|
|
34
|
+
//
|
|
35
|
+
// The pane's value (`value(id)`) says how it stands, never what the screen
|
|
36
|
+
// shows, a key or a token (unless the person put a recording in it); the hub
|
|
37
|
+
// reruns the pane when that changes, so its value follows. Nothing here is
|
|
38
|
+
// reachable from WebMCP (WHY_NOT.TERMINAL).
|
|
39
|
+
import { signal } from "@johnhenry/signalle";
|
|
40
|
+
import { Screen } from "./screen.js";
|
|
41
|
+
import { connectWsh, loadWsh } from "../wsh/connect.js";
|
|
42
|
+
import { wshSettings, isDemoWsh, isCompanionWsh, hostLabel } from "../wsh/settings.js";
|
|
43
|
+
import { transferPathProblem, transferLimit, sizeWords, castText, TRANSFER_LIMITS } from "../wsh/transfer.js";
|
|
44
|
+
import { forgetHostKey } from "../wsh/known-hosts.js";
|
|
45
|
+
|
|
46
|
+
export const COLS = 80;
|
|
47
|
+
export const ROWS = 24;
|
|
48
|
+
const PROMPT = "\x1b[32m$\x1b[0m ";
|
|
49
|
+
const HISTORY = 50;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Bumped when a connection starts or stops asking whether files may move (not on every screen update): the permission bar
|
|
53
|
+
* (src/ui/terminal-prompts.js) redraws on it. `hubs`: every live hub, to find the questions waiting.
|
|
54
|
+
*/
|
|
55
|
+
export const terminalAsks = signal(0);
|
|
56
|
+
export const hubs = new Set();
|
|
57
|
+
const asksChanged = () => (terminalAsks.value = terminalAsks.value + 1);
|
|
58
|
+
|
|
59
|
+
/** The canvas's hub, made on first use. */
|
|
60
|
+
export function hubOf(canvas, options) {
|
|
61
|
+
canvas.terminalHub ??= new TerminalHub(canvas, options);
|
|
62
|
+
return canvas.terminalHub;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const message = (error) => String(error?.message ?? error);
|
|
66
|
+
|
|
67
|
+
export class TerminalHub {
|
|
68
|
+
/**
|
|
69
|
+
* @param {object} canvas
|
|
70
|
+
* @param {{ connect?: typeof connectWsh, wsh?: () => Promise<object> }} [options] `connect`: how a connection is made (tests pass
|
|
71
|
+
* one with a WebSocket); `wsh`: the library, for its SessionRecorder.
|
|
72
|
+
*/
|
|
73
|
+
constructor(canvas, { connect = connectWsh, wsh = loadWsh } = {}) {
|
|
74
|
+
this.canvas = canvas;
|
|
75
|
+
this.connectFn = connect;
|
|
76
|
+
this.wshFn = wsh;
|
|
77
|
+
this.conns = new Map(); // pane id -> conn
|
|
78
|
+
/** Bumped on every change (screen output included), so pane bodies follow along. */
|
|
79
|
+
this.version = signal(0);
|
|
80
|
+
canvas.terminalHub ??= this;
|
|
81
|
+
hubs.add(this);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The questions waiting: [{ id, direction, label }] (what the pane's file row asks, for the bar). */
|
|
85
|
+
asks() {
|
|
86
|
+
return [...this.conns].filter(([, c]) => c.asking).map(([id, c]) => ({ id, direction: c.asking.direction, label: c.link?.label }));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#bump() {
|
|
90
|
+
this.version.value = this.version.value + 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Pane `id`'s connection record, made when first asked for. */
|
|
94
|
+
#conn(id) {
|
|
95
|
+
let conn = this.conns.get(id);
|
|
96
|
+
if (!conn) {
|
|
97
|
+
conn = { status: "disconnected", screen: null, line: "", history: [], at: -1, running: null, session: null, link: null, resume: null, exitCode: undefined, error: undefined, hostKeyChanged: null, cols: COLS, rows: ROWS, epoch: 0, consent: {}, asking: null, transfer: null, recorder: null, recorded: null };
|
|
98
|
+
conn.screen = new Screen({ cols: COLS, rows: ROWS, onReply: (text) => void conn.session?.write(text).catch(() => {}) });
|
|
99
|
+
this.conns.set(id, conn);
|
|
100
|
+
}
|
|
101
|
+
return conn;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The screen pane `id` draws (made when first asked for). */
|
|
105
|
+
screen(id) {
|
|
106
|
+
return this.#conn(id).screen;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* How pane `id` stands, for its body: `{ status, mode, demo, label?, key?, hostKey?, session, running, resumable,
|
|
111
|
+
* exitCode?, error?, hostKeyChanged? }`. `status`: disconnected, connecting, connected, detached or error.
|
|
112
|
+
*/
|
|
113
|
+
status(id) {
|
|
114
|
+
const conn = this.conns.get(id);
|
|
115
|
+
const s = wshSettings(this.canvas.panes.get(id));
|
|
116
|
+
return {
|
|
117
|
+
status: conn?.status ?? "disconnected",
|
|
118
|
+
mode: s.mode,
|
|
119
|
+
demo: isDemoWsh(s.url),
|
|
120
|
+
companion: isCompanionWsh(s.url),
|
|
121
|
+
...(conn?.link ? { label: conn.link.label, key: conn.link.key, ...(conn.link.hostKey ? { hostKey: conn.link.hostKey } : {}) } : {}),
|
|
122
|
+
session: Boolean(conn?.session),
|
|
123
|
+
...(conn?.link?.peer ? { peer: conn.link.peer, ...(conn.e2e ? { e2e: conn.e2e } : {}) } : {}),
|
|
124
|
+
running: Boolean(conn?.running),
|
|
125
|
+
resumable: Boolean(conn?.resume),
|
|
126
|
+
...(conn?.exitCode !== undefined ? { exitCode: conn.exitCode } : {}),
|
|
127
|
+
...(conn?.error ? { error: conn.error } : {}),
|
|
128
|
+
...(conn?.hostKeyChanged ? { hostKeyChanged: conn.hostKeyChanged } : {}),
|
|
129
|
+
// Files: what the person allowed for this connection, the direction waiting for an answer, the transfer under way or last done.
|
|
130
|
+
consent: { ...(conn?.consent ?? {}) },
|
|
131
|
+
...(conn?.asking ? { asking: conn.asking.direction } : {}),
|
|
132
|
+
...(conn?.transfer ? { transfer: { ...conn.transfer } } : {}),
|
|
133
|
+
// Recording: one under way (`recording`), or the last one stopped (`recorded`).
|
|
134
|
+
...(conn?.recorder ? { recording: { input: conn.recorder.input, events: conn.recorder.rec.entries.length, bytes: conn.recorder.bytes } } : {}),
|
|
135
|
+
...(conn?.recorded ? { recorded: { input: conn.recorded.input, seconds: conn.recorded.seconds, events: conn.recorded.events, inValue: conn.recorded.inValue, ...(conn.recorded.note ? { note: conn.recorded.note } : {}) } } : {}),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The pane's value: how it stands, in JSON (never the screen, a key, a token or a session id). */
|
|
140
|
+
value(id) {
|
|
141
|
+
const st = this.status(id);
|
|
142
|
+
const s = wshSettings(this.canvas.panes.get(id));
|
|
143
|
+
let server = "the demo host in this page";
|
|
144
|
+
if (st.companion) server = hostLabel(s.url);
|
|
145
|
+
else if (!st.demo) {
|
|
146
|
+
try {
|
|
147
|
+
server = hostLabel(s.url);
|
|
148
|
+
} catch {
|
|
149
|
+
server = "";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
status: st.status,
|
|
154
|
+
server,
|
|
155
|
+
user: s.user || "mallory",
|
|
156
|
+
mode: st.mode,
|
|
157
|
+
key: s.keyPane ? `secret pane ${s.keyPane}` : "this browser's key",
|
|
158
|
+
...(st.hostKey ? { hostKey: st.hostKey.fingerprint } : {}),
|
|
159
|
+
...(st.peer ? { peer: st.peer, ...(st.e2e ? { e2e: st.e2e } : {}) } : {}),
|
|
160
|
+
session: st.session,
|
|
161
|
+
...(st.exitCode !== undefined ? { exitCode: st.exitCode } : {}),
|
|
162
|
+
...(st.error ? { error: st.error } : {}),
|
|
163
|
+
// Only when the person put it there: the stopped recording, as an asciicast v2 file.
|
|
164
|
+
...(st.recorded?.inValue ? { recording: this.recording(id) } : {}),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Something the pane's value says changed: rerun it so its value follows (on a trusted canvas, while it is there). */
|
|
169
|
+
#changed(id) {
|
|
170
|
+
this.#bump();
|
|
171
|
+
const c = this.canvas;
|
|
172
|
+
if (c.disposed || !c.attached?.has(id) || c.trusted?.value === false) return;
|
|
173
|
+
c.hint?.(`terminal ${c.panes.get(id)?.name || id}`); // the run log's cause
|
|
174
|
+
c.flow?.run(id);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Its "exit" event: a session (pty) or a command (exec) ended. */
|
|
178
|
+
#exited(id, code, mode) {
|
|
179
|
+
const c = this.canvas;
|
|
180
|
+
if (c.disposed || !c.attached?.has(id) || c.trusted?.value === false) return;
|
|
181
|
+
c.events?.builtin(id, "exit", { code, mode, at: new Date().toISOString() });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
#set(id, conn, patch) {
|
|
185
|
+
Object.assign(conn, patch);
|
|
186
|
+
this.#changed(id);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Write text to the pane's screen (the hub's own lines: banners, prompts, exit codes). Recorded as output. */
|
|
190
|
+
#say(conn, text) {
|
|
191
|
+
conn.screen.write(text);
|
|
192
|
+
this.#rec(conn, "output", text);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** What the server sent: to the screen, and to a recording. */
|
|
196
|
+
#out(conn, data) {
|
|
197
|
+
conn.screen.write(data);
|
|
198
|
+
this.#rec(conn, "output", data);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The hub's echo of what was typed (exec mode's line editor): input, so a recording keeps it only with "include input". */
|
|
202
|
+
#echo(conn, text) {
|
|
203
|
+
conn.screen.write(text);
|
|
204
|
+
if (conn.recorder?.input) this.#rec(conn, "output", text);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Connect pane `id` (the person's click). In pty mode a session opens; in exec mode a prompt. `resume`: pick up the detached session. */
|
|
208
|
+
async connect(id, { resume = false } = {}) {
|
|
209
|
+
const pane = this.canvas.panes.get(id);
|
|
210
|
+
if (pane?.type !== "terminal") throw new Error(`terminal: there is no terminal pane ${JSON.stringify(id)}`);
|
|
211
|
+
const conn = this.#conn(id);
|
|
212
|
+
if (conn.status === "connecting" || conn.status === "connected") return this.status(id);
|
|
213
|
+
const epoch = ++conn.epoch;
|
|
214
|
+
const s = wshSettings(pane);
|
|
215
|
+
this.#set(id, conn, { status: "connecting", error: undefined, e2e: undefined, hostKeyChanged: null, exitCode: resume ? conn.exitCode : undefined, consent: {}, asking: null, transfer: null }); // each connection asks again before a file moves
|
|
216
|
+
asksChanged();
|
|
217
|
+
let link;
|
|
218
|
+
try {
|
|
219
|
+
link = await this.connectFn(this.canvas, id);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (conn.epoch !== epoch) return this.status(id);
|
|
222
|
+
this.#set(id, conn, { status: "error", error: message(error), ...(error?.hostKeyChanged ? { hostKeyChanged: error.hostKeyChanged } : {}) });
|
|
223
|
+
return this.status(id);
|
|
224
|
+
}
|
|
225
|
+
if (conn.epoch !== epoch || !this.canvas.panes.has(id)) {
|
|
226
|
+
await link.close();
|
|
227
|
+
return this.status(id);
|
|
228
|
+
}
|
|
229
|
+
conn.link = link;
|
|
230
|
+
link.client.onClose = () => this.#dropped(id, conn, link);
|
|
231
|
+
try {
|
|
232
|
+
if (s.mode === "pty" && !link.execOnly) {
|
|
233
|
+
if (resume && conn.resume) await this.#resume(id, conn, link);
|
|
234
|
+
else await this.#openPty(id, conn, link, s);
|
|
235
|
+
} else {
|
|
236
|
+
this.#say(conn, `\x1b[2mconnected to ${link.label} as ${s.user || "mallory"} (${link.key.source}); each line runs as an exec session${link.demo ? ": a demo, type help" : link.companion ? ": the companion's wsh lab, type help" : ""}\x1b[0m\r\n${PROMPT}`);
|
|
237
|
+
}
|
|
238
|
+
} catch (error) {
|
|
239
|
+
conn.link = null;
|
|
240
|
+
await link.close();
|
|
241
|
+
if (conn.epoch === epoch) this.#set(id, conn, { status: "error", error: message(error) });
|
|
242
|
+
return this.status(id);
|
|
243
|
+
}
|
|
244
|
+
this.#set(id, conn, { status: "connected" });
|
|
245
|
+
return this.status(id);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async #openPty(id, conn, link, s) {
|
|
249
|
+
const session = await link.client.openSession({ type: "pty", ...(s.command ? { command: s.command } : {}), cols: conn.cols, rows: conn.rows });
|
|
250
|
+
if (link.seal) conn.e2e = (await link.seal(session)).algorithm; // a peer behind a relay: sealed, or the connection fails
|
|
251
|
+
this.#bind(id, conn, session);
|
|
252
|
+
conn.resume = session.resumeToken ? { sessionId: session.sessionId, token: session.resumeToken, seq: 0 } : null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async #resume(id, conn, link) {
|
|
256
|
+
const { sessionId, token, seq } = conn.resume;
|
|
257
|
+
if (link.seal) throw new Error("terminal: a session behind a relay can't be resumed: its end-to-end key went with the connection");
|
|
258
|
+
let presence;
|
|
259
|
+
try {
|
|
260
|
+
presence = await link.client.resumeSession(sessionId, token, { lastSeq: seq });
|
|
261
|
+
} catch (error) {
|
|
262
|
+
throw new Error(`terminal: the session couldn't be resumed (${message(error)}). The server must keep sessions (@johnhenry/wsh/server's sessions option), and a detached session lasts only its detachTtlMs.`);
|
|
263
|
+
}
|
|
264
|
+
const session = presence.session;
|
|
265
|
+
if (!session) throw new Error("terminal: the server resumed the session but gave no channel to read it on");
|
|
266
|
+
this.#bind(id, conn, session);
|
|
267
|
+
void session.resize(conn.cols, conn.rows).catch(() => {});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Wire a pty session to the screen. Its `seq` is the server's count of its output bytes (a resumed one's too). */
|
|
271
|
+
#bind(id, conn, session) {
|
|
272
|
+
conn.session = session;
|
|
273
|
+
session.onData = (data) => {
|
|
274
|
+
this.#out(conn, data);
|
|
275
|
+
if (conn.resume) conn.resume.seq = session.seq;
|
|
276
|
+
this.#bump();
|
|
277
|
+
};
|
|
278
|
+
session.onExit = (code) => {
|
|
279
|
+
conn.exitCode = code;
|
|
280
|
+
conn.resume = null; // nothing to resume: it ended
|
|
281
|
+
this.#say(conn, `\r\n\x1b[2m[the session ended with exit code ${code}]\x1b[0m\r\n`);
|
|
282
|
+
this.#changed(id);
|
|
283
|
+
this.#exited(id, code, "pty");
|
|
284
|
+
};
|
|
285
|
+
session.onClose = () => {
|
|
286
|
+
if (conn.session !== session) return;
|
|
287
|
+
conn.session = null;
|
|
288
|
+
if (conn.status === "connected" && !conn.resume) void this.disconnect(id, { quiet: true });
|
|
289
|
+
this.#changed(id);
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** The connection went without being asked to (the network, the server): keep what Resume needs. */
|
|
294
|
+
#dropped(id, conn, link) {
|
|
295
|
+
if (conn.link !== link) return;
|
|
296
|
+
conn.link = null;
|
|
297
|
+
conn.session = null;
|
|
298
|
+
conn.running = null;
|
|
299
|
+
if (conn.asking) {
|
|
300
|
+
conn.asking.reject(new Error("terminal: the connection dropped"));
|
|
301
|
+
conn.asking = null;
|
|
302
|
+
asksChanged();
|
|
303
|
+
}
|
|
304
|
+
if (conn.status !== "connected") return;
|
|
305
|
+
const resumable = Boolean(conn.resume);
|
|
306
|
+
const why = link.ended?.(); // a companion session's budget or ceiling
|
|
307
|
+
this.#say(conn, `\r\n\x1b[2m[the connection dropped${why ? `: ${why}` : ""}${resumable ? ": Resume picks the session up if the server keeps it" : ""}]\x1b[0m\r\n`);
|
|
308
|
+
this.#set(id, conn, { status: resumable ? "detached" : "disconnected" });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Keys typed in the pane: to the pty, or to the exec mode's line (and, while a command runs, to its stdin). */
|
|
312
|
+
input(id, text) {
|
|
313
|
+
const conn = this.conns.get(id);
|
|
314
|
+
if (!conn || conn.status !== "connected") return;
|
|
315
|
+
if (conn.recorder?.input) this.#rec(conn, "input", text);
|
|
316
|
+
if (conn.session) return void conn.session.write(text).catch(() => {});
|
|
317
|
+
if (conn.running) return this.#toCommand(id, conn, text);
|
|
318
|
+
if (text.length > 1 && text[0] === "\x1b") return; // a key's escape sequence (Delete, Home, F1…): the line editor has no use for it
|
|
319
|
+
for (const ch of text) this.#lineKey(id, conn, ch);
|
|
320
|
+
this.#bump();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
#toCommand(id, conn, text) {
|
|
324
|
+
const session = conn.running;
|
|
325
|
+
if (text === "\x03") return void session.signal("INT").catch(() => {});
|
|
326
|
+
const echoed = text.replace(/\r/g, "\r\n");
|
|
327
|
+
this.#echo(conn, echoed);
|
|
328
|
+
void session.write(text.replace(/\r/g, "\n")).catch(() => {});
|
|
329
|
+
this.#bump();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
#lineKey(id, conn, ch) {
|
|
333
|
+
if (ch === "\r" || ch === "\n") {
|
|
334
|
+
const command = conn.line.trim();
|
|
335
|
+
conn.line = "";
|
|
336
|
+
conn.at = -1;
|
|
337
|
+
this.#echo(conn, "\r\n");
|
|
338
|
+
if (!command) return this.#say(conn, PROMPT);
|
|
339
|
+
conn.history = [...conn.history.filter((h) => h !== command), command].slice(-HISTORY);
|
|
340
|
+
void this.#run(id, conn, command);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (ch === "\x7f" || ch === "\b") {
|
|
344
|
+
if (conn.line) {
|
|
345
|
+
conn.line = conn.line.slice(0, -1);
|
|
346
|
+
this.#echo(conn, "\b \b");
|
|
347
|
+
}
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (ch === "\x03") {
|
|
351
|
+
conn.line = "";
|
|
352
|
+
this.#echo(conn, "^C\r\n");
|
|
353
|
+
return this.#say(conn, PROMPT);
|
|
354
|
+
}
|
|
355
|
+
if (ch === "\x15") {
|
|
356
|
+
// Ctrl-U: the whole line goes
|
|
357
|
+
this.#echo(conn, "\b \b".repeat([...conn.line].length));
|
|
358
|
+
conn.line = "";
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (ch < " ") return; // other controls (and escape sequences' first byte) do nothing here
|
|
362
|
+
conn.line += ch;
|
|
363
|
+
this.#echo(conn, ch);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Up and down in the exec mode's line history (the body sends these as named keys, not escape sequences). */
|
|
367
|
+
historyKey(id, direction) {
|
|
368
|
+
const conn = this.conns.get(id);
|
|
369
|
+
if (!conn || conn.status !== "connected" || conn.session || conn.running || !conn.history.length) return;
|
|
370
|
+
const at = conn.at === -1 ? conn.history.length : conn.at;
|
|
371
|
+
const next = Math.max(0, Math.min(conn.history.length, at + (direction === "up" ? -1 : 1)));
|
|
372
|
+
conn.at = next === conn.history.length ? -1 : next;
|
|
373
|
+
const line = conn.at === -1 ? "" : conn.history[conn.at];
|
|
374
|
+
this.#echo(conn, "\b \b".repeat([...conn.line].length) + line);
|
|
375
|
+
conn.line = line;
|
|
376
|
+
this.#bump();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async #run(id, conn, command) {
|
|
380
|
+
const link = conn.link;
|
|
381
|
+
let session;
|
|
382
|
+
try {
|
|
383
|
+
session = await link.client.openSession({ type: "exec", command, cols: conn.cols, rows: conn.rows });
|
|
384
|
+
if (link.seal) conn.e2e = (await link.seal(session)).algorithm;
|
|
385
|
+
} catch (error) {
|
|
386
|
+
this.#say(conn, `\x1b[31m${message(error)}\x1b[0m\r\n${PROMPT}`);
|
|
387
|
+
this.#bump();
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
conn.running = session;
|
|
391
|
+
const ended = new Promise((resolve) => {
|
|
392
|
+
session.onData = (data) => (this.#out(conn, data), this.#bump());
|
|
393
|
+
session.onExit = (code) => resolve(code);
|
|
394
|
+
session.onClose = () => resolve(undefined);
|
|
395
|
+
});
|
|
396
|
+
this.#bump();
|
|
397
|
+
const code = await ended;
|
|
398
|
+
if (conn.running !== session) return;
|
|
399
|
+
conn.running = null;
|
|
400
|
+
if (code !== undefined && code !== 0) this.#say(conn, `\x1b[2m[exit ${code}]\x1b[0m\r\n`);
|
|
401
|
+
if (conn.link === link) this.#say(conn, PROMPT);
|
|
402
|
+
if (code !== undefined && code !== conn.exitCode) this.#set(id, conn, { exitCode: code });
|
|
403
|
+
else this.#bump();
|
|
404
|
+
if (code !== undefined) this.#exited(id, code, "exec");
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** The pane's size in cells changed: the screen follows, and so does the pty. */
|
|
408
|
+
resize(id, cols, rows) {
|
|
409
|
+
const conn = this.#conn(id);
|
|
410
|
+
cols = Math.max(20, Math.min(400, cols | 0));
|
|
411
|
+
rows = Math.max(4, Math.min(200, rows | 0));
|
|
412
|
+
if (cols === conn.cols && rows === conn.rows) return;
|
|
413
|
+
conn.cols = cols;
|
|
414
|
+
conn.rows = rows;
|
|
415
|
+
conn.screen.resize(cols, rows);
|
|
416
|
+
if (conn.recorder) conn.recorder.rec.record("resize", { cols, rows });
|
|
417
|
+
if (conn.session) void conn.session.resize(cols, rows).catch(() => {});
|
|
418
|
+
this.#bump();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** Leave the session running on the server and disconnect (pty mode, a server that keeps sessions). Keeps the resume token here. */
|
|
422
|
+
async detach(id) {
|
|
423
|
+
const conn = this.conns.get(id);
|
|
424
|
+
if (!conn?.link || !conn.session) throw new Error("terminal: there is no session to detach");
|
|
425
|
+
const link = conn.link;
|
|
426
|
+
const session = conn.session;
|
|
427
|
+
try {
|
|
428
|
+
await link.client.detach(session.sessionId);
|
|
429
|
+
} catch (error) {
|
|
430
|
+
throw new Error(`terminal: the server didn't detach the session (${message(error)}): it must keep sessions (@johnhenry/wsh/server's sessions option)`);
|
|
431
|
+
}
|
|
432
|
+
conn.resume = { sessionId: session.sessionId, token: session.resumeToken ?? conn.resume?.token, seq: session.seq };
|
|
433
|
+
conn.session = null;
|
|
434
|
+
conn.link = null;
|
|
435
|
+
conn.epoch++;
|
|
436
|
+
await link.close();
|
|
437
|
+
this.#say(conn, "\r\n\x1b[2m[detached: the session keeps running on the server; Resume picks it up]\x1b[0m\r\n");
|
|
438
|
+
this.#set(id, conn, { status: "detached" });
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** Connect again and pick the detached session up. */
|
|
442
|
+
resume(id) {
|
|
443
|
+
if (!this.conns.get(id)?.resume) throw new Error("terminal: there is no detached session to resume");
|
|
444
|
+
return this.connect(id, { resume: true });
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/** End the connection (and, in pty mode, the session: a session left running is Detach's). */
|
|
448
|
+
async disconnect(id, { quiet = false } = {}) {
|
|
449
|
+
const conn = this.conns.get(id);
|
|
450
|
+
if (!conn) return;
|
|
451
|
+
conn.epoch++;
|
|
452
|
+
const link = conn.link;
|
|
453
|
+
conn.link = null;
|
|
454
|
+
conn.session = null;
|
|
455
|
+
conn.running = null;
|
|
456
|
+
conn.resume = null;
|
|
457
|
+
conn.line = "";
|
|
458
|
+
if (conn.asking) {
|
|
459
|
+
conn.asking.reject(new Error("terminal: the connection ended"));
|
|
460
|
+
conn.asking = null;
|
|
461
|
+
asksChanged();
|
|
462
|
+
}
|
|
463
|
+
if (link) {
|
|
464
|
+
await link.close();
|
|
465
|
+
if (!quiet) this.#say(conn, "\r\n\x1b[2m[disconnected]\x1b[0m\r\n");
|
|
466
|
+
}
|
|
467
|
+
if (conn.status !== "disconnected" || link) this.#set(id, conn, { status: "disconnected" });
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** The person accepts a server's changed host key: the old pin goes, and the next login pins the new key. */
|
|
471
|
+
async acceptHostKey(id) {
|
|
472
|
+
const conn = this.conns.get(id);
|
|
473
|
+
const changed = conn?.hostKeyChanged;
|
|
474
|
+
if (!changed) throw new Error("terminal: no changed host key to accept");
|
|
475
|
+
forgetHostKey(changed.label);
|
|
476
|
+
conn.hostKeyChanged = null;
|
|
477
|
+
conn.status = "disconnected";
|
|
478
|
+
return this.connect(id);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// ── files (#388) ──────────────────────────────────────────────────────────
|
|
482
|
+
|
|
483
|
+
/** The connection pane `id` moves a file on, or an Error in words. */
|
|
484
|
+
#linked(id) {
|
|
485
|
+
const conn = this.conns.get(id);
|
|
486
|
+
if (!conn?.link || conn.status !== "connected") throw new Error("terminal: connect first: a file moves over the session's connection");
|
|
487
|
+
if (conn.link.demo) throw new Error("terminal: the demo host in this page has no files to send or receive (the wsh lab, or a server you run with fs, has)");
|
|
488
|
+
return conn;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* The person's answer for `direction` ("send" or "receive") on this connection, asked for when there is none: resolves
|
|
493
|
+
* once allowed, rejects when not. One answer a direction a connection.
|
|
494
|
+
*/
|
|
495
|
+
#consent(id, conn, direction) {
|
|
496
|
+
if (conn.consent[direction] === true) return Promise.resolve();
|
|
497
|
+
if (conn.consent[direction] === false) return Promise.reject(new Error(`terminal: you didn't let files be ${direction === "send" ? "sent" : "received"} on this connection (connect again to be asked again)`));
|
|
498
|
+
if (conn.asking) return Promise.reject(new Error("terminal: answer the question about files first"));
|
|
499
|
+
return new Promise((resolve, reject) => {
|
|
500
|
+
conn.asking = { direction, resolve, reject };
|
|
501
|
+
this.#bump();
|
|
502
|
+
asksChanged();
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** The person answers the question the pane shows: may files go `direction` on this connection? */
|
|
507
|
+
answerTransfer(id, direction, allow) {
|
|
508
|
+
const conn = this.conns.get(id);
|
|
509
|
+
const asking = conn?.asking;
|
|
510
|
+
if (!asking || asking.direction !== direction) return false;
|
|
511
|
+
conn.asking = null;
|
|
512
|
+
conn.consent = { ...conn.consent, [direction]: Boolean(allow) };
|
|
513
|
+
if (allow) asking.resolve();
|
|
514
|
+
else asking.reject(new Error(`terminal: you didn't let files be ${direction === "send" ? "sent" : "received"} on this connection`));
|
|
515
|
+
this.#bump();
|
|
516
|
+
asksChanged();
|
|
517
|
+
return true;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** `promise`, or a refusal after TRANSFER_LIMITS.ms (wsh's client can wait forever for an answer a server sent early). */
|
|
521
|
+
#deadline(promise, what) {
|
|
522
|
+
let timer;
|
|
523
|
+
const late = new Promise((_, reject) => (timer = setTimeout(() => reject(new Error(`terminal: ${what} got no answer in ${TRANSFER_LIMITS.ms / 1000} s`)), TRANSFER_LIMITS.ms)));
|
|
524
|
+
return Promise.race([promise, late]).finally(() => clearTimeout(timer));
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
#transfer(id, conn, patch) {
|
|
528
|
+
conn.transfer = { ...(conn.transfer ?? {}), ...patch };
|
|
529
|
+
this.#bump();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/** Send a file the person picked (`{ name, bytes }`) to `path` under the server's file root. Resolves with `{ path, bytes }`. */
|
|
533
|
+
async sendFile(id, file, path) {
|
|
534
|
+
const conn = this.#linked(id);
|
|
535
|
+
const why = transferPathProblem(path);
|
|
536
|
+
if (why) throw new Error(`terminal: ${why}`);
|
|
537
|
+
const bytes = file?.bytes instanceof Uint8Array ? file.bytes : new Uint8Array(file?.bytes ?? 0);
|
|
538
|
+
const limit = transferLimit(wshSettings(this.canvas.panes.get(id)).url);
|
|
539
|
+
if (bytes.byteLength > limit) throw new Error(`terminal: ${file?.name ?? "that file"} is ${sizeWords(bytes.byteLength)}; at most ${sizeWords(limit)} goes in one transfer here`);
|
|
540
|
+
await this.#consent(id, conn, "send");
|
|
541
|
+
const link = conn.link;
|
|
542
|
+
if (!link) throw new Error("terminal: the connection ended");
|
|
543
|
+
this.#transfer(id, conn, { direction: "send", path, bytes: bytes.byteLength, state: "sending", error: undefined });
|
|
544
|
+
try {
|
|
545
|
+
await this.#deadline(link.client.upload(bytes, path), `sending ${path}`);
|
|
546
|
+
} catch (error) {
|
|
547
|
+
this.#transfer(id, conn, { state: "failed", error: message(error) });
|
|
548
|
+
throw new Error(`terminal: ${path} wasn't sent: ${message(error).replace(/^terminal: /, "")}`);
|
|
549
|
+
}
|
|
550
|
+
this.#transfer(id, conn, { state: "done" });
|
|
551
|
+
return { path, bytes: bytes.byteLength };
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** Receive the file at `path` under the server's file root: `{ name, path, bytes }` (the page saves it where the person says). */
|
|
555
|
+
async receiveFile(id, path) {
|
|
556
|
+
const conn = this.#linked(id);
|
|
557
|
+
const why = transferPathProblem(path);
|
|
558
|
+
if (why) throw new Error(`terminal: ${why}`);
|
|
559
|
+
const limit = transferLimit(wshSettings(this.canvas.panes.get(id)).url);
|
|
560
|
+
await this.#consent(id, conn, "receive");
|
|
561
|
+
const link = conn.link;
|
|
562
|
+
if (!link) throw new Error("terminal: the connection ended");
|
|
563
|
+
this.#transfer(id, conn, { direction: "receive", path, bytes: undefined, state: "receiving", error: undefined });
|
|
564
|
+
try {
|
|
565
|
+
// Its size first, so a file over the bound is refused before any of it comes.
|
|
566
|
+
// A server that does not do `stat` (the Rust wsh-server, as in a vm's guest) says so; then the download's own progress carries the bound below.
|
|
567
|
+
const unsupported = (text) => /not (yet )?implemented|unsupported|unknown file operation/i.test(String(text ?? ""));
|
|
568
|
+
let info;
|
|
569
|
+
try {
|
|
570
|
+
info = await this.#deadline(link.client.fileStat(path), `looking ${path} up`);
|
|
571
|
+
} catch (error) {
|
|
572
|
+
if (!unsupported(message(error))) throw error;
|
|
573
|
+
}
|
|
574
|
+
if (info && !info.success && !unsupported(info.error_message ?? info.errorMessage)) throw new Error(info.error_message ?? info.errorMessage ?? "no such file");
|
|
575
|
+
if (info?.success) {
|
|
576
|
+
const size = Number(info.metadata?.size);
|
|
577
|
+
if (info.metadata?.type && info.metadata.type !== "file") throw new Error(`it is a ${info.metadata.type}, not a file`);
|
|
578
|
+
if (Number.isFinite(size) && size > limit) throw new Error(`it is ${sizeWords(size)}; at most ${sizeWords(limit)} comes in one transfer here`);
|
|
579
|
+
}
|
|
580
|
+
const data = await this.#deadline(
|
|
581
|
+
link.client.download(path, {
|
|
582
|
+
onProgress: ({ total }) => {
|
|
583
|
+
if (total > limit) throw new Error(`it is ${sizeWords(total)}; at most ${sizeWords(limit)} comes in one transfer here`);
|
|
584
|
+
},
|
|
585
|
+
}),
|
|
586
|
+
`receiving ${path}`,
|
|
587
|
+
);
|
|
588
|
+
this.#transfer(id, conn, { state: "done", bytes: data.byteLength });
|
|
589
|
+
return { name: path.split("/").pop(), path, bytes: data };
|
|
590
|
+
} catch (error) {
|
|
591
|
+
this.#transfer(id, conn, { state: "failed", error: message(error) });
|
|
592
|
+
throw new Error(`terminal: ${path} wasn't received: ${message(error).replace(/^terminal: /, "")}`);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// ── recording (#388) ──────────────────────────────────────────────────────
|
|
597
|
+
|
|
598
|
+
/** Note what the screen is sent (or, with "include input", what is typed) in the recording under way. */
|
|
599
|
+
#rec(conn, type, data) {
|
|
600
|
+
const r = conn.recorder;
|
|
601
|
+
if (!r) return;
|
|
602
|
+
const text = typeof data === "string" ? data : r.decoder.decode(data, { stream: true });
|
|
603
|
+
if (!text) return;
|
|
604
|
+
r.bytes += text.length;
|
|
605
|
+
if (r.bytes > TRANSFER_LIMITS.recordingBytes) return this.#stopRec(conn, `it stopped at ${sizeWords(TRANSFER_LIMITS.recordingBytes)}, the most a recording keeps`);
|
|
606
|
+
r.rec.record(type, text);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** Start recording pane `id`'s screen (wsh's SessionRecorder). `input`: also what is typed (off by default: passwords). */
|
|
610
|
+
async startRecording(id, { input = false } = {}) {
|
|
611
|
+
const pane = this.canvas.panes.get(id);
|
|
612
|
+
if (pane?.type !== "terminal") throw new Error(`terminal: there is no terminal pane ${JSON.stringify(id)}`);
|
|
613
|
+
const conn = this.#conn(id);
|
|
614
|
+
if (conn.recorder) return this.status(id);
|
|
615
|
+
const wsh = await this.wshFn();
|
|
616
|
+
const rec = new wsh.SessionRecorder(`mallory-${id}`, { width: conn.cols, height: conn.rows });
|
|
617
|
+
const hadValue = conn.recorded?.inValue;
|
|
618
|
+
conn.recorder = { rec, input: Boolean(input), bytes: 0, decoder: new TextDecoder() };
|
|
619
|
+
conn.recorded = null; // a new recording replaces the last
|
|
620
|
+
if (hadValue) this.#changed(id);
|
|
621
|
+
else this.#bump();
|
|
622
|
+
return this.status(id);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
#stopRec(conn, note) {
|
|
626
|
+
const r = conn.recorder;
|
|
627
|
+
if (!r) return;
|
|
628
|
+
conn.recorder = null;
|
|
629
|
+
const doc = r.rec.toJSON();
|
|
630
|
+
const cast = castText(doc, { input: r.input });
|
|
631
|
+
const kept = cast.trimEnd().split("\n").length - 1;
|
|
632
|
+
conn.recorded = { cast, input: r.input, seconds: doc.events.length ? Number(doc.events.at(-1)[0]) : 0, events: kept, inValue: false, ...(note ? { note } : {}) };
|
|
633
|
+
this.#bump();
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/** Stop the recording under way: it is kept here (to save, or to put in the pane's value) until the next one. */
|
|
637
|
+
stopRecording(id) {
|
|
638
|
+
const conn = this.conns.get(id);
|
|
639
|
+
if (!conn?.recorder) throw new Error("terminal: nothing is being recorded");
|
|
640
|
+
this.#stopRec(conn);
|
|
641
|
+
return this.status(id);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** The stopped recording: `{ format: "asciicast-v2", input, seconds, events, cast }`, or null. */
|
|
645
|
+
recording(id) {
|
|
646
|
+
const r = this.conns.get(id)?.recorded;
|
|
647
|
+
return r ? { format: "asciicast-v2", input: r.input, seconds: r.seconds, events: r.events, cast: r.cast } : null;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/** Put the stopped recording in the pane's value (so a wire carries it), or take it out. Only the person does. */
|
|
651
|
+
recordingToValue(id, on = true) {
|
|
652
|
+
const conn = this.conns.get(id);
|
|
653
|
+
if (!conn?.recorded) throw new Error("terminal: there is no stopped recording");
|
|
654
|
+
if (conn.recorded.inValue === Boolean(on)) return;
|
|
655
|
+
conn.recorded.inValue = Boolean(on);
|
|
656
|
+
this.#changed(id);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/** Forget the stopped recording (and take it out of the value). */
|
|
660
|
+
discardRecording(id) {
|
|
661
|
+
const conn = this.conns.get(id);
|
|
662
|
+
if (!conn?.recorded) return;
|
|
663
|
+
const was = conn.recorded.inValue;
|
|
664
|
+
conn.recorded = null;
|
|
665
|
+
if (was) this.#changed(id);
|
|
666
|
+
else this.#bump();
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** Clear the screen (the pane's menu). */
|
|
670
|
+
clear(id) {
|
|
671
|
+
const conn = this.conns.get(id);
|
|
672
|
+
if (!conn) return;
|
|
673
|
+
conn.screen.reset();
|
|
674
|
+
if (conn.status === "connected" && !conn.session && !conn.running) this.#say(conn, PROMPT + conn.line);
|
|
675
|
+
this.#bump();
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** A pane's connection settings changed: its connection ends (the next Connect uses the new ones). */
|
|
679
|
+
settingsChanged(id) {
|
|
680
|
+
const conn = this.conns.get(id);
|
|
681
|
+
if (conn && conn.status !== "disconnected") void this.disconnect(id);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/** Panes that went (deleted, deactivated, no longer terminals): their connections end. */
|
|
685
|
+
sync() {
|
|
686
|
+
for (const id of [...this.conns.keys()]) {
|
|
687
|
+
const c = this.canvas;
|
|
688
|
+
if (c.attached?.has(id) && c.panes.get(id)?.type === "terminal" && !c.isDisabled?.(id)) continue;
|
|
689
|
+
const conn = this.conns.get(id);
|
|
690
|
+
this.conns.delete(id);
|
|
691
|
+
conn.epoch++;
|
|
692
|
+
if (conn.link) void conn.link.close();
|
|
693
|
+
}
|
|
694
|
+
this.#bump();
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/** The canvas closed: every connection ends. */
|
|
698
|
+
dispose() {
|
|
699
|
+
hubs.delete(this);
|
|
700
|
+
for (const conn of this.conns.values()) {
|
|
701
|
+
conn.epoch++;
|
|
702
|
+
if (conn.asking) (conn.asking.reject(new Error("terminal: closed")), (conn.asking = null)); // an unanswered question is a no
|
|
703
|
+
if (conn.link) void conn.link.close();
|
|
704
|
+
conn.link = null;
|
|
705
|
+
}
|
|
706
|
+
this.conns.clear();
|
|
707
|
+
this.#bump();
|
|
708
|
+
asksChanged();
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/** How many connections are open (debugging, lifecycle tests). */
|
|
712
|
+
get open() {
|
|
713
|
+
return [...this.conns.values()].filter((c) => c.link).length;
|
|
714
|
+
}
|
|
715
|
+
}
|