@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,278 @@
|
|
|
1
|
+
// The window manager's commands that the palette and the menus offer for panes: bring to the front, send to the
|
|
2
|
+
// back, move to a layer, pin in place, make sticky; and, in Present mode, the layout commands. Pure: no DOM.
|
|
3
|
+
// window-algebra's palette catalog (`COMMAND_CATALOG`) says what each command asks for (its payload fields) and
|
|
4
|
+
// `fieldChoices` lists the choices; this module narrows both to what is valid in the window state now (a pane already
|
|
5
|
+
// in front can't be raised; a layer it is already in isn't offered; a pinned pane isn't offered "Pin"), and says each
|
|
6
|
+
// step in words for the undo announcement.
|
|
7
|
+
//
|
|
8
|
+
// The stacking commands run on the window manager. Pin (the catalog's window/set-draggable) and sticky
|
|
9
|
+
// (window/set-sticky) are pane fields like the layer (src/model/desk.js: saved, undone, shared), so their entries
|
|
10
|
+
// are keyed by what they do ("window/pin", "window/unpin", …) and name the catalog command they are (`catalog`) and
|
|
11
|
+
// the payload that picks their half of it (`values`). The catalog's scratchpad (the stash), urgent and workspace
|
|
12
|
+
// commands are named here too, with `command`: the mallory command that does them (src/desk-commands.js,
|
|
13
|
+
// src/workspace-commands.js), because the canvas keeps that state in pane fields and its workspaces, not in the
|
|
14
|
+
// manager's scratchpad. Their entries only say what each is called, when it is valid and what it says; running
|
|
15
|
+
// one runs that command, unchanged.
|
|
16
|
+
//
|
|
17
|
+
// The catalog's layout commands (`LAYOUT_COMMANDS`) act on Present mode's tiled layout (src/ui/presentation.js):
|
|
18
|
+
// the canvas itself floats its panes, and arranging them is the arrange menu's (src/ui/layout.js).
|
|
19
|
+
import { COMMAND_CATALOG, fieldChoices, parseField, buildCommand, isTextField, update as wmUpdate } from "@johnhenry/window-algebra";
|
|
20
|
+
import { isPinned } from "./desk.js";
|
|
21
|
+
|
|
22
|
+
/** The layers a person can put a pane in, back to front (the others are for dialogs and overlays). */
|
|
23
|
+
export const PANE_LAYERS = Object.freeze(["background", "normal", "top"]);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* One layer model: a pane's layer is its saved `layer` field (src/model/desk.js: "back", "top", or absent for normal),
|
|
27
|
+
* which is undoable, saved and shared. The window manager keeps every pane on its normal layer; only its order
|
|
28
|
+
* inside a layer (raise, lower) is the manager's. These map the catalog's layer names to the field and back.
|
|
29
|
+
*/
|
|
30
|
+
export const FIELD_OF_LAYER = Object.freeze({ background: "back", normal: undefined, top: "top" });
|
|
31
|
+
const LAYER_OF_FIELD = Object.freeze({ back: "background", top: "top" });
|
|
32
|
+
/** The catalog's layer name ("background", "normal", "top") of a pane record. */
|
|
33
|
+
export const paneLayer = (pane) => LAYER_OF_FIELD[pane?.layer] ?? "normal";
|
|
34
|
+
|
|
35
|
+
/** What the desk and workspaces know that the manager's state does not: `pane(id)`, and how many there are. */
|
|
36
|
+
const NOTHING = Object.freeze({ pane: () => undefined, stashed: 0, failing: 0, workspaces: 0 });
|
|
37
|
+
|
|
38
|
+
const stackOf = (state, id) => state.stack[state.windows[id]?.layer] ?? [];
|
|
39
|
+
|
|
40
|
+
/** What each offered command is called, where it is listed and whether it can act on a window now. */
|
|
41
|
+
export const WINDOW_COMMANDS = Object.freeze({
|
|
42
|
+
"window/raise": {
|
|
43
|
+
title: "Bring pane to front",
|
|
44
|
+
valid: (state, id) => stackOf(state, id).at(-1) !== id,
|
|
45
|
+
words: (names) => `bringing ${names} to the front`,
|
|
46
|
+
},
|
|
47
|
+
"window/lower": {
|
|
48
|
+
title: "Send pane to back",
|
|
49
|
+
valid: (state, id) => stackOf(state, id)[0] !== id,
|
|
50
|
+
words: (names) => `sending ${names} to the back`,
|
|
51
|
+
},
|
|
52
|
+
"window/set-layer": {
|
|
53
|
+
title: "Move pane to a layer…",
|
|
54
|
+
valid: (state, id, layerFor) => PANE_LAYERS.some((layer) => layer !== layerFor(id)),
|
|
55
|
+
words: (names, values) => `moving ${names} to the ${values.layer} layer`,
|
|
56
|
+
},
|
|
57
|
+
// Pinned in place and sticky (src/model/desk.js): pane fields, as the layer is. A pane the canvas doesn't know isn't offered.
|
|
58
|
+
"window/pin": {
|
|
59
|
+
title: "Pin pane in place",
|
|
60
|
+
catalog: "window/set-draggable",
|
|
61
|
+
values: { draggable: false },
|
|
62
|
+
valid: (state, id, layerFor, read) => Boolean(read.pane(id)) && !isPinned(read.pane(id)),
|
|
63
|
+
words: (names) => `pinning ${names} in place`,
|
|
64
|
+
},
|
|
65
|
+
"window/unpin": {
|
|
66
|
+
title: "Unpin pane",
|
|
67
|
+
catalog: "window/set-draggable",
|
|
68
|
+
values: { draggable: true },
|
|
69
|
+
valid: (state, id, layerFor, read) => isPinned(read.pane(id)),
|
|
70
|
+
words: (names) => `unpinning ${names}`,
|
|
71
|
+
},
|
|
72
|
+
"window/stick": {
|
|
73
|
+
title: "Make pane sticky",
|
|
74
|
+
catalog: "window/set-sticky",
|
|
75
|
+
values: { sticky: true },
|
|
76
|
+
valid: (state, id, layerFor, read) => Boolean(read.pane(id)) && !read.pane(id).sticky && !read.pane(id).stashed,
|
|
77
|
+
words: (names) => `making ${names} sticky`,
|
|
78
|
+
},
|
|
79
|
+
"window/unstick": {
|
|
80
|
+
title: "Unstick pane",
|
|
81
|
+
catalog: "window/set-sticky",
|
|
82
|
+
values: { sticky: false },
|
|
83
|
+
valid: (state, id, layerFor, read) => Boolean(read.pane(id)?.sticky),
|
|
84
|
+
words: (names) => `unsticking ${names}`,
|
|
85
|
+
},
|
|
86
|
+
// The desk (src/model/desk.js): the stash is the catalog's scratchpad; urgent is a pane whose last run failed.
|
|
87
|
+
"window/to-scratchpad": {
|
|
88
|
+
title: "Stash pane",
|
|
89
|
+
command: "pane.stash",
|
|
90
|
+
valid: (state, id, layerFor, read) => read.workspaces > 0 && !read.pane(id)?.stashed,
|
|
91
|
+
words: (names) => `stashing ${names}`,
|
|
92
|
+
},
|
|
93
|
+
"window/from-scratchpad": {
|
|
94
|
+
title: "Bring pane out of the stash",
|
|
95
|
+
command: "pane.stash",
|
|
96
|
+
valid: (state, id, layerFor, read) => Boolean(read.pane(id)?.stashed),
|
|
97
|
+
words: (names) => `bringing ${names} out of the stash`,
|
|
98
|
+
},
|
|
99
|
+
"scratchpad/toggle": {
|
|
100
|
+
title: "Show or hide the stash",
|
|
101
|
+
command: "view.stash",
|
|
102
|
+
global: (read) => read.stashed > 0,
|
|
103
|
+
words: () => "showing or hiding the stash",
|
|
104
|
+
},
|
|
105
|
+
"focus/urgent": {
|
|
106
|
+
title: "Go to the next failing pane",
|
|
107
|
+
command: "view.focus-urgent",
|
|
108
|
+
global: (read) => read.failing > 0,
|
|
109
|
+
words: () => "going to the next failing pane",
|
|
110
|
+
},
|
|
111
|
+
// Workspaces (src/model/workspaces.js).
|
|
112
|
+
"window/move-to-workspace": {
|
|
113
|
+
title: "Move pane to a workspace…",
|
|
114
|
+
command: "workspace.move-panes",
|
|
115
|
+
valid: (state, id, layerFor, read) => read.workspaces > 1,
|
|
116
|
+
words: (names) => `moving ${names} to another workspace`,
|
|
117
|
+
},
|
|
118
|
+
"workspace/create": { title: "New workspace…", command: "workspace.new", global: (read) => read.workspaces > 0, words: () => "making a workspace" },
|
|
119
|
+
"workspace/activate": { title: "Switch workspace…", command: "workspace.switch", global: (read) => read.workspaces > 1, words: () => "switching workspace" },
|
|
120
|
+
"workspace/remove": { title: "Remove workspace…", command: "workspace.remove", global: (read) => read.workspaces > 1, words: () => "removing a workspace" },
|
|
121
|
+
"workspace/rename": { title: "Rename workspace…", command: "workspace.rename", global: (read) => read.workspaces > 0, words: () => "renaming a workspace" },
|
|
122
|
+
"workspace/reorder": { title: "Move workspace right", command: "workspace.move-right", global: (read) => read.workspaces > 1, words: () => "moving a workspace" },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
/** The catalog command an offered command is (its own type, or the one it is half of: pin is window/set-draggable). */
|
|
126
|
+
export const catalogType = (type) => WINDOW_COMMANDS[type]?.catalog ?? type;
|
|
127
|
+
|
|
128
|
+
/** The catalog types that a mallory command does (all but the stacking ones). */
|
|
129
|
+
export const viaTypes = () => Object.keys(WINDOW_COMMANDS).filter((type) => WINDOW_COMMANDS[type].command);
|
|
130
|
+
/** The mallory command id that does catalog command `type`, or undefined for one the manager runs. */
|
|
131
|
+
export const viaCommandFor = (type) => WINDOW_COMMANDS[type]?.command;
|
|
132
|
+
|
|
133
|
+
/** Window ids the command `type` would change now. */
|
|
134
|
+
export function validTargets(state, type, layerFor = (id) => state.windows[id]?.layer, read = NOTHING) {
|
|
135
|
+
const spec = WINDOW_COMMANDS[type];
|
|
136
|
+
if (!spec?.valid) return []; // a global command (no window to pick) has no targets
|
|
137
|
+
return Object.keys(state.windows).filter((id) => state.windows[id].workspace !== null && spec.valid(state, id, layerFor, read));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The offered command types that are valid in this window state, in the catalog's order. */
|
|
141
|
+
export function availableTypes(state, layerFor, read = NOTHING) {
|
|
142
|
+
return Object.keys(WINDOW_COMMANDS).filter((type) => (WINDOW_COMMANDS[type].global ? WINDOW_COMMANDS[type].global(read) : validTargets(state, type, layerFor, read).length > 0));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The next field to ask for, given the values so far, or null when the command is complete:
|
|
147
|
+
* `{ name, label, kind, choices? | text: true }`. A window field lists only the windows the command can act on;
|
|
148
|
+
* a layer field leaves out a layer every one of `ids` (the panes it is for) is in already. `layerFor(id)` says a
|
|
149
|
+
* pane's layer (the saved field: `paneLayer`); without it the manager's own layer is read.
|
|
150
|
+
*/
|
|
151
|
+
export function nextField(state, type, values = {}, ids = values.id === undefined ? [] : [values.id], layerFor = (id) => state.windows[id]?.layer, read = NOTHING) {
|
|
152
|
+
const fields = COMMAND_CATALOG[catalogType(type)]?.fields ?? [];
|
|
153
|
+
values = { ...WINDOW_COMMANDS[type]?.values, ...values };
|
|
154
|
+
for (const field of fields) {
|
|
155
|
+
if (field.optional && !field.ask) continue;
|
|
156
|
+
if (values[field.name] !== undefined) continue;
|
|
157
|
+
if (isTextField(field)) return { name: field.name, label: field.label, kind: field.kind, text: true, default: field.default };
|
|
158
|
+
let choices = fieldChoices(state, field) ?? [];
|
|
159
|
+
if (field.kind === "window") {
|
|
160
|
+
const ok = new Set(validTargets(state, type, layerFor, read));
|
|
161
|
+
choices = choices.filter((c) => ok.has(c.value));
|
|
162
|
+
} else if (type === "window/set-layer" && field.name === "layer") {
|
|
163
|
+
// A layer is offered when at least one of the panes isn't in it already.
|
|
164
|
+
choices = choices.filter((c) => PANE_LAYERS.includes(c.value) && ids.some((id) => layerFor(id) !== c.value));
|
|
165
|
+
}
|
|
166
|
+
return { name: field.name, label: field.kind === "window" ? "Pane" : field.label, kind: field.kind, choices };
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Turn what was typed or picked into the field's value (window-algebra's `parseField`). */
|
|
172
|
+
export function parseValue(state, type, name, input) {
|
|
173
|
+
const field = (COMMAND_CATALOG[catalogType(type)]?.fields ?? []).find((f) => f.name === name);
|
|
174
|
+
return field ? parseField(field, input) : { ok: false, error: `${type} has no ${name}.` };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The command to dispatch: an undo step of its own even for stacking, which clicks keep out of history. */
|
|
178
|
+
export function commandFor(type, values) {
|
|
179
|
+
return { ...buildCommand(catalogType(type), { ...WINDOW_COMMANDS[type]?.values, ...values }), history: true };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** "label", "label and price", "3 panes": the panes a step names. */
|
|
183
|
+
export function namesOf(ids, nameOf) {
|
|
184
|
+
const names = ids.map(nameOf);
|
|
185
|
+
return names.length > 2 ? `${names.length} panes` : names.join(" and ");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The step in words, for the announcement of its undo and redo. */
|
|
189
|
+
export function wordsFor(type, values, ids, nameOf) {
|
|
190
|
+
return WINDOW_COMMANDS[type].words(namesOf(ids, nameOf), values);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ── Present mode's layout (src/ui/presentation.js) ──────────────────────────────────────────────────────────────
|
|
194
|
+
|
|
195
|
+
/** The layout types a presentation can use (src/model/presentation.js PRESENT_LAYOUTS), with their labels. */
|
|
196
|
+
const layoutLabel = (layouts, type) => layouts.find((l) => l.id === type)?.label ?? type;
|
|
197
|
+
const activeLayout = (state) => state.workspaces[state.activeWorkspace]?.layout ?? {};
|
|
198
|
+
/** Would the manager take `command` now? Tried on the pure core: nothing changes. */
|
|
199
|
+
const takes = (state, command) => !wmUpdate(state, command).events.some((e) => e.type === "command/rejected");
|
|
200
|
+
/** BSP splits are found by the focused window: with none focused there is no split to act on. */
|
|
201
|
+
const splitFound = (state) => activeLayout(state).type !== "bsp" || Boolean(state.focus.window);
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The catalog's layout commands, for the presentation's window manager. `valid(state)` says whether one can act now
|
|
205
|
+
* (tried on the pure core with a sample payload, so a layout that has no ratio or no split isn't offered them);
|
|
206
|
+
* `words(values, layouts)` says the step.
|
|
207
|
+
*/
|
|
208
|
+
export const LAYOUT_COMMANDS = Object.freeze({
|
|
209
|
+
"layout/set": {
|
|
210
|
+
title: "Set presentation layout…",
|
|
211
|
+
valid: () => true,
|
|
212
|
+
words: (values, layouts) => `switching the presentation to ${layoutLabel(layouts, values.layout?.type)}`,
|
|
213
|
+
},
|
|
214
|
+
"layout/toggle": {
|
|
215
|
+
title: "Toggle presentation between two layouts…",
|
|
216
|
+
valid: () => true,
|
|
217
|
+
words: (values, layouts) => `toggling the presentation between ${layoutLabel(layouts, values.a?.type)} and ${layoutLabel(layouts, values.b?.type)}`,
|
|
218
|
+
},
|
|
219
|
+
"layout/to-tree": {
|
|
220
|
+
title: "Turn presentation layout into a docking tree",
|
|
221
|
+
valid: (state) => activeLayout(state).type !== "tree",
|
|
222
|
+
words: () => "turning the presentation layout into a docking tree",
|
|
223
|
+
},
|
|
224
|
+
"layout/set-ratio": {
|
|
225
|
+
title: "Set presentation split ratio…",
|
|
226
|
+
valid: (state) => splitFound(state) && takes(state, { type: "layout/set-ratio", ratio: 0.5 }),
|
|
227
|
+
words: (values) => `setting the split ratio to ${values.ratio}`,
|
|
228
|
+
},
|
|
229
|
+
"layout/rotate-split": {
|
|
230
|
+
title: "Rotate presentation split",
|
|
231
|
+
valid: (state) => Boolean(state.focus.window) && takes(state, { type: "layout/rotate-split" }),
|
|
232
|
+
words: () => "rotating a split",
|
|
233
|
+
},
|
|
234
|
+
"layout/resize-split": {
|
|
235
|
+
title: "Resize presentation split…",
|
|
236
|
+
valid: (state) => takes(state, { type: "layout/resize-split", path: "", delta: 0.05 }),
|
|
237
|
+
words: (values) => `resizing the ${values.path ? `split at ${values.path}` : "first split"} by ${values.delta}`,
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
/** The layout commands valid in this presentation state, in the catalog's order. */
|
|
242
|
+
export const availableLayoutTypes = (state) => Object.keys(LAYOUT_COMMANDS).filter((type) => LAYOUT_COMMANDS[type].valid(state));
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* The next field a layout command asks for, given the values so far, or null when it is complete. A layout field
|
|
246
|
+
* lists `layouts` (`[{ id, label, hint }]`, the presentation's), leaving out the one in use for "layout/set" and the
|
|
247
|
+
* first pick for the second of "layout/toggle". A ratio or a delta is typed (`text: true`).
|
|
248
|
+
*/
|
|
249
|
+
export function nextLayoutField(state, type, values = {}, layouts = []) {
|
|
250
|
+
for (const field of COMMAND_CATALOG[type]?.fields ?? []) {
|
|
251
|
+
if (field.optional && !field.ask) continue;
|
|
252
|
+
if (values[field.name] !== undefined) continue;
|
|
253
|
+
if (isTextField(field)) return { name: field.name, label: field.label, kind: field.kind, text: true, default: field.default };
|
|
254
|
+
if (field.kind === "layout") {
|
|
255
|
+
const leaveOut = type === "layout/set" ? activeLayout(state).type : type === "layout/toggle" && field.name === "b" ? values.a?.type : undefined;
|
|
256
|
+
return { name: field.name, label: field.label, kind: field.kind, choices: layouts.filter((l) => l.id !== leaveOut).map((l) => ({ value: l.id, label: l.label, ...(l.hint ? { detail: l.hint } : {}) })) };
|
|
257
|
+
}
|
|
258
|
+
return { name: field.name, label: field.label, kind: field.kind, choices: fieldChoices(state, field) ?? [] };
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Turn what was typed or picked for a layout command's field into its value (window-algebra's `parseField`). */
|
|
264
|
+
export function parseLayoutValue(type, name, input) {
|
|
265
|
+
const field = (COMMAND_CATALOG[type]?.fields ?? []).find((f) => f.name === name);
|
|
266
|
+
if (!field) return { ok: false, error: `${type} has no ${name}.` };
|
|
267
|
+
if (type === "layout/set-ratio" && name === "ratio") {
|
|
268
|
+
const n = Number(input);
|
|
269
|
+
if (String(input).trim() === "" || !Number.isFinite(n) || n <= 0 || n >= 1) return { ok: false, error: "The ratio is a number between 0 and 1, like 0.6." };
|
|
270
|
+
}
|
|
271
|
+
if (name === "delta" && Number.isFinite(Number(input)) && String(input).trim() !== "" && Math.abs(Number(input)) >= 1) return { ok: false, error: "The change is a fraction of the split, between -1 and 1, like 0.05." };
|
|
272
|
+
return parseField(field, input);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** The step to dispatch: the catalog command with its values, an undo step of its own, carrying its words. */
|
|
276
|
+
export function layoutCommandFor(type, values, words) {
|
|
277
|
+
return { ...buildCommand(type, values), history: true, words };
|
|
278
|
+
}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// Time-window gates: "hold each item until the business clock says it
|
|
2
|
+
// may go, and spread a held crowd over the first minutes of the window". Pure
|
|
3
|
+
// data and functions: no DOM, no timers, no Math.random, no clock of their own
|
|
4
|
+
// (every function takes the instant it means). Time zones are Intl only, through
|
|
5
|
+
// the helpers src/model/timers.js already uses for cron.
|
|
6
|
+
//
|
|
7
|
+
// A gate pane is a wait (src/model/waits.js, src/model/wait-clock.js) with no
|
|
8
|
+
// event paths: an instance's `deadlineAt` is the instant its item is released,
|
|
9
|
+
// computed when it starts, and its one outcome is "released" (or "cancelled").
|
|
10
|
+
// This module decides that instant.
|
|
11
|
+
//
|
|
12
|
+
// The window. Declared by an IANA zone, the weekdays it OPENS on, a start and an
|
|
13
|
+
// end time of day. An end at or before the start crosses midnight: the window
|
|
14
|
+
// that opens Friday 22:00 and ends 06:00 closes Saturday 06:00, and the days list
|
|
15
|
+
// names the day it opens. ("24:00" is an end that means midnight.) A window is
|
|
16
|
+
// one interval of instants [opensAt, closesAt).
|
|
17
|
+
//
|
|
18
|
+
// Daylight saving. A boundary is the FIRST instant the zone's wall clock reads
|
|
19
|
+
// that time or later:
|
|
20
|
+
// - a time the clock reads twice (the hour that repeats when clocks go back)
|
|
21
|
+
// is its first, earlier instant; a window crossing the repeat is open
|
|
22
|
+
// through the whole repeated hour, once;
|
|
23
|
+
// - a time the clock skips (the hour that disappears when clocks go forward)
|
|
24
|
+
// is the instant of the jump: a window that starts at 02:30 on that day
|
|
25
|
+
// opens when the clock reaches 03:00, and one that ends at 02:30 closes
|
|
26
|
+
// then; a window that lies entirely inside the skipped hour doesn't open
|
|
27
|
+
// that day.
|
|
28
|
+
//
|
|
29
|
+
// Holidays. A window doesn't open on a business-calendar holiday (a preset such as "us-federal", a date, or a month and
|
|
30
|
+
// day: src/model/calendar.js, which reads @johnhenry/temporals' BusinessCalendar): the day is skipped whole, a window past
|
|
31
|
+
// midnight included (it belongs to the day it opens), and the next listed weekday that isn't a holiday takes its place. The
|
|
32
|
+
// hours of a day, and daylight saving above, stay this module's: the business calendar decides which days open.
|
|
33
|
+
//
|
|
34
|
+
// Jitter. A crowd waiting for a window to open would all go at its first
|
|
35
|
+
// instant; `jitterMs` spreads them over the first part of the window instead:
|
|
36
|
+
// each item goes at the opening plus an offset in [0, jitterMs] chosen from a
|
|
37
|
+
// hash of (seed, item, opening), never Math.random, so the same seed and item
|
|
38
|
+
// give the same instant in every run, and a different seed spreads them
|
|
39
|
+
// differently. The offset never leaves the window: it is at most the window's
|
|
40
|
+
// length less a millisecond. An item that arrives while the window is open goes
|
|
41
|
+
// at once, with no jitter (the herd is the items that waited for the opening), unless the gate's `jitterOpen` is "spread":
|
|
42
|
+
// then it goes at its arrival plus an offset in [0, jitterMs] cut to what is left of the window, from a hash of (seed, item,
|
|
43
|
+
// arrival), so a burst that arrives together does not leave together.
|
|
44
|
+
// The seed is the gate's `seed`; unset, it is the canvas's id and the pane's id
|
|
45
|
+
// (stable for a canvas, different between gates).
|
|
46
|
+
import { zoneOk, wallMs, wallToInstant } from "./timers.js";
|
|
47
|
+
import { parseTime, parseTimeOfDay } from "./nl-time.js";
|
|
48
|
+
import { unit } from "./hash.js";
|
|
49
|
+
import { holidayProblem, cleanHolidays, holidaySet, isOpenDay } from "./calendar.js";
|
|
50
|
+
|
|
51
|
+
export { unit }; // the seeded hash (src/model/hash.js), shared with the weighted split (src/model/split.js)
|
|
52
|
+
|
|
53
|
+
export const DAY_NAMES = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
54
|
+
export const MAX_JITTER_MS = 24 * 3600 * 1000;
|
|
55
|
+
export const MAX_SEED = 64;
|
|
56
|
+
export const MAX_GATE_WAIT_MS = 366 * 24 * 3600 * 1000;
|
|
57
|
+
export const OUTCOME_RELEASED = "released";
|
|
58
|
+
/** The gate's terminal ports; "scheduled" (an item is being held) is informational and not an outcome. */
|
|
59
|
+
export const OUTCOME_EXPIRED = "expired"; // maxWaitMs ran out before the window released the item
|
|
60
|
+
export const GATE_OUTCOMES = [OUTCOME_RELEASED, "cancelled", OUTCOME_EXPIRED];
|
|
61
|
+
export const GATE_EVENTS = ["scheduled", ...GATE_OUTCOMES];
|
|
62
|
+
|
|
63
|
+
const MIN = 60000;
|
|
64
|
+
const DAY = 86400000;
|
|
65
|
+
const TIME = /^([01]?\d|2[0-3]):([0-5]\d)$/;
|
|
66
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_-]{0,31}$/;
|
|
67
|
+
const PATH = /^\S{0,200}$/;
|
|
68
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
69
|
+
|
|
70
|
+
export const DEFAULT_GATE = {
|
|
71
|
+
zone: "UTC",
|
|
72
|
+
days: [1, 2, 3, 4, 5],
|
|
73
|
+
start: "09:00",
|
|
74
|
+
end: "17:00",
|
|
75
|
+
holidays: [],
|
|
76
|
+
jitterMs: 0,
|
|
77
|
+
jitterOpen: "now",
|
|
78
|
+
seed: "",
|
|
79
|
+
atPath: "",
|
|
80
|
+
by: "",
|
|
81
|
+
limit: 1000,
|
|
82
|
+
maxWaitMs: 0,
|
|
83
|
+
restart: "replace",
|
|
84
|
+
startInput: "start",
|
|
85
|
+
cancelInput: "cancel",
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** "09:30" as minutes into the day; "24:00" (an end only) is 1440; undefined when it isn't a time. */
|
|
89
|
+
export function minutesOf(text, { end = false } = {}) {
|
|
90
|
+
if (end && text === "24:00") return 1440;
|
|
91
|
+
const m = TIME.exec(String(text ?? ""));
|
|
92
|
+
return m ? Number(m[1]) * 60 + Number(m[2]) : undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A window's start or end as it is stored: "HH:MM" ("24:00" for an end at midnight), from that or from words ("9am", "5:30 pm",
|
|
97
|
+
* "noon", "midnight"). Words are read once, here, so what the canvas keeps is the time of day and the phrase is gone. undefined
|
|
98
|
+
* when it is neither.
|
|
99
|
+
*/
|
|
100
|
+
export function timeOfDay(text, { end = false } = {}) {
|
|
101
|
+
const exact = minutesOf(text, { end });
|
|
102
|
+
if (exact !== undefined) return exact === 1440 ? "24:00" : clock(exact);
|
|
103
|
+
const words = typeof text === "string" ? parseTimeOfDay(text) : undefined;
|
|
104
|
+
if (words === undefined) return undefined;
|
|
105
|
+
return end && words === 0 ? "24:00" : clock(words);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const clock = (min) => `${String(Math.floor(min / 60)).padStart(2, "0")}:${String(min % 60).padStart(2, "0")}`;
|
|
109
|
+
|
|
110
|
+
/** A weekday as 0 (Sunday) to 6, from a number or a name ("mon", "Monday"); undefined when it is neither. */
|
|
111
|
+
function dayOf(v) {
|
|
112
|
+
if (Number.isInteger(v) && v >= 0 && v <= 6) return v;
|
|
113
|
+
const i = DAY_NAMES.indexOf(String(v ?? "").slice(0, 3).toLowerCase());
|
|
114
|
+
return typeof v === "string" && i >= 0 ? i : undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Normalize whatever a canvas holds into complete settings (never throws; gateProblem says what was wrong). */
|
|
118
|
+
export function gateSettings(raw) {
|
|
119
|
+
const g = isObject(raw) ? raw : {};
|
|
120
|
+
const int = (v, lo, hi, d) => (Number.isInteger(v) && v >= lo && v <= hi ? v : d);
|
|
121
|
+
const days = [...new Set((Array.isArray(g.days) ? g.days : DEFAULT_GATE.days).map(dayOf).filter((d) => d !== undefined))].sort((a, b) => a - b);
|
|
122
|
+
const start = timeOfDay(g.start) ?? DEFAULT_GATE.start;
|
|
123
|
+
const end = timeOfDay(g.end, { end: true }) ?? DEFAULT_GATE.end;
|
|
124
|
+
return {
|
|
125
|
+
zone: typeof g.zone === "string" && g.zone && zoneOk(g.zone) ? g.zone : DEFAULT_GATE.zone,
|
|
126
|
+
days: days.length ? days : DEFAULT_GATE.days,
|
|
127
|
+
start: clock(minutesOf(start)),
|
|
128
|
+
end: minutesOf(end, { end: true }) === 1440 ? "24:00" : clock(minutesOf(end, { end: true })),
|
|
129
|
+
holidays: cleanHolidays(g.holidays),
|
|
130
|
+
jitterMs: int(g.jitterMs, 0, MAX_JITTER_MS, 0),
|
|
131
|
+
jitterOpen: g.jitterOpen === "spread" ? "spread" : "now",
|
|
132
|
+
seed: typeof g.seed === "string" ? g.seed.slice(0, MAX_SEED) : "",
|
|
133
|
+
atPath: typeof g.atPath === "string" ? g.atPath : "",
|
|
134
|
+
by: typeof g.by === "string" ? g.by : "",
|
|
135
|
+
limit: int(g.limit, 1, 10000, DEFAULT_GATE.limit),
|
|
136
|
+
maxWaitMs: int(g.maxWaitMs, 0, MAX_GATE_WAIT_MS, 0),
|
|
137
|
+
restart: g.restart === "ignore" ? "ignore" : "replace",
|
|
138
|
+
startInput: typeof g.startInput === "string" && g.startInput ? g.startInput : "start",
|
|
139
|
+
cancelInput: typeof g.cancelInput === "string" && g.cancelInput ? g.cancelInput : "cancel",
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Why `raw` can't be a gate's settings (as written, before gateSettings fills in), or "". */
|
|
144
|
+
export function gateProblem(raw) {
|
|
145
|
+
if (raw === undefined || raw === null) return "";
|
|
146
|
+
if (!isObject(raw)) return "gate is { zone, days, start, end, jitterMs, … }";
|
|
147
|
+
const known = Object.keys(DEFAULT_GATE);
|
|
148
|
+
const extra = Object.keys(raw).filter((k) => !known.includes(k));
|
|
149
|
+
if (extra.length) return `gate has ${known.join(", ")} (not ${extra.join(", ")})`;
|
|
150
|
+
if (raw.zone !== undefined && (typeof raw.zone !== "string" || !raw.zone || !zoneOk(raw.zone))) return 'zone is an IANA time zone name like "America/New_York" (a window needs an explicit zone)';
|
|
151
|
+
if (raw.days !== undefined) {
|
|
152
|
+
if (!Array.isArray(raw.days) || !raw.days.length || raw.days.length > 7) return 'days is a list of 1 to 7 weekdays the window opens on: 0 to 6 (Sunday is 0) or names like "mon"';
|
|
153
|
+
if (raw.days.some((d) => dayOf(d) === undefined)) return 'days are 0 to 6 (Sunday is 0) or names like "mon"';
|
|
154
|
+
}
|
|
155
|
+
if (raw.start !== undefined && timeOfDay(raw.start) === undefined) return 'start is a time of day like "09:00" or in words like "9am" (24 hours; "noon" and "midnight" work)';
|
|
156
|
+
if (raw.end !== undefined && timeOfDay(raw.end, { end: true }) === undefined) return 'end is a time of day like "17:00" or in words like "5pm" (24 hours; "24:00" or "midnight" is the end of the day)';
|
|
157
|
+
const s = gateSettings(raw);
|
|
158
|
+
if (s.start === s.end) return "start and end are the same time: a window that is open all day would need no gate (end earlier than start crosses midnight)";
|
|
159
|
+
const holidays = holidayProblem(raw.holidays);
|
|
160
|
+
if (holidays) return holidays;
|
|
161
|
+
if (raw.jitterMs !== undefined && !(Number.isInteger(raw.jitterMs) && raw.jitterMs >= 0 && raw.jitterMs <= MAX_JITTER_MS)) return `jitterMs is a whole number of milliseconds from 0 to ${MAX_JITTER_MS}`;
|
|
162
|
+
if (raw.jitterOpen !== undefined && !["now", "spread"].includes(raw.jitterOpen)) return 'jitterOpen is "now" or "spread"';
|
|
163
|
+
if (raw.seed !== undefined && (typeof raw.seed !== "string" || raw.seed.length > MAX_SEED)) return `seed is text of at most ${MAX_SEED} characters`;
|
|
164
|
+
for (const k of ["atPath", "by"]) if (raw[k] !== undefined && (typeof raw[k] !== "string" || !PATH.test(raw[k]))) return `${k} is a property path like "order.id" (no spaces)`;
|
|
165
|
+
if (raw.limit !== undefined && !(Number.isInteger(raw.limit) && raw.limit >= 1 && raw.limit <= 10000)) return "limit is a whole number from 1 to 10000";
|
|
166
|
+
if (raw.maxWaitMs !== undefined && !(Number.isInteger(raw.maxWaitMs) && raw.maxWaitMs >= 0 && raw.maxWaitMs <= MAX_GATE_WAIT_MS)) return `maxWaitMs is a whole number of milliseconds from 0 (no limit) to ${MAX_GATE_WAIT_MS}`;
|
|
167
|
+
if (raw.restart !== undefined && !["replace", "ignore"].includes(raw.restart)) return 'restart is "replace" or "ignore"';
|
|
168
|
+
for (const k of ["startInput", "cancelInput"]) if (raw[k] !== undefined && !NAME.test(raw[k])) return `${k} is a name like "start"`;
|
|
169
|
+
return "";
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The settings in words, for the pane and agents. */
|
|
173
|
+
export function describeGate(raw) {
|
|
174
|
+
const g = gateSettings(raw);
|
|
175
|
+
const days = g.days.length === 7 ? "every day" : g.days.map((d) => DAY_NAMES[d]).join(", ");
|
|
176
|
+
const crosses = minutesOf(g.end, { end: true }) <= minutesOf(g.start);
|
|
177
|
+
const closed = g.holidays.length ? `, closed on holidays (${g.holidays.join(", ")})` : "";
|
|
178
|
+
return `holds each item until ${g.start}–${g.end}${crosses ? " (past midnight)" : ""} ${g.zone} on ${days}${closed}${g.jitterMs ? `, spread over the first ${g.jitterMs >= 1000 ? `${Math.round(g.jitterMs / 100) / 10} s` : `${g.jitterMs} ms`}${g.jitterOpen === "spread" ? " (also those that arrive while it is open)" : ""}` : ""}${g.maxWaitMs ? `; an item held more than ${g.maxWaitMs >= 1000 ? `${Math.round(g.maxWaitMs / 100) / 10} s` : `${g.maxWaitMs} ms`} expires` : ""}`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── the window as instants ───────────────────────────────────────────────────
|
|
182
|
+
|
|
183
|
+
/** The first instant (ms) the zone's wall clock reads `w` (a wall time as UTC ms) or later: see the daylight saving policy above. */
|
|
184
|
+
export function firstReading(w, zone) {
|
|
185
|
+
const t = wallToInstant(w, zone);
|
|
186
|
+
if (wallMs(t, zone) === w) return t; // a time the clock reads (the first of two, when it reads it twice)
|
|
187
|
+
let lo = t - 4 * 3600 * 1000; // the clock skipped it: the instant of the jump, found between a time before it and `t`
|
|
188
|
+
let hi = t;
|
|
189
|
+
while (hi - lo > 1000) {
|
|
190
|
+
const mid = lo + Math.floor((hi - lo) / 2000) * 1000;
|
|
191
|
+
if (wallMs(mid, zone) >= w) hi = mid;
|
|
192
|
+
else lo = mid;
|
|
193
|
+
}
|
|
194
|
+
return hi;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const cache = new Map(); // a burst of items asks about the same days: the windows of a day are worked out once
|
|
198
|
+
|
|
199
|
+
/** The windows that open on the days around `at`, earliest first: [{ opensAt, closesAt }] (a window the clock skips entirely isn't one). */
|
|
200
|
+
export function windowsAround(g, at, { before = 2, after = 8 } = {}) {
|
|
201
|
+
const s = gateSettings(g);
|
|
202
|
+
const open = minutesOf(s.start);
|
|
203
|
+
const close = minutesOf(s.end, { end: true });
|
|
204
|
+
const base = Math.floor(wallMs(at, s.zone) / DAY) * DAY;
|
|
205
|
+
const memo = `${s.zone}|${s.days}|${s.start}|${s.end}|${s.holidays}|${base}|${before}|${after}`;
|
|
206
|
+
const holidays = s.holidays.length ? holidaySet(s.holidays) : undefined;
|
|
207
|
+
if (cache.has(memo)) return cache.get(memo);
|
|
208
|
+
const out = [];
|
|
209
|
+
for (let k = -before; k <= after; k++) {
|
|
210
|
+
const day = base + k * DAY;
|
|
211
|
+
if (!s.days.length || !isOpenDay(s.days, holidays, day)) continue;
|
|
212
|
+
const opensAt = firstReading(day + open * MIN, s.zone);
|
|
213
|
+
const closesAt = firstReading(day + (close > open ? 0 : DAY) + close * MIN, s.zone);
|
|
214
|
+
if (closesAt > opensAt) out.push({ opensAt, closesAt });
|
|
215
|
+
}
|
|
216
|
+
out.sort((a, b) => a.opensAt - b.opensAt);
|
|
217
|
+
if (cache.size >= 256) cache.delete(cache.keys().next().value);
|
|
218
|
+
cache.set(memo, out);
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Is the window open at instant `at`? */
|
|
223
|
+
export const gateOpen = (g, at) => windowsAround(g, at).some((w) => w.opensAt <= at && at < w.closesAt);
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The window at `at`: the one that is open ({ open: true, opensAt, closesAt }) or the next to open ({ open: false, … }); null when none
|
|
227
|
+
* opens within the next 8 days (no days: never, for settings that pass gateProblem).
|
|
228
|
+
*/
|
|
229
|
+
export function windowAt(g, at) {
|
|
230
|
+
// Holidays can close more than a week of days in a row: look further when there are any and the first look found nothing.
|
|
231
|
+
for (const after of gateSettings(g).holidays.length ? [8, 45, 400] : [8]) {
|
|
232
|
+
const list = windowsAround(g, at, { after });
|
|
233
|
+
const now = list.find((w) => w.opensAt <= at && at < w.closesAt);
|
|
234
|
+
if (now) return { open: true, ...now };
|
|
235
|
+
const next = list.find((w) => w.opensAt > at);
|
|
236
|
+
if (next) return { open: false, ...next };
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ── jitter ───────────────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
/** The jitter offset (ms) of `item` for the window opening at `opensAt`: in [0, min(jitterMs, window length − 1)], the same for the same seed. */
|
|
244
|
+
export function jitterOffset(g, { seed, item, opensAt, closesAt }) {
|
|
245
|
+
const max = Math.min(g.jitterMs, Math.max(0, closesAt - opensAt - 1));
|
|
246
|
+
return max === 0 ? 0 : Math.floor(unit(`${seed}\u0000${item}\u0000${opensAt}`) * (max + 1));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** The seed for jitter: the gate's own, or (unset) the canvas and pane it is on, so two gates don't spread alike. */
|
|
250
|
+
export const seedOf = (g, scope = "") => (g.seed !== "" ? `seed:${g.seed}` : `scope:${scope}`);
|
|
251
|
+
|
|
252
|
+
// ── when an item goes ────────────────────────────────────────────────────────
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The time an item is eligible from, if its start payload says (`atPath`: an ISO time, ms, or words such as "tomorrow 9am" or
|
|
256
|
+
* "in 3 hours", read in the gate's zone from `startedAt`: when the item started, so planning it again reads them the same), else NaN.
|
|
257
|
+
*/
|
|
258
|
+
function carried(g, start, startedAt) {
|
|
259
|
+
if (!g.atPath) return NaN;
|
|
260
|
+
let at = start;
|
|
261
|
+
for (const part of g.atPath.split(".")) {
|
|
262
|
+
if (at === null || typeof at !== "object" || part === "__proto__" || !Object.hasOwn(at, part)) return NaN;
|
|
263
|
+
at = at[part];
|
|
264
|
+
}
|
|
265
|
+
if (typeof at === "number") return at;
|
|
266
|
+
if (typeof at !== "string") return NaN;
|
|
267
|
+
const iso = Date.parse(at);
|
|
268
|
+
if (Number.isFinite(iso)) return iso;
|
|
269
|
+
const words = parseTime(at, { now: startedAt, zone: g.zone });
|
|
270
|
+
return words.ok ? words.at : NaN;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* When an item goes (ms), and why. `now`: the instant it is decided; `start`: its start payload (carrying the time that makes it
|
|
275
|
+
* eligible when `atPath` is set: the window is looked up from then, never before `now`); `item`: what jitter is for (its key,
|
|
276
|
+
* else its id); `scope`: the canvas and pane (the seed when the gate has none). `replan`: the item is already waiting and is
|
|
277
|
+
* being planned again (its gate was edited, or its timer fired after the window closed): it is looked up from when it started,
|
|
278
|
+
* so a spread it was already in keeps its place; if that moment has passed but its window is still open it goes now, and if
|
|
279
|
+
* the window is over it waits for the next one.
|
|
280
|
+
* Returns { at, opensAt, closesAt, open, offset } or null.
|
|
281
|
+
*/
|
|
282
|
+
export function releaseAt(raw, { now, start, item, scope = "", replan = false, startedAt = now }) {
|
|
283
|
+
const g = gateSettings(raw);
|
|
284
|
+
const time = carried(g, start, startedAt);
|
|
285
|
+
const seed = seedOf(g, scope);
|
|
286
|
+
const plan = (from) => {
|
|
287
|
+
const w = windowAt(g, from);
|
|
288
|
+
if (!w) return null;
|
|
289
|
+
if (w.open) {
|
|
290
|
+
// A burst that arrives while the window is open goes at once, unless the gate spreads it too (jitterOpen "spread"):
|
|
291
|
+
// an offset from the arrival, cut to what is left of the window.
|
|
292
|
+
const offset = g.jitterOpen === "spread" ? jitterOffset(g, { seed: `${seed}\u0000open`, item, opensAt: from, closesAt: w.closesAt }) : 0;
|
|
293
|
+
return { at: from + offset, opensAt: w.opensAt, closesAt: w.closesAt, open: true, offset };
|
|
294
|
+
}
|
|
295
|
+
const offset = jitterOffset(g, { seed, item, opensAt: w.opensAt, closesAt: w.closesAt });
|
|
296
|
+
return { at: w.opensAt + offset, opensAt: w.opensAt, closesAt: w.closesAt, open: false, offset };
|
|
297
|
+
};
|
|
298
|
+
if (replan) {
|
|
299
|
+
const first = plan(Math.max(startedAt, Number.isFinite(time) ? time : -Infinity));
|
|
300
|
+
if (first && first.at >= now) return first;
|
|
301
|
+
if (first && first.closesAt > now) return { ...first, at: now };
|
|
302
|
+
}
|
|
303
|
+
return plan(Math.max(now, Number.isFinite(time) ? time : -Infinity));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** The days in the next two weeks the window would open on but a holiday closes: { holidaysAhead: ["2026-11-26"] }, or nothing when there are none. */
|
|
307
|
+
function holidaysAhead(g, now) {
|
|
308
|
+
const holidays = holidaySet(g.holidays);
|
|
309
|
+
const base = Math.floor(wallMs(now, g.zone) / DAY) * DAY;
|
|
310
|
+
const days = [];
|
|
311
|
+
for (let k = 0; k < 14 && days.length < 5; k++) {
|
|
312
|
+
const day = base + k * DAY;
|
|
313
|
+
if (g.days.includes(new Date(day).getUTCDay()) && holidays.has(day)) days.push(new Date(day).toISOString().slice(0, 10));
|
|
314
|
+
}
|
|
315
|
+
return days.length ? { holidaysAhead: days } : {};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/** Where gate `raw` stands at `now`, for the pane and agents: { zone, open, opensAt?, closesAt?, nextRelease? (an ISO time), … }. */
|
|
319
|
+
export function describeWindow(raw, now) {
|
|
320
|
+
const g = gateSettings(raw);
|
|
321
|
+
const w = windowAt(g, now);
|
|
322
|
+
const iso = (t) => new Date(t).toISOString();
|
|
323
|
+
return {
|
|
324
|
+
zone: g.zone,
|
|
325
|
+
open: Boolean(w?.open),
|
|
326
|
+
...(w ? (w.open ? { closesAt: iso(w.closesAt) } : { opensAt: iso(w.opensAt) }) : {}),
|
|
327
|
+
...(g.holidays.length ? holidaysAhead(g, now) : {}),
|
|
328
|
+
...(w ? { nextRelease: iso(w.open ? now : w.opensAt) } : {}),
|
|
329
|
+
...(w && g.jitterMs && (!w.open || g.jitterOpen === "spread") ? { spreadUntil: iso((w.open ? now : w.opensAt) + Math.min(g.jitterMs, Math.max(0, w.closesAt - (w.open ? now : w.opensAt) - 1))) } : {}),
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ── a gate as a wait ─────────────────────────────────────────────────────────
|
|
334
|
+
|
|
335
|
+
/** A gate's settings as the wait machinery reads them (src/model/waits.js waitSettings): no event paths, "released" for the deadline, its own ports. */
|
|
336
|
+
export function gateAsWait(raw) {
|
|
337
|
+
const g = gateSettings(raw);
|
|
338
|
+
return { by: g.by, limit: g.limit, restart: g.restart, startInput: g.startInput, cancelInput: g.cancelInput, maxWaitMs: 0, gate: g, deadlineOutcome: OUTCOME_RELEASED, ports: GATE_OUTCOMES };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* What decides what a waiting item MEANS (a change cancels them): how items are told apart and where they are fed. The window,
|
|
343
|
+
* the jitter and the seed only decide WHEN they go: editing those plans the waiting items again instead (the trait's `replan`).
|
|
344
|
+
*/
|
|
345
|
+
export function gatePrint(raw) {
|
|
346
|
+
const g = gateSettings(raw);
|
|
347
|
+
return JSON.stringify({ by: g.by, startInput: g.startInput, cancelInput: g.cancelInput });
|
|
348
|
+
}
|