@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,477 @@
|
|
|
1
|
+
// A runner reachable from other computers (#362.2, decided in #688): `mallory serve --remote-listen <address:port>`.
|
|
2
|
+
// Node-only (src/headless/ is never bundled). Off unless asked for; the loopback listener and everything on it are
|
|
3
|
+
// unchanged. The wire format is src/run/runner-pairing.js; the threat model is docs/guide/cli-and-serving.md's "Runners on other computers
|
|
4
|
+
// (pairing and TLS)".
|
|
5
|
+
//
|
|
6
|
+
// What the remote listener is:
|
|
7
|
+
// - TLS only (node:https, TLS 1.2 or later), with a certificate the runner makes for itself in its --remote-dir (ECDSA
|
|
8
|
+
// P-256, self-signed, kept for the next start so a pairing survives a restart) or one the person gives
|
|
9
|
+
// (--remote-cert/--remote-key). Its SHA-256 fingerprint is printed at the terminal;
|
|
10
|
+
// - the monitor's two read-only routes (status, runs; not the stream) and the pairing route, nothing else: no webhook,
|
|
11
|
+
// no decision page, no companion, no listing. Anything else is 404;
|
|
12
|
+
// - paired pages only: a one-time code at the terminal (80 bits, five minutes, ten wrong attempts lock pairing until a
|
|
13
|
+
// new code is made there), bound to the certificate's fingerprint and the page's own public key, never sent itself;
|
|
14
|
+
// after pairing every request is signed by that page's key and every answer by the runner's;
|
|
15
|
+
// - revocable: the paired pages live in <dir>/paired.json (0600), re-read when it changes, so `mallory serve
|
|
16
|
+
// --remote-dir DIR --remote-revoke <id|all>` from another terminal takes effect at the next request; the terminal of
|
|
17
|
+
// the running runner takes `revoke <id>` too, and a page can revoke itself;
|
|
18
|
+
// - fail closed: a missing or unreadable file, a malformed entry, a clock outside the window, a nonce seen before, a
|
|
19
|
+
// full nonce memory, an unknown key or a bad signature is a refusal, never a fallback to something looser.
|
|
20
|
+
import { createServer as createHttpsServer } from "node:https";
|
|
21
|
+
import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, randomBytes, sign as cryptoSign, verify as cryptoVerify, X509Certificate, timingSafeEqual, createHmac } from "node:crypto";
|
|
22
|
+
import { mkdir, readFile, writeFile, rename, lstat, chmod, stat, realpath } from "node:fs/promises";
|
|
23
|
+
import { networkInterfaces } from "node:os";
|
|
24
|
+
import { join, resolve } from "node:path";
|
|
25
|
+
import { isIP } from "node:net";
|
|
26
|
+
import { createRateLimit, createThrottle, checkOrigin } from "./guard.js";
|
|
27
|
+
import { PAIR_PATH, PAIR_PROTOCOL, PAIR_VERSION, PAIR_LIMITS, TIME_WINDOW_MS, pairMessage, requestMessage, responseMessage, formatPairCode, pairCodeFromBytes, publicJwkProblem, jwkThumbprint, pageIdOf, nonceProblem, toBase64url, fromBase64url } from "../run/runner-pairing.js";
|
|
28
|
+
import { MONITOR_PREFIX } from "../run/monitor.js";
|
|
29
|
+
|
|
30
|
+
const CERT_FILE = "runner-cert.pem";
|
|
31
|
+
const KEY_FILE = "runner-key.pem";
|
|
32
|
+
const PAIRED_FILE = "paired.json";
|
|
33
|
+
const CERT_DAYS = 397;
|
|
34
|
+
|
|
35
|
+
// ── a self-signed certificate, in DER, with nothing but node:crypto ───────────
|
|
36
|
+
|
|
37
|
+
const derLength = (n) => (n < 0x80 ? [n] : n < 0x100 ? [0x81, n] : n < 0x10000 ? [0x82, n >> 8, n & 0xff] : [0x83, n >> 16, (n >> 8) & 0xff, n & 0xff]);
|
|
38
|
+
const der = (tag, ...parts) => {
|
|
39
|
+
const body = Buffer.concat(parts.map((p) => (Buffer.isBuffer(p) ? p : Buffer.from(p))));
|
|
40
|
+
return Buffer.concat([Buffer.from([tag, ...derLength(body.length)]), body]);
|
|
41
|
+
};
|
|
42
|
+
const seq = (...parts) => der(0x30, ...parts);
|
|
43
|
+
const set = (...parts) => der(0x31, ...parts);
|
|
44
|
+
function oid(text) {
|
|
45
|
+
const [a, b, ...rest] = text.split(".").map(Number);
|
|
46
|
+
const out = [a * 40 + b];
|
|
47
|
+
for (const n of rest) {
|
|
48
|
+
const bytes = [n & 0x7f];
|
|
49
|
+
for (let v = Math.floor(n / 128); v > 0; v = Math.floor(v / 128)) bytes.unshift((v & 0x7f) | 0x80);
|
|
50
|
+
out.push(...bytes);
|
|
51
|
+
}
|
|
52
|
+
return der(0x06, out);
|
|
53
|
+
}
|
|
54
|
+
/** A DER INTEGER, minimal: redundant leading zero bytes dropped, one added where the high bit would read as negative (a serial starting 00 7f… is refused by OpenSSL as "illegal padding"). */
|
|
55
|
+
function integer(bytes) {
|
|
56
|
+
let start = 0;
|
|
57
|
+
while (start < bytes.length - 1 && bytes[start] === 0 && !(bytes[start + 1] & 0x80)) start++;
|
|
58
|
+
const body = bytes.subarray(start);
|
|
59
|
+
return der(0x02, body[0] & 0x80 ? Buffer.concat([Buffer.from([0]), body]) : body);
|
|
60
|
+
}
|
|
61
|
+
const utc = (date) => der(0x17, Buffer.from(`${date.toISOString().replace(/[-:T]/g, "").slice(2, 14)}Z`));
|
|
62
|
+
const name = (cn) => seq(set(seq(oid("2.5.4.3"), der(0x0c, Buffer.from(cn)))));
|
|
63
|
+
function ipBytes(ip) {
|
|
64
|
+
if (isIP(ip) === 4) return Buffer.from(ip.split(".").map(Number));
|
|
65
|
+
// IPv6: expand ::
|
|
66
|
+
const [head, tail = ""] = ip.split("::");
|
|
67
|
+
const h = head ? head.split(":") : [];
|
|
68
|
+
const t = tail ? tail.split(":") : [];
|
|
69
|
+
const groups = ip.includes("::") ? [...h, ...Array(8 - h.length - t.length).fill("0"), ...t] : h;
|
|
70
|
+
return Buffer.from(groups.flatMap((g) => [parseInt(g, 16) >> 8, parseInt(g, 16) & 0xff]));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* A self-signed certificate for `names` (host names and IP addresses the page will use), ECDSA P-256, valid from an hour
|
|
75
|
+
* ago for CERT_DAYS days. Returns `{ certPem, keyPem }`.
|
|
76
|
+
*/
|
|
77
|
+
export function selfSignedCertificate(names, { now = Date.now() } = {}) {
|
|
78
|
+
const { privateKey, publicKey } = generateKeyPairSync("ec", { namedCurve: "P-256" });
|
|
79
|
+
const ecdsaSha256 = seq(oid("1.2.840.10045.4.3.2"));
|
|
80
|
+
const serial = randomBytes(16);
|
|
81
|
+
serial[0] &= 0x7f;
|
|
82
|
+
const san = [...new Set(names)].map((n) => (isIP(n) ? der(0x87, ipBytes(n)) : der(0x82, Buffer.from(n))));
|
|
83
|
+
const extensions = der(
|
|
84
|
+
0xa3,
|
|
85
|
+
seq(
|
|
86
|
+
seq(oid("2.5.29.19"), der(0x01, [0xff]), der(0x04, seq())), // basicConstraints, critical: not a CA
|
|
87
|
+
seq(oid("2.5.29.15"), der(0x01, [0xff]), der(0x04, der(0x03, [0x07, 0x80]))), // keyUsage, critical: digitalSignature
|
|
88
|
+
seq(oid("2.5.29.37"), der(0x04, seq(oid("1.3.6.1.5.5.7.3.1")))), // extKeyUsage: serverAuth
|
|
89
|
+
...(san.length ? [seq(oid("2.5.29.17"), der(0x04, seq(...san)))] : []), // subjectAltName
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
const tbs = seq(der(0xa0, integer(Buffer.from([2]))), integer(serial), ecdsaSha256, name("mallory runner"), seq(utc(new Date(now - 3600_000)), utc(new Date(now + CERT_DAYS * 86400_000))), name("mallory runner"), publicKey.export({ type: "spki", format: "der" }), extensions);
|
|
93
|
+
const signature = cryptoSign("sha256", tbs, privateKey); // DER-encoded ECDSA, as X.509 wants
|
|
94
|
+
const cert = seq(tbs, ecdsaSha256, der(0x03, Buffer.concat([Buffer.from([0]), signature])));
|
|
95
|
+
const certPem = `-----BEGIN CERTIFICATE-----\n${cert.toString("base64").match(/.{1,64}/g).join("\n")}\n-----END CERTIFICATE-----\n`;
|
|
96
|
+
return { certPem, keyPem: privateKey.export({ type: "pkcs8", format: "pem" }) };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ── the runner's identity ─────────────────────────────────────────────────────
|
|
100
|
+
|
|
101
|
+
/** Make (0700) or check the runner's directory (or the tunnel's, `flag` naming it in errors): a real directory, not a symlink, that other users can't write to. */
|
|
102
|
+
export async function prepareRemoteDir(dir, flag = "--remote-dir") {
|
|
103
|
+
if (typeof dir !== "string" || !dir.trim()) throw new Error(`${flag} takes a directory path`);
|
|
104
|
+
const root = resolve(dir);
|
|
105
|
+
const existing = await lstat(root).catch(() => null);
|
|
106
|
+
if (existing?.isSymbolicLink()) throw new Error(`${flag} ${dir}: a symbolic link isn't accepted (name the directory itself)`);
|
|
107
|
+
if (existing && !existing.isDirectory()) throw new Error(`${flag} ${dir}: that isn't a directory`);
|
|
108
|
+
if (!existing) await mkdir(root, { recursive: true, mode: 0o700 });
|
|
109
|
+
else if (process.platform !== "win32" && (existing.mode & 0o077) !== 0) throw new Error(`${flag} ${dir}: other users can read or write it (chmod 700 it, or name a private directory)`);
|
|
110
|
+
if (process.platform !== "win32") await chmod(root, 0o700);
|
|
111
|
+
return await realpath(root);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const writePrivate = async (file, text) => {
|
|
115
|
+
const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
|
|
116
|
+
await writeFile(tmp, text, { mode: 0o600, flag: "wx" });
|
|
117
|
+
await rename(tmp, file);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The certificate and key the remote listener uses, and how it signs: `{ certPem, keyPem, der, fingerprint (hex),
|
|
122
|
+
* kind: "ec" | "rsa", sign(message) => base64url, names, source }`. `cert`/`key`: files the person gave (PEM; the
|
|
123
|
+
* key EC P-256 or RSA of 2048 bits or more, matching the certificate). Otherwise the one in `dir`, made on first use
|
|
124
|
+
* (or anew with `regenerate`, which voids every pairing: they are bound to the fingerprint).
|
|
125
|
+
*/
|
|
126
|
+
export async function loadIdentity({ dir, cert, key, names = [], regenerate = false, now = Date.now }) {
|
|
127
|
+
let certPem;
|
|
128
|
+
let keyPem;
|
|
129
|
+
let source;
|
|
130
|
+
if (cert || key) {
|
|
131
|
+
if (!cert || !key) throw new Error("--remote-cert and --remote-key go together");
|
|
132
|
+
certPem = await readFile(cert, "utf8").catch(() => {
|
|
133
|
+
throw new Error(`--remote-cert ${cert}: can't read it`);
|
|
134
|
+
});
|
|
135
|
+
keyPem = await readFile(key, "utf8").catch(() => {
|
|
136
|
+
throw new Error(`--remote-key ${key}: can't read it`);
|
|
137
|
+
});
|
|
138
|
+
source = "provided";
|
|
139
|
+
} else {
|
|
140
|
+
const certFile = join(dir, CERT_FILE);
|
|
141
|
+
const keyFile = join(dir, KEY_FILE);
|
|
142
|
+
const have = !regenerate && (await stat(certFile).catch(() => null)) && (await stat(keyFile).catch(() => null));
|
|
143
|
+
if (have) {
|
|
144
|
+
const keyStat = await lstat(keyFile);
|
|
145
|
+
if (keyStat.isSymbolicLink() || (process.platform !== "win32" && (keyStat.mode & 0o077) !== 0)) throw new Error(`${keyFile}: the runner's key must be a private file (0600, not a link)`);
|
|
146
|
+
certPem = await readFile(certFile, "utf8");
|
|
147
|
+
keyPem = await readFile(keyFile, "utf8");
|
|
148
|
+
source = "kept";
|
|
149
|
+
} else {
|
|
150
|
+
({ certPem, keyPem } = selfSignedCertificate(names, { now: now() }));
|
|
151
|
+
await writePrivate(keyFile, keyPem).catch(async (error) => {
|
|
152
|
+
if (error.code !== "EEXIST") throw error;
|
|
153
|
+
await writeFile(keyFile, keyPem, { mode: 0o600 });
|
|
154
|
+
});
|
|
155
|
+
if (process.platform !== "win32") await chmod(keyFile, 0o600);
|
|
156
|
+
await writeFile(certFile, certPem, { mode: 0o644 });
|
|
157
|
+
source = "generated";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let x509;
|
|
161
|
+
let privateKey;
|
|
162
|
+
try {
|
|
163
|
+
x509 = new X509Certificate(certPem);
|
|
164
|
+
privateKey = createPrivateKey(keyPem);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
throw new Error(`the runner's certificate or key can't be read: ${error.message}`);
|
|
167
|
+
}
|
|
168
|
+
if (!x509.checkPrivateKey(privateKey)) throw new Error("the runner's key doesn't belong to its certificate");
|
|
169
|
+
const details = privateKey.asymmetricKeyDetails ?? {};
|
|
170
|
+
let kind;
|
|
171
|
+
if (privateKey.asymmetricKeyType === "ec" && details.namedCurve === "prime256v1") kind = "ec";
|
|
172
|
+
else if (privateKey.asymmetricKeyType === "rsa" && (details.modulusLength ?? 0) >= 2048) kind = "rsa";
|
|
173
|
+
else throw new Error("the runner's key must be EC P-256 or RSA of 2048 bits or more (what a browser can check)");
|
|
174
|
+
const raw = x509.raw;
|
|
175
|
+
const fingerprint = createHash("sha256").update(raw).digest("hex");
|
|
176
|
+
const sign = (message) => toBase64url(kind === "ec" ? cryptoSign("sha256", Buffer.from(message), { key: privateKey, dsaEncoding: "ieee-p1363" }) : cryptoSign("sha256", Buffer.from(message), { key: privateKey, padding: 6 /* RSA_PKCS1_PSS_PADDING */, saltLength: 32 }));
|
|
177
|
+
const san = String(x509.subjectAltName ?? "")
|
|
178
|
+
.split(/,\s*/)
|
|
179
|
+
.map((s) => s.replace(/^(DNS|IP Address):/, ""))
|
|
180
|
+
.filter(Boolean);
|
|
181
|
+
const expired = Date.parse(x509.validTo) < now();
|
|
182
|
+
return { certPem, keyPem, der: new Uint8Array(raw), fingerprint, kind, sign, names: san, source, expired, validTo: x509.validTo };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ── the paired pages ──────────────────────────────────────────────────────────
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* <dir>/paired.json: `{ fingerprint, pages: [{ id, label, jwk, created }] }`. Read again whenever it changes on disk
|
|
189
|
+
* (a revoke from another terminal is at the next request); written whole, privately, by rename. Entries for another
|
|
190
|
+
* fingerprint (the certificate changed) and malformed entries count as none.
|
|
191
|
+
*/
|
|
192
|
+
export function pairedPages(dir, fingerprint) {
|
|
193
|
+
const file = join(dir, PAIRED_FILE);
|
|
194
|
+
// Keyed by the file's identity too: a change from another terminal is a new file (written, then renamed), and on a
|
|
195
|
+
// coarse clock it can have the old one's mtime and size (one page revoked, another of the same length paired).
|
|
196
|
+
const NONE = { key: "", pages: [] };
|
|
197
|
+
const keyOf = (st) => `${st.dev}:${st.ino}:${st.mtimeMs}:${st.ctimeMs}:${st.size}`;
|
|
198
|
+
let cache = NONE;
|
|
199
|
+
const valid = (p) => p && typeof p.id === "string" && /^[A-Za-z0-9_-]{16}$/.test(p.id) && !publicJwkProblem(p.jwk) && typeof p.label === "string" && p.label.length <= PAIR_LIMITS.label;
|
|
200
|
+
async function read() {
|
|
201
|
+
const st = await stat(file).catch(() => null);
|
|
202
|
+
if (!st) return (cache = NONE).pages;
|
|
203
|
+
if (keyOf(st) === cache.key) return cache.pages;
|
|
204
|
+
let pages = [];
|
|
205
|
+
try {
|
|
206
|
+
const raw = JSON.parse(await readFile(file, "utf8"));
|
|
207
|
+
pages = raw?.fingerprint === fingerprint && Array.isArray(raw.pages) ? raw.pages.filter(valid).slice(0, PAIR_LIMITS.pages) : [];
|
|
208
|
+
} catch {
|
|
209
|
+
pages = []; // unreadable: nobody is paired (fail closed)
|
|
210
|
+
}
|
|
211
|
+
cache = { key: keyOf(st), pages };
|
|
212
|
+
return pages;
|
|
213
|
+
}
|
|
214
|
+
async function write(pages) {
|
|
215
|
+
await writePrivate(file, `${JSON.stringify({ fingerprint, pages }, null, 2)}\n`);
|
|
216
|
+
cache = NONE;
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
file,
|
|
220
|
+
list: read,
|
|
221
|
+
async find(id) {
|
|
222
|
+
return (await read()).find((p) => p.id === id);
|
|
223
|
+
},
|
|
224
|
+
async add(page) {
|
|
225
|
+
const pages = (await read()).filter((p) => p.id !== page.id);
|
|
226
|
+
if (pages.length >= PAIR_LIMITS.pages) throw Object.assign(new Error(`at most ${PAIR_LIMITS.pages} pages may be paired: revoke one at the runner's terminal`), { status: 409 });
|
|
227
|
+
await write([...pages, page]);
|
|
228
|
+
},
|
|
229
|
+
/** Revoke one page by id (or a prefix of at least 6 characters), or "all". The ids revoked. */
|
|
230
|
+
async revoke(which) {
|
|
231
|
+
const pages = await read();
|
|
232
|
+
const gone = which === "all" ? pages : pages.filter((p) => p.id === which || (String(which).length >= 6 && p.id.startsWith(which)));
|
|
233
|
+
if (gone.length) await write(pages.filter((p) => !gone.includes(p)));
|
|
234
|
+
return gone.map((p) => p.id);
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ── the listener ──────────────────────────────────────────────────────────────
|
|
240
|
+
|
|
241
|
+
/** What one remote listener holds each client to, and everyone behind it. Tests pass smaller ones. */
|
|
242
|
+
export const REMOTE_LIMITS = {
|
|
243
|
+
requests: 120, // per client per window
|
|
244
|
+
totalRequests: 600,
|
|
245
|
+
windowMs: 60000,
|
|
246
|
+
clients: 256,
|
|
247
|
+
wrongAuth: 10, // bad signatures, unknown keys, stale times per client per window
|
|
248
|
+
wrongAuthTotal: 100,
|
|
249
|
+
nonces: 4096, // nonces remembered for replay; when full, signed requests wait (429) rather than go unchecked
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const clientOf = (req) => String(req.socket?.remoteAddress ?? "unknown");
|
|
253
|
+
|
|
254
|
+
/** The names a Host header may carry: the listen address, --remote-name values, this machine's addresses. */
|
|
255
|
+
export function allowedHostNames({ listenHost, names = [] }) {
|
|
256
|
+
const out = new Set(names.map((n) => n.toLowerCase()));
|
|
257
|
+
if (listenHost && !["0.0.0.0", "::", "[::]"].includes(listenHost)) out.add(listenHost.replace(/^\[|\]$/g, "").toLowerCase());
|
|
258
|
+
else for (const list of Object.values(networkInterfaces())) for (const a of list ?? []) if (!a.internal) out.add(a.address.toLowerCase());
|
|
259
|
+
return out;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function hostOf(header) {
|
|
263
|
+
const v = String(header ?? "").toLowerCase();
|
|
264
|
+
const m = /^(\[[0-9a-f:.]+\]|[a-z0-9.-]+)(?::(\d+))?$/.exec(v);
|
|
265
|
+
return m ? { host: m[1].replace(/^\[|\]$/g, ""), port: m[2] === undefined ? undefined : Number(m[2]) } : undefined;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The remote listener's request handling, without the socket (tests drive it with plain objects). `monitor` is the
|
|
270
|
+
* runner's monitor (src/headless/monitor.js), answered with `authorized: true` once a request's signature checks out.
|
|
271
|
+
*/
|
|
272
|
+
export function createRemoteRunner({ identity, pages, origin, monitor, hosts, port, scrub = (t) => t, stdout = () => {}, now = Date.now, limits: given = {} }) {
|
|
273
|
+
const limits = { ...REMOTE_LIMITS, ...given };
|
|
274
|
+
const rate = createRateLimit({ max: limits.requests, windowMs: limits.windowMs, now, clients: limits.clients });
|
|
275
|
+
const rateAll = createRateLimit({ max: limits.totalRequests, windowMs: limits.windowMs, now, clients: 1 });
|
|
276
|
+
const wrong = createRateLimit({ max: limits.wrongAuth, windowMs: limits.windowMs, now, clients: limits.clients });
|
|
277
|
+
const wrongAll = createRateLimit({ max: limits.wrongAuthTotal, windowMs: limits.windowMs, now, clients: 1 });
|
|
278
|
+
let codeThrottle = createThrottle({ max: PAIR_LIMITS.wrongCodes, windowMs: Infinity, now });
|
|
279
|
+
const seen = new Map(); // nonce -> forget after
|
|
280
|
+
let pairing = null; // { code, expires }
|
|
281
|
+
let listenPort = port; // the port the Host header must name (the real one, once listening on port 0)
|
|
282
|
+
const lastSeen = new Map(); // page id -> time, in memory, for `list` at the terminal
|
|
283
|
+
|
|
284
|
+
const remember = (nonce) => {
|
|
285
|
+
const t = now();
|
|
286
|
+
for (const [n, until] of seen) {
|
|
287
|
+
if (until > t) break;
|
|
288
|
+
seen.delete(n);
|
|
289
|
+
}
|
|
290
|
+
if (seen.has(nonce)) return "replay";
|
|
291
|
+
if (seen.size >= limits.nonces) return "full";
|
|
292
|
+
seen.set(nonce, t + 2 * TIME_WINDOW_MS);
|
|
293
|
+
return "ok";
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const newCode = () => {
|
|
297
|
+
pairing = { code: pairCodeFromBytes(randomBytes(16)), expires: now() + PAIR_LIMITS.codeMs };
|
|
298
|
+
codeThrottle = createThrottle({ max: PAIR_LIMITS.wrongCodes, windowMs: Infinity, now }); // a new code from the terminal unlocks
|
|
299
|
+
return formatPairCode(pairing.code);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/** Write an answer, signed by the runner's key over the request's nonce, the status, the time and the body. */
|
|
303
|
+
function answer(res, status, body, { nonce = "", headers = {} } = {}) {
|
|
304
|
+
const text = status === 204 ? "" : scrub(typeof body === "string" ? body : JSON.stringify(body));
|
|
305
|
+
const time = String(now());
|
|
306
|
+
const bodyHash = createHash("sha256").update(text).digest("hex");
|
|
307
|
+
const signature = identity.sign(responseMessage({ nonce, status, time, bodyHash }));
|
|
308
|
+
res.writeHead(status, { ...(status === 204 ? {} : { "content-type": "application/json; charset=utf-8" }), "x-content-type-options": "nosniff", "cache-control": "no-store", "x-mallory-time": time, "x-mallory-signature": signature, ...headers });
|
|
309
|
+
res.end(text);
|
|
310
|
+
return status;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async function pair(req, res, cors) {
|
|
314
|
+
if (!pairing || now() > pairing.expires) return answer(res, 403, { error: "no pairing code is active: type r then Enter at the runner's terminal for a new one" }, { headers: cors });
|
|
315
|
+
if (codeThrottle.blocked()) return answer(res, 423, { error: "pairing is locked after too many wrong attempts: make a new code at the runner's terminal (r then Enter)" }, { headers: cors });
|
|
316
|
+
// The pairing request carries its payload in one header (base64url JSON), so the page sends it through the same
|
|
317
|
+
// network-policy request as every other; a body is never read.
|
|
318
|
+
let body;
|
|
319
|
+
try {
|
|
320
|
+
const raw = String(req.headers["x-mallory-pair"] ?? "");
|
|
321
|
+
if (!raw || raw.length > PAIR_LIMITS.header) throw new Error("missing");
|
|
322
|
+
body = JSON.parse(new TextDecoder().decode(fromBase64url(raw)));
|
|
323
|
+
} catch {
|
|
324
|
+
return answer(res, 400, { error: "send x-mallory-pair: base64url JSON { jwk, proof, nonce, label }" }, { headers: cors });
|
|
325
|
+
}
|
|
326
|
+
const { jwk, proof, nonce, label = "" } = body ?? {};
|
|
327
|
+
const bad = publicJwkProblem(jwk) || nonceProblem(nonce) || (typeof proof === "string" && /^[0-9a-f]{64}$/.test(proof) ? "" : "the proof is 64 hex digits") || (typeof label === "string" && label.length <= PAIR_LIMITS.label && !/[\u0000-\u001f\u007f]/.test(label) ? "" : `a label is text, at most ${PAIR_LIMITS.label} characters`);
|
|
328
|
+
if (bad) return answer(res, 400, { error: bad }, { headers: cors });
|
|
329
|
+
const thumbprint = await jwkThumbprint({ kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y });
|
|
330
|
+
const expected = createHmac("sha256", pairing.code).update(pairMessage({ fingerprint: identity.fingerprint, thumbprint, nonce })).digest();
|
|
331
|
+
const given = Buffer.from(proof, "hex");
|
|
332
|
+
if (given.length !== expected.length || !timingSafeEqual(given, expected)) {
|
|
333
|
+
codeThrottle.fail(); // ten lock pairing for everyone until a new code is made at the terminal
|
|
334
|
+
// The code, the fingerprint the page was given, or its key in the request: one of them isn't what the runner has.
|
|
335
|
+
return answer(res, 403, { error: "the pairing didn't check out: the code, or the fingerprint typed into the page, isn't this runner's (or someone changed the request)" }, { headers: cors });
|
|
336
|
+
}
|
|
337
|
+
const id = pageIdOf(thumbprint);
|
|
338
|
+
try {
|
|
339
|
+
await pages.add({ id, label: label.trim() || "a page", jwk: { kty: "EC", crv: "P-256", x: jwk.x, y: jwk.y }, created: new Date(now()).toISOString() });
|
|
340
|
+
} catch (error) {
|
|
341
|
+
return answer(res, error.status ?? 500, { error: error.status ? error.message : "the pairing couldn't be saved" }, { headers: cors });
|
|
342
|
+
}
|
|
343
|
+
pairing = null; // single use
|
|
344
|
+
stdout(`mallory serve: paired a page "${label.trim() || "a page"}" (${id}); it can read the monitor's runs. Revoke it with: revoke ${id}`);
|
|
345
|
+
return answer(res, 200, { protocol: PAIR_PROTOCOL, version: PAIR_VERSION, page: { id }, runner: { fingerprint: identity.fingerprint, kind: identity.kind }, cert: toBase64url(identity.der), nonce, time: now() }, { nonce, headers: cors });
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Check a signed request: `{ ok: true, page, nonce }` or `{ ok: false, status, error }`. */
|
|
349
|
+
async function authenticate(req, path) {
|
|
350
|
+
const client = clientOf(req);
|
|
351
|
+
const h = req.headers;
|
|
352
|
+
const page = String(h["x-mallory-key"] ?? "");
|
|
353
|
+
const time = String(h["x-mallory-time"] ?? "");
|
|
354
|
+
const nonce = String(h["x-mallory-nonce"] ?? "");
|
|
355
|
+
const signature = String(h["x-mallory-signature"] ?? "");
|
|
356
|
+
const fail = (error) => (wrong.add(client), wrongAll.add("*"), { ok: false, status: 401, error });
|
|
357
|
+
if (!/^[A-Za-z0-9_-]{16}$/.test(page) || !/^\d{1,16}$/.test(time) || nonceProblem(nonce) || !/^[A-Za-z0-9_-]{40,700}$/.test(signature)) return fail("unauthorized: sign the request (pair this page first)");
|
|
358
|
+
if (Math.abs(Number(time) - now()) > TIME_WINDOW_MS) return fail("unauthorized: the request's time is too far from the runner's clock");
|
|
359
|
+
const known = await pages.find(page);
|
|
360
|
+
if (!known) return fail("unauthorized: this page isn't paired with the runner (or it was revoked)");
|
|
361
|
+
let key;
|
|
362
|
+
try {
|
|
363
|
+
key = createPublicKey({ key: known.jwk, format: "jwk" });
|
|
364
|
+
} catch {
|
|
365
|
+
return fail("unauthorized");
|
|
366
|
+
}
|
|
367
|
+
const message = requestMessage({ method: req.method, path, time, nonce, fingerprint: identity.fingerprint, page });
|
|
368
|
+
let ok = false;
|
|
369
|
+
try {
|
|
370
|
+
ok = cryptoVerify("sha256", Buffer.from(message), { key, dsaEncoding: "ieee-p1363" }, Buffer.from(fromBase64url(signature)));
|
|
371
|
+
} catch {
|
|
372
|
+
ok = false;
|
|
373
|
+
}
|
|
374
|
+
if (!ok) return fail("unauthorized: the signature doesn't check out");
|
|
375
|
+
const fresh = remember(nonce);
|
|
376
|
+
if (fresh === "replay") return fail("unauthorized: that request was already answered");
|
|
377
|
+
if (fresh === "full") return { ok: false, status: 429, error: "too many requests: wait and ask again", retryAfter: 60 };
|
|
378
|
+
lastSeen.set(page, now());
|
|
379
|
+
return { ok: true, page, nonce };
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function handle(req, res, { canvases }) {
|
|
383
|
+
const client = clientOf(req);
|
|
384
|
+
const url = new URL(req.url ?? "/", "https://runner.invalid");
|
|
385
|
+
const path = url.pathname;
|
|
386
|
+
const pathWithQuery = `${path}${url.search}`;
|
|
387
|
+
// DNS rebinding and stray names: the Host header must name this runner as the person set it up.
|
|
388
|
+
const host = hostOf(req.headers.host);
|
|
389
|
+
if (!host || !hosts.has(host.host) || (host.port !== undefined && host.port !== listenPort)) return answer(res, 403, { error: "unexpected Host header (start the runner with --remote-name <the name the page uses>)" });
|
|
390
|
+
if (/%2e|%2f|%5c|\\|\/\/|\/\.\.?(\/|$)/i.test(path)) return answer(res, 400, { error: "malformed path" });
|
|
391
|
+
// The one page that may ask (--monitor-origin); a request with no Origin is a tool's (it still has to sign).
|
|
392
|
+
const verdict = checkOrigin(req.headers, origin);
|
|
393
|
+
if (!verdict.ok) return answer(res, 403, { error: "that web page's origin isn't the one this runner allows (--monitor-origin)" });
|
|
394
|
+
const cors = req.headers.origin === undefined ? {} : { "access-control-allow-origin": origin, vary: "Origin", "access-control-expose-headers": "x-mallory-time, x-mallory-signature" };
|
|
395
|
+
const known = path === PAIR_PATH || path === `${MONITOR_PREFIX}/status` || path === `${MONITOR_PREFIX}/runs`;
|
|
396
|
+
if (req.method === "OPTIONS") {
|
|
397
|
+
if (req.headers.origin === undefined || !known) return answer(res, 404, { error: "not found" });
|
|
398
|
+
const pna = req.headers["access-control-request-private-network"] === "true" ? { "access-control-allow-private-network": "true" } : {};
|
|
399
|
+
res.writeHead(204, { ...cors, ...pna, "access-control-allow-methods": "GET, POST, DELETE", "access-control-allow-headers": "x-mallory-pair, x-mallory-key, x-mallory-time, x-mallory-nonce, x-mallory-signature", "access-control-max-age": "600", "cache-control": "no-store" });
|
|
400
|
+
res.end();
|
|
401
|
+
return 204;
|
|
402
|
+
}
|
|
403
|
+
const hit = rate.hit(client);
|
|
404
|
+
const hitAll = hit.ok ? rateAll.hit("*") : hit;
|
|
405
|
+
if (!hit.ok || !hitAll.ok) return answer(res, 429, { error: "too many requests: wait and ask again" }, { headers: { ...cors, "retry-after": String((hit.ok ? hitAll : hit).retryAfter) } });
|
|
406
|
+
if (wrong.blocked(client) || wrongAll.blocked("*")) return answer(res, 429, { error: "too many refused requests: wait a minute" }, { headers: { ...cors, "retry-after": String(wrong.blocked(client) ? wrong.retryAfter(client) : wrongAll.retryAfter("*")) } });
|
|
407
|
+
if (!known) return answer(res, 404, { error: "not found" }, { headers: cors });
|
|
408
|
+
if (path === PAIR_PATH && req.method === "POST") return pair(req, res, cors);
|
|
409
|
+
if (path === PAIR_PATH && req.method !== "DELETE") return answer(res, 405, { error: "method not allowed" }, { headers: { ...cors, allow: "POST, DELETE, OPTIONS" } });
|
|
410
|
+
if (path !== PAIR_PATH && req.method !== "GET") return answer(res, 405, { error: "method not allowed" }, { headers: { ...cors, allow: "GET, OPTIONS" } });
|
|
411
|
+
const auth = await authenticate(req, pathWithQuery);
|
|
412
|
+
if (!auth.ok) return answer(res, auth.status, { error: auth.error }, { headers: { ...cors, ...(auth.retryAfter ? { "retry-after": String(auth.retryAfter) } : {}) } });
|
|
413
|
+
if (path === PAIR_PATH) {
|
|
414
|
+
// A page revoking itself.
|
|
415
|
+
await pages.revoke(auth.page);
|
|
416
|
+
stdout(`mallory serve: the page ${auth.page} unpaired itself`);
|
|
417
|
+
return answer(res, 200, { revoked: auth.page }, { nonce: auth.nonce, headers: cors });
|
|
418
|
+
}
|
|
419
|
+
// The monitor's read-only routes, answered as the loopback monitor would (no stream: a page polls).
|
|
420
|
+
let status = 500;
|
|
421
|
+
let body = { error: "error" };
|
|
422
|
+
monitor.handle({ method: "GET", url: pathWithQuery, headers: {}, socket: { remoteAddress: client } }, (s, b) => ((status = s), (body = b)), { canvases }, { authorized: true });
|
|
423
|
+
if (status === 200 && path.endsWith("/status")) body = { ...body, feeds: body.feeds.filter((f) => f !== "stream"), remote: true };
|
|
424
|
+
return answer(res, status, body, { nonce: auth.nonce, headers: cors });
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
handle,
|
|
429
|
+
newCode,
|
|
430
|
+
setPort: (p) => (listenPort = p),
|
|
431
|
+
/** The pairing code now, or undefined (used or expired). */
|
|
432
|
+
code: () => (pairing && now() <= pairing.expires ? formatPairCode(pairing.code) : undefined),
|
|
433
|
+
secrets: () => (pairing ? [pairing.code, formatPairCode(pairing.code)] : []),
|
|
434
|
+
lastSeen: (id) => lastSeen.get(id),
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Start the TLS listener (`listen`: { host, port }). Resolves `{ url, port, close() }`. Its handler is `remote.handle`
|
|
440
|
+
* with the server's canvases now.
|
|
441
|
+
*/
|
|
442
|
+
export async function startRemoteListener({ identity, remote, listen, canvases, stderr = () => {} }) {
|
|
443
|
+
const server = createHttpsServer({ cert: identity.certPem, key: identity.keyPem, minVersion: "TLSv1.2" }, (req, res) => {
|
|
444
|
+
remote.handle(req, res, { canvases: canvases() }).catch((error) => {
|
|
445
|
+
stderr(`mallory serve: remote listener: ${error.message}`);
|
|
446
|
+
if (!res.headersSent) (res.writeHead(500, { "content-type": "application/json" }), res.end('{"error":"error"}'));
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
server.requestTimeout = 15000;
|
|
450
|
+
server.headersTimeout = 10000;
|
|
451
|
+
server.keepAliveTimeout = 5000;
|
|
452
|
+
server.maxHeadersCount = 50;
|
|
453
|
+
await new Promise((resolveListen, reject) => {
|
|
454
|
+
server.once("error", reject);
|
|
455
|
+
server.listen(listen.port, listen.host, () => (server.off("error", reject), resolveListen()));
|
|
456
|
+
});
|
|
457
|
+
const actual = server.address().port;
|
|
458
|
+
const shown = listen.host.includes(":") ? `[${listen.host}]` : listen.host;
|
|
459
|
+
return {
|
|
460
|
+
url: `https://${shown}:${actual}`,
|
|
461
|
+
port: actual,
|
|
462
|
+
close: () =>
|
|
463
|
+
new Promise((done) => {
|
|
464
|
+
server.close(() => done());
|
|
465
|
+
server.closeIdleConnections?.();
|
|
466
|
+
setTimeout(() => server.closeAllConnections?.(), 2000).unref();
|
|
467
|
+
}),
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** `host:port` as --remote-listen takes it: `0.0.0.0:8790`, `[::]:8790`, `192.168.1.20:8790`, `100.64.0.5:8790`. */
|
|
472
|
+
export function parseListen(value) {
|
|
473
|
+
const m = /^(\[[0-9a-fA-F:.]+\]|[0-9.]+|[a-zA-Z0-9.-]+):(\d{1,5})$/.exec(String(value ?? ""));
|
|
474
|
+
const port = m ? Number(m[2]) : NaN;
|
|
475
|
+
if (!m || !(port >= 0 && port <= 65535)) return undefined;
|
|
476
|
+
return { host: m[1].replace(/^\[|\]$/g, ""), port };
|
|
477
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// The child process that holds one pane Worker (#1050). A worker thread's resourceLimits cannot stop ONE huge allocation (`Array.from({ length: 3e8 })`,
|
|
2
|
+
// `new Array(2e9).fill()`): V8 raises a fatal "heap out of memory" that aborts the whole process, runner included. So the Worker thread runs in its
|
|
3
|
+
// own process, and the runner talks to it over IPC (src/headless/process-worker.js). If the child dies, only that pane's run ends.
|
|
4
|
+
import { createNodeWorkerFactory } from "@johnhenry/andbox";
|
|
5
|
+
|
|
6
|
+
// The thread gets an empty environment: MALLORY_SECRET_* and the rest of the runner's environment stay out of reach of canvas code.
|
|
7
|
+
const make = await createNodeWorkerFactory({ env: {}, maxMemoryMb: 1024 });
|
|
8
|
+
let worker = null;
|
|
9
|
+
process.on("message", (m) => {
|
|
10
|
+
if (m.t === "start") {
|
|
11
|
+
worker = make(m.source);
|
|
12
|
+
worker.onmessage = (e) => process.send({ t: "msg", data: e.data });
|
|
13
|
+
worker.onerror = (e) => process.send({ t: "err", message: e?.message ?? String(e) });
|
|
14
|
+
} else if (m.t === "post") worker?.postMessage(m.data);
|
|
15
|
+
else if (m.t === "stop") {
|
|
16
|
+
try { worker?.terminate(); } catch {}
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
process.on("disconnect", () => process.exit(0)); // the runner is gone: so is the pane
|
|
21
|
+
process.send({ t: "ready" });
|