@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,665 @@
|
|
|
1
|
+
// The traffic pane's engine (src/panes/traffic.js; docs/design/traffic.md, prism parity wave P-A): requests and responses from a tap value, a raw
|
|
2
|
+
// webhook capture, a HAR or request text, read into ONE entry shape; the filters, summary, diff, copy-as and bulk export built on it.
|
|
3
|
+
//
|
|
4
|
+
// Every entry passes `redactEntry` before it leaves normalizeTraffic, and every export and copy passes it again: the URL, the header values and
|
|
5
|
+
// the bodies go through the shared policy (src/security/redact.js) and nothing else decides what is a credential. So the pane's value (which
|
|
6
|
+
// an agent reads), what the body shows, and what is exported or copied all hold the same redacted text.
|
|
7
|
+
//
|
|
8
|
+
// Pure: no DOM, no network, no storage, no timers. Captured entries live only in memory (the pane's value and a page-side store); they are never
|
|
9
|
+
// part of a canvas document.
|
|
10
|
+
import { REDACTED, redactBody, redactHeaderValue, redactUrl } from "../security/redact.js";
|
|
11
|
+
import { readRequests, formatsOf, textFor, diffRequests, diffText, lineDiffBounded, compactLines } from "./http-tools.js";
|
|
12
|
+
import { PHASES, TIMING_SOURCES, fromHarTimings, toHarTimings, timingDiff, waterfall } from "./timing.js";
|
|
13
|
+
import { redactFrames } from "./ws-frames.js";
|
|
14
|
+
import { compileSafeRegex, slashRegex, SAFE_REGEX_PASS_STEPS } from "./safe-regex.js";
|
|
15
|
+
|
|
16
|
+
export const TRAFFIC_LIMITS = Object.freeze({ entries: [1, 500] });
|
|
17
|
+
export const TRAFFIC_DEFAULTS = Object.freeze({ max: 200 });
|
|
18
|
+
/**
|
|
19
|
+
* The most text one body keeps (after redaction), and the most all bodies of a pane's entries keep together. A body the page's own tap kept
|
|
20
|
+
* (a person set the cap on the http pane, up to 1 MiB, CAP-04) is shown up to MAX_TAP_BODY_CHARS; a body from any other source (a HAR, a raw capture,
|
|
21
|
+
* pasted text) is cut at MAX_BODY_CHARS. The total holds whatever the sources.
|
|
22
|
+
*/
|
|
23
|
+
export const MAX_BODY_CHARS = 16384;
|
|
24
|
+
export const MAX_TAP_BODY_CHARS = 1048576;
|
|
25
|
+
export const MAX_TOTAL_BODY_CHARS = 8388608;
|
|
26
|
+
export const FORMS = ["curl", "fetch", "raw", "har"];
|
|
27
|
+
/** The status classes the summary counts and the status filter understands, besides a three-digit code. */
|
|
28
|
+
export const CLASSES = ["1xx", "2xx", "3xx", "4xx", "5xx", "refused", "failed", "none"];
|
|
29
|
+
|
|
30
|
+
const TEXTY = /^(text\/|application\/(json|xml|javascript|ecmascript|x-www-form-urlencoded|x-ndjson|graphql)|[^;]*\+(json|xml))/i;
|
|
31
|
+
const URLISH_HEADERS = new Set(["location", "content-location", "link", "referer"]);
|
|
32
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
33
|
+
const short = (v, n = 200) => String(v ?? "").slice(0, n);
|
|
34
|
+
const num = (v) => (Number.isFinite(Number(v)) && v !== null && v !== "" && v !== undefined ? Number(v) : undefined);
|
|
35
|
+
const iso = (v) => {
|
|
36
|
+
if (v === undefined || v === null || v === "") return null;
|
|
37
|
+
const d = new Date(typeof v === "number" ? v : String(v));
|
|
38
|
+
return Number.isNaN(d.getTime()) ? null : d.toISOString();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// ── settings ─────────────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
/** The settings as they are used: unknown keys dropped, a number out of range falls back. */
|
|
44
|
+
export function cleanTraffic(raw) {
|
|
45
|
+
const r = isObject(raw) ? raw : {};
|
|
46
|
+
const [low, high] = TRAFFIC_LIMITS.entries;
|
|
47
|
+
// `reveal`: the person's "show credentials" switch (SRV-04). Only `true` is kept, so the default is off; it is person-only (src/panes/traffic.js).
|
|
48
|
+
return { max: Number.isInteger(r.max) && r.max >= low && r.max <= high ? r.max : TRAFFIC_DEFAULTS.max, ...(r.source === "history" ? { source: "history" } : r.source === "served" ? { source: "served" } : {}), ...(r.reveal === true ? { reveal: true } : {}) };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** What is wrong with these settings, or "". */
|
|
52
|
+
export function trafficProblem(raw) {
|
|
53
|
+
if (raw === undefined || raw === null) return "";
|
|
54
|
+
if (!isObject(raw)) return "traffic must be an object";
|
|
55
|
+
const [low, high] = TRAFFIC_LIMITS.entries;
|
|
56
|
+
for (const key of Object.keys(raw)) if (key !== "max" && key !== "source" && key !== "reveal") return `traffic has no setting "${key}"`;
|
|
57
|
+
if (raw.source !== undefined && raw.source !== "wire" && raw.source !== "history" && raw.source !== "served") return 'source must be "wire", "history" or "served"';
|
|
58
|
+
if (raw.reveal !== undefined && typeof raw.reveal !== "boolean") return "reveal must be true or false";
|
|
59
|
+
if (raw.max !== undefined && !(Number.isInteger(raw.max) && raw.max >= low && raw.max <= high)) return `max must be a whole number from ${low} to ${high}`;
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── show credentials (SRV-04) ────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
/** The tap's id of a tap entry (`tap-12` is 12), or undefined: only this canvas's own requests, seen by the policy, can have a revealed view. */
|
|
66
|
+
export function tapIdOf(entry) {
|
|
67
|
+
const m = entry?.source === "tap" && !entry.reported && !entry.via ? /^tap-(\d{1,12})$/.exec(String(entry.id)) : null; // (nothing writes `reported` now, #1017: a stray one still never gets the credentials tab)
|
|
68
|
+
return m ? Number(m[1]) : undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Whether a tap's revealed record belongs to this entry: the same method, time and redacted URL (a look-alike entry that borrows a tap id fails). */
|
|
72
|
+
export function revealMatches(entry, real) {
|
|
73
|
+
return !!real && !!entry && real.method === entry.method && typeof entry.at === "string" && new Date(real.at).toISOString() === entry.at && real.redactedUrl === entry.url;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ── redaction ────────────────────────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
function redactHeaderObject(list, redacted) {
|
|
79
|
+
// Pairs ([name, value]), objects ({ name, value }, a HAR's and fetch's list form) or a plain object; anything else is ignored.
|
|
80
|
+
const pairs = (Array.isArray(list) ? list : Object.entries(list && typeof list === "object" ? list : {})).map((h) => (Array.isArray(h) ? h : h && typeof h === "object" ? [h.name, h.value] : null)).filter(Boolean);
|
|
81
|
+
const out = {};
|
|
82
|
+
for (const [name, raw] of pairs) {
|
|
83
|
+
const key = String(name).toLowerCase();
|
|
84
|
+
if (!key || key.startsWith(":")) continue;
|
|
85
|
+
const text = Array.isArray(raw) ? raw.join(", ") : String(raw ?? "");
|
|
86
|
+
let shown = redactHeaderValue(key, text);
|
|
87
|
+
if (shown !== text) redacted.add(key);
|
|
88
|
+
if (shown !== REDACTED && URLISH_HEADERS.has(key)) {
|
|
89
|
+
const u = redactUrl(shown);
|
|
90
|
+
if (u.redacted.length) u.redacted.forEach((n) => redacted.add(n));
|
|
91
|
+
shown = u.url;
|
|
92
|
+
}
|
|
93
|
+
out[key] = key in out && shown !== REDACTED ? `${out[key]}, ${shown}` : shown;
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function redactBodyView(body, type, budget, limit = MAX_BODY_CHARS) {
|
|
99
|
+
if (!isObject(body)) return undefined;
|
|
100
|
+
const bytes = Number.isFinite(body.bytes) ? body.bytes : typeof body.text === "string" ? new TextEncoder().encode(body.text).byteLength : 0;
|
|
101
|
+
if (typeof body.text !== "string") return { bytes, truncated: body.truncated === true, ...(body.binary ? { binary: true } : {}) };
|
|
102
|
+
// The type the entry's headers give, and the one the source gave the body itself (a HAR's postData.mimeType, which may be the only one): the text is
|
|
103
|
+
// redacted by each, so a body whose type is only on the body is not left as it came.
|
|
104
|
+
let text = redactBody(body.text, type);
|
|
105
|
+
if (typeof body.type === "string" && body.type !== type) text = redactBody(text, body.type.slice(0, 256));
|
|
106
|
+
let truncated = body.truncated === true;
|
|
107
|
+
const room = Math.max(0, Math.min(limit, budget ? budget.left : limit));
|
|
108
|
+
if (text.length > room) {
|
|
109
|
+
text = text.slice(0, room);
|
|
110
|
+
truncated = true;
|
|
111
|
+
}
|
|
112
|
+
if (budget) budget.left -= text.length;
|
|
113
|
+
return { text, bytes, truncated };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const URL_PARTS = /^([a-z][a-z0-9+.-]*):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i;
|
|
117
|
+
|
|
118
|
+
/** An entry with every string a person sees or an export writes taken through the shared policy. Idempotent. `budget` ({ left }) limits all bodies together. */
|
|
119
|
+
export function redactEntry(entry, budget) {
|
|
120
|
+
const redacted = new Set(Array.isArray(entry.redacted) ? entry.redacted : []);
|
|
121
|
+
const u = redactUrl(String(entry.url ?? ""));
|
|
122
|
+
u.redacted.forEach((n) => redacted.add(n));
|
|
123
|
+
const parts = URL_PARTS.exec(u.url);
|
|
124
|
+
const authority = parts?.[2] ?? "";
|
|
125
|
+
const host = parts ? authority.slice(authority.lastIndexOf("@") + 1) : String(entry.host ?? "");
|
|
126
|
+
const path = parts ? parts[3] || "/" : u.url.split(/[?#]/)[0] || "/";
|
|
127
|
+
const query = parts ? (parts[4] ?? "") : (/\?[^#]*/.exec(u.url)?.[0] ?? "");
|
|
128
|
+
const requestHeaders = redactHeaderObject(entry.requestHeaders, redacted);
|
|
129
|
+
const responseHeaders = redactHeaderObject(entry.responseHeaders, redacted);
|
|
130
|
+
const out = {
|
|
131
|
+
id: String(entry.id),
|
|
132
|
+
source: entry.source,
|
|
133
|
+
at: entry.at ?? null,
|
|
134
|
+
method: String(entry.method ?? "GET").toUpperCase().slice(0, 12),
|
|
135
|
+
url: u.url,
|
|
136
|
+
host,
|
|
137
|
+
path,
|
|
138
|
+
query,
|
|
139
|
+
status: Number.isInteger(entry.status) && entry.status > 0 ? entry.status : 0,
|
|
140
|
+
statusText: short(entry.statusText),
|
|
141
|
+
result: entry.result,
|
|
142
|
+
allowed: entry.allowed === true, // (missing or not a boolean reads as refused: never a default of allowed)
|
|
143
|
+
...(entry.reason ? { reason: short(entry.reason) } : {}),
|
|
144
|
+
ms: Number.isFinite(entry.ms) ? entry.ms : null,
|
|
145
|
+
...(entry.pane ? { pane: short(entry.pane) } : {}),
|
|
146
|
+
requestHeaders,
|
|
147
|
+
responseHeaders,
|
|
148
|
+
requestBytes: Number.isFinite(entry.requestBytes) ? entry.requestBytes : 0,
|
|
149
|
+
responseBytes: Number.isFinite(entry.responseBytes) ? entry.responseBytes : 0,
|
|
150
|
+
};
|
|
151
|
+
// Only an entry that is shaped as the tap's own (source "tap", an id `tap-N`, not relayed) gets the larger cut, the same test the
|
|
152
|
+
// credentials tab uses (tapIdOf). Nothing here can prove a pane did not forge that shape; a forged entry is still held to the pane's total.
|
|
153
|
+
const limit = tapIdOf(entry) !== undefined ? MAX_TAP_BODY_CHARS : MAX_BODY_CHARS;
|
|
154
|
+
const rq = redactBodyView(entry.requestBody, requestHeaders["content-type"] ?? "", budget, limit);
|
|
155
|
+
const rs = redactBodyView(entry.responseBody, responseHeaders["content-type"] ?? "", budget, limit);
|
|
156
|
+
if (rq) out.requestBody = rq;
|
|
157
|
+
if (rs) out.responseBody = rs;
|
|
158
|
+
if (isObject(entry.timings)) {
|
|
159
|
+
const t = {};
|
|
160
|
+
for (const k of PHASES) if (Number.isFinite(entry.timings[k]) && entry.timings[k] >= 0) t[k] = entry.timings[k];
|
|
161
|
+
if (Object.keys(t).length) out.timings = t;
|
|
162
|
+
}
|
|
163
|
+
// Where the phases came from, and why a breakdown is missing: a name from a fixed list and a sentence our own code wrote (never the wire's).
|
|
164
|
+
if (TIMING_SOURCES.includes(entry.timingSource)) out.timingSource = entry.timingSource;
|
|
165
|
+
if (typeof entry.timingNote === "string" && entry.timingNote) out.timingNote = short(entry.timingNote).slice(0, 240);
|
|
166
|
+
if (entry.via === "companion") out.via = "companion";
|
|
167
|
+
if (typeof entry.initiator === "string" && ["fetch", "xmlhttprequest", "beacon", "other"].includes(entry.initiator)) out.initiator = entry.initiator;
|
|
168
|
+
// A WebSocket's frames (wave P-F, src/model/ws-frames.js): logged frames only, redacted again here; the close and the subprotocols are short plain facts.
|
|
169
|
+
const frames = redactFrames(entry.frames, budget);
|
|
170
|
+
if (frames) {
|
|
171
|
+
out.frames = frames;
|
|
172
|
+
out.framesTotal = Number.isInteger(entry.framesTotal) && entry.framesTotal >= frames.length ? entry.framesTotal : frames.length;
|
|
173
|
+
if (Number.isInteger(entry.closeCode)) out.closeCode = entry.closeCode;
|
|
174
|
+
if (typeof entry.closeReason === "string" && entry.closeReason) out.closeReason = redactFrames([{ dir: "in", text: entry.closeReason, bytes: 0 }])[0].text.slice(0, 120);
|
|
175
|
+
if (Array.isArray(entry.protocols)) out.protocols = entry.protocols.map((p) => short(p, 64)).slice(0, 4);
|
|
176
|
+
}
|
|
177
|
+
if (redacted.size) out.redacted = [...redacted];
|
|
178
|
+
return out;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── reading each source ──────────────────────────────────────────────────────
|
|
182
|
+
|
|
183
|
+
const headerList = (list) => (Array.isArray(list) ? list.filter((h) => h && h.name !== undefined).map((h) => [h.name, h.value]) : []);
|
|
184
|
+
|
|
185
|
+
function bodyOf(bytes, type) {
|
|
186
|
+
if (!bytes || !bytes.byteLength) return undefined;
|
|
187
|
+
if (type && !TEXTY.test(type)) return { bytes: bytes.byteLength, truncated: false, binary: true };
|
|
188
|
+
return { text: new TextDecoder("utf-8").decode(bytes.byteLength > MAX_BODY_CHARS * 4 ? bytes.subarray(0, MAX_BODY_CHARS * 4) : bytes), bytes: bytes.byteLength, truncated: false };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const fromBase64 = (text) => {
|
|
192
|
+
try {
|
|
193
|
+
const bin = atob(String(text));
|
|
194
|
+
return Uint8Array.from(bin, (c) => c.charCodeAt(0));
|
|
195
|
+
} catch {
|
|
196
|
+
return new Uint8Array();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
function fromTap(e) {
|
|
201
|
+
return {
|
|
202
|
+
source: "tap",
|
|
203
|
+
at: iso(e.at),
|
|
204
|
+
method: e.method,
|
|
205
|
+
url: e.url,
|
|
206
|
+
status: e.status,
|
|
207
|
+
statusText: e.statusText,
|
|
208
|
+
result: e.result === "pending" ? "request" : e.result,
|
|
209
|
+
allowed: e.allowed,
|
|
210
|
+
reason: e.reason,
|
|
211
|
+
ms: e.ms,
|
|
212
|
+
pane: e.paneName ?? e.pane,
|
|
213
|
+
requestHeaders: e.requestHeaders,
|
|
214
|
+
responseHeaders: e.responseHeaders,
|
|
215
|
+
requestBytes: e.requestBytes,
|
|
216
|
+
responseBytes: e.responseBytes,
|
|
217
|
+
requestBody: e.requestBody,
|
|
218
|
+
responseBody: e.responseBody,
|
|
219
|
+
redacted: e.redacted,
|
|
220
|
+
tapId: e.id,
|
|
221
|
+
timings: e.timings,
|
|
222
|
+
timingSource: e.timingSource,
|
|
223
|
+
timingNote: e.timingNote,
|
|
224
|
+
via: e.via,
|
|
225
|
+
initiator: e.initiator,
|
|
226
|
+
frames: e.frames,
|
|
227
|
+
framesTotal: e.framesTotal,
|
|
228
|
+
closeCode: e.closeCode,
|
|
229
|
+
closeReason: e.closeReason,
|
|
230
|
+
protocols: e.protocols,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function fromRaw(v) {
|
|
235
|
+
const headers = Array.isArray(v.headers) ? v.headers : [];
|
|
236
|
+
const lower = Object.fromEntries(headers.map(([n, val]) => [String(n).toLowerCase(), val]));
|
|
237
|
+
const host = String(lower.host ?? "localhost");
|
|
238
|
+
const path = `/${String(v.path ?? "").replace(/^\/+/, "")}`;
|
|
239
|
+
const search = v.search ? (String(v.search).startsWith("?") ? String(v.search) : `?${v.search}`) : "";
|
|
240
|
+
const bytes = v.encoding === "base64" ? fromBase64(v.body) : typeof v.body === "string" ? new TextEncoder().encode(v.body) : undefined;
|
|
241
|
+
return {
|
|
242
|
+
source: "raw",
|
|
243
|
+
at: iso(v.receivedAt),
|
|
244
|
+
method: v.method,
|
|
245
|
+
url: `http://${host}${path}${search}`,
|
|
246
|
+
result: "captured",
|
|
247
|
+
allowed: true,
|
|
248
|
+
requestHeaders: headers,
|
|
249
|
+
requestBytes: Number.isFinite(v.size) ? v.size : (bytes?.byteLength ?? 0),
|
|
250
|
+
requestBody: bodyOf(bytes, String(lower["content-type"] ?? "")),
|
|
251
|
+
redacted: Array.isArray(v.redacted) ? v.redacted : undefined,
|
|
252
|
+
rawId: v.id,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function fromHar(e) {
|
|
257
|
+
const rq = e.request ?? {};
|
|
258
|
+
const rs = e.response ?? {};
|
|
259
|
+
const rh = headerList(rq.headers);
|
|
260
|
+
const sh = headerList(rs.headers);
|
|
261
|
+
const rtype = String((rq.postData ?? {}).mimeType ?? rh.find(([n]) => String(n).toLowerCase() === "content-type")?.[1] ?? "");
|
|
262
|
+
const content = isObject(rs.content) ? rs.content : {};
|
|
263
|
+
const stype = String(content.mimeType ?? sh.find(([n]) => String(n).toLowerCase() === "content-type")?.[1] ?? "");
|
|
264
|
+
let responseBody;
|
|
265
|
+
if (typeof content.text === "string") {
|
|
266
|
+
const bytes = content.encoding === "base64" ? fromBase64(content.text) : new TextEncoder().encode(content.text);
|
|
267
|
+
responseBody = !stype || TEXTY.test(stype) ? { text: content.encoding === "base64" ? new TextDecoder().decode(bytes) : content.text, bytes: Number.isFinite(content.size) && content.size > 0 ? content.size : bytes.byteLength, truncated: false, ...(stype ? { type: stype } : {}) } : { bytes: bytes.byteLength, truncated: false, binary: true };
|
|
268
|
+
}
|
|
269
|
+
const post = typeof rq.postData?.text === "string" ? rq.postData.text : undefined;
|
|
270
|
+
const harTimings = fromHarTimings(e.timings);
|
|
271
|
+
const status = num(rs.status) ?? 0;
|
|
272
|
+
return {
|
|
273
|
+
source: "har",
|
|
274
|
+
at: iso(e.startedDateTime),
|
|
275
|
+
method: Array.isArray(e._webSocketMessages) ? "WS" : rq.method,
|
|
276
|
+
url: rq.url,
|
|
277
|
+
status,
|
|
278
|
+
statusText: rs.statusText,
|
|
279
|
+
result: status > 0 ? "response" : "failed",
|
|
280
|
+
allowed: true,
|
|
281
|
+
reason: status > 0 ? undefined : (rs._error ?? "no response"),
|
|
282
|
+
ms: Number.isFinite(e.time) && e.time >= 0 ? Math.round(e.time) : undefined,
|
|
283
|
+
pane: e._pane || undefined,
|
|
284
|
+
requestHeaders: rh,
|
|
285
|
+
responseHeaders: sh,
|
|
286
|
+
requestBytes: Number.isFinite(rq.bodySize) && rq.bodySize > 0 ? rq.bodySize : post ? new TextEncoder().encode(post).byteLength : 0,
|
|
287
|
+
responseBytes: Number.isFinite(content.size) && content.size > 0 ? content.size : Number.isFinite(rs.bodySize) && rs.bodySize > 0 ? rs.bodySize : 0,
|
|
288
|
+
requestBody: post !== undefined ? { text: post, bytes: new TextEncoder().encode(post).byteLength, truncated: false, ...(rtype ? { type: rtype } : {}) } : undefined,
|
|
289
|
+
responseBody,
|
|
290
|
+
timings: harTimings,
|
|
291
|
+
timingSource: Object.keys(harTimings).length ? "har" : undefined, // phasesOf calls a lone total "wall-clock"
|
|
292
|
+
via: e._via === "companion" ? "companion" : undefined,
|
|
293
|
+
...(Array.isArray(e._webSocketMessages) ? harFrames(e) : {}),
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** A socket's messages from a HAR entry as frames (Chrome: type send | receive, time in seconds, opcode 1 text or 2 binary, data). */
|
|
298
|
+
function harFrames(e) {
|
|
299
|
+
const frames = e._webSocketMessages.filter(isObject).map((m, i) => {
|
|
300
|
+
const binary = m.opcode === 2;
|
|
301
|
+
const data = typeof m.data === "string" ? m.data : "";
|
|
302
|
+
return { n: i + 1, dir: m.type === "send" ? "out" : "in", at: Number.isFinite(m.time) ? m.time * 1000 : null, bytes: binary && Number.isFinite(m.length) ? m.length : new TextEncoder().encode(data).byteLength, binary, ...(binary ? {} : { text: data }) };
|
|
303
|
+
});
|
|
304
|
+
const sum = (dir) => frames.filter((f) => f.dir === dir).reduce((n, f) => n + f.bytes, 0);
|
|
305
|
+
return { frames, framesTotal: frames.length, requestBytes: sum("out"), responseBytes: sum("in") };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function fromRequest(r) {
|
|
309
|
+
const type = String(r.headers?.["content-type"] ?? "");
|
|
310
|
+
return {
|
|
311
|
+
source: "request",
|
|
312
|
+
at: null,
|
|
313
|
+
method: r.method,
|
|
314
|
+
url: r.url,
|
|
315
|
+
result: "request",
|
|
316
|
+
allowed: true,
|
|
317
|
+
requestHeaders: r.headers,
|
|
318
|
+
requestBytes: r.body ? new TextEncoder().encode(r.body).byteLength : 0,
|
|
319
|
+
requestBody: r.body !== undefined ? { text: r.body, bytes: new TextEncoder().encode(r.body).byteLength, truncated: false } : undefined,
|
|
320
|
+
_type: type,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const isTapEntry = (e) => isObject(e) && typeof e.method === "string" && typeof e.url === "string" && typeof e.allowed === "boolean" && "result" in e;
|
|
325
|
+
const isRaw = (e) => isObject(e) && typeof e.method === "string" && typeof e.path === "string" && Array.isArray(e.headers);
|
|
326
|
+
/** A HAR entry's URL is http(s), or ws(s) when it carries a socket's messages (`_webSocketMessages`, as Chrome writes them). */
|
|
327
|
+
const harUrlOk = (e) => (Array.isArray(e._webSocketMessages) ? /^(https?|wss?):\/\//i : /^https?:\/\//i).test(String(e.request?.url ?? ""));
|
|
328
|
+
const isHarEntry = (e) => isObject(e) && isObject(e.request) && (isObject(e.response) || "startedDateTime" in e);
|
|
329
|
+
const isEntry = (e) => isObject(e) && typeof e.source === "string" && isObject(e.requestHeaders) && typeof e.url === "string" && typeof e.id === "string" && typeof e.result === "string";
|
|
330
|
+
|
|
331
|
+
/** Read any input into [{ kind, raw }…] (unredacted, no ids yet) and the problems met. */
|
|
332
|
+
function collect(input, depth, found, problems, ctx) {
|
|
333
|
+
if (input === undefined || input === null || input === "") return;
|
|
334
|
+
if (depth > 4) return void problems.push("too deeply nested to read");
|
|
335
|
+
if (typeof input === "string") {
|
|
336
|
+
const text = input.trim();
|
|
337
|
+
if (text.startsWith("{") || text.startsWith("[")) {
|
|
338
|
+
let json;
|
|
339
|
+
try {
|
|
340
|
+
json = JSON.parse(text);
|
|
341
|
+
} catch {
|
|
342
|
+
return void problems.push("that looks like JSON but isn't valid");
|
|
343
|
+
}
|
|
344
|
+
return collect(json, depth + 1, found, problems, ctx);
|
|
345
|
+
}
|
|
346
|
+
try {
|
|
347
|
+
for (const r of readRequests(text).requests) found.push({ kind: "request", raw: fromRequest(r) });
|
|
348
|
+
} catch (error) {
|
|
349
|
+
problems.push(String(error.message));
|
|
350
|
+
}
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (Array.isArray(input)) {
|
|
354
|
+
for (const item of input) collect(item, depth + 1, found, problems, ctx);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (!isObject(input)) return void problems.push("can't read that as traffic: give it a tap value, a webhook's raw capture, a HAR or a request");
|
|
358
|
+
if (Array.isArray(input.log?.entries)) {
|
|
359
|
+
for (const e of input.log.entries) {
|
|
360
|
+
const index = ctx.har++;
|
|
361
|
+
if (!isHarEntry(e) || !harUrlOk(e)) {
|
|
362
|
+
problems.push(`HAR entry ${index} isn't an http(s) request`);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
found.push({ kind: "har", raw: fromHar(e), index });
|
|
366
|
+
}
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (input.mode === "tap" && Array.isArray(input.entries)) {
|
|
370
|
+
for (const e of input.entries) if (isTapEntry(e)) found.push({ kind: "tap", raw: fromTap(e) });
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (isEntry(input)) {
|
|
374
|
+
// A piped-in entry never claims to be the tap's own (source "tap", a tap id): only a tap value is read as one (SRV-04).
|
|
375
|
+
const claimed = input.source === "tap";
|
|
376
|
+
return void found.push({ kind: ["har", "raw", "proxy", "served"].includes(input.source) ? input.source : "request", raw: { ...input, ...(claimed ? { source: "request" } : {}) }, normalized: !claimed });
|
|
377
|
+
}
|
|
378
|
+
if (isTapEntry(input)) return void found.push({ kind: "tap", raw: fromTap(input) });
|
|
379
|
+
if (isRaw(input)) return void found.push({ kind: "raw", raw: fromRaw(input) });
|
|
380
|
+
if (isHarEntry(input)) {
|
|
381
|
+
if (!harUrlOk(input)) return void problems.push("that HAR entry isn't an http(s) request");
|
|
382
|
+
return void found.push({ kind: "har", raw: fromHar(input), index: ctx.har++ });
|
|
383
|
+
}
|
|
384
|
+
if (Array.isArray(input.entries)) return collect(input.entries, depth + 1, found, problems, ctx);
|
|
385
|
+
if (typeof input.url === "string" && typeof input.method === "string") {
|
|
386
|
+
try {
|
|
387
|
+
for (const r of readRequests(input).requests) found.push({ kind: "request", raw: fromRequest(r) });
|
|
388
|
+
} catch (error) {
|
|
389
|
+
problems.push(String(error.message));
|
|
390
|
+
}
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
problems.push("can't read that as traffic: give it a tap value, a webhook's raw capture, a HAR or a request");
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Anything the pane's inputs hold, as entries: `{ entries (oldest first, at most `max`, redacted), source ("tap" | "raw" | "har" | "request" |
|
|
398
|
+
* "mixed" | "none"), problems: [text], dropped }`. It never throws: what can't be read is a problem.
|
|
399
|
+
*/
|
|
400
|
+
export function normalizeTraffic(input, { max = TRAFFIC_DEFAULTS.max } = {}) {
|
|
401
|
+
const found = [];
|
|
402
|
+
const problems = [];
|
|
403
|
+
try {
|
|
404
|
+
collect(input, 0, found, problems, { har: 0 });
|
|
405
|
+
} catch (error) {
|
|
406
|
+
problems.push(`can't read that: ${String(error?.message ?? error).slice(0, 200)}`);
|
|
407
|
+
}
|
|
408
|
+
const counters = { tap: 0, raw: 0, har: 0, request: 0, proxy: 0, served: 0 };
|
|
409
|
+
const seen = new Set();
|
|
410
|
+
const kept = found.slice(-Math.max(1, max));
|
|
411
|
+
const dropped = found.length - kept.length;
|
|
412
|
+
const budget = { left: MAX_TOTAL_BODY_CHARS };
|
|
413
|
+
const entries = kept.map(({ kind, raw, index, normalized }) => {
|
|
414
|
+
const n = counters[kind]++;
|
|
415
|
+
// Ids are stable for a source (a tap counter, a HAR index), so a pin or a selection survives the pane running again.
|
|
416
|
+
let id = normalized ? raw.id : kind === "tap" ? `tap-${raw.tapId}` : kind === "raw" ? `raw-${raw.rawId ?? n}` : kind === "har" ? `har-${index ?? n}` : `req-${n}`;
|
|
417
|
+
for (let i = 2; seen.has(id); i++) id = `${id.replace(/~\d+$/, "")}~${i}`;
|
|
418
|
+
seen.add(id);
|
|
419
|
+
const { _type, tapId, rawId, ...rest } = raw;
|
|
420
|
+
return redactEntry({ ...rest, id }, budget);
|
|
421
|
+
});
|
|
422
|
+
const kinds = new Set(found.map((f) => f.kind));
|
|
423
|
+
return { entries, source: kinds.size === 0 ? "none" : kinds.size === 1 ? [...kinds][0] : "mixed", problems, dropped };
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// ── status class, summary, filters ──────────────────────────────────────────
|
|
427
|
+
|
|
428
|
+
/** "2xx" … "5xx" for an entry with a response, else "refused", "failed" or "none" (a request with no answer yet, or a captured inbound one). */
|
|
429
|
+
export function statusClassOf(e) {
|
|
430
|
+
if (e.result === "refused" || e.allowed === false) return "refused";
|
|
431
|
+
if (e.result === "failed") return "failed";
|
|
432
|
+
return e.status >= 100 && e.status < 600 ? `${Math.floor(e.status / 100)}xx` : "none";
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** Counts by status class and by method, bytes, the slowest entry, how many hosts, and the time from the first entry to the last that has one. */
|
|
436
|
+
export function summarize(entries) {
|
|
437
|
+
const byClass = {};
|
|
438
|
+
const byMethod = {};
|
|
439
|
+
let first = Infinity;
|
|
440
|
+
let last = -Infinity;
|
|
441
|
+
let bytes = 0;
|
|
442
|
+
let slowest = null;
|
|
443
|
+
const hosts = new Set();
|
|
444
|
+
for (const e of entries) {
|
|
445
|
+
const c = statusClassOf(e);
|
|
446
|
+
byClass[c] = (byClass[c] ?? 0) + 1;
|
|
447
|
+
byMethod[e.method] = (byMethod[e.method] ?? 0) + 1;
|
|
448
|
+
const t = e.at ? Date.parse(e.at) : NaN;
|
|
449
|
+
if (Number.isFinite(t)) (first = Math.min(first, t)), (last = Math.max(last, t));
|
|
450
|
+
bytes += (e.requestBytes || 0) + (e.responseBytes || 0);
|
|
451
|
+
if (e.host) hosts.add(e.host);
|
|
452
|
+
if (Number.isFinite(e.ms) && (!slowest || e.ms > slowest.ms)) slowest = { id: e.id, method: e.method, path: e.path, ms: e.ms };
|
|
453
|
+
}
|
|
454
|
+
return { total: entries.length, byClass, byMethod, refused: byClass.refused ?? 0, failed: byClass.failed ?? 0, bytes, slowest, hosts: hosts.size, spanMs: last >= first ? last - first : null };
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const MODE_OF = { raw: "echo", request: "echo", proxy: "proxy", served: "served", tap: "tap", har: "har" };
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Where the entries came from, for the pane's mode badge (prism LST-13). An inbound request nothing answered (a webhook's raw capture, or
|
|
461
|
+
* request text with no response) is "echo"; a proxied exchange is "proxy", one the virtual origin answered is "served"; a request this
|
|
462
|
+
* canvas made is "tap"; a HAR is "har", request text with a response is "request". `kinds` is the sorted list of each kind present, `mode` the one kind or "mixed" ("other" for a source
|
|
463
|
+
* that is none of these: the value is never shown), and `hasResponses` says whether any entry has a response (status controls mean nothing without).
|
|
464
|
+
*/
|
|
465
|
+
export function captureModeOf(entries) {
|
|
466
|
+
const kinds = new Set();
|
|
467
|
+
let hasResponses = false;
|
|
468
|
+
for (const e of Array.isArray(entries) ? entries : []) {
|
|
469
|
+
if (!isObject(e)) continue;
|
|
470
|
+
const answered = e.status >= 100 && e.status < 600;
|
|
471
|
+
if (answered) hasResponses = true;
|
|
472
|
+
const kind = typeof e.source === "string" && Object.hasOwn(MODE_OF, e.source) ? MODE_OF[e.source] : "other";
|
|
473
|
+
kinds.add(kind === "echo" && answered ? "request" : kind);
|
|
474
|
+
}
|
|
475
|
+
const list = [...kinds].sort();
|
|
476
|
+
return { mode: list.length === 0 ? "none" : list.length === 1 ? list[0] : "mixed", kinds: list, hasResponses };
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function haystack(e) {
|
|
480
|
+
const parts = [e.method, e.url, e.status || "", e.statusText, e.pane, e.reason, e.requestBody?.text, e.responseBody?.text, ...(e.frames ?? []).map((f) => f.text)];
|
|
481
|
+
for (const h of [e.requestHeaders, e.responseHeaders]) for (const [k, v] of Object.entries(h ?? {})) parts.push(k, v);
|
|
482
|
+
return parts.filter((p) => p !== undefined && p !== "").join("\n").toLowerCase();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function matchesStatus(e, wanted) {
|
|
486
|
+
const w = wanted.trim().toLowerCase();
|
|
487
|
+
if (!w) return true;
|
|
488
|
+
if (CLASSES.includes(w)) return statusClassOf(e) === w;
|
|
489
|
+
if (/^[1-5]x{1,2}$/.test(w)) return statusClassOf(e) === `${w[0]}xx`;
|
|
490
|
+
if (/^\d{3}$/.test(w)) return e.status === Number(w);
|
|
491
|
+
return e.statusText.toLowerCase().includes(w);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* The entries a filter lets through, pinned ones first (each group in the order given). `filter`: { method, status ("2xx", "404", "refused",
|
|
496
|
+
* "failed"), host (substring), path (literal text, case-insensitive; a leading ^ anchors it to the start, a trailing $ to the end; or `/regex/`, matched in linear time), text (case-insensitive, over the request line,
|
|
497
|
+
* headers and bodies), refusedOnly, pinnedOnly }. `pins` is a Set of ids.
|
|
498
|
+
*/
|
|
499
|
+
export function filterEntries(entries, filter = {}, pins = new Set()) {
|
|
500
|
+
const method = String(filter.method ?? "").trim().toUpperCase();
|
|
501
|
+
const host = String(filter.host ?? "").trim().toLowerCase();
|
|
502
|
+
const pathText = String(filter.path ?? "").trim();
|
|
503
|
+
const text = String(filter.text ?? "").trim().toLowerCase();
|
|
504
|
+
// Text is literal, like the replace ops (#948, #952): case-insensitive, a leading ^ anchors it to the start of the path, a trailing $ to the end,
|
|
505
|
+
// and nothing else is special. `/regex/` (with an operator inside, so `/api/` stays text) runs the linear-time matcher instead (LST-07,
|
|
506
|
+
// src/model/safe-regex.js); a pattern it refuses matches nothing. No RegExp is built from what the person typed.
|
|
507
|
+
const wanted = slashRegex(pathText);
|
|
508
|
+
const compiled = wanted ? compileSafeRegex(wanted.pattern, { ignoreCase: true }) : null;
|
|
509
|
+
const anchoredStart = !wanted && pathText.startsWith("^");
|
|
510
|
+
const anchoredEnd = !wanted && pathText.length > (anchoredStart ? 1 : 0) && pathText.endsWith("$");
|
|
511
|
+
const pathNeedle = pathText.slice(anchoredStart ? 1 : 0, anchoredEnd ? -1 : undefined).toLowerCase();
|
|
512
|
+
// A regular expression can fail to answer (a path over the limit, or the pass's step budget gone): that entry is kept and marked, never hidden as if it did not match.
|
|
513
|
+
const budget = { left: SAFE_REGEX_PASS_STEPS };
|
|
514
|
+
const notTested = new Map();
|
|
515
|
+
const pathMatches = (e) => {
|
|
516
|
+
if (compiled) {
|
|
517
|
+
if (!compiled.ok) return false;
|
|
518
|
+
const answer = compiled.check(e.path + e.query, budget);
|
|
519
|
+
if (answer === "too-long" || answer === "too-costly") {
|
|
520
|
+
notTested.set(e.id, answer === "too-long" ? "too long" : "too costly");
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
return answer === "match";
|
|
524
|
+
}
|
|
525
|
+
const target = (e.path + e.query).toLowerCase();
|
|
526
|
+
if (anchoredStart && anchoredEnd) return target === pathNeedle;
|
|
527
|
+
if (anchoredStart) return target.startsWith(pathNeedle);
|
|
528
|
+
if (anchoredEnd) return target.endsWith(pathNeedle);
|
|
529
|
+
return target.includes(pathNeedle);
|
|
530
|
+
};
|
|
531
|
+
const keep = entries.filter((e) => {
|
|
532
|
+
if (method && e.method !== method) return false;
|
|
533
|
+
if (filter.status && !matchesStatus(e, String(filter.status))) return false;
|
|
534
|
+
if (filter.refusedOnly && statusClassOf(e) !== "refused") return false;
|
|
535
|
+
if (host && !e.host.toLowerCase().includes(host)) return false;
|
|
536
|
+
if (pathText && !pathMatches(e)) return false;
|
|
537
|
+
if (filter.pinnedOnly && !pins.has(e.id)) return false;
|
|
538
|
+
if (text && !haystack(e).includes(text)) return false;
|
|
539
|
+
return true;
|
|
540
|
+
});
|
|
541
|
+
const out = [...keep.filter((e) => pins.has(e.id)), ...keep.filter((e) => !pins.has(e.id))];
|
|
542
|
+
out.notTested = notTested; // id -> why the path pattern was not tried for it ("too long", "too costly"); empty for text filters
|
|
543
|
+
return out;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// ── diff, copy as, export ───────────────────────────────────────────────────
|
|
547
|
+
|
|
548
|
+
// A WebSocket entry is written as the handshake it began with (a GET to the http(s) twin of its URL, asking to upgrade): curl, fetch and raw HTTP have no socket.
|
|
549
|
+
const requestOf = (e) => (e.frames ? { method: "GET", url: e.url.replace(/^ws/i, "http"), headers: { ...e.requestHeaders, connection: "Upgrade", upgrade: "websocket" } } : { method: e.method, url: e.url, headers: { ...e.requestHeaders }, ...(e.requestBody?.text !== undefined ? { body: e.requestBody.text } : {}) });
|
|
550
|
+
const responseOf = (e) => ({ method: "→", url: [e.status || e.result, e.statusText].filter(Boolean).join(" "), headers: { ...e.responseHeaders }, ...(e.responseBody?.text !== undefined ? { body: e.responseBody.text } : {}) });
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Two entries compared: the request (line, headers, body by path or by form field), the response the same way (with the status), and the timing
|
|
554
|
+
* by phase. `text` is for a person; `form` ("curl", "fetch", "raw") adds the two requests written in that form and compared line by line
|
|
555
|
+
* (`formText`). Both entries are redacted first.
|
|
556
|
+
*/
|
|
557
|
+
export async function diffEntriesIn(a, b, form) {
|
|
558
|
+
const d = diffEntries(a, b);
|
|
559
|
+
if (!form) return d;
|
|
560
|
+
if (!["curl", "fetch", "raw"].includes(form)) throw new Error(`unknown form "${form}": use curl, fetch or raw`);
|
|
561
|
+
const [fa, fb] = await Promise.all([formatsOf(requestOf(redactEntry(a))), formatsOf(requestOf(redactEntry(b)))]);
|
|
562
|
+
const { lines: all } = lineDiffBounded(fa[form], fb[form]);
|
|
563
|
+
const lines = all.length > 400 ? compactLines(all) : all; // the changed lines with a little around them, not 70,000 of the same line
|
|
564
|
+
const changed = lines.filter((l) => l.op !== "=" || /more (removed|added) lines/.test(l.line));
|
|
565
|
+
const formText = changed.length === 0 ? `the requests are the same as ${form}` : changed.map((l) => `${l.op} ${l.line}`).join("\n");
|
|
566
|
+
return { ...d, form, formLines: lines, formText };
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/** Two entries compared: the request (line, headers, body) and the response (status, headers, body), and the time by phase. `text` is for a person. */
|
|
570
|
+
export function diffEntries(a, b) {
|
|
571
|
+
const A = redactEntry(a);
|
|
572
|
+
const B = redactEntry(b);
|
|
573
|
+
const request = diffRequests(requestOf(A), requestOf(B));
|
|
574
|
+
const response = diffRequests(responseOf(A), responseOf(B));
|
|
575
|
+
const status = A.status === B.status ? null : { from: A.status, to: B.status };
|
|
576
|
+
const timing = timingDiff(A, B);
|
|
577
|
+
const timingLines = timing.map((r) => `${r.phase}: ${r.from === null ? "—" : `${r.from} ms`} -> ${r.to === null ? "—" : `${r.to} ms`}${r.delta === null ? "" : ` (${r.delta > 0 ? "+" : ""}${r.delta} ms)`}`);
|
|
578
|
+
const text = [
|
|
579
|
+
"request",
|
|
580
|
+
request.identical ? "the requests are the same" : diffText(request),
|
|
581
|
+
"response",
|
|
582
|
+
response.identical ? "the responses are the same" : diffText(response),
|
|
583
|
+
...(timing.length ? ["timing", ...timingLines] : []),
|
|
584
|
+
].join("\n");
|
|
585
|
+
return { identical: request.identical && response.identical, request, response: { ...response, status }, timing, text };
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/** The shared time axis for the entries (src/model/timing.js waterfall), redacted first: each row's label, offset, total and phases. */
|
|
589
|
+
export function trafficWaterfall(entries) {
|
|
590
|
+
return waterfall(entries.map((e) => redactEntry(e)));
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const epoch = "1970-01-01T00:00:00.000Z";
|
|
594
|
+
|
|
595
|
+
async function harEntryOf(e) {
|
|
596
|
+
const base = (await formatsOf(requestOf(e))).har;
|
|
597
|
+
const t = e.timings;
|
|
598
|
+
return {
|
|
599
|
+
...base,
|
|
600
|
+
startedDateTime: e.at ?? epoch,
|
|
601
|
+
time: e.ms ?? 0,
|
|
602
|
+
request: { ...base.request, ...(e.requestBytes ? { bodySize: e.requestBytes } : {}) },
|
|
603
|
+
response: {
|
|
604
|
+
status: e.status || 0,
|
|
605
|
+
statusText: e.statusText || "",
|
|
606
|
+
httpVersion: "HTTP/1.1",
|
|
607
|
+
cookies: [],
|
|
608
|
+
headers: Object.entries(e.responseHeaders ?? {}).map(([name, value]) => ({ name, value })),
|
|
609
|
+
content: { size: e.responseBytes || 0, mimeType: e.responseHeaders?.["content-type"] ?? "", ...(e.responseBody?.text !== undefined ? { text: e.responseBody.text } : {}) },
|
|
610
|
+
redirectURL: e.responseHeaders?.location ?? "",
|
|
611
|
+
headersSize: -1,
|
|
612
|
+
bodySize: e.responseBytes || -1,
|
|
613
|
+
...(e.result === "refused" || e.result === "failed" ? { _error: `${e.result}${e.reason ? `: ${e.reason}` : ""}` } : {}),
|
|
614
|
+
},
|
|
615
|
+
timings: toHarTimings(t, e.ms),
|
|
616
|
+
...(e.via === "companion" ? { _via: "companion" } : {}),
|
|
617
|
+
...(e.frames ? { _webSocketMessages: e.frames.map((f) => ({ type: f.dir === "out" ? "send" : "receive", time: Number.isFinite(new Date(f.at).getTime()) ? new Date(f.at).getTime() / 1000 : 0, opcode: f.binary ? 2 : 1, data: f.binary ? `[${f.bytes} bytes, not kept]` : (f.text ?? "") })) } : {}),
|
|
618
|
+
_pane: e.pane ?? "",
|
|
619
|
+
_allowed: e.allowed,
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* A list of entries in one form: "har" (one HAR 1.2 log with the responses and phases the entries hold), "curl" (a script, one command
|
|
625
|
+
* a request), "fetch" or "raw" (each request's text one after the other). Entries are redacted again on the way (so a caller handing in
|
|
626
|
+
* its own cannot export a credential). An empty list is "".
|
|
627
|
+
*/
|
|
628
|
+
export async function exportEntries(entries, form, { module = false } = {}) {
|
|
629
|
+
if (!FORMS.includes(form)) throw new Error(`unknown form "${form}": use ${FORMS.join(", ")}`);
|
|
630
|
+
const safe = entries.map((e) => redactEntry(e));
|
|
631
|
+
if (!safe.length) return "";
|
|
632
|
+
// `module` (prism's `GET /export/fetch`, LST-10 and EXP-03): the fetch() code of every request as one ES module. The plain form is one snippet after
|
|
633
|
+
// another, which redeclares `response` and is not a module; here each request is an exported async function, and `runAll()` runs them in order.
|
|
634
|
+
if (module && form === "fetch") {
|
|
635
|
+
const parts = await Promise.all(safe.map(async (e) => textFor([requestOf(e)], "fetch")));
|
|
636
|
+
const body = parts.map((code, i) => `export async function request${i + 1}() {\n${code.trimEnd().split("\n").map((l) => (l ? ` ${l}` : l)).join("\n")}\n return { response, data };\n}\n`).join("\n");
|
|
637
|
+
const names = safe.map((_, i) => `request${i + 1}`).join(", ");
|
|
638
|
+
return `// ${safe.length} request${safe.length === 1 ? "" : "s"} from a mallory traffic pane, as an ES module. Credentials are written "${REDACTED}": put the real ones in before you run it.\n\n${body}\nexport const requests = [${names}];\n\nexport async function runAll() {\n const results = [];\n for (const run of requests) results.push(await run());\n return results;\n}\n`;
|
|
639
|
+
}
|
|
640
|
+
if (form === "har") return JSON.stringify({ log: { version: "1.2", creator: { name: "mallory traffic pane", version: "1" }, entries: await Promise.all(safe.map(harEntryOf)) } }, null, 2);
|
|
641
|
+
return textFor(safe.map(requestOf), form);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** One entry's request in one form: "curl", "fetch", "raw" (HTTP text) or "har" (a log of one). */
|
|
645
|
+
export async function copyEntryAs(entry, form) {
|
|
646
|
+
if (!FORMS.includes(form)) throw new Error(`unknown form "${form}": use ${FORMS.join(", ")}`);
|
|
647
|
+
return exportEntries([entry], form);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/** The entry as HTTP text, the request and then the response (what the "raw" tab shows). Redacted; a binary body is only its size. */
|
|
651
|
+
export function rawHttp(entry) {
|
|
652
|
+
const e = redactEntry(entry);
|
|
653
|
+
const line = (b) => (b?.text !== undefined ? `\n\n${b.text}${b.truncated ? "\n[cut]" : ""}` : b?.binary ? `\n\n[${b.bytes} bytes, not text]` : "");
|
|
654
|
+
const head = (o) => Object.entries(o).map(([k, v]) => `${k}: ${v}`).join("\n");
|
|
655
|
+
const request = `${e.method} ${e.path}${e.query} HTTP/1.1${e.host ? `\nhost: ${e.host}` : ""}${Object.keys(e.requestHeaders).length ? `\n${head(e.requestHeaders)}` : ""}${line(e.requestBody)}`;
|
|
656
|
+
const response = e.status ? `HTTP/1.1 ${e.status} ${e.statusText}`.trimEnd() + (Object.keys(e.responseHeaders).length ? `\n${head(e.responseHeaders)}` : "") + line(e.responseBody) : `(${e.result === "refused" || e.result === "failed" ? `${e.result}${e.reason ? `: ${e.reason}` : ""}` : "no response"})`;
|
|
657
|
+
return `${request}\n\n----\n\n${response}`;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// ── the pane's value ────────────────────────────────────────────────────────
|
|
661
|
+
|
|
662
|
+
/** What the pane stores (and an agent reads): the redacted entries oldest first, the summary, what was dropped and what could not be read. */
|
|
663
|
+
export function trafficValue({ entries, source, problems, dropped }) {
|
|
664
|
+
return { source, count: entries.length, dropped, problems, summary: summarize(entries), entries };
|
|
665
|
+
}
|