@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.
Files changed (760) hide show
  1. package/README.md +60 -2
  2. package/bin/mallory.mjs +51 -0
  3. package/package.json +51 -4
  4. package/src/a2a/client.js +511 -0
  5. package/src/a2a/demo-agent.js +396 -0
  6. package/src/a2a/hub.js +578 -0
  7. package/src/a2a/settings.js +88 -0
  8. package/src/a2a/task.js +358 -0
  9. package/src/acp/client.js +573 -0
  10. package/src/acp/demo-agent.js +332 -0
  11. package/src/acp/hub.js +632 -0
  12. package/src/acp/settings.js +78 -0
  13. package/src/actions/map.js +524 -0
  14. package/src/agent/cloud.js +77 -0
  15. package/src/agent/compact.js +84 -0
  16. package/src/agent/constants.js +39 -0
  17. package/src/agent/diff.js +101 -0
  18. package/src/agent/fork.js +159 -0
  19. package/src/agent/grounding.js +73 -0
  20. package/src/agent/guards.js +129 -0
  21. package/src/agent/local-transport.js +152 -0
  22. package/src/agent/loop.js +479 -0
  23. package/src/agent/park-store.js +77 -0
  24. package/src/agent/park.js +76 -0
  25. package/src/agent/ports.js +28 -0
  26. package/src/agent/providers.js +591 -0
  27. package/src/agent/restart.js +51 -0
  28. package/src/agent/router.js +380 -0
  29. package/src/agent/run.js +861 -0
  30. package/src/agent/tools.js +247 -0
  31. package/src/agent-library/engine.js +43 -0
  32. package/src/ai/bridge.js +155 -0
  33. package/src/ai/policy.js +131 -0
  34. package/src/aimatey/vendor.js +18 -0
  35. package/src/audio/container-duration.js +35 -0
  36. package/src/audio/instruments.js +776 -0
  37. package/src/audio/lanes.js +230 -0
  38. package/src/audio/patch.js +1410 -0
  39. package/src/audio/plan.js +276 -0
  40. package/src/audio/rack.js +1006 -0
  41. package/src/audio/sample-trim.js +293 -0
  42. package/src/audio/soundfont.js +243 -0
  43. package/src/audio/take-store.js +87 -0
  44. package/src/audio/takes.js +129 -0
  45. package/src/audio/wav.js +170 -0
  46. package/src/audio/zzfx.js +333 -0
  47. package/src/autonomy/bundle.js +207 -0
  48. package/src/autonomy/confine.js +61 -0
  49. package/src/autonomy/enforce.js +155 -0
  50. package/src/autonomy/file-kv.js +88 -0
  51. package/src/autonomy/ledger.js +203 -0
  52. package/src/autonomy/pins.js +50 -0
  53. package/src/autonomy/psl/index.js +32 -0
  54. package/src/autonomy/psl/suffixes.json +1 -0
  55. package/src/autonomy/record.js +28 -0
  56. package/src/autonomy/routines.js +107 -0
  57. package/src/autonomy/server.js +175 -0
  58. package/src/autonomy/signer-node.js +167 -0
  59. package/src/autonomy/store.js +43 -0
  60. package/src/autonomy/unattended.js +13 -0
  61. package/src/bytes/bytes.js +378 -0
  62. package/src/calc/syntax.js +125 -0
  63. package/src/calc/tex.js +28 -0
  64. package/src/calendar/vendor.js +2 -0
  65. package/src/clipboard.js +130 -0
  66. package/src/clsh/clsh.js +3417 -0
  67. package/src/codec/capnp.js +1804 -0
  68. package/src/codec/core.js +2043 -0
  69. package/src/codec/vendor/avro.js +136 -0
  70. package/src/codec/vendor/cbor.js +25 -0
  71. package/src/codec/vendor/flatbuffers.js +206 -0
  72. package/src/codec/vendor/msgpack.js +9 -0
  73. package/src/codec/vendor/protobuf.js +53 -0
  74. package/src/delegation/caps.js +60 -0
  75. package/src/delegation/config.js +32 -0
  76. package/src/device/model.js +246 -0
  77. package/src/device/recording.js +198 -0
  78. package/src/device/stream-model.js +151 -0
  79. package/src/documents/documents.js +1224 -0
  80. package/src/effects/catalog.js +63 -0
  81. package/src/effects/extras.js +133 -0
  82. package/src/effects/parse.js +339 -0
  83. package/src/embed/protocol.js +131 -0
  84. package/src/env/env.js +159 -0
  85. package/src/exact/vendor.js +45 -0
  86. package/src/example-meta.js +164 -0
  87. package/src/examples.js +94 -0
  88. package/src/export/canvas-image.js +217 -0
  89. package/src/export/expr-latex-lazy.js +8 -0
  90. package/src/export/formats.js +322 -0
  91. package/src/export/latex.js +183 -0
  92. package/src/export/pane.js +184 -0
  93. package/src/export/value.js +452 -0
  94. package/src/export/zip.js +214 -0
  95. package/src/ext/access.js +58 -0
  96. package/src/ext/btasks.js +225 -0
  97. package/src/ext/client.js +209 -0
  98. package/src/ext/tools.js +69 -0
  99. package/src/ext/view.js +105 -0
  100. package/src/ext/webmcp-tabs.js +299 -0
  101. package/src/files/archive.js +232 -0
  102. package/src/files/files.js +317 -0
  103. package/src/formats/json.js +24 -0
  104. package/src/formats/jupyter.js +188 -0
  105. package/src/formats/markdown.js +254 -0
  106. package/src/formats/n8n.js +276 -0
  107. package/src/formats/node-red.js +363 -0
  108. package/src/formats/registry.js +177 -0
  109. package/src/formats/rivet.js +259 -0
  110. package/src/formats/shared.js +98 -0
  111. package/src/formats/structure.js +182 -0
  112. package/src/formats/yaml.js +127 -0
  113. package/src/frame/frame.js +962 -0
  114. package/src/frame/vendor.js +1484 -0
  115. package/src/gate/audit.js +116 -0
  116. package/src/gate/gate.js +365 -0
  117. package/src/gate/policy.js +295 -0
  118. package/src/gate/scripted.js +110 -0
  119. package/src/gate/seams.js +32 -0
  120. package/src/gate/store.js +66 -0
  121. package/src/geometry/model.js +533 -0
  122. package/src/grant-key.js +149 -0
  123. package/src/graph/model.js +381 -0
  124. package/src/headless/a2a-push.js +123 -0
  125. package/src/headless/channels/config.js +142 -0
  126. package/src/headless/channels/connectors.js +283 -0
  127. package/src/headless/channels/index.js +257 -0
  128. package/src/headless/channels/mail.js +197 -0
  129. package/src/headless/channels/mailnet.js +223 -0
  130. package/src/headless/channels/platforms.js +194 -0
  131. package/src/headless/channels/replay.js +49 -0
  132. package/src/headless/cli.js +1397 -0
  133. package/src/headless/companion-client.js +182 -0
  134. package/src/headless/cost-cli.js +177 -0
  135. package/src/headless/deprecations-cli.js +102 -0
  136. package/src/headless/examples.js +48 -0
  137. package/src/headless/ffmpeg-exec.js +217 -0
  138. package/src/headless/gateways/config.js +213 -0
  139. package/src/headless/gateways/homeassistant.js +159 -0
  140. package/src/headless/gateways/index.js +121 -0
  141. package/src/headless/gateways/matter.js +150 -0
  142. package/src/headless/gateways/mqtt-client.js +177 -0
  143. package/src/headless/gateways/mqtt.js +70 -0
  144. package/src/headless/gateways/netway.js +226 -0
  145. package/src/headless/gateways/serverpod-worker.mjs +16 -0
  146. package/src/headless/gateways/serverpod.js +71 -0
  147. package/src/headless/gateways/util.js +27 -0
  148. package/src/headless/grant-cli.js +208 -0
  149. package/src/headless/guard.js +125 -0
  150. package/src/headless/guards.js +124 -0
  151. package/src/headless/machine-cli.js +853 -0
  152. package/src/headless/mcp-endpoint.js +287 -0
  153. package/src/headless/mcp-roots.js +38 -0
  154. package/src/headless/model-endpoint.js +88 -0
  155. package/src/headless/net.js +151 -0
  156. package/src/headless/node.js +263 -0
  157. package/src/headless/npm-tarball.js +29 -0
  158. package/src/headless/operator-page.js +112 -0
  159. package/src/headless/operator.js +242 -0
  160. package/src/headless/people.js +34 -0
  161. package/src/headless/pkg-cli.js +1103 -0
  162. package/src/headless/pkg-serve.js +138 -0
  163. package/src/headless/process-worker.js +88 -0
  164. package/src/headless/runner-remote.js +477 -0
  165. package/src/headless/sandbox-child.mjs +21 -0
  166. package/src/headless/scheduled.js +557 -0
  167. package/src/headless/serve-stream.js +97 -0
  168. package/src/headless/serve.js +2238 -0
  169. package/src/headless/short-links.js +158 -0
  170. package/src/headless/static-dirs.js +207 -0
  171. package/src/headless/trust-file.js +51 -0
  172. package/src/headless/watch.js +291 -0
  173. package/src/headless/ws-connect.js +65 -0
  174. package/src/headless/ws-connections.js +44 -0
  175. package/src/headless/ws-echo.js +150 -0
  176. package/src/headless/ws-proxy.js +354 -0
  177. package/src/headless/ws-ticket.js +48 -0
  178. package/src/hooks/config.js +50 -0
  179. package/src/hooks/engine.js +189 -0
  180. package/src/input/log.js +613 -0
  181. package/src/input/player.js +217 -0
  182. package/src/input/replay.js +209 -0
  183. package/src/jth/vendor.js +28 -0
  184. package/src/ledger/tx.js +94 -0
  185. package/src/machine/apply.js +193 -0
  186. package/src/machine/diff.js +168 -0
  187. package/src/machine/drive.js +296 -0
  188. package/src/machine/engine.js +478 -0
  189. package/src/machine/files-tool.js +76 -0
  190. package/src/machine/lint.js +139 -0
  191. package/src/machine/llmtm-trace.js +117 -0
  192. package/src/machine/llmtm.js +475 -0
  193. package/src/machine/otel.js +80 -0
  194. package/src/machine/pane-provider.js +51 -0
  195. package/src/machine/propose.js +159 -0
  196. package/src/machine/random.js +52 -0
  197. package/src/machine/risk.js +107 -0
  198. package/src/machine/session.js +1017 -0
  199. package/src/machine/shell-tool.js +45 -0
  200. package/src/machine/tape.js +349 -0
  201. package/src/machine/templates.js +104 -0
  202. package/src/machine/trace.js +664 -0
  203. package/src/machine/view.js +73 -0
  204. package/src/machine/vm-tool.js +47 -0
  205. package/src/machine/watchdog.js +46 -0
  206. package/src/mcp/app-args.js +51 -0
  207. package/src/mcp/app-run.js +56 -0
  208. package/src/mcp/apps.js +468 -0
  209. package/src/mcp/cache.js +232 -0
  210. package/src/mcp/client.js +507 -0
  211. package/src/mcp/demo-app.js +183 -0
  212. package/src/mcp/demo-server.js +602 -0
  213. package/src/mcp/elicitation.js +116 -0
  214. package/src/mcp/hub.js +1326 -0
  215. package/src/mcp/roots.js +139 -0
  216. package/src/mcp/sampling.js +105 -0
  217. package/src/mcp/settings.js +125 -0
  218. package/src/mcp/tape.js +292 -0
  219. package/src/mcp/uri-template.js +156 -0
  220. package/src/mcp/wsh-client.js +164 -0
  221. package/src/media/animated-codec.js +7 -0
  222. package/src/media/animated.js +623 -0
  223. package/src/media/compare-agent.js +70 -0
  224. package/src/media/compare-job.js +63 -0
  225. package/src/media/compare-page.js +296 -0
  226. package/src/media/compare-worker.js +14 -0
  227. package/src/media/compare.js +600 -0
  228. package/src/media/contract.js +62 -0
  229. package/src/media/decode-frame.js +57 -0
  230. package/src/media/decode-pool.js +188 -0
  231. package/src/media/ffmpeg-edit.js +344 -0
  232. package/src/media/ffmpeg-wasm-client.js +121 -0
  233. package/src/media/ffmpeg-wasm-session.js +79 -0
  234. package/src/media/ffmpeg-wasm.js +139 -0
  235. package/src/media/ffmpeg-worker.js +23 -0
  236. package/src/media/ffmpeg.js +903 -0
  237. package/src/media/helpers.js +419 -0
  238. package/src/media/keep.js +108 -0
  239. package/src/media/metadata-worker.js +16 -0
  240. package/src/media/metadata.js +2518 -0
  241. package/src/media/mime.js +102 -0
  242. package/src/media/page-decode.js +74 -0
  243. package/src/media/persist.js +114 -0
  244. package/src/media/png.js +226 -0
  245. package/src/media/sample-input.js +67 -0
  246. package/src/media/store.js +86 -0
  247. package/src/media/wav.js +109 -0
  248. package/src/midi/mappings.js +250 -0
  249. package/src/midi/message.js +125 -0
  250. package/src/model/action-hub.js +143 -0
  251. package/src/model/adapters.js +284 -0
  252. package/src/model/agent-runs.js +12 -0
  253. package/src/model/arrange.js +308 -0
  254. package/src/model/automation-clock.js +494 -0
  255. package/src/model/automation.js +653 -0
  256. package/src/model/batches.js +78 -0
  257. package/src/model/binary-view.js +195 -0
  258. package/src/model/breakpoints.js +392 -0
  259. package/src/model/calc-settings.js +65 -0
  260. package/src/model/calendar.js +254 -0
  261. package/src/model/canvas-id.js +5 -0
  262. package/src/model/canvas.js +5048 -0
  263. package/src/model/channel-names.js +29 -0
  264. package/src/model/channels.js +692 -0
  265. package/src/model/chart-clock.js +631 -0
  266. package/src/model/chart-code.js +69 -0
  267. package/src/model/codecs.js +60 -0
  268. package/src/model/companion-access.js +271 -0
  269. package/src/model/companion-pane.js +50 -0
  270. package/src/model/composite.js +324 -0
  271. package/src/model/context.js +380 -0
  272. package/src/model/controls.js +231 -0
  273. package/src/model/converter-presets.js +368 -0
  274. package/src/model/cost.js +580 -0
  275. package/src/model/curve-transform.js +122 -0
  276. package/src/model/cycles.js +176 -0
  277. package/src/model/debug-log.js +168 -0
  278. package/src/model/decision-clock.js +100 -0
  279. package/src/model/decisions.js +265 -0
  280. package/src/model/desk.js +87 -0
  281. package/src/model/device-hub.js +400 -0
  282. package/src/model/diff.js +445 -0
  283. package/src/model/emit-events.js +179 -0
  284. package/src/model/errors.js +238 -0
  285. package/src/model/event-presets.js +297 -0
  286. package/src/model/events.js +1303 -0
  287. package/src/model/explicit-setters.js +139 -0
  288. package/src/model/field-mapping.js +623 -0
  289. package/src/model/files-pane.js +263 -0
  290. package/src/model/flow-idle.js +89 -0
  291. package/src/model/foreach.js +549 -0
  292. package/src/model/frame-loop.js +71 -0
  293. package/src/model/frame-pressure.js +180 -0
  294. package/src/model/function-scaffold.js +1000 -0
  295. package/src/model/geometry-settings.js +54 -0
  296. package/src/model/goals.js +176 -0
  297. package/src/model/graph-settings.js +76 -0
  298. package/src/model/grid-widget.js +175 -0
  299. package/src/model/groups.js +332 -0
  300. package/src/model/hash.js +21 -0
  301. package/src/model/history.js +259 -0
  302. package/src/model/http-copy.js +88 -0
  303. package/src/model/http-send-companion.js +110 -0
  304. package/src/model/http-send.js +163 -0
  305. package/src/model/http-tap.js +521 -0
  306. package/src/model/http-tools.js +1138 -0
  307. package/src/model/import-lock.js +78 -0
  308. package/src/model/imports.js +258 -0
  309. package/src/model/infer-outputs.js +822 -0
  310. package/src/model/ink-connect.js +150 -0
  311. package/src/model/ink-diff.js +75 -0
  312. package/src/model/ink-gone.js +71 -0
  313. package/src/model/ink-route.js +120 -0
  314. package/src/model/ink-svg.js +206 -0
  315. package/src/model/ink.js +739 -0
  316. package/src/model/input-log-hub.js +456 -0
  317. package/src/model/input-split.js +69 -0
  318. package/src/model/json-schema-host.js +9 -0
  319. package/src/model/json-schema.js +368 -0
  320. package/src/model/jth.js +78 -0
  321. package/src/model/latex-expr.js +528 -0
  322. package/src/model/layout-history.js +120 -0
  323. package/src/model/lazy-map.js +88 -0
  324. package/src/model/ledger-pane.js +101 -0
  325. package/src/model/legacy-viaframe.js +90 -0
  326. package/src/model/lessons.js +448 -0
  327. package/src/model/links.js +981 -0
  328. package/src/model/live.js +411 -0
  329. package/src/model/math-widget.js +53 -0
  330. package/src/model/memory-settings.js +33 -0
  331. package/src/model/midi-controls.js +350 -0
  332. package/src/model/nl-time.js +408 -0
  333. package/src/model/notebook.js +137 -0
  334. package/src/model/pane-view-store.js +15 -0
  335. package/src/model/partial.js +115 -0
  336. package/src/model/pause-clock.js +53 -0
  337. package/src/model/peer-pane.js +32 -0
  338. package/src/model/persist-state.js +290 -0
  339. package/src/model/person-only.js +122 -0
  340. package/src/model/pin.js +209 -0
  341. package/src/model/plot-3d.js +213 -0
  342. package/src/model/plot-series.js +157 -0
  343. package/src/model/plot-settings.js +531 -0
  344. package/src/model/ports.js +312 -0
  345. package/src/model/presentation.js +222 -0
  346. package/src/model/preset-apply.js +316 -0
  347. package/src/model/preset-banks.js +335 -0
  348. package/src/model/preset-morph.js +263 -0
  349. package/src/model/preset-ops.js +205 -0
  350. package/src/model/preset-player.js +283 -0
  351. package/src/model/preset-states.js +172 -0
  352. package/src/model/profile-settings.js +109 -0
  353. package/src/model/promote.js +103 -0
  354. package/src/model/protected.js +10 -0
  355. package/src/model/proxy-log.js +230 -0
  356. package/src/model/proxy.js +367 -0
  357. package/src/model/quantity-widget.js +61 -0
  358. package/src/model/queue-book.js +359 -0
  359. package/src/model/quick-add.js +224 -0
  360. package/src/model/rate-limit.js +313 -0
  361. package/src/model/rate.js +95 -0
  362. package/src/model/recovery.js +216 -0
  363. package/src/model/rename-follow.js +113 -0
  364. package/src/model/repeater.js +1126 -0
  365. package/src/model/retention.js +664 -0
  366. package/src/model/route-edit.js +132 -0
  367. package/src/model/router.js +155 -0
  368. package/src/model/runaway.js +232 -0
  369. package/src/model/runlog.js +1033 -0
  370. package/src/model/runners/a2a.js +2 -0
  371. package/src/model/runners/acp.js +2 -0
  372. package/src/model/runners/actions.js +4 -0
  373. package/src/model/runners/agent.js +4 -0
  374. package/src/model/runners/audio.js +21 -0
  375. package/src/model/runners/automation.js +2 -0
  376. package/src/model/runners/calc.js +23 -0
  377. package/src/model/runners/catch.js +10 -0
  378. package/src/model/runners/codec.js +24 -0
  379. package/src/model/runners/companion-run.js +2 -0
  380. package/src/model/runners/device.js +7 -0
  381. package/src/model/runners/dom.js +13 -0
  382. package/src/model/runners/effects.js +2 -0
  383. package/src/model/runners/embed.js +11 -0
  384. package/src/model/runners/eval.js +2 -0
  385. package/src/model/runners/files.js +19 -0
  386. package/src/model/runners/geometry.js +23 -0
  387. package/src/model/runners/goals.js +18 -0
  388. package/src/model/runners/graph.js +23 -0
  389. package/src/model/runners/html.js +2 -0
  390. package/src/model/runners/http-proxy.js +185 -0
  391. package/src/model/runners/http-send.js +61 -0
  392. package/src/model/runners/http-static.js +83 -0
  393. package/src/model/runners/http-tap.js +26 -0
  394. package/src/model/runners/http.js +40 -0
  395. package/src/model/runners/import.js +2 -0
  396. package/src/model/runners/index.js +74 -0
  397. package/src/model/runners/input.js +14 -0
  398. package/src/model/runners/inputlog.js +7 -0
  399. package/src/model/runners/ledger.js +15 -0
  400. package/src/model/runners/machine.js +4 -0
  401. package/src/model/runners/mcp.js +2 -0
  402. package/src/model/runners/mcpapp.js +2 -0
  403. package/src/model/runners/media.js +18 -0
  404. package/src/model/runners/memory.js +28 -0
  405. package/src/model/runners/mesh-inspect.js +13 -0
  406. package/src/model/runners/peer.js +14 -0
  407. package/src/model/runners/plot.js +22 -0
  408. package/src/model/runners/render.js +14 -0
  409. package/src/model/runners/respond.js +2 -0
  410. package/src/model/runners/sample-soundfont.js +85 -0
  411. package/src/model/runners/sample.js +159 -0
  412. package/src/model/runners/scene.js +8 -0
  413. package/src/model/runners/score.js +24 -0
  414. package/src/model/runners/secret.js +10 -0
  415. package/src/model/runners/select.js +2 -0
  416. package/src/model/runners/shared.js +4 -0
  417. package/src/model/runners/shares.js +15 -0
  418. package/src/model/runners/shell.js +7 -0
  419. package/src/model/runners/skill.js +26 -0
  420. package/src/model/runners/state.js +2 -0
  421. package/src/model/runners/statechart.js +4 -0
  422. package/src/model/runners/subgraph.js +9 -0
  423. package/src/model/runners/tabs.js +25 -0
  424. package/src/model/runners/terminal.js +5 -0
  425. package/src/model/runners/text.js +4 -0
  426. package/src/model/runners/timer.js +7 -0
  427. package/src/model/runners/traffic.js +65 -0
  428. package/src/model/runners/trigger.js +2 -0
  429. package/src/model/runners/verdict.js +29 -0
  430. package/src/model/runners/vm.js +7 -0
  431. package/src/model/runners/wait.js +4 -0
  432. package/src/model/runners/ws-client.js +57 -0
  433. package/src/model/safe-regex.js +719 -0
  434. package/src/model/sample-settings.js +43 -0
  435. package/src/model/sample-source.js +47 -0
  436. package/src/model/saved-mapping.js +153 -0
  437. package/src/model/score-controllers.js +87 -0
  438. package/src/model/score-edit.js +399 -0
  439. package/src/model/score-instruments.js +300 -0
  440. package/src/model/score-library.js +407 -0
  441. package/src/model/score-markup.js +235 -0
  442. package/src/model/score-mix.js +248 -0
  443. package/src/model/score-patterns.js +276 -0
  444. package/src/model/score-selection.js +34 -0
  445. package/src/model/score-time.js +139 -0
  446. package/src/model/score-transforms.js +336 -0
  447. package/src/model/score-transport.js +192 -0
  448. package/src/model/selection.js +351 -0
  449. package/src/model/serial-controls.js +328 -0
  450. package/src/model/shares-pane.js +17 -0
  451. package/src/model/shell-pane.js +106 -0
  452. package/src/model/signature.js +1122 -0
  453. package/src/model/size-hints.js +106 -0
  454. package/src/model/size-ratio.js +12 -0
  455. package/src/model/skill-settings.js +23 -0
  456. package/src/model/snapping.js +466 -0
  457. package/src/model/split.js +375 -0
  458. package/src/model/spring-player.js +222 -0
  459. package/src/model/statecharts.js +1369 -0
  460. package/src/model/states-preset.js +208 -0
  461. package/src/model/static-route.js +100 -0
  462. package/src/model/step-words.js +45 -0
  463. package/src/model/subgraph.js +1042 -0
  464. package/src/model/switch.js +98 -0
  465. package/src/model/tabs-store.js +10 -0
  466. package/src/model/tensor-view.js +146 -0
  467. package/src/model/timer-clock.js +361 -0
  468. package/src/model/timers.js +422 -0
  469. package/src/model/timing.js +212 -0
  470. package/src/model/traffic-agent.js +111 -0
  471. package/src/model/traffic-store.js +20 -0
  472. package/src/model/traffic.js +665 -0
  473. package/src/model/transport.js +364 -0
  474. package/src/model/turns.js +86 -0
  475. package/src/model/types.js +425 -0
  476. package/src/model/value-path.js +138 -0
  477. package/src/model/versions.js +535 -0
  478. package/src/model/view-outputs.js +144 -0
  479. package/src/model/viewport-bookmarks.js +194 -0
  480. package/src/model/virtual-clock.js +85 -0
  481. package/src/model/vm-pane.js +258 -0
  482. package/src/model/wait-clock.js +715 -0
  483. package/src/model/wait-persist.js +248 -0
  484. package/src/model/waits.js +431 -0
  485. package/src/model/watch.js +80 -0
  486. package/src/model/webhook.js +496 -0
  487. package/src/model/when.js +48 -0
  488. package/src/model/widget-values.js +392 -0
  489. package/src/model/window-commands.js +278 -0
  490. package/src/model/windows.js +348 -0
  491. package/src/model/wire-inspect.js +343 -0
  492. package/src/model/wire-ops.js +324 -0
  493. package/src/model/wire-pipeline.js +378 -0
  494. package/src/model/wire-route.js +637 -0
  495. package/src/model/workspaces.js +122 -0
  496. package/src/model/ws-client.js +155 -0
  497. package/src/model/ws-demo.js +31 -0
  498. package/src/model/ws-frames.js +141 -0
  499. package/src/model/ws-hub.js +219 -0
  500. package/src/model/ws-served.js +13 -0
  501. package/src/model/xstate.js +374 -0
  502. package/src/narrative/narrative.js +1557 -0
  503. package/src/network/auth.js +224 -0
  504. package/src/network/csp-frame.js +197 -0
  505. package/src/network/declarative-shadow.js +27 -0
  506. package/src/network/frame-net-shim.js +962 -0
  507. package/src/network/hosts.js +157 -0
  508. package/src/network/policy.js +520 -0
  509. package/src/network/rtc-shim.js +418 -0
  510. package/src/network/secret-gate.js +78 -0
  511. package/src/network/secrets.js +261 -0
  512. package/src/network/sockets.js +287 -0
  513. package/src/network/store.js +186 -0
  514. package/src/network/streams.js +99 -0
  515. package/src/packages/asset-values.js +50 -0
  516. package/src/packages/assets.js +99 -0
  517. package/src/packages/deprecation.js +203 -0
  518. package/src/packages/fetch.js +152 -0
  519. package/src/packages/function-canvas.js +73 -0
  520. package/src/packages/module.js +120 -0
  521. package/src/packages/package.js +474 -0
  522. package/src/packages/published.js +27 -0
  523. package/src/packages/requires.js +83 -0
  524. package/src/packages/signing.js +145 -0
  525. package/src/packages/trust.js +107 -0
  526. package/src/panes/a2a.js +51 -0
  527. package/src/panes/acp.js +60 -0
  528. package/src/panes/actions.js +54 -0
  529. package/src/panes/agent.js +83 -0
  530. package/src/panes/audio.js +103 -0
  531. package/src/panes/automation.js +112 -0
  532. package/src/panes/calc.js +67 -0
  533. package/src/panes/catch.js +52 -0
  534. package/src/panes/codec.js +59 -0
  535. package/src/panes/colors.js +12 -0
  536. package/src/panes/companion.js +54 -0
  537. package/src/panes/decision.js +65 -0
  538. package/src/panes/device.js +56 -0
  539. package/src/panes/dom.js +37 -0
  540. package/src/panes/effects.js +118 -0
  541. package/src/panes/embed.js +30 -0
  542. package/src/panes/eval.js +186 -0
  543. package/src/panes/fields.js +299 -0
  544. package/src/panes/files.js +45 -0
  545. package/src/panes/gate.js +70 -0
  546. package/src/panes/geometry.js +64 -0
  547. package/src/panes/goals.js +75 -0
  548. package/src/panes/graph.js +66 -0
  549. package/src/panes/html.js +54 -0
  550. package/src/panes/http.js +82 -0
  551. package/src/panes/import.js +38 -0
  552. package/src/panes/input.js +124 -0
  553. package/src/panes/inputlog.js +66 -0
  554. package/src/panes/ledger.js +56 -0
  555. package/src/panes/machine.js +138 -0
  556. package/src/panes/mcp.js +85 -0
  557. package/src/panes/mcpapp.js +64 -0
  558. package/src/panes/media.js +38 -0
  559. package/src/panes/memory.js +46 -0
  560. package/src/panes/mesh-inspect.js +49 -0
  561. package/src/panes/note.js +38 -0
  562. package/src/panes/peer.js +44 -0
  563. package/src/panes/plot.js +196 -0
  564. package/src/panes/registry.js +475 -0
  565. package/src/panes/render.js +87 -0
  566. package/src/panes/respond.js +44 -0
  567. package/src/panes/router.js +84 -0
  568. package/src/panes/sample.js +75 -0
  569. package/src/panes/scene.js +55 -0
  570. package/src/panes/score.js +87 -0
  571. package/src/panes/secret.js +38 -0
  572. package/src/panes/select.js +67 -0
  573. package/src/panes/shader.js +166 -0
  574. package/src/panes/shared.js +33 -0
  575. package/src/panes/shares.js +43 -0
  576. package/src/panes/shell.js +47 -0
  577. package/src/panes/skill.js +44 -0
  578. package/src/panes/state.js +91 -0
  579. package/src/panes/statechart.js +63 -0
  580. package/src/panes/story.js +33 -0
  581. package/src/panes/subgraph.js +94 -0
  582. package/src/panes/tabs.js +52 -0
  583. package/src/panes/terminal.js +57 -0
  584. package/src/panes/text.js +36 -0
  585. package/src/panes/timer.js +55 -0
  586. package/src/panes/traffic.js +59 -0
  587. package/src/panes/verdict.js +62 -0
  588. package/src/panes/vm.js +46 -0
  589. package/src/panes/wait.js +61 -0
  590. package/src/panes/watch.js +57 -0
  591. package/src/panes/webhook.js +67 -0
  592. package/src/panes/ws-client.js +67 -0
  593. package/src/persist.js +281 -0
  594. package/src/plot/tex.js +19 -0
  595. package/src/plot/vendor.js +59 -0
  596. package/src/plot/view-vendor.js +5 -0
  597. package/src/privacy/levels.js +108 -0
  598. package/src/protocol/devtools.js +116 -0
  599. package/src/protocol/inspector.js +368 -0
  600. package/src/render/time.js +381 -0
  601. package/src/rooms/mesh-metrics.js +162 -0
  602. package/src/run/companion.js +355 -0
  603. package/src/run/describe.js +114 -0
  604. package/src/run/local-model.js +150 -0
  605. package/src/run/monitor.js +208 -0
  606. package/src/run/publish.js +360 -0
  607. package/src/run/respond-outcome.js +12 -0
  608. package/src/run/run.js +820 -0
  609. package/src/run/runner-pairing.js +243 -0
  610. package/src/run/values.js +122 -0
  611. package/src/runtime/compile.js +122 -0
  612. package/src/runtime/console-tag.js +64 -0
  613. package/src/runtime/frame-signals.js +126 -0
  614. package/src/runtime/iteration-push.js +19 -0
  615. package/src/runtime/keys.js +474 -0
  616. package/src/runtime/midi-input.js +170 -0
  617. package/src/runtime/person-waits.js +140 -0
  618. package/src/runtime/resource-timing.js +56 -0
  619. package/src/runtime/runtime.js +2150 -0
  620. package/src/runtime/sandbox-modules.js +163 -0
  621. package/src/runtime/spring.js +246 -0
  622. package/src/runtime/strict.js +215 -0
  623. package/src/runtime/transfer.js +75 -0
  624. package/src/runtime/tween.js +158 -0
  625. package/src/runtime/wasm-fuel.js +596 -0
  626. package/src/runtime/worker/00-prelude.js +88 -0
  627. package/src/runtime/worker/10-helpers.js +295 -0
  628. package/src/runtime/worker/20-io.js +645 -0
  629. package/src/runtime/worker/30-previews.js +210 -0
  630. package/src/runtime/worker/40-profile-lineage.js +278 -0
  631. package/src/runtime/worker/50-own-worker.js +233 -0
  632. package/src/runtime/worker/60-timers.js +172 -0
  633. package/src/runtime/worker/70-state-keyed.js +193 -0
  634. package/src/runtime/worker/80-each-compile-generators.js +619 -0
  635. package/src/runtime/worker/90-events-operators.js +655 -0
  636. package/src/runtime/worker/95-agents-batches.js +1820 -0
  637. package/src/runtime/worker/96-plot.js +47 -0
  638. package/src/runtime/worker/97-calc.js +28 -0
  639. package/src/runtime/worker/98-geometry.js +24 -0
  640. package/src/runtime/worker/99-graph.js +30 -0
  641. package/src/runtime/worker/99-shell.js +30 -0
  642. package/src/safety/config.js +57 -0
  643. package/src/safety/engine.js +324 -0
  644. package/src/scene/pixi-scene.js +806 -0
  645. package/src/scene/scene-assets.js +241 -0
  646. package/src/scene/scene-edit.js +319 -0
  647. package/src/secret/settings.js +41 -0
  648. package/src/security/multipart.js +257 -0
  649. package/src/security/redact.js +261 -0
  650. package/src/serial/broker.js +473 -0
  651. package/src/serial/config.js +185 -0
  652. package/src/serial/framers.js +389 -0
  653. package/src/serial/packets.js +64 -0
  654. package/src/shader/audio-texture.js +87 -0
  655. package/src/shader/channels.js +496 -0
  656. package/src/shader/common.js +90 -0
  657. package/src/shader/model.js +867 -0
  658. package/src/shader/passes.js +150 -0
  659. package/src/shader/shadertoy.js +198 -0
  660. package/src/shell/hub.js +287 -0
  661. package/src/sim/checkpoints.js +850 -0
  662. package/src/sim/compile.js +37 -0
  663. package/src/sim/fixed.js +377 -0
  664. package/src/sim/headless.js +205 -0
  665. package/src/sim/physics.js +399 -0
  666. package/src/smf-helper/vendor.js +2 -0
  667. package/src/sources/config.js +435 -0
  668. package/src/storage.js +153 -0
  669. package/src/table/table-geo.js +2344 -0
  670. package/src/table/table-lineage.js +808 -0
  671. package/src/table/table-quality.js +355 -0
  672. package/src/table/table-schema.js +392 -0
  673. package/src/table/table-sql.js +1650 -0
  674. package/src/table/table-stats.js +480 -0
  675. package/src/table/table.js +2102 -0
  676. package/src/tensor/tensor.js +1153 -0
  677. package/src/terminal/hub.js +715 -0
  678. package/src/terminal/screen.js +516 -0
  679. package/src/tests/capture.js +88 -0
  680. package/src/tests/compare.js +480 -0
  681. package/src/tests/dataset.js +170 -0
  682. package/src/tests/evaluate.js +286 -0
  683. package/src/tests/from-runs.js +99 -0
  684. package/src/tests/judge.js +134 -0
  685. package/src/tests/matchers.js +263 -0
  686. package/src/tests/matrix-spec.js +87 -0
  687. package/src/tests/matrix.js +397 -0
  688. package/src/tests/metrics.js +369 -0
  689. package/src/tests/no-value.js +42 -0
  690. package/src/tests/pane-check.js +45 -0
  691. package/src/tests/report.js +124 -0
  692. package/src/tests/reporters.js +140 -0
  693. package/src/tests/run.js +155 -0
  694. package/src/tilemap/tilemap.js +1122 -0
  695. package/src/units/units.js +3 -0
  696. package/src/util/bytes-text.js +21 -0
  697. package/src/util/num.js +10 -0
  698. package/src/util/regexp.js +2 -0
  699. package/src/util/text.js +38 -0
  700. package/src/verdict/engine.js +154 -0
  701. package/src/vm/guest-wsh.js +108 -0
  702. package/src/vm/hub.js +457 -0
  703. package/src/vm/image-files.js +4 -0
  704. package/src/vm/image.js +33 -0
  705. package/src/vm/image.lock.json +13 -0
  706. package/src/vm/link.js +266 -0
  707. package/src/vm/mount.js +212 -0
  708. package/src/vm/net.js +85 -0
  709. package/src/vm/pipe-ws.js +187 -0
  710. package/src/vm/v86-loader.js +11 -0
  711. package/src/webmcp/args.js +212 -0
  712. package/src/webmcp/hidden.js +218 -0
  713. package/src/webmcp/text.js +250 -0
  714. package/src/webmcp/tools/bookmark-tools.js +106 -0
  715. package/src/webmcp/tools/breakpoint-tools.js +48 -0
  716. package/src/webmcp/tools/canvases.js +208 -0
  717. package/src/webmcp/tools/context-tools.js +84 -0
  718. package/src/webmcp/tools/core.js +170 -0
  719. package/src/webmcp/tools/devices.js +41 -0
  720. package/src/webmcp/tools/edit.js +357 -0
  721. package/src/webmcp/tools/event-tools.js +145 -0
  722. package/src/webmcp/tools/image-tools.js +173 -0
  723. package/src/webmcp/tools/ink-tools.js +247 -0
  724. package/src/webmcp/tools/input-log-tools.js +163 -0
  725. package/src/webmcp/tools/live.js +166 -0
  726. package/src/webmcp/tools/machine-tools.js +74 -0
  727. package/src/webmcp/tools/media.js +161 -0
  728. package/src/webmcp/tools/midi-tools.js +32 -0
  729. package/src/webmcp/tools/preset-tools.js +184 -0
  730. package/src/webmcp/tools/quick-add-tools.js +95 -0
  731. package/src/webmcp/tools/reshape.js +152 -0
  732. package/src/webmcp/tools/run-tools.js +309 -0
  733. package/src/webmcp/tools/runs.js +101 -0
  734. package/src/webmcp/tools/scaffold-tools.js +161 -0
  735. package/src/webmcp/tools/serial-tools.js +36 -0
  736. package/src/webmcp/tools/shared.js +338 -0
  737. package/src/webmcp/tools/subgraphs.js +360 -0
  738. package/src/webmcp/tools/tests.js +170 -0
  739. package/src/webmcp/tools/traffic-tools.js +70 -0
  740. package/src/webmcp/tools/transport-tools.js +65 -0
  741. package/src/webmcp/tools/version-tools.js +126 -0
  742. package/src/webmcp/tools/versions.js +11 -0
  743. package/src/webmcp/tools/wire-tools.js +90 -0
  744. package/src/webmcp/tools/workspace-tools.js +93 -0
  745. package/src/webmcp/tools.js +1323 -0
  746. package/src/wsh/connect.js +347 -0
  747. package/src/wsh/demo-host.js +361 -0
  748. package/src/wsh/e2e.js +27 -0
  749. package/src/wsh/keys.js +154 -0
  750. package/src/wsh/known-hosts.js +39 -0
  751. package/src/wsh/private-key.js +95 -0
  752. package/src/wsh/reverse.js +34 -0
  753. package/src/wsh/settings.js +118 -0
  754. package/src/wsh/transfer.js +62 -0
  755. package/src/wsh/vendor.js +5 -0
  756. package/src/x402/challenge.js +171 -0
  757. package/src/x402/demo-server.js +127 -0
  758. package/src/x402/pay.js +125 -0
  759. package/src/x402/retry.js +95 -0
  760. package/src/x402/store.js +76 -0
@@ -0,0 +1,78 @@
1
+ // Finite-stream boundaries: the protocol, and its checks.
2
+ //
3
+ // A continuous event wire has no end, so an operator that holds values back
4
+ // (group, partitionBy, and a debounce or throttle's last value) keeps its
5
+ // partial result forever. A source that knows its stream is finite says so,
6
+ // explicitly, in the event's envelope (never in the payload, so no data value
7
+ // can be mistaken for a boundary):
8
+ //
9
+ // emit.event("row", row, { batch: "import-1" }) // this event belongs to batch "import-1"
10
+ // emit.batch.start("row", "import-1", { onError?: "discard" | "emit", onCancel?: "discard" | "emit" })
11
+ // emit.batch.end("row", "import-1") // the stream finished: flush what operators hold
12
+ // emit.batch.error("row", "import-1", reason) // it failed: discard or emit the partial batch, as declared
13
+ // emit.batch.cancel("row", "import-1", reason?) // it was stopped: likewise
14
+ //
15
+ // A batch is opened by its first tagged event or by `start` (which is what
16
+ // makes an empty batch possible), and every batch has operator state of its
17
+ // own, so interleaved batches never mix. An event with no batch key behaves as
18
+ // it always did. The policy is declared where the batch starts (default
19
+ // discard); a partial batch that is emitted carries `event.batch.partial` and
20
+ // `event.batch.reason`. Markers travel the event output's feed in order with
21
+ // the events they close, so pause, step and play treat them alike; they never
22
+ // reach a reader's queue or run its code.
23
+ //
24
+ // Pure: no DOM, no canvas. worker-runtime.js keeps a copy of the key rule (it
25
+ // can't import this file).
26
+
27
+ /** The markers, in the order a batch meets them. */
28
+ export const MARKERS = ["start", "end", "error", "cancel"];
29
+ /** What an error or a cancellation does with the partial batch. */
30
+ export const POLICIES = ["discard", "emit"];
31
+ /** The longest batch key. */
32
+ export const MAX_BATCH_KEY = 64;
33
+ /** How many batches one wire may have open at once. */
34
+ export const MAX_OPEN_BATCHES = 256;
35
+ /** The longest reason an error or a cancellation gives. */
36
+ export const MAX_REASON = 500;
37
+
38
+ /** Why `key` can't be a batch key, or "". */
39
+ export function batchKeyProblem(key) {
40
+ if (typeof key !== "string" || !key) return "a batch key is a non-empty string (the same text on every event and marker of one batch)";
41
+ if (key.length > MAX_BATCH_KEY) return `a batch key is at most ${MAX_BATCH_KEY} characters`;
42
+ return "";
43
+ }
44
+
45
+ /**
46
+ * Why `marker` ({ kind, batch, reason?, onError?, onCancel? }) isn't one, or "".
47
+ * Only a start declares a policy.
48
+ */
49
+ export function markerProblem(marker) {
50
+ if (!marker || typeof marker !== "object") return "a batch marker is { kind, batch }";
51
+ if (!MARKERS.includes(marker.kind)) return `a batch marker is ${MARKERS.slice(0, -1).join(", ")} or ${MARKERS.at(-1)}, not "${marker.kind}"`;
52
+ const key = batchKeyProblem(marker.batch);
53
+ if (key) return key;
54
+ for (const policy of ["onError", "onCancel"]) {
55
+ if (marker[policy] === undefined) continue;
56
+ if (marker.kind !== "start") return `${policy} is declared where a batch starts: only a start marker takes it`;
57
+ if (!POLICIES.includes(marker[policy])) return `${policy} is ${POLICIES.join(" or ")}, not "${marker[policy]}"`;
58
+ }
59
+ if (marker.reason !== undefined && (typeof marker.reason !== "string" || marker.reason.length > MAX_REASON)) return `a reason is text of at most ${MAX_REASON} characters`;
60
+ return "";
61
+ }
62
+
63
+ /** A marker as the model keeps it: only its own fields, the policy defaulted (discard). */
64
+ export function cleanMarker(marker) {
65
+ const out = { kind: marker.kind, batch: marker.batch };
66
+ if (marker.reason !== undefined) out.reason = String(marker.reason);
67
+ if (marker.kind === "start") {
68
+ out.onError = marker.onError ?? "discard";
69
+ out.onCancel = marker.onCancel ?? "discard";
70
+ }
71
+ return out;
72
+ }
73
+
74
+ /** One marker in words: `end of batch "a"`. */
75
+ export function describeMarker(marker) {
76
+ const what = { start: "start of", end: "end of", error: "error in", cancel: "cancellation of" }[marker?.kind] ?? "marker for";
77
+ return `${what} batch "${marker?.batch}"${marker?.reason ? ` (${marker.reason})` : ""}`;
78
+ }
@@ -0,0 +1,195 @@
1
+ // A bounded hex + ASCII view of a binary value (an ArrayBuffer, a typed array,
2
+ // a DataView): offsets, the length, and the kind of data its first bytes say it
3
+ // is (magic bytes). The sandbox Worker sends the first HEAD_BYTES of such a
4
+ // value as `head` (hex text) and its length as `bytes` on the value's preview
5
+ // (worker-runtime.js, which holds its own copy of HEAD_BYTES: it is evaluated
6
+ // as text and can't import this file; test/binary-view.test.mjs keeps them the
7
+ // same); the page turns that into rows here. Pure: no DOM, no Node built-ins.
8
+
9
+ import { scan, scanProto, DEFAULT_LIMITS } from "../codec/core.js";
10
+
11
+ /** How many bytes of a value the page is given (and shows). */
12
+ export const HEAD_BYTES = 512;
13
+ /** Bytes per row of the dump. */
14
+ export const ROW_BYTES = 16;
15
+
16
+ const ascii = (bytes, at, text) => [...text].every((c, i) => bytes[at + i] === c.charCodeAt(0));
17
+ const at = (bytes, ...values) => values.every((v, i) => bytes[i] === v);
18
+
19
+ /**
20
+ * Magic-byte signatures, most specific first. `test(bytes)` is given at least
21
+ * the first 12 bytes where the value has them (shorter signatures work on
22
+ * shorter values).
23
+ */
24
+ const SIGNATURES = [
25
+ { type: "PNG image", mime: "image/png", test: (b) => at(b, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a) },
26
+ { type: "JPEG image", mime: "image/jpeg", test: (b) => at(b, 0xff, 0xd8, 0xff) },
27
+ { type: "GIF image", mime: "image/gif", test: (b) => ascii(b, 0, "GIF87a") || ascii(b, 0, "GIF89a") },
28
+ { type: "WebP image", mime: "image/webp", test: (b) => ascii(b, 0, "RIFF") && ascii(b, 8, "WEBP") },
29
+ { type: "WAV audio", mime: "audio/wav", test: (b) => ascii(b, 0, "RIFF") && ascii(b, 8, "WAVE") },
30
+ { type: "AVI video", mime: "video/x-msvideo", test: (b) => ascii(b, 0, "RIFF") && ascii(b, 8, "AVI ") },
31
+ { type: "BMP image", mime: "image/bmp", test: (b) => ascii(b, 0, "BM") && b.length >= 14 },
32
+ { type: "TIFF image", mime: "image/tiff", test: (b) => at(b, 0x49, 0x49, 0x2a, 0x00) || at(b, 0x4d, 0x4d, 0x00, 0x2a) },
33
+ { type: "ICO icon", mime: "image/x-icon", test: (b) => at(b, 0x00, 0x00, 0x01, 0x00) },
34
+ { type: "CBOR data", mime: "application/cbor", test: (b) => at(b, 0xd9, 0xd9, 0xf7) },
35
+ { type: "gzip data", mime: "application/gzip", test: (b) => at(b, 0x1f, 0x8b) },
36
+ { type: "bzip2 data", mime: "application/x-bzip2", test: (b) => ascii(b, 0, "BZh") },
37
+ { type: "xz data", mime: "application/x-xz", test: (b) => at(b, 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00) },
38
+ { type: "Zstandard data", mime: "application/zstd", test: (b) => at(b, 0x28, 0xb5, 0x2f, 0xfd) },
39
+ { type: "7-Zip archive", mime: "application/x-7z-compressed", test: (b) => at(b, 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c) },
40
+ { type: "ZIP archive", mime: "application/zip", test: (b) => at(b, 0x50, 0x4b, 0x03, 0x04) || at(b, 0x50, 0x4b, 0x05, 0x06) },
41
+ { type: "PDF document", mime: "application/pdf", test: (b) => ascii(b, 0, "%PDF-") },
42
+ { type: "WebAssembly module", mime: "application/wasm", test: (b) => at(b, 0x00, 0x61, 0x73, 0x6d) },
43
+ { type: "SQLite database", mime: "application/vnd.sqlite3", test: (b) => ascii(b, 0, "SQLite format 3") },
44
+ { type: "FLAC audio", mime: "audio/flac", test: (b) => ascii(b, 0, "fLaC") },
45
+ { type: "Ogg media", mime: "audio/ogg", test: (b) => ascii(b, 0, "OggS") },
46
+ { type: "MIDI file", mime: "audio/midi", test: (b) => ascii(b, 0, "MThd") },
47
+ { type: "MP3 audio", mime: "audio/mpeg", test: (b) => ascii(b, 0, "ID3") || (b[0] === 0xff && (b[1] & 0xe0) === 0xe0 && (b[1] & 0x06) !== 0) },
48
+ { type: "MP4 media", mime: "video/mp4", test: (b) => ascii(b, 4, "ftyp") },
49
+ { type: "WebM / Matroska media", mime: "video/webm", test: (b) => at(b, 0x1a, 0x45, 0xdf, 0xa3) },
50
+ { type: "ELF executable", mime: "application/x-elf", test: (b) => at(b, 0x7f, 0x45, 0x4c, 0x46) },
51
+ { type: "Mach-O executable", mime: "application/x-mach-binary", test: (b) => at(b, 0xcf, 0xfa, 0xed, 0xfe) || at(b, 0xce, 0xfa, 0xed, 0xfe) || at(b, 0xfe, 0xed, 0xfa, 0xcf) || at(b, 0xca, 0xfe, 0xba, 0xbe) },
52
+ { type: "Windows executable", mime: "application/vnd.microsoft.portable-executable", test: (b) => ascii(b, 0, "MZ") },
53
+ { type: "TrueType font", mime: "font/ttf", test: (b) => at(b, 0x00, 0x01, 0x00, 0x00) },
54
+ { type: "WOFF font", mime: "font/woff", test: (b) => ascii(b, 0, "wOFF") },
55
+ { type: "WOFF2 font", mime: "font/woff2", test: (b) => ascii(b, 0, "wOF2") },
56
+ ];
57
+
58
+ /**
59
+ * What the first bytes say a value is: `{ type, mime }`, or null when no
60
+ * signature matches. Text that begins with `{`/`[`/`<` is not guessed at.
61
+ * @param {ArrayLike<number>} bytes
62
+ */
63
+ export function sniff(bytes) {
64
+ for (const sig of SIGNATURES) {
65
+ try {
66
+ if (sig.test(bytes)) return { type: sig.type, mime: sig.mime };
67
+ } catch {}
68
+ }
69
+ return null;
70
+ }
71
+
72
+ const GUESS_LABELS = { msgpack: "MessagePack", cbor: "CBOR", both: "MessagePack or CBOR", protobuf: "Protocol Buffers" };
73
+ const GUESS_LIMITS = { ...DEFAULT_LIMITS, items: 10000, ms: 50 };
74
+ const isContainer = { msgpack: (t) => (t >= 0x80 && t <= 0x9f) || (t >= 0xdc && t <= 0xdf), cbor: (t) => t >> 5 === 4 || t >> 5 === 5 };
75
+ const parses = (format, b) => {
76
+ try {
77
+ scan(format, b, GUESS_LIMITS);
78
+ return true;
79
+ } catch {
80
+ return false;
81
+ }
82
+ };
83
+
84
+ /**
85
+ * A guess at a whole value's format by its structure, for bytes with no signature: `{ format, label }` or null.
86
+ * MessagePack and CBOR count only when the bytes are exactly one map or list (a lone number parses as almost anything);
87
+ * Protocol Buffers when every byte is a well-formed field whose numbers are small, and the bytes aren't mostly text.
88
+ * Only ever a hint ("looks like"): the codec pane is what decodes.
89
+ * @param {Uint8Array} b the whole value
90
+ */
91
+ export function guessFormat(b) {
92
+ if (!b || b.length < 3) return null;
93
+ if (b.every((x) => x === 0)) return null;
94
+ const printable = b.reduce((n, x) => n + ((x >= 0x20 && x < 0x7f) || x === 9 || x === 10 || x === 13 ? 1 : 0), 0);
95
+ const mp = isContainer.msgpack(b[0]) && parses("msgpack", b);
96
+ const cb = isContainer.cbor(b[0]) && parses("cbor", b);
97
+ if (mp || cb) {
98
+ const format = mp && cb ? "both" : mp ? "msgpack" : "cbor";
99
+ return { format, label: GUESS_LABELS[format] };
100
+ }
101
+ if (printable / b.length > 0.85) return null;
102
+ if (b[0] >> 3 < 1 || b[0] >> 3 > 15) return null; // a first field of 1 to 15 (one byte of tag), as nearly every message has
103
+ try {
104
+ scanProto(null, b, GUESS_LIMITS);
105
+ } catch {
106
+ return null;
107
+ }
108
+ return { format: "protobuf", label: GUESS_LABELS.protobuf };
109
+ }
110
+
111
+ const hex2 = (n) => n.toString(16).padStart(2, "0");
112
+
113
+ /** Bytes as lower-case hex text, two digits each. */
114
+ export function toHex(bytes) {
115
+ let out = "";
116
+ for (let i = 0; i < bytes.length; i++) out += hex2(bytes[i]);
117
+ return out;
118
+ }
119
+
120
+ /** The bytes of a hex text; null when it isn't one (odd length, a non-hex digit). */
121
+ export function fromHex(text) {
122
+ if (typeof text !== "string" || text.length % 2 || /[^0-9a-f]/i.test(text)) return null;
123
+ const out = new Uint8Array(text.length / 2);
124
+ for (let i = 0; i < out.length; i++) out[i] = parseInt(text.slice(i * 2, i * 2 + 2), 16);
125
+ return out;
126
+ }
127
+
128
+ /**
129
+ * The dump of `bytes` as rows: `{ offset, hex, ascii }`, where `offset` is 8 hex
130
+ * digits, `hex` the bytes in two groups of eight (a short last row is padded so
131
+ * the columns line up) and `ascii` the printable ones (others as a dot).
132
+ * @param {Uint8Array} bytes
133
+ * @param {{ width?: number }} [options]
134
+ */
135
+ export function hexDump(bytes, { width = ROW_BYTES } = {}) {
136
+ const rows = [];
137
+ const half = Math.ceil(width / 2);
138
+ for (let start = 0; start < bytes.length; start += width) {
139
+ const slice = bytes.subarray(start, start + width);
140
+ const cells = Array.from({ length: width }, (_, i) => (i < slice.length ? hex2(slice[i]) : " "));
141
+ const text = Array.from(slice, (b) => (b >= 0x20 && b < 0x7f ? String.fromCharCode(b) : ".")).join("");
142
+ rows.push({ offset: start.toString(16).padStart(8, "0"), hex: `${cells.slice(0, half).join(" ")} ${cells.slice(half).join(" ")}`, ascii: text });
143
+ }
144
+ return rows;
145
+ }
146
+
147
+ /** One row as the text a dump tool prints: `00000000 89 50 … |.PNG…|`. */
148
+ export const rowText = (row) => `${row.offset} ${row.hex} |${row.ascii}|`;
149
+
150
+ const BINARY_TYPES = new Set(["arraybuffer", "dataview", "typedarray"]);
151
+
152
+ /** The bytes a preview carries: mallory's `head` (hex text), or @johnhenry/inspectable's `bytes` (numbers 0-255); null when it carries none. */
153
+ function headOf(preview) {
154
+ if (typeof preview.head === "string") return fromHex(preview.head);
155
+ const list = preview.bytes;
156
+ if (!BINARY_TYPES.has(preview.type) || !Array.isArray(list) || !list.every((b) => Number.isInteger(b) && b >= 0 && b <= 255)) return null;
157
+ return Uint8Array.from(list);
158
+ }
159
+
160
+ /**
161
+ * What the page shows for a preview that carries bytes: the kind
162
+ * (`Uint8Array`, `ArrayBuffer`…), the length in bytes (and in elements for a
163
+ * typed array), the shown bytes, whether they are all of them, the detected
164
+ * type and the rows. Null for a preview without bytes. The bytes are the
165
+ * sandbox's `head` and `bytes` (a length) where it put them (worker-runtime.js
166
+ * withBytes: the value and what it lists), and otherwise inspectable's own
167
+ * (`bytes` as numbers, `byteLength`), which every binary node has: a buffer in
168
+ * a Map, or in a part expanded later.
169
+ * @param {{ head?: string, bytes?: number | number[], byteLength?: number, name?: string, type?: string, size?: number }} preview
170
+ */
171
+ export function describeBinary(preview) {
172
+ if (!preview || typeof preview !== "object") return null;
173
+ const head = headOf(preview);
174
+ if (!head) return null;
175
+ const length = Number.isFinite(preview.bytes) ? preview.bytes : Number.isFinite(preview.byteLength) ? preview.byteLength : head.length;
176
+ const kind = preview.name || (preview.type === "arraybuffer" ? "ArrayBuffer" : preview.type === "dataview" ? "DataView" : "Uint8Array");
177
+ const elements = preview.type === "typedarray" && Number.isFinite(preview.size) ? preview.size : undefined;
178
+ const truncated = head.length < length;
179
+ const detected = sniff(head);
180
+ return { kind, length, elements, head, shown: head.length, truncated, detected, guess: detected || truncated ? null : guessFormat(head), rows: hexDump(head) };
181
+ }
182
+
183
+ const grouped = (n) => String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
184
+
185
+ /** The line above a dump: `Uint8Array(1,024) · 1,024 bytes · PNG image (image/png)`. */
186
+ export function summaryLine(info) {
187
+ const bytes = `${grouped(info.length)} byte${info.length === 1 ? "" : "s"}`;
188
+ const name = info.elements !== undefined ? `${info.kind}(${grouped(info.elements)})` : info.kind;
189
+ return [name, bytes, info.detected ? `${info.detected.type} (${info.detected.mime})` : "no known signature", ...(info.guess ? [`looks like ${info.guess.label} (a codec pane decodes it)`] : [])].join(" · ");
190
+ }
191
+
192
+ /** The whole dump as text (what "Copy" puts on the clipboard): the summary, the rows, and a note when it is cut short. */
193
+ export function dumpText(info) {
194
+ return [summaryLine(info), ...info.rows.map(rowText), ...(info.truncated ? [`… ${grouped(info.length - info.shown)} more bytes not shown`] : [])].join("\n");
195
+ }
@@ -0,0 +1,392 @@
1
+ // Graph breakpoints: stop a pane at the scheduler boundary, before it
2
+ // evaluates, and look at what it would receive.
3
+ //
4
+ // mallory already has: the run log and replay (what already happened), the
5
+ // live transport (time: pause/step the sources that change by themselves,
6
+ // src/model/transport.js) and partial runs / manual mode (propagation: which
7
+ // panes rerun, src/model/partial.js). None stops the graph in the middle of a
8
+ // run. A breakpoint does: when pane P is about to run (its inputs are ready,
9
+ // its gates passed, its code or effect not yet started), the run waits here,
10
+ // on the page, and P shows "stopped" with the inputs it would receive, why it
11
+ // became runnable, and three ways on:
12
+ //
13
+ // continue run it, and go on until the next stop
14
+ // step run it, and stop before the next pane that runs (any pane)
15
+ // step over run it, and stop before the next pane that runs in the same canvas (the subgraph pane or repeater
16
+ // instance it sits in): the panes inside a subgraph pane it started run through
17
+ // skip don't run it: it skips with a reason, so what reads it skips too
18
+ //
19
+ // A stop is a held dataflow run (the pane's state stays "running"), so
20
+ // everything else the scheduler does carries over: a newer run (an edit, a
21
+ // changed input, a sandbox restart, deleting the pane) aborts the run's signal
22
+ // and the stop is cancelled; events for a reader queue behind it up to their
23
+ // queueLimit; manual mode decides whether a pane runs at all, so a pane that
24
+ // doesn't run doesn't stop; and each queued run stops on its own. The stop is
25
+ // before the call into the Worker (or the pane's own Worker, or a frame), so
26
+ // nothing in the Worker is paused: this is not JavaScript statement debugging
27
+ // (a loop that already started runs to its end, or its timeout), and a value a
28
+ // sandbox restart puts back is not an evaluation, so it never stops.
29
+ //
30
+ // What this is NOT: a permission. Continuing runs the stopped run once: it
31
+ // grants no network host, no on-device AI, no store, no device; a prompt the
32
+ // run raises is the person's, as ever. Skipping and cancelling never replay
33
+ // an effect that already happened.
34
+ //
35
+ // Where the choices live: breakpoints are the person's debugger settings for
36
+ // this browser session (src/ui/breakpoint-ui.js keeps them in the tab's session
37
+ // storage), never in the canvas, its file, its link, or the run log. A canvas
38
+ // from a link cannot carry any. Headless runs (`mallory run`, `mallory serve`,
39
+ // the tests' runs) have no one to resume a stop, so there `available` stays
40
+ // false: setting one is refused with a reason, and a run never waits.
41
+ //
42
+ // Inputs shown at a stop respect run retention (src/model/retention.js):
43
+ // the pane's and its sources' policies limit the previews exactly as they limit
44
+ // the run log's, so a pane that must not keep its inputs does not show them
45
+ // here either. Pure: it runs under node --test.
46
+ import { canvasFacts, retentionOf } from "./runlog.js";
47
+ import { applyToStep, combine } from "./retention.js";
48
+ import { previewToText } from "../webmcp/text.js";
49
+ import { showKey } from "../runtime/keys.js";
50
+
51
+ /** Where pane `id` of `canvas` is: `<subgraph>/…<id>`; a repeater's instances share one key (`<repeater>/<star>/<id>`, a star for the instance), so one breakpoint reaches every instance. */
52
+ export function breakpointKey(canvas, id) {
53
+ const segs = [];
54
+ for (let c = canvas; c?.parent; c = c.parent) segs.unshift(c.instanceOf ? `${c.instanceOf.pane}/*/` : `${c.subgraphId}/`);
55
+ return `${segs.join("")}${id}`;
56
+ }
57
+
58
+ /** The instance of a repeater `canvas` is (a key or `#index`), or undefined. */
59
+ function instanceLabel(canvas) {
60
+ const inst = canvas.parent?.repeaters?.get(canvas.instanceOf?.pane)?.instances?.get(canvas.instanceOf?.seg);
61
+ if (!inst) return undefined;
62
+ return inst.key == null ? `#${inst.index}` : showKey(inst.key);
63
+ }
64
+
65
+ /** The subgraph panes and repeater instances around `canvas`, outermost first: `["list", "list › \"a\"", …]` as readable steps. */
66
+ export function pathOf(canvas) {
67
+ const out = [];
68
+ for (let c = canvas; c?.parent; c = c.parent) {
69
+ const outer = c.parent;
70
+ const name = outer.panes.get(c.subgraphId)?.name || c.subgraphId;
71
+ out.unshift(c.instanceOf ? `${name}[${instanceLabel(c) ?? c.instanceOf.seg}]` : name);
72
+ }
73
+ return out;
74
+ }
75
+
76
+ /**
77
+ * The inputs pane `id` would receive, as previews, limited by run retention the way the run log's are:
78
+ * `[{ name, from, state, value?, withheld? }]`. `withheld`: "summary" or "redacted" (a redacted
79
+ * preview is still shown, with its redacted parts replaced).
80
+ */
81
+ export function pendingInputs(canvas, id) {
82
+ const pane = canvas.panes.get(id);
83
+ if (!pane) return [];
84
+ const facts = canvasFacts(canvas).start(id);
85
+ const step = { pane: id, inputs: facts.inputs ?? [] };
86
+ const secrets = new Set();
87
+ for (const input of step.inputs) {
88
+ if (!input.preview || input.setter !== undefined) continue;
89
+ // The source's policy limits what of its output a reader may keep, then the reader's own (src/model/runlog.js #retainInputs).
90
+ const source = String(input.source).split("#")[0];
91
+ const policy = combine(retentionOf(canvas, source), input.inner ? retentionOf(canvas, String(input.inner).split("#")[0]) : undefined);
92
+ if (policy) applyToStep({ inputs: [input] }, policy, { secrets });
93
+ }
94
+ applyToStep(step, retentionOf(canvas, id), { secrets });
95
+ return step.inputs.map((input, i) => {
96
+ const wire = pane.inputs?.[i];
97
+ const from = canvas.panes.get(String(input.source).split("#")[0])?.name || input.source;
98
+ if (input.setter !== undefined) return { name: input.name, from, state: "setter", value: "(setter)" };
99
+ const state = wire ? canvas.inputState(wire).status : "idle";
100
+ const withheld = input.retention; // "summary" | "redacted"
101
+ if (withheld === "summary") return { name: input.name, from, state, withheld };
102
+ if (!input.preview) return { name: input.name, from, state };
103
+ return { name: input.name, from, state, value: previewToText(input.preview, { maxLength: 160 }), ...(withheld ? { withheld } : {}) };
104
+ });
105
+ }
106
+
107
+ /** Why pane `id` became runnable, in words: the run's cause, the event that triggered it, an edit. */
108
+ export function whyRunnable(canvas, id, runId) {
109
+ const out = [];
110
+ const log = canvas.runLog ?? canvas.root?.runLog;
111
+ const run = [...(log?.runs ?? [])].reverse().find((r) => r.status === "running" && !r.mark);
112
+ if (run?.cause) out.push(run.cause);
113
+ const event = canvas.events?.stepFacts?.(id, runId)?.event;
114
+ if (event) out.push(`an event${event.input ? ` on ${event.input}` : ""} arrived`);
115
+ if (canvas.edited?.has(id)) out.push("its code or settings were edited");
116
+ return out;
117
+ }
118
+
119
+ export class Breakpoints extends EventTarget {
120
+ /** @param {object} root the root Canvas */
121
+ constructor(root) {
122
+ super();
123
+ this.root = root;
124
+ this.available = false; // a page with someone to resume it turns this on (enable); headless runs never do
125
+ this.disabled = false; // every breakpoint off at once (they keep their place)
126
+ this.marks = new Map(); // key -> { enabled }
127
+ this.stops = new Map(); // stop number -> the stopped run
128
+ this.stepping = false; // the next pane to run stops (in stepScope, when there is one)
129
+ this.stepScope = null; // a step over: the canvas whose next pane stops; panes of other canvases run through
130
+ this.seq = 0;
131
+ this.armedStep = 0; // which step() armed `stepping` (a later step makes an earlier idle look stale)
132
+ }
133
+
134
+ /** The page turns breakpoints on: someone is there to continue a stop. */
135
+ enable() {
136
+ this.available = true;
137
+ this.#changed("available");
138
+ }
139
+
140
+ get armed() {
141
+ return this.available && !this.disabled;
142
+ }
143
+
144
+ /** Is there a breakpoint on pane `id` of `canvas` (enabled or not)? */
145
+ has(canvas, id) {
146
+ return this.marks.has(breakpointKey(canvas, id));
147
+ }
148
+
149
+ /** Is the breakpoint on pane `id` of `canvas` set and enabled? */
150
+ isOn(canvas, id) {
151
+ return this.marks.get(breakpointKey(canvas, id))?.enabled === true;
152
+ }
153
+
154
+ /**
155
+ * Set (`on`), clear (false) a breakpoint on pane `id` of `canvas`. Returns `{ ok, reason? }`: refused
156
+ * where nothing can resume a stop (a headless run) or for a pane that isn't in the dataflow.
157
+ */
158
+ set(canvas, id, on = true, { enabled = true } = {}) {
159
+ if (!this.available) return { ok: false, reason: "breakpoints are a browser debugger setting: headless runs never stop, so there is nobody to resume one" };
160
+ if (!canvas?.attached?.has(id) || !canvas.flow.has(id)) return { ok: false, reason: `${canvas?.panes.get(id)?.name || id} doesn't run, so it has nothing to stop before` };
161
+ const key = breakpointKey(canvas, id);
162
+ if (on) this.marks.set(key, { enabled });
163
+ else this.marks.delete(key);
164
+ this.#changed("marks");
165
+ return { ok: true };
166
+ }
167
+
168
+ /** Set the breakpoint when there is none, clear it when there is. */
169
+ toggle(canvas, id) {
170
+ return this.set(canvas, id, !this.has(canvas, id));
171
+ }
172
+
173
+ /** Enable or disable one breakpoint without losing its place. */
174
+ setEnabled(canvas, id, on) {
175
+ const mark = this.marks.get(breakpointKey(canvas, id));
176
+ if (!mark) return false;
177
+ mark.enabled = Boolean(on);
178
+ this.#changed("marks");
179
+ return true;
180
+ }
181
+
182
+ /** Turn every breakpoint off or on again at once. Turning off lets the stopped runs continue. */
183
+ setDisabled(on) {
184
+ this.disabled = Boolean(on);
185
+ if (this.disabled) this.continueAll();
186
+ this.#changed("marks");
187
+ }
188
+
189
+ /** Put back breakpoints this browser kept: `[{ key, enabled }]` (no stops: those were runs of a page that is gone). */
190
+ restore(list = [], { disabled = false } = {}) {
191
+ this.marks = new Map(list.filter((m) => m && typeof m.key === "string").map((m) => [m.key, { enabled: m.enabled !== false }]));
192
+ this.disabled = Boolean(disabled);
193
+ this.#changed("marks");
194
+ }
195
+
196
+ /** What to keep: `{ marks: [{ key, enabled }], disabled }`. */
197
+ snapshot() {
198
+ return { marks: [...this.marks].map(([key, m]) => ({ key, enabled: m.enabled })), disabled: this.disabled };
199
+ }
200
+
201
+ /** A deleted pane's breakpoint goes with it (and those inside it). */
202
+ forgetPane(canvas, id) {
203
+ const key = breakpointKey(canvas, id);
204
+ let any = false;
205
+ for (const k of [...this.marks.keys()]) if (k === key || k.startsWith(`${key}/`)) any = this.marks.delete(k) || any;
206
+ if (any) this.#changed("marks");
207
+ }
208
+
209
+ /** Drop every breakpoint. */
210
+ clear() {
211
+ if (!this.marks.size) return;
212
+ this.marks.clear();
213
+ this.#changed("marks");
214
+ }
215
+
216
+ // ── stopping ─────────────────────────────────────────────────────────────
217
+
218
+ /**
219
+ * Called by Canvas#run when pane `id` of `canvas` is about to evaluate (inputs ready, gates passed):
220
+ * `null` (the usual answer, and no await for the caller) unless a breakpoint (or a step) stops it. A stop
221
+ * is a promise that waits for `continue` ("run"), `skip` ("skip") or the run being replaced ("cancelled":
222
+ * its signal aborted, the pane deleted or the canvas closed).
223
+ * @returns {Promise<"run" | "skip" | "cancelled"> | null}
224
+ */
225
+ hold(canvas, id, ctx) {
226
+ if (!this.available || (!this.stepping && (this.disabled || !this.marks.size))) return null; // the common case: cheap and synchronous
227
+ if (canvas.disposed || ctx.signal?.aborted) return Promise.resolve("cancelled");
228
+ const marked = this.armed && this.marks.get(breakpointKey(canvas, id))?.enabled === true;
229
+ const stepHere = this.stepping && (!this.stepScope || this.stepScope === canvas);
230
+ if (!marked && !stepHere) return null;
231
+ const why = marked ? "breakpoint" : "step";
232
+ if (stepHere) this.#disarm(); // a step stops once
233
+ return new Promise((resolve) => {
234
+ const number = ++this.seq;
235
+ const stop = { number, canvas, id, key: breakpointKey(canvas, id), runId: ctx.runId, why, at: Date.now() };
236
+ const finish = (answer) => {
237
+ if (!this.stops.delete(number)) return;
238
+ ctx.signal?.removeEventListener("abort", onAbort);
239
+ resolve(answer);
240
+ this.#changed("stops");
241
+ };
242
+ const onAbort = () => finish("cancelled");
243
+ stop.finish = finish;
244
+ ctx.signal?.addEventListener("abort", onAbort, { once: true });
245
+ this.stops.set(number, stop);
246
+ this.#changed("stops");
247
+ });
248
+ }
249
+
250
+ /**
251
+ * Resolve (true) once `test(this)` holds, checked now and whenever the stops or breakpoints change (never a timer,
252
+ * ); false when `signal` aborts first. A stop inside a subgraph pane or a repeater's instance changes nothing
253
+ * in the outer canvas's dataflow, so a wait for "something stopped" cannot be built on `flow.until`.
254
+ */
255
+ until(test = () => this.stops.size > 0, { signal } = {}) {
256
+ return new Promise((resolve) => {
257
+ if (test(this)) return resolve(true);
258
+ const done = (value) => {
259
+ this.removeEventListener("change", check);
260
+ signal?.removeEventListener("abort", stop);
261
+ resolve(value);
262
+ };
263
+ const check = () => test(this) && done(true);
264
+ const stop = () => done(false);
265
+ this.addEventListener("change", check);
266
+ signal?.addEventListener("abort", stop, { once: true });
267
+ });
268
+ }
269
+
270
+ /** The stop of pane `id` of `canvas`, or undefined. */
271
+ stopOf(canvas, id) {
272
+ for (const stop of this.stops.values()) if (stop.canvas === canvas && stop.id === id) return stop;
273
+ return undefined;
274
+ }
275
+
276
+ /** Is pane `id` of `canvas` stopped now? */
277
+ isStopped(canvas, id) {
278
+ return Boolean(this.stopOf(canvas, id));
279
+ }
280
+
281
+ /** A stop by its number, by `<path>/<id>` key (the first), or the only one. */
282
+ #find(ref) {
283
+ if (ref === undefined || ref === null) return this.stops.size === 1 ? [...this.stops.values()][0] : undefined;
284
+ if (typeof ref === "number" || /^\d+$/.test(String(ref))) return this.stops.get(Number(ref));
285
+ return [...this.stops.values()].find((s) => s.key === String(ref) || s.canvas.panes.get(s.id)?.name === String(ref) || s.id === String(ref));
286
+ }
287
+
288
+ /** Continue a stop (the only one when `ref` is left out): its run goes ahead once. Returns whether there was one. */
289
+ resume(ref) {
290
+ const stop = this.#find(ref);
291
+ if (!stop) return false;
292
+ stop.finish("run");
293
+ return true;
294
+ }
295
+
296
+ /** Skip a stop: its pane doesn't run, and skips with a reason. */
297
+ skip(ref) {
298
+ const stop = this.#find(ref);
299
+ if (!stop) return false;
300
+ stop.finish("skip");
301
+ return true;
302
+ }
303
+
304
+ /**
305
+ * Step: continue a stop and stop before the next pane that runs, whichever it is. With `over`, only a pane of
306
+ * the stopped pane's own canvas counts: the panes inside a subgraph pane it runs (or in any other subgraph or
307
+ * instance) go through, so a subgraph pane is stepped over as one pane. A breakpoint still stops anywhere.
308
+ */
309
+ step(ref, { over = false } = {}) {
310
+ const stop = this.#find(ref);
311
+ if (!stop) return false;
312
+ this.stepping = true;
313
+ this.stepScope = over ? stop.canvas : null;
314
+ const armed = ++this.armedStep;
315
+ stop.finish("run");
316
+ this.#changed("stops");
317
+ // A step is spent when the next pane stops. If nothing else runs (the stepped pane was the last), the graph goes idle
318
+ // with the step still armed, and it would stop some unrelated later run: disarm it then.
319
+ this.root.flow?.idle?.().then(() => {
320
+ if (this.stepping && this.armedStep === armed && !this.stops.size) {
321
+ this.#disarm();
322
+ this.#changed("stops");
323
+ }
324
+ });
325
+ return true;
326
+ }
327
+
328
+ /** Continue every stop and stop stepping. */
329
+ continueAll() {
330
+ const had = this.stepping;
331
+ this.#disarm();
332
+ for (const stop of [...this.stops.values()]) stop.finish("run");
333
+ if (had) this.#changed("stops");
334
+ }
335
+
336
+ /** The canvas (or a pane's subgraph) closed: its stops end as cancelled, its breakpoints go. */
337
+ forgetCanvas(canvas) {
338
+ for (const stop of [...this.stops.values()]) if (stop.canvas === canvas) stop.finish("cancelled");
339
+ }
340
+
341
+ /** Close everything this holds (the root canvas closed). */
342
+ dispose() {
343
+ for (const stop of [...this.stops.values()]) stop.finish("cancelled");
344
+ this.#disarm();
345
+ }
346
+
347
+ // ── reading ──────────────────────────────────────────────────────────────
348
+
349
+ /** One stop as plain data: where, why it is runnable, the inputs it would get (retention applied). */
350
+ describe(stop) {
351
+ const { canvas, id } = stop;
352
+ const pane = canvas.panes.get(id);
353
+ return {
354
+ stop: stop.number,
355
+ pane: stop.key,
356
+ key: stop.key,
357
+ name: pane?.name || id,
358
+ type: pane?.type,
359
+ path: pathOf(canvas),
360
+ stoppedBy: stop.why,
361
+ why: whyRunnable(canvas, id, stop.runId),
362
+ inputs: pendingInputs(canvas, id),
363
+ since: stop.at,
364
+ };
365
+ }
366
+
367
+ /** Every stop now, oldest first, as plain data. */
368
+ list() {
369
+ return [...this.stops.values()].map((s) => this.describe(s));
370
+ }
371
+
372
+ /** `{ available, disabled, stepping, breakpoints: [{ pane, enabled, stopped }], stops: [] }` for the toolbar and agents. */
373
+ status() {
374
+ return {
375
+ available: this.available,
376
+ armed: this.armed,
377
+ disabled: this.disabled,
378
+ stepping: this.stepping,
379
+ breakpoints: [...this.marks].map(([key, m]) => ({ pane: key, enabled: m.enabled, stopped: [...this.stops.values()].some((s) => s.key === key) })),
380
+ stops: this.list(),
381
+ };
382
+ }
383
+
384
+ #disarm() {
385
+ this.stepping = false;
386
+ this.stepScope = null;
387
+ }
388
+
389
+ #changed(what) {
390
+ this.dispatchEvent(new CustomEvent("change", { detail: { what } }));
391
+ }
392
+ }