@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,520 @@
1
+ // The network policy: which hosts a canvas's panes may reach. `decide()` and
2
+ // `domCsp()` are pure; `createNetworkPolicy()` wraps a transport (the page's
3
+ // fetch) into the function panes' requests go through:
4
+ //
5
+ // (url, init, context) => Promise<{ url, status, statusText, headers, body, redirected }>
6
+ //
7
+ // That shape is what andbox's host-mediated fetch expects, so the same
8
+ // function can later be handed to `createSandbox({ network: { fetch } })`.
9
+ // With `context.stream` (a pane's own fetch), a transport that can may
10
+ // answer a streaming response (./streams.js) with `stream`, a ReadableStream
11
+ // of the body, instead of `body`; it is scrubbed of secrets as it arrives.
12
+ import { classifyHost, hostOf, matchesAny, normalizeHost } from "./hosts.js";
13
+ import { applySecrets, placeholdersIn, redactError, redactResponse } from "./secrets.js";
14
+ import { applyAuth } from "./auth.js";
15
+ import { netRefusal, effectiveMode } from "../privacy/levels.js";
16
+
17
+ /**
18
+ * Mark why a request failed, for error policies (src/model/errors.js): "refused"
19
+ * (the network policy), "secret" (an API key problem; neither is ever retried)
20
+ * or "network" (no response). Returns the error.
21
+ */
22
+ export function fetchFailure(error, kind) {
23
+ const e = error instanceof Error ? error : new Error(String(error));
24
+ if (!e.fetchFailure) Object.defineProperty(e, "fetchFailure", { value: kind, configurable: true, writable: true });
25
+ return e;
26
+ }
27
+
28
+ /**
29
+ * The browser's "Failed to fetch" (a TypeError: offline, a host that doesn't
30
+ * answer, or one that doesn't let pages read it) says which host and the
31
+ * likely reasons. Aborts and timeouts pass through as they are.
32
+ */
33
+ export function noAnswer(error, url) {
34
+ if (!(error instanceof TypeError)) return error;
35
+ return new TypeError(`fetch: no answer from ${hostOf(url)} (${error.message}). This browser may be offline, or the host doesn't let web pages read it (CORS).`);
36
+ }
37
+
38
+ /** "ask" (the default), "allow" (every public host), "block" (only the hosts this canvas allows). */
39
+ export const MODES = ["ask", "allow", "block"];
40
+
41
+ const PLACE = {
42
+ loopback: "this computer",
43
+ unspecified: "this computer",
44
+ private: "your local network",
45
+ "link-local": "your local network",
46
+ local: "your local network",
47
+ multicast: "your local network",
48
+ };
49
+
50
+ /**
51
+ * Should a request to `url` go ahead? The first rule that matches decides:
52
+ *
53
+ * | # | rule | result | `source` |
54
+ * |---|----------------------------------------|--------------------------------|-------------|
55
+ * | 1 | not http(s), or not a URL | refused | "protocol" |
56
+ * | 2 | this computer / local network, while | refused | "local" |
57
+ * | | "Allow local network" is off | | |
58
+ * | 3 | this canvas blocks the host | refused | "canvas" |
59
+ * | 4 | this canvas allows the host | allowed (in every mode) | "canvas" |
60
+ * | 5 | every canvas blocks the host | refused | "global" |
61
+ * | 6 | mode "block" | refused | "mode" |
62
+ * | 7 | every canvas allows the host | allowed | "global" |
63
+ * | 8 | mode "allow" | allowed | "mode" |
64
+ * | 9 | mode "ask" | refused, and asked about | "mode" |
65
+ *
66
+ * Every kind of request (a fetch, a module import, an embed, a DOM pane's
67
+ * frame loading a script) follows the same table: package CDNs and built-in
68
+ * examples get no exception. So a canvas's own choice beats the lists for
69
+ * every canvas, and "block every host" lets through only what this canvas
70
+ * allows: the global allow list doesn't apply in it.
71
+ *
72
+ * @param {string} url
73
+ * @param {{
74
+ * kind?: "fetch" | "import" | "embed" | "frame",
75
+ * mode?: "ask" | "allow" | "block",
76
+ * allowLocal?: boolean,
77
+ * allowed?: string[], // hosts this canvas allows (this browser's choice)
78
+ * blocked?: string[], // hosts this canvas blocks
79
+ * globalAllowed?: string[], // hosts every canvas may reach (this browser's choice)
80
+ * globalBlocked?: string[], // hosts no canvas may reach (unless it allows them itself)
81
+ * privacy?: { level: string, owned?: { host: string, local?: boolean }[], route?: string }, // a global level over all of the above: it only ever refuses more (rule 2b) and turns "allow" into "ask"
82
+ * }} rules
83
+ * @returns {{ allow: true, host: string, source: string } | { allow: false, host: string, reason: string, source: string, ask: boolean, message: string }}
84
+ */
85
+ export function decide(url, { kind = "fetch", mode: asked = "ask", allowLocal = false, allowed = [], blocked = [], globalAllowed = [], globalBlocked = [], privacy } = {}) {
86
+ const mode = effectiveMode(asked, privacy);
87
+ let target;
88
+ try {
89
+ target = new URL(url);
90
+ } catch {
91
+ return { allow: false, host: "", reason: "invalid", source: "protocol", ask: false, message: `${kind}: "${url}" isn't a valid URL` };
92
+ }
93
+ const host = normalizeHost(target.hostname);
94
+ const refuse = (reason, source, message, ask = false) => ({ allow: false, host, reason, source, ask, message });
95
+ const pass = (source) => ({ allow: true, host, source });
96
+ if (target.protocol !== "https:" && target.protocol !== "http:") {
97
+ return refuse("protocol", "protocol", `${kind}: only http(s) URLs are allowed (got ${target.protocol})`);
98
+ }
99
+ const where = PLACE[classifyHost(host)];
100
+ if (where && !allowLocal) {
101
+ return refuse("local", "local", `${host} is on ${where}. mallory blocks local-network addresses; turn on "Allow local network" in ⚙ settings → Network to reach it.`);
102
+ }
103
+ const held = netRefusal(privacy, host);
104
+ if (held) return refuse("privacy", "privacy", held);
105
+ if (matchesAny(host, blocked)) return refuse("blocked", "canvas", `${host} is blocked for this canvas (the network chip in the toolbar, or ⚙ settings → Network, to change that).`);
106
+ if (matchesAny(host, allowed)) return pass("canvas");
107
+ if (matchesAny(host, globalBlocked)) return refuse("blocked", "global", `${host} is blocked on every canvas (allow it for this canvas from the network chip in the toolbar, or change ⚙ settings → Network).`);
108
+ if (mode === "block") return refuse("mode", "mode", `Network access is turned off (⚙ settings → Network), so ${host} can't be reached unless this canvas allows it.`);
109
+ if (matchesAny(host, globalAllowed)) return pass("global");
110
+ if (mode === "allow") return pass("mode");
111
+ return refuse("ask", "mode", `${host} isn't allowed for this canvas yet. Allow it in the permission bar under the toolbar to rerun this pane.`, true);
112
+ }
113
+
114
+ /**
115
+ * What applies to one host on a canvas, for showing it: `state` is
116
+ * "allowed", "blocked" or "ask", `source` which rule decided (see decide()),
117
+ * and `also` the other lists that name the host but lost to it.
118
+ */
119
+ export function hostState(host, rules = {}, kind = "fetch") {
120
+ // A pattern (`*.example.com`) is judged by a name it matches. `kind` only
121
+ // changes the wording of messages: every kind follows the same rules.
122
+ const verdict = decide(`https://${normalizeHost(host).replace(/^\*\./, "any.")}/`, { ...rules, kind });
123
+ const state = verdict.allow ? "allowed" : verdict.ask ? "ask" : "blocked";
124
+ const lists = [
125
+ ["canvas", "allowed", rules.allowed],
126
+ ["canvas", "blocked", rules.blocked],
127
+ ["global", "allowed", rules.globalAllowed],
128
+ ["global", "blocked", rules.globalBlocked],
129
+ ];
130
+ const also = lists.filter(([source, , list]) => source !== verdict.source && (list ?? []).some((p) => normalizeHost(p) === normalizeHost(host))).map(([source, effect]) => ({ source, state: effect }));
131
+ return { host: normalizeHost(host), state, source: verdict.source, reason: verdict.reason, also };
132
+ }
133
+
134
+ /** CSP source expressions for a host, any port. */
135
+ const sources = (host, schemes) => schemes.map((s) => `${s}://${host}:*`);
136
+ const web = (hosts) => hosts.flatMap((h) => sources(h, ["https", "http"]));
137
+
138
+ /**
139
+ * Can a CSP source name this host exactly? Plain DNS names and IPv4
140
+ * addresses only: CSP has no form for an IPv6 literal (or a name with `_`),
141
+ * and a `*.` pattern would also let through hosts under it that a more
142
+ * specific rule blocks.
143
+ */
144
+ export const cspNameable = (host) => /^[a-z0-9-]+(\.[a-z0-9-]+)*$/.test(normalizeHost(host));
145
+
146
+ /**
147
+ * The hosts a frame's or the sandbox Worker's CSP lists: the hosts this
148
+ * canvas and every canvas allow, plus `rules.seen` (hosts decide() allowed
149
+ * when a frame or the Worker met them; in "allow every host" mode the lists
150
+ * don't name them), each only while decide() lets a request to it through and
151
+ * a CSP source can name it. So the precedence, the local-network rule and the
152
+ * blocked lists hold in every mode.
153
+ */
154
+ export function cspHosts(rules = {}) {
155
+ const { allowed = [], globalAllowed = [], seen = [] } = rules;
156
+ return [...new Set([...allowed, ...globalAllowed, ...seen].map(normalizeHost))].filter((h) => cspNameable(h) && decide(`https://${h}/`, rules).allow);
157
+ }
158
+
159
+ /**
160
+ * The Content-Security-Policy for a DOM pane's frame. Every directive that
161
+ * loads something (scripts, styles, fonts, images, media, workers,
162
+ * frame-src) lists only cspHosts() (`connect-src` lists none: see below), so the precedence (this canvas, every
163
+ * canvas, the mode) and the local-network rule are the same as for the
164
+ * sandbox's requests; package CDNs get no exception. data: and blob: URLs stay
165
+ * usable. "Allow every host" mode gets one too: a host a frame meets
166
+ * that decide() allows is learned (`rules.seen`, src/ui/network-ui.js) and the
167
+ * pane reruns in a new frame, while local and blocked hosts stay out.
168
+ */
169
+ export function domCsp(rules = {}) {
170
+ const hosts = cspHosts(rules);
171
+ const list = (items) => (items.length ? items.join(" ") : "'none'");
172
+ const assets = ["data:", "blob:", ...web(hosts)];
173
+ return [
174
+ "default-src 'none'",
175
+ `script-src 'unsafe-eval' 'wasm-unsafe-eval' 'unsafe-inline' ${assets.join(" ")}`,
176
+ `style-src 'unsafe-inline' ${assets.join(" ")}`,
177
+ `img-src ${assets.join(" ")}`,
178
+ `font-src ${assets.join(" ")}`,
179
+ `media-src ${assets.join(" ")}`,
180
+ `worker-src ${assets.join(" ")}`,
181
+ // No host here at all (WSK-05): a frame's fetch, EventSource and XMLHttpRequest go to the page instead (src/network/frame-net.js; the frame's bootstrap
182
+ // replaces them), so the network policy, the tap, the address guard and secret() placeholders apply to them as to a pane's own fetch. `data:` and
183
+ // `blob:` carry no network. No ws: or wss: either (wave P-F, invariant 5): a frame's socket is refused by the browser; the ws-client pane opens sockets
184
+ // from the page. A beacon (navigator.sendBeacon) is shimmed the same way; a Worker made in a frame inherits this and so has no network of its own.
185
+ "connect-src data: blob:",
186
+ `frame-src ${list(domFrameSrc(rules))}`,
187
+ "object-src 'none'",
188
+ "base-uri 'none'",
189
+ "form-action 'none'",
190
+ ].join("; ");
191
+ }
192
+
193
+ /**
194
+ * Where a DOM pane's frame (and frames inside it) may navigate: the
195
+ * hosts cspHosts() lists, over http and https, any port; the same list as
196
+ * domCsp()'s frame-src. Frame panes pass it to andbox as `frameSrc`, which
197
+ * puts it in the frame-src of a wrapper around the frame: a frame's own CSP
198
+ * can't stop it navigating itself (`location = ...`, a link, a meta refresh),
199
+ * its embedding document's frame-src can, before any request is sent. Empty
200
+ * when the canvas allows no host (`frame-src 'none'`).
201
+ */
202
+ export function domFrameSrc(rules = {}) {
203
+ return web(cspHosts(rules));
204
+ }
205
+
206
+ /**
207
+ * The CSP of the sandbox Worker, which it inherits from the frame it is
208
+ * made in (src/network/csp-frame.js). Module loads (`import()` in pane code,
209
+ * an import pane's module, and every module those import) reach only
210
+ * cspHosts(), checked by the browser before each request and each redirect.
211
+ * Nothing else in the Worker reaches the network on its own: its `fetch` goes
212
+ * to the page (and the policy), so `connect-src` and the rest are 'none'.
213
+ */
214
+ export function workerCsp(rules = {}) {
215
+ // A runnable bundle's modules reach the Worker as blob: URLs of the bytes the page checked, which `blob:` covers: no bundle folder here.
216
+ return [
217
+ "default-src 'none'",
218
+ `script-src 'unsafe-eval' 'wasm-unsafe-eval' blob: data: ${web(cspHosts(rules)).join(" ")}`.trim(),
219
+ "worker-src blob:",
220
+ "connect-src 'none'",
221
+ ].join("; ");
222
+ }
223
+
224
+ /**
225
+ * Where a request's redirects may go, as CSP sources for the page's
226
+ * transport: the browser checks each redirect against them before it
227
+ * follows it (src/network/csp-frame.js). The request's own host and
228
+ * cspHosts(); in "allow every host" mode any https host too (a hop to an
229
+ * http host must be one of those, so the local network over http is never
230
+ * reached by a redirect). `null` when the request's host can't be named in a
231
+ * CSP (an IPv6 literal): then the browser follows redirects on its own and
232
+ * only the final URL is checked.
233
+ */
234
+ /**
235
+ * Known redirect pairs (the owner's choice, 2026-11-08): a host and the hosts it is known to redirect to. The browser doesn't say where a redirect went, so a new
236
+ * host can't be learned from a refusal (docs/guide/security-model.md, "Network"); these are the pairs whose targets are fixed and documented, so they can be named up front. Fixed in code:
237
+ * a canvas can't add one.
238
+ * - github.com: a `/raw/` link goes to raw.githubusercontent.com, a release asset to objects.githubusercontent.com, a source archive to codeload.github.com
239
+ * (https://docs.github.com/en/repositories/working-with-files/using-files/downloading-source-code-archives).
240
+ * - registry.npmjs.org: serves its own tarballs and metadata; listed so the rule is stated (the host is already in the list).
241
+ * No CDN pair is listed: esm.sh, cdn.jsdelivr.net, unpkg.com and ga.jspm.io redirect only inside their own host (a version or path rewrite), which the
242
+ * request's own host already covers, and nothing in this code or its docs shows otherwise.
243
+ */
244
+ export const KNOWN_REDIRECTS = Object.freeze(
245
+ Object.assign(Object.create(null), {
246
+ "github.com": Object.freeze(["raw.githubusercontent.com", "objects.githubusercontent.com", "codeload.github.com"]),
247
+ "registry.npmjs.org": Object.freeze(["registry.npmjs.org"]),
248
+ }),
249
+ );
250
+
251
+ export function redirectSources(url, rules = {}) {
252
+ const host = hostOf(url);
253
+ if (!host || !cspNameable(host)) return null;
254
+ const hosts = [...new Set([host, ...cspHosts(rules)])];
255
+ // Never `https:` alone (WSK-05 review): a scheme source names every host, the local network's https addresses and the hosts the canvas blocks included, and the
256
+ // browser sends a hop before anything can refuse it. In "allow every host" mode a redirect may therefore go to the request's own host and to the hosts the canvas
257
+ // allows or has met (`seen`); to any other it fails closed (the browser doesn't say where a redirect went, so it can't be learned: docs/guide/security-model.md, "Network"). With
258
+ // the local network on, the loopback names a CSP can write are added unless the canvas blocks them; other private addresses are reached by allowing them.
259
+ const local = rules.allowLocal ? ["localhost", "127.0.0.1"].filter((h) => decide(`https://${h}/`, rules).allow) : [];
260
+ // The request's known redirect targets, when the request itself is allowed here (allow-all mode, or ask mode with its host granted; not with the network off).
261
+ // A target must pass decide() as if the mode were "allow": never local or private, never blocked by this canvas or every canvas; only the asking is waived,
262
+ // because the person granted the source. (A request that follows no redirect, or carries a secret, never gets this far: see `send`.)
263
+ const known = rules.mode !== "block" && decide(url, rules).allow ? (Object.hasOwn(KNOWN_REDIRECTS, host) ? KNOWN_REDIRECTS[host] : []).filter((t) => cspNameable(t) && decide(`https://${t}/`, { ...rules, mode: "allow" }).allow) : [];
264
+ return web([...new Set([...hosts, ...local, ...known])]);
265
+ }
266
+
267
+ const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
268
+ const MAX_REDIRECTS = 20;
269
+
270
+ /**
271
+ * Wrap a transport in the policy.
272
+ *
273
+ * @param {{
274
+ * transport: (url: string, init: object) => Promise<object>, // makes the request (the page's fetch)
275
+ * rules: (context: object) => Parameters<typeof decide>[1], // the current mode, allowlists, ...
276
+ * secrets?: () => Map<string, { value: string, hosts: string[], kind?: object }>,
277
+ * onRefused?: (refusal: object, context: object) => void, // show a prompt, log, ...
278
+ * onAllowed?: (verdict: object, context: object) => void, // log what was reached
279
+ * redirects?: "follow" | "check",
280
+ * }} options
281
+ * `redirects`: "follow" (the page) lets the transport follow
282
+ * redirects, handing it `hops` (redirectSources()) so the browser checks
283
+ * each one against them before following it (src/network/csp-frame.js);
284
+ * the final URL is checked again. "check" (Node, whose fetch shows
285
+ * redirects) follows them here: each Location is decided like a new
286
+ * request (and refused, with its prompt, before anything goes to it).
287
+ * @returns {(url: string, init?: object, context?: object) => Promise<object>}
288
+ */
289
+ export function createNetworkPolicy({ transport, rules, secrets = () => new Map(), onRefused, onAllowed, redirects = "follow", tap }) {
290
+ const check = createUrlCheck({ rules, onRefused, onAllowed });
291
+
292
+ // The tap (src/model/http-tap.js, #846) watches each request as it comes in, BEFORE secret() placeholders are filled in, and what it ends
293
+ // as (the policy's response, or the error it throws). It only observes: what it returns or throws is never used, and the request and the
294
+ // answer are the same with or without it.
295
+ return async function policyFetch(url, init = {}, context = {}) {
296
+ let seen;
297
+ try {
298
+ seen = tap?.begin({ url, init, context });
299
+ } catch {
300
+ seen = undefined;
301
+ }
302
+ if (!seen) return policyRequest(url, init, context);
303
+ try {
304
+ const response = await policyRequest(url, init, context);
305
+ try {
306
+ seen.end(response);
307
+ } catch {}
308
+ return response;
309
+ } catch (error) {
310
+ try {
311
+ seen.fail(error);
312
+ } catch {}
313
+ throw error;
314
+ }
315
+ };
316
+
317
+ async function policyRequest(url, init = {}, context = {}) {
318
+ let target;
319
+ try {
320
+ target = new URL(url);
321
+ } catch {
322
+ throw fetchFailure(new TypeError(`fetch: "${url}" isn't a valid URL`), "refused");
323
+ }
324
+ check(target.href, context);
325
+ const headers = (init.headers ?? []).map(([k, v]) => [String(k), String(v)]);
326
+ // A request that isn't from code the person wrote (an MCP app's page, which picks its own hosts) gets no key at all: a placeholder anywhere, in any spelling
327
+ // the filler knows, is refused before the filler runs, so the page can't have a stored key put into a request to a host the app named itself.
328
+ if (context.noSecrets === true) {
329
+ const has = (t) => placeholdersIn(t).length > 0;
330
+ if (has(String(url)) || has(target.href) || headers.some(([k, v]) => has(k) || has(v)) || (typeof init.body === "string" && has(init.body)) || (init.auth !== undefined && init.auth !== null)) {
331
+ throw fetchFailure(new Error("fetch: stored API keys (secret placeholders) are not available to this page; only panes you wrote can use them."), "refused");
332
+ }
333
+ }
334
+ const wantsSecrets = placeholdersIn(target.href).length > 0 || headers.some(([k, v]) => placeholdersIn(k).length || placeholdersIn(v).length) || (typeof init.body === "string" && placeholdersIn(init.body).length > 0);
335
+ let request;
336
+ try {
337
+ request = wantsSecrets ? applySecrets({ url: target.href, headers, body: init.body }, secrets()) : { url: target.href, headers, used: [] };
338
+ // `fetch(url, { auth: "NAME" })`: the key applied by its kind (src/network/auth.js).
339
+ if (init.auth !== undefined && init.auth !== null) {
340
+ const applied = applyAuth(request, init.auth, secrets());
341
+ request = { url: applied.url, headers: applied.headers, used: [...request.used, ...applied.used] };
342
+ }
343
+ } catch (error) {
344
+ throw fetchFailure(error, "secret"); // an API key problem (a placeholder or an auth key): never retried
345
+ }
346
+ // A request carrying a secret never follows a redirect: browsers drop
347
+ // Authorization on a cross-origin redirect, but not other headers.
348
+ // `context.redirects: "same-host"` (a proxy route, src/model/proxy.js): redirects are followed one hop at a time and only within the
349
+ // request's own host and port; a Location on another host is refused before anything is sent to it, whatever the rules allow.
350
+ const sameHost = context.redirects === "same-host";
351
+ const manual = request.used.length > 0 || redirects === "check" || sameHost;
352
+ // `context.redirects: "none"` (an MCP app's page, which may reach only what it declared; a frame's `redirect: "error"`): the first redirect is an error, so no hop
353
+ // is ever sent to a host nobody checked.
354
+ const noRedirects = context.redirects === "none" && !manual;
355
+ const send = async (href, method, body, headers) => {
356
+ const hops = manual || noRedirects ? undefined : redirectSources(href, rules(context));
357
+ try {
358
+ return await transport(href, {
359
+ method,
360
+ headers,
361
+ body,
362
+ signal: context.signal,
363
+ // A host a CSP can't name (an IPv6 literal) can't have its hops checked by the browser: it gets none.
364
+ redirect: manual ? "manual" : noRedirects || hops === null ? "error" : "follow",
365
+ ...(manual || noRedirects || hops === null ? {} : { hops }),
366
+ ...(context.stream === true && redirects !== "check" ? { stream: true, ...(context.streamAll === true ? { streamAll: true } : {}) } : {}),
367
+ ...(Number(context.maxBytes) > 0 ? { maxBytes: Number(context.maxBytes) } : {}), // a caller that knows what size to expect (the soundfont loader) says so
368
+ ...(Number(context.timeoutMs) > 0 ? { timeoutMs: Number(context.timeoutMs) } : {}),
369
+ });
370
+ } catch (error) {
371
+ throw fetchFailure(redactError(noAnswer(error, href), request.used), "network");
372
+ }
373
+ };
374
+ let response = await send(request.url, init.method ?? "GET", init.body, request.headers);
375
+ if ((redirects === "check" || sameHost) && !request.used.length) response = await followChecked(response, { url: request.url, method: init.method ?? "GET", body: init.body, headers: request.headers }, send, (next, from) => {
376
+ if (sameHost && (new URL(next).origin !== new URL(from).origin || (new URL(from).protocol === "https:" && new URL(next).protocol !== "https:"))) throw fetchFailure(new Error(`fetch: ${hostOf(from)} redirected to ${hostOf(next)}: a proxy route follows redirects within its own origin (scheme, host and port) only, and never from https to http`), "refused");
377
+ const verdict = decide(next, { ...rules(context), kind: context.kind ?? "fetch" });
378
+ if (!verdict.allow) {
379
+ try {
380
+ reportRefusal(onRefused, verdict, context);
381
+ } catch (error) {
382
+ throw fetchFailure(new Error(`fetch: ${hostOf(from)} redirected to ${verdict.host}: ${error.message}`), "refused"); // the headless runner's words
383
+ }
384
+ }
385
+ return verdict;
386
+ });
387
+ // A refused response's streaming body is never read.
388
+ const drop = (error) => {
389
+ response.stream?.cancel().catch(() => {});
390
+ return error;
391
+ };
392
+ if (request.used.length && (response.type === "opaqueredirect" || (response.status >= 300 && response.status < 400))) {
393
+ throw drop(fetchFailure(new Error(`fetch: ${hostOf(request.url)} answered with a redirect; requests that carry a secret don't follow redirects.`), "refused"));
394
+ }
395
+ // The browser followed any redirects; check where the response came from.
396
+ if (response.redirected && response.url && hostOf(response.url) !== hostOf(request.url)) {
397
+ const verdict = decide(response.url, { ...rules(context), kind: context.kind ?? "fetch" });
398
+ if (!verdict.allow) {
399
+ try {
400
+ reportRefusal(onRefused, verdict, context);
401
+ } catch (error) {
402
+ throw drop(error);
403
+ }
404
+ throw drop(fetchFailure(new Error(`fetch: ${hostOf(request.url)} redirected to ${verdict.host}, and ${verdict.message}`), "refused"));
405
+ }
406
+ }
407
+ const { type, ...shape } = response;
408
+ return redactResponse(shape, request.used);
409
+ }
410
+ }
411
+
412
+ /**
413
+ * Follow redirects one hop at a time (`redirects: "check"`): each
414
+ * Location is decided by `decide(url)` before anything is sent to it, with the
415
+ * Fetch standard's method and body rewriting (303, and 301/302 after a POST,
416
+ * become a GET without a body) and the `authorization` header dropped when the
417
+ * hop leaves the origin, as browsers do. A transport that hides the target (a
418
+ * browser's opaque redirect) fails closed.
419
+ */
420
+ async function followChecked(first, { url, method, body, headers }, send, decideHop) {
421
+ let response = first;
422
+ let href = url;
423
+ for (let hop = 0; ; hop++) {
424
+ if (response.type === "opaqueredirect") throw fetchFailure(new Error(`fetch: ${hostOf(href)} answered with a redirect whose target this transport hides, so it isn't followed.`), "refused");
425
+ const location = REDIRECT_STATUSES.has(response.status) ? (response.headers ?? []).find(([k]) => String(k).toLowerCase() === "location")?.[1] : undefined;
426
+ if (location === undefined) return hop === 0 ? response : { ...response, url: href, redirected: true };
427
+ if (hop + 1 > MAX_REDIRECTS) throw fetchFailure(new Error(`fetch: more than ${MAX_REDIRECTS} redirects from ${hostOf(url)}`), "network");
428
+ let next;
429
+ try {
430
+ next = new URL(location, href);
431
+ } catch {
432
+ throw fetchFailure(new Error(`fetch: ${hostOf(href)} redirected to an invalid URL`), "network");
433
+ }
434
+ const verdict = decideHop(next.href, href);
435
+ if (!verdict.allow) throw fetchFailure(new Error(`fetch: ${hostOf(href)} redirected to ${verdict.host || next.protocol}, and ${verdict.message}`), "refused");
436
+ const status = response.status;
437
+ if ((status === 303 && method !== "GET" && method !== "HEAD") || ((status === 301 || status === 302) && method === "POST")) {
438
+ method = "GET";
439
+ body = undefined;
440
+ headers = headers.filter(([k]) => !["content-type", "content-length", "content-encoding", "content-language", "content-location"].includes(String(k).toLowerCase()));
441
+ }
442
+ if (next.origin !== new URL(href).origin) headers = headers.filter(([k]) => String(k).toLowerCase() !== "authorization");
443
+ href = next.href;
444
+ response = await send(href, method, body, headers);
445
+ }
446
+ }
447
+
448
+ /**
449
+ * A check for one URL (import panes, embeds) that throws the policy's error.
450
+ * `check.allows(url, context)` asks the same question without logging,
451
+ * prompting or throwing (an import pane uses it to prefer a package CDN the
452
+ * canvas already allows).
453
+ */
454
+ export function createUrlCheck({ rules, onRefused, onAllowed }) {
455
+ const check = (url, context = {}) => {
456
+ const verdict = decide(url, { ...rules(context), kind: context.kind ?? "fetch" });
457
+ if (!verdict.allow) {
458
+ reportRefusal(onRefused, verdict, context);
459
+ throw Object.defineProperty(fetchFailure(new Error(verdict.message), "refused"), "verdict", { value: verdict, configurable: true }); // the tap reads the reason (./../model/http-tap.js)
460
+ }
461
+ onAllowed?.(verdict, context);
462
+ return verdict;
463
+ };
464
+ check.verdict = (url, context = {}) => decide(url, { ...rules(context), kind: context.kind ?? "fetch" });
465
+ check.allows = (url, context = {}) => check.verdict(url, context).allow;
466
+ return check;
467
+ }
468
+
469
+ /** Why the policy refused a host, in a few words (a skip reason in mport's trace). */
470
+ export function refusalReason({ host, reason, source } = {}) {
471
+ const h = host || "the URL";
472
+ if (reason === "ask") return `the network policy doesn't allow ${h} yet`;
473
+ if (reason === "blocked") return `${h} is blocked ${source === "global" ? "on every canvas" : "here"}`;
474
+ if (reason === "mode") return `network access is off, so ${h} isn't allowed`;
475
+ if (reason === "local") return `${h} is on the local network, which isn't allowed`;
476
+ if (reason === "privacy") return `${h} is held back by the privacy level`;
477
+ if (reason === "protocol" || reason === "invalid") return "not an http(s) URL";
478
+ return `the network policy doesn't allow ${h}`;
479
+ }
480
+
481
+ /**
482
+ * The fetch for mallory's own lookups: mport's registry lookups and HEAD
483
+ * probes, and the npm registry search. `lookup(url, init, context)` goes
484
+ * through the policy like a pane's fetch (no secrets) and answers with a
485
+ * standard Response, which is what mport expects; a refusal throws before
486
+ * anything is sent, with the policy's verdict on the error (`verdict`).
487
+ * `lookup.check` is createUrlCheck()'s check for the same rules, so a caller
488
+ * can ask about a host before anything goes to it (`check.verdict`, quiet) or
489
+ * raise the refusal and its prompt (`check(url, context)`).
490
+ */
491
+ export function createLookupFetch({ transport, rules, onRefused, onAllowed, redirects }) {
492
+ const policy = createNetworkPolicy({ transport, rules, onRefused: (verdict, context) => ((context.verdict = verdict), onRefused?.(verdict, context)), onAllowed, redirects });
493
+ const lookup = async (url, init = {}, context = {}) => {
494
+ const method = String(init.method ?? "GET").toUpperCase();
495
+ const ctx = { ...context, kind: context.kind ?? "fetch", signal: init.signal ?? context.signal };
496
+ let r;
497
+ try {
498
+ r = await policy(String(url), { method, headers: [...new Headers(init.headers ?? {})] }, ctx);
499
+ } catch (error) {
500
+ if (ctx.verdict && error && typeof error === "object" && !error.verdict) Object.defineProperty(error, "verdict", { value: ctx.verdict, configurable: true });
501
+ throw error;
502
+ }
503
+ // A caller that asked for a streamed body (context.stream) gets it as it arrives, for the response types the transport streams.
504
+ const empty = method === "HEAD" || [101, 204, 205, 304].includes(r.status) || (!r.stream && !r.body?.byteLength);
505
+ const response = new Response(empty ? null : (r.stream ?? r.body), { status: r.status, statusText: r.statusText, headers: r.headers });
506
+ Object.defineProperty(response, "url", { value: r.url ?? String(url) });
507
+ return response;
508
+ };
509
+ lookup.check = createUrlCheck({ rules, onRefused, onAllowed });
510
+ return lookup;
511
+ }
512
+
513
+ /** Tell `onRefused` about a refusal; whatever it throws (the headless runner's message) is a refusal too. */
514
+ function reportRefusal(onRefused, verdict, context) {
515
+ try {
516
+ onRefused?.(verdict, context);
517
+ } catch (error) {
518
+ throw fetchFailure(error, "refused");
519
+ }
520
+ }