@1agh/maude 2.0.8 → 2.1.1

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 (401) hide show
  1. package/README.md +2 -1
  2. package/apps/hub/src/project-transactions/kernel.mjs +13 -7
  3. package/apps/studio/access/closure.ts +86 -10
  4. package/apps/studio/access/filters.ts +18 -1
  5. package/apps/studio/access/request.ts +8 -0
  6. package/apps/studio/acp/design-write-verb.ts +12 -2
  7. package/apps/studio/acp/env.ts +7 -2
  8. package/apps/studio/acp/index.ts +15 -4
  9. package/apps/studio/acp/login-state.ts +22 -5
  10. package/apps/studio/acp/may-scope.ts +38 -1
  11. package/apps/studio/acp/plugin-bootstrap.ts +13 -1
  12. package/apps/studio/acp/probe.ts +11 -4
  13. package/apps/studio/actions/agents.ts +110 -28
  14. package/apps/studio/actions/canvas-keys.ts +4 -2
  15. package/apps/studio/actions/ctx.ts +3 -0
  16. package/apps/studio/actions/defs/annotation.ts +84 -2
  17. package/apps/studio/actions/defs/app.ts +28 -1
  18. package/apps/studio/actions/defs/edit.ts +13 -0
  19. package/apps/studio/actions/defs/export.ts +12 -0
  20. package/apps/studio/actions/defs/sync.ts +18 -0
  21. package/apps/studio/actions/defs/video.ts +9 -0
  22. package/apps/studio/actions/documents.ts +6 -1
  23. package/apps/studio/actions/keymap.gen.ts +147 -9
  24. package/apps/studio/actions/menu.ts +5 -1
  25. package/apps/studio/actions/types.ts +4 -2
  26. package/apps/studio/actions/verbs.ts +9 -0
  27. package/apps/studio/actions.manifest.json +300 -45
  28. package/apps/studio/actions.parity.json +19 -1
  29. package/apps/studio/ai/save-hold.ts +2 -1
  30. package/apps/studio/ai/write-claim-scope.ts +7 -1
  31. package/apps/studio/ai/write-claim.ts +154 -3
  32. package/apps/studio/annotations/ai-read.ts +42 -6
  33. package/apps/studio/annotations/ai-write.ts +145 -2
  34. package/apps/studio/annotations/board-ops.ts +34 -3
  35. package/apps/studio/annotations/checklist-ops.ts +374 -0
  36. package/apps/studio/annotations/elements/checkitem.model.ts +129 -0
  37. package/apps/studio/annotations/elements/sticky.model.ts +54 -2
  38. package/apps/studio/annotations/ops.ts +30 -0
  39. package/apps/studio/annotations/registry.ts +9 -1
  40. package/apps/studio/annotations/templates.ts +4 -2
  41. package/apps/studio/annotations/text-steps.ts +114 -10
  42. package/apps/studio/annotations/ui/checklist-wire.ts +129 -0
  43. package/apps/studio/annotations/ui/checklist.tsx +429 -0
  44. package/apps/studio/annotations/ui/element-node.tsx +48 -2
  45. package/apps/studio/annotations/ui/template-place.ts +11 -1
  46. package/apps/studio/annotations/v1-adapter.ts +22 -3
  47. package/apps/studio/annotations-context-toolbar.tsx +12 -0
  48. package/apps/studio/annotations-layer.tsx +442 -49
  49. package/apps/studio/annotations-model.ts +4 -2
  50. package/apps/studio/api.ts +148 -21
  51. package/apps/studio/artboard-live-gate.tsx +54 -17
  52. package/apps/studio/artboard-still-persist.ts +166 -0
  53. package/apps/studio/artboard-still-raster.ts +6 -2
  54. package/apps/studio/artboard-still.ts +390 -20
  55. package/apps/studio/asset-added.ts +154 -0
  56. package/apps/studio/asset-details.ts +46 -3
  57. package/apps/studio/asset-origins.ts +5 -3
  58. package/apps/studio/asset-trash.ts +6 -1
  59. package/apps/studio/bin/_agent-browser-safe.mjs +3 -4
  60. package/apps/studio/bin/_annotate-post.mjs +14 -5
  61. package/apps/studio/bin/_audio-search.mjs +8 -2
  62. package/apps/studio/bin/_curl-local.mjs +7 -4
  63. package/apps/studio/bin/_desktop-locate.sh +145 -0
  64. package/apps/studio/bin/_ds-check-live.mjs +2 -1
  65. package/apps/studio/bin/_exports.mjs +38 -2
  66. package/apps/studio/bin/_history.mjs +79 -8
  67. package/apps/studio/bin/_import-asset.mjs +14 -9
  68. package/apps/studio/bin/_import-figma.mjs +510 -98
  69. package/apps/studio/bin/_index-cli.mjs +10 -21
  70. package/apps/studio/bin/_ingest-footage.mjs +24 -6
  71. package/apps/studio/bin/_media-probe.mjs +232 -0
  72. package/apps/studio/bin/_perf-probe-open.mjs +6 -0
  73. package/apps/studio/bin/_perf-probe-safari.mjs +6 -0
  74. package/apps/studio/bin/_perf-probe-studio.mjs +6 -1
  75. package/apps/studio/bin/_perf-probe.mjs +8 -3
  76. package/apps/studio/bin/_perf-sweep-shared.mjs +789 -0
  77. package/apps/studio/bin/_perf-sweep.mjs +240 -0
  78. package/apps/studio/bin/_record-shot.sh +33 -8
  79. package/apps/studio/bin/_screenshot-playwright.mjs +45 -2
  80. package/apps/studio/bin/_studio-verb.mjs +8 -3
  81. package/apps/studio/bin/_thumb-route.mjs +21 -0
  82. package/apps/studio/bin/_thumbs-playwright.mjs +83 -1
  83. package/apps/studio/bin/_transcribe.mjs +22 -6
  84. package/apps/studio/bin/_unsynced-refs.mjs +22 -0
  85. package/apps/studio/bin/_url-guard.mjs +120 -5
  86. package/apps/studio/bin/_url-guard.sh +29 -7
  87. package/apps/studio/bin/_video-limits.mjs +104 -0
  88. package/apps/studio/bin/_video-playwright.mjs +119 -19
  89. package/apps/studio/bin/_video-proxy.mjs +130 -0
  90. package/apps/studio/bin/_write-claim.mjs +38 -16
  91. package/apps/studio/bin/annotate.mjs +12 -2
  92. package/apps/studio/bin/canvas-rects.sh +19 -4
  93. package/apps/studio/bin/chat-open.sh +7 -1
  94. package/apps/studio/bin/draw-proof.sh +6 -2
  95. package/apps/studio/bin/generate.sh +32 -10
  96. package/apps/studio/bin/handoff.sh +2 -2
  97. package/apps/studio/bin/perf.sh +96 -15
  98. package/apps/studio/bin/photo-adjust.sh +6 -3
  99. package/apps/studio/bin/photo-bg-remove.sh +2 -2
  100. package/apps/studio/bin/prep.sh +21 -4
  101. package/apps/studio/bin/read-annotations.mjs +3 -0
  102. package/apps/studio/bin/runtime-health.sh +27 -1
  103. package/apps/studio/bin/screenshot.sh +152 -12
  104. package/apps/studio/bin/server-up.sh +64 -6
  105. package/apps/studio/bin/smoke.sh +43 -8
  106. package/apps/studio/bin/to-lottie.sh +3 -2
  107. package/apps/studio/bin/video-proxy.sh +27 -0
  108. package/apps/studio/bin/visual-sanity.sh +3 -1
  109. package/apps/studio/bridge/dgn-protocol.ts +157 -1
  110. package/apps/studio/bridge/mode-shows.ts +8 -6
  111. package/apps/studio/bridge/still-webp.ts +233 -0
  112. package/apps/studio/build.ts +18 -0
  113. package/apps/studio/canvas-build.ts +93 -11
  114. package/apps/studio/canvas-comment-mount.tsx +53 -8
  115. package/apps/studio/canvas-edit.ts +34 -1
  116. package/apps/studio/canvas-lib-module.ts +210 -0
  117. package/apps/studio/canvas-lib.tsx +3 -12
  118. package/apps/studio/canvas-pipeline.ts +111 -5
  119. package/apps/studio/canvas-shell.tsx +8 -11
  120. package/apps/studio/canvas-theme-pill.tsx +5 -3
  121. package/apps/studio/check/index.ts +12 -5
  122. package/apps/studio/check/video.ts +18 -2
  123. package/apps/studio/client/app.jsx +65 -7
  124. package/apps/studio/client/clipboard-relay.ts +193 -16
  125. package/apps/studio/client/comments-overlay.css +18 -0
  126. package/apps/studio/client/export-center.jsx +30 -0
  127. package/apps/studio/client/generate-dialog.jsx +49 -4
  128. package/apps/studio/client/github.js +7 -0
  129. package/apps/studio/client/home/HomeAccountsRow.jsx +221 -0
  130. package/apps/studio/client/home/HomeConnection.jsx +111 -0
  131. package/apps/studio/client/home/home-accounts-model.js +110 -1
  132. package/apps/studio/client/home/home-api.js +9 -2
  133. package/apps/studio/client/home/home-app.jsx +126 -13
  134. package/apps/studio/client/home/home-model.js +69 -1
  135. package/apps/studio/client/home/home-where-model.js +105 -0
  136. package/apps/studio/client/home/home.css +239 -1
  137. package/apps/studio/client/hooks/use-canvas-bridge.jsx +173 -98
  138. package/apps/studio/client/hooks/use-palette-and-panels.jsx +5 -1
  139. package/apps/studio/client/hooks/use-tabs.jsx +11 -4
  140. package/apps/studio/client/panels/DiffView.jsx +7 -1
  141. package/apps/studio/client/panels/TeamProjects.jsx +137 -134
  142. package/apps/studio/client/panels/chat-context.js +2 -0
  143. package/apps/studio/client/panels/slash-commands.gen.js +13 -13
  144. package/apps/studio/client/selection-scope.js +16 -9
  145. package/apps/studio/client/share-link.js +12 -0
  146. package/apps/studio/client/shell/viewport.jsx +11 -1
  147. package/apps/studio/client/shell-events.js +8 -0
  148. package/apps/studio/client/styles/3-kit-maude-v2.css +16 -0
  149. package/apps/studio/client/styles/_index.css +4 -0
  150. package/apps/studio/client/v2/ai/Feed.jsx +1 -1
  151. package/apps/studio/client/v2/ai/OfferCard.jsx +34 -0
  152. package/apps/studio/client/v2/ai/activity-line.js +54 -1
  153. package/apps/studio/client/v2/ai/ai-offer.js +21 -1
  154. package/apps/studio/client/v2/ai/run-model.js +3 -1
  155. package/apps/studio/client/v2/annotations/vote-store.js +28 -4
  156. package/apps/studio/client/v2/assets/asset-drop-session.js +37 -2
  157. package/apps/studio/client/v2/assets/canvas-drop-catcher.jsx +7 -5
  158. package/apps/studio/client/v2/assets/details-model.js +1 -1
  159. package/apps/studio/client/v2/assets/details.jsx +5 -0
  160. package/apps/studio/client/v2/assets/tile-drag.js +11 -7
  161. package/apps/studio/client/v2/comments/comments-panel.jsx +22 -3
  162. package/apps/studio/client/v2/create/duplicate-done.js +6 -2
  163. package/apps/studio/client/v2/diagnostics/diagnostics-host.jsx +1 -0
  164. package/apps/studio/client/v2/diagnostics/diagnostics-model.js +32 -2
  165. package/apps/studio/client/v2/diagnostics/diagnostics-sheet.jsx +35 -8
  166. package/apps/studio/client/v2/diagnostics/diagnostics.css +34 -0
  167. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +113 -3
  168. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +343 -6
  169. package/apps/studio/client/v2/diagnostics/sync-details/unsynced-refs.js +55 -0
  170. package/apps/studio/client/v2/ds/review.css +1 -1
  171. package/apps/studio/client/v2/export/exports-model.js +7 -0
  172. package/apps/studio/client/v2/export/exports-panel.jsx +1 -0
  173. package/apps/studio/client/v2/export/job-row.jsx +32 -2
  174. package/apps/studio/client/v2/handoff/ready-card.jsx +1 -1
  175. package/apps/studio/client/v2/history/compare-view.jsx +1 -0
  176. package/apps/studio/client/v2/inspector/css-write.js +6 -1
  177. package/apps/studio/client/v2/inspector/frame.jsx +28 -4
  178. package/apps/studio/client/v2/inspector/kinds/clip-model.js +51 -0
  179. package/apps/studio/client/v2/inspector/kinds/clip.jsx +75 -2
  180. package/apps/studio/client/v2/inspector/model.js +21 -0
  181. package/apps/studio/client/v2/inspector/sections/fill.jsx +12 -3
  182. package/apps/studio/client/v2/inspector/sections/recent-colours.js +8 -5
  183. package/apps/studio/client/v2/inspector/view-mode.jsx +11 -1
  184. package/apps/studio/client/v2/link-server/LinkServerDialog.jsx +492 -0
  185. package/apps/studio/client/v2/link-server/LinkServerHost.jsx +42 -0
  186. package/apps/studio/client/v2/link-server/link-server-api.js +142 -0
  187. package/apps/studio/client/v2/link-server/link-server-model.js +438 -0
  188. package/apps/studio/client/v2/link-server/link-server.css +109 -0
  189. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +31 -86
  190. package/apps/studio/client/v2/onboarding/onboarding-model.js +1 -18
  191. package/apps/studio/client/v2/preview/link-follow.js +4 -2
  192. package/apps/studio/client/v2/preview/preview-chrome-host.jsx +16 -6
  193. package/apps/studio/client/v2/search/help-model.js +2 -0
  194. package/apps/studio/client/v2/search/search-keywords.js +3 -2
  195. package/apps/studio/client/v2/settings/account.jsx +4 -2
  196. package/apps/studio/client/v2/settings/advanced-section.jsx +344 -137
  197. package/apps/studio/client/v2/settings/connection-row.jsx +3 -59
  198. package/apps/studio/client/v2/settings/connections-section.jsx +118 -425
  199. package/apps/studio/client/v2/settings/general-section.jsx +155 -24
  200. package/apps/studio/client/v2/settings/project-sync-settings.jsx +4 -3
  201. package/apps/studio/client/v2/settings/reset-section.jsx +14 -3
  202. package/apps/studio/client/v2/settings/settings-card.jsx +142 -0
  203. package/apps/studio/client/v2/settings/settings-cards.js +220 -0
  204. package/apps/studio/client/v2/settings/settings-handlers.js +7 -6
  205. package/apps/studio/client/v2/settings/settings-model.js +100 -31
  206. package/apps/studio/client/v2/settings/settings-sheet.jsx +25 -6
  207. package/apps/studio/client/v2/settings/settings.css +374 -64
  208. package/apps/studio/client/v2/settings/this-project-card.jsx +730 -0
  209. package/apps/studio/client/v2/settings/this-project-model.js +172 -0
  210. package/apps/studio/client/v2/settings/use-connections.js +3 -2
  211. package/apps/studio/client/v2/settings/use-open-card.js +37 -0
  212. package/apps/studio/client/v2/share/share-sheet.jsx +28 -11
  213. package/apps/studio/client/v2/shell/api-session-boot.js +6 -0
  214. package/apps/studio/client/v2/shell/api-session.js +126 -0
  215. package/apps/studio/client/v2/shell/connection-state.js +197 -0
  216. package/apps/studio/client/v2/shell/floating-panels.css +31 -1
  217. package/apps/studio/client/v2/shell/image-pick.js +61 -8
  218. package/apps/studio/client/v2/shell/menu-aim.js +43 -0
  219. package/apps/studio/client/v2/shell/menu-runner.js +25 -7
  220. package/apps/studio/client/v2/shell/occlusion-insets.js +18 -1
  221. package/apps/studio/client/v2/shell/project-account-bus.js +36 -0
  222. package/apps/studio/client/v2/shell/project-account-card.jsx +357 -148
  223. package/apps/studio/client/v2/shell/project-account-model.js +272 -149
  224. package/apps/studio/client/v2/shell/project-account-toast.js +66 -0
  225. package/apps/studio/client/v2/shell/project-account.css +237 -0
  226. package/apps/studio/client/v2/shell/project-pill.jsx +52 -6
  227. package/apps/studio/client/v2/shell/share-cluster-host.jsx +166 -83
  228. package/apps/studio/client/v2/shell/shell-parity.js +3 -2
  229. package/apps/studio/client/v2/shell/shell-parity.json +71 -36
  230. package/apps/studio/client/v2/shell/still-bridge.js +194 -0
  231. package/apps/studio/client/v2/shell/still-store.js +319 -0
  232. package/apps/studio/client/v2/shell/use-account.js +2 -0
  233. package/apps/studio/client/v2/shell/use-tool-panels.js +2 -1
  234. package/apps/studio/client/v2/signin/use-signin.js +1 -1
  235. package/apps/studio/client/v2/timeline/Timeline.jsx +15 -0
  236. package/apps/studio/client/v2/timeline/frame-handle-model.js +142 -0
  237. package/apps/studio/client/v2/timeline/frame-handle.jsx +151 -0
  238. package/apps/studio/clip-ops.ts +126 -8
  239. package/apps/studio/cloud/endpoints.ts +29 -4
  240. package/apps/studio/collab/ai-activity.ts +10 -8
  241. package/apps/studio/collab/awareness-bridge.ts +34 -9
  242. package/apps/studio/collab/index.ts +3 -0
  243. package/apps/studio/collab/registry.ts +41 -10
  244. package/apps/studio/comment-reattach.ts +149 -0
  245. package/apps/studio/comments/mine-stamp.ts +15 -7
  246. package/apps/studio/comments/ops.ts +52 -8
  247. package/apps/studio/comments-overlay.tsx +146 -9
  248. package/apps/studio/dist/client.bundle.js +892 -885
  249. package/apps/studio/dist/comment-mount.js +2 -2
  250. package/apps/studio/dist/styles.css +1 -1
  251. package/apps/studio/dom-selection.ts +87 -18
  252. package/apps/studio/ds/board/directions.css +8 -0
  253. package/apps/studio/ds/board/outline.tsx +16 -0
  254. package/apps/studio/ds/canvas-check.ts +6 -0
  255. package/apps/studio/edit-ops/clip/reframe.ts +19 -3
  256. package/apps/studio/edit-ops/clip-carry.ts +602 -0
  257. package/apps/studio/edit-ops/clipboard.ts +318 -23
  258. package/apps/studio/edit-ops/dispatch.ts +20 -2
  259. package/apps/studio/edit-ops/scope-names.ts +249 -40
  260. package/apps/studio/edit-ops/slot-defaults.ts +3 -0
  261. package/apps/studio/edit-ops/types.ts +6 -0
  262. package/apps/studio/editing/align-bar.tsx +33 -9
  263. package/apps/studio/editing/artboard-actions.ts +5 -0
  264. package/apps/studio/editing/artboard-menu.tsx +6 -2
  265. package/apps/studio/editing/click-to-type.ts +1 -1
  266. package/apps/studio/editing/clip-words.ts +48 -0
  267. package/apps/studio/editing/clipboard.ts +21 -6
  268. package/apps/studio/editing/declared-background.ts +25 -0
  269. package/apps/studio/editing/index.tsx +3 -0
  270. package/apps/studio/editing/object-keys.ts +4 -4
  271. package/apps/studio/editing/object-menu.tsx +13 -3
  272. package/apps/studio/editing/pen/points.tsx +61 -0
  273. package/apps/studio/editing/text-in-place.tsx +11 -0
  274. package/apps/studio/editing/video-frame-handle.tsx +425 -0
  275. package/apps/studio/exporters/capture-prepass.ts +374 -0
  276. package/apps/studio/exporters/degraded.ts +148 -0
  277. package/apps/studio/exporters/hub-render-door.ts +28 -2
  278. package/apps/studio/exporters/index.ts +3 -1
  279. package/apps/studio/exporters/job-budget.ts +93 -0
  280. package/apps/studio/exporters/jobs.ts +215 -28
  281. package/apps/studio/exporters/parity-check.ts +254 -0
  282. package/apps/studio/exporters/remote.ts +209 -15
  283. package/apps/studio/exporters/svg-inline.ts +87 -0
  284. package/apps/studio/exporters/video-render-lib.ts +88 -26
  285. package/apps/studio/exporters/video.ts +29 -6
  286. package/apps/studio/figma/assets.ts +58 -43
  287. package/apps/studio/figma/codegen-fonts.ts +100 -0
  288. package/apps/studio/figma/fig-decode.ts +390 -25
  289. package/apps/studio/figma/fig-kiwi.ts +18 -4
  290. package/apps/studio/figma/fig-vector.ts +59 -3
  291. package/apps/studio/figma/sanitize.ts +2 -0
  292. package/apps/studio/figma/style-map.ts +293 -48
  293. package/apps/studio/figma/to-artboard.ts +455 -69
  294. package/apps/studio/figma/to-strokes.ts +44 -11
  295. package/apps/studio/figma/types.ts +13 -0
  296. package/apps/studio/footage/schema.ts +3 -3
  297. package/apps/studio/generation/adapters/elevenlabs.ts +7 -1
  298. package/apps/studio/generation/adapters/groq.ts +8 -1
  299. package/apps/studio/generation/spend.ts +312 -0
  300. package/apps/studio/generation/types.ts +12 -0
  301. package/apps/studio/handoff/run.ts +1 -1
  302. package/apps/studio/handoff/targets.ts +2 -2
  303. package/apps/studio/handoff/write-scopes.ts +1 -1
  304. package/apps/studio/history/describe-annotations.ts +4 -0
  305. package/apps/studio/home/accounts.ts +30 -11
  306. package/apps/studio/home/cloud.ts +6 -1
  307. package/apps/studio/home/create-local.ts +32 -3
  308. package/apps/studio/home/hub-health.ts +76 -0
  309. package/apps/studio/home/routes.ts +15 -4
  310. package/apps/studio/http.ts +438 -86
  311. package/apps/studio/imported-module-ids.ts +91 -0
  312. package/apps/studio/inspect.ts +2 -0
  313. package/apps/studio/migrate/hub.ts +8 -1
  314. package/apps/studio/notifications.tsx +47 -5
  315. package/apps/studio/paths.ts +10 -1
  316. package/apps/studio/port.ts +3 -2
  317. package/apps/studio/preview/preview-camera.tsx +15 -382
  318. package/apps/studio/readiness.ts +10 -1
  319. package/apps/studio/release-build.ts +51 -0
  320. package/apps/studio/routes/agent.ts +188 -9
  321. package/apps/studio/routes/ai.ts +43 -11
  322. package/apps/studio/routes/annotations.ts +27 -1
  323. package/apps/studio/routes/assets.ts +18 -1
  324. package/apps/studio/routes/canvas-origin.ts +12 -9
  325. package/apps/studio/routes/cloud-move.ts +15 -0
  326. package/apps/studio/routes/edit.ts +3 -0
  327. package/apps/studio/routes/export.ts +51 -0
  328. package/apps/studio/routes/generate.ts +42 -12
  329. package/apps/studio/routes/hub-link-folder.ts +334 -0
  330. package/apps/studio/routes/hub-signin.ts +78 -1
  331. package/apps/studio/routes/index.ts +9 -1
  332. package/apps/studio/routes/shell.ts +217 -5
  333. package/apps/studio/routes/sync.ts +136 -8
  334. package/apps/studio/routes/votes.ts +2 -1
  335. package/apps/studio/schema/annotations.v2.schema.json +143 -1
  336. package/apps/studio/schema/beats.v1.schema.json +1 -1
  337. package/apps/studio/schema/edl.v1.schema.json +1 -1
  338. package/apps/studio/schema/formats.ts +3 -3
  339. package/apps/studio/schema/transcript.v1.schema.json +1 -1
  340. package/apps/studio/server.ts +142 -43
  341. package/apps/studio/shell/api-key.ts +503 -0
  342. package/apps/studio/shell/attest.ts +59 -0
  343. package/apps/studio/shell/capture-url.ts +20 -0
  344. package/apps/studio/shell/cli-yield.ts +276 -0
  345. package/apps/studio/shell/clip-transfer.ts +302 -0
  346. package/apps/studio/shell/key-file.ts +108 -0
  347. package/apps/studio/shell/server-json.ts +75 -0
  348. package/apps/studio/shell/worktree.ts +19 -0
  349. package/apps/studio/spoof-chars.ts +9 -0
  350. package/apps/studio/studio-page-host.ts +1 -1
  351. package/apps/studio/sync/accepted-cold-start.ts +144 -8
  352. package/apps/studio/sync/accepted-link.ts +76 -29
  353. package/apps/studio/sync/action-stage.ts +575 -44
  354. package/apps/studio/sync/adopt-held.ts +85 -0
  355. package/apps/studio/sync/ctl-heal.ts +58 -0
  356. package/apps/studio/sync/file-ledger.ts +38 -4
  357. package/apps/studio/sync/file-membership.ts +16 -1
  358. package/apps/studio/sync/file-plane.ts +289 -22
  359. package/apps/studio/sync/held-deletes.ts +86 -5
  360. package/apps/studio/sync/hub-link.ts +8 -0
  361. package/apps/studio/sync/index.ts +196 -12
  362. package/apps/studio/sync/journal-client.ts +50 -4
  363. package/apps/studio/sync/link-consent.ts +22 -75
  364. package/apps/studio/sync/link-survey.ts +252 -0
  365. package/apps/studio/sync/local-kernel.ts +296 -8
  366. package/apps/studio/sync/projection.ts +22 -3
  367. package/apps/studio/sync/seed-progress.ts +12 -0
  368. package/apps/studio/sync/source-recovery.ts +59 -3
  369. package/apps/studio/sync/status.ts +19 -2
  370. package/apps/studio/sync/unsynced-refs.ts +397 -0
  371. package/apps/studio/sync/writer-registry.ts +20 -0
  372. package/apps/studio/thumbs/service.ts +4 -1
  373. package/apps/studio/tool-palette.tsx +23 -0
  374. package/apps/studio/ui-prefs.ts +40 -0
  375. package/apps/studio/use-agent-presence.tsx +2 -2
  376. package/apps/studio/use-canvas-keys.ts +6 -1
  377. package/apps/studio/video/format-ids.ts +2 -2
  378. package/apps/studio/video/inject.ts +31 -0
  379. package/apps/studio/video/media-risk.ts +58 -0
  380. package/apps/studio/video/object-fit.ts +137 -0
  381. package/apps/studio/video/provider-transcript.ts +141 -0
  382. package/apps/studio/whats-new.json +137 -0
  383. package/apps/studio/workspace-mode.ts +1 -0
  384. package/apps/studio/ws.ts +5 -0
  385. package/cli/commands/design.mjs +119 -8
  386. package/cli/lib/bash-guard.mjs +366 -6
  387. package/cli/lib/confine-read.mjs +1 -0
  388. package/cli/lib/design-help.gen.mjs +3 -2
  389. package/cli/lib/design-hook.mjs +387 -81
  390. package/cli/lib/design-link.mjs +16 -1
  391. package/cli/lib/design-open.mjs +49 -3
  392. package/cli/lib/desktop-locate.mjs +770 -0
  393. package/cli/lib/handoff.mjs +1 -1
  394. package/cli/lib/hook-state.mjs +291 -0
  395. package/cli/lib/pkg-root.mjs +65 -13
  396. package/cli/lib/studio-locate.mjs +59 -16
  397. package/package.json +15 -8
  398. package/plugins/design/templates/_shell.html +13 -0
  399. package/apps/studio/client/v2/onboarding/HubSheet.jsx +0 -212
  400. package/apps/studio/client/v2/shell/account-card-model.js +0 -114
  401. package/apps/studio/client/v2/shell/account-card.jsx +0 -189
@@ -2,6 +2,7 @@ import { claimCreatedCanvas, runForCreate } from './ai/create-claim.ts';
2
2
  import {
3
3
  claimWritesForChat,
4
4
  hookClaims,
5
+ noWriteClaim,
5
6
  routeWriteClaim,
6
7
  withWriteClaim,
7
8
  } from './ai/write-claim.ts';
@@ -20,7 +21,7 @@ import { MAX_ANNOTATIONS_BYTES } from './sync/limits.ts';
20
21
  // top-level fall-through for paths Bun's `routes` field doesn't cover.
21
22
 
22
23
  import { createHash, timingSafeEqual } from 'node:crypto';
23
- import { existsSync, readFileSync, realpathSync, unlinkSync, watch } from 'node:fs';
24
+ import { existsSync, readFileSync, realpathSync, rmSync, unlinkSync, watch } from 'node:fs';
24
25
  import { basename, join, posix, relative, resolve, sep } from 'node:path';
25
26
  // Ownership mutations live with the CLI on purpose — see /_api/sync/ownership.
26
27
  import { adoptToHub, detachToRepo, ownershipState } from '../../cli/lib/design-ownership.mjs';
@@ -104,6 +105,7 @@ import { actionsManifestVersion } from './actions/manifest-version.ts';
104
105
  import { createLocalLeaseHome } from './ai/lease-home.ts';
105
106
  import { createRunRegistry, type RunRegistry } from './ai/runs.ts';
106
107
  import { type Api, ASSET_CHUNK_BYTES, ASSET_MAX_BYTES, ASSET_MAX_VIDEO_BYTES } from './api.ts';
108
+ import { addedRelOf, recordAssetAdded } from './asset-added.ts';
107
109
  import { importBrandRequest } from './bin/_brand-site.mjs';
108
110
  import { buildCanvasModule } from './canvas-build.ts';
109
111
  import {
@@ -112,6 +114,14 @@ import {
112
114
  sandboxFailureClass,
113
115
  withBuildSlot,
114
116
  } from './canvas-build-sandbox.ts';
117
+ import {
118
+ invalidateSharedCanvasLib,
119
+ SHARED_LIB_SLUG_RE,
120
+ type SharedCanvasLib,
121
+ sharedCanvasLib,
122
+ sharedCanvasLibByHash,
123
+ withSharedCanvasLib,
124
+ } from './canvas-lib-module.ts';
115
125
  import { canvasLibPath } from './canvas-lib-resolver.ts';
116
126
  import { budgetFromEnv, createModuleCache, moduleBytes } from './canvas-module-cache.ts';
117
127
  import { TranspileError } from './canvas-pipeline.ts';
@@ -211,6 +221,12 @@ import {
211
221
  hasProvider,
212
222
  listProviders,
213
223
  } from './generation/registry.ts';
224
+ import {
225
+ createSpendGuard,
226
+ estimateJobCost,
227
+ readSpendSettings,
228
+ type SpendGuard,
229
+ } from './generation/spend.ts';
214
230
  import { validateGenRequest } from './generation/types.ts';
215
231
  import {
216
232
  downloadWhisperModel,
@@ -286,6 +302,16 @@ import {
286
302
  import { checkRouteTable, mountRoutes, type RouteSpec } from './routes/table.ts';
287
303
  import { getRuntimeBundle, packageForSlug } from './runtime-bundle.ts';
288
304
  import { currentSession } from './session-scope.ts';
305
+ import {
306
+ apiKeyRequired,
307
+ bootApiKey,
308
+ credentialRouteRefusal,
309
+ mintLaunchToken,
310
+ personRequest,
311
+ requestCredential,
312
+ } from './shell/api-key.ts';
313
+ import { setLocalCaptureResolver } from './shell/capture-url.ts';
314
+ import { writeLinkFile } from './shell/key-file.ts';
289
315
  import { resolveProfile } from './shell/profile.ts';
290
316
  import {
291
317
  cacheControlFor,
@@ -311,7 +337,14 @@ import { workspaceDisclosure } from './sync/workspace-signin.ts';
311
337
  import { thumbNotFound, thumbResponse, wantResponse } from './thumbs/routes.ts';
312
338
  import { BOOT_COVERS_DELAY_MS, createThumbService } from './thumbs/service.ts';
313
339
  import { normalizeTreeState } from './tree-state.ts';
314
- import { readUiPrefs, validateUiPrefsPatch, writeUiPrefs } from './ui-prefs.ts';
340
+ import {
341
+ readUiPrefs,
342
+ scopeRecentColoursRead,
343
+ scopeRecentColoursWrite,
344
+ validateUiPrefsPatch,
345
+ writeUiPrefs,
346
+ } from './ui-prefs.ts';
347
+ import { persistCloudTranscript } from './video/provider-transcript.ts';
315
348
  import { loadWhatsNew, resolveMaudeVersion } from './whats-new.ts';
316
349
  import { isWorkspaceMode, resolveRenderLane } from './workspace-mode.ts';
317
350
  import { isLoopbackHost } from './ws.ts';
@@ -669,6 +702,53 @@ export function claimingTableRoute(
669
702
  };
670
703
  }
671
704
 
705
+ /**
706
+ * D5 — legacy routes that START long-lived work (an ACP chat, export / generate jobs, sync and its
707
+ * settings, a hub or cloud link, git, an install): nothing they write — now or from what they schedule —
708
+ * is a run's. AsyncLocalStorage carries a claim into every continuation, so they answer under
709
+ * `noWriteClaim` instead of the request's claim.
710
+ */
711
+ const NO_CLAIM_LEGACY =
712
+ /^\/(?:_sync-status$|_api\/(?:acp|sync|hub|cloud|git|github|claude|figma|generate|export)(?:[/-]|$))/;
713
+
714
+ /**
715
+ * #164 B4 — the legacy `routes` literal's writes answer inside the run's claim the same way
716
+ * (`claimingTableRoute`): an AI `curl-local` POST naming its chat to `/_api/insert-artboard`,
717
+ * `/_api/set-artboard-label`, `/_api/edit-array-src`, `/_api/canvas-meta`, `/_api/annotations`, … then
718
+ * claims its bytes into the run instead of landing as the person's edit. F2 — this is the MAIN origin's
719
+ * map: a canvas-safe path is wrapped here too, and the canvas listeners mount the unwrapped handler
720
+ * (`Http.unclaimed`, routes/canvas-origin.ts) — the gate is the listener, never the path, because the
721
+ * untrusted frame can set any header on its own origin. Never wrapped: `/_api/canvas` (create and
722
+ * delete claim inside their own handler), and the hook / flush paths `claimingTableRoute` leaves alone.
723
+ * A read is passed straight through.
724
+ */
725
+ export function claimingLegacyRoutes<
726
+ T extends Record<string, (req: Request) => Response | Promise<Response>>,
727
+ >(routes: T, runs: Parameters<typeof routeWriteClaim>[1]): T {
728
+ const exempt = (p: string) =>
729
+ p === '/_api/canvas' ||
730
+ p.startsWith('/_api/agent/') ||
731
+ p === '/_api/diagnostics/save-hold-flush';
732
+ const out: Record<string, (req: Request) => Response | Promise<Response>> = {};
733
+ for (const [p, handler] of Object.entries(routes)) {
734
+ out[p] =
735
+ exempt(p) || typeof handler !== 'function'
736
+ ? handler
737
+ : NO_CLAIM_LEGACY.test(p)
738
+ ? (req: Request) => noWriteClaim(() => handler(req))
739
+ : (req: Request) =>
740
+ req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS'
741
+ ? handler(req)
742
+ : withWriteClaim(
743
+ sameOriginWrite(req) && isTrustedRequestHost(req)
744
+ ? routeWriteClaim(req, runs)
745
+ : null,
746
+ () => handler(req)
747
+ );
748
+ }
749
+ return out as T;
750
+ }
751
+
672
752
  // ─────────────────────────────────────────────────────────────────────────────
673
753
  // Cloud Phase 25 C2 — the local half of the read-only gate.
674
754
  //
@@ -847,6 +927,24 @@ export type CanvasInputsGate = ((inputs: readonly string[], entry: string) => Re
847
927
  // boot id in means a restart — the expected workflow after a dev-server source
848
928
  // edit (see CLAUDE.md) — changes every canvas etag, so a normal reload re-fetches
849
929
  // fresh chrome. (DDR-067.)
930
+ /**
931
+ * #169 T8.1c — the shared `@maude/canvas-lib` module (canvas-lib-module.ts) for a canvas build served
932
+ * on this server, or null to inline canvas-lib as before: in a cell (the sandboxed build keeps
933
+ * inlining), with `MAUDE_SHARED_CANVAS_LIB=0`, or when the shared build failed. The shell maps the
934
+ * specifier under exactly the same answer (`serveCanvasShell`), which is sticky per chrome version,
935
+ * so a module that imports it is only ever served beside a shell that maps it.
936
+ */
937
+ async function sharedLibForCanvas(): Promise<SharedCanvasLib | null> {
938
+ if (isWorkspaceMode() || process.env.MAUDE_SHARED_CANVAS_LIB === '0') return null;
939
+ return sharedCanvasLib().catch((err) => {
940
+ console.warn(
941
+ '[canvas-lib] shared module unavailable, inlining:',
942
+ err instanceof Error ? err.message : err
943
+ );
944
+ return null;
945
+ });
946
+ }
947
+
850
948
  /** When this server process started — anything it wrote is stamped after it. */
851
949
  const PROCESS_STARTED_AT = Date.now();
852
950
  const RUNTIME_BOOT_ID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`;
@@ -1020,8 +1118,10 @@ export async function serveCanvasTsx(
1020
1118
  try {
1021
1119
  // 2.0.7 (#3) — in one of the server's build slots, like the sandbox's workers: a design system
1022
1120
  // opening asks for many builds at once, and each in-process Bun.build holds its own module graph.
1121
+ const sharedLib = await sharedLibForCanvas();
1023
1122
  result = await withBuildSlot(() =>
1024
1123
  buildCanvasModule(absPath, source, {
1124
+ ...(sharedLib ? { sharedCanvasLib: sharedLib } : {}),
1025
1125
  designRoot: ctx.paths.designRoot,
1026
1126
  // UNCONDITIONAL, desktop included (feature-sync-file-plane, Task 9 —
1027
1127
  // the binding debate's CONDITION on the `code-module` class): a
@@ -1332,8 +1432,10 @@ async function serveHistoricalCanvas(
1332
1432
  const css = await laneAtRef(versionReaders(ctx), repoRel, sha, 'css', from);
1333
1433
  const cssSig = css == null ? todayCssSig(absPath) : null;
1334
1434
  try {
1435
+ const sharedLib = await sharedLibForCanvas();
1335
1436
  const result = await withBuildSlot(() =>
1336
1437
  buildCanvasModule(absPath, source, {
1438
+ ...(sharedLib ? { sharedCanvasLib: sharedLib } : {}),
1337
1439
  overrides: cssOverridesFor(absPath, css),
1338
1440
  designRoot: ctx.paths.designRoot,
1339
1441
  // Same unconditional allowlist as the live build above — a HISTORICAL
@@ -1524,6 +1626,11 @@ export interface Http {
1524
1626
  * allowlists derive them: `CANVAS_SAFE_API` here and routes/canvas-origin.ts.
1525
1627
  */
1526
1628
  tableCanvasPaths: readonly string[];
1629
+ /**
1630
+ * F2 — the canvas-safe legacy paths (CANVAS_SAFE_API) as the canvas listeners mount them: guarded,
1631
+ * but never inside a run's write claim. `routes` carries the main origin's claim-wrapped copy.
1632
+ */
1633
+ unclaimed: Record<string, (req: Request) => Response | Promise<Response>>;
1527
1634
  /** S9.9 — THIS request's access (V2-1.7 §5.4); server.ts `withSession` puts it in ALS. */
1528
1635
  accessOf(req?: Request): Access;
1529
1636
  /** S9.11 — the closure of a session's grants on this child's disk (null without grants). */
@@ -1588,6 +1695,14 @@ export function createHttp(
1588
1695
  * captured instance would hand one member another's open canvas. */
1589
1696
  const inspect = () => inspects.for(currentSession());
1590
1697
 
1698
+ // The spend cap on paid media generation (generation/spend.ts): per-run + per-day caps for this project and a
1699
+ // confirm above a threshold, the numbers from the per-Mac prefs. A new approval pushes to the app (WebSocket).
1700
+ const spendGuard: SpendGuard = createSpendGuard({
1701
+ designRoot: ctx.paths.designRoot,
1702
+ settings: () => readSpendSettings(readUiPrefs().generateSpend),
1703
+ onApproval: (a) => ctx.bus.emit('generate:approval', a),
1704
+ });
1705
+
1591
1706
  // V2-2.9 (T23) — the Diagnostics API's status providers for the sources this layer owns
1592
1707
  // (sync registers itself in server.ts). Cheap, synchronous snapshots; scrubbed on read.
1593
1708
  const countBy = (items: { status?: string }[]) =>
@@ -1646,6 +1761,7 @@ export function createHttp(
1646
1761
  ctx.bus.on('fs:any', (rel: string) => {
1647
1762
  if (rel.startsWith('_lib/')) {
1648
1763
  canvasCache.clear();
1764
+ invalidateSharedCanvasLib();
1649
1765
  CHROME_EPOCH++;
1650
1766
  }
1651
1767
  });
@@ -1654,6 +1770,7 @@ export function createHttp(
1654
1770
  try {
1655
1771
  libWatcher = watch(canvasLibPath(), () => {
1656
1772
  canvasCache.clear();
1773
+ invalidateSharedCanvasLib();
1657
1774
  CHROME_EPOCH++;
1658
1775
  ctx.bus.emit('fs:any', '_lib/canvas-lib.tsx');
1659
1776
  });
@@ -2168,6 +2285,20 @@ export function createHttp(
2168
2285
  // S8.5 — the Render row: a cloud door on this Mac, and a comp's own length (Suggest each time)
2169
2286
  cloudRender: () => resolveRenderLane() === 'local' && cloudExports.available(),
2170
2287
  videoSeconds: (rel) => cloudFacts.videoSeconds(rel),
2288
+ // #128 T3.7b — Cancel: a cloud row on a desktop (the hub is asked), else one of THIS session's jobs
2289
+ cancel: async (id, session) => {
2290
+ if (!isWorkspaceMode()) {
2291
+ const c = await cloudExports.cancel(id);
2292
+ if (c.ok) return { ok: true };
2293
+ if (c.code !== 'not-found')
2294
+ return {
2295
+ ok: false,
2296
+ reason: c.code === 'not-running' || c.code === 'forbidden' ? c.code : 'unreachable',
2297
+ };
2298
+ }
2299
+ const r = exportJobs.cancel(id, session);
2300
+ return r.ok ? { ok: true } : { ok: false, reason: r.reason };
2301
+ },
2171
2302
  // S8.4 — Retry: only the failed items of one of THIS session's group jobs
2172
2303
  retry: (id, items, session, allow) => exportJobs.retry(id, items, session, allow),
2173
2304
  // S8.7 — the Print preflight: fonts are read under the design root; the safe margin is measured from the
@@ -2397,9 +2528,6 @@ export function createHttp(
2397
2528
  legacyEntries: () => ai.list(),
2398
2529
  // S9.11 (V2-1.16 L13) — a canvas-only session's runs and banner entries
2399
2530
  seerFor: (req) => seerFor(req),
2400
- // T16 — a v1 `/design:edit` is ONE project action
2401
- beginAction: (key, name) => ctx.syncControl?.current?.()?.beginAiAction?.(key, name),
2402
- endAction: (key, outcome) => ctx.syncControl?.current?.()?.endAiAction?.(key, outcome),
2403
2531
  // S5.11b — Run on a copy: the accepted source + the waiting run's stage
2404
2532
  control: () => ctx.syncControl?.current?.() ?? null,
2405
2533
  // S5.18 (G2) — the copy's name + place go into the canvas sidecar through the layout-write door
@@ -2483,7 +2611,12 @@ export function createHttp(
2483
2611
  },
2484
2612
  // S11.11 — POST /_api/sync/resync (routes/sync.ts), moved from the legacy literal.
2485
2613
  // gate-b-sec4 — GET /_api/sync/link + POST /_api/sync/link/confirm: the parked committed link.
2486
- sync: { control: () => ctx.syncControl, trace: resyncTrace, link: createLinkGate(ctx) },
2614
+ sync: {
2615
+ control: () => ctx.syncControl,
2616
+ trace: resyncTrace,
2617
+ link: createLinkGate(ctx),
2618
+ designRoot: ctx.paths.designRoot,
2619
+ },
2487
2620
  // S11.13 — Settings › Advanced reads: the decision-memory count and the bundled plugin versions.
2488
2621
  settings: { repoRoot: ctx.paths.repoRoot },
2489
2622
  // S5.7 — the chat store's search / trash / resume-session routes (routes/chat.ts).
@@ -2582,6 +2715,8 @@ export function createHttp(
2582
2715
  announce: (rel) => {
2583
2716
  if (isWorkspaceMode()) ctx.bus.emit('fs:any', rel);
2584
2717
  },
2718
+ // #172 — "Added by" travels with the project: the vouched member in a cell, else this Mac's git user.
2719
+ addedBy: (req) => assetAddedWho(req),
2585
2720
  },
2586
2721
  // S8.20 — /_api/describe* (routes/describe.ts): search in pictures — the consent, Stop, and what AI saw. A Mac only.
2587
2722
  describe: {
@@ -2621,6 +2756,7 @@ export function createHttp(
2621
2756
  return ab ? { w: ab.w, h: ab.h, label: ab.label } : null;
2622
2757
  },
2623
2758
  jobs: generateJobs,
2759
+ spend: spendGuard,
2624
2760
  saveAsset: (bytes) => api.saveAsset(bytes),
2625
2761
  emit: (g) => ctx.bus.emit('generate:takes', g),
2626
2762
  }),
@@ -2696,6 +2832,14 @@ export function createHttp(
2696
2832
  linkedHubUrl: () => ctx.cfg.linkedHub?.url,
2697
2833
  restartSync: () => ctx.syncControl?.restart(),
2698
2834
  },
2835
+ // 2.1.1 — POST /_api/hub/link-folder (routes/hub-link-folder.ts): main origin, window only, on the attach lane.
2836
+ hubLinkFolder: {
2837
+ designRoot: ctx.paths.designRoot,
2838
+ repoRoot: ctx.paths.repoRoot,
2839
+ canvasGroups: () => ctx.cfg.canvasGroups,
2840
+ localFormat: () => asFormat(ctx.cfg.formatVersion),
2841
+ attachStored: (url) => cloudApi.attachStored(url),
2842
+ },
2699
2843
  }).map(guardTableRoute);
2700
2844
  // p8-a1-claims — outside the gates: a write that names an AI chat answers inside its run's claim
2701
2845
  // (in place, so every consumer of the table — the mount, the local gate — sees the same specs)
@@ -3487,14 +3631,31 @@ export function createHttp(
3487
3631
  const body = await readJson<{ canvas?: unknown }>(req);
3488
3632
  const canvas = typeof body?.canvas === 'string' ? body.canvas : '';
3489
3633
  const out = join(ctx.paths.designRoot, '_reports', `shell-${Date.now()}.png`);
3634
+ // A key-required server (sec-loopback-bearer §7) answers the shell page only to a caller with
3635
+ // its key: the capture gets a one-time launch link minted in-process, through a 0600 file in
3636
+ // the server's private link folder (shell/key-file.ts `serverLinkDir`, which the AI chat's Read
3637
+ // is denied; screenshot.sh takes only a file from there) — never argv, which `ps` shows to every
3638
+ // process of this user.
3639
+ let linkFile: string | null = null;
3640
+ let target: string[] = ['--port', port];
3641
+ if (apiKeyRequired()) {
3642
+ linkFile = writeLinkFile(
3643
+ `http://localhost:${port}/?maude-launch=${mintLaunchToken(bootApiKey(), undefined, 'helper')}`
3644
+ );
3645
+ if (!linkFile)
3646
+ return Response.json(
3647
+ { error: 'shell capture failed: could not write its link' },
3648
+ { status: 502 }
3649
+ );
3650
+ target = ['--url-file', linkFile];
3651
+ }
3490
3652
  try {
3491
3653
  const proc = Bun.spawn(
3492
3654
  [
3493
3655
  'bash',
3494
3656
  join(BIN_DIR, 'screenshot.sh'),
3495
3657
  '--shell',
3496
- '--port',
3497
- port,
3658
+ ...target,
3498
3659
  '--out',
3499
3660
  out,
3500
3661
  '--root',
@@ -3531,6 +3692,8 @@ export function createHttp(
3531
3692
  });
3532
3693
  } catch (e) {
3533
3694
  return Response.json({ error: `shell capture failed: ${String(e)}` }, { status: 502 });
3695
+ } finally {
3696
+ if (linkFile) rmSync(linkFile, { force: true });
3534
3697
  }
3535
3698
  },
3536
3699
 
@@ -3835,7 +3998,8 @@ export function createHttp(
3835
3998
  },
3836
3999
 
3837
4000
  // S5.3 — `/_api/ai` (GET, canvas-safe) and `/_api/ai/start|heartbeat|end` moved to
3838
- // routes/ai.ts, on the run registry (the banner is derived from it).
4001
+ // routes/ai.ts, on the run registry (the banner is derived from it). T2.5b: the three POSTs
4002
+ // answer 410 Gone (the design plugin's hooks own the run, `/_api/agent/run/begin`).
3839
4003
 
3840
4004
  '/_api/sync/offline': async (req: Request) => {
3841
4005
  // T19 — "Download everything for offline": every file of the project
@@ -6010,6 +6174,7 @@ export function createHttp(
6010
6174
  { status: result.status ?? 400, headers: { 'Cache-Control': 'no-store' } }
6011
6175
  );
6012
6176
  }
6177
+ if (result.path) await recordUploadAdded(req, result.path);
6013
6178
  return Response.json(
6014
6179
  { path: result.path },
6015
6180
  { status: 201, headers: { 'Cache-Control': 'no-store' } }
@@ -6093,6 +6258,7 @@ export function createHttp(
6093
6258
  { status: result.status ?? 400, headers: { 'Cache-Control': 'no-store' } }
6094
6259
  );
6095
6260
  }
6261
+ if (result.path) await recordUploadAdded(req, result.path);
6096
6262
  return Response.json(
6097
6263
  { path: result.path },
6098
6264
  { status: 201, headers: { 'Cache-Control': 'no-store' } }
@@ -6522,7 +6688,7 @@ export function createHttp(
6522
6688
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
6523
6689
  if (req.method === 'GET') {
6524
6690
  return Response.json(
6525
- { jobs: generateJobs.list() },
6691
+ { jobs: generateJobs.list(), approvals: spendGuard.pending(), spent: spendGuard.spent() },
6526
6692
  { headers: { 'Cache-Control': 'no-store' } }
6527
6693
  );
6528
6694
  }
@@ -6531,6 +6697,24 @@ export function createHttp(
6531
6697
  return new Response('cross-origin write rejected', { status: 403 });
6532
6698
  const body = await readJson<Record<string, unknown>>(req, 64 * 1024);
6533
6699
  if (!body) return new Response('body required', { status: 400 });
6700
+ // The person's answer to a "needs your OK" card. Only the app's page can give it: a browser always
6701
+ // sends Origin on a POST, the `maude design generate` verb (curl) never does.
6702
+ if (typeof body.approve === 'string' || typeof body.decline === 'string') {
6703
+ // sec-loopback-bearer §7.8 — in required mode, the page's own session on a same-origin
6704
+ // request; the header key every helper and verb sends never answers it
6705
+ if (!personRequest(req))
6706
+ return Response.json(
6707
+ { ok: false, message: 'This is answered in Maude, not from a command.' },
6708
+ { status: 403, headers: { 'Cache-Control': 'no-store' } }
6709
+ );
6710
+ const id = (body.approve ?? body.decline) as string;
6711
+ const done =
6712
+ typeof body.approve === 'string' ? spendGuard.approve(id) : spendGuard.decline(id);
6713
+ return Response.json(
6714
+ { ok: done },
6715
+ { status: done ? 200 : 404, headers: { 'Cache-Control': 'no-store' } }
6716
+ );
6717
+ }
6534
6718
  const check = validateGenRequest(body);
6535
6719
  if (!check.ok) return new Response(check.errors.join('; '), { status: 400 });
6536
6720
  const genReq = body as unknown as import('./generation/types.ts').GenRequest;
@@ -6542,6 +6726,32 @@ export function createHttp(
6542
6726
  status: 400,
6543
6727
  });
6544
6728
 
6729
+ // The spend cap: estimate, check the per-run + per-day caps and the confirm threshold BEFORE anything is
6730
+ // queued or sent. A stop is JSON (reason + message), never a plain string the verb has to scrape.
6731
+ const estimate = estimateJobCost(genReq);
6732
+ const admitted = spendGuard.admit({
6733
+ key: new Bun.CryptoHasher('sha256')
6734
+ .update(
6735
+ JSON.stringify([
6736
+ genReq.provider,
6737
+ genReq.modality,
6738
+ genReq.model ?? '',
6739
+ genReq.prompt ?? '',
6740
+ genReq.sourceAsset ?? '',
6741
+ genReq.aspectRatio ?? '',
6742
+ genReq.params ?? null,
6743
+ ])
6744
+ )
6745
+ .digest('hex'),
6746
+ estimate,
6747
+ summary: `${genReq.modality === 'image' ? 'a picture' : `a ${genReq.modality} clip`} from ${descriptor?.label ?? genReq.provider}`,
6748
+ approvalId: typeof body.approvalId === 'string' ? body.approvalId : undefined,
6749
+ });
6750
+ if (!admitted.ok) {
6751
+ const { status, ...why } = admitted;
6752
+ return Response.json(why, { status, headers: { 'Cache-Control': 'no-store' } });
6753
+ }
6754
+
6545
6755
  try {
6546
6756
  const { id } = generateJobs.enqueue({
6547
6757
  provider: genReq.provider,
@@ -6551,71 +6761,94 @@ export function createHttp(
6551
6761
  // per-request adapter context with the saveAsset-backed localizer, and
6552
6762
  // submit → result → localize each produced asset into assets/<sha8>.
6553
6763
  run: async (signal) => {
6554
- const apiKey = await getProviderKey(genReq.provider);
6555
- const adapter = createAdapter(genReq.provider, {
6556
- apiKey,
6557
- signal,
6558
- localize: (asset) => localizeGenAsset(asset, { saveAsset: api.saveAsset }),
6559
- // Task 1.2 — source-asset access for the maskless-edit / i2v flows
6560
- // (Nano Banana reads the source into an inlineData part). Contained
6561
- // to assets/ host-side; the adapter never touches the filesystem.
6562
- readSourceAsset: (rel) => api.readAssetBytes(rel),
6563
- });
6564
- const job = await adapter.submit(genReq);
6565
- const result = await job.result();
6566
- const assets: string[] = [];
6567
- for (const asset of result.assets) {
6568
- // Task 2.6 — a CLOUD STT result (ElevenLabs Scribe / Groq) is
6569
- // caption TEXT, not media: it lands as a `assets/<sha8>.srt|.vtt`
6570
- // sidecar next to its source (the SAME path the local whisper verb
6571
- // writes), never through the magic-byte media store. Everything
6572
- // else (image/video/audio) localizes into the content-addressed
6573
- // media store as before.
6574
- if (asset.kind === 'transcription' && typeof asset.text === 'string') {
6575
- if (!genReq.sourceAsset)
6576
- throw new Error('transcription result has no source asset to sidecar');
6577
- const fmt = asset.mime === 'text/vtt' ? 'vtt' : 'srt';
6578
- const saved = await api.writeCaptionSidecar(genReq.sourceAsset, fmt, asset.text);
6579
- if (!saved.ok || !saved.path)
6580
- throw new Error(`caption sidecar write failed: ${saved.error ?? 'unknown'}`);
6581
- assets.push(saved.path);
6582
- } else {
6583
- assets.push(await localizeGenAsset(asset, { saveAsset: api.saveAsset }));
6584
- }
6585
- }
6586
- // Task 2.5 — record the AUDIO INTENT next to a generated audio asset
6587
- // (the durable, semantic reuse index) so a later near-identical
6588
- // request can offer the existing track instead of paying again.
6589
- if (genReq.modality === 'audio' && assets.length > 0) {
6590
- const kind = (genReq.params as Record<string, unknown> | undefined)?.audioKind;
6591
- await api.writeAudioIntent(assets[0], {
6592
- kind: typeof kind === 'string' ? kind : undefined,
6593
- prompt: genReq.prompt,
6594
- provider: genReq.provider,
6595
- model: genReq.model,
6764
+ try {
6765
+ const apiKey = await getProviderKey(genReq.provider);
6766
+ const adapter = createAdapter(genReq.provider, {
6767
+ apiKey,
6768
+ signal,
6769
+ localize: (asset) => localizeGenAsset(asset, { saveAsset: api.saveAsset }),
6770
+ // Task 1.2 — source-asset access for the maskless-edit / i2v flows
6771
+ // (Nano Banana reads the source into an inlineData part). Contained
6772
+ // to assets/ host-side; the adapter never touches the filesystem.
6773
+ readSourceAsset: (rel) => api.readAssetBytes(rel),
6596
6774
  });
6597
- }
6598
- // Task 3.2 — a generated VIDEO clip gets a provenance FootageAnalysis
6599
- // stub next to it (assets/<sha8>.footage.json), so it is immediately
6600
- // KNOWN to the footage/reel pipeline: the director sees the clip is
6601
- // synthetic (the `ai-generated` tag) and what it was made for (the
6602
- // prompt), and the footage-analyst later fills the real shots. A
6603
- // sidecar hiccup must NOT lose the (expensive) clip — best-effort.
6604
- if (genReq.modality === 'video' && assets.length > 0) {
6605
- try {
6606
- await footageStore.saveAnalysis(
6607
- assets[0],
6608
- generatedClipAnalysis(assets[0], {
6609
- provider: genReq.provider,
6610
- model: genReq.model,
6611
- prompt: genReq.prompt,
6612
- })
6613
- );
6614
- } catch {
6615
- /* provenance-only — the clip already landed in assets/ */
6775
+ const job = await adapter.submit(genReq);
6776
+ const result = await job.result();
6777
+ const assets: string[] = [];
6778
+ for (const asset of result.assets) {
6779
+ // Task 2.6 — a CLOUD STT result (ElevenLabs Scribe / Groq) is
6780
+ // caption TEXT, not media: it lands as a `assets/<sha8>.srt|.vtt`
6781
+ // sidecar next to its source (the SAME path the local whisper verb
6782
+ // writes), never through the magic-byte media store. Everything
6783
+ // else (image/video/audio) localizes into the content-addressed
6784
+ // media store as before.
6785
+ if (asset.kind === 'transcription' && typeof asset.text === 'string') {
6786
+ if (!genReq.sourceAsset)
6787
+ throw new Error('transcription result has no source asset to sidecar');
6788
+ const fmt = asset.mime === 'text/vtt' ? 'vtt' : 'srt';
6789
+ const saved = await api.writeCaptionSidecar(genReq.sourceAsset, fmt, asset.text);
6790
+ if (!saved.ok || !saved.path)
6791
+ throw new Error(`caption sidecar write failed: ${saved.error ?? 'unknown'}`);
6792
+ assets.push(saved.path);
6793
+ // #128 §7 — the SRT is reflowed segments; the WORDS go to the same
6794
+ // `assets/<sha8>.transcript.json` the local engine writes, so word-by-word
6795
+ // captions and the Transcript panel work for every engine.
6796
+ const lang = (genReq.params as Record<string, unknown> | undefined)?.language;
6797
+ const kept = persistCloudTranscript(
6798
+ ctx.paths.designRoot,
6799
+ {
6800
+ provider: genReq.provider,
6801
+ model: genReq.model,
6802
+ sourceAsset: genReq.sourceAsset,
6803
+ lang: typeof lang === 'string' ? lang : undefined,
6804
+ },
6805
+ asset
6806
+ );
6807
+ if (!kept.path)
6808
+ console.error(
6809
+ `[transcribe] no word-timing sidecar for ${genReq.sourceAsset}: ${kept.skipped}`
6810
+ );
6811
+ } else {
6812
+ assets.push(await localizeGenAsset(asset, { saveAsset: api.saveAsset }));
6813
+ }
6814
+ }
6815
+ // Task 2.5 — record the AUDIO INTENT next to a generated audio asset
6816
+ // (the durable, semantic reuse index) so a later near-identical
6817
+ // request can offer the existing track instead of paying again.
6818
+ if (genReq.modality === 'audio' && assets.length > 0) {
6819
+ const kind = (genReq.params as Record<string, unknown> | undefined)?.audioKind;
6820
+ await api.writeAudioIntent(assets[0], {
6821
+ kind: typeof kind === 'string' ? kind : undefined,
6822
+ prompt: genReq.prompt,
6823
+ provider: genReq.provider,
6824
+ model: genReq.model,
6825
+ });
6826
+ }
6827
+ // Task 3.2 — a generated VIDEO clip gets a provenance FootageAnalysis
6828
+ // stub next to it (assets/<sha8>.footage.json), so it is immediately
6829
+ // KNOWN to the footage/reel pipeline: the director sees the clip is
6830
+ // synthetic (the `ai-generated` tag) and what it was made for (the
6831
+ // prompt), and the footage-analyst later fills the real shots. A
6832
+ // sidecar hiccup must NOT lose the (expensive) clip — best-effort.
6833
+ if (genReq.modality === 'video' && assets.length > 0) {
6834
+ try {
6835
+ await footageStore.saveAnalysis(
6836
+ assets[0],
6837
+ generatedClipAnalysis(assets[0], {
6838
+ provider: genReq.provider,
6839
+ model: genReq.model,
6840
+ prompt: genReq.prompt,
6841
+ })
6842
+ );
6843
+ } catch {
6844
+ /* provenance-only — the clip already landed in assets/ */
6845
+ }
6616
6846
  }
6847
+ return { assets, usage: result.usage };
6848
+ } catch (err) {
6849
+ admitted.refund(); // a job that failed was not paid for
6850
+ throw err;
6617
6851
  }
6618
- return { assets, usage: result.usage };
6619
6852
  },
6620
6853
  });
6621
6854
  // Don't await the run — the job's own status (GET + the generate:job WS
@@ -6626,6 +6859,7 @@ export function createHttp(
6626
6859
  { status: 202, headers: { 'Cache-Control': 'no-store' } }
6627
6860
  );
6628
6861
  } catch (err) {
6862
+ admitted.refund(); // never queued
6629
6863
  if (err instanceof GenerationQueueFullError)
6630
6864
  return new Response(err.message, { status: 429 });
6631
6865
  throw err;
@@ -6759,6 +6993,7 @@ export function createHttp(
6759
6993
  const prefs = readUiPrefs() as Record<string, unknown>;
6760
6994
  // V2-8.9 r2 F4 — a cell's one prefs.json is every member's: no shared Recent colours
6761
6995
  if (isWorkspaceMode()) delete prefs.recentColours;
6996
+ else scopeRecentColoursRead(prefs, rootIdentity(ctx.paths.repoRoot));
6762
6997
  return Response.json(prefs, { headers: { 'Cache-Control': 'no-store' } });
6763
6998
  }
6764
6999
  if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
@@ -6785,6 +7020,16 @@ export function createHttp(
6785
7020
  status: 403,
6786
7021
  headers: { 'Cache-Control': 'no-store' },
6787
7022
  });
7023
+ // The spend limits on paid generation are the PERSON's: set in Settings (a browser page, which sends
7024
+ // Origin), never from a command the AI runs, and only by a session that edits the project.
7025
+ if ('generateSpend' in patch && (!personRequest(req) || !accessOf(req).can('edit', null)))
7026
+ return Response.json(
7027
+ {
7028
+ error: 'spend-limits-in-settings',
7029
+ message: 'Generation spend limits are changed in Settings › Advanced, by you.',
7030
+ },
7031
+ { status: 403, headers: { 'Cache-Control': 'no-store' } }
7032
+ );
6788
7033
  // V2-8.9 r2 F4 — in a cell any member (a viewer too) could plant swatches every editor then sees and
6789
7034
  // clicks: Recent colours stay in the page there (the Inspector's store keeps them for the page).
6790
7035
  if ('recentColours' in patch && isWorkspaceMode())
@@ -6792,6 +7037,9 @@ export function createHttp(
6792
7037
  { error: 'recent-colours-cell', message: 'Recent colours are not saved in Maude Cloud.' },
6793
7038
  { status: 403, headers: { 'Cache-Control': 'no-store' } }
6794
7039
  );
7040
+ // #168 G3 — Recent colours are keyed by this project's own identity, never a name the client sends
7041
+ const scoped = scopeRecentColoursWrite(patch, rootIdentity(ctx.paths.repoRoot));
7042
+ if (scoped) return new Response(scoped, { status: 400 });
6795
7043
  try {
6796
7044
  return Response.json(writeUiPrefs(patch), { headers: { 'Cache-Control': 'no-store' } });
6797
7045
  } catch (err) {
@@ -7182,7 +7430,8 @@ export function createHttp(
7182
7430
  });
7183
7431
  if (routeProblems.length > 0)
7184
7432
  throw new Error(`[studio] the route table is unsound:\n ${routeProblems.join('\n ')}`);
7185
- const routes = { ...laneRoutes.exact, ...legacyRoutes };
7433
+ // #164 B4 — the legacy writes claim like the table's (claimingLegacyRoutes); the keys are unchanged
7434
+ const routes = { ...laneRoutes.exact, ...claimingLegacyRoutes(legacyRoutes, runs) };
7186
7435
 
7187
7436
  // Named `handleFallthrough`, not `fetch` — a same-named local function shadows
7188
7437
  // the global `fetch` for every call site in this module's scope, which is how
@@ -7243,6 +7492,23 @@ export function createHttp(
7243
7492
  // built once on first request, cached in-process for the session.
7244
7493
  if (pathname.startsWith('/_canvas-runtime/')) {
7245
7494
  const slugWithExt = decodeURIComponent(pathname.slice('/_canvas-runtime/'.length));
7495
+ // #169 T8.1c — the shared canvas-lib module, by the content hash the shell's importmap
7496
+ // names (the current build or one of the last few). Immutable: new bytes get a new URL.
7497
+ const libHash = SHARED_LIB_SLUG_RE.exec(slugWithExt)?.[1];
7498
+ if (libHash) {
7499
+ const lib = sharedCanvasLibByHash(libHash);
7500
+ if (!lib) return new Response('Not found', { status: 404 });
7501
+ const etag = `"${lib.hash}"`;
7502
+ const headers = {
7503
+ 'Content-Type': 'application/javascript; charset=utf-8',
7504
+ ETag: etag,
7505
+ 'Cache-Control': 'public, max-age=31536000, immutable',
7506
+ 'X-Content-Type-Options': 'nosniff',
7507
+ };
7508
+ if (req.headers.get('if-none-match') === etag)
7509
+ return new Response(null, { status: 304, headers });
7510
+ return new Response(lib.bytes, { status: 200, headers });
7511
+ }
7246
7512
  const pkg = packageForSlug(slugWithExt);
7247
7513
  if (!pkg) return new Response('Not found', { status: 404 });
7248
7514
  try {
@@ -7293,7 +7559,15 @@ export function createHttp(
7293
7559
  // render (?hide-chrome=1) that still lands here ALWAYS gets the
7294
7560
  // network-locked capture CSP so it can't SSRF/exfil (attacker F1).
7295
7561
  const capture = url.searchParams.get('hide-chrome') === '1';
7296
- return serveCanvasShell(process.env.MAUDE_CSP_POC === '1', capture, url.searchParams, req);
7562
+ // sec-loopback-bearer §7.3 — the shell is exempt from the key; a caller that sent none gets
7563
+ // the bare shell (nothing about the canvas it names)
7564
+ return serveCanvasShell(
7565
+ process.env.MAUDE_CSP_POC === '1',
7566
+ capture,
7567
+ url.searchParams,
7568
+ req,
7569
+ !authenticatedCaller(req)
7570
+ );
7297
7571
  }
7298
7572
 
7299
7573
  // DDR-150 dogfood — canvas-relative assets alias. A comp's
@@ -7625,7 +7899,24 @@ export function createHttp(
7625
7899
  return site === null || site === 'none' || site === 'same-origin';
7626
7900
  }
7627
7901
 
7902
+ /**
7903
+ * sec-loopback-bearer §7.3 — did this main-origin request carry the key or the page's session? The
7904
+ * shell routes are exempt from the key (every headless capture follows their 307), so the gate only
7905
+ * records what it saw. Outside required mode every caller counts (phase 1).
7906
+ */
7907
+ function authenticatedCaller(req: Request): boolean {
7908
+ return !apiKeyRequired() || requestCredential(req) !== null;
7909
+ }
7910
+
7628
7911
  function captureRedirect(url: URL, req: Request): Response | null {
7912
+ return captureRedirectFor(url, authenticatedCaller(req) && startedByUserAgent(req), req);
7913
+ }
7914
+
7915
+ /**
7916
+ * The 307 to the capture origin. `mint` = the redirect may carry a frame capability for the canvas
7917
+ * the URL names (an authenticated caller the user agent started, or the server itself).
7918
+ */
7919
+ function captureRedirectFor(url: URL, mint: boolean, req?: Request): Response | null {
7629
7920
  if (!ctx.captureOrigin) return null;
7630
7921
  // gate-b-c4 — the capture is a frame too: scoped to the canvas the URL names (a server-minted
7631
7922
  // capability; a URL naming no canvas, or a bad path, goes frame-less and reads nothing).
@@ -7639,8 +7930,9 @@ export function createHttp(
7639
7930
  // gate-b-c4d — minted only for a navigation the user agent or this origin started. Canvas A
7640
7931
  // running in a capture could otherwise `window.open` this URL for canvas B: the popup lands
7641
7932
  // on A's own (capture) origin, A reads `fc` from its `location` and reads B as the owner. Such
7642
- // a request (`same-site`) still redirects — frame-less, so the capture reads nothing.
7643
- const fc = rel && startedByUserAgent(req) ? frameCapFor(req, [rel]) : null;
7933
+ // a request (`same-site`) still redirects — frame-less, so the capture reads nothing. So does a
7934
+ // caller with no key on a key-required server (sec-loopback-bearer §7.3).
7935
+ const fc = rel && mint ? frameCapFor(req, [rel]) : null;
7644
7936
  if (fc) search.set(FRAME_PARAM, fc);
7645
7937
  const qs = search.toString();
7646
7938
  return new Response(null, {
@@ -7652,6 +7944,20 @@ export function createHttp(
7652
7944
  });
7653
7945
  }
7654
7946
 
7947
+ // sec-loopback-bearer §7.3 — the server's own headless captures (exporters, thumbnails) open the
7948
+ // capture origin directly: in required mode a child browser carries no key, so the redirect is
7949
+ // resolved here, with the capability minted for the server's own (local) subject.
7950
+ setLocalCaptureResolver((raw) => {
7951
+ if (!apiKeyRequired()) return raw;
7952
+ try {
7953
+ const u = new URL(raw);
7954
+ if (u.pathname !== '/_canvas-shell.html' && u.pathname !== '/_canvas-shell') return raw;
7955
+ return captureRedirectFor(u, true)?.headers.get('Location') ?? raw;
7956
+ } catch {
7957
+ return raw;
7958
+ }
7959
+ });
7960
+
7655
7961
  /** The meta lane of the canvas a `?sha=` shell renders, or null (no sha, no such lane, bad path). */
7656
7962
  async function versionMetaFor(query?: URLSearchParams): Promise<string | null> {
7657
7963
  const ref = query?.get('sha');
@@ -7695,7 +8001,8 @@ export function createHttp(
7695
8001
  applyCsp: boolean,
7696
8002
  capture: boolean,
7697
8003
  query: URLSearchParams | undefined,
7698
- req: Request
8004
+ req: Request,
8005
+ bare = false
7699
8006
  ): Promise<Response> {
7700
8007
  // `comment-mount.js` is versioned for the same reason as the studio page's
7701
8008
  // bundle (see `serveIndexHtml`): a fixed URL outlives a release in any
@@ -7705,10 +8012,14 @@ export function createHttp(
7705
8012
  const mountV = (await mount.exists())
7706
8013
  ? `?v=${mount.size.toString(16)}-${Math.trunc(mount.lastModified).toString(16)}`
7707
8014
  : '';
7708
- const shellHtml = (await Bun.file(join(TEMPLATES_DIR, '_shell.html')).text()).replace(
8015
+ const template = (await Bun.file(join(TEMPLATES_DIR, '_shell.html')).text()).replace(
7709
8016
  "'/_client/comment-mount.js'",
7710
8017
  `'/_client/comment-mount.js${mountV}'`
7711
8018
  );
8019
+ // #169 T8.1c — `@maude/canvas-lib` → the shared module, under the same answer the canvas builds
8020
+ // get (`sharedLibForCanvas`); before the CSP hashes the importmap script.
8021
+ const sharedLib = await sharedLibForCanvas();
8022
+ const shellHtml = sharedLib ? withSharedCanvasLib(template, sharedLib.url) : template;
7712
8023
  // Inject inspector overlay — Cmd+Click selection + add-comment flow, then the canvas
7713
8024
  // system's schema fallbacks (V2-1.13 §5.5 P-2: only the roles/classes it never declares,
7714
8025
  // inline — both canvas CSPs allow inline styles, so no new route).
@@ -7720,7 +8031,7 @@ export function createHttp(
7720
8031
  // module is refused to that frame anyway).
7721
8032
  const withInspector = inspect().injectInspector(shellHtml);
7722
8033
  let injected = withInspector;
7723
- if (shellCanvasVisible(req, query)) {
8034
+ if (!bare && shellCanvasVisible(req, query)) {
7724
8035
  const pastMeta = await versionMetaFor(query);
7725
8036
  injected = injectVersionMeta(
7726
8037
  injectFallbacks(
@@ -7879,6 +8190,30 @@ export function createHttp(
7879
8190
  // `x-maude-access` claim (DEFAULT CLOSED: no proven edit role = read-only); a
7880
8191
  // desktop reads the linked hub's stored claim (`accessFor`, re-read each call so
7881
8192
  // a sign-in lands on the next write); an unlinked project is the owner's.
8193
+ /**
8194
+ * #172 — who to write in `assets/<stem>.added.json` for a picture this request brings in. In a cell the proxy
8195
+ * vouches the member (`x-maude-user`; the header is read ONLY in workspace mode, where the proxy sets it — on a Mac
8196
+ * a browser could send any value, so it is never read there); on a Mac it is the git user. A server-derived value,
8197
+ * never a body field, so canvas code cannot name someone else.
8198
+ */
8199
+ async function assetAddedWho(req: Request): Promise<string> {
8200
+ const vouched = isWorkspaceMode() ? req.headers.get('x-maude-user') : null;
8201
+ return vouched?.slice(0, 120) || (await api.gitCurrentUser());
8202
+ }
8203
+
8204
+ /** #172 — write-once "Added by" record for a fresh upload; announced to peers in a cell. Never fails the upload. */
8205
+ async function recordUploadAdded(req: Request, assetPath: string): Promise<void> {
8206
+ try {
8207
+ const who = await assetAddedWho(req);
8208
+ if (recordAssetAdded(ctx.paths.designRoot, assetPath, who) && isWorkspaceMode()) {
8209
+ const rel = addedRelOf(assetPath);
8210
+ if (rel) ctx.bus.emit('fs:any', rel);
8211
+ }
8212
+ } catch {
8213
+ /* a missing line, never a failed upload */
8214
+ }
8215
+ }
8216
+
7882
8217
  function accessOf(req?: Request): Access {
7883
8218
  const base = isWorkspaceMode()
7884
8219
  ? accessFromProxy(req?.headers ?? new Headers())
@@ -8108,7 +8443,8 @@ export function createHttp(
8108
8443
  // comments this session sees — so an invisible id is a missing one (U1).
8109
8444
  if (access.grants.length > 0 && req.method === 'POST') {
8110
8445
  // S8.4 — Retry names a job, not a canvas: the route gates every canvas its items reach
8111
- if (pathname === '/_api/export-jobs/retry') return null;
8446
+ if (pathname === '/_api/export-jobs/retry' || pathname === '/_api/export-jobs/cancel')
8447
+ return null;
8112
8448
  if (V2_EXPORT_DOORS.has(pathname)) {
8113
8449
  const body = (await req
8114
8450
  .clone()
@@ -8181,15 +8517,26 @@ export function createHttp(
8181
8517
  return undefined;
8182
8518
  }
8183
8519
 
8520
+ // sec-loopback-bearer — a credential route needs the per-spawn API key from a caller that is not
8521
+ // a browser (shell/api-key.ts); it runs first, on the exact map and on the fall-through.
8184
8522
  const guardedRoutes = Object.fromEntries(
8185
8523
  Object.entries(routes).map(([path, handler]) => [
8186
8524
  path,
8187
- async (req: Request) => (await readOnlyRefusal(req)) ?? handler(req),
8525
+ async (req: Request) =>
8526
+ credentialRouteRefusal(req) ?? (await readOnlyRefusal(req)) ?? handler(req),
8188
8527
  ])
8189
8528
  ) as unknown as typeof routes;
8529
+ // F2 — the canvas listeners' copy of the hand-listed canvas-safe paths: the same guarded handler,
8530
+ // WITHOUT the claim wrapper (a canvas-origin request can never claim into a run)
8531
+ const own = legacyRoutes as Record<string, (req: Request) => Response | Promise<Response>>;
8532
+ const unclaimed = Object.fromEntries(
8533
+ [...CANVAS_SAFE_API]
8534
+ .filter((p) => typeof own[p] === 'function')
8535
+ .map((p) => [p, async (req: Request) => (await readOnlyRefusal(req)) ?? own[p](req)])
8536
+ ) as Http['unclaimed'];
8190
8537
 
8191
8538
  async function guardedFetch(req: Request): Promise<Response> {
8192
- return (await readOnlyRefusal(req)) ?? handleFallthrough(req);
8539
+ return credentialRouteRefusal(req) ?? (await readOnlyRefusal(req)) ?? handleFallthrough(req);
8193
8540
  }
8194
8541
 
8195
8542
  /**
@@ -8203,10 +8550,12 @@ export function createHttp(
8203
8550
  */
8204
8551
  async function annotationOps(req: Request, listener: 'main' | 'canvas'): Promise<Response> {
8205
8552
  if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
8206
- const body = await readJson<{ file?: unknown; actionId?: unknown; ops?: unknown }>(
8207
- req,
8208
- MAX_ANNOTATIONS_BYTES + 2048
8209
- );
8553
+ const body = await readJson<{
8554
+ file?: unknown;
8555
+ actionId?: unknown;
8556
+ ops?: unknown;
8557
+ label?: unknown;
8558
+ }>(req, MAX_ANNOTATIONS_BYTES + 2048);
8210
8559
  if (!body || typeof body.file !== 'string' || !body.file) {
8211
8560
  return new Response('body must include { file, actionId, ops }', { status: 400 });
8212
8561
  }
@@ -8235,6 +8584,8 @@ export function createHttp(
8235
8584
  // only through the vote door (routes/votes.ts → api.applyAnnotationOps in-process).
8236
8585
  const r = await api.applyAnnotationOps(body.file, ops, body.actionId as string | undefined, {
8237
8586
  guard: voteDoorOnly,
8587
+ // T7.3b (#113) — a person's gesture in words, untrusted (api.ts cleans it; a run batch drops it)
8588
+ ...(tag.runId === null && typeof body.label === 'string' ? { label: body.label } : {}),
8238
8589
  });
8239
8590
  if (r.refused) {
8240
8591
  return Response.json(
@@ -8274,6 +8625,7 @@ export function createHttp(
8274
8625
  return {
8275
8626
  routes: guardedRoutes,
8276
8627
  canvasRoutes,
8628
+ unclaimed,
8277
8629
  tableCanvasPaths: laneRoutes.canvasPaths,
8278
8630
  accessOf,
8279
8631
  frameScopeOf,