@1agh/maude 1.10.0 → 2.0.0-rc.2

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 (1985) hide show
  1. package/apps/hub/src/project-transactions/baseline.mjs +276 -0
  2. package/apps/hub/src/project-transactions/kernel.mjs +1756 -0
  3. package/apps/hub/src/project-transactions/lanes.mjs +287 -0
  4. package/apps/hub/src/project-transactions/runs-core.mjs +639 -0
  5. package/apps/hub/src/project-transactions/store-core.mjs +831 -0
  6. package/apps/studio/access/closure.ts +1075 -0
  7. package/apps/studio/access/filters.ts +1193 -0
  8. package/apps/studio/access/frame.ts +365 -0
  9. package/apps/studio/access/known-canvases.ts +82 -0
  10. package/apps/studio/access/request.ts +637 -0
  11. package/apps/studio/access/roles.ts +187 -0
  12. package/apps/studio/access/scope.ts +407 -0
  13. package/apps/studio/access/share-map.ts +434 -0
  14. package/apps/studio/acp/adapter-stderr.ts +22 -0
  15. package/apps/studio/acp/agent-path.ts +39 -0
  16. package/apps/studio/acp/ask-queue.ts +238 -0
  17. package/apps/studio/acp/audience.ts +615 -0
  18. package/apps/studio/acp/bootstrap-brief.ts +32 -15
  19. package/apps/studio/acp/bridge.ts +890 -114
  20. package/apps/studio/acp/chat-search.ts +195 -0
  21. package/apps/studio/acp/connected-fact.ts +83 -0
  22. package/apps/studio/acp/design-write-verb.ts +71 -0
  23. package/apps/studio/acp/env.ts +86 -0
  24. package/apps/studio/acp/index.ts +808 -58
  25. package/apps/studio/acp/login-state.ts +15 -1
  26. package/apps/studio/acp/may-scope.ts +771 -0
  27. package/apps/studio/acp/plugin-bootstrap.ts +90 -5
  28. package/apps/studio/acp/probe.ts +18 -4
  29. package/apps/studio/acp/repo-private.ts +73 -0
  30. package/apps/studio/acp/running.ts +50 -5
  31. package/apps/studio/acp/transcript.ts +356 -21
  32. package/apps/studio/acp/write-scope.ts +141 -11
  33. package/apps/studio/actions/agents.ts +2068 -0
  34. package/apps/studio/actions/canvas-keys.ts +41 -0
  35. package/apps/studio/actions/ctx.ts +118 -0
  36. package/apps/studio/actions/defs/_v1.ts +55 -0
  37. package/apps/studio/actions/defs/ai-runs.ts +56 -0
  38. package/apps/studio/actions/defs/annotation.ts +164 -0
  39. package/apps/studio/actions/defs/app.ts +269 -0
  40. package/apps/studio/actions/defs/canvas.ts +281 -0
  41. package/apps/studio/actions/defs/chat.ts +158 -0
  42. package/apps/studio/actions/defs/diagnostics.ts +52 -0
  43. package/apps/studio/actions/defs/ds.ts +139 -0
  44. package/apps/studio/actions/defs/edit.ts +986 -0
  45. package/apps/studio/actions/defs/export.ts +221 -0
  46. package/apps/studio/actions/defs/history.ts +175 -0
  47. package/apps/studio/actions/defs/native.ts +264 -0
  48. package/apps/studio/actions/defs/presence.ts +53 -0
  49. package/apps/studio/actions/defs/search.ts +90 -0
  50. package/apps/studio/actions/defs/sync.ts +47 -0
  51. package/apps/studio/actions/defs/timeline.ts +254 -0
  52. package/apps/studio/actions/defs/tool.ts +152 -0
  53. package/apps/studio/actions/defs/ui.ts +38 -0
  54. package/apps/studio/actions/defs/video.ts +115 -0
  55. package/apps/studio/actions/defs/view.ts +556 -0
  56. package/apps/studio/actions/documents.ts +32 -0
  57. package/apps/studio/actions/forward.ts +48 -0
  58. package/apps/studio/actions/help.ts +115 -0
  59. package/apps/studio/actions/index.ts +51 -0
  60. package/apps/studio/actions/keymap.gen.ts +1170 -0
  61. package/apps/studio/actions/keys.ts +271 -0
  62. package/apps/studio/actions/legacy.ts +250 -0
  63. package/apps/studio/actions/manifest-version.ts +18 -0
  64. package/apps/studio/actions/menu.ts +203 -0
  65. package/apps/studio/actions/native-menu.ts +132 -0
  66. package/apps/studio/actions/resolve.ts +118 -0
  67. package/apps/studio/actions/types.ts +266 -0
  68. package/apps/studio/actions/uniqueness.ts +119 -0
  69. package/apps/studio/actions/verbs.ts +306 -0
  70. package/apps/studio/actions.manifest.json +7826 -0
  71. package/apps/studio/actions.parity.json +268 -0
  72. package/apps/studio/activity.ts +4 -31
  73. package/apps/studio/agent-runs.ts +679 -0
  74. package/apps/studio/ai/attach-grants.ts +497 -0
  75. package/apps/studio/ai/copy-meta.ts +204 -0
  76. package/apps/studio/ai/create-claim.ts +88 -0
  77. package/apps/studio/ai/lease-home.ts +212 -0
  78. package/apps/studio/ai/run-doing.ts +106 -0
  79. package/apps/studio/ai/run-lifecycle.ts +337 -0
  80. package/apps/studio/ai/run-progress.ts +154 -0
  81. package/apps/studio/ai/runs.ts +1232 -0
  82. package/apps/studio/ai/save-hold.ts +565 -0
  83. package/apps/studio/ai/watch-progress.ts +182 -0
  84. package/apps/studio/ai/write-claim-scope.ts +39 -0
  85. package/apps/studio/ai/write-claim.ts +193 -0
  86. package/apps/studio/ai-banner.tsx +8 -14
  87. package/apps/studio/annotations/ai-read.ts +289 -1
  88. package/apps/studio/annotations/ai-write.ts +281 -23
  89. package/apps/studio/annotations/artboard-members.ts +86 -0
  90. package/apps/studio/annotations/board-ops.ts +358 -0
  91. package/apps/studio/annotations/board-schema.ts +81 -0
  92. package/apps/studio/annotations/constants.ts +2 -0
  93. package/apps/studio/annotations/elements/_shared.ts +290 -1
  94. package/apps/studio/annotations/elements/arrow.model.ts +29 -2
  95. package/apps/studio/annotations/elements/ballot.model.ts +110 -0
  96. package/apps/studio/annotations/elements/media.model.ts +11 -1
  97. package/apps/studio/annotations/elements/section.model.ts +3 -1
  98. package/apps/studio/annotations/elements/stamp.model.ts +83 -0
  99. package/apps/studio/annotations/elements/sticky.model.ts +235 -0
  100. package/apps/studio/annotations/elements/vote.model.ts +71 -0
  101. package/apps/studio/annotations/fields.ts +51 -0
  102. package/apps/studio/annotations/figjam-into.ts +119 -0
  103. package/apps/studio/annotations/hosts.ts +231 -0
  104. package/apps/studio/annotations/migrate-v1.ts +21 -2
  105. package/apps/studio/annotations/ops.ts +23 -0
  106. package/apps/studio/annotations/registry.ts +154 -16
  107. package/apps/studio/annotations/route.ts +268 -0
  108. package/apps/studio/annotations/run-tag.ts +150 -0
  109. package/apps/studio/annotations/stamp-kinds.ts +66 -0
  110. package/apps/studio/annotations/templates.ts +154 -0
  111. package/apps/studio/annotations/text-steps.ts +253 -0
  112. package/apps/studio/annotations/time-marks.ts +140 -0
  113. package/apps/studio/annotations/types.ts +22 -0
  114. package/apps/studio/annotations/ui/ai-marks.tsx +64 -0
  115. package/apps/studio/annotations/ui/ai-seen.tsx +117 -0
  116. package/apps/studio/annotations/ui/arrow-bind.ts +347 -0
  117. package/apps/studio/annotations/ui/arrow-cards.tsx +396 -0
  118. package/apps/studio/annotations/ui/arrow-kinds.ts +90 -0
  119. package/apps/studio/annotations/ui/bar-place.ts +18 -0
  120. package/apps/studio/annotations/ui/element-node.tsx +300 -52
  121. package/apps/studio/annotations/ui/host-view.ts +99 -0
  122. package/apps/studio/annotations/ui/locked.tsx +83 -0
  123. package/apps/studio/annotations/ui/lod.tsx +246 -0
  124. package/apps/studio/annotations/ui/placement.tsx +270 -0
  125. package/apps/studio/annotations/ui/pointer-pipeline.ts +10 -0
  126. package/apps/studio/annotations/ui/posture.ts +124 -0
  127. package/apps/studio/annotations/ui/quiet-tip.ts +28 -0
  128. package/apps/studio/annotations/ui/render-model.ts +27 -2
  129. package/apps/studio/annotations/ui/rest-route.ts +152 -0
  130. package/apps/studio/annotations/ui/ride.ts +957 -0
  131. package/apps/studio/annotations/ui/scene.tsx +59 -11
  132. package/apps/studio/annotations/ui/section-fold.ts +95 -0
  133. package/apps/studio/annotations/ui/shell-asks.ts +62 -0
  134. package/apps/studio/annotations/ui/stamps.ts +221 -0
  135. package/apps/studio/annotations/ui/stamps.tsx +272 -0
  136. package/apps/studio/annotations/ui/sticker-drop.ts +147 -0
  137. package/apps/studio/annotations/ui/sticker-preview.ts +41 -0
  138. package/apps/studio/annotations/ui/sticky-resolve.ts +106 -0
  139. package/apps/studio/annotations/ui/template-place.ts +108 -0
  140. package/apps/studio/annotations/ui/text-editor.tsx +6 -4
  141. package/apps/studio/annotations/ui/text-session.ts +63 -1
  142. package/apps/studio/annotations/ui/text-style.ts +11 -3
  143. package/apps/studio/annotations/ui/time-pins.tsx +134 -0
  144. package/apps/studio/annotations/ui/tool-prefs.ts +242 -0
  145. package/apps/studio/annotations/ui/tool-state.ts +211 -0
  146. package/apps/studio/annotations/ui/visibility.ts +76 -0
  147. package/apps/studio/annotations/ui/vote-dots.tsx +283 -0
  148. package/apps/studio/annotations/v1-adapter.ts +88 -5
  149. package/apps/studio/annotations/validate-board.ts +257 -0
  150. package/apps/studio/annotations/vote-guard.ts +48 -0
  151. package/apps/studio/annotations/votes-local.ts +481 -0
  152. package/apps/studio/annotations-bindings.ts +54 -8
  153. package/apps/studio/annotations-context-toolbar.tsx +612 -150
  154. package/apps/studio/annotations-layer.tsx +1768 -674
  155. package/apps/studio/annotations-model.ts +80 -5
  156. package/apps/studio/api.ts +1553 -459
  157. package/apps/studio/artboard-activity-overlay.tsx +530 -3
  158. package/apps/studio/artboard-ai-copies.tsx +187 -0
  159. package/apps/studio/artboard-convert-marks.tsx +142 -0
  160. package/apps/studio/artboard-gap-mark.tsx +177 -0
  161. package/apps/studio/artboard-ghosts-overlay.tsx +106 -0
  162. package/apps/studio/artboard-growth-memory.ts +56 -0
  163. package/apps/studio/artboard-growth-tag.tsx +115 -0
  164. package/apps/studio/artboard-guides-overlay.tsx +86 -26
  165. package/apps/studio/artboard-marquee.tsx +21 -6
  166. package/apps/studio/artboard-new-section.tsx +188 -0
  167. package/apps/studio/artboard-warn-mark.tsx +330 -0
  168. package/apps/studio/asset-details.ts +339 -0
  169. package/apps/studio/asset-generated.ts +99 -0
  170. package/apps/studio/asset-origins.ts +147 -0
  171. package/apps/studio/asset-placeholder.tsx +481 -0
  172. package/apps/studio/asset-rename.ts +171 -0
  173. package/apps/studio/asset-trash.ts +176 -0
  174. package/apps/studio/asset-upload-bars.tsx +167 -0
  175. package/apps/studio/asset-upload.ts +145 -1
  176. package/apps/studio/attribute-artboards.ts +327 -0
  177. package/apps/studio/bin/_ab-headless.sh +35 -0
  178. package/apps/studio/bin/_ab-park.sh +83 -0
  179. package/apps/studio/bin/_agent-browser-safe.mjs +36 -3
  180. package/apps/studio/bin/_annotate-post.mjs +137 -0
  181. package/apps/studio/bin/_assets.mjs +213 -0
  182. package/apps/studio/bin/_brand-colours.mjs +189 -0
  183. package/apps/studio/bin/_brand-fonts.mjs +158 -0
  184. package/apps/studio/bin/_brand-site.mjs +309 -0
  185. package/apps/studio/bin/_canvas-errors.mjs +143 -0
  186. package/apps/studio/bin/_canvas-rects-playwright.mjs +6 -3
  187. package/apps/studio/bin/_canvas-rects-static.mjs +1 -1
  188. package/apps/studio/bin/_check.mjs +122 -0
  189. package/apps/studio/bin/_comments.mjs +274 -0
  190. package/apps/studio/bin/_curl-local.mjs +122 -3
  191. package/apps/studio/bin/_decode-webaudio.mjs +120 -0
  192. package/apps/studio/bin/_describe.mjs +220 -0
  193. package/apps/studio/bin/_ds-check.mjs +26 -0
  194. package/apps/studio/bin/_ds-prove-playwright.mjs +327 -0
  195. package/apps/studio/bin/_ds-upgrade.mjs +14 -0
  196. package/apps/studio/bin/_ds.mjs +82 -0
  197. package/apps/studio/bin/_enumerate-artboards-playwright.mjs +6 -3
  198. package/apps/studio/bin/_exports.mjs +244 -0
  199. package/apps/studio/bin/_fetch-asset.mjs +209 -15
  200. package/apps/studio/bin/_history.mjs +509 -0
  201. package/apps/studio/bin/_html-playwright.mjs +10 -3
  202. package/apps/studio/bin/_import-asset.mjs +446 -15
  203. package/apps/studio/bin/_import-brand.mjs +40 -156
  204. package/apps/studio/bin/_import-figma.mjs +878 -20
  205. package/apps/studio/bin/_import-tokens.mjs +8 -118
  206. package/apps/studio/bin/_index-cli.mjs +126 -0
  207. package/apps/studio/bin/_layout-check.mjs +35 -0
  208. package/apps/studio/bin/_logs.mjs +130 -0
  209. package/apps/studio/bin/_motion-sample-playwright.mjs +6 -3
  210. package/apps/studio/bin/_no-egress.sh +36 -0
  211. package/apps/studio/bin/_pdf-playwright.mjs +9 -3
  212. package/apps/studio/bin/_perf-probe-safari.mjs +327 -37
  213. package/apps/studio/bin/_perf-probe-studio.mjs +259 -0
  214. package/apps/studio/bin/_perf-probe.mjs +35 -1
  215. package/apps/studio/bin/_perf-shared.mjs +377 -12
  216. package/apps/studio/bin/_place.mjs +35 -0
  217. package/apps/studio/bin/_png-playwright.mjs +27 -7
  218. package/apps/studio/bin/_pptx-playwright.mjs +4 -3
  219. package/apps/studio/bin/_pw-launch.mjs +124 -2
  220. package/apps/studio/bin/_record-shot.sh +65 -0
  221. package/apps/studio/bin/_rects-input.mjs +69 -0
  222. package/apps/studio/bin/_reel-place.mjs +160 -0
  223. package/apps/studio/bin/_region.mjs +37 -1
  224. package/apps/studio/bin/_runs.mjs +178 -0
  225. package/apps/studio/bin/_screenshot-playwright.mjs +6 -3
  226. package/apps/studio/bin/_studio-verb.mjs +220 -0
  227. package/apps/studio/bin/_svg-playwright.mjs +4 -3
  228. package/apps/studio/bin/_sync.mjs +179 -0
  229. package/apps/studio/bin/_thumbs-playwright.mjs +704 -0
  230. package/apps/studio/bin/_tile-draw.mjs +74 -0
  231. package/apps/studio/bin/_transcribe-local.mjs +243 -0
  232. package/apps/studio/bin/_transcribe.mjs +48 -56
  233. package/apps/studio/bin/_trash.mjs +287 -0
  234. package/apps/studio/bin/_url-guard.mjs +88 -0
  235. package/apps/studio/bin/_url-guard.sh +16 -0
  236. package/apps/studio/bin/_video-playwright.mjs +9 -3
  237. package/apps/studio/bin/_video-verbs.mjs +403 -0
  238. package/apps/studio/bin/_write-claim.mjs +124 -0
  239. package/apps/studio/bin/annotate.mjs +348 -330
  240. package/apps/studio/bin/assets.sh +28 -0
  241. package/apps/studio/bin/beats.mjs +237 -0
  242. package/apps/studio/bin/beats.sh +24 -0
  243. package/apps/studio/bin/bootstrap-check.sh +2 -1
  244. package/apps/studio/bin/canvas-edit.sh +17 -9
  245. package/apps/studio/bin/canvas-errors.sh +18 -0
  246. package/apps/studio/bin/canvas-rects.sh +14 -0
  247. package/apps/studio/bin/canvas-source.sh +18 -0
  248. package/apps/studio/bin/captions.sh +13 -0
  249. package/apps/studio/bin/chat-open.sh +2 -2
  250. package/apps/studio/bin/check.sh +27 -0
  251. package/apps/studio/bin/comments.sh +20 -0
  252. package/apps/studio/bin/cut-to-beat.sh +13 -0
  253. package/apps/studio/bin/cut-words.sh +13 -0
  254. package/apps/studio/bin/describe.sh +28 -0
  255. package/apps/studio/bin/draw-proof.sh +41 -8
  256. package/apps/studio/bin/ds-check.sh +30 -0
  257. package/apps/studio/bin/ds-upgrade.sh +30 -0
  258. package/apps/studio/bin/ds.sh +29 -0
  259. package/apps/studio/bin/exports.sh +19 -0
  260. package/apps/studio/bin/generate.sh +45 -3
  261. package/apps/studio/bin/handoff.sh +60 -1
  262. package/apps/studio/bin/history.sh +24 -0
  263. package/apps/studio/bin/import-brand.sh +5 -3
  264. package/apps/studio/bin/index.sh +26 -0
  265. package/apps/studio/bin/layout-check.sh +20 -0
  266. package/apps/studio/bin/logs.sh +17 -0
  267. package/apps/studio/bin/perf.sh +93 -3
  268. package/apps/studio/bin/photo-bg-remove.sh +49 -7
  269. package/apps/studio/bin/place.sh +20 -0
  270. package/apps/studio/bin/read-annotations.mjs +52 -1
  271. package/apps/studio/bin/reel-place.sh +15 -0
  272. package/apps/studio/bin/runs.sh +19 -0
  273. package/apps/studio/bin/screenshot.sh +37 -21
  274. package/apps/studio/bin/server-up.sh +50 -13
  275. package/apps/studio/bin/smoke.sh +10 -0
  276. package/apps/studio/bin/sync.sh +18 -0
  277. package/apps/studio/bin/to-lottie.sh +1 -1
  278. package/apps/studio/bin/transcribe-local.sh +27 -0
  279. package/apps/studio/bin/trash.sh +23 -0
  280. package/apps/studio/bin/visual-sanity.sh +1 -0
  281. package/apps/studio/bridge/canvas-mode-store.ts +301 -0
  282. package/apps/studio/bridge/canvas-modes.ts +548 -0
  283. package/apps/studio/bridge/dgn-protocol.ts +2671 -0
  284. package/apps/studio/bridge/esc-ladder.ts +98 -0
  285. package/apps/studio/bridge/link-target.ts +157 -0
  286. package/apps/studio/bridge/mode-shows.ts +167 -0
  287. package/apps/studio/bridge/occlusion.ts +108 -0
  288. package/apps/studio/bridge/paste-data.ts +101 -0
  289. package/apps/studio/build.ts +12 -1
  290. package/apps/studio/bunfig.toml +4 -0
  291. package/apps/studio/canvas-build-sandbox.ts +34 -5
  292. package/apps/studio/canvas-build-worker.ts +23 -1
  293. package/apps/studio/canvas-build.ts +419 -15
  294. package/apps/studio/canvas-comment-mount.tsx +113 -25
  295. package/apps/studio/canvas-create.ts +285 -49
  296. package/apps/studio/canvas-cursors.ts +12 -0
  297. package/apps/studio/canvas-ds-icons.tsx +241 -0
  298. package/apps/studio/canvas-edit.ts +1188 -172
  299. package/apps/studio/canvas-hud-tokens.gen.ts +120 -0
  300. package/apps/studio/canvas-icons.tsx +47 -0
  301. package/apps/studio/canvas-imports.ts +23 -4
  302. package/apps/studio/canvas-lib-inline.ts +57 -3
  303. package/apps/studio/canvas-lib.tsx +1033 -263
  304. package/apps/studio/canvas-list-watch.ts +73 -2
  305. package/apps/studio/canvas-meta.schema.json +11 -0
  306. package/apps/studio/canvas-notifications.tsx +28 -3
  307. package/apps/studio/canvas-pipeline.ts +43 -8
  308. package/apps/studio/canvas-replay-keys.ts +65 -0
  309. package/apps/studio/canvas-rows.ts +116 -0
  310. package/apps/studio/canvas-shell.tsx +784 -698
  311. package/apps/studio/canvas-source/errors.ts +315 -0
  312. package/apps/studio/canvas-source/source-map.ts +69 -0
  313. package/apps/studio/canvas-theme-pill.tsx +164 -0
  314. package/apps/studio/canvas-theme.ts +133 -0
  315. package/apps/studio/canvas-top-level.ts +69 -0
  316. package/apps/studio/check/ids.ts +28 -0
  317. package/apps/studio/check/index.ts +586 -0
  318. package/apps/studio/check/link-resolver.ts +75 -0
  319. package/apps/studio/check/meta.ts +79 -0
  320. package/apps/studio/check/video.ts +352 -0
  321. package/apps/studio/client/actions/shell-key-handlers.js +450 -0
  322. package/apps/studio/client/app.jsx +2918 -1203
  323. package/apps/studio/client/canvas-url.js +241 -5
  324. package/apps/studio/client/clipboard-relay.ts +144 -0
  325. package/apps/studio/client/command-palette-match.js +4 -2
  326. package/apps/studio/client/comments-overlay.css +529 -144
  327. package/apps/studio/client/dialogs/asset-picker.jsx +77 -32
  328. package/apps/studio/client/dialogs/command-palette.jsx +453 -67
  329. package/apps/studio/client/dialogs/export-dialog.jsx +6 -781
  330. package/apps/studio/client/dialogs/help-modal.jsx +31 -2
  331. package/apps/studio/client/dialogs/shortcuts-overlay.jsx +201 -106
  332. package/apps/studio/client/edit-op-relay.ts +77 -0
  333. package/apps/studio/client/embed-view.jsx +25 -5
  334. package/apps/studio/client/export-bridge-scope.js +72 -0
  335. package/apps/studio/client/export-center.jsx +179 -369
  336. package/apps/studio/client/export-lane.js +117 -0
  337. package/apps/studio/client/export-region.ts +25 -0
  338. package/apps/studio/client/file-tree.jsx +4 -4
  339. package/apps/studio/client/fonts/LICENSE-Inter-Tight.txt +93 -0
  340. package/apps/studio/client/fonts/LICENSE-Inter.txt +93 -0
  341. package/apps/studio/client/fonts/LICENSE-JetBrains-Mono.txt +93 -0
  342. package/apps/studio/client/fonts/inter-latin-ext-wght-normal.woff2 +0 -0
  343. package/apps/studio/client/fonts/inter-latin-wght-normal.woff2 +0 -0
  344. package/apps/studio/client/fonts/inter-tight-latin-ext-wght-normal.woff2 +0 -0
  345. package/apps/studio/client/fonts/inter-tight-latin-wght-normal.woff2 +0 -0
  346. package/apps/studio/client/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
  347. package/apps/studio/client/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
  348. package/apps/studio/client/frame-cap.js +132 -0
  349. package/apps/studio/client/generate-dialog.jsx +38 -36
  350. package/apps/studio/client/github.js +85 -26
  351. package/apps/studio/client/home/HomeAsk.jsx +220 -0
  352. package/apps/studio/client/home/InviteSheet.jsx +150 -0
  353. package/apps/studio/client/home/Shelves.jsx +216 -0
  354. package/apps/studio/client/home/Starters.jsx +42 -0
  355. package/apps/studio/client/home/TargetChip.jsx +152 -0
  356. package/apps/studio/client/home/home-api.js +275 -0
  357. package/apps/studio/client/home/home-app.jsx +1884 -0
  358. package/apps/studio/client/home/home-icons.jsx +143 -0
  359. package/apps/studio/client/home/home-menu.js +43 -0
  360. package/apps/studio/client/home/home-model.js +514 -0
  361. package/apps/studio/client/home/home-starters.js +136 -0
  362. package/apps/studio/client/home/home.css +1681 -0
  363. package/apps/studio/client/home/invite-flow.js +422 -0
  364. package/apps/studio/client/home/shell-mode.js +49 -0
  365. package/apps/studio/client/hooks/annotations-hidden-toast.js +21 -0
  366. package/apps/studio/client/hooks/canvas-origin-probe.js +26 -0
  367. package/apps/studio/client/hooks/edit-scope-query.js +16 -0
  368. package/apps/studio/client/hooks/use-action-keys.jsx +121 -0
  369. package/apps/studio/client/hooks/use-canvas-bridge.jsx +881 -247
  370. package/apps/studio/client/hooks/use-git-actions.jsx +33 -12
  371. package/apps/studio/client/hooks/use-palette-and-panels.jsx +722 -287
  372. package/apps/studio/client/hooks/use-photo-and-timeline.jsx +268 -307
  373. package/apps/studio/client/hooks/use-project-data.jsx +23 -2
  374. package/apps/studio/client/hooks/use-shell-core.jsx +582 -126
  375. package/apps/studio/client/hooks/use-tabs.jsx +268 -126
  376. package/apps/studio/client/index-loader.ts +3 -1
  377. package/apps/studio/client/index.html +0 -3
  378. package/apps/studio/client/inspector/color-picker.jsx +29 -18
  379. package/apps/studio/client/inspector/css-knobs.jsx +765 -436
  380. package/apps/studio/client/inspector/css-vocab.jsx +37 -4
  381. package/apps/studio/client/inspector/ds-tokens.js +127 -15
  382. package/apps/studio/client/inspector/grid-tracks-editor.jsx +21 -15
  383. package/apps/studio/client/inspector/inspect-computed.jsx +17 -15
  384. package/apps/studio/client/inspector/inspector-panel.jsx +314 -207
  385. package/apps/studio/client/inspector/layers.jsx +90 -65
  386. package/apps/studio/client/inspector/selection.js +20 -0
  387. package/apps/studio/client/inspector/token-popover.jsx +42 -28
  388. package/apps/studio/client/inspector-controls.jsx +453 -106
  389. package/apps/studio/client/panels/BrandUploadPanel.jsx +8 -229
  390. package/apps/studio/client/panels/ChatPanel.jsx +391 -1674
  391. package/apps/studio/client/panels/CloudBar.jsx +548 -252
  392. package/apps/studio/client/panels/CollabModelInfographic.jsx +77 -20
  393. package/apps/studio/client/panels/CreateProject.jsx +224 -40
  394. package/apps/studio/client/panels/DiffView.jsx +27 -10
  395. package/apps/studio/client/panels/ElicitationPrompt.jsx +4 -3
  396. package/apps/studio/client/panels/FigmaImportPanel.jsx +12 -263
  397. package/apps/studio/client/panels/IdentityBar.jsx +262 -74
  398. package/apps/studio/client/panels/IntroVideoDialog.jsx +6 -1
  399. package/apps/studio/client/panels/PermissionPrompt.jsx +85 -9
  400. package/apps/studio/client/panels/ReadinessList.jsx +71 -46
  401. package/apps/studio/client/panels/RepoBranchSwitcher.jsx +124 -745
  402. package/apps/studio/client/panels/SettingsPanel.jsx +492 -608
  403. package/apps/studio/client/panels/SetupChecklist.jsx +10 -3
  404. package/apps/studio/client/panels/SourceConflictPanel.jsx +96 -20
  405. package/apps/studio/client/panels/SyncConsentDialog.jsx +14 -13
  406. package/apps/studio/client/panels/TeamProjects.jsx +365 -119
  407. package/apps/studio/client/panels/ToolGroup.jsx +6 -2
  408. package/apps/studio/client/panels/acp-runtime.js +127 -22
  409. package/apps/studio/client/panels/acp-usage.js +4 -1
  410. package/apps/studio/client/panels/chat-context.js +74 -5
  411. package/apps/studio/client/panels/chat-header.jsx +67 -0
  412. package/apps/studio/client/panels/chat-markdown.jsx +6 -2
  413. package/apps/studio/client/panels/file-deep-link-dialog.jsx +88 -17
  414. package/apps/studio/client/panels/file-preview.jsx +50 -24
  415. package/apps/studio/client/panels/git-grouping.js +9 -2
  416. package/apps/studio/client/panels/slash-commands.gen.js +171 -0
  417. package/apps/studio/client/panels/slash-commands.js +65 -25
  418. package/apps/studio/client/panels/timeline-media-cache.js +68 -2
  419. package/apps/studio/client/panels/timeline-parse.js +62 -22
  420. package/apps/studio/client/panels/timeline-snap.js +4 -1
  421. package/apps/studio/client/panels/transcript-view.js +9 -0
  422. package/apps/studio/client/photo-knobs.jsx +225 -46
  423. package/apps/studio/client/prefs-migrate.js +79 -0
  424. package/apps/studio/client/report-bug.jsx +59 -26
  425. package/apps/studio/client/selection-scope.js +215 -0
  426. package/apps/studio/client/share-link.js +104 -8
  427. package/apps/studio/client/shell/account-tone.js +28 -0
  428. package/apps/studio/client/shell/banners.jsx +21 -188
  429. package/apps/studio/client/shell/comments-panel.jsx +5 -176
  430. package/apps/studio/client/shell/constants.js +1 -0
  431. package/apps/studio/client/shell/dock.jsx +217 -31
  432. package/apps/studio/client/shell/drop-guard.js +52 -0
  433. package/apps/studio/client/shell/icons.jsx +165 -23
  434. package/apps/studio/client/shell/util.js +20 -33
  435. package/apps/studio/client/shell/viewport.jsx +249 -95
  436. package/apps/studio/client/shell-bus.js +82 -0
  437. package/apps/studio/client/shell-events.js +251 -0
  438. package/apps/studio/client/stamp-follow.js +62 -0
  439. package/apps/studio/client/stores/shell-store.jsx +15 -0
  440. package/apps/studio/client/styles/0-reset.css +79 -16
  441. package/apps/studio/client/styles/1-tokens-maude-v2.css +367 -0
  442. package/apps/studio/client/styles/1-tokens-shell.css +374 -0
  443. package/apps/studio/client/styles/2-layout.css +404 -24
  444. package/apps/studio/client/styles/3-kit-maude-v2.css +683 -0
  445. package/apps/studio/client/styles/_index.css +185 -18
  446. package/apps/studio/client/styles/fonts.css +63 -0
  447. package/apps/studio/client/system/system-view.jsx +52 -6
  448. package/apps/studio/client/tour/collab-tour.js +43 -38
  449. package/apps/studio/client/tour/overlay.jsx +61 -19
  450. package/apps/studio/client/tour/quick-setup-tour.js +27 -20
  451. package/apps/studio/client/tour/tour-model.js +36 -0
  452. package/apps/studio/client/tour/usage-tour.js +43 -24
  453. package/apps/studio/client/tree/tree.jsx +661 -409
  454. package/apps/studio/client/tree-expansion.js +5 -2
  455. package/apps/studio/client/tree-row-menu.jsx +43 -29
  456. package/apps/studio/client/ui-open.js +104 -0
  457. package/apps/studio/client/use-tree-drag.js +2 -0
  458. package/apps/studio/client/v2/access/access-card.jsx +54 -0
  459. package/apps/studio/client/v2/access/access-client.js +525 -0
  460. package/apps/studio/client/v2/access/access-host.jsx +328 -0
  461. package/apps/studio/client/v2/access/access.css +163 -0
  462. package/apps/studio/client/v2/access/ask-to-edit.jsx +97 -0
  463. package/apps/studio/client/v2/access/disabled-reason.js +50 -0
  464. package/apps/studio/client/v2/access/link-off-card.jsx +37 -0
  465. package/apps/studio/client/v2/access/trashed-banner.jsx +123 -0
  466. package/apps/studio/client/v2/advanced/where-matrix.js +231 -0
  467. package/apps/studio/client/v2/ai/AChip.jsx +158 -0
  468. package/apps/studio/client/v2/ai/Advanced.jsx +640 -0
  469. package/apps/studio/client/v2/ai/AiChatIsland.jsx +108 -0
  470. package/apps/studio/client/v2/ai/AskSelectionHost.jsx +173 -0
  471. package/apps/studio/client/v2/ai/AttachMenu.jsx +190 -0
  472. package/apps/studio/client/v2/ai/BigChat.jsx +195 -0
  473. package/apps/studio/client/v2/ai/ChatList.jsx +614 -0
  474. package/apps/studio/client/v2/ai/ChatUndo.jsx +164 -0
  475. package/apps/studio/client/v2/ai/ChoiceCard.jsx +178 -0
  476. package/apps/studio/client/v2/ai/Composer.jsx +655 -0
  477. package/apps/studio/client/v2/ai/ConnectSheet.jsx +118 -0
  478. package/apps/studio/client/v2/ai/Consent.jsx +66 -0
  479. package/apps/studio/client/v2/ai/DropOverlay.jsx +113 -0
  480. package/apps/studio/client/v2/ai/Feed.jsx +589 -0
  481. package/apps/studio/client/v2/ai/FoldNeeds.jsx +23 -0
  482. package/apps/studio/client/v2/ai/NeedsYouSlot.jsx +250 -0
  483. package/apps/studio/client/v2/ai/NotReady.jsx +110 -0
  484. package/apps/studio/client/v2/ai/OfferCard.jsx +165 -0
  485. package/apps/studio/client/v2/ai/PermissionCard.jsx +168 -0
  486. package/apps/studio/client/v2/ai/PickedShots.jsx +33 -0
  487. package/apps/studio/client/v2/ai/ProblemCard.jsx +41 -0
  488. package/apps/studio/client/v2/ai/QuitDialog.jsx +127 -0
  489. package/apps/studio/client/v2/ai/RawLog.jsx +68 -0
  490. package/apps/studio/client/v2/ai/Result.jsx +144 -0
  491. package/apps/studio/client/v2/ai/RunList.jsx +352 -0
  492. package/apps/studio/client/v2/ai/RunSurface.jsx +248 -0
  493. package/apps/studio/client/v2/ai/ScopeChip.jsx +239 -0
  494. package/apps/studio/client/v2/ai/SentStrip.jsx +70 -0
  495. package/apps/studio/client/v2/ai/StoppedDivider.jsx +84 -0
  496. package/apps/studio/client/v2/ai/Suggest.jsx +153 -0
  497. package/apps/studio/client/v2/ai/TurnResult.jsx +95 -0
  498. package/apps/studio/client/v2/ai/WaitingCard.jsx +133 -0
  499. package/apps/studio/client/v2/ai/WillChange.jsx +40 -0
  500. package/apps/studio/client/v2/ai/Working.jsx +74 -0
  501. package/apps/studio/client/v2/ai/advanced-handlers.js +56 -0
  502. package/apps/studio/client/v2/ai/advanced-model.js +214 -0
  503. package/apps/studio/client/v2/ai/ai-list-advanced.css +625 -0
  504. package/apps/studio/client/v2/ai/ai-may.js +75 -0
  505. package/apps/studio/client/v2/ai/ai-offer.js +178 -0
  506. package/apps/studio/client/v2/ai/ai-run.css +281 -0
  507. package/apps/studio/client/v2/ai/ai-send.js +164 -0
  508. package/apps/studio/client/v2/ai/ai.css +261 -0
  509. package/apps/studio/client/v2/ai/answer-note.js +44 -0
  510. package/apps/studio/client/v2/ai/ask-frame.js +131 -0
  511. package/apps/studio/client/v2/ai/ask-selection-lane.js +100 -0
  512. package/apps/studio/client/v2/ai/ask-selection.css +142 -0
  513. package/apps/studio/client/v2/ai/ask-selection.js +84 -0
  514. package/apps/studio/client/v2/ai/attach.css +366 -0
  515. package/apps/studio/client/v2/ai/attach.js +186 -0
  516. package/apps/studio/client/v2/ai/chat-list-model.js +333 -0
  517. package/apps/studio/client/v2/ai/chat-store-api.js +93 -0
  518. package/apps/studio/client/{styles/6-acp-chat.css → v2/ai/chat.css} +1152 -797
  519. package/apps/studio/client/v2/ai/connect-flow.js +75 -0
  520. package/apps/studio/client/v2/ai/gate-lines.js +121 -0
  521. package/apps/studio/client/v2/ai/icons.jsx +66 -0
  522. package/apps/studio/client/v2/ai/jump-model.js +61 -0
  523. package/apps/studio/client/v2/ai/made-by-ai.js +179 -0
  524. package/apps/studio/client/v2/ai/needs-you-store.js +112 -0
  525. package/apps/studio/client/v2/ai/needs-you-toast.js +104 -0
  526. package/apps/studio/client/v2/ai/needs-you.css +554 -0
  527. package/apps/studio/client/v2/ai/needs-you.js +401 -0
  528. package/apps/studio/client/v2/ai/panel-focus.js +71 -0
  529. package/apps/studio/client/v2/ai/panel.css +88 -0
  530. package/apps/studio/client/v2/ai/paste-chips.jsx +108 -0
  531. package/apps/studio/client/v2/ai/picked-shots.js +48 -0
  532. package/apps/studio/client/v2/ai/quit.css +64 -0
  533. package/apps/studio/client/v2/ai/result-shown.js +50 -0
  534. package/apps/studio/client/v2/ai/ring-relay.js +143 -0
  535. package/apps/studio/client/v2/ai/row-slots-lane.js +67 -0
  536. package/apps/studio/client/v2/ai/run-api.js +137 -0
  537. package/apps/studio/client/v2/ai/run-cards.js +31 -0
  538. package/apps/studio/client/v2/ai/run-compare.js +60 -0
  539. package/apps/studio/client/v2/ai/run-icons.jsx +53 -0
  540. package/apps/studio/client/v2/ai/run-model.js +348 -0
  541. package/apps/studio/client/v2/ai/runs-model.js +568 -0
  542. package/apps/studio/client/v2/ai/runs-store.js +161 -0
  543. package/apps/studio/client/v2/ai/runs.css +226 -0
  544. package/apps/studio/client/v2/ai/scope.js +298 -0
  545. package/apps/studio/client/v2/ai/seen-relay.js +95 -0
  546. package/apps/studio/client/v2/ai/sent-attachments.js +77 -0
  547. package/apps/studio/client/v2/ai/stopped.js +69 -0
  548. package/apps/studio/client/v2/ai/suggest-why.js +200 -0
  549. package/apps/studio/client/v2/ai/use-ai-scope.js +198 -0
  550. package/apps/studio/client/v2/ai/use-ask-ai.js +63 -0
  551. package/apps/studio/client/v2/ai/use-ask-selection.js +41 -0
  552. package/apps/studio/client/v2/ai/use-attachments.js +239 -0
  553. package/apps/studio/client/v2/ai/use-chat-runs.js +32 -0
  554. package/apps/studio/client/v2/ai/use-run-versions.js +39 -0
  555. package/apps/studio/client/v2/ai/video/ClipsAttached.jsx +23 -0
  556. package/apps/studio/client/v2/ai/video/LeftOut.jsx +29 -0
  557. package/apps/studio/client/v2/ai/video/WatchProgress.jsx +65 -0
  558. package/apps/studio/client/v2/ai/video/card-model.js +107 -0
  559. package/apps/studio/client/v2/ai/video/cards.jsx +51 -0
  560. package/apps/studio/client/v2/ai/video/clip-pic.js +12 -0
  561. package/apps/studio/client/v2/ai/video/video-cards.css +168 -0
  562. package/apps/studio/client/v2/annotations/annotation-asks.js +171 -0
  563. package/apps/studio/client/v2/annotations/annotation-list-model.js +238 -0
  564. package/apps/studio/client/v2/annotations/annotation-list.css +277 -0
  565. package/apps/studio/client/v2/annotations/annotation-list.jsx +433 -0
  566. package/apps/studio/client/v2/annotations/recent-stickers.js +64 -0
  567. package/apps/studio/client/v2/annotations/stamp-row.jsx +66 -0
  568. package/apps/studio/client/v2/annotations/stamps-glyphs.jsx +35 -0
  569. package/apps/studio/client/v2/annotations/sticker-preload.js +44 -0
  570. package/apps/studio/client/v2/annotations/sticker-search.js +155 -0
  571. package/apps/studio/client/v2/annotations/stickers-gallery.css +295 -0
  572. package/apps/studio/client/v2/annotations/stickers-gallery.jsx +454 -0
  573. package/apps/studio/client/v2/annotations/templates-panel.css +344 -0
  574. package/apps/studio/client/v2/annotations/templates-panel.jsx +240 -0
  575. package/apps/studio/client/v2/annotations/v2-scope.js +20 -0
  576. package/apps/studio/client/v2/annotations/vote-bar.jsx +212 -0
  577. package/apps/studio/client/v2/annotations/vote-sheet.jsx +200 -0
  578. package/apps/studio/client/v2/annotations/vote-store.js +392 -0
  579. package/apps/studio/client/v2/annotations/vote.css +153 -0
  580. package/apps/studio/client/v2/assets/ask-once.js +65 -0
  581. package/apps/studio/client/v2/assets/asset-drop-session.js +238 -0
  582. package/apps/studio/client/v2/assets/asset-state-lane.js +267 -0
  583. package/apps/studio/client/v2/assets/assets-bus.js +109 -0
  584. package/apps/studio/client/v2/assets/browse-model.js +90 -0
  585. package/apps/studio/client/v2/assets/browse-view.jsx +202 -0
  586. package/apps/studio/client/v2/assets/canvas-drop-catcher.jsx +114 -0
  587. package/apps/studio/client/v2/assets/connect-key-sheet.jsx +69 -0
  588. package/apps/studio/client/v2/assets/copy-asset.js +37 -0
  589. package/apps/studio/client/v2/assets/describe-client.js +156 -0
  590. package/apps/studio/client/v2/assets/describe-consent.jsx +184 -0
  591. package/apps/studio/client/v2/assets/describe.css +72 -0
  592. package/apps/studio/client/v2/assets/details-advanced.jsx +76 -0
  593. package/apps/studio/client/v2/assets/details-model.js +233 -0
  594. package/apps/studio/client/v2/assets/details.jsx +292 -0
  595. package/apps/studio/client/v2/assets/generate-ask.jsx +506 -0
  596. package/apps/studio/client/v2/assets/generated.js +83 -0
  597. package/apps/studio/client/v2/assets/import-lines.js +228 -0
  598. package/apps/studio/client/v2/assets/import-offline.js +32 -0
  599. package/apps/studio/client/v2/assets/import-toast.js +56 -0
  600. package/apps/studio/client/v2/assets/just-added.js +32 -0
  601. package/apps/studio/client/v2/assets/kinds-chip.jsx +77 -0
  602. package/apps/studio/client/v2/assets/library-foot.js +42 -0
  603. package/apps/studio/client/v2/assets/missing-frame.css +60 -0
  604. package/apps/studio/client/v2/assets/missing-frame.jsx +218 -0
  605. package/apps/studio/client/v2/assets/multi-select.js +58 -0
  606. package/apps/studio/client/v2/assets/place-asset.js +128 -0
  607. package/apps/studio/client/v2/assets/relink.js +96 -0
  608. package/apps/studio/client/v2/assets/rename-asset.js +83 -0
  609. package/apps/studio/client/v2/assets/search-marks.jsx +75 -0
  610. package/apps/studio/client/v2/assets/takes-overlay.jsx +86 -0
  611. package/apps/studio/client/v2/assets/takes.css +177 -0
  612. package/apps/studio/client/v2/assets/takes.js +224 -0
  613. package/apps/studio/client/v2/assets/tidy.jsx +144 -0
  614. package/apps/studio/client/v2/assets/tile-drag.js +53 -0
  615. package/apps/studio/client/v2/assets/tile-menu.jsx +119 -0
  616. package/apps/studio/client/v2/assets/tile.jsx +131 -0
  617. package/apps/studio/client/v2/assets/trash-assets.js +98 -0
  618. package/apps/studio/client/v2/assets/use-asset-details.js +58 -0
  619. package/apps/studio/client/v2/assets/use-assets.js +121 -0
  620. package/apps/studio/client/v2/assets/use-takes-lane.js +150 -0
  621. package/apps/studio/client/v2/canvases/canvas-icons.jsx +107 -0
  622. package/apps/studio/client/v2/canvases/canvases-panel.jsx +1466 -0
  623. package/apps/studio/client/v2/canvases/canvases.css +699 -0
  624. package/apps/studio/client/v2/canvases/covers.js +32 -0
  625. package/apps/studio/client/v2/canvases/inline-rename.jsx +122 -0
  626. package/apps/studio/client/v2/canvases/jump-list.jsx +100 -0
  627. package/apps/studio/client/v2/canvases/jump-model.js +102 -0
  628. package/apps/studio/client/v2/canvases/kept-on-this-mac.jsx +192 -0
  629. package/apps/studio/client/v2/canvases/last-canvas.js +36 -0
  630. package/apps/studio/client/v2/canvases/move-model.js +45 -0
  631. package/apps/studio/client/v2/canvases/move-sheet.jsx +91 -0
  632. package/apps/studio/client/v2/canvases/open-link.js +154 -0
  633. package/apps/studio/client/v2/canvases/panel-search.js +156 -0
  634. package/apps/studio/client/v2/canvases/rename-model.js +134 -0
  635. package/apps/studio/client/v2/canvases/row-menu.jsx +145 -0
  636. package/apps/studio/client/v2/canvases/row-slots.js +224 -0
  637. package/apps/studio/client/v2/canvases/sort.js +132 -0
  638. package/apps/studio/client/v2/canvases/support-model.js +68 -0
  639. package/apps/studio/client/v2/canvases/trash-canvas.js +120 -0
  640. package/apps/studio/client/v2/canvases/tree-model.js +760 -0
  641. package/apps/studio/client/v2/canvases/use-canvas-index.js +50 -0
  642. package/apps/studio/client/v2/canvases/use-canvases-sort.js +59 -0
  643. package/apps/studio/client/v2/canvases/use-move.js +61 -0
  644. package/apps/studio/client/v2/canvases/use-pins.js +80 -0
  645. package/apps/studio/client/v2/cloud/browser-door.js +152 -0
  646. package/apps/studio/client/v2/cloud/cloud-name.js +38 -0
  647. package/apps/studio/client/v2/code/canvas-error-card.jsx +407 -0
  648. package/apps/studio/client/v2/code/canvas-imports-card.jsx +31 -0
  649. package/apps/studio/client/v2/code/code-bus.js +63 -0
  650. package/apps/studio/client/v2/code/code-view.jsx +277 -0
  651. package/apps/studio/client/v2/code/code.css +373 -0
  652. package/apps/studio/client/v2/code/highlight.js +163 -0
  653. package/apps/studio/client/v2/code/use-canvas-source.js +338 -0
  654. package/apps/studio/client/v2/comments/comment-bridge.js +154 -0
  655. package/apps/studio/client/v2/comments/comment-client.js +84 -0
  656. package/apps/studio/client/v2/comments/comment-tool.js +18 -0
  657. package/apps/studio/client/v2/comments/comments-model.js +213 -0
  658. package/apps/studio/client/v2/comments/comments-panel.jsx +400 -0
  659. package/apps/studio/client/v2/comments/comments.css +305 -0
  660. package/apps/studio/client/v2/comments/mention-callouts.jsx +90 -0
  661. package/apps/studio/client/v2/comments/mention-model.js +118 -0
  662. package/apps/studio/client/v2/comments/native-mention-notice.js +73 -0
  663. package/apps/studio/client/v2/comments/reply-focus.js +30 -0
  664. package/apps/studio/client/v2/comments/use-comments-shell.jsx +176 -0
  665. package/apps/studio/client/v2/create/NameDialog.jsx +95 -0
  666. package/apps/studio/client/v2/create/NameDialogHost.jsx +141 -0
  667. package/apps/studio/client/v2/create/create-project.css +260 -0
  668. package/apps/studio/client/v2/create/duplicate-done.js +45 -0
  669. package/apps/studio/client/v2/create/empty-project.css +113 -0
  670. package/apps/studio/client/v2/create/empty-project.jsx +162 -0
  671. package/apps/studio/client/v2/create/first-draft.js +30 -0
  672. package/apps/studio/client/v2/create/intent-host.jsx +40 -0
  673. package/apps/studio/client/v2/create/name-dialog-bus.js +41 -0
  674. package/apps/studio/client/v2/create/name-dialog.css +36 -0
  675. package/apps/studio/client/v2/create/new-canvas.js +64 -0
  676. package/apps/studio/client/v2/create/open-sizes.js +41 -0
  677. package/apps/studio/client/v2/create/render-error.css +29 -0
  678. package/apps/studio/client/v2/create/render-error.jsx +107 -0
  679. package/apps/studio/client/v2/create/repair-offer.js +36 -0
  680. package/apps/studio/client/v2/create/take-intent.js +154 -0
  681. package/apps/studio/client/v2/create/use-project-empty.js +85 -0
  682. package/apps/studio/client/v2/create/use-render-error.js +116 -0
  683. package/apps/studio/client/v2/diagnostics/diagnostics-bus.js +47 -0
  684. package/apps/studio/client/v2/diagnostics/diagnostics-handlers.js +108 -0
  685. package/apps/studio/client/v2/diagnostics/diagnostics-host.jsx +196 -0
  686. package/apps/studio/client/v2/diagnostics/diagnostics-model.js +253 -0
  687. package/apps/studio/client/v2/diagnostics/diagnostics-sheet.jsx +557 -0
  688. package/apps/studio/client/v2/diagnostics/diagnostics.css +612 -0
  689. package/apps/studio/client/v2/diagnostics/resync-model.js +51 -0
  690. package/apps/studio/client/v2/diagnostics/resync-run.js +79 -0
  691. package/apps/studio/client/v2/diagnostics/sync-actions.js +38 -0
  692. package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +241 -0
  693. package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +392 -0
  694. package/apps/studio/client/v2/diagnostics/use-diagnostics-menu.js +58 -0
  695. package/apps/studio/client/v2/ds/advanced-bus.js +40 -0
  696. package/apps/studio/client/v2/ds/advanced-host.jsx +228 -0
  697. package/apps/studio/client/v2/ds/advanced-model.js +110 -0
  698. package/apps/studio/client/v2/ds/advanced-store.js +47 -0
  699. package/apps/studio/client/v2/ds/advanced.css +277 -0
  700. package/apps/studio/client/v2/ds/advanced.jsx +203 -0
  701. package/apps/studio/client/v2/ds/check-card.jsx +80 -0
  702. package/apps/studio/client/v2/ds/colour-picker.jsx +121 -0
  703. package/apps/studio/client/v2/ds/colour-words.js +48 -0
  704. package/apps/studio/client/v2/ds/conflict-pick.jsx +151 -0
  705. package/apps/studio/client/v2/ds/contrast-warning.jsx +80 -0
  706. package/apps/studio/client/v2/ds/contrast.js +137 -0
  707. package/apps/studio/client/v2/ds/convert-dialog.jsx +133 -0
  708. package/apps/studio/client/v2/ds/convert-host.jsx +143 -0
  709. package/apps/studio/client/v2/ds/convert-model.js +221 -0
  710. package/apps/studio/client/v2/ds/default-write.js +69 -0
  711. package/apps/studio/client/v2/ds/direction-bar.jsx +287 -0
  712. package/apps/studio/client/v2/ds/door-write.js +163 -0
  713. package/apps/studio/client/v2/ds/edge-model.js +151 -0
  714. package/apps/studio/client/v2/ds/edge-write.js +91 -0
  715. package/apps/studio/client/v2/ds/edges.css +152 -0
  716. package/apps/studio/client/v2/ds/follower-swap.js +88 -0
  717. package/apps/studio/client/v2/ds/go-to.js +71 -0
  718. package/apps/studio/client/v2/ds/kinds/master.jsx +214 -0
  719. package/apps/studio/client/v2/ds/kinds/token.jsx +546 -0
  720. package/apps/studio/client/v2/ds/library-bus.js +43 -0
  721. package/apps/studio/client/v2/ds/library-card.jsx +379 -0
  722. package/apps/studio/client/v2/ds/library-host.jsx +436 -0
  723. package/apps/studio/client/v2/ds/library-model.js +305 -0
  724. package/apps/studio/client/v2/ds/library-store.js +45 -0
  725. package/apps/studio/client/v2/ds/library.css +148 -0
  726. package/apps/studio/client/v2/ds/make-host.jsx +244 -0
  727. package/apps/studio/client/v2/ds/make-model.js +208 -0
  728. package/apps/studio/client/v2/ds/make-sheet.jsx +264 -0
  729. package/apps/studio/client/v2/ds/make-write.js +90 -0
  730. package/apps/studio/client/v2/ds/make.css +242 -0
  731. package/apps/studio/client/v2/ds/master-write.js +145 -0
  732. package/apps/studio/client/v2/ds/new-canvas-default.js +89 -0
  733. package/apps/studio/client/v2/ds/off-system-host.jsx +107 -0
  734. package/apps/studio/client/v2/ds/off-system.jsx +101 -0
  735. package/apps/studio/client/v2/ds/outside-banner.jsx +153 -0
  736. package/apps/studio/client/v2/ds/pinned-rows.js +138 -0
  737. package/apps/studio/client/v2/ds/pins.js +102 -0
  738. package/apps/studio/client/v2/ds/preview-bar.jsx +220 -0
  739. package/apps/studio/client/v2/ds/preview-doors.js +47 -0
  740. package/apps/studio/client/v2/ds/preview-mode.js +163 -0
  741. package/apps/studio/client/v2/ds/reach-data.js +68 -0
  742. package/apps/studio/client/v2/ds/reach-model.js +184 -0
  743. package/apps/studio/client/v2/ds/reach-view.jsx +577 -0
  744. package/apps/studio/client/v2/ds/reach.css +298 -0
  745. package/apps/studio/client/v2/ds/rename-write.js +88 -0
  746. package/apps/studio/client/v2/ds/review-bus.js +41 -0
  747. package/apps/studio/client/v2/ds/review-host.jsx +438 -0
  748. package/apps/studio/client/v2/ds/review-model.js +307 -0
  749. package/apps/studio/client/v2/ds/review-sheet.jsx +390 -0
  750. package/apps/studio/client/v2/ds/review.css +894 -0
  751. package/apps/studio/client/v2/ds/row-dots.js +41 -0
  752. package/apps/studio/client/v2/ds/switch-bus.js +56 -0
  753. package/apps/studio/client/v2/ds/switch-host.jsx +241 -0
  754. package/apps/studio/client/v2/ds/switch-model.js +254 -0
  755. package/apps/studio/client/v2/ds/switch-sheet.jsx +364 -0
  756. package/apps/studio/client/v2/ds/switch.css +263 -0
  757. package/apps/studio/client/v2/ds/system-menu.jsx +81 -0
  758. package/apps/studio/client/v2/ds/system-rename.jsx +102 -0
  759. package/apps/studio/client/v2/ds/token-write.js +241 -0
  760. package/apps/studio/client/v2/ds/token.css +185 -0
  761. package/apps/studio/client/v2/ds/trash-token-sheet.jsx +112 -0
  762. package/apps/studio/client/v2/ds/truth-card.jsx +85 -0
  763. package/apps/studio/client/v2/ds/truth-host.jsx +239 -0
  764. package/apps/studio/client/v2/ds/truth-model.js +315 -0
  765. package/apps/studio/client/v2/ds/truth-store.js +45 -0
  766. package/apps/studio/client/v2/ds/truth.css +143 -0
  767. package/apps/studio/client/v2/ds/update-available.jsx +261 -0
  768. package/apps/studio/client/v2/ds/update-dots.js +103 -0
  769. package/apps/studio/client/v2/ds/update-model.js +295 -0
  770. package/apps/studio/client/v2/ds/upgrade-bus.js +40 -0
  771. package/apps/studio/client/v2/ds/upgrade-host.jsx +185 -0
  772. package/apps/studio/client/v2/ds/upgrade-model.js +266 -0
  773. package/apps/studio/client/v2/ds/upgrade-offers.js +34 -0
  774. package/apps/studio/client/v2/ds/upgrade-sheet.jsx +277 -0
  775. package/apps/studio/client/v2/ds/upgrade.css +166 -0
  776. package/apps/studio/client/v2/ds/use-covers.js +27 -0
  777. package/apps/studio/client/v2/ds/use-ds-frames.js +165 -0
  778. package/apps/studio/client/v2/ds/use-ds-model.js +61 -0
  779. package/apps/studio/client/v2/ds/use-ds-search.js +61 -0
  780. package/apps/studio/client/v2/ds/use-ds-state.js +65 -0
  781. package/apps/studio/client/v2/ds/uses-link.jsx +58 -0
  782. package/apps/studio/client/v2/empty/all-trashed-model.js +321 -0
  783. package/apps/studio/client/v2/empty/all-trashed-relay.js +65 -0
  784. package/apps/studio/client/v2/empty/all-trashed.jsx +229 -0
  785. package/apps/studio/client/v2/empty/arriving.jsx +180 -0
  786. package/apps/studio/client/v2/empty/artboard-hint.jsx +47 -0
  787. package/apps/studio/client/v2/empty/ask-button.jsx +35 -0
  788. package/apps/studio/client/v2/empty/confetti.jsx +46 -0
  789. package/apps/studio/client/v2/empty/empty-canvas.jsx +96 -0
  790. package/apps/studio/client/v2/empty/empty-copy.js +265 -0
  791. package/apps/studio/client/v2/empty/empty-hint-store.js +31 -0
  792. package/apps/studio/client/v2/empty/empty-host.jsx +168 -0
  793. package/apps/studio/client/v2/empty/empty.css +440 -0
  794. package/apps/studio/client/v2/empty/empty.jsx +162 -0
  795. package/apps/studio/client/v2/empty/fill-ask.js +22 -0
  796. package/apps/studio/client/v2/empty/free-centre.js +11 -0
  797. package/apps/studio/client/v2/empty/index.js +40 -0
  798. package/apps/studio/client/v2/empty/layers-empty.jsx +22 -0
  799. package/apps/studio/client/v2/empty/not-local.jsx +111 -0
  800. package/apps/studio/client/v2/empty/select-new-artboard.js +32 -0
  801. package/apps/studio/client/v2/empty/skeleton.jsx +51 -0
  802. package/apps/studio/client/v2/empty/spot-art.jsx +923 -0
  803. package/apps/studio/client/v2/empty/spot.jsx +96 -0
  804. package/apps/studio/client/v2/empty/suggestions.jsx +18 -0
  805. package/apps/studio/client/v2/empty/use-empty-canvas.js +251 -0
  806. package/apps/studio/client/v2/export/access-line.jsx +48 -0
  807. package/apps/studio/client/v2/export/advanced/advanced-copy.js +77 -0
  808. package/apps/studio/client/v2/export/advanced/advanced.css +252 -0
  809. package/apps/studio/client/v2/export/advanced/advanced.jsx +148 -0
  810. package/apps/studio/client/v2/export/advanced/command.js +128 -0
  811. package/apps/studio/client/v2/export/advanced/command.jsx +50 -0
  812. package/apps/studio/client/v2/export/advanced/fields.jsx +132 -0
  813. package/apps/studio/client/v2/export/advanced/image.jsx +124 -0
  814. package/apps/studio/client/v2/export/advanced/model.js +199 -0
  815. package/apps/studio/client/v2/export/advanced/names.jsx +65 -0
  816. package/apps/studio/client/v2/export/advanced/print.jsx +99 -0
  817. package/apps/studio/client/v2/export/advanced/render.jsx +63 -0
  818. package/apps/studio/client/v2/export/advanced/video.jsx +76 -0
  819. package/apps/studio/client/v2/export/annotations-policy.js +28 -0
  820. package/apps/studio/client/v2/export/cloud-queue.js +69 -0
  821. package/apps/studio/client/v2/export/copy-command.js +72 -0
  822. package/apps/studio/client/v2/export/copy-png.js +144 -0
  823. package/apps/studio/client/v2/export/done-toast.jsx +89 -0
  824. package/apps/studio/client/v2/export/edges.css +74 -0
  825. package/apps/studio/client/v2/export/export-copy.js +352 -0
  826. package/apps/studio/client/v2/export/export-sheet.jsx +804 -0
  827. package/apps/studio/client/v2/export/export-sizes.js +217 -0
  828. package/apps/studio/client/v2/export/export.css +832 -0
  829. package/apps/studio/client/v2/export/exports-model.js +383 -0
  830. package/apps/studio/client/v2/export/exports-panel.css +192 -0
  831. package/apps/studio/client/v2/export/exports-panel.jsx +164 -0
  832. package/apps/studio/client/v2/export/file-rows.jsx +84 -0
  833. package/apps/studio/client/v2/export/inspector-export.jsx +335 -0
  834. package/apps/studio/client/v2/export/job-row.jsx +358 -0
  835. package/apps/studio/client/v2/export/last-finished.js +34 -0
  836. package/apps/studio/client/v2/export/native-save.js +160 -0
  837. package/apps/studio/client/v2/export/other-formats.jsx +199 -0
  838. package/apps/studio/client/v2/export/parts.jsx +117 -0
  839. package/apps/studio/client/v2/export/preflight/fonts.js +27 -0
  840. package/apps/studio/client/v2/export/preflight/paper.jsx +177 -0
  841. package/apps/studio/client/v2/export/preflight/safe-margin.js +24 -0
  842. package/apps/studio/client/v2/export/preflight/use-preflight.js +74 -0
  843. package/apps/studio/client/v2/export/preview.jsx +79 -0
  844. package/apps/studio/client/v2/export/print.css +219 -0
  845. package/apps/studio/client/v2/export/run-export.js +177 -0
  846. package/apps/studio/client/v2/export/scope-bar.jsx +70 -0
  847. package/apps/studio/client/v2/export/sections/batch-model.js +224 -0
  848. package/apps/studio/client/v2/export/sections/batch.jsx +235 -0
  849. package/apps/studio/client/v2/export/sections/image.jsx +93 -0
  850. package/apps/studio/client/v2/export/sections/print-copy.js +41 -0
  851. package/apps/studio/client/v2/export/sections/print.jsx +285 -0
  852. package/apps/studio/client/v2/export/sections/render-row.jsx +81 -0
  853. package/apps/studio/client/v2/export/sections/version.jsx +176 -0
  854. package/apps/studio/client/v2/export/sections/video-copy.js +92 -0
  855. package/apps/studio/client/v2/export/sections/video-model.js +127 -0
  856. package/apps/studio/client/v2/export/sections/video.jsx +397 -0
  857. package/apps/studio/client/v2/export/sections/web.jsx +151 -0
  858. package/apps/studio/client/v2/export/share-hint.jsx +51 -0
  859. package/apps/studio/client/v2/export/use-export-spec.js +546 -0
  860. package/apps/studio/client/v2/export/video-content.js +75 -0
  861. package/apps/studio/client/v2/export/video.css +221 -0
  862. package/apps/studio/client/v2/fold/advanced-fold.jsx +96 -0
  863. package/apps/studio/client/v2/fold/fold-store.js +151 -0
  864. package/apps/studio/client/v2/fold/fold.css +59 -0
  865. package/apps/studio/client/v2/fold/use-fold.js +36 -0
  866. package/apps/studio/client/v2/handoff/edges.jsx +74 -0
  867. package/apps/studio/client/v2/handoff/handoff-sheet.jsx +469 -0
  868. package/apps/studio/client/v2/handoff/handoff.css +181 -0
  869. package/apps/studio/client/v2/handoff/ready-card.jsx +84 -0
  870. package/apps/studio/client/v2/handoff/targets.js +111 -0
  871. package/apps/studio/client/v2/help/add-guides.js +43 -0
  872. package/apps/studio/client/v2/help/help.css +995 -0
  873. package/apps/studio/client/v2/history/blame.js +161 -0
  874. package/apps/studio/client/v2/history/branch-actions.js +214 -0
  875. package/apps/studio/client/v2/history/change-list.jsx +102 -0
  876. package/apps/studio/client/v2/history/clear-band.js +144 -0
  877. package/apps/studio/client/v2/history/compare-store.js +80 -0
  878. package/apps/studio/client/v2/history/compare-view.jsx +318 -0
  879. package/apps/studio/client/v2/history/compare-words.js +8 -0
  880. package/apps/studio/client/v2/history/git-advanced.jsx +580 -0
  881. package/apps/studio/client/v2/history/git-io.js +58 -0
  882. package/apps/studio/client/v2/history/git-model.js +526 -0
  883. package/apps/studio/client/v2/history/git-parts.jsx +662 -0
  884. package/apps/studio/client/v2/history/history-host.jsx +78 -0
  885. package/apps/studio/client/v2/history/history-panel.jsx +599 -0
  886. package/apps/studio/client/v2/history/history.css +1477 -0
  887. package/apps/studio/client/v2/history/name-dialog.jsx +109 -0
  888. package/apps/studio/client/v2/history/object-filter.js +143 -0
  889. package/apps/studio/client/v2/history/object-history-ask.js +62 -0
  890. package/apps/studio/client/v2/history/object-view.jsx +236 -0
  891. package/apps/studio/client/v2/history/rows.ts +445 -0
  892. package/apps/studio/client/v2/history/use-versions.js +391 -0
  893. package/apps/studio/client/v2/history/view-bar.jsx +80 -0
  894. package/apps/studio/client/v2/import/brand-model.js +145 -0
  895. package/apps/studio/client/v2/import/brand-result.jsx +197 -0
  896. package/apps/studio/client/v2/import/brand-sheet.jsx +434 -0
  897. package/apps/studio/client/v2/import/brand.css +378 -0
  898. package/apps/studio/client/v2/import/figma-artboard.jsx +121 -0
  899. package/apps/studio/client/v2/import/figma-model.js +237 -0
  900. package/apps/studio/client/v2/import/figma-prefill.js +23 -0
  901. package/apps/studio/client/v2/import/figma-sheet.jsx +525 -0
  902. package/apps/studio/client/v2/import/figma-summary.jsx +62 -0
  903. package/apps/studio/client/v2/import/figma.css +179 -0
  904. package/apps/studio/client/v2/import/frame-picker.jsx +57 -0
  905. package/apps/studio/client/v2/inspect/inspect-host.jsx +53 -0
  906. package/apps/studio/client/v2/inspect/inspect-model.js +132 -0
  907. package/apps/studio/client/v2/inspect/inspect-panel.jsx +214 -0
  908. package/apps/studio/client/v2/inspect/inspect.css +87 -0
  909. package/apps/studio/client/v2/inspector/advanced-rows-default.jsx +773 -0
  910. package/apps/studio/client/v2/inspector/advanced-rows.js +106 -0
  911. package/apps/studio/client/v2/inspector/advanced.jsx +286 -0
  912. package/apps/studio/client/v2/inspector/blocks.js +57 -0
  913. package/apps/studio/client/v2/inspector/colour-groups.js +129 -0
  914. package/apps/studio/client/v2/inspector/component-picker.css +133 -0
  915. package/apps/studio/client/v2/inspector/component-picker.jsx +367 -0
  916. package/apps/studio/client/v2/inspector/crumbs.jsx +89 -0
  917. package/apps/studio/client/v2/inspector/css-text.js +179 -0
  918. package/apps/studio/client/v2/inspector/css-write.js +204 -0
  919. package/apps/studio/client/v2/inspector/element-code.js +39 -0
  920. package/apps/studio/client/v2/inspector/element-id.js +70 -0
  921. package/apps/studio/client/v2/inspector/formats-ui.js +101 -0
  922. package/apps/studio/client/v2/inspector/formats-write.js +60 -0
  923. package/apps/studio/client/v2/inspector/frame.jsx +336 -0
  924. package/apps/studio/client/v2/inspector/inspector-actions.js +60 -0
  925. package/apps/studio/client/v2/inspector/inspector.css +2872 -0
  926. package/apps/studio/client/v2/inspector/jsx-slice.js +219 -0
  927. package/apps/studio/client/v2/inspector/kinds/add-width.js +55 -0
  928. package/apps/studio/client/v2/inspector/kinds/artboard-advanced-rows.jsx +89 -0
  929. package/apps/studio/client/v2/inspector/kinds/artboard-advanced.jsx +62 -0
  930. package/apps/studio/client/v2/inspector/kinds/artboard-fixed.jsx +111 -0
  931. package/apps/studio/client/v2/inspector/kinds/artboard-kinds-model.js +171 -0
  932. package/apps/studio/client/v2/inspector/kinds/artboard-model.js +155 -0
  933. package/apps/studio/client/v2/inspector/kinds/artboard-multi.jsx +142 -0
  934. package/apps/studio/client/v2/inspector/kinds/artboard-print-advanced.jsx +210 -0
  935. package/apps/studio/client/v2/inspector/kinds/artboard-print-model.js +112 -0
  936. package/apps/studio/client/v2/inspector/kinds/artboard-print.jsx +268 -0
  937. package/apps/studio/client/v2/inspector/kinds/artboard-rows.jsx +124 -0
  938. package/apps/studio/client/v2/inspector/kinds/artboard-video.jsx +144 -0
  939. package/apps/studio/client/v2/inspector/kinds/artboard-web.jsx +170 -0
  940. package/apps/studio/client/v2/inspector/kinds/artboard.jsx +168 -0
  941. package/apps/studio/client/v2/inspector/kinds/caption.jsx +203 -0
  942. package/apps/studio/client/v2/inspector/kinds/clip-model.js +190 -0
  943. package/apps/studio/client/v2/inspector/kinds/clip.css +157 -0
  944. package/apps/studio/client/v2/inspector/kinds/clip.jsx +447 -0
  945. package/apps/studio/client/v2/inspector/kinds/frame.jsx +118 -0
  946. package/apps/studio/client/v2/inspector/kinds/image.jsx +267 -0
  947. package/apps/studio/client/v2/inspector/kinds/index.js +180 -0
  948. package/apps/studio/client/v2/inspector/kinds/instance.jsx +377 -0
  949. package/apps/studio/client/v2/inspector/kinds/multi-artboard.jsx +129 -0
  950. package/apps/studio/client/v2/inspector/kinds/multi.jsx +220 -0
  951. package/apps/studio/client/v2/inspector/kinds/music.jsx +294 -0
  952. package/apps/studio/client/v2/inspector/kinds/path.jsx +174 -0
  953. package/apps/studio/client/v2/inspector/kinds/shape.jsx +59 -0
  954. package/apps/studio/client/v2/inspector/kinds/text.jsx +518 -0
  955. package/apps/studio/client/v2/inspector/kinds/title-rows.jsx +135 -0
  956. package/apps/studio/client/v2/inspector/kinds/video-facts.js +142 -0
  957. package/apps/studio/client/v2/inspector/layers-row-tools.jsx +93 -0
  958. package/apps/studio/client/v2/inspector/layers-slot.jsx +93 -0
  959. package/apps/studio/client/v2/inspector/link-write.js +52 -0
  960. package/apps/studio/client/v2/inspector/live-size.js +96 -0
  961. package/apps/studio/client/v2/inspector/model.js +228 -0
  962. package/apps/studio/client/v2/inspector/path-point.js +104 -0
  963. package/apps/studio/client/v2/inspector/print-write.js +85 -0
  964. package/apps/studio/client/v2/inspector/safe-zones-write.js +88 -0
  965. package/apps/studio/client/v2/inspector/sections/add-requests.js +35 -0
  966. package/apps/studio/client/v2/inspector/sections/border.jsx +141 -0
  967. package/apps/studio/client/v2/inspector/sections/color-control.jsx +246 -0
  968. package/apps/studio/client/v2/inspector/sections/colour-custom.jsx +826 -0
  969. package/apps/studio/client/v2/inspector/sections/colour-model.js +404 -0
  970. package/apps/studio/client/v2/inspector/sections/colour-popover.jsx +631 -0
  971. package/apps/studio/client/v2/inspector/sections/colour-words.js +131 -0
  972. package/apps/studio/client/v2/inspector/sections/corners.jsx +177 -0
  973. package/apps/studio/client/v2/inspector/sections/effects.jsx +67 -0
  974. package/apps/studio/client/v2/inspector/sections/export-slot.jsx +60 -0
  975. package/apps/studio/client/v2/inspector/sections/fill.jsx +187 -0
  976. package/apps/studio/client/v2/inspector/sections/formats.jsx +209 -0
  977. package/apps/studio/client/v2/inspector/sections/index.js +74 -0
  978. package/apps/studio/client/v2/inspector/sections/interaction.jsx +204 -0
  979. package/apps/studio/client/v2/inspector/sections/layout.jsx +314 -0
  980. package/apps/studio/client/v2/inspector/sections/opacity-row.jsx +37 -0
  981. package/apps/studio/client/v2/inspector/sections/point.jsx +102 -0
  982. package/apps/studio/client/v2/inspector/sections/position.jsx +259 -0
  983. package/apps/studio/client/v2/inspector/sections/recent-colours.js +106 -0
  984. package/apps/studio/client/v2/inspector/sections/row.jsx +91 -0
  985. package/apps/studio/client/v2/inspector/sections/safe-zones.jsx +174 -0
  986. package/apps/studio/client/v2/inspector/sections/sections.css +1474 -0
  987. package/apps/studio/client/v2/inspector/sections/size.jsx +104 -0
  988. package/apps/studio/client/v2/inspector/sections/type.jsx +168 -0
  989. package/apps/studio/client/v2/inspector/sections/warnings.css +44 -0
  990. package/apps/studio/client/v2/inspector/sections/warnings.jsx +137 -0
  991. package/apps/studio/client/v2/inspector/sections.js +226 -0
  992. package/apps/studio/client/v2/inspector/slots.js +110 -0
  993. package/apps/studio/client/v2/inspector/token-chip.jsx +315 -0
  994. package/apps/studio/client/v2/inspector/view-mode.jsx +193 -0
  995. package/apps/studio/client/v2/inspector/warning-fix.js +111 -0
  996. package/apps/studio/client/v2/kinds/ConvertDialog.jsx +183 -0
  997. package/apps/studio/client/v2/kinds/KindChips.jsx +60 -0
  998. package/apps/studio/client/v2/kinds/KindDimHost.jsx +35 -0
  999. package/apps/studio/client/v2/kinds/LayersKindFilter.jsx +108 -0
  1000. package/apps/studio/client/v2/kinds/SizePicker.jsx +566 -0
  1001. package/apps/studio/client/v2/kinds/SizePickerHost.jsx +104 -0
  1002. package/apps/studio/client/v2/kinds/advanced-rows.js +40 -0
  1003. package/apps/studio/client/v2/kinds/convert-api.js +116 -0
  1004. package/apps/studio/client/v2/kinds/convert.css +87 -0
  1005. package/apps/studio/client/v2/kinds/kind-dim-relay.js +93 -0
  1006. package/apps/studio/client/v2/kinds/kind-filter-model.js +106 -0
  1007. package/apps/studio/client/v2/kinds/kind-filter-store.js +71 -0
  1008. package/apps/studio/client/v2/kinds/kind-filter.css +105 -0
  1009. package/apps/studio/client/v2/kinds/layers-kind-model.js +99 -0
  1010. package/apps/studio/client/v2/kinds/size-picker-model.js +189 -0
  1011. package/apps/studio/client/v2/kinds/size-picker.css +393 -0
  1012. package/apps/studio/client/v2/layers/artboard-layers.jsx +105 -0
  1013. package/apps/studio/client/v2/layers/layers.css +94 -0
  1014. package/apps/studio/client/v2/left-panel/advanced-model.js +98 -0
  1015. package/apps/studio/client/v2/left-panel/assets-panel.jsx +1203 -0
  1016. package/apps/studio/client/v2/left-panel/canvas-file-menu.js +115 -0
  1017. package/apps/studio/client/v2/left-panel/canvases-advanced.jsx +270 -0
  1018. package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +274 -0
  1019. package/apps/studio/client/v2/left-panel/layers-advanced.jsx +179 -0
  1020. package/apps/studio/client/v2/left-panel/left-panel-bus.js +83 -0
  1021. package/apps/studio/client/v2/left-panel/left-panel-model.js +184 -0
  1022. package/apps/studio/client/v2/left-panel/left-panel.css +1846 -0
  1023. package/apps/studio/client/v2/left-panel/selector-scope.js +42 -0
  1024. package/apps/studio/client/v2/left-panel/trash-model.js +282 -0
  1025. package/apps/studio/client/v2/left-panel/trash-view.jsx +257 -0
  1026. package/apps/studio/client/v2/left-panel/use-trash.js +172 -0
  1027. package/apps/studio/client/v2/left-panel/view-prefs.js +84 -0
  1028. package/apps/studio/client/v2/onboarding/AdvSheet.jsx +114 -0
  1029. package/apps/studio/client/v2/onboarding/AdvancedSheets.jsx +239 -0
  1030. package/apps/studio/client/v2/onboarding/CliSheet.jsx +101 -0
  1031. package/apps/studio/client/v2/onboarding/ConnectAiSheet.jsx +60 -0
  1032. package/apps/studio/client/v2/onboarding/FigmaSheet.jsx +96 -0
  1033. package/apps/studio/client/v2/onboarding/FolderGithubSheet.jsx +77 -0
  1034. package/apps/studio/client/v2/onboarding/GithubSegment.jsx +241 -0
  1035. package/apps/studio/client/v2/onboarding/HubSheet.jsx +244 -0
  1036. package/apps/studio/client/v2/onboarding/connect-ai-home.js +94 -0
  1037. package/apps/studio/client/v2/onboarding/github-home.js +84 -0
  1038. package/apps/studio/client/v2/onboarding/onboarding-model.js +106 -0
  1039. package/apps/studio/client/v2/onboarding/onboarding.css +546 -0
  1040. package/apps/studio/client/v2/photo/apply-every-use-sheet.jsx +196 -0
  1041. package/apps/studio/client/v2/photo/canvas-rel.js +20 -0
  1042. package/apps/studio/client/v2/photo/looks.js +129 -0
  1043. package/apps/studio/client/v2/photo/photo-section.jsx +625 -0
  1044. package/apps/studio/client/v2/photo/photo.css +218 -0
  1045. package/apps/studio/client/v2/portal-scope.jsx +14 -0
  1046. package/apps/studio/client/v2/presence/faces.jsx +356 -0
  1047. package/apps/studio/client/v2/presence/presence.css +187 -0
  1048. package/apps/studio/client/v2/presence/use-presence-host.js +83 -0
  1049. package/apps/studio/client/v2/present/audience-window.js +63 -0
  1050. package/apps/studio/client/v2/present/canvas-pill.jsx +55 -0
  1051. package/apps/studio/client/v2/present/copy-link.js +82 -0
  1052. package/apps/studio/client/v2/present/follow-location.js +82 -0
  1053. package/apps/studio/client/v2/present/follow-model.js +68 -0
  1054. package/apps/studio/client/v2/present/follow-view.jsx +354 -0
  1055. package/apps/studio/client/v2/present/follow.css +91 -0
  1056. package/apps/studio/client/v2/present/order-map.jsx +64 -0
  1057. package/apps/studio/client/v2/present/order-notes-artboards.js +88 -0
  1058. package/apps/studio/client/v2/present/order-notes-model.js +141 -0
  1059. package/apps/studio/client/v2/present/order-notes-mount.jsx +26 -0
  1060. package/apps/studio/client/v2/present/order-notes-sheet.jsx +293 -0
  1061. package/apps/studio/client/v2/present/order-notes.css +150 -0
  1062. package/apps/studio/client/v2/present/present-chrome-host.jsx +95 -0
  1063. package/apps/studio/client/v2/present/present-controls-model.js +114 -0
  1064. package/apps/studio/client/v2/present/present-controls.jsx +263 -0
  1065. package/apps/studio/client/v2/present/present-zoom-store.js +33 -0
  1066. package/apps/studio/client/v2/present/present.css +258 -0
  1067. package/apps/studio/client/v2/present/presenter-button.jsx +25 -0
  1068. package/apps/studio/client/v2/present/presenter-host.jsx +246 -0
  1069. package/apps/studio/client/v2/present/presenter-model.js +167 -0
  1070. package/apps/studio/client/v2/present/presenter-store.js +140 -0
  1071. package/apps/studio/client/v2/present/presenter-view.css +298 -0
  1072. package/apps/studio/client/v2/present/presenter-view.jsx +241 -0
  1073. package/apps/studio/client/v2/present/video-present-model.js +92 -0
  1074. package/apps/studio/client/v2/present/video-present.css +164 -0
  1075. package/apps/studio/client/v2/present/video-present.jsx +331 -0
  1076. package/apps/studio/client/v2/preview/external-link-confirm.jsx +245 -0
  1077. package/apps/studio/client/v2/preview/link-follow.js +109 -0
  1078. package/apps/studio/client/v2/preview/open-in-app.jsx +46 -0
  1079. package/apps/studio/client/v2/preview/preview-back.js +21 -0
  1080. package/apps/studio/client/v2/preview/preview-bar.jsx +86 -0
  1081. package/apps/studio/client/v2/preview/preview-chrome-host.jsx +234 -0
  1082. package/apps/studio/client/v2/preview/preview-history.js +61 -0
  1083. package/apps/studio/client/v2/preview/preview.css +262 -0
  1084. package/apps/studio/client/v2/preview/zoom-only.jsx +58 -0
  1085. package/apps/studio/client/v2/search/help-model.js +275 -0
  1086. package/apps/studio/client/v2/search/moved-keys.js +74 -0
  1087. package/apps/studio/client/v2/search/palette-icons.js +45 -0
  1088. package/apps/studio/client/v2/search/search-ds.js +142 -0
  1089. package/apps/studio/client/v2/search/search-env.js +110 -0
  1090. package/apps/studio/client/v2/search/search-keywords.js +162 -0
  1091. package/apps/studio/client/v2/search/search-model.js +623 -0
  1092. package/apps/studio/client/v2/search/search-projects.js +214 -0
  1093. package/apps/studio/client/v2/search/search-recent.js +94 -0
  1094. package/apps/studio/client/v2/search/search-remote.js +30 -0
  1095. package/apps/studio/client/v2/search/search.css +519 -0
  1096. package/apps/studio/client/v2/settings/account.jsx +164 -0
  1097. package/apps/studio/client/v2/settings/advanced-prefs.js +91 -0
  1098. package/apps/studio/client/v2/settings/advanced-section.jsx +308 -0
  1099. package/apps/studio/client/v2/settings/connection-row.jsx +79 -0
  1100. package/apps/studio/client/v2/settings/connections-model.js +138 -0
  1101. package/apps/studio/client/v2/settings/connections-section.jsx +663 -0
  1102. package/apps/studio/client/v2/settings/general-section.jsx +155 -0
  1103. package/apps/studio/client/v2/settings/parts.jsx +48 -0
  1104. package/apps/studio/client/v2/settings/prefs-migrate.js +141 -0
  1105. package/apps/studio/client/v2/settings/project-sync-settings.jsx +255 -0
  1106. package/apps/studio/client/v2/settings/reset-section.jsx +164 -0
  1107. package/apps/studio/client/v2/settings/settings-handlers.js +46 -0
  1108. package/apps/studio/client/v2/settings/settings-model.js +523 -0
  1109. package/apps/studio/client/v2/settings/settings-sheet.jsx +204 -0
  1110. package/apps/studio/client/v2/settings/settings.css +975 -0
  1111. package/apps/studio/client/v2/settings/theme-auto.js +75 -0
  1112. package/apps/studio/client/v2/settings/use-advanced-prefs.js +32 -0
  1113. package/apps/studio/client/v2/settings/use-connections.js +485 -0
  1114. package/apps/studio/client/v2/share/glyphs.jsx +92 -0
  1115. package/apps/studio/client/v2/share/invite-row.jsx +68 -0
  1116. package/apps/studio/client/v2/share/link-dialog.js +53 -0
  1117. package/apps/studio/client/v2/share/link-row.jsx +38 -0
  1118. package/apps/studio/client/v2/share/move-to-cloud.jsx +88 -0
  1119. package/apps/studio/client/v2/share/people-list.jsx +151 -0
  1120. package/apps/studio/client/v2/share/person.jsx +26 -0
  1121. package/apps/studio/client/v2/share/role-menu.jsx +145 -0
  1122. package/apps/studio/client/v2/share/share-advanced.jsx +411 -0
  1123. package/apps/studio/client/v2/share/share-model.js +469 -0
  1124. package/apps/studio/client/v2/share/share-sheet.jsx +602 -0
  1125. package/apps/studio/client/v2/share/share.css +828 -0
  1126. package/apps/studio/client/v2/shell/account-card-model.js +114 -0
  1127. package/apps/studio/client/v2/shell/account-card.jsx +177 -0
  1128. package/apps/studio/client/v2/shell/annotation-prefs-store.js +105 -0
  1129. package/apps/studio/client/v2/shell/ask-to-edit.js +33 -0
  1130. package/apps/studio/client/v2/shell/callouts-host.jsx +151 -0
  1131. package/apps/studio/client/v2/shell/callouts-model.js +358 -0
  1132. package/apps/studio/client/v2/shell/callouts.css +164 -0
  1133. package/apps/studio/client/v2/shell/callouts.jsx +162 -0
  1134. package/apps/studio/client/v2/shell/canvas-mode.js +393 -0
  1135. package/apps/studio/client/v2/shell/contrast.css +37 -0
  1136. package/apps/studio/client/v2/shell/corner-icons.jsx +153 -0
  1137. package/apps/studio/client/v2/shell/dock-rail-homes.js +106 -0
  1138. package/apps/studio/client/v2/shell/f6-cycle.js +124 -0
  1139. package/apps/studio/client/v2/shell/floating-panels.css +2858 -0
  1140. package/apps/studio/client/v2/shell/fold-ghost.js +70 -0
  1141. package/apps/studio/client/v2/shell/format-update.css +43 -0
  1142. package/apps/studio/client/v2/shell/format-update.js +487 -0
  1143. package/apps/studio/client/v2/shell/format-update.jsx +479 -0
  1144. package/apps/studio/client/v2/shell/held-conflict.js +51 -0
  1145. package/apps/studio/client/v2/shell/image-pick.js +140 -0
  1146. package/apps/studio/client/v2/shell/insets-now.js +35 -0
  1147. package/apps/studio/client/v2/shell/inspector-follow.js +113 -0
  1148. package/apps/studio/client/v2/shell/menu-runner.js +711 -0
  1149. package/apps/studio/client/v2/shell/modal-focus.js +259 -0
  1150. package/apps/studio/client/v2/shell/mode-switch.jsx +418 -0
  1151. package/apps/studio/client/v2/shell/native-doors.js +121 -0
  1152. package/apps/studio/client/v2/shell/occlusion-insets.js +116 -0
  1153. package/apps/studio/client/v2/shell/panel-availability.js +27 -0
  1154. package/apps/studio/client/v2/shell/panel-layout.js +144 -0
  1155. package/apps/studio/client/v2/shell/panel-sizes.js +150 -0
  1156. package/apps/studio/client/v2/shell/paste-forward.js +43 -0
  1157. package/apps/studio/client/v2/shell/present-from-label.js +19 -0
  1158. package/apps/studio/client/v2/shell/project-menu-model.js +216 -0
  1159. package/apps/studio/client/v2/shell/project-pill.css +214 -0
  1160. package/apps/studio/client/v2/shell/project-pill.jsx +456 -0
  1161. package/apps/studio/client/v2/shell/recovery-store.js +139 -0
  1162. package/apps/studio/client/v2/shell/role-denial.js +73 -0
  1163. package/apps/studio/client/v2/shell/role-gate.js +29 -0
  1164. package/apps/studio/client/v2/shell/save-hold-notice.js +69 -0
  1165. package/apps/studio/client/v2/shell/save-status.js +191 -0
  1166. package/apps/studio/client/v2/shell/scroll-lock.js +49 -0
  1167. package/apps/studio/client/v2/shell/share-cluster-host.jsx +389 -0
  1168. package/apps/studio/client/v2/shell/share-cluster.css +608 -0
  1169. package/apps/studio/client/v2/shell/share-cluster.jsx +255 -0
  1170. package/apps/studio/client/v2/shell/shell-error-boundary.jsx +81 -0
  1171. package/apps/studio/client/v2/shell/shell-panels-relay.js +95 -0
  1172. package/apps/studio/client/v2/shell/shell-parity.js +457 -0
  1173. package/apps/studio/client/v2/shell/shell-parity.json +2106 -0
  1174. package/apps/studio/client/v2/shell/single-keys-store.js +49 -0
  1175. package/apps/studio/client/v2/shell/tool-panels.css +39 -0
  1176. package/apps/studio/client/v2/shell/tool-panels.js +156 -0
  1177. package/apps/studio/client/v2/shell/use-account.js +59 -0
  1178. package/apps/studio/client/v2/shell/use-annotation-prefs.js +77 -0
  1179. package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +388 -0
  1180. package/apps/studio/client/v2/shell/use-dismiss-outside.js +35 -0
  1181. package/apps/studio/client/v2/shell/use-fit-on-ai-pin.js +42 -0
  1182. package/apps/studio/client/v2/shell/use-fit-while-ai-drafts.js +37 -0
  1183. package/apps/studio/client/v2/shell/use-occluded-insets.js +107 -0
  1184. package/apps/studio/client/v2/shell/use-panel-layout.js +45 -0
  1185. package/apps/studio/client/v2/shell/use-single-keys.js +56 -0
  1186. package/apps/studio/client/v2/shell/use-tool-panels.js +205 -0
  1187. package/apps/studio/client/v2/signin/CreateLocalSheet.jsx +155 -0
  1188. package/apps/studio/client/v2/signin/SignInCard.jsx +284 -0
  1189. package/apps/studio/client/v2/signin/SignInToast.jsx +22 -0
  1190. package/apps/studio/client/v2/signin/WhatsNewLine.jsx +64 -0
  1191. package/apps/studio/client/v2/signin/advanced-rows.js +40 -0
  1192. package/apps/studio/client/v2/signin/signin-model.js +138 -0
  1193. package/apps/studio/client/v2/signin/signin.css +484 -0
  1194. package/apps/studio/client/v2/signin/use-signin.js +209 -0
  1195. package/apps/studio/client/v2/signin/use-whats-new-line.js +94 -0
  1196. package/apps/studio/client/v2/sync-states/back-online.jsx +61 -0
  1197. package/apps/studio/client/v2/sync-states/conflict-card.jsx +326 -0
  1198. package/apps/studio/client/v2/sync-states/offline-foot.jsx +79 -0
  1199. package/apps/studio/client/v2/sync-states/row-words.js +83 -0
  1200. package/apps/studio/client/v2/sync-states/sync-states-model.js +264 -0
  1201. package/apps/studio/client/v2/sync-states/sync-states.css +232 -0
  1202. package/apps/studio/client/v2/timeline/Timeline.jsx +3194 -0
  1203. package/apps/studio/client/v2/timeline/TimelineHost.jsx +360 -0
  1204. package/apps/studio/client/v2/timeline/advanced/actions.js +27 -0
  1205. package/apps/studio/client/v2/timeline/advanced/advanced-store.js +116 -0
  1206. package/apps/studio/client/v2/timeline/advanced/advanced.css +323 -0
  1207. package/apps/studio/client/v2/timeline/advanced/cut-as-code.jsx +127 -0
  1208. package/apps/studio/client/v2/timeline/advanced/easing-curve.jsx +200 -0
  1209. package/apps/studio/client/v2/timeline/advanced/foot.jsx +210 -0
  1210. package/apps/studio/client/v2/timeline/advanced/model.js +121 -0
  1211. package/apps/studio/client/v2/timeline/advanced/render-settings.jsx +62 -0
  1212. package/apps/studio/client/v2/timeline/advanced/video-cap.js +174 -0
  1213. package/apps/studio/client/v2/timeline/ai-edge-model.js +111 -0
  1214. package/apps/studio/client/v2/timeline/ai-edge.css +104 -0
  1215. package/apps/studio/client/v2/timeline/ai-edge.jsx +113 -0
  1216. package/apps/studio/client/v2/timeline/anchor-lane.js +80 -0
  1217. package/apps/studio/client/v2/timeline/anchor.js +80 -0
  1218. package/apps/studio/client/v2/timeline/assemble-video.js +64 -0
  1219. package/apps/studio/client/v2/timeline/clip-search.js +88 -0
  1220. package/apps/studio/client/v2/timeline/clip-verb.js +224 -0
  1221. package/apps/studio/client/v2/timeline/comment-strip-host.jsx +93 -0
  1222. package/apps/studio/client/v2/timeline/comment-strip-model.js +103 -0
  1223. package/apps/studio/client/v2/timeline/comment-strip.jsx +82 -0
  1224. package/apps/studio/client/v2/timeline/edit/clip-menu.js +118 -0
  1225. package/apps/studio/client/v2/timeline/edit/clip-menu.jsx +48 -0
  1226. package/apps/studio/client/v2/timeline/edit/drop.jsx +101 -0
  1227. package/apps/studio/client/v2/timeline/edit/move.jsx +43 -0
  1228. package/apps/studio/client/v2/timeline/edit/ripple.js +43 -0
  1229. package/apps/studio/client/v2/timeline/edit/trim.jsx +52 -0
  1230. package/apps/studio/client/v2/timeline/edit/words.js +65 -0
  1231. package/apps/studio/client/v2/timeline/fit-fill.jsx +172 -0
  1232. package/apps/studio/client/v2/timeline/fit-model.js +137 -0
  1233. package/apps/studio/client/v2/timeline/fold.js +128 -0
  1234. package/apps/studio/client/v2/timeline/footage-rows.jsx +46 -0
  1235. package/apps/studio/client/v2/timeline/footage-state.js +135 -0
  1236. package/apps/studio/client/v2/timeline/glyphs.jsx +118 -0
  1237. package/apps/studio/client/v2/timeline/island-context.js +29 -0
  1238. package/apps/studio/client/v2/timeline/island-controls.jsx +83 -0
  1239. package/apps/studio/client/v2/timeline/island.jsx +54 -0
  1240. package/apps/studio/client/v2/timeline/joins/join-model.js +133 -0
  1241. package/apps/studio/client/v2/timeline/joins/joins.css +277 -0
  1242. package/apps/studio/client/v2/timeline/joins/transition-picker.jsx +240 -0
  1243. package/apps/studio/client/v2/timeline/keys.js +74 -0
  1244. package/apps/studio/client/v2/timeline/lanes/caption-lane.jsx +149 -0
  1245. package/apps/studio/client/v2/timeline/lanes/music-lane.jsx +294 -0
  1246. package/apps/studio/client/v2/timeline/lanes/music-media.js +200 -0
  1247. package/apps/studio/client/v2/timeline/lanes/music-model.js +190 -0
  1248. package/apps/studio/client/v2/timeline/loop-handle.jsx +70 -0
  1249. package/apps/studio/client/v2/timeline/marker-store.js +117 -0
  1250. package/apps/studio/client/v2/timeline/markers.js +79 -0
  1251. package/apps/studio/client/v2/timeline/marks.jsx +152 -0
  1252. package/apps/studio/client/v2/timeline/music-hint.jsx +98 -0
  1253. package/apps/studio/client/v2/timeline/other-takes-model.js +103 -0
  1254. package/apps/studio/client/v2/timeline/other-takes-store.js +49 -0
  1255. package/apps/studio/client/v2/timeline/other-takes.css +98 -0
  1256. package/apps/studio/client/v2/timeline/other-takes.jsx +269 -0
  1257. package/apps/studio/client/v2/timeline/peers.jsx +246 -0
  1258. package/apps/studio/client/v2/timeline/playhead.js +97 -0
  1259. package/apps/studio/client/v2/timeline/poster.js +109 -0
  1260. package/apps/studio/client/v2/timeline/reframe-island.jsx +478 -0
  1261. package/apps/studio/client/v2/timeline/reframe-model.js +135 -0
  1262. package/apps/studio/client/v2/timeline/reframe.css +150 -0
  1263. package/apps/studio/client/v2/timeline/ruler.js +61 -0
  1264. package/apps/studio/client/v2/timeline/selection.js +110 -0
  1265. package/apps/studio/client/v2/timeline/timeline-empty.jsx +108 -0
  1266. package/apps/studio/client/v2/timeline/timeline-store.js +147 -0
  1267. package/apps/studio/client/v2/timeline/timeline.css +2879 -0
  1268. package/apps/studio/client/v2/timeline/together.css +85 -0
  1269. package/apps/studio/client/v2/timeline/track-toggle.js +56 -0
  1270. package/apps/studio/client/v2/timeline/tracks.js +68 -0
  1271. package/apps/studio/client/v2/timeline/transport.js +66 -0
  1272. package/apps/studio/client/v2/timeline/zoom.js +37 -0
  1273. package/apps/studio/client/v2/transcript/TranscriptHost.jsx +162 -0
  1274. package/apps/studio/client/v2/transcript/TranscriptPanel.jsx +358 -0
  1275. package/apps/studio/client/v2/transcript/captions-api.js +297 -0
  1276. package/apps/studio/client/v2/transcript/captions-file-flag.js +38 -0
  1277. package/apps/studio/client/v2/transcript/comp-media-store.js +89 -0
  1278. package/apps/studio/client/v2/transcript/transcript-model.js +240 -0
  1279. package/apps/studio/client/v2/transcript/transcript.css +262 -0
  1280. package/apps/studio/client/v2/undo/projection.js +291 -0
  1281. package/apps/studio/client/v2/undo/undo-history.jsx +286 -0
  1282. package/apps/studio/client/v2/undo/undo.css +81 -0
  1283. package/apps/studio/client/v2/undo/use-undo-mode-lane.js +96 -0
  1284. package/apps/studio/client/v2/undo/use-undo-projection.jsx +460 -0
  1285. package/apps/studio/client/v2/undo/zoom-undo.jsx +79 -0
  1286. package/apps/studio/client/whats-new-seen.js +40 -0
  1287. package/apps/studio/client/whats-new.jsx +65 -62
  1288. package/apps/studio/clip-ops.ts +38 -6
  1289. package/apps/studio/cloud/config-path.ts +42 -0
  1290. package/apps/studio/cloud/endpoints.ts +212 -50
  1291. package/apps/studio/cloud/renew.ts +29 -16
  1292. package/apps/studio/collab/ai-activity.ts +19 -0
  1293. package/apps/studio/collab/awareness-bridge.ts +131 -4
  1294. package/apps/studio/collab/git-lifecycle.ts +52 -20
  1295. package/apps/studio/collab/holds.ts +69 -0
  1296. package/apps/studio/collab/index.ts +25 -0
  1297. package/apps/studio/collab/protocol.ts +64 -0
  1298. package/apps/studio/collab/registry.ts +59 -6
  1299. package/apps/studio/collab/room.ts +374 -16
  1300. package/apps/studio/collab/timeline-awareness.ts +123 -0
  1301. package/apps/studio/collab/timeline-presence.tsx +219 -0
  1302. package/apps/studio/commands/move-artboards-command.ts +45 -4
  1303. package/apps/studio/comments/anchors.ts +147 -0
  1304. package/apps/studio/comments/author-face.ts +41 -0
  1305. package/apps/studio/comments/from-line.ts +43 -0
  1306. package/apps/studio/comments/imported-from.ts +113 -0
  1307. package/apps/studio/comments/local-author.ts +41 -0
  1308. package/apps/studio/comments/mentions.ts +115 -0
  1309. package/apps/studio/comments/mine-stamp.ts +78 -0
  1310. package/apps/studio/comments/ops.ts +293 -0
  1311. package/apps/studio/comments/people.ts +66 -0
  1312. package/apps/studio/comments/where.ts +136 -0
  1313. package/apps/studio/comments-overlay.tsx +1220 -253
  1314. package/apps/studio/config.schema.json +33 -0
  1315. package/apps/studio/context-menu.tsx +126 -42
  1316. package/apps/studio/context.ts +178 -13
  1317. package/apps/studio/cursors-overlay.tsx +28 -11
  1318. package/apps/studio/debug-bundle.ts +21 -5
  1319. package/apps/studio/describe/batch.ts +414 -0
  1320. package/apps/studio/describe/budget.ts +147 -0
  1321. package/apps/studio/describe/claude.ts +273 -0
  1322. package/apps/studio/describe/consent.ts +120 -0
  1323. package/apps/studio/describe/validate.ts +192 -0
  1324. package/apps/studio/design-setup-readiness.ts +2 -2
  1325. package/apps/studio/diagnostics/store.ts +220 -0
  1326. package/apps/studio/dist/client.bundle.js +2429 -2329
  1327. package/apps/studio/dist/comment-mount.js +12 -9
  1328. package/apps/studio/dist/styles.css +1 -1
  1329. package/apps/studio/dom-selection.ts +239 -23
  1330. package/apps/studio/drag-bus.ts +211 -0
  1331. package/apps/studio/draw/serialize-animate.ts +4 -4
  1332. package/apps/studio/ds/board/board-specimen.css +199 -0
  1333. package/apps/studio/ds/board/board.css +674 -0
  1334. package/apps/studio/ds/board/brand-notes.ts +92 -0
  1335. package/apps/studio/ds/board/build-model.ts +418 -0
  1336. package/apps/studio/ds/board/component-states.ts +111 -0
  1337. package/apps/studio/ds/board/directions-model.ts +145 -0
  1338. package/apps/studio/ds/board/directions.css +169 -0
  1339. package/apps/studio/ds/board/directions.tsx +100 -0
  1340. package/apps/studio/ds/board/ds-bar.tsx +107 -0
  1341. package/apps/studio/ds/board/index.tsx +71 -0
  1342. package/apps/studio/ds/board/logo-paint.ts +118 -0
  1343. package/apps/studio/ds/board/outline.tsx +127 -0
  1344. package/apps/studio/ds/board/parts.tsx +160 -0
  1345. package/apps/studio/ds/board/section-brand.tsx +148 -0
  1346. package/apps/studio/ds/board/section-colour.tsx +160 -0
  1347. package/apps/studio/ds/board/section-components.tsx +146 -0
  1348. package/apps/studio/ds/board/section-motion.tsx +106 -0
  1349. package/apps/studio/ds/board/section-patterns.tsx +89 -0
  1350. package/apps/studio/ds/board/section-space.tsx +109 -0
  1351. package/apps/studio/ds/board/section-type.tsx +129 -0
  1352. package/apps/studio/ds/board/specimen.tsx +61 -0
  1353. package/apps/studio/ds/board/state.ts +105 -0
  1354. package/apps/studio/ds/board/template.ts +152 -0
  1355. package/apps/studio/ds/board/types.ts +346 -0
  1356. package/apps/studio/ds/canvas-check.ts +914 -0
  1357. package/apps/studio/ds/canvas-cli.ts +346 -0
  1358. package/apps/studio/ds/check-system-verb.ts +88 -0
  1359. package/apps/studio/ds/check-system.ts +293 -0
  1360. package/apps/studio/ds/check.ts +541 -0
  1361. package/apps/studio/ds/cli.ts +348 -0
  1362. package/apps/studio/ds/component-list.ts +150 -0
  1363. package/apps/studio/ds/contrast.ts +438 -0
  1364. package/apps/studio/ds/convert-map.ts +126 -0
  1365. package/apps/studio/ds/convert.ts +603 -0
  1366. package/apps/studio/ds/css-scan.ts +292 -0
  1367. package/apps/studio/ds/default-components.tsx +377 -0
  1368. package/apps/studio/ds/default.ts +58 -0
  1369. package/apps/studio/ds/design-system.tsx.tpl +40 -0
  1370. package/apps/studio/ds/ds-resolver.ts +205 -0
  1371. package/apps/studio/ds/ds-verb.ts +563 -0
  1372. package/apps/studio/ds/edges.ts +412 -0
  1373. package/apps/studio/ds/emit.ts +217 -0
  1374. package/apps/studio/ds/engine.ts +1652 -0
  1375. package/apps/studio/ds/fallbacks.ts +116 -0
  1376. package/apps/studio/ds/generate.ts +746 -0
  1377. package/apps/studio/ds/head.ts +372 -0
  1378. package/apps/studio/ds/instance-info.ts +90 -0
  1379. package/apps/studio/ds/library.ts +1137 -0
  1380. package/apps/studio/ds/make.ts +726 -0
  1381. package/apps/studio/ds/migrate-emitter.ts +42 -0
  1382. package/apps/studio/ds/nearest.ts +163 -0
  1383. package/apps/studio/ds/outside.ts +343 -0
  1384. package/apps/studio/ds/override-map.ts +213 -0
  1385. package/apps/studio/ds/pairing-css.ts +145 -0
  1386. package/apps/studio/ds/pin-scope.ts +268 -0
  1387. package/apps/studio/ds/registry.ts +228 -0
  1388. package/apps/studio/ds/rename.ts +104 -0
  1389. package/apps/studio/ds/render-rev.ts +144 -0
  1390. package/apps/studio/ds/revision.ts +268 -0
  1391. package/apps/studio/ds/shell-fallbacks.ts +84 -0
  1392. package/apps/studio/ds/switch.ts +426 -0
  1393. package/apps/studio/ds/system-files.ts +251 -0
  1394. package/apps/studio/ds/system.ts +312 -0
  1395. package/apps/studio/ds/undo-hook.ts +46 -0
  1396. package/apps/studio/ds/upgrade-apply.ts +258 -0
  1397. package/apps/studio/ds/upgrade-cli.ts +216 -0
  1398. package/apps/studio/ds/upgrade-codemod.ts +116 -0
  1399. package/apps/studio/ds/upgrade-progress.ts +153 -0
  1400. package/apps/studio/ds/upgrade-prove.ts +429 -0
  1401. package/apps/studio/ds/upgrade-stage.ts +387 -0
  1402. package/apps/studio/ds/upgrade.ts +394 -0
  1403. package/apps/studio/ds/value-types.ts +190 -0
  1404. package/apps/studio/edit-ops/align.ts +43 -0
  1405. package/apps/studio/edit-ops/arrange.ts +93 -0
  1406. package/apps/studio/edit-ops/artboard-facts.ts +70 -0
  1407. package/apps/studio/edit-ops/artboard-resize.ts +50 -0
  1408. package/apps/studio/edit-ops/artboard-trash.ts +77 -0
  1409. package/apps/studio/edit-ops/clear-link.ts +16 -0
  1410. package/apps/studio/edit-ops/clip/captions.ts +154 -0
  1411. package/apps/studio/edit-ops/clip/comp.ts +124 -0
  1412. package/apps/studio/edit-ops/clip/cut-source-range.ts +100 -0
  1413. package/apps/studio/edit-ops/clip/cut-to-beat.ts +136 -0
  1414. package/apps/studio/edit-ops/clip/duck.ts +123 -0
  1415. package/apps/studio/edit-ops/clip/easing.ts +76 -0
  1416. package/apps/studio/edit-ops/clip/formats.ts +163 -0
  1417. package/apps/studio/edit-ops/clip/gestures.ts +161 -0
  1418. package/apps/studio/edit-ops/clip/index.ts +543 -0
  1419. package/apps/studio/edit-ops/clip/jsx.ts +251 -0
  1420. package/apps/studio/edit-ops/clip/place.ts +127 -0
  1421. package/apps/studio/edit-ops/clip/reframe.ts +194 -0
  1422. package/apps/studio/edit-ops/clip/take-swap.ts +53 -0
  1423. package/apps/studio/edit-ops/clip/title-motion.ts +103 -0
  1424. package/apps/studio/edit-ops/clip/title-style.ts +177 -0
  1425. package/apps/studio/edit-ops/clip/track.ts +102 -0
  1426. package/apps/studio/edit-ops/clipboard.ts +482 -0
  1427. package/apps/studio/edit-ops/combine.ts +264 -0
  1428. package/apps/studio/edit-ops/constraints.ts +148 -0
  1429. package/apps/studio/edit-ops/convert-kind.ts +203 -0
  1430. package/apps/studio/edit-ops/corner-radius.ts +86 -0
  1431. package/apps/studio/edit-ops/crop.ts +303 -0
  1432. package/apps/studio/edit-ops/czech-ties.ts +84 -0
  1433. package/apps/studio/edit-ops/detach-instance.ts +119 -0
  1434. package/apps/studio/edit-ops/dispatch.ts +552 -0
  1435. package/apps/studio/edit-ops/distribute.ts +31 -0
  1436. package/apps/studio/edit-ops/ds-instance-update.ts +46 -0
  1437. package/apps/studio/edit-ops/ds-use-nearest.ts +72 -0
  1438. package/apps/studio/edit-ops/duplicate-at-width.ts +241 -0
  1439. package/apps/studio/edit-ops/frame.ts +68 -0
  1440. package/apps/studio/edit-ops/guides.ts +67 -0
  1441. package/apps/studio/edit-ops/hide.ts +30 -0
  1442. package/apps/studio/edit-ops/hover-rules.ts +94 -0
  1443. package/apps/studio/edit-ops/image-fit.ts +571 -0
  1444. package/apps/studio/edit-ops/insert-component.ts +344 -0
  1445. package/apps/studio/edit-ops/insert-preset.ts +151 -0
  1446. package/apps/studio/edit-ops/insert-shape.ts +326 -0
  1447. package/apps/studio/edit-ops/instance-model.ts +286 -0
  1448. package/apps/studio/edit-ops/instance-tree.ts +215 -0
  1449. package/apps/studio/edit-ops/layout-patch.ts +81 -0
  1450. package/apps/studio/edit-ops/lock.ts +30 -0
  1451. package/apps/studio/edit-ops/op-label.ts +155 -0
  1452. package/apps/studio/edit-ops/path-model.ts +671 -0
  1453. package/apps/studio/edit-ops/path.ts +172 -0
  1454. package/apps/studio/edit-ops/photo-every-use.ts +64 -0
  1455. package/apps/studio/edit-ops/photo-use.ts +41 -0
  1456. package/apps/studio/edit-ops/place-freely.ts +47 -0
  1457. package/apps/studio/edit-ops/place-plan.ts +60 -0
  1458. package/apps/studio/edit-ops/print.ts +104 -0
  1459. package/apps/studio/edit-ops/references.ts +231 -0
  1460. package/apps/studio/edit-ops/relink.ts +49 -0
  1461. package/apps/studio/edit-ops/reorder.ts +104 -0
  1462. package/apps/studio/edit-ops/reset-overrides.ts +75 -0
  1463. package/apps/studio/edit-ops/revert.ts +63 -0
  1464. package/apps/studio/edit-ops/rotate.ts +58 -0
  1465. package/apps/studio/edit-ops/safe-zones.ts +38 -0
  1466. package/apps/studio/edit-ops/scope-names.ts +151 -0
  1467. package/apps/studio/edit-ops/select-matching.ts +48 -0
  1468. package/apps/studio/edit-ops/set-gap.ts +65 -0
  1469. package/apps/studio/edit-ops/set-id.ts +42 -0
  1470. package/apps/studio/edit-ops/set-link.ts +39 -0
  1471. package/apps/studio/edit-ops/siblings.ts +105 -0
  1472. package/apps/studio/edit-ops/slot-defaults.ts +48 -0
  1473. package/apps/studio/edit-ops/stamp.ts +27 -0
  1474. package/apps/studio/edit-ops/swap-variant.ts +163 -0
  1475. package/apps/studio/edit-ops/text-copy.ts +146 -0
  1476. package/apps/studio/edit-ops/text-detach.ts +62 -0
  1477. package/apps/studio/edit-ops/text-style-ops.ts +131 -0
  1478. package/apps/studio/edit-ops/text-style.ts +141 -0
  1479. package/apps/studio/edit-ops/tidy.ts +72 -0
  1480. package/apps/studio/edit-ops/types.ts +229 -0
  1481. package/apps/studio/edit-ops/unframe.ts +53 -0
  1482. package/apps/studio/edit-ops/words-css.ts +487 -0
  1483. package/apps/studio/edit-ops/words-paint.ts +521 -0
  1484. package/apps/studio/edit-ops/z-order.ts +81 -0
  1485. package/apps/studio/editing/ai-point-ring.tsx +158 -0
  1486. package/apps/studio/editing/ai-scope-outline.tsx +180 -0
  1487. package/apps/studio/editing/align-bar.tsx +510 -0
  1488. package/apps/studio/editing/anchor-report.ts +123 -0
  1489. package/apps/studio/editing/anchor-reporter.tsx +64 -0
  1490. package/apps/studio/editing/aria-live.tsx +162 -0
  1491. package/apps/studio/editing/arrange.ts +345 -0
  1492. package/apps/studio/editing/artboard-actions.ts +275 -0
  1493. package/apps/studio/editing/artboard-commands.tsx +232 -0
  1494. package/apps/studio/editing/artboard-guides.tsx +265 -0
  1495. package/apps/studio/editing/artboard-handles.tsx +524 -0
  1496. package/apps/studio/editing/artboard-menu.tsx +153 -0
  1497. package/apps/studio/editing/artboard-resize.ts +306 -0
  1498. package/apps/studio/editing/ask-bubble.tsx +161 -0
  1499. package/apps/studio/editing/asset-drag.ts +70 -0
  1500. package/apps/studio/editing/click-to-type.ts +207 -0
  1501. package/apps/studio/editing/clipboard-actions.ts +91 -0
  1502. package/apps/studio/editing/clipboard.ts +194 -0
  1503. package/apps/studio/editing/clipped-grab.ts +45 -0
  1504. package/apps/studio/editing/corner-dots.tsx +394 -0
  1505. package/apps/studio/editing/crop-geometry.ts +128 -0
  1506. package/apps/studio/editing/crop-mode.tsx +522 -0
  1507. package/apps/studio/editing/crumbs.ts +158 -0
  1508. package/apps/studio/editing/draw-geometry.ts +151 -0
  1509. package/apps/studio/editing/draw-tools.tsx +490 -0
  1510. package/apps/studio/editing/drop-chip.tsx +105 -0
  1511. package/apps/studio/editing/duplicate-rhythm.ts +166 -0
  1512. package/apps/studio/editing/edit-chrome-gate.tsx +58 -0
  1513. package/apps/studio/editing/edit-op.ts +90 -0
  1514. package/apps/studio/editing/empty-report.ts +182 -0
  1515. package/apps/studio/editing/empty-reporter.tsx +74 -0
  1516. package/apps/studio/editing/figma-paste.ts +71 -0
  1517. package/apps/studio/editing/finder-drop-model.ts +130 -0
  1518. package/apps/studio/editing/finder-drop.tsx +400 -0
  1519. package/apps/studio/editing/focus-model.tsx +429 -0
  1520. package/apps/studio/editing/gap-bands.tsx +257 -0
  1521. package/apps/studio/editing/hold-rings.tsx +461 -0
  1522. package/apps/studio/editing/image-drop.tsx +193 -0
  1523. package/apps/studio/editing/index.tsx +402 -0
  1524. package/apps/studio/editing/instance-actions.ts +152 -0
  1525. package/apps/studio/editing/kids-summary.ts +75 -0
  1526. package/apps/studio/editing/kind-dim.tsx +54 -0
  1527. package/apps/studio/editing/layout-actions.ts +159 -0
  1528. package/apps/studio/editing/lock-badge.tsx +178 -0
  1529. package/apps/studio/editing/long-page.ts +102 -0
  1530. package/apps/studio/editing/minimap-context.tsx +161 -0
  1531. package/apps/studio/editing/nudge.tsx +212 -0
  1532. package/apps/studio/editing/object-actions.ts +156 -0
  1533. package/apps/studio/editing/object-keys.ts +58 -0
  1534. package/apps/studio/editing/object-menu.tsx +216 -0
  1535. package/apps/studio/editing/object-ops.ts +114 -0
  1536. package/apps/studio/editing/paste-bar.tsx +388 -0
  1537. package/apps/studio/editing/pen/combine-run.ts +113 -0
  1538. package/apps/studio/editing/pen/draw.tsx +364 -0
  1539. package/apps/studio/editing/pen/index.tsx +48 -0
  1540. package/apps/studio/editing/pen/overlay.tsx +147 -0
  1541. package/apps/studio/editing/pen/pen-geometry.ts +234 -0
  1542. package/apps/studio/editing/pen/point-store.ts +64 -0
  1543. package/apps/studio/editing/pen/points.tsx +421 -0
  1544. package/apps/studio/editing/place-freely.tsx +389 -0
  1545. package/apps/studio/editing/place-ghost.tsx +418 -0
  1546. package/apps/studio/editing/place-image.tsx +219 -0
  1547. package/apps/studio/editing/preset-ruler.tsx +218 -0
  1548. package/apps/studio/editing/rename-order.ts +58 -0
  1549. package/apps/studio/editing/reorder-slot.tsx +567 -0
  1550. package/apps/studio/editing/rotate-handle.tsx +353 -0
  1551. package/apps/studio/editing/selection.tsx +319 -0
  1552. package/apps/studio/editing/set-gap.ts +55 -0
  1553. package/apps/studio/editing/size-ghost.tsx +343 -0
  1554. package/apps/studio/editing/space-tap.ts +56 -0
  1555. package/apps/studio/editing/sticky-name.tsx +112 -0
  1556. package/apps/studio/editing/tab-order.tsx +298 -0
  1557. package/apps/studio/editing/take-keys.ts +115 -0
  1558. package/apps/studio/editing/text-actions.ts +214 -0
  1559. package/apps/studio/editing/text-in-place.tsx +187 -0
  1560. package/apps/studio/editing/tidy-preview.tsx +83 -0
  1561. package/apps/studio/editing/token-ruler.tsx +231 -0
  1562. package/apps/studio/editing/type-role.ts +122 -0
  1563. package/apps/studio/editing/undo-preview.tsx +120 -0
  1564. package/apps/studio/editing/video-label.ts +66 -0
  1565. package/apps/studio/editing/video-play.ts +65 -0
  1566. package/apps/studio/editing/world-menu.ts +36 -0
  1567. package/apps/studio/element-ids.ts +1030 -0
  1568. package/apps/studio/equal-spacing-handles.tsx +1 -1
  1569. package/apps/studio/exporters/_runtime.ts +64 -24
  1570. package/apps/studio/exporters/audio.ts +136 -0
  1571. package/apps/studio/exporters/door-fingerprint.ts +202 -0
  1572. package/apps/studio/exporters/estimate.ts +314 -0
  1573. package/apps/studio/exporters/file-names.ts +197 -0
  1574. package/apps/studio/exporters/format-scopes.ts +7 -1
  1575. package/apps/studio/exporters/hub-render-door.ts +368 -0
  1576. package/apps/studio/exporters/index.ts +53 -7
  1577. package/apps/studio/exporters/jobs.ts +484 -80
  1578. package/apps/studio/exporters/jpg.ts +21 -0
  1579. package/apps/studio/exporters/pdf-fonts.ts +102 -0
  1580. package/apps/studio/exporters/pdf.ts +133 -14
  1581. package/apps/studio/exporters/png.ts +136 -9
  1582. package/apps/studio/exporters/print-back.ts +92 -0
  1583. package/apps/studio/exporters/print-preflight.ts +373 -0
  1584. package/apps/studio/exporters/rects-runner.ts +130 -0
  1585. package/apps/studio/exporters/remote.ts +726 -3
  1586. package/apps/studio/exporters/render-seconds.ts +57 -0
  1587. package/apps/studio/exporters/replay.ts +48 -0
  1588. package/apps/studio/exporters/scope.ts +560 -15
  1589. package/apps/studio/exporters/spec-run.ts +270 -0
  1590. package/apps/studio/exporters/spec-v2.ts +408 -0
  1591. package/apps/studio/exporters/video-cap.ts +280 -0
  1592. package/apps/studio/exporters/wait-ai.ts +192 -0
  1593. package/apps/studio/figma/client.ts +67 -0
  1594. package/apps/studio/figma/comments-to-pins.ts +249 -0
  1595. package/apps/studio/figma/comments-to-strokes.ts +6 -1
  1596. package/apps/studio/figma/into-board.ts +141 -0
  1597. package/apps/studio/figma/to-strokes.ts +54 -0
  1598. package/apps/studio/format.ts +172 -30
  1599. package/apps/studio/fs-watch.ts +28 -1
  1600. package/apps/studio/generation/adapters/gemini.ts +3 -0
  1601. package/apps/studio/generation/adapters/stub.ts +133 -0
  1602. package/apps/studio/generation/gen-sidecar.ts +108 -0
  1603. package/apps/studio/generation/registry.ts +16 -5
  1604. package/apps/studio/generation/takes.ts +398 -0
  1605. package/apps/studio/generation/types.ts +7 -0
  1606. package/apps/studio/git/service.ts +143 -14
  1607. package/apps/studio/github/endpoints.ts +1 -1
  1608. package/apps/studio/github/identity-cache.ts +53 -14
  1609. package/apps/studio/handoff/blockers.ts +120 -0
  1610. package/apps/studio/handoff/run.ts +233 -0
  1611. package/apps/studio/handoff/targets.ts +334 -0
  1612. package/apps/studio/handoff/write-scopes.ts +57 -0
  1613. package/apps/studio/handoff.ts +24 -5
  1614. package/apps/studio/history/changes.ts +199 -0
  1615. package/apps/studio/history/describe-annotations.ts +216 -0
  1616. package/apps/studio/history/describe-css.ts +592 -0
  1617. package/apps/studio/history/describe-match.ts +866 -0
  1618. package/apps/studio/history/describe-meta.ts +281 -0
  1619. package/apps/studio/history/describe-version.ts +89 -0
  1620. package/apps/studio/history/describe-words.ts +513 -0
  1621. package/apps/studio/history/describe.ts +1452 -0
  1622. package/apps/studio/history/last-good.ts +123 -0
  1623. package/apps/studio/history/links.ts +112 -0
  1624. package/apps/studio/history/object-history.ts +535 -0
  1625. package/apps/studio/history/render-ok-signal.ts +81 -0
  1626. package/apps/studio/history/restore-artboard-action.ts +183 -0
  1627. package/apps/studio/history/restore-artboard.ts +607 -0
  1628. package/apps/studio/history/restore-object.ts +168 -0
  1629. package/apps/studio/history/run-label.ts +18 -0
  1630. package/apps/studio/history/surface-requests.ts +115 -0
  1631. package/apps/studio/history/titles.ts +259 -0
  1632. package/apps/studio/history/trash.ts +314 -0
  1633. package/apps/studio/history/version-lanes.ts +115 -0
  1634. package/apps/studio/history/versions.ts +458 -0
  1635. package/apps/studio/hmr-broadcast.ts +55 -1
  1636. package/apps/studio/home/ai.ts +79 -0
  1637. package/apps/studio/home/cli.ts +221 -0
  1638. package/apps/studio/home/cloud.ts +297 -0
  1639. package/apps/studio/home/create-local.ts +164 -0
  1640. package/apps/studio/home/github.ts +99 -0
  1641. package/apps/studio/home/hub.ts +340 -0
  1642. package/apps/studio/home/index-gc.ts +288 -0
  1643. package/apps/studio/home/index-reader.ts +338 -0
  1644. package/apps/studio/home/invite.ts +204 -0
  1645. package/apps/studio/home/main.ts +159 -0
  1646. package/apps/studio/home/pid.ts +12 -0
  1647. package/apps/studio/home/routes.ts +591 -0
  1648. package/apps/studio/home/signin.ts +285 -0
  1649. package/apps/studio/home/user-state.ts +177 -0
  1650. package/apps/studio/home/whats-new.ts +42 -0
  1651. package/apps/studio/http.ts +2589 -947
  1652. package/apps/studio/index/assets-response.ts +34 -0
  1653. package/apps/studio/index/assets.ts +335 -0
  1654. package/apps/studio/index/ds-usage.ts +983 -0
  1655. package/apps/studio/index/extract.ts +348 -0
  1656. package/apps/studio/index/extractors/asset-usage.ts +349 -0
  1657. package/apps/studio/index/extractors/attribution-cache.ts +225 -0
  1658. package/apps/studio/index/history-refs.ts +301 -0
  1659. package/apps/studio/index/history-source.ts +39 -0
  1660. package/apps/studio/index/match.ts +307 -0
  1661. package/apps/studio/index/scan-kick.ts +47 -0
  1662. package/apps/studio/index/service.ts +367 -0
  1663. package/apps/studio/index/snapshot.ts +135 -0
  1664. package/apps/studio/index/types.ts +139 -0
  1665. package/apps/studio/index/version-feed.ts +71 -0
  1666. package/apps/studio/input-router.tsx +522 -55
  1667. package/apps/studio/inspect-canvas.ts +86 -0
  1668. package/apps/studio/inspect-overlay.tsx +192 -0
  1669. package/apps/studio/inspect.ts +96 -33
  1670. package/apps/studio/kinds/convert.ts +175 -0
  1671. package/apps/studio/kinds/export-defaults.ts +42 -0
  1672. package/apps/studio/kinds/meta.ts +237 -0
  1673. package/apps/studio/kinds/physical.ts +84 -0
  1674. package/apps/studio/kinds/presets.ts +452 -0
  1675. package/apps/studio/kinds/print-custom.ts +165 -0
  1676. package/apps/studio/kinds/print-edit.ts +130 -0
  1677. package/apps/studio/kinds/print-guides.ts +23 -0
  1678. package/apps/studio/kinds/safe-zones.ts +250 -0
  1679. package/apps/studio/kinds/warnings.ts +422 -0
  1680. package/apps/studio/layer-name.ts +148 -0
  1681. package/apps/studio/layout/free-space.ts +131 -0
  1682. package/apps/studio/link-chip-overlay.tsx +175 -0
  1683. package/apps/studio/link-import.ts +617 -0
  1684. package/apps/studio/loopback-listen.ts +105 -0
  1685. package/apps/studio/macro-guard.ts +67 -0
  1686. package/apps/studio/managed-projects.ts +63 -14
  1687. package/apps/studio/marquee-overlay.tsx +2 -2
  1688. package/apps/studio/measure-overlay.tsx +10 -4
  1689. package/apps/studio/migrate/cli.ts +164 -0
  1690. package/apps/studio/migrate/ds-registry.ts +42 -0
  1691. package/apps/studio/migrate/engine.ts +926 -0
  1692. package/apps/studio/migrate/hub.ts +219 -0
  1693. package/apps/studio/migrate/steps.ts +627 -0
  1694. package/apps/studio/notifications.tsx +197 -52
  1695. package/apps/studio/outbox/content.ts +139 -0
  1696. package/apps/studio/outbox/drain.ts +269 -0
  1697. package/apps/studio/outbox/hub-reachability.ts +58 -0
  1698. package/apps/studio/outbox/index.ts +57 -0
  1699. package/apps/studio/outbox/policy.ts +859 -0
  1700. package/apps/studio/outbox/senders/export-cloud.ts +116 -0
  1701. package/apps/studio/outbox/store.ts +336 -0
  1702. package/apps/studio/outbox/types.ts +160 -0
  1703. package/apps/studio/participants-chrome.tsx +178 -60
  1704. package/apps/studio/paths.ts +8 -0
  1705. package/apps/studio/photo-store.ts +230 -1
  1706. package/apps/studio/port.ts +93 -0
  1707. package/apps/studio/presence/canvas-presence.tsx +522 -0
  1708. package/apps/studio/presence/fields.ts +93 -0
  1709. package/apps/studio/presence/model.ts +296 -0
  1710. package/apps/studio/presence/tones.ts +39 -0
  1711. package/apps/studio/present/fit.ts +138 -0
  1712. package/apps/studio/present/follow.ts +142 -0
  1713. package/apps/studio/present/media-presence.ts +105 -0
  1714. package/apps/studio/present/meta-schema.ts +612 -0
  1715. package/apps/studio/present/order.ts +153 -0
  1716. package/apps/studio/present/pointer-dot.tsx +379 -0
  1717. package/apps/studio/present/pointer-point.ts +24 -0
  1718. package/apps/studio/present/present-media.ts +446 -0
  1719. package/apps/studio/present/present-stage.tsx +1018 -0
  1720. package/apps/studio/present/present-zoom.ts +63 -0
  1721. package/apps/studio/present/relay-strip.ts +136 -0
  1722. package/apps/studio/preview/preview-camera.tsx +442 -0
  1723. package/apps/studio/preview/wheel-scroll.ts +85 -0
  1724. package/apps/studio/print/units.ts +3 -0
  1725. package/apps/studio/print-overlay-content.tsx +127 -10
  1726. package/apps/studio/read-only-mode.ts +83 -0
  1727. package/apps/studio/readiness.ts +18 -3
  1728. package/apps/studio/ripple.ts +19 -1
  1729. package/apps/studio/routes/agent.ts +1025 -0
  1730. package/apps/studio/routes/ai.ts +422 -0
  1731. package/apps/studio/routes/annotations.ts +649 -0
  1732. package/apps/studio/routes/asset-details.ts +87 -0
  1733. package/apps/studio/routes/asset-rename.ts +60 -0
  1734. package/apps/studio/routes/asset-state.ts +137 -0
  1735. package/apps/studio/routes/asset-trash.ts +77 -0
  1736. package/apps/studio/routes/assets.ts +217 -0
  1737. package/apps/studio/routes/availability.ts +94 -0
  1738. package/apps/studio/routes/canvas-meta-rider.ts +304 -0
  1739. package/apps/studio/routes/canvas-origin.ts +88 -0
  1740. package/apps/studio/routes/canvas-source.ts +315 -0
  1741. package/apps/studio/routes/chat-attach.ts +335 -0
  1742. package/apps/studio/routes/chat.ts +137 -0
  1743. package/apps/studio/routes/cloud-move.ts +364 -0
  1744. package/apps/studio/routes/cloud-plan.ts +36 -0
  1745. package/apps/studio/routes/comments.ts +118 -0
  1746. package/apps/studio/routes/connections.ts +132 -0
  1747. package/apps/studio/routes/describe.ts +122 -0
  1748. package/apps/studio/routes/diagnostics.ts +118 -0
  1749. package/apps/studio/routes/ds-check.ts +124 -0
  1750. package/apps/studio/routes/ds-convert.ts +55 -0
  1751. package/apps/studio/routes/ds-edges.ts +136 -0
  1752. package/apps/studio/routes/ds-library.ts +194 -0
  1753. package/apps/studio/routes/ds-make.ts +91 -0
  1754. package/apps/studio/routes/ds-switch.ts +68 -0
  1755. package/apps/studio/routes/ds-upgrade.ts +139 -0
  1756. package/apps/studio/routes/ds.ts +808 -0
  1757. package/apps/studio/routes/edit.ts +658 -0
  1758. package/apps/studio/routes/element-links.ts +155 -0
  1759. package/apps/studio/routes/export.ts +486 -0
  1760. package/apps/studio/routes/figma.ts +200 -0
  1761. package/apps/studio/routes/generate.ts +443 -0
  1762. package/apps/studio/routes/handoff.ts +319 -0
  1763. package/apps/studio/routes/help-guides.ts +37 -0
  1764. package/apps/studio/routes/history.ts +739 -0
  1765. package/apps/studio/routes/import-link.ts +186 -0
  1766. package/apps/studio/routes/index.ts +293 -0
  1767. package/apps/studio/routes/kinds.ts +257 -0
  1768. package/apps/studio/routes/links.ts +72 -0
  1769. package/apps/studio/routes/outbox.ts +87 -0
  1770. package/apps/studio/routes/photo-every-use.ts +241 -0
  1771. package/apps/studio/routes/pins.ts +66 -0
  1772. package/apps/studio/routes/present.ts +187 -0
  1773. package/apps/studio/routes/project-format.ts +148 -0
  1774. package/apps/studio/routes/project-undo.ts +497 -0
  1775. package/apps/studio/routes/settings.ts +179 -0
  1776. package/apps/studio/routes/share.ts +463 -0
  1777. package/apps/studio/routes/shell.ts +137 -0
  1778. package/apps/studio/routes/sync-conflicts.ts +150 -0
  1779. package/apps/studio/routes/sync.ts +172 -0
  1780. package/apps/studio/routes/table.ts +224 -0
  1781. package/apps/studio/routes/trash.ts +393 -0
  1782. package/apps/studio/routes/video.ts +395 -0
  1783. package/apps/studio/routes/votes.ts +486 -0
  1784. package/apps/studio/safe-zones-overlay.tsx +269 -0
  1785. package/apps/studio/scaffold-design.ts +72 -124
  1786. package/apps/studio/schema/annotations.v2.schema.json +2303 -0
  1787. package/apps/studio/schema/beats.v1.schema.json +94 -0
  1788. package/apps/studio/schema/canvas-meta.v2.schema.json +264 -0
  1789. package/apps/studio/schema/canvas-tsx.md +357 -0
  1790. package/apps/studio/schema/comments.v2.schema.json +125 -0
  1791. package/apps/studio/schema/ds-components-v1.schema.json +96 -0
  1792. package/apps/studio/schema/ds-formats.md +146 -0
  1793. package/apps/studio/schema/ds-head-v1.schema.json +67 -0
  1794. package/apps/studio/schema/ds-revision-v1.schema.json +31 -0
  1795. package/apps/studio/schema/ds-schema-v1.fallbacks.css +118 -0
  1796. package/apps/studio/schema/ds-schema-v1.json +2029 -0
  1797. package/apps/studio/schema/ds-schema-v1.schema.json +663 -0
  1798. package/apps/studio/schema/ds-tokens-v1.schema.json +210 -0
  1799. package/apps/studio/schema/edl.v1.schema.json +124 -0
  1800. package/apps/studio/schema/formats.ts +175 -0
  1801. package/apps/studio/schema/gen.v1.schema.json +33 -0
  1802. package/apps/studio/schema/transcript.v1.schema.json +133 -0
  1803. package/apps/studio/server.ts +454 -166
  1804. package/apps/studio/shell/info-file.ts +54 -0
  1805. package/apps/studio/shell/parent-watch.ts +97 -0
  1806. package/apps/studio/shell/profile.ts +61 -0
  1807. package/apps/studio/shell-canvas-file.ts +36 -0
  1808. package/apps/studio/skip-dirs.ts +455 -0
  1809. package/apps/studio/spoof-chars.ts +17 -0
  1810. package/apps/studio/static-lane.ts +212 -0
  1811. package/apps/studio/sync/accepted-cold-start.ts +35 -13
  1812. package/apps/studio/sync/accepted-link.ts +524 -27
  1813. package/apps/studio/sync/access-notices.ts +143 -0
  1814. package/apps/studio/sync/action-feed.ts +145 -0
  1815. package/apps/studio/sync/action-stage.ts +831 -165
  1816. package/apps/studio/sync/asset-push.ts +24 -2
  1817. package/apps/studio/sync/asset-state.ts +391 -0
  1818. package/apps/studio/sync/atomic-write.ts +42 -1
  1819. package/apps/studio/sync/availability.ts +185 -0
  1820. package/apps/studio/sync/canvas-path.ts +70 -6
  1821. package/apps/studio/sync/cell-pairing.ts +5 -24
  1822. package/apps/studio/sync/comment-door.ts +104 -0
  1823. package/apps/studio/sync/conflict-record.ts +186 -0
  1824. package/apps/studio/sync/create-collision.ts +297 -0
  1825. package/apps/studio/sync/ctl-provider.ts +16 -1
  1826. package/apps/studio/sync/file-ledger.ts +12 -0
  1827. package/apps/studio/sync/file-membership.ts +123 -10
  1828. package/apps/studio/sync/file-plane.ts +195 -12
  1829. package/apps/studio/sync/format-sync.ts +13 -7
  1830. package/apps/studio/sync/history-fields.ts +61 -0
  1831. package/apps/studio/sync/hub-link.ts +24 -4
  1832. package/apps/studio/sync/hub-text-undo.ts +178 -0
  1833. package/apps/studio/sync/hubs-config.ts +122 -20
  1834. package/apps/studio/sync/index.ts +1499 -128
  1835. package/apps/studio/sync/journal-client.ts +56 -0
  1836. package/apps/studio/sync/keep-both.ts +187 -0
  1837. package/apps/studio/sync/link-consent.ts +390 -0
  1838. package/apps/studio/sync/local-kernel.ts +2725 -0
  1839. package/apps/studio/sync/media-gate.ts +97 -0
  1840. package/apps/studio/sync/object-conflict.ts +199 -0
  1841. package/apps/studio/sync/poke.ts +50 -0
  1842. package/apps/studio/sync/presentation.ts +20 -2
  1843. package/apps/studio/sync/project-config-push.ts +5 -2
  1844. package/apps/studio/sync/projection.ts +208 -34
  1845. package/apps/studio/sync/resync-trace.ts +220 -0
  1846. package/apps/studio/sync/retry-after.ts +27 -0
  1847. package/apps/studio/sync/status.ts +16 -1
  1848. package/apps/studio/sync/supervisor.ts +20 -2
  1849. package/apps/studio/sync/transaction-client.ts +364 -34
  1850. package/apps/studio/sync/trash-clear-copies.ts +120 -0
  1851. package/apps/studio/sync/trash-watch.ts +157 -0
  1852. package/apps/studio/sync/trash.ts +50 -2
  1853. package/apps/studio/sync/undo-target.ts +110 -0
  1854. package/apps/studio/sync/workspace-signin.ts +14 -3
  1855. package/apps/studio/sync/write-hold.ts +238 -0
  1856. package/apps/studio/sync/writer-registry.ts +380 -5
  1857. package/apps/studio/sync-name-key.ts +59 -0
  1858. package/apps/studio/thumbs/keys.ts +147 -0
  1859. package/apps/studio/thumbs/routes.ts +68 -0
  1860. package/apps/studio/thumbs/service.ts +884 -0
  1861. package/apps/studio/thumbs/store.ts +114 -0
  1862. package/apps/studio/thumbs/validate.ts +62 -0
  1863. package/apps/studio/tool-palette.tsx +782 -563
  1864. package/apps/studio/toolbars/marker-tip.ts +22 -0
  1865. package/apps/studio/toolbars/shell-panels.ts +55 -0
  1866. package/apps/studio/toolbars/tool-panel.ts +89 -0
  1867. package/apps/studio/toolbars/toolbar-css.ts +283 -0
  1868. package/apps/studio/toolbars/toolbar-icons.tsx +135 -0
  1869. package/apps/studio/toolbars/toolbar-rect.ts +82 -0
  1870. package/apps/studio/ui-prefs-migrate.ts +467 -0
  1871. package/apps/studio/ui-prefs.ts +305 -3
  1872. package/apps/studio/undo-stack.ts +10 -0
  1873. package/apps/studio/use-annotation-resize.tsx +23 -17
  1874. package/apps/studio/use-artboard-drag.tsx +156 -15
  1875. package/apps/studio/use-canvas-keys.ts +58 -0
  1876. package/apps/studio/use-chrome-visibility.tsx +13 -0
  1877. package/apps/studio/use-collab.tsx +556 -56
  1878. package/apps/studio/use-element-resize.tsx +13 -9
  1879. package/apps/studio/use-governed-mode.ts +23 -0
  1880. package/apps/studio/use-keyboard-discipline.tsx +114 -49
  1881. package/apps/studio/use-selection-set.tsx +110 -9
  1882. package/apps/studio/use-snap-guides.tsx +74 -5
  1883. package/apps/studio/use-spacing-handles.tsx +90 -27
  1884. package/apps/studio/use-tool-mode.tsx +204 -10
  1885. package/apps/studio/use-undo-stack.tsx +19 -23
  1886. package/apps/studio/video/beats.ts +484 -0
  1887. package/apps/studio/video/decode-webaudio.ts +115 -0
  1888. package/apps/studio/video/decode.ts +288 -0
  1889. package/apps/studio/video/derive.ts +647 -0
  1890. package/apps/studio/video/format-ids.ts +158 -0
  1891. package/apps/studio/video/framing.ts +246 -0
  1892. package/apps/studio/video/inject.ts +324 -0
  1893. package/apps/studio/video/keyframes.ts +356 -0
  1894. package/apps/studio/video/link-groups.ts +40 -0
  1895. package/apps/studio/video/linked-formats.ts +142 -0
  1896. package/apps/studio/video/mask-comments.ts +36 -0
  1897. package/apps/studio/video/media-analysis.ts +169 -0
  1898. package/apps/studio/video/reel-place.ts +286 -0
  1899. package/apps/studio/video/reframe-read.ts +90 -0
  1900. package/apps/studio/video/schema.ts +422 -0
  1901. package/apps/studio/video/speech.ts +129 -0
  1902. package/apps/studio/video/title-motion.ts +85 -0
  1903. package/apps/studio/video/transcript-cut.ts +91 -0
  1904. package/apps/studio/video/whisper-parse.ts +123 -0
  1905. package/apps/studio/video/words-run.ts +210 -0
  1906. package/apps/studio/video/words-timing.ts +222 -0
  1907. package/apps/studio/video-comp.tsx +238 -9
  1908. package/apps/studio/video-links-overlay.tsx +272 -0
  1909. package/apps/studio/video-natural.ts +73 -0
  1910. package/apps/studio/video-play-chrome.tsx +229 -0
  1911. package/apps/studio/video-play-overlay.tsx +190 -0
  1912. package/apps/studio/video-vocab.tsx +460 -0
  1913. package/apps/studio/view-only-gesture.tsx +101 -0
  1914. package/apps/studio/viewport-fit.ts +28 -0
  1915. package/apps/studio/web-overlay-content.tsx +4 -2
  1916. package/apps/studio/whats-new.json +100 -20
  1917. package/apps/studio/whats-new.schema.json +10 -0
  1918. package/apps/studio/whats-new.ts +4 -0
  1919. package/apps/studio/workspace-mode.ts +10 -0
  1920. package/apps/studio/ws.ts +299 -8
  1921. package/cli/bin/maude.mjs +1 -0
  1922. package/cli/commands/design.mjs +401 -72
  1923. package/cli/commands/flow.mjs +12 -1
  1924. package/cli/commands/help.mjs +8 -0
  1925. package/cli/commands/migrate.mjs +55 -0
  1926. package/cli/lib/bash-guard.mjs +1691 -0
  1927. package/cli/lib/confine-out.mjs +150 -0
  1928. package/cli/lib/confine-read.mjs +179 -0
  1929. package/cli/lib/confine-root.mjs +157 -0
  1930. package/cli/lib/design-help.gen.mjs +119 -0
  1931. package/cli/lib/design-hook.mjs +1764 -0
  1932. package/cli/lib/design-link.mjs +68 -4
  1933. package/cli/lib/design-open.mjs +238 -0
  1934. package/cli/lib/export-spec.mjs +394 -0
  1935. package/cli/lib/finding-text.mjs +63 -0
  1936. package/cli/lib/flow-usage.mjs +6 -10
  1937. package/cli/lib/gitignore-block.mjs +1 -0
  1938. package/cli/lib/handoff.mjs +285 -0
  1939. package/cli/lib/handoff.schema.json +336 -0
  1940. package/cli/lib/hubs-config.mjs +10 -0
  1941. package/cli/lib/json-schema-lite.mjs +260 -0
  1942. package/cli/lib/project-links.mjs +88 -0
  1943. package/cli/lib/studio-locate.mjs +83 -0
  1944. package/cli/lib/sub-verbs.mjs +111 -0
  1945. package/cli/lib/workspace-plan.mjs +16 -3
  1946. package/package.json +29 -10
  1947. package/plugins/design/README.md +46 -0
  1948. package/plugins/design/templates/_shell.html +749 -69
  1949. package/plugins/design/templates/blank-canvas.tsx.template +26 -0
  1950. package/plugins/design/templates/brief-board.tsx.template +12 -11
  1951. package/plugins/design/templates/canvas.tsx.template +3 -3
  1952. package/plugins/design/templates/design-system-inspiration/core/README.philosophy.md.tpl +104 -0
  1953. package/plugins/design/templates/design-system-inspiration/core/colors_and_type.css.tpl +38 -3
  1954. package/plugins/design/templates/design-system-inspiration/core/components.json.tpl +127 -0
  1955. package/plugins/design/templates/design-system-inspiration/core/config.json.tpl +1 -0
  1956. package/plugins/design/templates/design-system-inspiration/core/preview/_components.css.tpl +111 -0
  1957. package/plugins/flow/.claude-plugin/config.schema.json +6 -1
  1958. package/apps/studio/annotations/ui/edit-actions.ts +0 -551
  1959. package/apps/studio/canvas-header.ts +0 -165
  1960. package/apps/studio/client/hmr.mjs +0 -113
  1961. package/apps/studio/client/hooks/use-keyboard-shortcuts.jsx +0 -297
  1962. package/apps/studio/client/iframe-lazy.mjs +0 -121
  1963. package/apps/studio/client/inspector/artboard-knobs.jsx +0 -456
  1964. package/apps/studio/client/menus/menubar.jsx +0 -856
  1965. package/apps/studio/client/panels/CapabilityBar.jsx +0 -101
  1966. package/apps/studio/client/panels/ClipInspector.jsx +0 -409
  1967. package/apps/studio/client/panels/GitPanel.jsx +0 -1026
  1968. package/apps/studio/client/panels/OnboardingWizard.jsx +0 -642
  1969. package/apps/studio/client/panels/StickerPicker.jsx +0 -160
  1970. package/apps/studio/client/panels/SyncPanel.jsx +0 -1190
  1971. package/apps/studio/client/panels/TimelinePanel.jsx +0 -2259
  1972. package/apps/studio/client/share-dialog.jsx +0 -91
  1973. package/apps/studio/client/shell/collapsed-rail.jsx +0 -23
  1974. package/apps/studio/client/shell/status-bar.jsx +0 -215
  1975. package/apps/studio/client/styles/1-tokens-maude.css +0 -296
  1976. package/apps/studio/client/styles/1-tokens.css +0 -304
  1977. package/apps/studio/client/styles/3-shell-maude.css +0 -3158
  1978. package/apps/studio/client/styles/3-shell.css +0 -1036
  1979. package/apps/studio/client/styles/4-components-maude.css +0 -134
  1980. package/apps/studio/client/styles/4-components.css +0 -2204
  1981. package/apps/studio/client/styles/5-maude-overrides.css +0 -162
  1982. package/apps/studio/client/styles.css +0 -1264
  1983. package/apps/studio/contextual-toolbar.tsx +0 -512
  1984. package/apps/studio/export-dialog.tsx +0 -827
  1985. package/apps/studio/undo-hud.tsx +0 -16
@@ -1,7 +1,17 @@
1
+ import { claimCreatedCanvas, runForCreate } from './ai/create-claim.ts';
2
+ import {
3
+ claimWritesForChat,
4
+ hookClaims,
5
+ routeWriteClaim,
6
+ withWriteClaim,
7
+ } from './ai/write-claim.ts';
1
8
  import { MAX_ELEMENTS } from './annotations/constants.ts';
2
9
  import { parseOps as parseAnnotationOps } from './annotations/ops.ts';
10
+ import { runTagGate, runTagRefusalResponse } from './annotations/run-tag.ts';
3
11
  import { serializeBoard } from './annotations/schema.ts';
12
+ import { VOTE_DOOR_REFUSAL, voteDoorOnly } from './annotations/vote-guard.ts';
4
13
  import { validAnnotationWriteId } from './annotations-sync.ts';
14
+ import { artboardLabels } from './edit-ops/duplicate-at-width.ts';
5
15
  import { MAX_ANNOTATIONS_BYTES } from './sync/limits.ts';
6
16
  // HTTP layer for Bun.serve.
7
17
  //
@@ -9,11 +19,67 @@ import { MAX_ANNOTATIONS_BYTES } from './sync/limits.ts';
9
19
  // the route table without rewriting this module. The `fetch` export is the
10
20
  // top-level fall-through for paths Bun's `routes` field doesn't cover.
11
21
 
12
- import { createHash } from 'node:crypto';
22
+ import { createHash, timingSafeEqual } from 'node:crypto';
13
23
  import { existsSync, readFileSync, realpathSync, unlinkSync, watch } from 'node:fs';
14
- import { basename, dirname, join, posix, relative, resolve, sep } from 'node:path';
24
+ import { basename, join, posix, relative, resolve, sep } from 'node:path';
15
25
  // Ownership mutations live with the CLI on purpose — see /_api/sync/ownership.
16
26
  import { adoptToHub, detachToRepo, ownershipState } from '../../cli/lib/design-ownership.mjs';
27
+ import { assetReferrers, type Closure, localDepsFromSource } from './access/closure.ts';
28
+ import {
29
+ canvasOnlyLogPaths,
30
+ canvasOriginTarget,
31
+ diffRefusal,
32
+ diffShaVisible,
33
+ exportTargetVerdict,
34
+ filterAcceptedHistory,
35
+ filterAssetListing,
36
+ filterConfig,
37
+ filterGitBranches,
38
+ filterGitDiff,
39
+ filterGitStatus,
40
+ filterIndexSearch,
41
+ filterIndexSnapshot,
42
+ filterTrashListing,
43
+ mergeCanvasOnlyLog,
44
+ projectVisibility,
45
+ type Seer,
46
+ seerOf,
47
+ } from './access/filters.ts';
48
+ import {
49
+ currentFrame,
50
+ FRAME_PARAM,
51
+ type FrameScope,
52
+ frameKeyFor,
53
+ frameSubjectOf,
54
+ frameTokenOf,
55
+ inputsRefusal,
56
+ loadFrameSecret,
57
+ mintFrameCap,
58
+ narrowToFrame,
59
+ verifyFrameCap,
60
+ } from './access/frame.ts';
61
+ import { closureConfigFor } from './access/known-canvases.ts';
62
+ import {
63
+ ACP_REFUSAL,
64
+ accessForDesktop,
65
+ accessFromProxy,
66
+ COMMENT_WRITE_PATTERNS,
67
+ COMMENT_WRITES,
68
+ canvasOnlyRefused,
69
+ canvasScopeRefusal,
70
+ diskProjectReader,
71
+ EXPORT_WRITES,
72
+ type GateInput,
73
+ localGate,
74
+ notInScopeResponse,
75
+ SESSION_WRITES,
76
+ targetOf,
77
+ toDesignRel,
78
+ writeCapability,
79
+ } from './access/request.ts';
80
+ import { type Access, sees as accessSees, accessView } from './access/scope.ts';
81
+ import { type AskQueue, createAskQueue, currentAllowanceResetsAt } from './acp/ask-queue.ts';
82
+ import { createConnectedFact } from './acp/connected-fact.ts';
17
83
  import {
18
84
  cancelSignin,
19
85
  getClaudeAuthStatus,
@@ -22,44 +88,73 @@ import {
22
88
  startInstall,
23
89
  startSignin,
24
90
  } from './acp/login-state.ts';
25
- import { probeAcpAvailabilityAuthed } from './acp/probe.ts';
91
+ import { probeAcpAvailability, probeAcpAvailabilityAuthed } from './acp/probe.ts';
26
92
  import { activitySnapshot, runningChats } from './acp/running.ts';
27
93
  import {
28
94
  chatTranscriptSeq,
29
95
  deleteChat,
96
+ groupChatsByCanvas,
30
97
  listChats,
31
98
  readChatMessages,
32
99
  writeChatMeta,
33
100
  } from './acp/transcript.ts';
101
+ import { actionsManifestVersion } from './actions/manifest-version.ts';
102
+ import { createLocalLeaseHome } from './ai/lease-home.ts';
103
+ import { createRunRegistry, type RunRegistry } from './ai/runs.ts';
34
104
  import { type Api, ASSET_CHUNK_BYTES, ASSET_MAX_BYTES, ASSET_MAX_VIDEO_BYTES } from './api.ts';
35
- import { ImportAssetError, importSvg, SVG_MAX_BYTES } from './bin/_import-asset.mjs';
36
- import { ImportBrandError, importBrand } from './bin/_import-brand.mjs';
105
+ import { importBrandRequest } from './bin/_brand-site.mjs';
37
106
  import { buildCanvasModule } from './canvas-build.ts';
38
107
  import { buildCanvasSandboxed, buildStats } from './canvas-build-sandbox.ts';
39
108
  import { canvasLibPath } from './canvas-lib-resolver.ts';
40
109
  import { TranspileError } from './canvas-pipeline.ts';
110
+ import { CanvasBuildError, canvasSourceSig, recordCanvasBuild } from './canvas-source/errors.ts';
41
111
  import { rememberCanvasBuild } from './canvas-source-memo.ts';
42
112
  import { createCloudEndpoints } from './cloud/endpoints.ts';
43
113
  import type { AiActivity } from './collab/ai-activity.ts';
114
+ import { localAuthor } from './comments/local-author.ts';
44
115
  import type { Context } from './context.ts';
45
116
  import { reloadConfig } from './context.ts';
46
117
  import { buildDebugBundle } from './debug-bundle.ts';
118
+ import { createDescribeService, type DescribeService, envDescriber } from './describe/batch.ts';
47
119
  import { probeSetupReadiness } from './design-setup-readiness.ts';
120
+ import { diagnostics, registerStatus, report } from './diagnostics/store.ts';
121
+ import { createDsEngine, kernelPortFrom } from './ds/engine.ts';
122
+ import { heldArtboards } from './ds/make.ts';
123
+ import { createDsOutsideWatcher } from './ds/outside.ts';
124
+ import { injectFallbacks } from './ds/shell-fallbacks.ts';
125
+ import { registerDsUndoHook } from './ds/undo-hook.ts';
126
+ import { createReferenceLanes } from './edit-ops/references.ts';
48
127
  import { frameAncestors } from './embed-origins.ts';
128
+ import { closureFingerprint } from './exporters/door-fingerprint.ts';
129
+ import { contentDisposition } from './exporters/file-names.ts';
49
130
  import { isScopeValidForFormat, scopeRefusalMessage } from './exporters/format-scopes.ts';
131
+ import { createHubRenderDoorGetter } from './exporters/hub-render-door.ts';
50
132
  import { type Format, isFormat, isScope, type Scope } from './exporters/index.ts';
51
- import { type ExportJobQueue, ExportQueueFullError } from './exporters/jobs.ts';
52
- import type { ActiveJsonShape } from './exporters/scope.ts';
133
+ import { ExportJobIdError, type ExportJobQueue, ExportQueueFullError } from './exporters/jobs.ts';
134
+ import { createRectsRunner } from './exporters/rects-runner.ts';
135
+ import {
136
+ type CloudRenderDoor,
137
+ cloudLabel,
138
+ cloudTargetFacts,
139
+ createCloudExports,
140
+ desktopCloudFacts,
141
+ intentRole,
142
+ } from './exporters/remote.ts';
143
+ import { renderSecondsStats } from './exporters/render-seconds.ts';
144
+ import { type ActiveJsonShape, resolveScope } from './exporters/scope.ts';
145
+ import { isV2Body } from './exporters/spec-v2.ts';
53
146
  import { createFigmaEndpoints } from './figma/endpoints.ts';
54
147
  import { generatedClipAnalysis } from './footage/schema.ts';
55
148
  import { createFootageStore, FOOTAGE_MAX_BYTES } from './footage-store.ts';
56
149
  import {
150
+ asFormat,
57
151
  canvasFormatLine,
152
+ FORMAT_GATE_OPTS,
153
+ formatConfigFields,
58
154
  formatGate,
59
155
  formatGateAllowsWrite,
60
156
  formatRefusalResponse,
61
157
  projectFormat,
62
- STAGED_FORMAT_GATE_OPTS,
63
158
  } from './format.ts';
64
159
  import {
65
160
  type AudioMatch,
@@ -114,71 +209,105 @@ import {
114
209
  } from './generation/whisper-models.ts';
115
210
  import { refuseCheckoutRewrite } from './git/accepted-guard.ts';
116
211
  import { createGitEndpoints } from './git/endpoints.ts';
117
- import { gitShowFile } from './git/service.ts';
212
+ import { gitCommitFiles, gitShowFile } from './git/service.ts';
118
213
  import { createGitHubEndpoints } from './github/endpoints.ts';
214
+ import { createHandoffs } from './handoff/run.ts';
215
+ import { trashArtboardRestorer } from './history/restore-artboard-action.ts';
216
+ import {
217
+ cssOverridesFor,
218
+ injectVersionMeta,
219
+ type LaneReaders,
220
+ laneAtRef,
221
+ type VersionSource,
222
+ } from './history/version-lanes.ts';
223
+ import type { GitEntry } from './history/versions.ts';
224
+ import { createHistory } from './history.ts';
225
+ import { assetsResponse } from './index/assets-response.ts';
226
+ import { warmDsUsage } from './index/ds-usage.ts';
227
+ import { extractCanvas } from './index/extract.ts';
228
+ import {
229
+ type AttributionCache,
230
+ attributionDir,
231
+ createAttributionCache,
232
+ } from './index/extractors/attribution-cache.ts';
233
+ import { historySourceFromRuntime } from './index/history-source.ts';
234
+ import { kickWhenReady } from './index/scan-kick.ts';
235
+ import { createIndexService } from './index/service.ts';
236
+ import { pidOf, projectDir } from './index/snapshot.ts';
237
+ import { feedVersionsToIndex } from './index/version-feed.ts';
119
238
  import type { InspectRegistry } from './inspect.ts';
120
239
  import { canvasSlug, writeLocator } from './locator.ts';
121
240
  import { prepareManagedProject } from './managed-projects.ts';
122
241
  import { materializeMissing } from './materialize-client.ts';
242
+ import { createHubReachability } from './outbox/hub-reachability.ts';
243
+ import { createOutbox, type GateFacts, type IntentRecord } from './outbox/index.ts';
244
+ import { exportCloudSender } from './outbox/senders/export-cloud.ts';
123
245
  import { isUnderOrEqual, resolveUrlPathUnder } from './path-containment.ts';
124
246
  import { BIN_DIR, DEV_SERVER_ROOT, MEDIA_DIR, STICKERS_DIR } from './paths.ts';
125
- import { createPhotoStore, PHOTO_EDIT_MAX_BYTES } from './photo-store.ts';
247
+ import { createPhotoStore, EDIT8_RE, PHOTO_EDIT_MAX_BYTES } from './photo-store.ts';
126
248
  import { probeReadiness } from './readiness.ts';
249
+ import {
250
+ type AgentRouteDeps,
251
+ allSpecs,
252
+ announceAction,
253
+ assetStateDepsFor,
254
+ canvasPathsOfIndex,
255
+ cloudExportResponse,
256
+ createTrashWriteStop,
257
+ voteHomeResolver as createVoteHomeResolver,
258
+ type ExportRouteDeps,
259
+ gateSpecV2,
260
+ generateDepsFor,
261
+ type HandoffRouteDeps,
262
+ heldByAiRefusal,
263
+ planExportV2,
264
+ resolveQueuedHandoff,
265
+ riderPatch,
266
+ runStageHooks,
267
+ type ShareRouteDeps,
268
+ shareAskToEditSender,
269
+ shareInviteSender,
270
+ trashAccess,
271
+ withTrashStop,
272
+ } from './routes/index.ts';
273
+ import { checkRouteTable, mountRoutes, type RouteSpec } from './routes/table.ts';
127
274
  import { getRuntimeBundle, packageForSlug } from './runtime-bundle.ts';
128
275
  import { currentSession } from './session-scope.ts';
276
+ import { resolveProfile } from './shell/profile.ts';
277
+ import {
278
+ cacheControlFor,
279
+ documentCsp,
280
+ ext,
281
+ isRefusedDotPath,
282
+ MIME,
283
+ serveClientAsset,
284
+ serveFile,
285
+ serveIndexHtml,
286
+ } from './static-lane.ts';
129
287
  import { sanitizeForLog } from './sync/cell-pairing.ts';
130
288
  import { linkHub } from './sync/hub-link.ts';
131
- import { isHubReadOnly } from './sync/hubs-config.ts';
289
+ import { accessFor, getHubRecord, linkRoleSource } from './sync/hubs-config.ts';
290
+ import { hubHealth } from './sync/journal-client.ts';
291
+ import { createKeepBothResolver } from './sync/keep-both.ts';
292
+ import { createLinkGate } from './sync/link-consent.ts';
293
+ import { createResyncTrace, type ResyncStatusSource } from './sync/resync-trace.ts';
132
294
  import { isFirstAnchorMode, readSyncSettings, writeSyncSettings } from './sync/settings.ts';
133
295
  import { listTrash, pruneTrash, restoreFromTrash } from './sync/trash.ts';
134
296
  import { signInToWorkspace, workspaceDisclosure } from './sync/workspace-signin.ts';
297
+ import { thumbNotFound, thumbResponse, wantResponse } from './thumbs/routes.ts';
298
+ import { BOOT_COVERS_DELAY_MS, createThumbService } from './thumbs/service.ts';
135
299
  import { normalizeTreeState } from './tree-state.ts';
136
- import { readUiPrefs, type UiPrefs, writeUiPrefs } from './ui-prefs.ts';
300
+ import { readUiPrefs, validateUiPrefsPatch, writeUiPrefs } from './ui-prefs.ts';
137
301
  import { loadWhatsNew, resolveMaudeVersion } from './whats-new.ts';
138
302
  import { isWorkspaceMode, resolveRenderLane } from './workspace-mode.ts';
139
303
  import { isLoopbackHost } from './ws.ts';
140
304
 
305
+ export { cacheControlFor, MIME, serveIndexHtml } from './static-lane.ts';
306
+
141
307
  // Real disk install root — never the virtual `/$bunfs/root` of compiled bins.
142
308
  // See paths.ts for the resolution logic + Phase 19.1 / v0.18.1 rationale.
143
309
  const HERE = DEV_SERVER_ROOT;
144
310
 
145
- export const MIME: Record<string, string> = {
146
- '.html': 'text/html; charset=utf-8',
147
- '.css': 'text/css; charset=utf-8',
148
- '.js': 'application/javascript; charset=utf-8',
149
- '.mjs': 'application/javascript; charset=utf-8',
150
- '.jsx': 'text/plain; charset=utf-8',
151
- '.ts': 'text/plain; charset=utf-8',
152
- '.tsx': 'text/plain; charset=utf-8',
153
- '.json': 'application/json; charset=utf-8',
154
- '.md': 'text/markdown; charset=utf-8',
155
- '.svg': 'image/svg+xml',
156
- '.png': 'image/png',
157
- '.jpg': 'image/jpeg',
158
- '.jpeg': 'image/jpeg',
159
- '.gif': 'image/gif',
160
- '.webp': 'image/webp',
161
- '.ico': 'image/x-icon',
162
- '.woff': 'font/woff',
163
- '.woff2': 'font/woff2',
164
- '.ttf': 'font/ttf',
165
- '.otf': 'font/otf',
166
- // DDR-148 — video/audio media referenced by a video-comp `<Video>`/`<Audio>`.
167
- '.mp4': 'video/mp4',
168
- '.m4v': 'video/mp4',
169
- '.mov': 'video/quicktime',
170
- '.webm': 'video/webm',
171
- '.mp3': 'audio/mpeg',
172
- '.wav': 'audio/wav',
173
- '.m4a': 'audio/mp4',
174
- '.ogg': 'audio/ogg',
175
- };
176
-
177
- function ext(p: string): string {
178
- const i = p.lastIndexOf('.');
179
- return i === -1 ? '' : p.slice(i).toLowerCase();
180
- }
181
-
182
311
  /**
183
312
  * T2 (9.1-A) — build the strict CSP for the canvas-content shell. Every inline
184
313
  * `<script>` (importmap, module bootstrap, inspector) is allowlisted by sha256
@@ -192,14 +321,16 @@ function ext(p: string): string {
192
321
  * is not the F1 RCE vector (script + connect are). No `'unsafe-eval'` — the
193
322
  * POC verifies the runtime (motion/pixi/Bun.build output) doesn't need it.
194
323
  *
195
- * `webrtc 'block'` (A6, DDR-060 F1 re-audit) — `connect-src` governs only
324
+ * WebRTC (A6, DDR-060 F1 re-audit) — `connect-src` governs only
196
325
  * fetch/XHR/WebSocket/sendBeacon; WebRTC does NOT flow through Fetch, so an
197
326
  * `RTCPeerConnection` with an attacker STUN/TURN hostname smuggles bytes out via
198
- * ICE DNS/STUN even under `connect-src 'self'`. ⚠️ This directive is specified
199
- * (CSP3) but UNIMPLEMENTED in shipping Chrome/Firefox as of 2026 (Chromium
200
- * #40188662, Firefox bug 1783489) — currently a NO-OP. The enforceable control
201
- * today is the RTC-constructor lockout in `templates/_shell.html`; this directive
202
- * is kept for when browsers honor it. WebRTC + self-navigation exfil remain
327
+ * ICE DNS/STUN even under `connect-src 'self'`. The CSP3 `webrtc 'block'`
328
+ * directive was REMOVED (p8-sweep-leftovers): it is enforced nowhere we ship —
329
+ * Chromium (capture/export workers) logs "Unrecognized … 'webrtc'" and ignores
330
+ * it (#40188662), and WKWebView (the desktop app) parses it but still gathers
331
+ * ICE candidates (measured, macOS 26.5). The enforceable controls are the
332
+ * RTC-constructor lockout in `templates/_shell.html` and the capture browser's
333
+ * `--force-webrtc-ip-handling-policy` (p8-secfix-m1). WebRTC + self-navigation exfil remain
203
334
  * DOCUMENTED residuals of opt-in linked mode (the reachable data is collab
204
335
  * metadata, not repo files — traversal is closed). Do NOT treat this as a closed
205
336
  * exfil lane. The canvas runtime itself uses zero WebRTC.
@@ -290,15 +421,17 @@ export function cspForCanvasShell(
290
421
  // DDR-148 — a video-comp's <Video>/<Audio> loads media from the canvas
291
422
  // origin's own designRoot (assets/). Same inert-bytes trust as img-src
292
423
  // 'self'; without it default-src 'none' blocks all media (black video, no
293
- // sound). `blob:` covers Remotion's processed-media URLs.
294
- "media-src 'self' blob:",
424
+ // sound). `blob:` covers Remotion's processed-media URLs; `data:` its silent
425
+ // `data:audio/mp3` unlock clip (p8-sweep-leftovers — refused, it logged on every
426
+ // video canvas). A media `data:` URL is decoded bytes: no script, no host.
427
+ // `data:` is for media-src ONLY — script-src never takes it.
428
+ "media-src 'self' blob: data:",
295
429
  "style-src 'self' 'unsafe-inline'",
296
430
  "font-src 'self' data:",
297
431
  "frame-src 'self'",
298
432
  "base-uri 'none'",
299
433
  "object-src 'none'",
300
434
  "form-action 'none'",
301
- "webrtc 'block'",
302
435
  ];
303
436
  // DDR-247 — an embedder of the studio page is an ANCESTOR of this frame too,
304
437
  // and frame-ancestors checks every ancestor, so it is listed here as well.
@@ -313,9 +446,7 @@ export function cspForCanvasShell(
313
446
  * main origin at all — the main origin 307s them to the read-only capture
314
447
  * origin, which serves the strict canvas CSP (`cspForCanvasShell`, DDR-232).
315
448
  * This policy now applies only where a capture still renders on the main
316
- * origin: with the split OFF (`MAUDE_CANVAS_ORIGIN_SPLIT=0`). (Maude's own
317
- * local `_draw/` / `_photo/` harnesses stay on the main origin too, but only
318
- * as bare `?canvas=` requests — one carrying `hide-chrome` is redirected.)
449
+ * origin: with the split OFF (`MAUDE_CANVAS_ORIGIN_SPLIT=0`).
319
450
  *
320
451
  * Original rationale: the export rendered the (untrusted, DDR-054) canvas on
321
452
  * the MAIN origin — where the normal
@@ -345,7 +476,6 @@ export function cspForCapture(): string {
345
476
  "object-src 'none'",
346
477
  "base-uri 'none'",
347
478
  "form-action 'none'",
348
- "webrtc 'block'",
349
479
  ].join('; ');
350
480
  }
351
481
 
@@ -456,6 +586,57 @@ export function sameOriginRead(req: Request): boolean {
456
586
  return site === 'same-origin' || site === 'none';
457
587
  }
458
588
 
589
+ /**
590
+ * Every table route is privileged (migrate rewrites the tree; the outbox lists queued intents):
591
+ * the same double gate every main-origin route carries — Origin check (reads and writes) +
592
+ * the DNS-rebinding guard — before the handler runs. V2-2.5: module-level (was `guardLane`
593
+ * inside createHttp, verbatim) so test/csrf-write-guard.test.ts can hold every spec to it.
594
+ */
595
+ export function guardTableRoute(spec: RouteSpec): RouteSpec {
596
+ return {
597
+ ...spec,
598
+ handle: (req, params) => {
599
+ const sameOrigin = spec.method === 'GET' ? sameOriginRead(req) : sameOriginWrite(req);
600
+ if (!sameOrigin)
601
+ return (
602
+ spec.refuse?.('cross-origin') ?? new Response('cross-origin rejected', { status: 403 })
603
+ );
604
+ if (!isTrustedRequestHost(req))
605
+ return (
606
+ spec.refuse?.('untrusted-host') ??
607
+ new Response('local request required (DNS-rebinding guard)', { status: 403 })
608
+ );
609
+ return spec.handle(req, params);
610
+ },
611
+ };
612
+ }
613
+
614
+ /**
615
+ * p8-a1-claims — a main-only table route that writes answers inside its run's write claim when the
616
+ * request names an AI chat (`X-Maude-Chat`, `_studio-verb.mjs` / `curl-local`): what it writes then
617
+ * joins that chat's LIVE run by its bytes (ai/write-claim.ts), with no time window. A canvas-origin
618
+ * spec is never wrapped (the untrusted canvas frame can set any header on its own origin), nor a read;
619
+ * the claim needs the same two gates `guardTableRoute` applies, checked again here.
620
+ */
621
+ export function claimingTableRoute(
622
+ spec: RouteSpec,
623
+ runs: Parameters<typeof routeWriteClaim>[1]
624
+ ): RouteSpec {
625
+ if (spec.origin === 'canvas' || spec.method === 'GET') return spec;
626
+ // p8-sec2-attrib A2 — the run's own bookkeeping (the hook routes) and the closing page's flush of a
627
+ // person's held saves are never a run's writes: answering them inside its claim made the landing the AI's
628
+ if (spec.path.startsWith('/_api/agent/') || spec.path === '/_api/diagnostics/save-hold-flush')
629
+ return spec;
630
+ return {
631
+ ...spec,
632
+ handle: (req, params) =>
633
+ withWriteClaim(
634
+ sameOriginWrite(req) && isTrustedRequestHost(req) ? routeWriteClaim(req, runs) : null,
635
+ () => spec.handle(req, params)
636
+ ),
637
+ };
638
+ }
639
+
459
640
  // ─────────────────────────────────────────────────────────────────────────────
460
641
  // Cloud Phase 25 C2 — the local half of the read-only gate.
461
642
  //
@@ -471,60 +652,16 @@ export function sameOriginRead(req: Request): boolean {
471
652
  // DDR-115, plus the two role-granted verbs the cell itself allows —
472
653
  // export ≈ `/api/export`, session management ≈ `/auth/logout`):
473
654
  const READ_ONLY_SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
474
- export const READ_ONLY_ALLOWED_WRITES = new Set([
475
- '/_hmr', // build-watch rebuild hint — dev plumbing, not project state
476
- '/_canvas-state', // per-user camera / view state (DDR-115: never versioned)
477
- '/_api/canvas-meta', // viewport lane only — the layout lane is refused in-handler
478
- '/_api/ui-prefs', // per-user UI preferences
479
- '/_api/tree-state', // per-user Files-panel disclosure (issue #124)
480
- '/_api/timeline-media', // per-user runtime media cache (scrub read path)
481
- '/_api/export', // "look, comment and download" — the cell allows /api/export too
482
- '/_api/export-jobs',
483
- '/_api/export-jobs/download',
484
- // DDR-231 Phase 2 T6 — the browser lane's ledger row. A viewer may already
485
- // EXPORT (the two entries above), so recording that they did is the same
486
- // class of write: it touches no project state, only the recent-exports list.
487
- // Refusing it here while allowing the export produced exactly the reported
488
- // symptom for viewers — a file downloads and nothing anywhere says so.
489
- '/_api/export-history',
490
- // …and the deck's composition half. The member's own browser captured the
491
- // PNGs; this route only packs bytes they already hold into a .pptx and hands
492
- // it back — it writes no project state. Missing from this list, a VIEWER's
493
- // PPTX export captured every artboard and then died on a 403 with the dialog
494
- // still saying "Capturing 10/10" (found by the T7 export E2E, which runs
495
- // unauthenticated and therefore as a viewer).
496
- '/_api/export-assemble',
497
- '/_api/report', // bug reports are about Maude, not the project
498
- '/_api/report-fallback',
499
- // Cloud Phase 27 — COMMENT IS THE ONE WRITE A VIEWER HOLDS. The role matrix
500
- // has said so since Phase 25 C4 (`viewer.comment === true`), the People page
501
- // promises it in those words, and the cell's proxy allows it — but this list
502
- // did not, so a viewer's comment was accepted by the authority and then
503
- // refused by the defence-in-depth layer behind it. Found by commenting as a
504
- // viewer against a real cell. A second gate that is STRICTER than the first is
505
- // still a gate that is wrong.
506
- '/_comments',
507
- '/_api/hub/link', // link/unlink ≈ session management (cell allows /auth/logout)
508
- '/_api/cloud/detach', // unlink — the same session-management class as hub/link
509
- '/_api/workspace/sign-in', // signing in is how the role is (re)learned
510
- '/_api/workspace/disclosure',
511
- '/_api/cloud/signin/start', // account session, not project state
512
- '/_api/cloud/signin/poll',
513
- '/_api/cloud/signout',
514
- // Fetch moves remote-tracking refs and nothing else — no working tree, no
515
- // index. It stays a read.
516
- '/_api/git/fetch',
517
- // `pull` and `checkout` USED TO BE HERE, on the reasoning that "viewing
518
- // another branch is not changing one". Cloud Phase 27 D2 retired that: both
519
- // rewrite the working tree, and the tree is SHARED — in a cell by every
520
- // member, and on a hub-linked desktop by whoever else has that project open.
521
- // A viewer switching branches replaces the files under someone mid-edit.
522
- //
523
- // The proxy's manifest already refuses them, but this gate is the one the
524
- // hub-linked desktop and self-host path consult (`isHubReadOnly`), where no
525
- // manifest runs at all — so leaving them here would have left the hole open
526
- // exactly where the proxy cannot reach. Two gates, and neither is trusted to
527
- // be the last word.
655
+ // S9.9 (V2-1.7 §5.7) — split by capability in access/request.ts: SESSION_WRITES
656
+ // (`session`), COMMENT_WRITES (`comment`), EXPORT_WRITES (`export`). This is their
657
+ // union — what a session WITHOUT `edit` may still write at all; which of them a given
658
+ // role may write is `localGate`'s answer (an observer holds session, not comment or
659
+ // export). `pull` / `checkout` stay off it (Cloud Phase 27 D2: they rewrite the shared
660
+ // working tree).
661
+ export const READ_ONLY_ALLOWED_WRITES = new Set<string>([
662
+ ...SESSION_WRITES,
663
+ ...COMMENT_WRITES,
664
+ ...EXPORT_WRITES,
528
665
  ]);
529
666
 
530
667
  /**
@@ -535,9 +672,14 @@ export const READ_ONLY_ALLOWED_WRITES = new Set([
535
672
  * the list above, so the bar for adding one is that an exact path genuinely
536
673
  * cannot express it.
537
674
  */
538
- export const READ_ONLY_ALLOWED_WRITE_PATTERNS: RegExp[] = [
539
- /^\/_api\/comments\/[A-Za-z0-9_-]+\/reply$/,
540
- ];
675
+ export const READ_ONLY_ALLOWED_WRITE_PATTERNS: RegExp[] = [...COMMENT_WRITE_PATTERNS];
676
+
677
+ /** The `/_api/canvas-meta` PATCH lanes that are per-user state (`_canvas-state/`, DDR-115). */
678
+ export const CANVAS_META_SESSION_LANES: ReadonlySet<string> = new Set([
679
+ 'viewport',
680
+ 'overlays',
681
+ 'locked',
682
+ ]);
541
683
 
542
684
  /** The refusal a read-only session gets for a project-mutating write. */
543
685
  export function readOnlyRefusalResponse(): Response {
@@ -575,8 +717,34 @@ function safePathUnderRoot(reqUrl: string, repoRoot: string): string | null {
575
717
 
576
718
  // `dist/` lives next to server.ts when running source-mode (bun run server.ts)
577
719
  // and inside the standalone binary's embedded FS in --compile mode.
720
+ /**
721
+ * `/_config.saveMode` (p8-update-to-accepted): the live sync's DDR-241 mode, null in solo.
722
+ * p8-fix-a F19 — `'pending'` until the hub has answered once (a project that has never heard from it, and
723
+ * has no remembered answer, is NOT `legacy`): the shell shows "saves the old way" only for a real `legacy`.
724
+ */
725
+ export function saveModeOf(
726
+ runtime: { acceptedMode?(): boolean; acceptedModeKnown?(): boolean } | null | undefined
727
+ ): 'accepted' | 'legacy' | 'pending' | null {
728
+ if (!runtime?.acceptedMode) return null;
729
+ if (runtime.acceptedModeKnown && !runtime.acceptedModeKnown()) return 'pending';
730
+ return runtime.acceptedMode() ? 'accepted' : 'legacy';
731
+ }
732
+
733
+ /**
734
+ * p8-fix-a F19 — this project's own page on the cloud dashboard (`<dashboard>/projects/<id>`), for the
735
+ * links that name a setting on it (Saving). Needs BOTH the configured dashboard and the cell's tenant id
736
+ * (the dashboard's project id: the studio door builds its sign-in URL from the same pair); absent when
737
+ * either is missing, and the client falls back to the dashboard root.
738
+ */
739
+ export function projectDashboardUrl(
740
+ env: Record<string, string | undefined> = process.env
741
+ ): string | null {
742
+ const dashboard = (env.HUB_DASHBOARD_URL ?? '').replace(/\/+$/, '');
743
+ const tenant = env.MAUDE_TENANT_ID ?? '';
744
+ return dashboard && tenant ? `${dashboard}/projects/${encodeURIComponent(tenant)}` : null;
745
+ }
746
+
578
747
  const DIST_DIR = join(HERE, 'dist');
579
- const CLIENT_DIR = join(HERE, 'client');
580
748
  // Templates stayed under the design *plugin* (plugins/design/templates) when the
581
749
  // dev-server moved to apps/studio (DDR-095) — both ship in the npm tarball, so
582
750
  // from DEV_SERVER_ROOT (apps/studio) reach across with ../../plugins/design.
@@ -600,9 +768,28 @@ interface CanvasCacheEntry {
600
768
  * local `.tsx/.ts` modules, incl. unresolved extensionless candidates) —
601
769
  * re-statted each request to recompute `sig` without re-reading the source. */
602
770
  deps: string[];
771
+ /** gate-b-c4e — every file the build inlined (absolute), held to the frame's closure on serve. */
772
+ inputs: readonly string[];
603
773
  }
604
774
  const canvasCache = new Map<string, CanvasCacheEntry>();
605
775
 
776
+ /**
777
+ * gate-b-c4e — may THIS request receive a module built from `inputs` (absolute paths)? null = yes.
778
+ * The build is shared by every requester (cached per path), so the check runs on every serve.
779
+ * gate-b-c4g — `entry`: the canvas the module was built from; a list that does not name it is
780
+ * refused (an empty metafile is no evidence the module inlined nothing).
781
+ */
782
+ export type CanvasInputsGate = ((inputs: readonly string[], entry: string) => Response | null) & {
783
+ /**
784
+ * gate-b-c4l (defender L-b) — judged BEFORE any build: a frame on a canvas whose import walk the
785
+ * closure blocked (another canvas, a file that is never a module, an import that resolves to
786
+ * nothing) is refused with the one not-in-scope answer. Without it a planted import of a MISSING
787
+ * file failed the build (500, "Could not resolve") while an existing canvas built and was refused
788
+ * (403): an existence probe. The build's own errors also quote the files they read.
789
+ */
790
+ before?: (entry: string) => Response | null;
791
+ };
792
+
606
793
  // Per-process boot id, folded into every canvas ETag. The canvas transpile
607
794
  // BUNDLES the shared chrome (canvas-lib → tool-palette / annotations-layer /
608
795
  // use-tool-mode / canvas-cursors / …), but the freshness sig + base etag only
@@ -625,63 +812,8 @@ const RUNTIME_BOOT_ID = `${Date.now().toString(36)}${Math.random().toString(36).
625
812
  // gets the stale bundle even after the HMR hard-reload. (DDR-067.)
626
813
  let CHROME_EPOCH = 0;
627
814
 
628
- /** Relative import specifiers in a canvas source → absolute paths (the files
629
- * Bun.build inlines): sibling `.css`, and — RC6 of
630
- * rca/issue-canvas-hmr-optimistic-update-consistency — imported local
631
- * `.tsx/.ts/.jsx/.js` modules, which are inlined exactly like CSS (only
632
- * RUNTIME_PACKAGES stay external, canvas-build.ts), so an edit to an imported
633
- * sibling must bust the mtime-keyed cache the same way. Extensionless
634
- * specifiers contribute EVERY resolution candidate (`.tsx`, `.ts`, …,
635
- * `index.tsx`); missing candidates stat as 0, so a dep file APPEARING later
636
- * also changes the signature. One level only — no transitive graph (the
637
- * import-graph HMR re-emit is a tracked follow-up). Bare / virtual specifiers
638
- * (`@maude/…`, npm) are skipped. Resolved paths are clamped to `designRoot`:
639
- * a canvas source is attacker-influenced under linked mode (DDR-054), and
640
- * these paths are `stat`-ed for mtime, so a `../../../etc/…` specifier must
641
- * not let the freshness probe reach outside the design tree. Legit DS imports
642
- * (`../../system/<ds>/…`) stay inside designRoot. */
643
- export function localDepsFromSource(
644
- source: string,
645
- canvasAbsPath: string,
646
- designRoot: string
647
- ): string[] {
648
- const dir = dirname(canvasAbsPath);
649
- const root = resolve(designRoot);
650
- const deps: string[] = [];
651
- const seen = new Set<string>();
652
- const push = (abs: string) => {
653
- if (abs !== root && !abs.startsWith(root + sep)) return; // clamp (DDR-054)
654
- if (seen.has(abs)) return;
655
- seen.add(abs);
656
- deps.push(abs);
657
- };
658
- const specRes = [
659
- /\bimport\s+["']([^"']+)["']/g, // side-effect: import './x.css'
660
- /\bfrom\s+["']([^"']+)["']/g, // import … from / export … from
661
- /\bimport\(\s*["']([^"']+)["']\s*\)/g, // dynamic import('./x')
662
- ];
663
- for (const re of specRes) {
664
- for (let m = re.exec(source); m !== null; m = re.exec(source)) {
665
- const spec = m[1];
666
- if (!spec?.startsWith('.')) continue;
667
- const base = resolve(dir, spec);
668
- if (/\.(css|tsx|ts|jsx|js)$/i.test(spec)) {
669
- push(base);
670
- } else {
671
- for (const cand of [
672
- `${base}.tsx`,
673
- `${base}.ts`,
674
- `${base}.jsx`,
675
- `${base}.js`,
676
- resolve(base, 'index.tsx'),
677
- resolve(base, 'index.ts'),
678
- ])
679
- push(cand);
680
- }
681
- }
682
- }
683
- return deps;
684
- }
815
+ // `localDepsFromSource` (the canvas build's freshness deps) lives in `access/closure.ts` since S9.1:
816
+ // the ACL closure scanner walks the same import graph (V2-1.7 G3), so there is one home for it.
685
817
 
686
818
  /** mtime signature over the .tsx + every inlined relative dep (`.css` + local
687
819
  * modules). A missing/unreadable file contributes 0 — a delete is itself a
@@ -707,7 +839,7 @@ export interface ServeCanvasTestHooks {
707
839
  */
708
840
  function canvasBuildErrorResponse(err: unknown, ctx: Context): Response {
709
841
  const msg = err instanceof Error ? err.message : String(err);
710
- const line = canvasFormatLine(msg, formatGate(ctx, STAGED_FORMAT_GATE_OPTS));
842
+ const line = canvasFormatLine(msg, formatGate(ctx, FORMAT_GATE_OPTS));
711
843
  return new Response(`Canvas build error: ${line ? `${line}\n\n` : ''}${msg}`, {
712
844
  status: 500,
713
845
  headers: { 'Content-Type': 'text/plain; charset=utf-8' },
@@ -719,7 +851,8 @@ export async function serveCanvasTsx(
719
851
  req: Request,
720
852
  ctx: Context,
721
853
  locatorAbsPath: string,
722
- testHooks?: ServeCanvasTestHooks
854
+ testHooks?: ServeCanvasTestHooks,
855
+ inputsGate?: CanvasInputsGate
723
856
  ): Promise<Response> {
724
857
  // Phase 27 (E2) — DiffView "before" pane. `?sha=<ref>` builds the canvas from
725
858
  // its source AT a past version (git show) instead of the working-tree file, so
@@ -728,10 +861,12 @@ export async function serveCanvasTsx(
728
861
  // resolves sibling imports against the CURRENT on-disk files (an accepted
729
862
  // approximation: the canvas code at the sha, with today's DS/lib).
730
863
  const shaParam = new URL(req.url).searchParams.get('sha');
731
- if (shaParam) return serveHistoricalCanvas(absPath, shaParam, req, ctx);
864
+ if (shaParam) return serveHistoricalCanvas(absPath, shaParam, req, ctx, inputsGate);
732
865
 
733
866
  const file = Bun.file(absPath);
734
867
  if (!(await file.exists())) return new Response('Not found', { status: 404 });
868
+ const refusedBefore = inputsGate?.before?.(absPath);
869
+ if (refusedBefore) return refusedBefore;
735
870
 
736
871
  // Freshness = the .tsx mtime AND every inlined sibling `.css` mtime. Keying on
737
872
  // the .tsx alone meant a direct edit to `<canvas>.css` was a cache HIT, so the
@@ -772,6 +907,11 @@ export async function serveCanvasTsx(
772
907
  assetUrlBase: designRootUrlBase(ctx.paths),
773
908
  });
774
909
  if (!built.ok) {
910
+ // gate-b-c4m (defender L-B) — a frame's failed build answers like a refused one: Bun
911
+ // resolves imports the closure walk does not follow (a CSS `url()`), and "Could not resolve"
912
+ // beside the refusal's 403 was an existence oracle. A syntax error in the canvas's own source
913
+ // stays legible — the session can already read that file.
914
+ if (inputsGate && !built.transpile) return notInScopeResponse();
775
915
  return new Response(`Canvas build error: ${built.error}`, {
776
916
  status: built.kind === 'build' ? 422 : 500,
777
917
  headers: { 'Content-Type': 'text/plain; charset=utf-8' },
@@ -781,12 +921,18 @@ export async function serveCanvasTsx(
781
921
  js: built.js,
782
922
  locator: built.locator,
783
923
  etag: built.etag,
924
+ inputs: built.inputs,
784
925
  } as Awaited<ReturnType<typeof buildCanvasModule>>;
926
+ // gate-b-c4g — judged BEFORE anything is kept or written: a refused request leaves no
927
+ // cache entry, no remembered source and no locator file (the sandbox caches the build).
928
+ const refusedHere = inputsGate?.(result.inputs, absPath);
929
+ if (refusedHere) return refusedHere;
785
930
  cached = {
786
931
  sig: builtSig,
787
932
  etag: `${result.etag}-${RUNTIME_BOOT_ID}-${CHROME_EPOCH}`,
788
933
  js: result.js,
789
934
  deps,
935
+ inputs: result.inputs,
790
936
  };
791
937
  canvasCache.set(absPath, cached);
792
938
  rememberCanvasBuild(absPath, { source, locator: result.locator });
@@ -805,14 +951,28 @@ export async function serveCanvasTsx(
805
951
  assetUrlBase: designRootUrlBase(ctx.paths),
806
952
  });
807
953
  } catch (err) {
954
+ // S11.6 — the build's own error (an import, the allowlist) for `/_api/canvas-errors`;
955
+ // a syntax error is re-read from the file there, so only these need remembering.
956
+ recordCanvasBuild(
957
+ absPath,
958
+ canvasSourceSig(source),
959
+ err instanceof CanvasBuildError ? (err.errors[0] ?? null) : null
960
+ );
808
961
  if (err instanceof TranspileError) {
809
962
  return new Response(`Transpile error: ${err.message}`, {
810
963
  status: 500,
811
964
  headers: { 'Content-Type': 'text/plain; charset=utf-8' },
812
965
  });
813
966
  }
967
+ // gate-b-c4m (defender L-B) — to a frame, any other build failure answers like a refusal (the
968
+ // sandboxed branch above says why); the error itself reaches the shell via /_api/canvas-errors.
969
+ if (inputsGate) return notInScopeResponse();
814
970
  return canvasBuildErrorResponse(err, ctx);
815
971
  }
972
+ // gate-b-c4g — judged BEFORE anything is kept or written: a refused request leaves no cache
973
+ // entry, no remembered source and no locator file; the next permitted request builds afresh.
974
+ const refusedHere = inputsGate?.(result.inputs, absPath);
975
+ if (refusedHere) return refusedHere;
816
976
  // The signature against the freshly-parsed deps — this very edit may have
817
977
  // added or removed a `.css` import — stamped before the build (above).
818
978
  cached = {
@@ -823,17 +983,20 @@ export async function serveCanvasTsx(
823
983
  etag: `${result.etag}-${RUNTIME_BOOT_ID}-${CHROME_EPOCH}`,
824
984
  js: result.js,
825
985
  deps,
986
+ inputs: result.inputs,
826
987
  };
827
988
  canvasCache.set(absPath, cached);
828
989
  rememberCanvasBuild(absPath, { source, locator: result.locator });
990
+ recordCanvasBuild(absPath, canvasSourceSig(source), null);
829
991
  // Persist the locator map. Awaited so the inspector / Phase-12 layers
830
992
  // panel sees a consistent (cdId -> source) view by the time the canvas
831
993
  // mounts. Per-path mutex inside writeLocator() makes concurrent transpiles
832
994
  // safe.
833
995
  await writeLocator(locatorAbsPath, canvasSlug(absPath, ctx.paths.designRoot), result.locator);
996
+ return respondWithCanvasModule(req, cached);
834
997
  }
835
998
 
836
- return respondWithCanvasModule(req, cached);
999
+ return inputsGate?.(cached.inputs, absPath) ?? respondWithCanvasModule(req, cached);
837
1000
  }
838
1001
 
839
1002
  /** The conditional-GET half of serving a built canvas module. Shared by the
@@ -865,7 +1028,12 @@ function respondWithCanvasModule(req: Request, cached: { js: string; etag: strin
865
1028
  // can't grow the heap unbounded — the route is reachable from the UNTRUSTED
866
1029
  // canvas origin (it's on the canvas-serve path), so a hub-pushed canvas could
867
1030
  // otherwise OOM the sidecar (security review — ethical-hacker, Finding 1).
868
- const historicalCanvasCache = new Map<string, { js: string; etag: string }>();
1031
+ // `cssSig`: today's same-name CSS file as the build saw it — set only when the version had no CSS
1032
+ // lane of its own (the build then used today's file), so such an entry goes stale with that file.
1033
+ const historicalCanvasCache = new Map<
1034
+ string,
1035
+ { js: string; etag: string; cssSig: string | null; inputs: readonly string[] }
1036
+ >();
869
1037
  const HIST_MAX_CACHE = 96;
870
1038
  // Rate-limit the EXPENSIVE miss path (git show + Bun.build, or a non-resolving
871
1039
  // git lookup) so a distinct-sha spray from the canvas origin can't starve the
@@ -928,6 +1096,30 @@ function cloudHistoryApi(ctx: Context): ReturnType<typeof createCloudEndpoints>
928
1096
  return cloudHistoryFor.api;
929
1097
  }
930
1098
 
1099
+ /**
1100
+ * S1.11 / S1.12 — every reader a version's lanes come from (V2-1.9 §5.6): the project's store for
1101
+ * `r<rev>`, git then the linked cell for a sha. One object so the build, the shell's meta and the
1102
+ * row pictures (thumbs) all read a version the same way.
1103
+ */
1104
+ function versionReaders(ctx: Context): LaneReaders {
1105
+ return {
1106
+ accepted: async (repoRel, revision, lane) =>
1107
+ (await ctx.syncControl?.current?.()?.acceptedVersion?.(repoRel, revision, lane)) ?? null,
1108
+ git: (sha, repoRel) => gitShowFile(ctx.paths.repoRoot, sha, repoRel),
1109
+ cloud: async (sha, repoRel) => {
1110
+ const r = await cloudHistoryApi(ctx).historyFile(sha, repoRel);
1111
+ return r.ok ? r.source : null;
1112
+ },
1113
+ };
1114
+ }
1115
+
1116
+ /** Today's same-name CSS as a build would read it (mtime + size; a missing file is its own value). */
1117
+ function todayCssSig(absTsx: string): string {
1118
+ const f = Bun.file(absTsx.replace(/\.tsx$/i, '.css'));
1119
+ const mt = f.lastModified;
1120
+ return Number.isFinite(mt) && mt > 0 ? `${mt}:${f.size}` : 'none';
1121
+ }
1122
+
931
1123
  function historicalBuildAllowed(): boolean {
932
1124
  const now = Date.now();
933
1125
  if (now - histWindowStart >= HIST_WINDOW_MS) {
@@ -938,15 +1130,48 @@ function historicalBuildAllowed(): boolean {
938
1130
  histBuilds++;
939
1131
  return true;
940
1132
  }
1133
+
1134
+ /**
1135
+ * S11.6 — a past version's SOURCE for `GET /_api/canvas-source?sha=` (routes/canvas-source.ts):
1136
+ * the same three readers as the `?sha=` build below (an accepted revision `r<n>`, local git, the
1137
+ * linked cell), under the same global budget. `'busy'` = over budget (the route answers 429).
1138
+ */
1139
+ async function historicalCanvasSource(
1140
+ ctx: Context,
1141
+ repoRel: string,
1142
+ sha: string
1143
+ ): Promise<string | null | 'busy'> {
1144
+ if (!historicalBuildAllowed()) return 'busy';
1145
+ const acceptedRev = /^r(\d{1,12})$/.exec(sha);
1146
+ if (acceptedRev)
1147
+ return (
1148
+ (await ctx.syncControl
1149
+ ?.current?.()
1150
+ ?.acceptedVersion?.(repoRel, Number(acceptedRev[1]))
1151
+ .catch(() => null)) ?? null
1152
+ );
1153
+ const local = await gitShowFile(ctx.paths.repoRoot, sha, repoRel);
1154
+ if (local != null) return local;
1155
+ const fromCloud = await cloudHistoryApi(ctx).historyFile(sha, repoRel);
1156
+ return fromCloud.ok ? fromCloud.source : null;
1157
+ }
941
1158
  async function serveHistoricalCanvas(
942
1159
  absPath: string,
943
1160
  sha: string,
944
1161
  req: Request,
945
- ctx: Context
1162
+ ctx: Context,
1163
+ inputsGate?: CanvasInputsGate
946
1164
  ): Promise<Response> {
1165
+ const refusedBefore = inputsGate?.before?.(absPath);
1166
+ if (refusedBefore) return refusedBefore;
947
1167
  const repoRel = relative(ctx.paths.repoRoot, absPath).replace(/\\/g, '/');
948
1168
  const key = `${absPath}\0${sha}\0${RUNTIME_BOOT_ID}\0${CHROME_EPOCH}`;
949
1169
  let cached = historicalCanvasCache.get(key);
1170
+ // A version without its own CSS lane was built over TODAY's file: that file changed → rebuild.
1171
+ if (cached && cached.cssSig !== null && cached.cssSig !== todayCssSig(absPath)) {
1172
+ historicalCanvasCache.delete(key);
1173
+ cached = undefined;
1174
+ }
950
1175
  if (cached) {
951
1176
  // LRU touch — re-insert so the hot entry isn't the next eviction victim.
952
1177
  historicalCanvasCache.delete(key);
@@ -979,6 +1204,7 @@ async function serveHistoricalCanvas(
979
1204
  // ACCEPTED REVISIONS: `r<revision>` names a project revision (T27), read
980
1205
  // from the project's store — immutable, so it caches like a sha.
981
1206
  const acceptedRev = /^r(\d{1,12})$/.exec(sha);
1207
+ let from: VersionSource = acceptedRev ? 'accepted' : 'git';
982
1208
  let source = acceptedRev
983
1209
  ? ((await ctx.syncControl
984
1210
  ?.current?.()
@@ -988,6 +1214,7 @@ async function serveHistoricalCanvas(
988
1214
  if (source == null && !acceptedRev) {
989
1215
  const fromCloud = await cloudHistoryApi(ctx).historyFile(sha, repoRel);
990
1216
  source = fromCloud.ok ? fromCloud.source : null;
1217
+ from = 'cloud';
991
1218
  // ONLY AN AUTHORITATIVE ABSENCE IS REMEMBERED (security re-review of
992
1219
  // 8134ca8f, finding F1). Two things must never be cached here:
993
1220
  //
@@ -1012,8 +1239,12 @@ async function serveHistoricalCanvas(
1012
1239
  }
1013
1240
  }
1014
1241
  if (source == null) return new Response('No saved version of this canvas', { status: 404 });
1242
+ // The version's same-name CSS from the SAME source as its TSX (V2-1.9 §5.6); none → today's file.
1243
+ const css = await laneAtRef(versionReaders(ctx), repoRel, sha, 'css', from);
1244
+ const cssSig = css == null ? todayCssSig(absPath) : null;
1015
1245
  try {
1016
1246
  const result = await buildCanvasModule(absPath, source, {
1247
+ overrides: cssOverridesFor(absPath, css),
1017
1248
  designRoot: ctx.paths.designRoot,
1018
1249
  // Same unconditional allowlist as the live build above — a HISTORICAL
1019
1250
  // source is still tenant/peer-authored content.
@@ -1023,6 +1254,8 @@ async function serveHistoricalCanvas(
1023
1254
  cached = {
1024
1255
  js: result.js,
1025
1256
  etag: `${result.etag}-${sha}-${RUNTIME_BOOT_ID}-${CHROME_EPOCH}`,
1257
+ cssSig,
1258
+ inputs: result.inputs,
1026
1259
  };
1027
1260
  historicalCanvasCache.set(key, cached);
1028
1261
  if (historicalCanvasCache.size > HIST_MAX_CACHE) {
@@ -1030,9 +1263,14 @@ async function serveHistoricalCanvas(
1030
1263
  if (oldest !== undefined) historicalCanvasCache.delete(oldest);
1031
1264
  }
1032
1265
  } catch (err) {
1266
+ // gate-b-c4l (L-b) — a past version is not what the closure walked: to a gated session
1267
+ // (a frame) a failed build answers like a refused one, so it probes nothing.
1268
+ if (inputsGate) return notInScopeResponse();
1033
1269
  return canvasBuildErrorResponse(err, ctx);
1034
1270
  }
1035
1271
  }
1272
+ const refused = inputsGate?.(cached.inputs, absPath);
1273
+ if (refused) return refused;
1036
1274
  if (req.headers.get('if-none-match') === cached.etag) {
1037
1275
  return new Response(null, {
1038
1276
  status: 304,
@@ -1049,107 +1287,6 @@ async function serveHistoricalCanvas(
1049
1287
  });
1050
1288
  }
1051
1289
 
1052
- /**
1053
- * How long a served file may be reused — Cloud Phase 27 B2.
1054
- *
1055
- * `no-store` on everything is correct on a laptop, where the round trip is a
1056
- * memcpy and the designer is editing the file you just served. Over the
1057
- * internet it means a teammate re-downloads every photograph on every pan, on
1058
- * a project whose media is 266 MB. So:
1059
- *
1060
- * content-addressed name → immutable, a year. The name IS the content
1061
- * (sha8), so a changed file is a changed URL and
1062
- * a stale answer is impossible by construction.
1063
- * everything else → revalidate (`no-cache` + ETag). A designer
1064
- * editing `hero.png` in place still sees their
1065
- * edit; the wire cost of not having changed it is
1066
- * a 304, not the file.
1067
- *
1068
- * Universal, not cloud-only: the rule is true on all three shells, and a
1069
- * caching policy that differs per shell is a bug report nobody can reproduce.
1070
- */
1071
- export function cacheControlFor(absPath: string): { cacheControl: string; addEtag: boolean } {
1072
- const name = absPath.slice(absPath.lastIndexOf('/') + 1);
1073
- // The shape every writer emits — timeline insert/replace/assemble, the asset
1074
- // upload route, `maude design fetch-asset`: <sha8>.<ext>, lowercase hex.
1075
- if (/^[0-9a-f]{8,64}\.[A-Za-z0-9]+$/.test(name)) {
1076
- return { cacheControl: 'public, max-age=31536000, immutable', addEtag: false };
1077
- }
1078
- return { cacheControl: 'no-cache', addEtag: true };
1079
- }
1080
-
1081
- /**
1082
- * The studio page, with its bundle and stylesheet URLs VERSIONED.
1083
- *
1084
- * `/_client/client.bundle.js` used to be a fixed URL answered `no-cache`. Behind
1085
- * Cloudflare that header does not survive: the zone's default Browser Cache
1086
- * TTL turns a `.js` into `max-age=14400`, so after a release a cloud user ran
1087
- * the previous client for up to four hours, against a server that had moved on
1088
- * (measured on alligators after v1.6.5: new server, old bundle, none of the
1089
- * release's UI). A query that changes whenever the built file does makes every
1090
- * cache, ours or anyone's in front of us, fetch it again. `serveFile` ignores
1091
- * the query, so the old URL keeps working for anything that still asks for it.
1092
- */
1093
- export async function serveIndexHtml(extraHeaders: Record<string, string> = {}): Promise<Response> {
1094
- const index = Bun.file(join(CLIENT_DIR, 'index.html'));
1095
- if (!(await index.exists())) return new Response('Not found', { status: 404 });
1096
- let html = await index.text();
1097
- for (const name of ['client.bundle.js', 'styles.css']) {
1098
- const built = Bun.file(join(DIST_DIR, name));
1099
- if (!(await built.exists())) continue;
1100
- const v = `${built.size.toString(16)}-${Math.trunc(built.lastModified).toString(16)}`;
1101
- html = html.replaceAll(`"/_client/${name}"`, `"/_client/${name}?v=${v}"`);
1102
- }
1103
- return new Response(html, {
1104
- headers: {
1105
- 'Content-Type': 'text/html; charset=utf-8',
1106
- 'Cache-Control': 'no-cache',
1107
- 'X-Content-Type-Options': 'nosniff',
1108
- ...extraHeaders,
1109
- },
1110
- });
1111
- }
1112
-
1113
- /** A weak validator from the file's own metadata — no read, no hash. */
1114
- function etagFor(file: { size: number; lastModified: number }): string {
1115
- return `W/"${file.size.toString(16)}-${Math.trunc(file.lastModified).toString(16)}"`;
1116
- }
1117
-
1118
- /**
1119
- * An SVG is a DOCUMENT, and a document runs script.
1120
- *
1121
- * `image/svg+xml` is inert as an `<img>`, a CSS `url()` or a `<use>` target —
1122
- * none of those are browsing contexts. Navigate to one directly and it is a
1123
- * page, with `<script>` in it, executing on whatever origin served it. On the
1124
- * canvas origin that is a stored-XSS primitive: canvases carry the tenant's own
1125
- * SVGs, only the shell HTML gets a CSP, and every other static response here
1126
- * has carried `nosniff` and nothing else.
1127
- *
1128
- * `default-src 'none'; sandbox` costs the legitimate uses nothing (an image is
1129
- * not a document, so the policy never applies to them) and makes the
1130
- * navigate-to-it case a blank page instead of a foothold. Found by an
1131
- * adversarial pass as step one of a three-link cross-tenant chain; the other
1132
- * two links are closed in the same change, and this is the cheapest of the
1133
- * three to break.
1134
- */
1135
- const INERT_DOCUMENT_CSP = "default-src 'none'; sandbox";
1136
-
1137
- async function serveFile(absPath: string, headers: Record<string, string> = {}): Promise<Response> {
1138
- const file = Bun.file(absPath);
1139
- if (!(await file.exists())) return new Response('Not found', { status: 404 });
1140
- const e = ext(absPath);
1141
- const policy = cacheControlFor(absPath);
1142
- return new Response(file, {
1143
- headers: {
1144
- 'Content-Type': MIME[e] || 'application/octet-stream',
1145
- 'Cache-Control': policy.cacheControl,
1146
- ...(policy.addEtag ? { ETag: etagFor(file) } : {}),
1147
- ...(e === '.svg' ? { 'Content-Security-Policy': INERT_DOCUMENT_CSP } : {}),
1148
- ...headers,
1149
- },
1150
- });
1151
- }
1152
-
1153
1290
  /** Media (video/audio) extensions that get HTTP Range support when served. */
1154
1291
  const RANGE_MEDIA_EXTS = new Set(['.mp4', '.m4v', '.mov', '.webm', '.mp3', '.wav', '.m4a', '.ogg']);
1155
1292
 
@@ -1181,7 +1318,7 @@ async function serveMaterialized(
1181
1318
  'X-Content-Type-Options': 'nosniff',
1182
1319
  // The blob's name IS its sha256 — a stronger validator than size+mtime.
1183
1320
  ...(policy.addEtag ? { ETag: `"${basename(cacheAbs)}"` } : {}),
1184
- ...(e === '.svg' ? { 'Content-Security-Policy': INERT_DOCUMENT_CSP } : {}),
1321
+ ...documentCsp(e),
1185
1322
  };
1186
1323
  if (RANGE_MEDIA_EXTS.has(e)) return serveMediaFile(cacheAbs, req, headers);
1187
1324
  return new Response(Bun.file(cacheAbs), { headers });
@@ -1270,14 +1407,43 @@ export function canvasCommitters(
1270
1407
  .sort((a, b) => b.commits - a.commits);
1271
1408
  }
1272
1409
 
1410
+ /**
1411
+ * V2-8.9 r2 L1 — `/_api/git-user` as the UNTRUSTED canvas origins may see it: the git `user.name`, else
1412
+ * "You". Never `localAuthor`'s OS-account fallback (`os.userInfo().username`) — canvas code could write
1413
+ * this Mac's account name into a canvas that syncs. The shell (main origin) keeps `localAuthor`, the
1414
+ * one identity a comment is stamped with. Same pattern as `canvasCommitters`.
1415
+ */
1416
+ export function canvasUserName(configured: unknown): string {
1417
+ const name = typeof configured === 'string' ? configured.trim().slice(0, 120) : '';
1418
+ return name || 'You';
1419
+ }
1420
+
1273
1421
  export interface Http {
1274
1422
  routes: Record<string, (req: Request) => Response | Promise<Response>>;
1275
1423
  /**
1276
1424
  * V2-2.8 S6 — handlers the canvas origins mount INSTEAD of the main-origin
1277
1425
  * one at the same path, because they answer a narrower projection
1278
- * (server.ts `startCanvasServer` routes map). Same path, same allowlists.
1426
+ * (routes/canvas-origin.ts, the canvas server's routes map). Same path, same allowlists.
1427
+ */
1428
+ canvasRoutes: Record<
1429
+ '/_api/git-committers' | '/_api/annotations/ops' | '/_api/git-user',
1430
+ (req: Request) => Response | Promise<Response>
1431
+ >;
1432
+ /**
1433
+ * V2-2.5 — the exact paths of the table's `origin: 'canvas'` specs. Both canvas
1434
+ * allowlists derive them: `CANVAS_SAFE_API` here and routes/canvas-origin.ts.
1435
+ */
1436
+ tableCanvasPaths: readonly string[];
1437
+ /** S9.9 — THIS request's access (V2-1.7 §5.4); server.ts `withSession` puts it in ALS. */
1438
+ accessOf(req?: Request): Access;
1439
+ /** S9.11 — the closure of a session's grants on this child's disk (null without grants). */
1440
+ closureOf(access: Access): Closure | null;
1441
+ /**
1442
+ * gate-b-c4 — the frame a canvas / capture listener request was opened for (its verified `fc`
1443
+ * capability; `canvases: null` = frame-less). server.ts runs the request inside it, and
1444
+ * `accessOf` then answers the opener's access narrowed to those canvases (access/frame.ts).
1279
1445
  */
1280
- canvasRoutes: Record<'/_api/git-committers', (req: Request) => Response | Promise<Response>>;
1446
+ frameScopeOf(req: Request): FrameScope;
1281
1447
  fetch(req: Request): Promise<Response>;
1282
1448
  /**
1283
1449
  * T2 (9.1-A) — build the canvas mount-harness response. `applyCsp` adds the
@@ -1285,7 +1451,14 @@ export interface Http {
1285
1451
  * origin keeps it env-gated for the POC). Shared so both listeners produce
1286
1452
  * byte-identical HTML.
1287
1453
  */
1288
- serveCanvasShell(applyCsp: boolean, capture?: boolean): Promise<Response>;
1454
+ serveCanvasShell(
1455
+ applyCsp: boolean,
1456
+ capture: boolean,
1457
+ query: URLSearchParams | undefined,
1458
+ // gate-b-c4d — required: what the shell inlines about a canvas is held to this request's frame,
1459
+ // and a caller that left it out would read with unnarrowed access.
1460
+ req: Request
1461
+ ): Promise<Response>;
1289
1462
  /**
1290
1463
  * T2 (9.1-A) — allowlist gate for the segregated canvas origin. Returns true
1291
1464
  * only for the routes the canvas runtime legitimately needs (shell, runtime
@@ -1295,6 +1468,8 @@ export interface Http {
1295
1468
  * the app shell, or arbitrary repo files. WS upgrades are gated in server.ts.
1296
1469
  */
1297
1470
  isCanvasSafeRoute(pathname: string): boolean;
1471
+ /** S5.6 — the chat's outbox door (acp/ask-queue.ts): server.ts hands it to `createAcp`. */
1472
+ askQueue: AskQueue;
1298
1473
  }
1299
1474
 
1300
1475
  export function createHttp(
@@ -1305,13 +1480,49 @@ export function createHttp(
1305
1480
  inspects: InspectRegistry,
1306
1481
  ai: AiActivity,
1307
1482
  exportJobs: ExportJobQueue,
1308
- generateJobs: GenerationJobQueue
1483
+ generateJobs: GenerationJobQueue,
1484
+ /** V2-2.4b — the attached shell count for `maude design open` (ws.ts owns the sockets; ws is
1485
+ * created first in server.ts). Lazy: read per request, never while building the table. */
1486
+ opts: {
1487
+ shellCount?: () => number;
1488
+ /** S5.3 — THE run registry (server.ts builds it on the lease home); absent = in-memory */
1489
+ runs?: RunRegistry;
1490
+ /** S8.5 — the cloud render door for this Mac; absent/null = no cloud (videos render here) */
1491
+ cloudRenderDoor?: () => CloudRenderDoor | null;
1492
+ /** V2-1.15 §4 #13 — the people holding an element of a canvas now (collab/holds.ts) */
1493
+ personHolds?: AgentRouteDeps['personHolds'];
1494
+ } = {}
1309
1495
  ): Http {
1310
1496
  /** The current request's inspector state (Cloud Phase 27 D3). Resolved per
1311
1497
  * call rather than captured, because "whose" changes per request and a
1312
1498
  * captured instance would hand one member another's open canvas. */
1313
1499
  const inspect = () => inspects.for(currentSession());
1314
1500
 
1501
+ // V2-2.9 (T23) — the Diagnostics API's status providers for the sources this layer owns
1502
+ // (sync registers itself in server.ts). Cheap, synchronous snapshots; scrubbed on read.
1503
+ const countBy = (items: { status?: string }[]) =>
1504
+ items.reduce<Record<string, number>>((acc, j) => {
1505
+ const k = j.status ?? 'unknown';
1506
+ acc[k] = (acc[k] ?? 0) + 1;
1507
+ return acc;
1508
+ }, {});
1509
+ registerStatus('server', () => ({
1510
+ version: resolveMaudeVersion(),
1511
+ project: ctx.cfg.name ?? null,
1512
+ pid: process.pid,
1513
+ uptimeSeconds: Math.round(process.uptime()),
1514
+ rssBytes: process.memoryUsage().rss,
1515
+ }));
1516
+ registerStatus('ai', () => ({
1517
+ // the ACP chat's AiActivity entries + the banner the run registry derives (S5.3)
1518
+ activeCanvases: ai.list().length + runs.bannerEntries().length,
1519
+ runs: runs.view().live,
1520
+ // Q2 — a linked hub without runs-v1 keeps per-Mac leases, and Diagnostics says so
1521
+ leaseHome: runs.diagnostics(),
1522
+ generation: countBy(generateJobs.list()),
1523
+ }));
1524
+ registerStatus('export', () => ({ jobs: countBy(exportJobs.list()) }));
1525
+
1315
1526
  // Task 2.7 (approach A) — in-flight whisper-model download state (one at a
1316
1527
  // time), polled by the Settings "Download model" card via GET
1317
1528
  // /_api/generate/whisper-model. Closure-scoped: one server, one download.
@@ -1468,6 +1679,10 @@ export function createHttp(
1468
1679
  // untrusted canvas iframe origin can never read/write the director's analysis.
1469
1680
  const footageStore = createFootageStore(ctx);
1470
1681
  const gitApi = createGitEndpoints(ctx);
1682
+ // S9.10 (V2-1.16 L6–L10) — what THIS request's session may see. A project role sees
1683
+ // everything (every filter is the identity, U7); a canvas-only session its grants + closure.
1684
+ const visibility = projectVisibility(ctx);
1685
+ const visOf = (req: Request) => visibility.visibilityFor(accessOf(req));
1471
1686
  // Phase 28 (E3) — `/_api/github/*`. Same dual-allowlist rule: main-origin only,
1472
1687
  // and every route is token-bearing (server-held keychain token via the loopback
1473
1688
  // bridge), so all four also carry a loopback-Host check.
@@ -1634,25 +1849,1015 @@ export function createHttp(
1634
1849
  // NOT `x-maude-canvas-token`, which carries the member's own (up to
1635
1850
  // write-capable) role. The worker only reads, so it holds only read.
1636
1851
  token: req.headers.get('x-maude-render-token') ?? undefined,
1852
+ // gate-b-c4 — the render is a frame too: renderRemotely mints its capability over the
1853
+ // job's canvases from this (stripped before the body crosses — exporters/remote.ts).
1854
+ ...(frameKeyOf(req)
1855
+ ? {
1856
+ frameMint: {
1857
+ key: (frameKeyOf(req) as Buffer).toString('base64url'),
1858
+ designRel: ctx.paths.designRel,
1859
+ },
1860
+ }
1861
+ : {}),
1637
1862
  tokensCssRel: ctx.cfg.designSystems?.[0]?.tokensCssRel ?? ctx.cfg.tokensCssRel,
1638
1863
  },
1639
1864
  };
1640
1865
  }
1641
1866
 
1642
- // V2-1.12 §5.6 — the format gate, STAGED: `newerOnly: true` gates only a
1643
- // project newer than this build. One constant in format.ts, so the sync
1644
- // runtime (sync/format-sync.ts) can never disagree with this gate.
1645
- // (V2-2.18 1.x compat cut: the outbox and `maude migrate v2` route tables
1646
- // of V2-2.14/V2-2.16 are v2-only and are not mounted here — a 1.x build
1647
- // has no "Update project".)
1648
- const gateNow = () => formatGate(ctx, STAGED_FORMAT_GATE_OPTS);
1649
- /** What a read-only session may still write (the module allowlist). */
1867
+ // V2-2.16 / V2-2.14 — the lanes' route tables (V2-2.5 folds them into its
1868
+ // one table). MAIN ORIGIN ONLY: none is in CANVAS_SAFE_API or the canvas
1869
+ // server's routes map. The outbox has no senders yet — S5 / S8 / S9 register
1870
+ // their doors and enqueue in-process; until then it serves the content-lane
1871
+ // view and the (empty) intent list, and nothing is sent.
1872
+ // S5.6 — the first sender: `ai.prompt` → the run registry (acp/ask-queue.ts). The drain reads
1873
+ // `senders[kind]` per pass, so the door is filled in once the registry exists (below).
1874
+ const outboxSenders: Parameters<typeof createOutbox>[0]['senders'] = {};
1875
+ // ONE source of gate facts for the chat (queue or send now) and the drain (release).
1876
+ // `online` has no server-side source yet (the shell's reachability) — it stays open, as before.
1877
+ // S5.18 (G10): `ai-connected` is the SIGNED-IN answer (the one `/_api/acp/status` gives the panel), not "claude is
1878
+ // installed" — a signed-out Mac keeps the prompt. A status probe that finds it connected wakes the drain.
1879
+ const aiConnectedFact = createConnectedFact({
1880
+ probe: probeAcpAvailabilityAuthed,
1881
+ sync: () => probeAcpAvailability().available,
1882
+ onOpen: () => void outbox.drain.wake().catch(() => null),
1883
+ });
1884
+ // P8 G1b (01 cf-offline-create) — the `hub` gate's fact, from the sync runtime's own connection state:
1885
+ // a linked project's prompt waits while the hub is past the grace window (V2-1.14 §5.4), and the
1886
+ // hub's return wakes the drain.
1887
+ const hubReach = createHubReachability({
1888
+ linkedHub: () => ctx.cfg.linkedHub?.url ?? null,
1889
+ onReachable: () => void outbox.drain.wake().catch(() => null),
1890
+ });
1891
+ ctx.bus.on('sync:status', (p: unknown) => hubReach.note(p));
1892
+ const outboxGates = (): GateFacts => ({
1893
+ online: true,
1894
+ hubReachable: hubReach.reachable(),
1895
+ signedIn: true,
1896
+ aiConnected: aiConnectedFact.read(),
1897
+ aiReady: true,
1898
+ allowanceResetsAt: currentAllowanceResetsAt(),
1899
+ });
1900
+ // S8.5 — the gone-target facts (V2-1.14 §5.9) from this Mac's own files. Every other kind keeps
1901
+ // the facts it had; an `export.cloud` record is also judged by its canvas / artboards (G3) and
1902
+ // your role now (G14 Can view, G9 removed). The trash write stop is built further down: read lazily.
1903
+ const cloudFacts = desktopCloudFacts(ctx.paths.designRoot, () => trashWriteStop.stopped());
1904
+ const outboxTarget = (r: IntentRecord) => {
1905
+ const base = { projectId: null, projectName: ctx.projectLabel, role: 'owner' as const };
1906
+ if (r.kind !== 'export.cloud') return base;
1907
+ const url = ctx.cfg.linkedHub?.url;
1908
+ const role = url ? intentRole(accessFor(url).role) : 'owner';
1909
+ return cloudTargetFacts(r, { ...base, role }, cloudFacts);
1910
+ };
1911
+ const outbox = createOutbox({
1912
+ designRoot: ctx.paths.designRoot,
1913
+ senders: outboxSenders,
1914
+ gates: outboxGates,
1915
+ target: (r) => outboxTarget(r),
1916
+ onChange: (seq) => ctx.bus.emit('outbox:changed', { seq }),
1917
+ });
1918
+ outbox.store.load();
1919
+ outbox.store.prune();
1920
+ // V2-1.12 §5.6 — the format gate, FULL (CONTRACT §4.1, Michal 2A): a project
1921
+ // not at this build's format is view only; a format-1 one until "Update
1922
+ // project". One constant in format.ts, so the sync runtime
1923
+ // (sync/format-sync.ts) can never disagree with this gate.
1924
+ const gateNow = () => formatGate(ctx, FORMAT_GATE_OPTS);
1925
+ // V2-2.5 — THE route table (routes/index.ts), every spec behind `guardTableRoute`. Its exact
1926
+ // paths merge into `routes` below, so `readOnlyRefusal` wraps them like every legacy key; its
1927
+ // `:param` paths run first in the fall-through (behind the same `guardedFetch` refusal).
1928
+ // S5.3 — one run registry for the hook routes, `/_api/ai/runs*` and the v1 banner routes.
1929
+ // S2.1 — the edit-op route's pre-op snapshots (/design:rollback), the same store api.ts writes.
1930
+ const editOpHistory = createHistory(ctx);
1931
+ const runs =
1932
+ opts.runs ??
1933
+ createRunRegistry({
1934
+ designRoot: null,
1935
+ designRel: ctx.paths.designRel,
1936
+ home: createLocalLeaseHome({ actor: 'you' }),
1937
+ autoRenew: false,
1938
+ emit: (e, p) => ctx.bus.emit(e, p),
1939
+ // S5.5b — THE end of every run's stage, by its run id: publish / partial / hold, and the
1940
+ // published run is announced as `project:action` with the artboards it touched.
1941
+ stage: runStageHooks({
1942
+ control: () => ctx.syncControl?.current?.() ?? null,
1943
+ emit: (e, p) => ctx.bus.emit(e, p),
1944
+ }),
1945
+ });
1946
+ const askQueue = createAskQueue({
1947
+ outbox,
1948
+ gates: outboxGates,
1949
+ project: () => hubReach.project(),
1950
+ runs: () => runs,
1951
+ ready: () => aiConnectedFact.pending(),
1952
+ });
1953
+ outboxSenders['ai.prompt'] = askQueue.sender;
1954
+ // S9.19 — the Share sheet's door to the linked hub (routes/share.ts). The hub is the one this
1955
+ // project is linked to AND that this Mac holds a credential for (a committed config alone names no
1956
+ // hub a token is sent to); an invite the hub cannot hear yet waits in the outbox and this sends it.
1957
+ const shareDeps: ShareRouteDeps = {
1958
+ hub: () => {
1959
+ const url = ctx.cfg.linkedHub?.url;
1960
+ const rec = url ? getHubRecord(url) : null;
1961
+ return url && rec?.token ? { url, token: rec.token } : null;
1962
+ },
1963
+ outbox,
1964
+ };
1965
+ outboxSenders['share.invite'] = shareInviteSender(shareDeps);
1966
+ // S9.21 — an Ask to edit queued while the hub could not hear it; sends `{ canvas? }` only.
1967
+ outboxSenders['share.ask-to-edit'] = shareAskToEditSender(shareDeps);
1968
+ // S8.5 — a cloud video asked while the cloud could not hear it: `export.cloud`, record id = job id.
1969
+ // The sender hands it over; the tracker follows it to the file (and resumes after a restart).
1970
+ // S8.5b-3 — the default door is the linked hub's, and only while its `/health` lists `render-jobs-v1`
1971
+ // (otherwise null: the Render row stays hidden). Never in a cell (it IS the hub). A test or embedder
1972
+ // can still inject its own via `opts.cloudRenderDoor`.
1973
+ const hubRenderDoor = createHubRenderDoorGetter({
1974
+ hub: () => (isWorkspaceMode() ? null : shareDeps.hub()),
1975
+ });
1976
+ hubRenderDoor.warm();
1977
+ const cloudExports = createCloudExports({
1978
+ designRoot: ctx.paths.designRoot,
1979
+ outbox,
1980
+ door: () => opts.cloudRenderDoor?.() ?? hubRenderDoor.door(),
1981
+ emit: (row) => ctx.bus.emit('export:job', row),
1982
+ });
1983
+ outboxSenders['export.cloud'] = exportCloudSender({
1984
+ door: cloudExports.door,
1985
+ accepted: cloudExports.accepted,
1986
+ settle: opts.cloudRenderDoor ? undefined : hubRenderDoor.settle,
1987
+ // S8.5b — what this Mac holds of the export's canvases, taken at send time (exporters/door-fingerprint.ts):
1988
+ // a Canvas scope is its canvas, a Folder scope every canvas in it, otherwise the project.
1989
+ fingerprint: (spec) => {
1990
+ const all = projectIndex.snapshot().canvases.map((c) => c.rel);
1991
+ const folder = spec.folder ? spec.folder.replace(/\/+$/, '') : null;
1992
+ const list = spec.canvas
1993
+ ? [spec.canvas]
1994
+ : folder
1995
+ ? all.filter((r) => r.startsWith(`${folder}/`))
1996
+ : all;
1997
+ // gate-b-c4k — judged with the effective config, like the frame's closure (access/filters.ts)
1998
+ const r = closureFingerprint(ctx.paths.designRoot, list, {
1999
+ config: closureConfigFor(ctx), // p8-c4b — with the authority's known canvases
2000
+ });
2001
+ return r.ok ? r.expect : r.reason === 'too-large' ? 'too-big' : null;
2002
+ },
2003
+ });
2004
+ cloudExports.resume();
2005
+ // S8.10 — Handoff to production: one AI run whose write scope is the target file only. Offline or
2006
+ // before Connect it waits as `export.handoff` and starts by itself (routes/handoff.ts, handoff/run.ts).
2007
+ // Every closure is lazy: the index is built further down.
2008
+ const handoffRoute: HandoffRouteDeps = {
2009
+ designRoot: ctx.paths.designRoot,
2010
+ designRel: ctx.paths.designRel,
2011
+ repoRoot: ctx.paths.repoRoot,
2012
+ access: (req) => accessOf(req),
2013
+ readCanvas: (rel) => {
2014
+ try {
2015
+ return readFileSync(join(ctx.paths.designRoot, rel), 'utf8');
2016
+ } catch {
2017
+ return null;
2018
+ }
2019
+ },
2020
+ config: () => {
2021
+ try {
2022
+ return JSON.parse(readFileSync(join(ctx.paths.designRoot, 'config.json'), 'utf8'));
2023
+ } catch {
2024
+ return null;
2025
+ }
2026
+ },
2027
+ designSystems: () => (ctx.cfg.designSystems ?? []).map((d) => d.name),
2028
+ dsOf: (rel) => projectIndex.canvas(rel)?.ds ?? null,
2029
+ // S8 Q12 — the cell route `/r/<name>.json` is the L4 lane's; until it serves, no cloud line
2030
+ registryUrl: () => null,
2031
+ aiConnected: () => aiConnectedFact.read(),
2032
+ handoffs: null as unknown as HandoffRouteDeps['handoffs'],
2033
+ };
2034
+ handoffRoute.handoffs = createHandoffs({
2035
+ repoRoot: ctx.paths.repoRoot,
2036
+ designRel: ctx.paths.designRel,
2037
+ outbox,
2038
+ gates: outboxGates,
2039
+ runs: () => runs,
2040
+ resolve: (payload) => resolveQueuedHandoff(handoffRoute, payload),
2041
+ });
2042
+ outboxSenders['export.handoff'] = handoffRoute.handoffs.sender;
2043
+ // boot: a prompt queued before a restart is released once its gates are open (V2-1.14 §5.5)
2044
+ void outbox.drain.wake().catch(() => null);
2045
+ // S11.11 — Resync's trace (sync/resync-trace.ts): `POST /_api/sync/resync` (routes/sync.ts) starts
2046
+ // it, `/_sync-status` below reports it ("Resyncing… 1 204 of 1 318", then the result).
2047
+ // S11.12 — the held source conflict's third answer (one attempt per canvas at a time).
2048
+ const keepBothConflict = createKeepBothResolver({
2049
+ runtime: () => ctx.syncControl?.current?.() ?? null,
2050
+ designRoot: ctx.paths.designRoot,
2051
+ fileForSlug: (slug) => api.fileForSlug(slug),
2052
+ duplicate: (input) => api.duplicateCanvas(input),
2053
+ });
2054
+ const resyncTrace = createResyncTrace({
2055
+ // ctx.syncControl's structural type (context.ts) omits `status()`; the live runtime has it
2056
+ read: () =>
2057
+ (
2058
+ ctx.syncControl?.current?.() as { status?(): ResyncStatusSource | null } | null | undefined
2059
+ )?.status?.() ?? null,
2060
+ expectFiles: () => readSyncSettings(ctx.paths.repoRoot)?.syncFiles !== false,
2061
+ });
2062
+ // S8.1 — what the v2 export doors read: the index rows (the expansion runs over the ones the
2063
+ // session sees), the active canvas, this session's access and export history, the lane.
2064
+ const exportV2Deps: ExportRouteDeps = {
2065
+ designRel: ctx.paths.designRel,
2066
+ projectName: () => ctx.cfg.name || ctx.projectLabel || 'export',
2067
+ canvases: () => projectIndex.snapshot().canvases,
2068
+ activeCanvas: () => {
2069
+ const active = (inspect().state as { active?: string | null }).active;
2070
+ return active ? toDesignRel(active, ctx.paths.designRel) : null;
2071
+ },
2072
+ // a cell child's session is the proxy's claim ON THE REQUEST (never the ambient default)
2073
+ access: (req) => accessOf(req),
2074
+ history: () => exportJobs.loadHistory(),
2075
+ // P8 C2 — /_api/export-preview: row and tile pictures from the project's picture service (created further down)
2076
+ thumb: (req) => thumbs.thumb(req),
2077
+ renderLane: () => resolveRenderLane(),
2078
+ // S8.5 — the Render row: a cloud door on this Mac, and a comp's own length (Suggest each time)
2079
+ cloudRender: () => resolveRenderLane() === 'local' && cloudExports.available(),
2080
+ videoSeconds: (rel) => cloudFacts.videoSeconds(rel),
2081
+ // S8.4 — Retry: only the failed items of one of THIS session's group jobs
2082
+ retry: (id, items, session, allow) => exportJobs.retry(id, items, session, allow),
2083
+ // S8.7 — the Print preflight: fonts are read under the design root; the safe margin is measured from the
2084
+ // canvas-rects manifest (a headless render of the canvas, through the capture origin's 307 like every
2085
+ // capture). One render at a time (the browser session is single), a short memory per file version, and a
2086
+ // failure is "unmeasured" — never an error the sheet shows. A cell gets no rects runner at all: it
2087
+ // renders tenant TSX, and a cell must not evaluate it (DDR-193) — the margin is then "unmeasured".
2088
+ preflight: {
2089
+ designRoot: ctx.paths.designRoot,
2090
+ ...(isWorkspaceMode()
2091
+ ? {}
2092
+ : {
2093
+ rects: createRectsRunner({
2094
+ repoRoot: ctx.paths.repoRoot,
2095
+ designRoot: ctx.paths.designRoot,
2096
+ script: join(BIN_DIR, 'canvas-rects.sh'),
2097
+ }),
2098
+ }),
2099
+ },
2100
+ };
2101
+ // S10.3 — the design-system engine (S10.2) over THE kernel port, its one ⌘Z hook, and the
2102
+ // outside-change watcher (W = 5 s quiet per system folder, fed by the design-root fs events).
2103
+ const dsEngine = createDsEngine({
2104
+ designRoot: ctx.paths.designRoot,
2105
+ kernel: kernelPortFrom(() => ctx.syncControl?.current?.() ?? null),
2106
+ });
2107
+ registerDsUndoHook(dsEngine);
2108
+ const dsOutside = createDsOutsideWatcher({
2109
+ designRoot: ctx.paths.designRoot,
2110
+ engine: dsEngine,
2111
+ onChange: (system) => ctx.bus.emit('ds:outside', { system }),
2112
+ });
2113
+ ctx.bus.on('fs:any', (rel: string) => dsOutside.notify(rel));
2114
+ // S10.3b — a file the file plane delivered is a peer's change, not an unknown outside edit
2115
+ ctx.bus.on('file-plane:delivered', (p: { rel?: unknown }) => {
2116
+ if (typeof p?.rel === 'string') dsOutside.notify(p.rel, { kind: 'peer' });
2117
+ });
2118
+ // S8.20 — built with the thumbnail service below; the describe routes read it lazily
2119
+ let describeSvc: DescribeService | null = null;
2120
+ const tableSpecs = allSpecs({
2121
+ outbox: { outbox },
2122
+ // S11.4 — what is on this Mac vs still coming: the runtime's in-memory listing against the
2123
+ // index's own disk scan (never a hub request); filtered by the request's access.
2124
+ availability: {
2125
+ source: () => ctx.syncControl?.current?.()?.availability?.() ?? null,
2126
+ local: async () => canvasPathsOfIndex(await api.buildIndexData()),
2127
+ designRel: ctx.paths.designRel,
2128
+ access: (req) => accessOf(req),
2129
+ project: () => ctx.cfg.name ?? null,
2130
+ },
2131
+ // S9.24 — the object conflicts THIS Mac lost (_state/conflicts/): the card's list, and a pick
2132
+ // as one ordinary lane edit through the canvas's own op path (one batch = one undo step).
2133
+ syncConflicts: {
2134
+ designRoot: ctx.paths.designRoot,
2135
+ designRel: ctx.paths.designRel,
2136
+ fileForSlug: (slug) => api.fileForSlug(slug),
2137
+ readBoard: (file) => api.readBoard(file),
2138
+ applyAnnotationOps: (file, ops) => api.applyAnnotationOps(file, ops),
2139
+ access: (req) => accessOf(req),
2140
+ emit: (e, p) => ctx.bus.emit(e, p),
2141
+ },
2142
+ // S10.3 — `/_api/ds/*` (routes/ds.ts): Q15 gates on the session's access, the person by
2143
+ // the same rule as a sticky's converter, the usage index the project index hosts (S10.5)
2144
+ ds: {
2145
+ engine: () => dsEngine,
2146
+ outside: () => dsOutside,
2147
+ usage: () => projectIndex.dsUsage(),
2148
+ access: (req) => accessOf(req),
2149
+ person: async (req) => {
2150
+ const vouched = isWorkspaceMode() ? req.headers.get('x-maude-user') : null;
2151
+ return { name: vouched || (await api.gitCurrentUser()) || 'You' };
2152
+ },
2153
+ emit: (e, p) => ctx.bus.emit(e, p),
2154
+ // S10.16a — a Design system canvas's section reads 'drawing' while a run holds its artboard
2155
+ held: (canvasRel) => heldArtboards(runs, canvasRel),
2156
+ },
2157
+ // S4.14 — `/_api/votes*` (routes/votes.ts): board ballots locally, a proxy to a `votes-v1` hub when
2158
+ // linked, off in a cell / on an older hub. The voter is this machine's person, never the body.
2159
+ votes: {
2160
+ designRel: ctx.paths.designRel,
2161
+ home: createVoteHomeResolver({
2162
+ linked: () => {
2163
+ const url = ctx.cfg.linkedHub?.url;
2164
+ return url ? { hubUrl: url, token: () => getHubRecord(url)?.token ?? null } : null;
2165
+ },
2166
+ workspace: () => isWorkspaceMode(),
2167
+ health: (hubUrl) => hubHealth({ hubUrl }),
2168
+ }),
2169
+ person: async () => ((await api.gitCurrentUser()) || 'You').slice(0, 64),
2170
+ // S4.V4 G4 — a live room's board, ahead of its flush: start → GET must see the vote it just wrote
2171
+ readBoard: (file) => api.readBoardLive(file),
2172
+ applyOps: (file, ops) => api.applyAnnotationOps(file, ops),
2173
+ // sec-a C1(c) — the result names come from the canvas source, never the canvas's vote-board
2174
+ labels: (canvas) => {
2175
+ if (!canvas || canvas.startsWith('/') || canvas.split('/').some((s) => s === '..' || !s))
2176
+ return {};
2177
+ try {
2178
+ const src = readFileSync(join(ctx.paths.designRoot, ...canvas.split('/')), 'utf8');
2179
+ const out: Record<string, string> = {};
2180
+ for (const [id, label] of artboardLabels(src)) out[`ab:${id}`] = label;
2181
+ return out;
2182
+ } catch {
2183
+ return {};
2184
+ }
2185
+ },
2186
+ scope: (req, file) => {
2187
+ const see = seerFor(req);
2188
+ if (!see) return null;
2189
+ const rel = toDesignRel(file, ctx.paths.designRel);
2190
+ return rel === null || !see(rel) ? notInScopeResponse() : null;
2191
+ },
2192
+ },
2193
+ // S5.5 — undo over the one op log (V2-1.5 §5.3); the home answers, the bus hears it
2194
+ // S1.7 — the shared Trash (routes/trash.ts). The access: in a cell the proxy's vouched
2195
+ // `x-maude-access` claim (fail closed); on a desktop the person at the keyboard — a local
2196
+ // project's owner, or the role the hub vouched at sign-in (the hub re-checks every op).
2197
+ trash: {
2198
+ control: () => ctx.syncControl?.current?.() ?? null,
2199
+ access: (req) =>
2200
+ trashAccess({
2201
+ workspace: isWorkspaceMode(),
2202
+ header: req.headers.get('x-maude-access'),
2203
+ localRole: ctx.cfg.linkedHub
2204
+ ? (getHubRecord(ctx.cfg.linkedHub.url)?.role ?? null)
2205
+ : 'owner',
2206
+ }),
2207
+ readSource: (rel) => {
2208
+ if (!rel || rel.startsWith('/') || rel.split('/').some((s) => s === '..' || s === ''))
2209
+ return null;
2210
+ try {
2211
+ return readFileSync(join(ctx.paths.designRoot, ...rel.split('/')), 'utf8');
2212
+ } catch {
2213
+ return null;
2214
+ }
2215
+ },
2216
+ emit: (e, p) => ctx.bus.emit(e, p),
2217
+ // S1.13b — an artboard comes back through S1.13's splice, from the revision before its
2218
+ // trash action, as ONE `restore` action (S1 Q3; history/restore-artboard-action.ts).
2219
+ restoreArtboard: trashArtboardRestorer({
2220
+ control: () => ctx.syncControl?.current?.() ?? null,
2221
+ designRel: ctx.paths.designRel,
2222
+ announce: (actionId) =>
2223
+ void announceAction(
2224
+ {
2225
+ control: () => ctx.syncControl?.current?.() ?? null,
2226
+ emit: (e, p) => ctx.bus.emit(e, p),
2227
+ },
2228
+ actionId
2229
+ ),
2230
+ }),
2231
+ },
2232
+ projectUndo: {
2233
+ control: () => ctx.syncControl?.current?.() ?? null,
2234
+ designRel: ctx.paths.designRel,
2235
+ emit: (e, p) => ctx.bus.emit(e, p),
2236
+ },
2237
+ // S1.12b — Version history (V2-1.9 §5.11): rows, words, names, kept-aside versions. The
2238
+ // session's access is `currentAccess()` (S9.9, server.ts withSession).
2239
+ // S11.17 — the crash line's "Your work up to …" reads the project home; the disk hold is the studio's
2240
+ diagnostics: { control: () => ctx.syncControl?.current?.() ?? null },
2241
+ history: {
2242
+ control: () => ctx.syncControl?.current?.() ?? null,
2243
+ designRel: ctx.paths.designRel,
2244
+ // S1.13 — Go back reads `_state/render-ok.json` under the design root
2245
+ designRoot: ctx.paths.designRoot,
2246
+ // S1.14 — row pictures from the project's picture service; `thumbs` is created further down,
2247
+ // so it is read lazily (S1.V G4: without it every versions row drew an empty box)
2248
+ thumb: (req) => thumbs.thumb(req),
2249
+ cache: (() => {
2250
+ let cache: AttributionCache | null = null;
2251
+ return () => {
2252
+ cache ??= createAttributionCache({ dir: attributionDir(pidOf(ctx.paths.repoRoot)) });
2253
+ return cache;
2254
+ };
2255
+ })(),
2256
+ // a hub without accepted revisions: its commit history of the canvas (§5.2 last line)
2257
+ gitHistory: async (repoRel, limit) => {
2258
+ const r = await cloudApi.history(repoRel, String(limit));
2259
+ const j = r.json as { ok?: boolean; reason?: string; entries?: GitEntry[] } | null;
2260
+ if (j?.ok) return j.entries ?? [];
2261
+ return j?.reason === 'unreachable' ? undefined : null;
2262
+ },
2263
+ gitLane: async (repoRel, sha, lane) => {
2264
+ const readers = versionReaders(ctx);
2265
+ if (lane !== 'html') return laneAtRef(readers, repoRel, `git:${sha}`, lane);
2266
+ const fromCommit = await readers.git?.(sha, repoRel).catch(() => null);
2267
+ if (fromCommit != null) return fromCommit;
2268
+ return (await readers.cloud?.(sha, repoRel).catch(() => null)) ?? null;
2269
+ },
2270
+ emit: (e, p) => ctx.bus.emit(e, p),
2271
+ },
2272
+ // S1.18 — stable canvas links over the same home (entry → current path)
2273
+ links: {
2274
+ control: () => ctx.syncControl?.current?.() ?? null,
2275
+ designRel: ctx.paths.designRel,
2276
+ // S9.9 — the session's access, read per request: a canvas-only visitor resolves only the
2277
+ // canvases it holds (history/links.ts answers `unknown` for the rest — no existence oracle).
2278
+ scope: (req) => accessOf(req),
2279
+ },
2280
+ // S4.7 — sticky ↔ comment as one action; the converter is the session (a cell's vouched
2281
+ // member, else this machine's git identity) — never the body (contract S4-S9 §3.1).
2282
+ annotations: {
2283
+ api,
2284
+ control: () => ctx.syncControl?.current?.() ?? null,
2285
+ // S4.16 - POST /_api/annotations/figjam plans the import under the project (the S4.5 engine)
2286
+ figjam: { root: ctx.paths.repoRoot, designRel: ctx.paths.designRel },
2287
+ // the same name a reply of yours is stamped with (`commentsAddReply` → localAuthor: git user, else
2288
+ // this Mac's account) — else, on a machine with no git user.name, your own reply reads as foreign
2289
+ person: async (req) => {
2290
+ const vouched = isWorkspaceMode() ? req.headers.get('x-maude-user') : null;
2291
+ return { name: vouched || localAuthor(await api.gitCurrentUser()) };
2292
+ },
2293
+ // S9.9 — a canvas-only session converts only on a canvas it sees (`not-in-scope`, like missing).
2294
+ scope: (req, file) => {
2295
+ const see = seerFor(req);
2296
+ if (!see) return null;
2297
+ const rel = toDesignRel(file, ctx.paths.designRel);
2298
+ return rel === null || !see(rel) ? notInScopeResponse() : null;
2299
+ },
2300
+ },
2301
+ ai: {
2302
+ registry: runs,
2303
+ repoRoot: ctx.paths.repoRoot,
2304
+ designRel: ctx.paths.designRel,
2305
+ // the ACP chat's own banner entries (acp/index.ts → AiActivity) until S5.6 moves the
2306
+ // chat turn onto the registry
2307
+ legacyEntries: () => ai.list(),
2308
+ // S9.11 (V2-1.16 L13) — a canvas-only session's runs and banner entries
2309
+ seerFor: (req) => seerFor(req),
2310
+ // T16 — a v1 `/design:edit` is ONE project action
2311
+ beginAction: (key, name) => ctx.syncControl?.current?.()?.beginAiAction?.(key, name),
2312
+ endAction: (key, outcome) => ctx.syncControl?.current?.()?.endAiAction?.(key, outcome),
2313
+ // S5.11b — Run on a copy: the accepted source + the waiting run's stage
2314
+ control: () => ctx.syncControl?.current?.() ?? null,
2315
+ // S5.18 (G2) — the copy's name + place go into the canvas sidecar through the layout-write door
2316
+ meta: { write: (file, text, base, o) => api.writeCanvasMetaText(file, text, base, o) },
2317
+ },
2318
+ agent: {
2319
+ repoRoot: ctx.paths.repoRoot,
2320
+ designRel: ctx.paths.designRel,
2321
+ shells: () => opts.shellCount?.() ?? 0,
2322
+ emit: (e, p) => ctx.bus.emit(e, p),
2323
+ personHolds: opts.personHolds,
2324
+ // §5.4 `read-only`: the agent routes are non-browser, so only the format gate applies here
2325
+ // (a hub role is a browser-session property).
2326
+ readOnly: () => gateNow() !== null,
2327
+ // p8-a1-claims — POST /_api/agent/write/claim: a disk-writing verb's bytes, claimed for its chat's live run
2328
+ claimWrites: (chat, writes) =>
2329
+ claimWritesForChat(runs, ctx.syncControl?.current?.(), ctx.paths.designRel, chat, writes),
2330
+ // the run bracket onto today's T16 project action + the ai-activity banner, keyed like the
2331
+ // Maude chat's (acp/index.ts keyFor): `${designRel}/${designRoot-relative canvas}`.
2332
+ // A Maude chat run (actor maude-chat, MAUDE_AGENT_ACTOR from acp/bridge.ts) is bracketed by
2333
+ // acp/index.ts already — its T16 action + banner; the hook routes skip it, so it is never
2334
+ // bracketed twice. Every other run is a terminal Claude Code.
2335
+ bracket: {
2336
+ // S5.5b — the stage is begun under the registry's run id; the REGISTRY ends it
2337
+ // (`stage` above), so there is no `end` here: one turn is never two stages.
2338
+ begin: (r) => {
2339
+ if (r.actor === 'maude-chat') return;
2340
+ ctx.syncControl
2341
+ ?.current?.()
2342
+ ?.beginAiAction?.(`agent:${r.session}`, r.label || 'AI', { runId: r.run });
2343
+ },
2344
+ // S5.3 — the ai-activity banner of a hook run is DERIVED from the registry (ai/runs.ts
2345
+ // `bannerEntries`), never a second entry in AiActivity. p8-a1-claims — `touch` (after the
2346
+ // write) no longer claims what the disk holds then: those could be a person's bytes. The
2347
+ // claims are made BEFORE the write: `claim` (edit/check's replayed bytes) and `window`
2348
+ // (a Bash call that cannot claim, for the canvases it names).
2349
+ ...hookClaims(() => ctx.syncControl?.current?.(), ctx.paths.designRel),
2350
+ },
2351
+ },
2352
+ projectFormat: {
2353
+ repoRoot: ctx.paths.repoRoot,
2354
+ designRel: ctx.paths.designRel,
2355
+ hub: () => {
2356
+ const url = ctx.cfg.linkedHub?.url;
2357
+ const rec = url ? getHubRecord(url) : null;
2358
+ return url && rec ? { url, token: rec.token, role: rec.role ?? 'member' } : null;
2359
+ },
2360
+ // gate-b-sec4 — the committed link boot parked (never made on this Mac): Connect, not Sign in
2361
+ parkedHub: () => ctx.unconfirmedHub?.url ?? null,
2362
+ formatView: (req) => formatConfigFields(ctx, roleReadOnly(req), FORMAT_GATE_OPTS),
2363
+ onMigrated: () => {
2364
+ if (reloadConfig(ctx)) ctx.bus.emit('config-updated');
2365
+ },
2366
+ },
2367
+ // S9.7b — POST /_api/comments/op (routes/comments.ts). The author is the session: a cell's
2368
+ // vouched member, else this machine's git identity — never a name in the body.
2369
+ comments: {
2370
+ designRel: ctx.paths.designRel,
2371
+ actor: async (req) => ({
2372
+ name:
2373
+ (isWorkspaceMode() ? req.headers.get('x-maude-user') : null)?.slice(0, 120) ||
2374
+ localAuthor(await api.gitCurrentUser()),
2375
+ }),
2376
+ fileOf: (id) => api.commentFileOf(id),
2377
+ apply: (file, op, actor) => api.commentOp(file, op, actor),
2378
+ },
2379
+ // V2-3.4 — GET /_api/shell/status (routes/shell.ts): the desktop shell's token-gated probe.
2380
+ shell: { outbox, exportJobs, generateJobs },
2381
+ pins: { designRoot: ctx.paths.designRoot },
2382
+ // S3.10a — where an on-click link goes, read from the versioned TSX (routes/element-links.ts)
2383
+ elementLinks: {
2384
+ designRoot: ctx.paths.designRoot,
2385
+ designRel: ctx.paths.designRel,
2386
+ // the session's own predicate (S9.9): a canvas-only session reads its grants' closure and nothing else,
2387
+ // so a link to a canvas it was not granted reads `dangling` (no existence oracle, V2-1.16 U1)
2388
+ sees: (req, rel) => {
2389
+ const access = accessOf(req);
2390
+ // S9.11's closure (the same one readOnlyRefusal / the seer use), null without grants
2391
+ return accessSees(access, closureOf(access), rel);
2392
+ },
2393
+ },
2394
+ // S11.11 — POST /_api/sync/resync (routes/sync.ts), moved from the legacy literal.
2395
+ // gate-b-sec4 — GET /_api/sync/link + POST /_api/sync/link/confirm: the parked committed link.
2396
+ sync: { control: () => ctx.syncControl, trace: resyncTrace, link: createLinkGate(ctx) },
2397
+ // S11.13 — Settings › Advanced reads: the decision-memory count and the bundled plugin versions.
2398
+ settings: { repoRoot: ctx.paths.repoRoot },
2399
+ // S5.7 — the chat store's search / trash / resume-session routes (routes/chat.ts).
2400
+ chat: {
2401
+ designRoot: ctx.paths.designRoot,
2402
+ outbox: outbox.store,
2403
+ isRunning: (id) => runningChats().includes(id),
2404
+ },
2405
+ // S2.1 — POST /_api/edit-op (routes/edit.ts): one dispatch route, pure writers in edit-ops/.
2406
+ // The write announces its base like every lane writer; AI holds read the run registry above.
2407
+ edit: {
2408
+ designRoot: ctx.paths.designRoot,
2409
+ designRel: ctx.paths.designRel,
2410
+ repoRoot: ctx.paths.repoRoot,
2411
+ emit: (e, p) => ctx.bus.emit(e, p),
2412
+ snapshot: (rel, before, reason) => editOpHistory.writeSnapshot(rel, before, reason),
2413
+ actionFor: (repoRel, after) =>
2414
+ ctx.syncControl?.current?.()?.acceptedActionForContent?.(repoRel, after) ?? null,
2415
+ // S2.2b — `element.set-id` moves comment pins + board hosts through api.ts's write paths
2416
+ references: createReferenceLanes({
2417
+ designRel: ctx.paths.designRel,
2418
+ loadComments: (f) => api.loadCommentsForFile(f),
2419
+ rewriteComments: (f, fn) =>
2420
+ api.rewriteComments(f, fn as Parameters<Api['rewriteComments']>[1]),
2421
+ readBoard: (f) => api.readBoard(f),
2422
+ applyBoardOps: (f, ops) => api.applyAnnotationOps(f, ops),
2423
+ acceptedMode: () => !!ctx.syncControl?.current?.()?.acceptedMode?.(),
2424
+ }),
2425
+ // S2.10 — an artboard copy's place goes to the layout lane in the same request (routes/edit.ts)
2426
+ meta: {
2427
+ load: (file) => api.loadCanvasMeta(file),
2428
+ patch: (file, patch) => api.patchCanvasMeta(file, patch),
2429
+ writeText: (file, next, base, o) => api.writeCanvasMetaText(file, next, base, o),
2430
+ },
2431
+ // S2.10b — an op-log home lands the source + the layout lane as ONE action (routes/edit.ts `land`)
2432
+ control: () => ctx.syncControl?.current?.() ?? null,
2433
+ // S2.10c — a trashed artboard's annotations leave in the same action (the board's own writer)
2434
+ board: {
2435
+ read: (file) => api.readBoard(file),
2436
+ apply: (file, ops, o) => api.applyAnnotationOps(file, ops, undefined, o),
2437
+ },
2438
+ // S2.16 — GET /_api/ds/components is minRole edit: the route asks the session's access
2439
+ access: (req) => accessOf(req),
2440
+ // S8.15 — /_api/photo-every-use (routes/photo-every-use.ts): Apply to every use
2441
+ photoEveryUse: {
2442
+ access: (req) => accessOf(req),
2443
+ closure: (access) => closureOf(access),
2444
+ usedIn: (rel) =>
2445
+ projectIndex.assetsAnswer().assets.find((a) => a.rel === rel)?.usedIn ?? [],
2446
+ read: (rel) => {
2447
+ try {
2448
+ return readFileSync(join(ctx.paths.designRoot, rel), 'utf8');
2449
+ } catch {
2450
+ return null;
2451
+ }
2452
+ },
2453
+ exists: (rel) => existsSync(join(ctx.paths.designRoot, rel)),
2454
+ saveEveryUse: (asset, edit) => photoStore.savePhotoEdit(asset, edit),
2455
+ },
2456
+ },
2457
+ // S8.19 — GET /_api/asset-state (routes/asset-state.ts): built once, over the live runtime.
2458
+ assetState: assetStateDepsFor({
2459
+ designRoot: ctx.paths.designRoot,
2460
+ designRel: ctx.paths.designRel,
2461
+ runtime: () => ctx.syncControl?.current?.() ?? null,
2462
+ access: (req) => accessOf(req),
2463
+ }),
2464
+ // S8.13 — POST /_api/assets/trash (routes/asset-trash.ts): the verdict is the index's row for the file.
2465
+ assetTrash: {
2466
+ designRoot: ctx.paths.designRoot,
2467
+ access: (req) => accessOf(req),
2468
+ rows: () => projectIndex.assetsAnswer().assets,
2469
+ announce: (rel) => {
2470
+ if (isWorkspaceMode()) ctx.bus.emit('fs:any', rel);
2471
+ },
2472
+ },
2473
+ // S8.17 — POST /_api/figma/frames + /_api/figma/import-frames (routes/figma.ts): the verb, lazily.
2474
+ figma: {
2475
+ root: ctx.paths.repoRoot,
2476
+ designRel: ctx.paths.designRel,
2477
+ access: (req) => accessOf(req),
2478
+ announce: (rel) => {
2479
+ if (isWorkspaceMode()) ctx.bus.emit('fs:any', rel);
2480
+ },
2481
+ // S8.17b — imported Figma comment pins are stamped `by` the importer: the vouched member in a cell,
2482
+ // the git user on this Mac (same rule as the comments deps).
2483
+ importer: async (req) =>
2484
+ (isWorkspaceMode() ? req.headers.get('x-maude-user') : null)?.slice(0, 120) ||
2485
+ (await api.gitCurrentUser()),
2486
+ },
2487
+ // S8.22 — POST /_api/import-asset (routes/assets.ts): v2 body, PSD/HEIC through the sandboxed sips, dedupe answer.
2488
+ assetImport: {
2489
+ root: ctx.paths.repoRoot,
2490
+ designRel: ctx.paths.designRel,
2491
+ access: (req) => accessOf(req),
2492
+ announce: (rel) => {
2493
+ if (isWorkspaceMode()) ctx.bus.emit('fs:any', rel);
2494
+ },
2495
+ },
2496
+ // S8.20 — /_api/describe* (routes/describe.ts): search in pictures — the consent, Stop, and what AI saw. A Mac only.
2497
+ describe: {
2498
+ service: () => describeSvc,
2499
+ access: (req) => accessOf(req),
2500
+ inCell: isWorkspaceMode(),
2501
+ },
2502
+ // S8.21 — GET /_api/asset-details, /_api/asset-generated (routes/asset-details.ts): details per kind, the Generated runs.
2503
+ // The Original path is this Mac's own record: a cell has no Mac, so it keeps none.
2504
+ assetDetails: {
2505
+ designRoot: ctx.paths.designRoot,
2506
+ access: (req) => accessOf(req),
2507
+ usedIn: (rel) => projectIndex.assetsAnswer().assets.find((a) => a.rel === rel)?.usedIn ?? [],
2508
+ read: (rel) => {
2509
+ try {
2510
+ return readFileSync(join(ctx.paths.designRoot, rel), 'utf8');
2511
+ } catch {
2512
+ return null;
2513
+ }
2514
+ },
2515
+ inCell: isWorkspaceMode(),
2516
+ },
2517
+ // S8.16 — /_api/generate-takes* (routes/generate.ts): N takes on the generation queue, the consent quote, ← →.
2518
+ generate: generateDepsFor({
2519
+ designRoot: ctx.paths.designRoot,
2520
+ designRel: ctx.paths.designRel,
2521
+ access: (req) => accessOf(req),
2522
+ artboard: (canvas, id) => {
2523
+ const ab = projectIndex.canvas(canvas)?.artboards.find((a) => a.id === id);
2524
+ return ab ? { w: ab.w, h: ab.h, label: ab.label } : null;
2525
+ },
2526
+ jobs: generateJobs,
2527
+ saveAsset: (bytes) => api.saveAsset(bytes),
2528
+ emit: (g) => ctx.bus.emit('generate:takes', g),
2529
+ }),
2530
+ // S8.10 — /_api/handoff* (routes/handoff.ts): built with the outbox above (its sender is the same).
2531
+ handoff: handoffRoute,
2532
+ // S9.19 — /_api/share/*: the desktop's door to the linked hub's access API.
2533
+ share: shareDeps,
2534
+ // S3.5 — PATCH /_api/present-meta (routes/present.ts): order, skip and notes in the versioned
2535
+ // meta, through the layout lane's writer. Ids are checked against a FRESH parse of the source
2536
+ // (the index may lag an artboard added a moment ago); a canvas whose artboards a parse cannot
2537
+ // list is complete once the renderer harvested them (V2-1.17 §5.8).
2538
+ present: {
2539
+ repoRoot: ctx.paths.repoRoot,
2540
+ designRoot: ctx.paths.designRoot,
2541
+ artboards: (srcAbs) => {
2542
+ const rel = relative(ctx.paths.designRoot, srcAbs).replace(/\\/g, '/');
2543
+ try {
2544
+ const row = extractCanvas(
2545
+ {
2546
+ designRoot: ctx.paths.designRoot,
2547
+ repoRoot: ctx.paths.repoRoot,
2548
+ groups: ctx.cfg.canvasGroups,
2549
+ defaultDs: null,
2550
+ designSystems: ctx.cfg.designSystems ?? [],
2551
+ },
2552
+ rel
2553
+ );
2554
+ if (row.parse !== 'ok') return null;
2555
+ if (!row.dynamic) return { ids: row.artboards.map((a) => a.id), complete: true };
2556
+ const live = projectIndex.canvas(rel);
2557
+ return live?.artboardsFrom === 'runtime'
2558
+ ? { ids: [...row.artboards, ...live.artboards].map((a) => a.id), complete: true }
2559
+ : { ids: row.artboards.map((a) => a.id), complete: false };
2560
+ } catch {
2561
+ return null;
2562
+ }
2563
+ },
2564
+ write: async (file, nextText, baseText) => {
2565
+ await api.writeCanvasMetaText(file, nextText, baseText);
2566
+ },
2567
+ },
2568
+ // S8.1 — ExportSpec v2: the estimate route, and the v2 half of /_api/export(-jobs) below
2569
+ export: exportV2Deps,
2570
+ // S11.6 — GET /_api/canvas-source + /_api/canvas-errors (routes/canvas-source.ts): main origin
2571
+ // only, `export` on the canvas (Can view refused), a canvas-only session its grants only.
2572
+ canvasSource: {
2573
+ designRoot: ctx.paths.designRoot,
2574
+ designRel: ctx.paths.designRel,
2575
+ historicalSource: (repoRel, ref) => historicalCanvasSource(ctx, repoRel, ref),
2576
+ // A GET of project source is CORS-readable once a rebound page shares this origin.
2577
+ trustedHost: (req) => isTrustedRequestHost(req),
2578
+ },
2579
+ // S5.10 — attachments + folder consent (routes/chat-attach.ts). Main origin only.
2580
+ chatAttach: {
2581
+ designRoot: ctx.paths.designRoot,
2582
+ projectRoot: ctx.paths.repoRoot,
2583
+ saveAsset: (stream) => api.saveAssetFromStream(stream),
2584
+ },
2585
+ // S6.0b — POST|GET /_api/cloud/move (routes/cloud-move.ts): main origin only, on the attach lane.
2586
+ cloudMove: {
2587
+ designRoot: ctx.paths.designRoot,
2588
+ projectName: () => ctx.cfg.name ?? null,
2589
+ localFormat: () => asFormat(ctx.cfg.formatVersion),
2590
+ cloud: cloudApi,
2591
+ },
2592
+ // S6.15 — POST /_api/help/add-guides (routes/help-guides.ts): main origin only, Can edit and up.
2593
+ helpGuides: { uiDir: () => join(ctx.paths.designRoot, ctx.cfg.newCanvasDir || 'ui') },
2594
+ // S9.20b — GET /_api/cloud/plan (routes/cloud-plan.ts): main origin only, the device token.
2595
+ cloudPlan: { cloud: cloudApi },
2596
+ // S11.14 — GET /_api/connections/hub (routes/connections.ts): main origin only, the hub credential.
2597
+ connections: { designRoot: ctx.paths.designRoot },
2598
+ }).map(guardTableRoute);
2599
+ // p8-a1-claims — outside the gates: a write that names an AI chat answers inside its run's claim
2600
+ // (in place, so every consumer of the table — the mount, the local gate — sees the same specs)
2601
+ tableSpecs.splice(0, tableSpecs.length, ...tableSpecs.map((s) => claimingTableRoute(s, runs)));
2602
+ const laneRoutes = mountRoutes(tableSpecs);
2603
+ // V2-2.17 — the project index (contract V2-1.17): built now, updated per fs event, persisted
2604
+ // in the machine cache (~/.maude/index/v1, outside the project). Cells write none.
2605
+ const projectIndex = createIndexService({
2606
+ root: ctx.paths.repoRoot,
2607
+ designRel: ctx.paths.designRel,
2608
+ context: () => ({
2609
+ designRoot: ctx.paths.designRoot,
2610
+ repoRoot: ctx.paths.repoRoot,
2611
+ groups: ctx.cfg.canvasGroups,
2612
+ defaultDs: ctx.cfg.defaultDesignSystem || ctx.cfg.designSystems?.[0]?.name || null,
2613
+ designSystems: ctx.cfg.designSystems ?? [],
2614
+ componentDir: ctx.cfg.newComponentDir,
2615
+ }),
2616
+ project: () => ({
2617
+ name: ctx.cfg.name ?? ctx.projectLabel,
2618
+ label: ctx.projectLabel ?? null,
2619
+ formatVersion: projectFormat(ctx).value,
2620
+ linkedHub: ctx.cfg.linkedHub ? { url: ctx.cfg.linkedHub.url } : null,
2621
+ managed: isWorkspaceMode(),
2622
+ }),
2623
+ persist: !isWorkspaceMode(),
2624
+ // S10.5 — host the ds-usage index (lazy; persisted on a desktop, memory-only in a cell)
2625
+ dsUsage: { persist: !isWorkspaceMode() },
2626
+ // S8.12 — "Not used" reads the retained versions through the sync runtime Version history reads; null (no home
2627
+ // answers yet) leaves the verdict at 'checking', never at "not used"
2628
+ history: () => historySourceFromRuntime(ctx.syncControl?.current?.(), ctx.paths.designRel),
2629
+ });
2630
+ // S8.12 — server.ts attaches the sync runtime after this runs; the history scan starts when a home answers
2631
+ kickWhenReady({
2632
+ ready: () => !!ctx.syncControl?.current?.(),
2633
+ kick: () => projectIndex.startHistoryScan(),
2634
+ });
2635
+ ctx.bus.on('fs:any', (rel: string) => {
2636
+ projectIndex.update([rel]);
2637
+ });
2638
+ ctx.bus.on('config-updated', () => projectIndex.rebuild());
2639
+ // V2-8.5 r7 — the first Design system board reads the persisted usage file: build it soon after boot
2640
+ warmDsUsage(projectIndex.dsUsage(), () => (ctx.cfg.designSystems?.length ?? 0) > 0);
2641
+ projectIndex.on('changed', (e) => ctx.bus.emit('index-changed', e));
2642
+ // S8.11 — a version recorded after the history scan joins the asset index ("Not used" counts it).
2643
+ feedVersionsToIndex({
2644
+ control: () => ctx.syncControl?.current?.(),
2645
+ designRel: ctx.paths.designRel,
2646
+ index: projectIndex,
2647
+ on: (e, fn) => ctx.bus.on(e, fn),
2648
+ });
2649
+ // V2-2.17 — the thumbnail service (contract V2-1.17 §5.8): renders only on the read-only capture
2650
+ // origin (R1), pictures in the machine cache next to the index, served below on the main origin
2651
+ // only (R4). Cells render nothing (R7). At boot only the missing/stale covers render (below).
2652
+ const thumbs = createThumbService({
2653
+ pid: pidOf(ctx.paths.repoRoot),
2654
+ designRoot: ctx.paths.designRoot,
2655
+ index: projectIndex,
2656
+ freshDepsHash: (rel) => {
2657
+ try {
2658
+ return extractCanvas(
2659
+ {
2660
+ designRoot: ctx.paths.designRoot,
2661
+ repoRoot: ctx.paths.repoRoot,
2662
+ groups: ctx.cfg.canvasGroups,
2663
+ defaultDs: null,
2664
+ designSystems: ctx.cfg.designSystems ?? [],
2665
+ },
2666
+ rel
2667
+ ).depsHash;
2668
+ } catch {
2669
+ return null;
2670
+ }
2671
+ },
2672
+ config: () => ({
2673
+ theme: ctx.cfg.themeDefault,
2674
+ tokensCssRel: ctx.cfg.designSystems?.[0]?.tokensCssRel ?? ctx.cfg.tokensCssRel,
2675
+ }),
2676
+ serverOrigin: () => ctx.mainOrigin?.split(' ')[0],
2677
+ captureOrigin: () => ctx.captureOrigin,
2678
+ enabled: !isWorkspaceMode(),
2679
+ exportBusy: () => exportJobs.list().some((j) => j.status === 'running'),
2680
+ readVersion: async (rel, at) => {
2681
+ const repoRel = relative(ctx.paths.repoRoot, join(ctx.paths.designRoot, rel)).replace(
2682
+ /\\/g,
2683
+ '/'
2684
+ );
2685
+ if ('sha' in at) return gitShowFile(ctx.paths.repoRoot, at.sha, repoRel);
2686
+ return (
2687
+ (await ctx.syncControl
2688
+ ?.current?.()
2689
+ ?.acceptedVersion?.(repoRel, at.rev)
2690
+ .catch(() => null)) ?? null
2691
+ );
2692
+ },
2693
+ // S1.11 — the version's own CSS / meta, from the reader the historical build overlays it from.
2694
+ readVersionLane: (rel, lane, at) => {
2695
+ const repoRel = relative(ctx.paths.repoRoot, join(ctx.paths.designRoot, rel)).replace(
2696
+ /\\/g,
2697
+ '/'
2698
+ );
2699
+ return laneAtRef(
2700
+ versionReaders(ctx),
2701
+ repoRel,
2702
+ 'sha' in at ? at.sha : `r${at.rev}`,
2703
+ lane,
2704
+ 'sha' in at ? 'git' : 'accepted'
2705
+ );
2706
+ },
2707
+ onReady: (key) => ctx.bus.emit('thumb-ready', { key }),
2708
+ });
2709
+ // P8 — the index is built: queue background covers for the canvases whose cover is missing or
2710
+ // stale (Home has no renderer, so a project opened before v2 kept grey covers). Nothing to do =
2711
+ // no renderer started. After the first paint has settled; the bun test preload opts out
2712
+ // (MAUDE_NO_BOOT_COVERS=1) so a test server does not start a Chromium of its own.
2713
+ if (process.env.MAUDE_NO_BOOT_COVERS !== '1')
2714
+ void thumbs.bootCovers({ delayMs: BOOT_COVERS_DELAY_MS }).catch(() => {});
2715
+ // S8.20 — search in pictures (describe/, contract V2-1.17 §5.9): opt-in per person on this Mac, never in a cell (A5).
2716
+ // The picture that goes is the Assets tile the renderer made; the describer is S12.13's asset-describer agent (describe/claude.ts via envDescriber; the stub under MAUDE_DESCRIBE_STUB=1).
2717
+ describeSvc = isWorkspaceMode()
2718
+ ? null
2719
+ : createDescribeService({
2720
+ designRoot: ctx.paths.designRoot,
2721
+ pid: pidOf(ctx.paths.repoRoot),
2722
+ rows: () => projectIndex.assetsAnswer().assets,
2723
+ describer: envDescriber,
2724
+ prepare: async (row) => {
2725
+ const t = await thumbs.assetTile(row.rel, 'card');
2726
+ return t.status === 'ready' ? thumbs.read(t.key) : null;
2727
+ },
2728
+ auto: true,
2729
+ });
2730
+ projectIndex.on('changed', () => describeSvc?.poke());
2731
+ ctx.bus.on('thumb-ready', () => describeSvc?.poke());
2732
+ describeSvc?.poke();
2733
+
2734
+ /** What a read-only session may still write: the module allowlist plus what
2735
+ * the lane tables declare (`readOnly: 'allowed'`). */
1650
2736
  const readOnlyAllowed = {
1651
- exact: READ_ONLY_ALLOWED_WRITES as ReadonlySet<string>,
1652
- patterns: READ_ONLY_ALLOWED_WRITE_PATTERNS as readonly RegExp[],
2737
+ exact: new Set<string>([...READ_ONLY_ALLOWED_WRITES, ...laneRoutes.readOnlyAllowed.exact]),
2738
+ patterns: [...READ_ONLY_ALLOWED_WRITE_PATTERNS, ...laneRoutes.readOnlyAllowed.patterns],
1653
2739
  };
1654
2740
 
1655
- const routes = {
2741
+ // The client's config (see the '/_config' route below for the gate in front of it).
2742
+ // S9.10 (V2-1.16 L8) — a canvas-only session gets no canvas groups, only the DS its
2743
+ // canvases render with, no new-canvas dir and no hub link (`filterConfig`); U7 identity.
2744
+ const configJson = (req: Request, body: Record<string, unknown>) =>
2745
+ Response.json(filterConfig(body, visOf(req), ctx.cfg.designSystems ?? []));
2746
+ const configResponse = (req: Request) =>
2747
+ configJson(req, {
2748
+ ...ctx.cfg,
2749
+ canvasOrigin: ctx.canvasOrigin,
2750
+ // V2-1.12 §5.6 — readOnly is the role OR the format gate
2751
+ // (projectReadOnly covers both); the client shows WHY, and
2752
+ // `formatGate` drives the banner. Named one by one: the client
2753
+ // projection names every computed field (config-projection.test.ts).
2754
+ readOnly: projectReadOnly(req),
2755
+ formatVersion: projectFormat(ctx).value,
2756
+ formatGate: gateNow(),
2757
+ readOnlyReason: roleReadOnly(req) ? 'role' : gateNow() ? 'format' : null,
2758
+ // rc.1 finding 1 (Michal A) — 'missing': the role floor came from a hub record without a role (a 1.x
2759
+ // `link --token`), so the format callout offers Sign in, not Ask the owner. This Mac's own record only.
2760
+ roleSource:
2761
+ roleReadOnly(req) && !isWorkspaceMode() && ctx.cfg.linkedHub?.url
2762
+ ? linkRoleSource(ctx.cfg.linkedHub.url)
2763
+ : null,
2764
+ // p8-update-to-accepted — how this project saves (DDR-241) as its sync last heard from the
2765
+ // hub: 'accepted' | 'legacy'; null when nothing syncs (solo). A hint for the Update project
2766
+ // offer only — the migrator's dry run asks the hub itself before anything is offered.
2767
+ saveMode: saveModeOf(ctx.syncControl?.current?.()),
2768
+ // S9.22b — may this session comment (reply, resolve) on the project? The SERVER's answer from
2769
+ // the session's access, never the client's: Can comment and up. A canvas-only session answers
2770
+ // like a missing one (project-level `comment` needs a project role); the op door still judges
2771
+ // every op on its own canvas (hidden ≠ refused). The client turns it into the canvas URL's `cm=1`.
2772
+ canComment: accessOf(req).can('comment', null),
2773
+ // p8-e2e-rolefix — WHO this session is, as the server resolved it: the project role (null = a
2774
+ // canvas-only session) and its canvas grants. The shell's access word ("Can view" / "Can comment")
2775
+ // and the mode switch's caps read it; before it a desktop sent no role at all (only a cloud tab's
2776
+ // `cloud.role`), so every read-only desktop session — a Can view invitee included — read "Can
2777
+ // comment". The session's own claim, main origin only; the gates above stay the lock.
2778
+ access: accessView(accessOf(req)),
2779
+ // gate-b-c4 — the key this session's shell mints each frame's capability with
2780
+ // (client/frame-cap.js). Only while a canvas origin exists (the split on): with it off the
2781
+ // canvas runs on this origin and there is no frame to scope. MAIN ORIGIN ONLY — `/_config`
2782
+ // is in neither canvas allowlist, so canvas code never sees it.
2783
+ ...(ctx.canvasOrigin && frameKeyOf(req)
2784
+ ? { frameKey: (frameKeyOf(req) as Buffer).toString('base64url') }
2785
+ : {}),
2786
+ // DDR-247 — the apps allowed to frame this studio for `?embed=1`. The
2787
+ // embed view posts its status ONLY to a parent on this list, never to
2788
+ // '*'. Public already: the same origins ride in the page's CSP header.
2789
+ ...(ctx.embedOrigins?.length ? { embedOrigins: ctx.embedOrigins } : {}),
2790
+ // WHICH RELEASE THIS IS. `/_config` reaches the browser in cloud mode,
2791
+ // so the bar for adding a field here is "would I publish it" — and a
2792
+ // version is the git tag, which is public. Nothing else rides along.
2793
+ //
2794
+ // Resolved through `resolveMaudeVersion`, the same function the What's
2795
+ // New feed uses: one answer, so the chip in the status bar and the feed
2796
+ // can never name different versions.
2797
+ version: resolveMaudeVersion(),
2798
+ // feature-cloud-export-render-workers — which export lane this server
2799
+ // holds (`local` | `remote` | `none`). The client gates the export
2800
+ // dialogs on it so a cell without a render service says WHY a format
2801
+ // is unavailable instead of firing a request the proxy 404s.
2802
+ exportLane: resolveRenderLane(),
2803
+ // V2-3.4 — WHICH account profile this server runs as (shell/profile.ts): set per tab by
2804
+ // the desktop shell, validated + sanitized; absent env ⇒ { id: 'default' }.
2805
+ profile: resolveProfile(),
2806
+ // Cloud Phase 27 (DDR-209) — the capability that opens the cookieless
2807
+ // canvas origin, minted per session by the proxy. Absent on a desktop,
2808
+ // where the canvas origin is loopback and needs none. `canvasUrl()`
2809
+ // appends it exactly the way it already appends `readOnly`, which is
2810
+ // what keeps this a FLAG on the shared client rather than a fork of it.
2811
+ ...(req.headers.get('x-maude-canvas-token')
2812
+ ? { canvasToken: req.headers.get('x-maude-canvas-token') }
2813
+ : {}),
2814
+ // Cloud Phase 27 C2/C4 — the ONE cloud-only input the shared client
2815
+ // takes. Its presence says "you are in a browser tab, on somebody
2816
+ // else's machine", which is what lets the client state the agent's
2817
+ // absence and offer a way back to the dashboard. A flag, not a fork:
2818
+ // every other difference between the three shells stays zero.
2819
+ ...(isWorkspaceMode()
2820
+ ? {
2821
+ cloud: {
2822
+ // PRESENCE IS THE SWITCH — never a default. `HUB_DASHBOARD_URL`
2823
+ // is written only by the managed fleet (cli/lib/cell-plan.mjs);
2824
+ // a self-hosted `maude hub workspace` never sets it and has no
2825
+ // multi-project dashboard to return to. Defaulting it to the
2826
+ // SaaS put a `← Dashboard` link in every self-hoster's menubar
2827
+ // that walked them off their own deployment onto cloud.maude.sh
2828
+ // — a dead end for an account most of them do not have. Same
2829
+ // rule the hub landing already keeps (server.mjs `isPlatform`)
2830
+ // and the auth pages already keep (browser-auth.mjs): no URL,
2831
+ // no link. Absent, not null, so the client's own check is the
2832
+ // single one — exactly like `canvasToken` two fields down.
2833
+ ...(process.env.HUB_DASHBOARD_URL
2834
+ ? { dashboardUrl: process.env.HUB_DASHBOARD_URL }
2835
+ : {}),
2836
+ // F19 — this project's own dashboard page, when the cell knows its id.
2837
+ ...(projectDashboardUrl() ? { projectUrl: projectDashboardUrl() } : {}),
2838
+ projectName: process.env.MAUDE_PROJECT_NAME ?? ctx.cfg.name ?? null,
2839
+ // WHO the tab is signed in as, and WHAT that makes them —
2840
+ // per REQUEST, from the proxy's injected headers, never from
2841
+ // this process's environment (one cell serves an owner and a
2842
+ // viewer at the same time).
2843
+ //
2844
+ // The owner who could not edit his own project could not see
2845
+ // why: the stamp said VIEW ONLY and nothing on screen said
2846
+ // which account that verdict was about. Naming the account and
2847
+ // the role turns "this is broken" into "I am signed in as the
2848
+ // wrong person", which is a thing someone can act on — and the
2849
+ // sign-out beside it is how they act on it.
2850
+ user: req.headers.get('x-maude-user') || null,
2851
+ role: req.headers.get('x-maude-role') || null,
2852
+ },
2853
+ }
2854
+ : {}),
2855
+ });
2856
+
2857
+ // The LEGACY route literal (V2-2.5): every key here predates the table. A NEW route is a
2858
+ // `routes/<area>.ts` spec (routes/index.ts), not a new key — so work packages never edit the
2859
+ // same switch. Merged with the table's exact paths into `routes` below.
2860
+ const legacyRoutes = {
1656
2861
  '/_health': () =>
1657
2862
  Response.json({
1658
2863
  ok: true,
@@ -1671,6 +2876,10 @@ export function createHttp(
1671
2876
  // server filesystem path is not something it should learn. The
1672
2877
  // supervisor hashes its own expected root and compares.
1673
2878
  rootId: rootIdentity(ctx.paths.repoRoot),
2879
+ // V2-1.11 §5.6 — the app↔plugin↔CLI handshake: the design plugin's session-start hook
2880
+ // compares its bundled actions.manifest.json with these. Public data (action ids, tiers).
2881
+ manifestVersion: actionsManifestVersion(),
2882
+ version: resolveMaudeVersion(),
1674
2883
  pid: process.pid,
1675
2884
  // Cloud Phase 26 Stage 4 — the build sandbox's own counters, so the
1676
2885
  // €3/cell model finally has figures instead of a prediction. Counts and
@@ -1684,7 +2893,11 @@ export function createHttp(
1684
2893
  // it discloses nothing across a tenant boundary. Inventing a privileged
1685
2894
  // route would have meant inventing an auth path for the supervisor's
1686
2895
  // loopback probe, for data the tenant already has.
1687
- render: buildStats(),
2896
+ //
2897
+ // Michal 2026-10-21 (S8.5b M2): `renderSeconds` (+ `renderJobs`, `renderSecondsSince`) is the seconds this tenant's export jobs
2898
+ // spent rendering on the cloud lane since the studio booted, with the boot time beside it
2899
+ // so a restart reads as a reset. Additive. Counts and durations only.
2900
+ render: { ...buildStats(), ...renderSecondsStats() },
1688
2901
  }),
1689
2902
 
1690
2903
  '/_active': () => Response.json(inspect().state),
@@ -1703,7 +2916,9 @@ export function createHttp(
1703
2916
  if (!sameOriginRead(req)) return new Response('cross-origin rejected', { status: 403 });
1704
2917
  if (!isTrustedRequestHost(req))
1705
2918
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
1706
- return Response.json(await probeAcpAvailabilityAuthed(), {
2919
+ const availability = await probeAcpAvailabilityAuthed();
2920
+ aiConnectedFact.note(availability.available); // S5.18: the panel's answer is the queue's answer
2921
+ return Response.json(availability, {
1707
2922
  headers: { 'Cache-Control': 'no-store' },
1708
2923
  });
1709
2924
  },
@@ -1869,10 +3084,19 @@ export function createHttp(
1869
3084
 
1870
3085
  // Phase 31 — repo-level chat list + history (for the chat switcher +
1871
3086
  // hydration). MAIN-ORIGIN ONLY. Read-only; ids are sanitized before disk.
1872
- '/_api/acp/chats': () =>
1873
- Response.json(listChats(ctx.paths.designRoot), {
1874
- headers: { 'Cache-Control': 'no-store' },
1875
- }),
3087
+ // S5.7: `?trashed=1` is the trash's own list (S1's Trash panel provider); `?group=canvas`
3088
+ // answers `{ groups: [{ canvas, chats }] }` instead of the flat array. No query = the
3089
+ // flat, newest-first array every existing consumer reads.
3090
+ '/_api/acp/chats': (req: Request) => {
3091
+ const q = new URL(req.url).searchParams;
3092
+ const chats = listChats(ctx.paths.designRoot, { trashed: q.get('trashed') === '1' });
3093
+ return Response.json(
3094
+ q.get('group') === 'canvas' ? { groups: groupChatsByCanvas(chats) } : chats,
3095
+ {
3096
+ headers: { 'Cache-Control': 'no-store' },
3097
+ }
3098
+ );
3099
+ },
1876
3100
  '/_api/acp/chat': async (req: Request) => {
1877
3101
  const id = (new URL(req.url).searchParams.get('id') ?? '')
1878
3102
  .replace(/[^a-z0-9_-]/gi, '')
@@ -1996,7 +3220,9 @@ export function createHttp(
1996
3220
  // Phase 9 Task 8 — offline-mode banner poll fallback. The linked-mode sync
1997
3221
  // runtime writes `_sync.json`; browser tabs also get live pushes over the
1998
3222
  // WS ('sync:status'). Returns `{ linked: false }` in solo mode.
1999
- '/_sync-status': () => {
3223
+ '/_sync-status': (req: Request) => {
3224
+ // S9.11 (V2-1.16 L16) — `project` class: sync trouble names every canvas's slug.
3225
+ if (accessOf(req).canvasOnly) return notInScopeResponse();
2000
3226
  const file = join(ctx.paths.designRoot, '_sync.json');
2001
3227
  if (!existsSync(file)) {
2002
3228
  return Response.json({ linked: false }, { headers: { 'Cache-Control': 'no-store' } });
@@ -2011,7 +3237,9 @@ export function createHttp(
2011
3237
  if (!(Number(status?.updatedAt) >= PROCESS_STARTED_AT)) {
2012
3238
  return Response.json({ linked: false }, { headers: { 'Cache-Control': 'no-store' } });
2013
3239
  }
2014
- return Response.json(status, {
3240
+ // S11.11 — the last Resync, while it runs and for a while after (sync/resync-trace.ts)
3241
+ const resync = resyncTrace.view();
3242
+ return Response.json(resync ? { ...status, resync } : status, {
2015
3243
  headers: { 'Cache-Control': 'no-store' },
2016
3244
  });
2017
3245
  } catch {
@@ -2024,83 +3252,15 @@ export function createHttp(
2024
3252
  // knows before it draws anything. It decides what the UI OFFERS and is
2025
3253
  // never what stops a write — the cell enforces that (Phase 25 C1),
2026
3254
  // whatever a patched client believes.
3255
+ // Phase 4 gate security review (D1 / EH-P4-1): the same double gate as the /_api/* reads. The
3256
+ // config names the project, its hub link and workspace, the canvas origin and port and the
3257
+ // build — recon a DNS-rebound page must not read. The cell vouches with x-maude-role.
2027
3258
  '/_config': (req: Request) =>
2028
- Response.json({
2029
- ...ctx.cfg,
2030
- canvasOrigin: ctx.canvasOrigin,
2031
- // V2-1.12 §5.6 — readOnly is the role OR the format gate
2032
- // (projectReadOnly covers both); the client shows WHY, and
2033
- // `formatGate` drives the banner. Named one by one: the client
2034
- // projection names every computed field (config-projection.test.ts).
2035
- readOnly: projectReadOnly(req),
2036
- formatVersion: projectFormat(ctx).value,
2037
- formatGate: gateNow(),
2038
- readOnlyReason: roleReadOnly(req) ? 'role' : gateNow() ? 'format' : null,
2039
- // DDR-247 — the apps allowed to frame this studio for `?embed=1`. The
2040
- // embed view posts its status ONLY to a parent on this list, never to
2041
- // '*'. Public already: the same origins ride in the page's CSP header.
2042
- ...(ctx.embedOrigins?.length ? { embedOrigins: ctx.embedOrigins } : {}),
2043
- // WHICH RELEASE THIS IS. `/_config` reaches the browser in cloud mode,
2044
- // so the bar for adding a field here is "would I publish it" — and a
2045
- // version is the git tag, which is public. Nothing else rides along.
2046
- //
2047
- // Resolved through `resolveMaudeVersion`, the same function the What's
2048
- // New feed uses: one answer, so the chip in the status bar and the feed
2049
- // can never name different versions.
2050
- version: resolveMaudeVersion(),
2051
- // feature-cloud-export-render-workers — which export lane this server
2052
- // holds (`local` | `remote` | `none`). The client gates the export
2053
- // dialogs on it so a cell without a render service says WHY a format
2054
- // is unavailable instead of firing a request the proxy 404s.
2055
- exportLane: resolveRenderLane(),
2056
- // Cloud Phase 27 (DDR-209) — the capability that opens the cookieless
2057
- // canvas origin, minted per session by the proxy. Absent on a desktop,
2058
- // where the canvas origin is loopback and needs none. `canvasUrl()`
2059
- // appends it exactly the way it already appends `readOnly`, which is
2060
- // what keeps this a FLAG on the shared client rather than a fork of it.
2061
- ...(req.headers.get('x-maude-canvas-token')
2062
- ? { canvasToken: req.headers.get('x-maude-canvas-token') }
2063
- : {}),
2064
- // Cloud Phase 27 C2/C4 — the ONE cloud-only input the shared client
2065
- // takes. Its presence says "you are in a browser tab, on somebody
2066
- // else's machine", which is what lets the client state the agent's
2067
- // absence and offer a way back to the dashboard. A flag, not a fork:
2068
- // every other difference between the three shells stays zero.
2069
- ...(isWorkspaceMode()
2070
- ? {
2071
- cloud: {
2072
- // PRESENCE IS THE SWITCH — never a default. `HUB_DASHBOARD_URL`
2073
- // is written only by the managed fleet (cli/lib/cell-plan.mjs);
2074
- // a self-hosted `maude hub workspace` never sets it and has no
2075
- // multi-project dashboard to return to. Defaulting it to the
2076
- // SaaS put a `← Dashboard` link in every self-hoster's menubar
2077
- // that walked them off their own deployment onto cloud.maude.sh
2078
- // — a dead end for an account most of them do not have. Same
2079
- // rule the hub landing already keeps (server.mjs `isPlatform`)
2080
- // and the auth pages already keep (browser-auth.mjs): no URL,
2081
- // no link. Absent, not null, so the client's own check is the
2082
- // single one — exactly like `canvasToken` two fields down.
2083
- ...(process.env.HUB_DASHBOARD_URL
2084
- ? { dashboardUrl: process.env.HUB_DASHBOARD_URL }
2085
- : {}),
2086
- projectName: process.env.MAUDE_PROJECT_NAME ?? ctx.cfg.name ?? null,
2087
- // WHO the tab is signed in as, and WHAT that makes them —
2088
- // per REQUEST, from the proxy's injected headers, never from
2089
- // this process's environment (one cell serves an owner and a
2090
- // viewer at the same time).
2091
- //
2092
- // The owner who could not edit his own project could not see
2093
- // why: the stamp said VIEW ONLY and nothing on screen said
2094
- // which account that verdict was about. Naming the account and
2095
- // the role turns "this is broken" into "I am signed in as the
2096
- // wrong person", which is a thing someone can act on — and the
2097
- // sign-out beside it is how they act on it.
2098
- user: req.headers.get('x-maude-user') || null,
2099
- role: req.headers.get('x-maude-role') || null,
2100
- },
2101
- }
2102
- : {}),
2103
- }),
3259
+ !sameOriginRead(req)
3260
+ ? new Response('cross-origin rejected', { status: 403 })
3261
+ : !isTrustedRequestHost(req)
3262
+ ? new Response('local request required (DNS-rebinding guard)', { status: 403 })
3263
+ : configResponse(req),
2104
3264
 
2105
3265
  // What's New feed (DDR-A) — read-only product-update list surfaced in the
2106
3266
  // Maude UI chrome. Main-origin only by omission from the canvas-origin
@@ -2113,6 +3273,69 @@ export function createHttp(
2113
3273
  // the scrubber runs here, server-side): MAIN-ORIGIN ONLY — absent from
2114
3274
  // CANVAS_SAFE_API + startCanvasServer routes — plus the same double gate as
2115
3275
  // /_api/acp/status (a drive-by page must not read logs via DNS rebinding).
3276
+ // V2-2.9 (T23) — local diagnostics: every source's status + recent lines (JSON) and the
3277
+ // "Copy diagnostic report" text. PRIVILEGED like /_api/debug-bundle: main-origin only (absent
3278
+ // from CANVAS_SAFE_API + startCanvasServer routes, DDR-088) + the DNS-rebinding guard.
3279
+ '/_api/diagnostics': (req: Request) => {
3280
+ if (!sameOriginRead(req)) return new Response('cross-origin rejected', { status: 403 });
3281
+ if (!isTrustedRequestHost(req))
3282
+ return new Response('local request required (DNS-rebinding guard)', { status: 403 });
3283
+ // V2-4.7b — Diagnostics › Advanced › Project folder (a copy-value row). This Mac's own path
3284
+ // (it names the user), so it rides here behind the rebinding guard and never on /_config
3285
+ // (unguarded); a cloud tab (somebody else's machine) never gets it (Phase 4 gate review D1).
3286
+ return Response.json(
3287
+ { ...diagnostics(), ...(!isWorkspaceMode() ? { projectFolder: ctx.paths.repoRoot } : {}) },
3288
+ { headers: { 'Cache-Control': 'no-store' } }
3289
+ );
3290
+ },
3291
+ '/_api/diagnostics/report': (req: Request) => {
3292
+ if (!sameOriginRead(req)) return new Response('cross-origin rejected', { status: 403 });
3293
+ if (!isTrustedRequestHost(req))
3294
+ return new Response('local request required (DNS-rebinding guard)', { status: 403 });
3295
+ const text = report({
3296
+ maude: resolveMaudeVersion(),
3297
+ platform: `${process.platform}-${process.arch}`,
3298
+ project: ctx.cfg.name ?? '',
3299
+ });
3300
+ return new Response(text, {
3301
+ headers: { 'Content-Type': 'text/plain; charset=utf-8', 'Cache-Control': 'no-store' },
3302
+ });
3303
+ },
3304
+
3305
+ // V2-2.17 — the project index: the snapshot (`?since=<seq>` answers {unchanged} when
3306
+ // current) or a search (`?q=`). Main origin only (absent from both canvas allowlists,
3307
+ // DDR-088) + the DNS-rebinding guard; cells will filter by V2-1.16 `sees` (S9).
3308
+ '/_api/index': (req: Request) => {
3309
+ if (!sameOriginRead(req)) return new Response('cross-origin rejected', { status: 403 });
3310
+ if (!isTrustedRequestHost(req))
3311
+ return new Response('local request required (DNS-rebinding guard)', { status: 403 });
3312
+ const url = new URL(req.url);
3313
+ const q = url.searchParams.get('q');
3314
+ // S9.10 (V2-1.16 L8/L9) — a canvas-only session's index is its canvases only: counts,
3315
+ // stamp and seq derived from them (U5). Identity for a project role (U7).
3316
+ const vis = visOf(req);
3317
+ // S8.12 — the Assets tab's read: rows, usage, the history scan state (index/assets-response.ts)
3318
+ if (url.searchParams.get('part') === 'assets') return assetsResponse(projectIndex, vis);
3319
+ if (q !== null)
3320
+ return Response.json(filterIndexSearch(projectIndex.search(q, { limit: 200 }), vis), {
3321
+ headers: { 'Cache-Control': 'no-store' },
3322
+ });
3323
+ const snap = filterIndexSnapshot(projectIndex.snapshot(), vis);
3324
+ const since = Number(url.searchParams.get('since'));
3325
+ if (Number.isFinite(since) && since > 0 && since === snap.writer.seq)
3326
+ return Response.json({ unchanged: true, seq: snap.writer.seq });
3327
+ return Response.json(snap, { headers: { 'Cache-Control': 'no-store' } });
3328
+ },
3329
+
3330
+ // V2-2.17 — raise on-screen picture keys to `visible` (§5.3). Main origin only; answers
3331
+ // nothing about any key (L14). GET /_api/thumb/<key> is dynamic: see handleFallthrough.
3332
+ '/_api/thumbs/want': (req: Request) => {
3333
+ if (!sameOriginWrite(req)) return new Response('cross-origin rejected', { status: 403 });
3334
+ if (!isTrustedRequestHost(req))
3335
+ return new Response('local request required (DNS-rebinding guard)', { status: 403 });
3336
+ return wantResponse(thumbs, req);
3337
+ },
3338
+
2116
3339
  '/_api/debug-bundle': (req: Request) => {
2117
3340
  if (!sameOriginRead(req)) return new Response('cross-origin rejected', { status: 403 });
2118
3341
  if (!isTrustedRequestHost(req))
@@ -2337,8 +3560,33 @@ export function createHttp(
2337
3560
  // the api layer — DDR-115). The layout lane mutates the versioned
2338
3561
  // `.meta.json`, so a read-only session is refused here, in-handler,
2339
3562
  // where the two lanes are distinguishable.
2340
- if (projectReadOnly(req) && 'layout' in body.patch) {
2341
- return readOnlyRefusalFor(req);
3563
+ //
3564
+ // S9.9 — the layout lane needs `edit` ON THE TARGET canvas (a canvas grant
3565
+ // counts, V2-1.7 G1), and a session without `edit` there may send ONLY the
3566
+ // per-user lanes: any other key is refused rather than ignored, so a
3567
+ // planted or stale client can never widen what this route writes.
3568
+ const target = toDesignRel(body.file, designRel);
3569
+ const access = accessOf(req);
3570
+ const editsTarget =
3571
+ !gateNow() &&
3572
+ (access.can('edit', null) || (target !== null && access.can('edit', target)));
3573
+ if (!editsTarget) {
3574
+ const keys = Object.keys(body.patch);
3575
+ if (keys.includes('layout') || keys.some((k) => !CANVAS_META_SESSION_LANES.has(k)))
3576
+ return readOnlyRefusalFor(req);
3577
+ }
3578
+ // S2.9b — the `annotations` rider: the move and the annotations riding with it as ONE
3579
+ // action. Needs `annotate` on the target as well as the layout lane's `edit`, and holds
3580
+ // the rider to the move delta on every origin (routes/canvas-meta-rider.ts).
3581
+ const rider = (body as { annotations?: unknown }).annotations;
3582
+ if (rider !== undefined) {
3583
+ const annotates =
3584
+ access.can('annotate', null) || (target !== null && access.can('annotate', target));
3585
+ if (!editsTarget || !annotates) return readOnlyRefusalFor(req);
3586
+ return riderPatch(
3587
+ { api, control: () => ctx.syncControl?.current?.() ?? null },
3588
+ { file: body.file, patch: body.patch, annotations: rider }
3589
+ );
2342
3590
  }
2343
3591
  const next = await api.patchCanvasMeta(body.file, body.patch);
2344
3592
  if (!next) return new Response('Not found or rejected', { status: 404 });
@@ -2361,11 +3609,27 @@ export function createHttp(
2361
3609
  // rebinding on every method.
2362
3610
  if (!isTrustedRequestHost(req))
2363
3611
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
2364
- const asset = new URL(req.url).searchParams.get('asset');
3612
+ const q = new URL(req.url).searchParams;
3613
+ const asset = q.get('asset');
3614
+ // S8.15 — `?edit=<edit8>` reads one use's edit; `?perUse=1` writes one (the server names it)
3615
+ const editName = q.get('edit');
3616
+ if (editName !== null && !EDIT8_RE.test(editName))
3617
+ return new Response('invalid edit name', { status: 400 });
2365
3618
  if (req.method === 'GET') {
2366
- const edit = await photoStore.getPhotoEdit(asset);
3619
+ const edit = editName
3620
+ ? await photoStore.getPerUseEdit(asset, editName)
3621
+ : await photoStore.getPhotoEdit(asset);
2367
3622
  return Response.json(edit ?? {}, { headers: { 'Cache-Control': 'no-store' } });
2368
3623
  }
3624
+ if ((req.method === 'PUT' || req.method === 'POST') && q.get('perUse') === '1') {
3625
+ const body = await readJson<unknown>(req, PHOTO_EDIT_MAX_BYTES + 1024);
3626
+ if (body == null) return new Response('body required', { status: 400 });
3627
+ const r = await photoStore.savePerUseEdit(asset, body);
3628
+ return Response.json(r.ok ? { ok: true, path: r.path, edit: r.edit8, value: r.edit } : r, {
3629
+ status: r.ok ? 200 : r.status,
3630
+ headers: { 'Cache-Control': 'no-store' },
3631
+ });
3632
+ }
2369
3633
  if (req.method === 'PUT' || req.method === 'POST') {
2370
3634
  const body = await readJson<unknown>(req, PHOTO_EDIT_MAX_BYTES + 1024);
2371
3635
  if (body == null) return new Response('body required', { status: 400 });
@@ -2431,33 +3695,9 @@ export function createHttp(
2431
3695
  return new Response('Method not allowed', { status: 405 });
2432
3696
  },
2433
3697
 
2434
- '/_api/canvas-source': async (req: Request) => {
2435
- // DDR-148 — read-only raw .tsx source for the Timeline panel's sequence/
2436
- // keyframe parser. GET ?file=<canvas rel or slug> → { source }.
2437
- // MAIN-ORIGIN ONLY: intentionally absent from CANVAS_SAFE_API +
2438
- // startCanvasServer's routes (dual-allowlist, DDR-054) — the untrusted
2439
- // canvas iframe must never read arbitrary project source. Containment via
2440
- // api.loadCanvasSource → resolveCanvasAbs (stays under designRoot).
2441
- if (req.method !== 'GET') return new Response('Method not allowed', { status: 405 });
2442
- // DNS-rebinding guard — a GET read of project source is CORS-readable once
2443
- // a rebound page shares this origin; the dev-server always binds 127.0.0.1,
2444
- // so a real browser (Host: localhost:<port>) passes and only a rebound
2445
- // foreign hostname 403s. (No sameOriginWrite here — GET.)
2446
- if (!isTrustedRequestHost(req))
2447
- return new Response('local request required (DNS-rebinding guard)', { status: 403 });
2448
- const file = new URL(req.url).searchParams.get('file');
2449
- const r = await api.loadCanvasSource(file);
2450
- if (!r.ok) {
2451
- return Response.json(
2452
- { ok: false, error: r.error },
2453
- { status: r.status, headers: { 'Cache-Control': 'no-store' } }
2454
- );
2455
- }
2456
- return Response.json(
2457
- { ok: true, source: r.source },
2458
- { headers: { 'Cache-Control': 'no-store' } }
2459
- );
2460
- },
3698
+ // '/_api/canvas-source' (DDR-148's Timeline read) moved to the route table in S11.6:
3699
+ // routes/canvas-source.ts — same `?file=` answer, now with the code view's fields and its
3700
+ // access rule (`export` on the canvas: Can view refused, a canvas-only session its grants).
2461
3701
 
2462
3702
  '/_api/git-committers': async (req: Request) => {
2463
3703
  // Phase 6 — feed for the @mention autocomplete in composer + reply box.
@@ -2484,96 +3724,14 @@ export function createHttp(
2484
3724
  if (isWorkspaceMode() && vouched) {
2485
3725
  return Response.json({ name: vouched }, { headers: { 'Cache-Control': 'no-store' } });
2486
3726
  }
2487
- const name = await api.gitCurrentUser();
3727
+ // The name a new comment is stamped with (git user, else this Mac's account): the Comments panel's
3728
+ // Mine filter, the pin initials and presence all compare against it, so it must be ONE identity.
3729
+ const name = localAuthor(await api.gitCurrentUser());
2488
3730
  return Response.json({ name }, { headers: { 'Cache-Control': 'no-store' } });
2489
3731
  },
2490
3732
 
2491
- '/_api/ai': async (req: Request) => {
2492
- // Phase 8 Task 4 — read-only snapshot of the current AI activity map.
2493
- // GET → { entries: [{ file, author, startedAt, lastHeartbeat }, …] }
2494
- // Clients use this on mount to backfill the banner state without
2495
- // waiting for the next bus event.
2496
- if (req.method !== 'GET') return new Response('Method not allowed', { status: 405 });
2497
- return Response.json({ entries: ai.list() }, { headers: { 'Cache-Control': 'no-store' } });
2498
- },
2499
-
2500
- '/_api/ai/start': async (req: Request) => {
2501
- // Phase 8 Task 4 — `/design:edit` (or any external slash command driving
2502
- // Claude work) POSTs here when work begins. body = { file, author }.
2503
- // Replaces any prior entry for the file.
2504
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
2505
- // CSRF guard: phase-30 bridges ai-activity onto room awareness, which
2506
- // crosses the hub — a forged cross-origin POST would inject a fake
2507
- // "<x> is editing <file>" presence to every connected peer. The loopback
2508
- // slash-command driver omits Origin (→ allowed); a browser drive-by can't.
2509
- if (!sameOriginWrite(req))
2510
- return new Response('cross-origin write rejected', { status: 403 });
2511
- if (!isTrustedRequestHost(req))
2512
- return new Response('local request required (DNS-rebinding guard)', { status: 403 });
2513
- const body = await readJson<{ file?: string; author?: string }>(req);
2514
- if (!body || typeof body.file !== 'string' || !body.file.trim()) {
2515
- return new Response('body.file required', { status: 400 });
2516
- }
2517
- const author =
2518
- typeof body.author === 'string' && body.author.trim()
2519
- ? body.author.trim().slice(0, 120)
2520
- : 'Claude';
2521
- const entry = ai.start(body.file.trim(), author);
2522
- // T16 — the edit is ONE project action: what the agent writes until
2523
- // /end is published together (or held, if it fails).
2524
- const name =
2525
- body.file
2526
- .trim()
2527
- .split('/')
2528
- .pop()
2529
- ?.replace(/\.(tsx|html)$/i, '') ?? 'canvas';
2530
- ctx.syncControl
2531
- ?.current?.()
2532
- ?.beginAiAction?.(`edit:${body.file.trim()}`, `${author} edited ${name}`);
2533
- return Response.json(entry, { headers: { 'Cache-Control': 'no-store' } });
2534
- },
2535
-
2536
- '/_api/ai/heartbeat': async (req: Request) => {
2537
- // Refresh the lastHeartbeat. Returns 404 if no entry — slash command
2538
- // can treat that as "the server bounced; re-issue /start".
2539
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
2540
- if (!sameOriginWrite(req))
2541
- return new Response('cross-origin write rejected', { status: 403 });
2542
- if (!isTrustedRequestHost(req))
2543
- return new Response('local request required (DNS-rebinding guard)', { status: 403 });
2544
- const body = await readJson<{ file?: string }>(req);
2545
- if (!body || typeof body.file !== 'string' || !body.file.trim()) {
2546
- return new Response('body.file required', { status: 400 });
2547
- }
2548
- const entry = ai.heartbeat(body.file.trim());
2549
- if (!entry) return new Response('no active entry', { status: 404 });
2550
- return Response.json(entry, { headers: { 'Cache-Control': 'no-store' } });
2551
- },
2552
-
2553
- '/_api/ai/end': async (req: Request) => {
2554
- // Explicit completion (normal or error). Banner clears immediately.
2555
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
2556
- if (!sameOriginWrite(req))
2557
- return new Response('cross-origin write rejected', { status: 403 });
2558
- if (!isTrustedRequestHost(req))
2559
- return new Response('local request required (DNS-rebinding guard)', { status: 403 });
2560
- const body = await readJson<{ file?: string; outcome?: string }>(req);
2561
- if (!body || typeof body.file !== 'string' || !body.file.trim()) {
2562
- return new Response('body.file required', { status: 400 });
2563
- }
2564
- // T16 — close the action BEFORE the banner clears: `done` publishes
2565
- // what the agent wrote as one action, `failed` keeps it unpublished for
2566
- // the person's decision. (No outcome = done, the pre-T16 contract.)
2567
- const action = await ctx.syncControl
2568
- ?.current?.()
2569
- ?.endAiAction?.(`edit:${body.file.trim()}`, body.outcome === 'failed' ? 'failed' : 'done')
2570
- .catch(() => null);
2571
- const cleared = ai.end(body.file.trim());
2572
- return Response.json(
2573
- { cleared, ...(action ? { action } : {}) },
2574
- { status: cleared ? 200 : 404, headers: { 'Cache-Control': 'no-store' } }
2575
- );
2576
- },
3733
+ // S5.3 — `/_api/ai` (GET, canvas-safe) and `/_api/ai/start|heartbeat|end` moved to
3734
+ // routes/ai.ts, on the run registry (the banner is derived from it).
2577
3735
 
2578
3736
  '/_api/sync/offline': async (req: Request) => {
2579
3737
  // T19 — "Download everything for offline": every file of the project
@@ -2611,6 +3769,22 @@ export function createHttp(
2611
3769
  if (!sameOriginWrite(req))
2612
3770
  return new Response('cross-origin write rejected', { status: 403 });
2613
3771
  const body = await readJson<{ file?: string; choice?: string }>(req);
3772
+ // S11.12 — Keep both: theirs becomes the canvas, mine a sibling "<name> this Mac" (sync/keep-both.ts).
3773
+ if (body?.file && body.choice === 'keep-both') {
3774
+ const kb = await keepBothConflict(body.file);
3775
+ if (kb.status === 'none')
3776
+ return Response.json(
3777
+ { ok: false, error: 'No conflict on that canvas.' },
3778
+ { status: 404 }
3779
+ );
3780
+ return Response.json(
3781
+ { ok: kb.status === 'kept-both', ...kb },
3782
+ {
3783
+ status: kb.status === 'kept-both' ? 200 : 409,
3784
+ headers: { 'Cache-Control': 'no-store' },
3785
+ }
3786
+ );
3787
+ }
2614
3788
  const choice = body?.choice === 'mine' ? 'mine' : body?.choice === 'theirs' ? 'theirs' : null;
2615
3789
  if (!body?.file || !choice)
2616
3790
  return Response.json({ ok: false, error: 'file and choice required' }, { status: 400 });
@@ -2630,20 +3804,37 @@ export function createHttp(
2630
3804
  return new Response('cross-origin write rejected', { status: 403 });
2631
3805
  if (!isTrustedRequestHost(req))
2632
3806
  return new Response('local request required', { status: 403 });
2633
- const body = await readJson<{ choice?: string }>(req);
3807
+ const body = await readJson<{ choice?: string; runId?: unknown }>(req);
2634
3808
  const choice =
2635
3809
  body?.choice === 'discard' ? 'discard' : body?.choice === 'publish' ? 'publish' : null;
3810
+ // S5.5b — the held card keeps or undoes ONE run; no id = every held run (v1).
3811
+ const runId =
3812
+ typeof body?.runId === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(body.runId)
3813
+ ? body.runId
3814
+ : undefined;
3815
+ if (body?.runId !== undefined && !runId)
3816
+ return Response.json({ ok: false, error: 'runId is a run id' }, { status: 400 });
2636
3817
  if (!choice)
2637
3818
  return Response.json(
2638
3819
  { ok: false, error: 'choice must be publish or discard' },
2639
3820
  { status: 400 }
2640
3821
  );
2641
- const r = await ctx.syncControl?.current?.()?.resolveAiAction?.(choice);
3822
+ const r = await ctx.syncControl?.current?.()?.resolveAiAction?.(choice, runId);
2642
3823
  if (!r)
2643
3824
  return Response.json(
2644
3825
  { ok: false, error: 'There is no unfinished AI edit.' },
2645
3826
  { status: 409 }
2646
3827
  );
3828
+ if (r.status === 'accepted' && r.actionId) {
3829
+ void announceAction(
3830
+ {
3831
+ control: () => ctx.syncControl?.current?.() ?? null,
3832
+ emit: (e, p) => ctx.bus.emit(e, p),
3833
+ },
3834
+ r.actionId,
3835
+ r.touched ?? {}
3836
+ ).catch(() => {});
3837
+ }
2647
3838
  return Response.json(
2648
3839
  { ok: r.status !== 'rejected', ...r },
2649
3840
  { headers: { 'Cache-Control': 'no-store' } }
@@ -2706,37 +3897,9 @@ export function createHttp(
2706
3897
  return new Response('Method not allowed', { status: 405 });
2707
3898
  },
2708
3899
 
2709
- '/_api/annotations/ops': async (req: Request) => {
2710
- // DDR-242 §4 — the canvas write path: an op batch applied under the one
2711
- // merge rule. Canvas-origin reachable (inert collab data, DDR-054) — every
2712
- // op is validated element-by-element and the board stays capped.
2713
- // POST body { file, actionId, ops: Op[] } → 200 { ok, changed, rejected[] }
2714
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
2715
- const body = await readJson<{ file?: unknown; actionId?: unknown; ops?: unknown }>(
2716
- req,
2717
- MAX_ANNOTATIONS_BYTES + 2048
2718
- );
2719
- if (!body || typeof body.file !== 'string' || !body.file) {
2720
- return new Response('body must include { file, actionId, ops }', { status: 400 });
2721
- }
2722
- if (body.actionId !== undefined && !validAnnotationWriteId(body.actionId)) {
2723
- return new Response('invalid actionId', { status: 400 });
2724
- }
2725
- if (!Array.isArray(body.ops))
2726
- return new Response('body.ops must be an array', { status: 400 });
2727
- // Bounded to what a whole board can need (select-all + delete on a full
2728
- // board) and REFUSED past it — never truncated, which would half-apply a
2729
- // gesture. Batch cost is linear in the ops (ops.ts indexes).
2730
- if (body.ops.length > MAX_ELEMENTS) {
2731
- return new Response('too many ops in one batch', { status: 413 });
2732
- }
2733
- const { ops } = parseAnnotationOps(body.ops, MAX_ELEMENTS);
2734
- const r = await api.applyAnnotationOps(body.file, ops, body.actionId as string | undefined);
2735
- return Response.json(r, {
2736
- status: r.ok ? 200 : r.unreadable ? 409 : 413,
2737
- headers: { 'Cache-Control': 'no-store' },
2738
- });
2739
- },
3900
+ // T-S4.5b — the handler lives in annotationOps (below) so the canvas listener mounts its
3901
+ // own variant (canvasRoutes): a `run:<id>` tag is main-origin only.
3902
+ '/_api/annotations/ops': (req: Request) => annotationOps(req, 'main'),
2740
3903
 
2741
3904
  '/_api/canvas': async (req: Request) => {
2742
3905
  // Phase 22 — create + soft-delete a canvas from the browser file tree.
@@ -2759,8 +3922,34 @@ export function createHttp(
2759
3922
  }
2760
3923
  if (req.method === 'DELETE') {
2761
3924
  const file = new URL(req.url).searchParams.get('file');
2762
- const result = await api.deleteCanvas({ file });
3925
+ // p8-a1-claims (F17) — `maude design trash move` names its chat (X-Maude-Chat): the delete is that
3926
+ // chat's live run's, claimed BEFORE the file leaves, so the run publishes it and its undo restores it.
3927
+ const mine = runForCreate(req, runs);
3928
+ // p8-sec2-lows I1 — the claim must not outlive a delete that did not happen.
3929
+ let release: (() => void) | null = null;
3930
+ if (mine && typeof file === 'string' && /\.tsx$/i.test(file)) {
3931
+ const rel = file.replace(/^\/+/, '');
3932
+ const repoRel = rel.startsWith(`${ctx.paths.designRel}/`)
3933
+ ? rel
3934
+ : `${ctx.paths.designRel}/${rel}`;
3935
+ const control = ctx.syncControl?.current?.();
3936
+ control?.beginAiAction?.(`run:${mine.runId}`, mine.label, {
3937
+ runId: mine.runId,
3938
+ chatId: mine.chatId,
3939
+ claimOnly: true,
3940
+ });
3941
+ control?.claimAiDelete?.(mine.runId, repoRel);
3942
+ release = () => control?.unclaimAiDelete?.(mine.runId, repoRel);
3943
+ }
3944
+ let result: Awaited<ReturnType<typeof api.deleteCanvas>>;
3945
+ try {
3946
+ result = await api.deleteCanvas({ file });
3947
+ } catch (err) {
3948
+ release?.();
3949
+ throw err;
3950
+ }
2763
3951
  if (!result.ok) {
3952
+ release?.();
2764
3953
  return Response.json(
2765
3954
  { ok: false, error: result.error },
2766
3955
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
@@ -2804,6 +3993,18 @@ export function createHttp(
2804
3993
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
2805
3994
  );
2806
3995
  }
3996
+ // S12.16 — the AI chat creates through `maude design curl-local`, which names its chat
3997
+ // (ai/create-claim.ts): the new canvas is that chat's live run's write, not an outside one.
3998
+ const mine = runForCreate(req, runs);
3999
+ if (mine) {
4000
+ claimCreatedCanvas(ctx.syncControl?.current?.(), {
4001
+ runId: mine.runId,
4002
+ chatId: mine.chatId,
4003
+ label: mine.label,
4004
+ repoRel: result.file,
4005
+ abs: join(ctx.paths.repoRoot, result.file),
4006
+ });
4007
+ }
2807
4008
  return Response.json(
2808
4009
  { ok: true, file: result.file, rel: result.rel, slug: result.slug },
2809
4010
  { status: 201, headers: { 'Cache-Control': 'no-store' } }
@@ -2902,7 +4103,12 @@ export function createHttp(
2902
4103
  // security review A3). That probe lands in phase-28 over the server-held
2903
4104
  // keychain token (server-side, never client-supplied), not here.
2904
4105
  const checkRemote = new URL(req.url).searchParams.get('remote') === '1';
2905
- return gitJson(await gitApi.status({ checkRemote }));
4106
+ // S9.12 (V2-1.16 L6) — a canvas-only session's changed files are its visible ones.
4107
+ const status = await gitApi.status({ checkRemote });
4108
+ return gitJson({
4109
+ ...status,
4110
+ json: filterGitStatus(status.json, visOf(req), ctx.paths.designRel),
4111
+ });
2906
4112
  },
2907
4113
 
2908
4114
  '/_api/git/log': async (req: Request) => {
@@ -2911,12 +4117,47 @@ export function createHttp(
2911
4117
  // ONLY (this route is absent from CANVAS_SAFE_API) — the path is
2912
4118
  // containment-validated in the endpoint before it reaches git.
2913
4119
  const u = new URL(req.url).searchParams;
2914
- return gitJson(await gitApi.log(u.get('limit'), u.get('path')));
4120
+ // S9.10 (V2-1.16 L6, U4) — a canvas-only session's log runs over its own canvases'
4121
+ // files only (`?path=` is already scope-checked); subjects are rewritten from them and
4122
+ // the author's e-mail is dropped. A project role's log is unchanged (U7).
4123
+ const logPaths = canvasOnlyLogPaths(visOf(req), u.get('path'), ctx.paths.designRel);
4124
+ if (logPaths === null) return gitJson(await gitApi.log(u.get('limit'), u.get('path')));
4125
+ const limit = Math.min(Math.max(Math.floor(Number(u.get('limit')) || 30), 1), 200);
4126
+ const runs = await Promise.all(
4127
+ logPaths.map(async ({ repoRel, canvas }) => {
4128
+ const r = await gitApi.log(String(limit), repoRel);
4129
+ const entries = (
4130
+ r.json as { entries?: Parameters<typeof mergeCanvasOnlyLog>[0][0]['entries'] }
4131
+ ).entries;
4132
+ return { canvas, entries: r.status === 200 && Array.isArray(entries) ? entries : [] };
4133
+ })
4134
+ );
4135
+ return gitJson({ status: 200, json: { entries: mergeCanvasOnlyLog(runs, limit) } });
2915
4136
  },
2916
4137
 
2917
4138
  '/_api/git/diff': async (req: Request) => {
2918
4139
  if (req.method !== 'GET') return new Response('Method not allowed', { status: 405 });
2919
- return gitJson(await gitApi.diff(new URL(req.url).searchParams.get('sha')));
4140
+ // S9.10 (V2-1.16 L6) — a diff is raw source: the export class. A canvas-only list
4141
+ // holds only the files its canvases own.
4142
+ const vis = visOf(req);
4143
+ if (diffRefusal(vis)) return readOnlyRefusalResponse();
4144
+ const sha = new URL(req.url).searchParams.get('sha');
4145
+ // S9.12b (U1) — a named sha whose own change touched nothing it may diff answers like
4146
+ // a missing one (no sha = the dirty set, which every session may ask for).
4147
+ if (
4148
+ !vis.full &&
4149
+ sha !== null &&
4150
+ sha !== 'HEAD' &&
4151
+ !diffShaVisible(await gitCommitFiles(ctx.paths.repoRoot, sha), vis, ctx.paths.designRel)
4152
+ )
4153
+ return gitJson({ status: 200, json: { entries: [] } });
4154
+ const result = await gitApi.diff(sha);
4155
+ if (vis.full || result.status !== 200) return gitJson(result);
4156
+ const entries = (result.json as { entries?: Array<{ file: string }> }).entries ?? [];
4157
+ return gitJson({
4158
+ ...result,
4159
+ json: { entries: filterGitDiff(entries, vis, ctx.paths.designRel) },
4160
+ });
2920
4161
  },
2921
4162
 
2922
4163
  // ── Phase 29 (E4) — drafts (branches). MAIN-ORIGIN ONLY (absent from
@@ -2925,7 +4166,9 @@ export function createHttp(
2925
4166
  // watcher turns into a Yjs flush + reload (DDR-051) — no logic duplicated here.
2926
4167
  '/_api/git/branches': async (req: Request) => {
2927
4168
  if (req.method !== 'GET') return new Response('Method not allowed', { status: 405 });
2928
- return gitJson(await gitApi.branches());
4169
+ // S9.12 (V2-1.16 L6, U4) — draft names are free text: a canvas-only session lists none.
4170
+ const branches = await gitApi.branches();
4171
+ return gitJson({ ...branches, json: filterGitBranches(branches.json, visOf(req)) });
2929
4172
  },
2930
4173
 
2931
4174
  '/_api/git/branch': async (req: Request) => {
@@ -3057,7 +4300,8 @@ export function createHttp(
3057
4300
  if (!sameOriginRead(req)) return new Response('cross-origin rejected', { status: 403 });
3058
4301
  if (!isTrustedRequestHost(req))
3059
4302
  return new Response('local request required', { status: 403 });
3060
- return gitJson(cloudApi.status());
4303
+ // S9.20b — carries the account's `plan` (cloud /api/home, cached; null when not answered)
4304
+ return gitJson(await cloudApi.statusWithPlan());
3061
4305
  },
3062
4306
  '/_api/cloud/signin/start': async (req: Request) => {
3063
4307
  if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
@@ -3144,108 +4388,21 @@ export function createHttp(
3144
4388
  if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
3145
4389
  if (!sameOriginWrite(req))
3146
4390
  return new Response('cross-origin write rejected', { status: 403 });
3147
- if (!isTrustedRequestHost(req))
3148
- return new Response('local request required', { status: 403 });
3149
- return gitJson(await cloudApi.detach());
3150
- },
3151
-
3152
- // ── Resync (feature-sync-resync-and-out-of-process-sweep) ───────────────
3153
- // MAIN-ORIGIN ONLY: absent from BOTH CANVAS_SAFE_API and startCanvasServer's
3154
- // `routes` map (DDR-088's two-allowlist rule). Canvas content is untrusted
3155
- // (DDR-054) and must not be able to command the desktop to re-push a whole
3156
- // project — a canvas that could would be an amplification primitive against
3157
- // the person's own hub, and a way to spend their rate-limit budget.
3158
- // ACCEPTED REVISIONS — the project's logical history (DDR-241, T27/T28).
3159
- // Main origin only: history names people, restore and undo are writes.
3160
- '/_api/project/history': async (req: Request) => {
3161
- if (req.method !== 'GET') return new Response('Method not allowed', { status: 405 });
3162
- if (!isTrustedRequestHost(req)) return new Response('Forbidden', { status: 403 });
3163
- const url = new URL(req.url);
3164
- const runtime = ctx.syncControl?.current?.();
3165
- const rows = runtime?.acceptedHistory
3166
- ? await runtime
3167
- .acceptedHistory({
3168
- limit: Number(url.searchParams.get('limit') ?? 50) || 50,
3169
- before: Number(url.searchParams.get('before') ?? 0) || null,
3170
- path: url.searchParams.get('path'),
3171
- })
3172
- .catch(() => undefined)
3173
- : null;
3174
- if (rows === undefined) {
3175
- return gitJson({ status: 200, json: { ok: false, reason: 'unreachable' } });
3176
- }
3177
- if (rows === null) return gitJson({ status: 200, json: { ok: false, reason: 'legacy' } });
3178
- return gitJson({ status: 200, json: { ok: true, history: rows } });
3179
- },
3180
- '/_api/project/restore': async (req: Request) => {
3181
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
3182
- if (!sameOriginWrite(req) || !isTrustedRequestHost(req))
3183
- return new Response('Forbidden', { status: 403 });
3184
- const body = await readJson<{ path?: unknown; revision?: unknown }>(req, 4096);
3185
- const revision = Number(body?.revision);
3186
- if (typeof body?.path !== 'string' || !Number.isSafeInteger(revision) || revision < 0) {
3187
- return new Response('body must include { path, revision }', { status: 400 });
3188
- }
3189
- const r = await ctx.syncControl?.current?.()?.acceptedRestore?.(body.path, revision);
3190
- if (!r) return gitJson({ status: 200, json: { ok: false, reason: 'legacy' } });
3191
- return gitJson({
3192
- status: r.status === 'accepted' ? 200 : 409,
3193
- json: { ok: r.status === 'accepted', ...r },
3194
- });
3195
- },
3196
- '/_api/project/undo': async (req: Request) => {
3197
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
3198
- if (!sameOriginWrite(req) || !isTrustedRequestHost(req))
3199
- return new Response('Forbidden', { status: 403 });
3200
- const body = await readJson<{ actionId?: unknown; redo?: unknown }>(req, 4096);
3201
- if (typeof body?.actionId !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(body.actionId)) {
3202
- return new Response('body must include { actionId }', { status: 400 });
3203
- }
3204
- const r = await ctx.syncControl
3205
- ?.current?.()
3206
- ?.acceptedUndo?.(body.actionId, body.redo === true);
3207
- if (!r) return gitJson({ status: 200, json: { ok: false, reason: 'legacy' } });
3208
- return gitJson({
3209
- status: r.status === 'accepted' ? 200 : 409,
3210
- json: { ok: r.status === 'accepted', ...r },
3211
- });
3212
- },
3213
- '/_api/sync/resync': async (req: Request) => {
3214
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
3215
- // REFUSALS ANSWER IN JSON, WITH A REASON.
3216
- //
3217
- // These were plain-text 403s, so the panel — which reads `json.detail` and
3218
- // falls back to a fixed string — rendered every one of them as "Resync
3219
- // could not start.", a sentence naming no cause and offering no next step.
3220
- // A person hitting the gate legitimately (a canvas iframe, a stale tab,
3221
- // the wrong host) got the same six words as a person hitting a bug, and
3222
- // neither could tell which they had. The GATES are unchanged: what a
3223
- // refusal SAYS is not a security property, and saying nothing was never
3224
- // protecting anything.
3225
- if (!sameOriginWrite(req)) return syncRefusal('cross-origin', 'Resync must be started');
3226
- if (!isTrustedRequestHost(req))
3227
- return syncRefusal('untrusted-host', 'Resync must be started');
3228
- const control = ctx.syncControl;
3229
- if (!control) {
3230
- return gitJson({
3231
- status: 200,
3232
- json: { ok: false, reason: 'no-supervisor', detail: 'Restart Maude to start syncing.' },
3233
- });
3234
- }
3235
- // REFUSED, not queued — see `SyncSupervisor.busy`. A second press must
3236
- // not buy a second full re-link of every canvas.
3237
- if (control.busy?.()) {
3238
- return gitJson({
3239
- status: 409,
3240
- json: { ok: false, reason: 'busy', detail: 'Syncing is already restarting.' },
3241
- });
3242
- }
3243
- // No argument: KEEP the configured hub. Only an explicit `null` unlinks,
3244
- // and this route must never be able to.
3245
- const sync = await control.restart();
3246
- return gitJson({ status: 200, json: { ok: true, sync } });
4391
+ if (!isTrustedRequestHost(req))
4392
+ return new Response('local request required', { status: 403 });
4393
+ return gitJson(await cloudApi.detach());
3247
4394
  },
3248
4395
 
4396
+ // ── Resync (feature-sync-resync-and-out-of-process-sweep) ───────────────
4397
+ // MAIN-ORIGIN ONLY: absent from BOTH CANVAS_SAFE_API and startCanvasServer's
4398
+ // `routes` map (DDR-088's two-allowlist rule). Canvas content is untrusted
4399
+ // (DDR-054) and must not be able to command the desktop to re-push a whole
4400
+ // project — a canvas that could would be an amplification primitive against
4401
+ // the person's own hub, and a way to spend their rate-limit budget.
4402
+ // ACCEPTED REVISIONS — `/_api/project/history` + `/_api/project/restore` are table routes
4403
+ // since S1.12b (routes/history.ts), judged per session with Version history's new routes.
4404
+ // `/_api/project/undo` + `/_api/project/undo-stack` are table routes since
4405
+ // S5.5 (routes/project-undo.ts): one id, several, or a whole chat.
3249
4406
  // feature-before-first-external-users Task 2 — the three user-facing sync
3250
4407
  // toggles (syncFiles / propagateDeletes / resolveFirstAnchor), so the
3251
4408
  // breaker remediation stops meaning "edit JSON by hand" (DDR-177: the
@@ -3422,7 +4579,8 @@ export function createHttp(
3422
4579
  if (!isTrustedRequestHost(req))
3423
4580
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
3424
4581
  if (req.method === 'GET') {
3425
- const entries = listTrash(ctx.paths.designRoot);
4582
+ // S9.12b — a canvas-only session lists only the copies of canvases it sees.
4583
+ const entries = filterTrashListing(listTrash(ctx.paths.designRoot), visOf(req));
3426
4584
  const bytes = entries.reduce((n, e) => n + e.size, 0);
3427
4585
  return Response.json(
3428
4586
  // Cap the wire size; totals stay exact so the panel never lies.
@@ -3748,10 +4906,19 @@ export function createHttp(
3748
4906
  expected?: unknown;
3749
4907
  }>(req, 8 * 1024);
3750
4908
  if (!body) return new Response('body required', { status: 400 });
4909
+ // S5.4 / S2.18 — a live AI run's element is AI's until it's done: 409 held-by-ai.
4910
+ const held = heldByAiRefusal(runs, ctx.paths.designRel, body.canvas, body.id);
4911
+ if (held) return held;
3751
4912
  const result = await api.editCss(body);
3752
4913
  if (!result.ok) {
3753
4914
  return Response.json(
3754
- { ok: false, error: result.error, ...(result.conflict ? { conflict: true } : {}) },
4915
+ {
4916
+ ok: false,
4917
+ error: result.error,
4918
+ ...(result.conflict ? { conflict: true } : {}),
4919
+ // p8-lock-reasons — a locked target answers the edit-op's 409 shape (code + message)
4920
+ ...(result.code ? { code: result.code, message: result.error } : {}),
4921
+ },
3755
4922
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
3756
4923
  );
3757
4924
  }
@@ -3784,10 +4951,18 @@ export function createHttp(
3784
4951
  before?: unknown;
3785
4952
  }>(req, 16 * 1024);
3786
4953
  if (!body) return new Response('body required', { status: 400 });
4954
+ // S5.4 / S2.18 — a live AI run's element is AI's until it's done: 409 held-by-ai.
4955
+ const held = heldByAiRefusal(runs, ctx.paths.designRel, body.canvas, body.id);
4956
+ if (held) return held;
3787
4957
  const result = await api.editText(body);
3788
4958
  if (!result.ok) {
3789
4959
  return Response.json(
3790
- { ok: false, error: result.error },
4960
+ {
4961
+ ok: false,
4962
+ error: result.error,
4963
+ // p8-lock-reasons — a locked target answers the edit-op's 409 shape (code + message)
4964
+ ...(result.code ? { code: result.code, message: result.error } : {}),
4965
+ },
3791
4966
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
3792
4967
  );
3793
4968
  }
@@ -3818,10 +4993,19 @@ export function createHttp(
3818
4993
  expected?: unknown;
3819
4994
  }>(req, 8 * 1024);
3820
4995
  if (!body) return new Response('body required', { status: 400 });
4996
+ // S5.4 / S2.18 — a live AI run's element is AI's until it's done: 409 held-by-ai.
4997
+ const held = heldByAiRefusal(runs, ctx.paths.designRel, body.canvas, body.id);
4998
+ if (held) return held;
3821
4999
  const result = await api.editAttr(body);
3822
5000
  if (!result.ok) {
3823
5001
  return Response.json(
3824
- { ok: false, error: result.error, ...(result.conflict ? { conflict: true } : {}) },
5002
+ {
5003
+ ok: false,
5004
+ error: result.error,
5005
+ ...(result.conflict ? { conflict: true } : {}),
5006
+ // p8-lock-reasons — a locked target answers the edit-op's 409 shape (code + message)
5007
+ ...(result.code ? { code: result.code, message: result.error } : {}),
5008
+ },
3825
5009
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
3826
5010
  );
3827
5011
  }
@@ -3863,7 +5047,12 @@ export function createHttp(
3863
5047
  const result = await api.reorder(body);
3864
5048
  if (!result.ok) {
3865
5049
  return Response.json(
3866
- { ok: false, error: result.error },
5050
+ {
5051
+ ok: false,
5052
+ error: result.error,
5053
+ // p8-lock-reasons — a locked target answers the edit-op's 409 shape (code + message)
5054
+ ...(result.code ? { code: result.code, message: result.error } : {}),
5055
+ },
3867
5056
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
3868
5057
  );
3869
5058
  }
@@ -3914,52 +5103,7 @@ export function createHttp(
3914
5103
  );
3915
5104
  },
3916
5105
 
3917
- '/_api/clip-edit': async (req: Request) => {
3918
- // feature-enhanced-video-editing (Phase 2) — parametric clip verbs, one
3919
- // dispatch route: POST { canvas, artboardId?, stableId, contentHash?,
3920
- // verb: speed|trim-in|audio|detach-audio|framing|grade|transition, …verb
3921
- // params }. Same MAIN-ORIGIN-ONLY trust boundary as the other source
3922
- // writes (absent from CANVAS_SAFE_API + startCanvasServer routes,
3923
- // DDR-054) — this is also the agent door for /design:edit's timeline
3924
- // vocabulary.
3925
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
3926
- if (!sameOriginWrite(req))
3927
- return new Response('cross-origin write rejected', { status: 403 });
3928
- if (!isTrustedRequestHost(req))
3929
- return new Response('local request required (DNS-rebinding guard)', { status: 403 });
3930
- const body = await readJson<{
3931
- canvas?: unknown;
3932
- artboardId?: unknown;
3933
- stableId?: unknown;
3934
- contentHash?: unknown;
3935
- verb?: unknown;
3936
- rate?: unknown;
3937
- deltaFrames?: unknown;
3938
- muted?: unknown;
3939
- volume?: unknown;
3940
- framing?: unknown;
3941
- grade?: unknown;
3942
- presentation?: unknown;
3943
- durationInFrames?: unknown;
3944
- atFrame?: unknown;
3945
- src?: unknown;
3946
- mediaKind?: unknown;
3947
- text?: unknown;
3948
- toIndex?: unknown;
3949
- }>(req, 16 * 1024);
3950
- if (!body) return new Response('body required', { status: 400 });
3951
- const result = await api.clipEditOp(body);
3952
- if (!result.ok) {
3953
- return Response.json(
3954
- { ok: false, error: result.error },
3955
- { status: result.status, headers: { 'Cache-Control': 'no-store' } }
3956
- );
3957
- }
3958
- return Response.json(
3959
- { ok: true, seq: result.seq, ...result.extra },
3960
- { status: 200, headers: { 'Cache-Control': 'no-store' } }
3961
- );
3962
- },
5106
+ // '/_api/clip-edit' moved to routes/edit.ts (S7.6): an alias of the edit-op dispatcher.
3963
5107
 
3964
5108
  '/_api/remove-sequence': async (req: Request) => {
3965
5109
  // DDR-150 P3 — remove a clip. POST { canvas, stableId, artboardId?,
@@ -4202,7 +5346,12 @@ export function createHttp(
4202
5346
  const result = await api.deleteElementOp(body);
4203
5347
  if (!result.ok) {
4204
5348
  return Response.json(
4205
- { ok: false, error: result.error },
5349
+ {
5350
+ ok: false,
5351
+ error: result.error,
5352
+ // p8-lock-reasons — a locked target answers the edit-op's 409 shape (code + message)
5353
+ ...(result.code ? { code: result.code, message: result.error } : {}),
5354
+ },
4206
5355
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
4207
5356
  );
4208
5357
  }
@@ -4239,7 +5388,12 @@ export function createHttp(
4239
5388
  const result = await api.insertElementOp(body);
4240
5389
  if (!result.ok) {
4241
5390
  return Response.json(
4242
- { ok: false, error: result.error },
5391
+ {
5392
+ ok: false,
5393
+ error: result.error,
5394
+ // p8-lock-reasons — a locked target answers the edit-op's 409 shape (code + message)
5395
+ ...(result.code ? { code: result.code, message: result.error } : {}),
5396
+ },
4243
5397
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
4244
5398
  );
4245
5399
  }
@@ -4275,7 +5429,12 @@ export function createHttp(
4275
5429
  const result = await api.convertChildrenToAbsoluteOp(body);
4276
5430
  if (!result.ok) {
4277
5431
  return Response.json(
4278
- { ok: false, error: result.error },
5432
+ {
5433
+ ok: false,
5434
+ error: result.error,
5435
+ // p8-lock-reasons — a locked target answers the edit-op's 409 shape (code + message)
5436
+ ...(result.code ? { code: result.code, message: result.error } : {}),
5437
+ },
4279
5438
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
4280
5439
  );
4281
5440
  }
@@ -4303,7 +5462,12 @@ export function createHttp(
4303
5462
  const result = await api.detachComponentOp(body);
4304
5463
  if (!result.ok) {
4305
5464
  return Response.json(
4306
- { ok: false, error: result.error },
5465
+ {
5466
+ ok: false,
5467
+ error: result.error,
5468
+ // p8-lock-reasons — a locked target answers the edit-op's 409 shape (code + message)
5469
+ ...(result.code ? { code: result.code, message: result.error } : {}),
5470
+ },
4307
5471
  { status: result.status, headers: { 'Cache-Control': 'no-store' } }
4308
5472
  );
4309
5473
  }
@@ -4416,7 +5580,8 @@ export function createHttp(
4416
5580
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
4417
5581
  const r = await api.listAssets();
4418
5582
  return Response.json(
4419
- { ok: true, assets: r.assets },
5583
+ // S9.12 (V2-1.16 L8) — a canvas-only session lists the assets its closure reads.
5584
+ { ok: true, assets: filterAssetListing(r.assets, visOf(req)) },
4420
5585
  { headers: { 'Cache-Control': 'no-store' } }
4421
5586
  );
4422
5587
  },
@@ -4847,74 +6012,8 @@ export function createHttp(
4847
6012
  );
4848
6013
  },
4849
6014
 
4850
- // DDR-167 (Phase 3 / T10) — hardened LOCAL-file SVG ingestion for the
4851
- // in-app Brand-upload panel (T12). Privileged + main-origin-only (Decision
4852
- // 4): absent from CANVAS_SAFE_API + startCanvasServer's routes map — the
4853
- // untrusted canvas iframe must never reach it. Raw-bytes body only, never
4854
- // multipart (this dev server has no multipart parsing anywhere). The
4855
- // `X-Import-Kind` header is a dispatch HINT ONLY — never trusted for the
4856
- // security-relevant decision; the sanitize pipeline's own pre-parse
4857
- // structural sniff decides. PDF import is wired but not yet available —
4858
- // see the DDR's addendum on why the planned rasterization mechanism
4859
- // (headless-Chromium navigating a file:// PDF) doesn't render content
4860
- // under browser automation; a `kind: pdf` request 501s naming that.
4861
- '/_api/import-asset': async (req: Request) => {
4862
- if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
4863
- if (!sameOriginWrite(req))
4864
- return new Response('cross-origin write rejected', { status: 403 });
4865
- if (!isTrustedRequestHost(req))
4866
- return new Response('local request required (DNS-rebinding guard)', { status: 403 });
4867
- const kind = (req.headers.get('x-import-kind') || 'svg').toLowerCase();
4868
- if (kind !== 'svg') {
4869
- return Response.json(
4870
- {
4871
- ok: false,
4872
- error: 'PDF import is not yet available (DDR-167 addendum) — only SVG import is wired.',
4873
- },
4874
- { status: 501, headers: { 'Cache-Control': 'no-store' } }
4875
- );
4876
- }
4877
- const declared = Number(req.headers.get('content-length') || '0');
4878
- if (Number.isFinite(declared) && declared > SVG_MAX_BYTES) {
4879
- return Response.json(
4880
- { ok: false, error: `SVG exceeds the ${SVG_MAX_BYTES / (1024 * 1024)} MB cap` },
4881
- { status: 413, headers: { 'Cache-Control': 'no-store' } }
4882
- );
4883
- }
4884
- if (!req.body) return new Response('empty body', { status: 400 });
4885
- let svgText: string;
4886
- try {
4887
- svgText = await new Response(req.body).text();
4888
- } catch {
4889
- return new Response('could not read body', { status: 400 });
4890
- }
4891
- try {
4892
- const result = await importSvg(svgText, {
4893
- root: ctx.paths.repoRoot,
4894
- designRootRel: ctx.paths.designRel,
4895
- });
4896
- return Response.json(
4897
- { ok: true, path: result.path },
4898
- { status: 201, headers: { 'Cache-Control': 'no-store' } }
4899
- );
4900
- } catch (err) {
4901
- const status =
4902
- err instanceof ImportAssetError
4903
- ? err.code === 3
4904
- ? 400
4905
- : err.code === 5
4906
- ? 415
4907
- : err.code === 6
4908
- ? 500
4909
- : 400
4910
- : 500;
4911
- const message = err instanceof Error ? err.message : String(err);
4912
- return Response.json(
4913
- { ok: false, error: message },
4914
- { status, headers: { 'Cache-Control': 'no-store' } }
4915
- );
4916
- }
4917
- },
6015
+ // DDR-167 (Phase 3 / T10) — hardened local-file ingestion, privileged + main-origin-only (Decision 4).
6016
+ // S8.22: `/_api/import-asset` moved to the route table (routes/assets.ts) with its v2 body.
4918
6017
 
4919
6018
  // DDR-173 (Phase 3 / T12) — brand-file typed-cue extraction for the
4920
6019
  // in-app Brand-upload panel. Privileged + main-origin-only, same posture
@@ -4931,54 +6030,22 @@ export function createHttp(
4931
6030
  return new Response('cross-origin write rejected', { status: 403 });
4932
6031
  if (!isTrustedRequestHost(req))
4933
6032
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
4934
- let body: { assetPath?: unknown };
6033
+ // S8.18 — `{ assetPath }` (v1: a logo), `{ url }` (a website, read through the fetch-asset
6034
+ // gate — typed values only), or both. The body rules live in bin/_brand-site.mjs.
6035
+ let body: { assetPath?: unknown; url?: unknown };
4935
6036
  try {
4936
- body = (await req.json()) as { assetPath?: unknown };
6037
+ body = (await req.json()) as { assetPath?: unknown; url?: unknown };
4937
6038
  } catch {
4938
6039
  return new Response('invalid JSON body', { status: 400 });
4939
6040
  }
4940
- const assetPath = body.assetPath;
4941
- if (typeof assetPath !== 'string' || !/^assets\/[a-z0-9]{8}\.svg$/.test(assetPath)) {
4942
- return Response.json(
4943
- { ok: false, error: 'assetPath must be a server-generated assets/<sha8>.svg path' },
4944
- { status: 400, headers: { 'Cache-Control': 'no-store' } }
4945
- );
4946
- }
4947
- const designAbs = resolve(ctx.paths.repoRoot, ctx.paths.designRel);
4948
- const resolvedAsset = resolve(designAbs, assetPath);
4949
- if (!resolvedAsset.startsWith(resolve(designAbs, 'assets') + sep)) {
4950
- return Response.json(
4951
- { ok: false, error: 'assetPath escapes the assets directory' },
4952
- { status: 400, headers: { 'Cache-Control': 'no-store' } }
4953
- );
4954
- }
4955
- try {
4956
- const result = await importBrand({
4957
- sanitizedSvgPath: resolvedAsset,
4958
- root: ctx.paths.repoRoot,
4959
- designRootRel: ctx.paths.designRel,
4960
- });
4961
- return Response.json(
4962
- { ok: true, ...result },
4963
- { status: 201, headers: { 'Cache-Control': 'no-store' } }
4964
- );
4965
- } catch (err) {
4966
- const status =
4967
- err instanceof ImportBrandError
4968
- ? err.code === 3
4969
- ? 400
4970
- : err.code === 4
4971
- ? 404
4972
- : err.code === 6
4973
- ? 500
4974
- : 400
4975
- : 500;
4976
- const message = err instanceof Error ? err.message : String(err);
4977
- return Response.json(
4978
- { ok: false, error: message },
4979
- { status, headers: { 'Cache-Control': 'no-store' } }
4980
- );
4981
- }
6041
+ const answer = await importBrandRequest(body, {
6042
+ repoRoot: ctx.paths.repoRoot,
6043
+ designRel: ctx.paths.designRel,
6044
+ });
6045
+ return Response.json(answer.body, {
6046
+ status: answer.status,
6047
+ headers: { 'Cache-Control': 'no-store' },
6048
+ });
4982
6049
  },
4983
6050
 
4984
6051
  '/_api/export-history': async (req: Request) => {
@@ -5048,22 +6115,34 @@ export function createHttp(
5048
6115
  options?: Record<string, unknown>;
5049
6116
  }>(req, 64 * 1024);
5050
6117
  if (!body) return new Response('body required', { status: 400 });
5051
- if (!isFormat(body.format)) return new Response('unknown or missing format', { status: 400 });
5052
- if (!isScope(body.scope)) return new Response('unknown or missing scope', { status: 400 });
6118
+ // S8.1 — `{v:2, spec}` beside the v1 body: one spec = one group job (routes/export.ts).
6119
+ const v2 = isV2Body(body) ? planExportV2(body.spec, exportV2Deps, req) : null;
6120
+ if (v2 && !v2.ok) return v2.response;
6121
+ if (!v2 && !isFormat(body.format))
6122
+ return new Response('unknown or missing format', { status: 400 });
6123
+ if (!v2 && !isScope(body.scope))
6124
+ return new Response('unknown or missing scope', { status: 400 });
5053
6125
  // DDR-231 Phase 2 T4 — the PAIR, not just each half. `pdf` + `project-raw`
5054
6126
  // is two individually-valid values that resolve to a `file-tree` target,
5055
6127
  // which the render service refuses as `invalid render job` — a refusal
5056
6128
  // that named neither the field nor the remedy. Reproduced locally against
5057
6129
  // a real maude-render; see test/export-format-scope-coherence.test.ts.
5058
- if (!isScopeValidForFormat(body.format, body.scope)) {
5059
- return new Response(scopeRefusalMessage(body.format, body.scope), { status: 400 });
6130
+ if (!v2 && !isScopeValidForFormat(body.format as Format, body.scope as Scope)) {
6131
+ return new Response(scopeRefusalMessage(body.format as Format, body.scope as Scope), {
6132
+ status: 400,
6133
+ });
5060
6134
  }
5061
- const format = body.format;
5062
- const scope = body.scope;
6135
+ const format = (v2?.ok ? v2.first.format : body.format) as Format;
6136
+ const scope = (v2?.ok ? v2.first.scope : body.scope) as Scope;
5063
6137
  try {
5064
- const { result } = exportJobs.enqueue(
5065
- buildExportArgs(req, { format, scope, options: body.options })
5066
- );
6138
+ const { result } = exportJobs.enqueue({
6139
+ ...buildExportArgs(req, {
6140
+ format,
6141
+ scope,
6142
+ options: v2?.ok ? v2.first.options : body.options,
6143
+ }),
6144
+ ...(v2?.ok ? { group: v2.group } : {}),
6145
+ });
5067
6146
  const finished = await result;
5068
6147
  // Bun.serve accepts Uint8Array directly; the cast satisfies the
5069
6148
  // SharedArrayBuffer-strict BodyInit narrowing on @types/bun.
@@ -5071,7 +6150,8 @@ export function createHttp(
5071
6150
  status: 200,
5072
6151
  headers: {
5073
6152
  'Content-Type': finished.contentType,
5074
- 'Content-Disposition': `attachment; filename="${finished.filename}"`,
6153
+ // S8.1 — an ASCII name is the v1 header byte for byte; a v2 name adds `filename*`
6154
+ 'Content-Disposition': contentDisposition(finished.filename),
5075
6155
  'Cache-Control': 'no-store',
5076
6156
  },
5077
6157
  });
@@ -5095,8 +6175,21 @@ export function createHttp(
5095
6175
  if (!isTrustedRequestHost(req))
5096
6176
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
5097
6177
  if (req.method === 'GET') {
6178
+ // S8.5b-1 (§7, T11) — the hub mints a fresh viewer render token on every status read;
6179
+ // a job that has not finished renders with it (owner-scoped, like every read here).
6180
+ const fresh = req.headers.get('x-maude-render-token');
6181
+ const one = new URL(req.url).searchParams.get('id');
6182
+ if (one !== null) {
6183
+ // S8.5b-1 — one job by id (the render door's status read); another member's is missing
6184
+ const job = exportJobs.get(one);
6185
+ if (!job) return new Response('Not found', { status: 404 });
6186
+ if (fresh) exportJobs.refreshRenderToken(one, fresh);
6187
+ return Response.json({ jobs: [job] }, { headers: { 'Cache-Control': 'no-store' } });
6188
+ }
6189
+ if (fresh) for (const j of exportJobs.list()) exportJobs.refreshRenderToken(j.id, fresh);
5098
6190
  return Response.json(
5099
- { jobs: exportJobs.list() },
6191
+ // S8.5 — this Mac's cloud rows (queued in the outbox, rendering, done) beside its own jobs
6192
+ { jobs: [...cloudExports.rows(), ...exportJobs.list()] },
5100
6193
  { headers: { 'Cache-Control': 'no-store' } }
5101
6194
  );
5102
6195
  }
@@ -5109,6 +6202,50 @@ export function createHttp(
5109
6202
  options?: Record<string, unknown>;
5110
6203
  }>(req, 64 * 1024);
5111
6204
  if (!body) return new Response('body required', { status: 400 });
6205
+ // S8.1 — `{v:2, spec}` beside the v1 body (same plan as /_api/export above).
6206
+ const v2 = isV2Body(body) ? planExportV2(body.spec, exportV2Deps, req) : null;
6207
+ if (v2 && !v2.ok) return v2.response;
6208
+ if (v2?.ok) {
6209
+ // S8.5 — a video sent to the cloud from this Mac waits in the outbox (id = job id)
6210
+ const cloud = cloudExportResponse(v2.group, {
6211
+ cloud: cloudExports,
6212
+ renderLane: resolveRenderLane(),
6213
+ label: cloudLabel(v2.group.spec, ctx.cfg.name || ctx.projectLabel || ''),
6214
+ actor: 'you',
6215
+ device: 'studio',
6216
+ project: { id: null, hub: ctx.cfg.linkedHub?.url ?? null },
6217
+ });
6218
+ if (cloud) return cloud;
6219
+ // S8.5b-1 — the cloud render door names its job (the desktop's outbox record id). The hub
6220
+ // proxy strips every inbound x-maude-*, so only the door sets it, and only a cell (a render
6221
+ // lane that is not this Mac's) honours it.
6222
+ const doorJob =
6223
+ resolveRenderLane() !== 'local' ? req.headers.get('x-maude-door-job') : null;
6224
+ try {
6225
+ const { id, result, already } = exportJobs.enqueue({
6226
+ ...buildExportArgs(req, {
6227
+ format: v2.first.format as Format,
6228
+ scope: v2.first.scope,
6229
+ options: v2.first.options,
6230
+ }),
6231
+ group: v2.group,
6232
+ ...(doorJob !== null ? { clientId: doorJob } : {}),
6233
+ });
6234
+ result.catch(() => {});
6235
+ return Response.json(already ? { jobId: id, already: true } : { jobId: id }, {
6236
+ status: already ? 200 : 202,
6237
+ headers: { 'Cache-Control': 'no-store' },
6238
+ });
6239
+ } catch (err) {
6240
+ if (err instanceof ExportQueueFullError)
6241
+ return new Response(err.message, { status: 429 });
6242
+ if (err instanceof ExportJobIdError)
6243
+ return err.reason === 'taken'
6244
+ ? Response.json({ code: 'id-taken' }, { status: 409 })
6245
+ : Response.json({ code: 'bad-job-id' }, { status: 400 });
6246
+ throw err;
6247
+ }
6248
+ }
5112
6249
  if (!isFormat(body.format)) return new Response('unknown or missing format', { status: 400 });
5113
6250
  if (!isScope(body.scope)) return new Response('unknown or missing scope', { status: 400 });
5114
6251
  // DDR-231 Phase 2 T4 — the PAIR, not just each half. `pdf` + `project-raw`
@@ -5152,6 +6289,17 @@ export function createHttp(
5152
6289
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
5153
6290
  const id = new URL(req.url).searchParams.get('id');
5154
6291
  if (!id) return new Response('id query param required', { status: 400 });
6292
+ // S8.5 — a cloud job's file came down to this Mac (`_state/export-cloud/<id>/`)
6293
+ const cloudDl = cloudExports.bytes(id);
6294
+ if (cloudDl.ok)
6295
+ return new Response(cloudDl.body as unknown as BodyInit, {
6296
+ status: 200,
6297
+ headers: {
6298
+ 'Content-Type': 'application/octet-stream',
6299
+ 'Content-Disposition': contentDisposition(cloudDl.filename),
6300
+ 'Cache-Control': 'no-store',
6301
+ },
6302
+ });
5155
6303
  const dl = await exportJobs.getBytes(id);
5156
6304
  if (!dl.ok) {
5157
6305
  return new Response(dl.reason === 'not-done' ? 'job not finished' : 'Not found', {
@@ -5162,7 +6310,7 @@ export function createHttp(
5162
6310
  status: 200,
5163
6311
  headers: {
5164
6312
  'Content-Type': dl.contentType,
5165
- 'Content-Disposition': `attachment; filename="${dl.filename}"`,
6313
+ 'Content-Disposition': contentDisposition(dl.filename),
5166
6314
  'Cache-Control': 'no-store',
5167
6315
  },
5168
6316
  });
@@ -5521,7 +6669,10 @@ export function createHttp(
5521
6669
  if (!isTrustedRequestHost(req))
5522
6670
  return new Response('local request required (DNS-rebinding guard)', { status: 403 });
5523
6671
  if (req.method === 'GET') {
5524
- return Response.json(readUiPrefs(), { headers: { 'Cache-Control': 'no-store' } });
6672
+ const prefs = readUiPrefs() as Record<string, unknown>;
6673
+ // V2-8.9 r2 F4 — a cell's one prefs.json is every member's: no shared Recent colours
6674
+ if (isWorkspaceMode()) delete prefs.recentColours;
6675
+ return Response.json(prefs, { headers: { 'Cache-Control': 'no-store' } });
5525
6676
  }
5526
6677
  if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
5527
6678
  if (!sameOriginWrite(req))
@@ -5530,36 +6681,30 @@ export function createHttp(
5530
6681
  if (!body || typeof body !== 'object')
5531
6682
  return new Response('body must be a JSON object', { status: 400 });
5532
6683
  // Build a clean patch — only well-typed known keys pass through, so a bad
5533
- // field is rejected rather than silently resetting a stored value.
5534
- const patch: Partial<UiPrefs> = {};
5535
- if ('theme' in body) {
5536
- if (body.theme !== 'light' && body.theme !== 'dark')
5537
- return new Response('theme must be light|dark', { status: 400 });
5538
- patch.theme = body.theme;
5539
- }
5540
- for (const k of ['minimap', 'zoom', 'annotations', 'autoOpenInspector'] as const) {
5541
- if (k in body) {
5542
- if (typeof body[k] !== 'boolean')
5543
- return new Response(`${k} must be a boolean`, { status: 400 });
5544
- patch[k] = body[k] as boolean;
5545
- }
5546
- }
5547
- if ('layersMode' in body) {
5548
- if (body.layersMode !== 'separate' && body.layersMode !== 'in-inspector')
5549
- return new Response('layersMode must be separate|in-inspector', { status: 400 });
5550
- patch.layersMode = body.layersMode;
5551
- }
5552
- if ('panelSides' in body) {
5553
- const ps = body.panelSides;
5554
- if (!ps || typeof ps !== 'object' || Array.isArray(ps))
5555
- return new Response('panelSides must be an object', { status: 400 });
5556
- for (const v of Object.values(ps as Record<string, unknown>)) {
5557
- if (v !== 'left' && v !== 'right')
5558
- return new Response('panelSides values must be left|right', { status: 400 });
5559
- }
5560
- // writeUiPrefs → coerce keeps only known ids, so unknown keys are dropped.
5561
- patch.panelSides = ps as UiPrefs['panelSides'];
5562
- }
6684
+ // field is rejected rather than silently resetting a stored value
6685
+ // (validateUiPrefsPatch in ui-prefs.ts owns the whitelist, V2-2.7).
6686
+ const checked = validateUiPrefsPatch(body);
6687
+ if (!checked.ok) return new Response(checked.error, { status: 400 });
6688
+ const patch = checked.patch;
6689
+ // A6c (S11.13 security) — `ownPluginCopy` / `experimentalTeams` change how THIS Mac's AI
6690
+ // chat starts (plugin-bootstrap, the adapter's env), so they are the AI chat's, not a view
6691
+ // preference: only a session that edits the project may flip them (D2, like `acpRefusal`),
6692
+ // and never in a cloud cell (no one's Mac). The whole patch is refused, nothing half-saved.
6693
+ if (
6694
+ ('ownPluginCopy' in patch || 'experimentalTeams' in patch) &&
6695
+ (isWorkspaceMode() || !accessOf(req).can('edit', null))
6696
+ )
6697
+ return Response.json(ACP_REFUSAL, {
6698
+ status: 403,
6699
+ headers: { 'Cache-Control': 'no-store' },
6700
+ });
6701
+ // V2-8.9 r2 F4 — in a cell any member (a viewer too) could plant swatches every editor then sees and
6702
+ // clicks: Recent colours stay in the page there (the Inspector's store keeps them for the page).
6703
+ if ('recentColours' in patch && isWorkspaceMode())
6704
+ return Response.json(
6705
+ { error: 'recent-colours-cell', message: 'Recent colours are not saved in Maude Cloud.' },
6706
+ { status: 403, headers: { 'Cache-Control': 'no-store' } }
6707
+ );
5563
6708
  try {
5564
6709
  return Response.json(writeUiPrefs(patch), { headers: { 'Cache-Control': 'no-store' } });
5565
6710
  } catch (err) {
@@ -5938,12 +7083,28 @@ export function createHttp(
5938
7083
  '/index.html': (req: Request) => serveStudioPage(req),
5939
7084
  } satisfies Record<string, (req: Request) => Response | Promise<Response>>;
5940
7085
 
7086
+ // V2-2.5 — one map: the table's exact paths, then the legacy keys (the order the spread had).
7087
+ // A table path that is also a legacy key would be dropped by this spread without a word, so the
7088
+ // table is checked here, at construction, and the server refuses to boot on a problem — the
7089
+ // same fail-loud posture as the containment boot-assert (test/routes-table.test.ts).
7090
+ const routeProblems = checkRouteTable({
7091
+ specs: tableSpecs,
7092
+ legacyKeys: Object.keys(legacyRoutes),
7093
+ readOnlyAllowedWrites: READ_ONLY_ALLOWED_WRITES,
7094
+ readOnlyAllowedPatterns: READ_ONLY_ALLOWED_WRITE_PATTERNS,
7095
+ });
7096
+ if (routeProblems.length > 0)
7097
+ throw new Error(`[studio] the route table is unsound:\n ${routeProblems.join('\n ')}`);
7098
+ const routes = { ...laneRoutes.exact, ...legacyRoutes };
7099
+
5941
7100
  // Named `handleFallthrough`, not `fetch` — a same-named local function shadows
5942
7101
  // the global `fetch` for every call site in this module's scope, which is how
5943
7102
  // the `/_api/report` route ended up calling itself instead of the network (see
5944
7103
  // the `globalThis.fetch` comment on that route; RCA issue-report-a-bug-http-500).
5945
7104
  async function handleFallthrough(req: Request): Promise<Response> {
5946
7105
  try {
7106
+ const laneResponse = laneRoutes.dynamic(req);
7107
+ if (laneResponse) return await laneResponse;
5947
7108
  const url = new URL(req.url);
5948
7109
  const pathname = url.pathname;
5949
7110
 
@@ -5951,6 +7112,19 @@ export function createHttp(
5951
7112
  // the fall-through instead of the static `routes` map. `<id>` is the
5952
7113
  // c_<hex> id of the parent comment; body is `{ body, author? }`. Bodies
5953
7114
  // share the same 4000-char cap as a top-level comment.
7115
+ // V2-2.17 — GET /_api/thumb/<key> (contract V2-1.17 §5.3, R4–R6). Main origin only: absent
7116
+ // from CANVAS_SAFE_API and the canvas routes map, so the canvas and capture origins 403 it
7117
+ // at their door. Unreferenced and missing keys are the same 404.
7118
+ const thumbMatch = /^\/_api\/thumb\/([^/]*)$/.exec(pathname);
7119
+ if (thumbMatch) {
7120
+ if (req.method !== 'GET' && req.method !== 'HEAD')
7121
+ return new Response('Method not allowed', { status: 405 });
7122
+ if (!sameOriginRead(req)) return new Response('cross-origin rejected', { status: 403 });
7123
+ if (!isTrustedRequestHost(req))
7124
+ return new Response('local request required (DNS-rebinding guard)', { status: 403 });
7125
+ return thumbMatch[1] ? thumbResponse(thumbs, thumbMatch[1]) : thumbNotFound();
7126
+ }
7127
+
5954
7128
  const replyMatch = pathname.match(/^\/_api\/comments\/([A-Za-z0-9_]+)\/reply$/);
5955
7129
  if (replyMatch) {
5956
7130
  if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
@@ -5972,13 +7146,8 @@ export function createHttp(
5972
7146
 
5973
7147
  // Bundled client assets (preferred path — bundle from dist/).
5974
7148
  if (pathname.startsWith('/_client/')) {
5975
- const rel = decodeURIComponent(pathname.slice('/_client/'.length));
5976
- if (rel.includes('..')) return new Response('Forbidden', { status: 403 });
5977
7149
  // Try dist/ first (built bundle + styles), fall back to client/ (raw source files).
5978
- const distHit = join(DIST_DIR, rel);
5979
- if (await Bun.file(distHit).exists()) return serveFile(distHit);
5980
- const srcHit = join(CLIENT_DIR, rel);
5981
- return serveFile(srcHit);
7150
+ return serveClientAsset(decodeURIComponent(pathname.slice('/_client/'.length)));
5982
7151
  }
5983
7152
 
5984
7153
  // React 19 runtime bundles for TSX canvases. The browser pulls these
@@ -6020,10 +7189,16 @@ export function createHttp(
6020
7189
  // V2-2.8 S9 (V2-1.16 L21) — only the MAIN listener reaches this branch
6021
7190
  // (the canvas and capture listeners answer the shell themselves, in
6022
7191
  // server.ts). While the split is on, every request here goes to the
6023
- // read-only capture origin, bar Maude's own local harnesses (see
6024
- // captureRedirect) — so what follows serves only those, and every
6025
- // shell when the split is OFF.
6026
- const toCapture = captureRedirect(req, url);
7192
+ // read-only capture origin, Maude's own local harnesses included (see
7193
+ // captureRedirect) — so what follows serves a shell only when the
7194
+ // split is OFF.
7195
+ // gate-b-c4 — the photo-bg-remove harness (exactly `?canvas=_photo/<slug>.bgremove.tsx
7196
+ // &nonce=<the helper's one-time nonce>`, gate-b-c4c) renders on the INTERACTIVE canvas
7197
+ // origin (it needs that origin's asset + photo-edit writes); the main origin sends it
7198
+ // there with the frame's capability, which a local helper cannot mint itself.
7199
+ const toHarness = bgRemoveRedirect(url, req);
7200
+ if (toHarness) return toHarness;
7201
+ const toCapture = captureRedirect(url, req);
6027
7202
  if (toCapture) return toCapture;
6028
7203
  // The segregated canvas origin (server.ts) calls serveCanvasShell(true)
6029
7204
  // directly with CSP always on; on the legacy main origin the CSP stays
@@ -6031,7 +7206,7 @@ export function createHttp(
6031
7206
  // render (?hide-chrome=1) that still lands here ALWAYS gets the
6032
7207
  // network-locked capture CSP so it can't SSRF/exfil (attacker F1).
6033
7208
  const capture = url.searchParams.get('hide-chrome') === '1';
6034
- return serveCanvasShell(process.env.MAUDE_CSP_POC === '1', capture);
7209
+ return serveCanvasShell(process.env.MAUDE_CSP_POC === '1', capture, url.searchParams, req);
6035
7210
  }
6036
7211
 
6037
7212
  // DDR-150 dogfood — canvas-relative assets alias. A comp's
@@ -6041,6 +7216,8 @@ export function createHttp(
6041
7216
  // the canvas origin). Without this, every src the timeline insert /
6042
7217
  // replace / assemble writers emit 404'd in the Player.
6043
7218
  if (pathname.startsWith('/assets/')) {
7219
+ // DNS rebinding (Phase 2 gate) — the same Host check as the repo-file lane below.
7220
+ if (!isTrustedRequestHost(req)) return new Response('Forbidden', { status: 403 });
6044
7221
  let name = '';
6045
7222
  try {
6046
7223
  name = decodeURIComponent(pathname.slice('/assets/'.length));
@@ -6163,6 +7340,9 @@ export function createHttp(
6163
7340
  if (!isTrustedRequestHost(req)) return new Response('Forbidden', { status: 403 });
6164
7341
  const fp = safePathUnderRoot(req.url, ctx.paths.repoRoot);
6165
7342
  if (!fp) return new Response('Forbidden', { status: 403 });
7343
+ // V2-8.9 re-check 2 H-a — no dot path outside the design root (static-lane.ts).
7344
+ if (isRefusedDotPath(fp, ctx.paths.repoRoot, ctx.paths.designRoot))
7345
+ return new Response('Not found', { status: 404 });
6166
7346
 
6167
7347
  const file = Bun.file(fp);
6168
7348
  const exists = await file.exists();
@@ -6180,7 +7360,14 @@ export function createHttp(
6180
7360
  const underDesignRoot = isUnderOrEqual(fp, ctx.paths.designRoot);
6181
7361
  // .tsx under designRoot is a canvas — transpile + emit locator, return JS.
6182
7362
  if (e === '.tsx' && underDesignRoot) {
6183
- return serveCanvasTsx(fp, req, ctx, join(ctx.paths.designRoot, '_locator.json'));
7363
+ return serveCanvasTsx(
7364
+ fp,
7365
+ req,
7366
+ ctx,
7367
+ join(ctx.paths.designRoot, '_locator.json'),
7368
+ undefined,
7369
+ canvasInputsGate(req)
7370
+ );
6184
7371
  }
6185
7372
  // Video/audio get Range support (scrubbing + WKWebView compat) — the
6186
7373
  // `/.design/assets/…` form comps reference goes through here.
@@ -6218,8 +7405,9 @@ export function createHttp(
6218
7405
  // whether you sniff it or not. See INERT_DOCUMENT_CSP: an SVG
6219
7406
  // NAVIGATED TO is a page with `<script>` in it, executing on this
6220
7407
  // origin, and "the canvas CSP blocks script" above is true only of
6221
- // the shell — not of the asset served on its own.
6222
- ...(e === '.svg' ? { 'Content-Security-Policy': INERT_DOCUMENT_CSP } : {}),
7408
+ // the shell — not of the asset served on its own. A repo `.html` is
7409
+ // the same case on the privileged origin (REPO_HTML_CSP).
7410
+ ...documentCsp(e),
6223
7411
  },
6224
7412
  });
6225
7413
  } catch (err) {
@@ -6265,45 +7453,156 @@ export function createHttp(
6265
7453
  * URL will load and redirecting "only the dangerous ones" fails open on any
6266
7454
  * input the prediction misreads (V2-2.8 security review).
6267
7455
  *
6268
- * The ONE exception (a named residual): Maude's own local harnesses, matched
6269
- * exactly — `maude design draw-proof` (`_draw/<slug>.proof.tsx`) and
6270
- * `photo-bg-remove` (`_photo/<slug>.bgremove.tsx`), with no parameter beyond
6271
- * `canvas` and the server's own `designRel`. They live under DDR-115
6272
- * runtime dirs the canvas-safe table refuses, and are generated on this
6273
- * machine (never synced), so they keep rendering here exactly as before —
6274
- * but only when the helper itself navigated there: Fetch Metadata `none`
6275
- * (a browser-initiated `goto`/`open`) or absent (a non-browser client). A
6276
- * page — another site, or a canvas on the canvas origin (same-site) —
6277
- * steering a browser to a leftover harness URL is redirected like the rest.
6278
- * Nothing is redirected when the split is off or in a cell (no capture
6279
- * listener; a cell's proxy never routes the main-origin shell).
7456
+ * NO exceptions — Maude's own local harnesses included (V2-2.4b gate). They
7457
+ * used to stay here on direct navigation as "generated on this machine", but
7458
+ * the AI agent is on this machine too: it can write `_draw/x.proof.tsx`
7459
+ * itself and open it with an auto-approved verb, and even a helper-generated
7460
+ * proof mounts model-authored SVG. `maude design draw-proof` therefore
7461
+ * renders on the capture origin like every other capture, and
7462
+ * `photo-bg-remove` opens its harness on the canvas origin directly (it
7463
+ * needs that origin's canvas-safe asset + photo-edit writes). Both reach
7464
+ * their module through the exact `LOCAL_HARNESS` shape `isCanvasSafeRoute`
7465
+ * admits under the runtime dirs. Nothing is redirected when the split is off
7466
+ * or in a cell (no capture listener; a cell's proxy never routes the
7467
+ * main-origin shell).
6280
7468
  */
6281
7469
  const LOCAL_HARNESS =
6282
7470
  /^_(?:draw\/[a-z0-9_][a-z0-9._-]*\.proof|photo\/[a-z0-9_][a-z0-9._-]*\.bgremove)\.tsx$/;
6283
- function isLocalHarness(req: Request, url: URL): boolean {
7471
+ const BG_REMOVE_HARNESS = /^_photo\/[a-z0-9_][a-z0-9._-]*\.bgremove\.tsx$/;
7472
+ const HARNESS_NONCE = /^[0-9a-f]{32}$/;
7473
+ const HARNESS_NONCE_LINE = /^\/\/ maude-harness-nonce: ([0-9a-f]{32})$/m;
7474
+ function bgRemoveRedirect(url: URL, req: Request): Response | null {
7475
+ if (!ctx.canvasOrigin || isWorkspaceMode()) return null;
7476
+ // gate-b-c4c — exactly {canvas, nonce}: the helper's one-time nonce, which it also wrote into
7477
+ // the harness it generated. The harness name is the photo's hash (guessable), so without the
7478
+ // nonce any canvas could frame this URL, land on its OWN origin with the capability in the
7479
+ // URL and read it from `iframe.contentWindow.location`. Canvas code cannot read the nonce:
7480
+ // the harness module is served only inside the harness's own frame.
7481
+ const keys = [...url.searchParams.keys()].sort();
7482
+ if (keys.length !== 2 || keys[0] !== 'canvas' || keys[1] !== 'nonce') return null;
7483
+ const rel = url.searchParams.get('canvas') ?? '';
7484
+ const nonce = url.searchParams.get('nonce') ?? '';
7485
+ if (!BG_REMOVE_HARNESS.test(rel) || !HARNESS_NONCE.test(nonce)) return null;
7486
+ // Belt over the nonce: only a navigation the user agent started itself (agent-browser's
7487
+ // `open` — `none`; no header from a non-browser client). A canvas's iframe is `same-site`.
7488
+ if (!startedByUserAgent(req)) return null;
7489
+ // gate-b-c4b (lead: Option A) — the frame spans the harness AND every canvas that uses the
7490
+ // photo it processes (`source=` in the generated harness): it must read that photo and write
7491
+ // its every-use edit, which only a frame that may edit every user of the photo may. The
7492
+ // harness is local runtime state (`_photo/`, never synced); no other exception.
7493
+ let text: string;
7494
+ try {
7495
+ text = readFileSync(join(ctx.paths.designRoot, rel), 'utf8');
7496
+ } catch {
7497
+ return null;
7498
+ }
7499
+ const want = HARNESS_NONCE_LINE.exec(text)?.[1];
7500
+ if (!want || !timingSafeEqual(Buffer.from(want), Buffer.from(nonce))) return null;
7501
+ const source =
7502
+ /\bsource=["'](assets\/[0-9a-f]{8,64}\.[A-Za-z0-9]{1,8})["']/.exec(text)?.[1] ?? null;
7503
+ // gate-b-c4c — `.tsx` canvases only: `assetReferrers` is a text match, so it also names a
7504
+ // stylesheet or a note that mentions the photo (it already skips `_` first segments).
7505
+ const users = source
7506
+ ? assetReferrers(
7507
+ diskProjectReader(ctx.paths.designRoot, () => String(Date.now())),
7508
+ source
7509
+ ).filter((u) => u.endsWith('.tsx'))
7510
+ : [];
7511
+ const fc = frameCapFor(req, [rel, ...users]);
7512
+ if (!fc) return null;
7513
+ const qs = new URLSearchParams({ canvas: rel, [FRAME_PARAM]: fc });
7514
+ return new Response(null, {
7515
+ status: 307,
7516
+ headers: {
7517
+ Location: `${ctx.canvasOrigin}/_canvas-shell.html?${qs.toString()}`,
7518
+ 'Cache-Control': 'no-store',
7519
+ },
7520
+ });
7521
+ }
7522
+
7523
+ /**
7524
+ * gate-b-c4d — Fetch Metadata: did the user agent start this request itself (a typed URL, an
7525
+ * automation `goto`/`open` — `none`), did one of this origin's own pages (`same-origin`), or is it
7526
+ * a non-browser client (no header)? Anything else was started by another site — and every
7527
+ * canvas runs on one (the canvas and capture origins are other ports: `same-site`).
7528
+ */
7529
+ function startedByUserAgent(req: Request): boolean {
6284
7530
  const site = req.headers.get('sec-fetch-site');
6285
- if (site !== null && site !== 'none') return false;
6286
- const params = [...url.searchParams.keys()];
6287
- if (params.some((k) => k !== 'canvas' && k !== 'designRel')) return false;
6288
- const canvases = url.searchParams.getAll('canvas');
6289
- if (canvases.length !== 1 || !LOCAL_HARNESS.test(canvases[0] ?? '')) return false;
6290
- const own = ctx.paths.designRel.replace(/^\/+|\/+$/g, '');
6291
- const asked = url.searchParams.getAll('designRel');
6292
- return asked.length === 0 || (asked.length === 1 && asked[0] === own);
7531
+ return site === null || site === 'none' || site === 'same-origin';
6293
7532
  }
6294
- function captureRedirect(req: Request, url: URL): Response | null {
7533
+
7534
+ function captureRedirect(url: URL, req: Request): Response | null {
6295
7535
  if (!ctx.captureOrigin) return null;
6296
- if (isLocalHarness(req, url)) return null;
7536
+ // gate-b-c4 — the capture is a frame too: scoped to the canvas the URL names (a server-minted
7537
+ // capability; a URL naming no canvas, or a bad path, goes frame-less and reads nothing).
7538
+ const search = new URLSearchParams(url.search);
7539
+ search.delete(FRAME_PARAM);
7540
+ // gate-b-c4c — a bg-remove nonce that did not mint the harness frame is not forwarded.
7541
+ search.delete('nonce');
7542
+ // `frame` names the canvas of a shell that imports its module itself (a thumbnail tile).
7543
+ const named = search.get('canvas') ?? search.get('frame');
7544
+ const rel = named ? toDesignRel(named, designRel) : null;
7545
+ // gate-b-c4d — minted only for a navigation the user agent or this origin started. Canvas A
7546
+ // running in a capture could otherwise `window.open` this URL for canvas B: the popup lands
7547
+ // on A's own (capture) origin, A reads `fc` from its `location` and reads B as the owner. Such
7548
+ // a request (`same-site`) still redirects — frame-less, so the capture reads nothing.
7549
+ const fc = rel && startedByUserAgent(req) ? frameCapFor(req, [rel]) : null;
7550
+ if (fc) search.set(FRAME_PARAM, fc);
7551
+ const qs = search.toString();
6297
7552
  return new Response(null, {
6298
7553
  status: 307,
6299
7554
  headers: {
6300
- Location: `${ctx.captureOrigin}/_canvas-shell.html${url.search}`,
7555
+ Location: `${ctx.captureOrigin}/_canvas-shell.html${qs ? `?${qs}` : ''}`,
6301
7556
  'Cache-Control': 'no-store',
6302
7557
  },
6303
7558
  });
6304
7559
  }
6305
7560
 
6306
- async function serveCanvasShell(applyCsp: boolean, capture = false): Promise<Response> {
7561
+ /** The meta lane of the canvas a `?sha=` shell renders, or null (no sha, no such lane, bad path). */
7562
+ async function versionMetaFor(query?: URLSearchParams): Promise<string | null> {
7563
+ const ref = query?.get('sha');
7564
+ const canvasParam = query?.get('canvas');
7565
+ if (!ref || !canvasParam) return null;
7566
+ // The shell's own normalisation (designRoot-relative OR repo-relative), confined to the design root.
7567
+ const clean = canvasParam.replace(/^\/+/, '');
7568
+ const designRel = ctx.paths.designRel.replace(/^\/+|\/+$/g, '');
7569
+ const rel = clean.startsWith(`${designRel}/`) ? clean.slice(designRel.length + 1) : clean;
7570
+ const abs = resolve(ctx.paths.designRoot, rel);
7571
+ if (!abs.startsWith(ctx.paths.designRoot + sep) || !/\.tsx$/i.test(abs)) return null;
7572
+ const repoRel = relative(ctx.paths.repoRoot, abs).replace(/\\/g, '/');
7573
+ return laneAtRef(versionReaders(ctx), repoRel, ref, 'meta');
7574
+ }
7575
+
7576
+ /**
7577
+ * gate-b-c4c — may this request's access (on the canvas / capture listeners: narrowed to its
7578
+ * frame) read the canvas a shell query names? The shell document itself is frame-less, so what
7579
+ * it inlines about that canvas (a past version's meta, its `dsPairing` aliases) needs this. Both
7580
+ * normalisations the two readers use are asked — this server's design root (`versionMetaFor`)
7581
+ * and the query's own `designRel` (`pairingCssFor`) — so neither reads a canvas the other did
7582
+ * not check. A query naming no canvas inlines nothing about one.
7583
+ */
7584
+ function shellCanvasVisible(req: Request, query?: URLSearchParams): boolean {
7585
+ const raw = query?.get('canvas');
7586
+ if (!raw) return true;
7587
+ const access = accessOf(req);
7588
+ const clean = raw.replace(/^\/+/, '');
7589
+ for (const root of [ctx.paths.designRel, query?.get('designRel') || '.design']) {
7590
+ const d = root.replace(/^\/+|\/+$/g, '');
7591
+ const rel = d && clean.startsWith(`${d}/`) ? clean.slice(d.length + 1) : clean;
7592
+ const abs = resolve(ctx.paths.designRoot, rel);
7593
+ if (!abs.startsWith(ctx.paths.designRoot + sep)) continue; // neither reader reads it
7594
+ if (!access.seesCanvas(relative(ctx.paths.designRoot, abs).split(sep).join('/')))
7595
+ return false;
7596
+ }
7597
+ return true;
7598
+ }
7599
+
7600
+ async function serveCanvasShell(
7601
+ applyCsp: boolean,
7602
+ capture: boolean,
7603
+ query: URLSearchParams | undefined,
7604
+ req: Request
7605
+ ): Promise<Response> {
6307
7606
  // `comment-mount.js` is versioned for the same reason as the studio page's
6308
7607
  // bundle (see `serveIndexHtml`): a fixed URL outlives a release in any
6309
7608
  // cache in front of the canvas origin. Replaced BEFORE the CSP hashes are
@@ -6316,8 +7615,30 @@ export function createHttp(
6316
7615
  "'/_client/comment-mount.js'",
6317
7616
  `'/_client/comment-mount.js${mountV}'`
6318
7617
  );
6319
- // Inject inspector overlay — Cmd+Click selection + add-comment flow.
6320
- const injected = inspect().injectInspector(shellHtml);
7618
+ // Inject inspector overlay — Cmd+Click selection + add-comment flow, then the canvas
7619
+ // system's schema fallbacks (V2-1.13 §5.5 P-2: only the roles/classes it never declares,
7620
+ // inline — both canvas CSPs allow inline styles, so no new route).
7621
+ // S1.11 — a past version (`?sha=`) carries its own meta lane (V2-1.9 §5.6): injected here,
7622
+ // BEFORE the CSP hashes the inline scripts, escaped for a script tag (past meta is peer-authored).
7623
+ // S10.4b — the past meta also carries that version's `dsPairing` aliases into the fallback slot.
7624
+ // gate-b-c4c — only for a request that sees the named canvas: canvas A's code could otherwise
7625
+ // fetch this document for B and read B's meta. Anyone else gets the bare shell (the canvas's
7626
+ // module is refused to that frame anyway).
7627
+ const withInspector = inspect().injectInspector(shellHtml);
7628
+ let injected = withInspector;
7629
+ if (shellCanvasVisible(req, query)) {
7630
+ const pastMeta = await versionMetaFor(query);
7631
+ injected = injectVersionMeta(
7632
+ injectFallbacks(
7633
+ withInspector,
7634
+ ctx.paths.designRoot,
7635
+ ctx.cfg as unknown as Record<string, unknown>,
7636
+ query,
7637
+ pastMeta
7638
+ ),
7639
+ pastMeta
7640
+ );
7641
+ }
6321
7642
  const headers: Record<string, string> = {
6322
7643
  'Content-Type': 'text/html; charset=utf-8',
6323
7644
  'Cache-Control': 'no-store',
@@ -6365,25 +7686,10 @@ export function createHttp(
6365
7686
  '.ogg',
6366
7687
  ]);
6367
7688
 
6368
- // Exact API paths the canvas iframe needs (collab + display data). See
6369
- // isCanvasSafeRoute for the trust rationale. Mutations are limited to inert
6370
- // collab data (annotations SVG, comment replies via the dynamic route).
6371
- const CANVAS_SAFE_API = new Set([
6372
- '/_api/git-user', // presence display name
6373
- '/_api/canvas-meta', // layout/viewport sidecar (GET + PATCH)
6374
- '/_api/annotations', // annotation board (GET + whole-board PUT) — drives the collab bridge
6375
- '/_api/annotations/ops', // DDR-242 annotation op batches (POST). MIRROR in server.ts routes.
6376
- '/_api/asset', // Phase 23 — capped binary image upload (sniff+category cap+sha8 name+no-SVG)
6377
- // Issue #126 — chunked video/audio upload (fixed chunks, session cap, budget
6378
- // reserved at start, sniff on the reassembled stream). MIRROR in server.ts routes.
6379
- '/_api/asset/chunk-start',
6380
- '/_api/asset/chunk',
6381
- '/_api/asset/chunk-finish',
6382
- '/_api/photo-edit', // feature-photo-editor — PhotoEdit sidecar GET/PUT (cap-stack gated). MIRROR in server.ts routes.
6383
- '/_api/git-committers', // @mention autocomplete — a no-e-mail projection here (V2-2.8 S6)
6384
- '/_api/ai', // AI-activity banner
6385
- '/_comments', // per-file comment list (renders pins)
6386
- ]);
7689
+ // The canvas fall-through's exact paths: the hand-listed CANVAS_SAFE_API (module level, after
7690
+ // createHttp — V2-2.5 moved it there verbatim so a test can read it) plus the table's
7691
+ // `origin: 'canvas'` specs. test/canvas-origin-parity.test.ts holds it to the canvas map.
7692
+ const canvasSafeApi = new Set([...CANVAS_SAFE_API, ...laneRoutes.canvasPaths]);
6387
7693
 
6388
7694
  function isCanvasSafeRoute(pathname: string): boolean {
6389
7695
  // A1/A2 (DDR-060 F1 re-audit, phase-9.1-t2-f1-cross-origin-reaudit.md) —
@@ -6423,9 +7729,9 @@ export function createHttp(
6423
7729
  // execution, secrets, export, /_config, /_sync-status, or files outside
6424
7730
  // designRoot/annotations; the canvas origin's CSP `connect-src 'self'` still
6425
7731
  // confines the iframe so hub-pushed JSX can't reach IMDS/LAN/main-origin.
6426
- if (CANVAS_SAFE_API.has(safe)) return true;
7732
+ if (canvasSafeApi.has(safe)) return true;
6427
7733
  // POST /_api/comments/<id>/reply — dynamic path (fetch-handled).
6428
- if (/^\/_api\/comments\/[A-Za-z0-9_]+\/reply$/.test(safe)) return true;
7734
+ if (CANVAS_SAFE_DYNAMIC.some((re) => re.test(safe))) return true;
6429
7735
  const designPrefix = `/${ctx.paths.designRel.replace(/^\/+|\/+$/g, '')}/`;
6430
7736
  if (safe.startsWith(designPrefix)) {
6431
7737
  const rest = safe.slice(designPrefix.length);
@@ -6445,6 +7751,11 @@ export function createHttp(
6445
7751
  // "aggregate, not a specimen". It 403'd, so every canvas rendered with
6446
7752
  // its component styles missing and looked broken in a way that pointed
6447
7753
  // nowhere near this line.
7754
+ // …except Maude's two generated harness modules, by their exact shape
7755
+ // (draw-proof on the capture origin, photo-bg-remove on the canvas
7756
+ // origin — see LOCAL_HARNESS). Untrusted code on an untrusted origin,
7757
+ // like any canvas: nothing else under `_draw/` / `_photo/` is served.
7758
+ if (LOCAL_HARNESS.test(rest)) return true;
6448
7759
  if (rest.split('/')[0].startsWith('_')) return false;
6449
7760
  return CANVAS_ASSET_EXTS.has(ext(safe));
6450
7761
  }
@@ -6468,30 +7779,90 @@ export function createHttp(
6468
7779
  // covers all three doors at once: the main-origin `routes` table, the
6469
7780
  // canvas-origin `routes` allowlist in server.ts (it references these same
6470
7781
  // handlers), and the dynamic-path `fetch` fall-through (comment replies).
7782
+ //
7783
+ // S9.9 (V2-1.7 §5.4) — the role is now an ACCESS: the project role + canvas
7784
+ // grants, established per request by `accessOf`. A cell child reads the proxy's
7785
+ // `x-maude-access` claim (DEFAULT CLOSED: no proven edit role = read-only); a
7786
+ // desktop reads the linked hub's stored claim (`accessFor`, re-read each call so
7787
+ // a sign-in lands on the next write); an unlinked project is the owner's.
7788
+ function accessOf(req?: Request): Access {
7789
+ const base = isWorkspaceMode()
7790
+ ? accessFromProxy(req?.headers ?? new Headers())
7791
+ : accessForDesktop(ctx.cfg.linkedHub?.url, accessFor);
7792
+ // gate-b-c4 — on the canvas / capture listeners, the opener narrowed to the frame's canvas.
7793
+ const frame = currentFrame();
7794
+ return frame ? narrowToFrame(base, frame.canvases) : base;
7795
+ }
7796
+
7797
+ // gate-b-c4 — the per-frame capability's key material (access/frame.ts). The secret lives in
7798
+ // this machine's per-project state OUTSIDE the design root (gate-b-c4e: the canvas build can
7799
+ // inline any file under it; the old `_state/frame-cap.key` is deleted on boot); a key is per
7800
+ // SUBJECT: a desktop's is '' (the secret is its own), a cell's is the proxy's vouched member —
7801
+ // and a cell request without one gets no key (one shared key would let a capability baked into
7802
+ // canvas code verify for everybody).
7803
+ const frameSecret = loadFrameSecret(
7804
+ join(projectDir(pidOf(ctx.paths.repoRoot)), 'frame-cap.key'),
7805
+ join(ctx.paths.designRoot, '_state', 'frame-cap.key'),
7806
+ // gate-b-c4g (L2) — asserted at boot: never inside the design root or the repo.
7807
+ [ctx.paths.designRoot, ctx.paths.repoRoot]
7808
+ );
7809
+ function frameKeyOf(req?: Request): Buffer | null {
7810
+ if (!isWorkspaceMode()) return frameKeyFor(frameSecret, '');
7811
+ const subject = frameSubjectOf(req?.headers ?? new Headers());
7812
+ return subject ? frameKeyFor(frameSecret, subject) : null;
7813
+ }
7814
+ function frameScopeOf(req: Request): FrameScope {
7815
+ const key = frameKeyOf(req);
7816
+ // gate-b-c4k — the subject the key was minted for (the same rule as frameKeyOf): a desktop's is
7817
+ // '' whatever the request's headers say, so canvas code cannot rotate it for a fresh budget.
7818
+ const subject = isWorkspaceMode() ? (frameSubjectOf(req.headers) ?? '') : '';
7819
+ return { canvases: key ? verifyFrameCap(key, frameTokenOf(req)) : null, subject };
7820
+ }
7821
+ /** A capability for `canvases`, minted for the subject of `req` (headless callers, redirects). */
7822
+ function frameCapFor(req: Request | undefined, canvases: readonly string[]): string | null {
7823
+ const key = frameKeyOf(req);
7824
+ return key ? mintFrameCap(key, canvases) : null;
7825
+ }
7826
+
7827
+ /** May NOT edit at project level — the 1-bit projection old callers read. */
6471
7828
  function roleReadOnly(req?: Request): boolean {
6472
- // ---- Cloud Phase 27 A3/A4 (DDR-209): the role is PER SESSION ----------
6473
- //
6474
- // In a cell this process serves an owner and a viewer at the same time, so
6475
- // the on-disk answer below — one role per hub URL — is not merely stale, it
6476
- // is the wrong SHAPE. The proxy in front vouches a role per request and
6477
- // injects the capability it derived from the one role table.
6478
- //
6479
- // AND IT DEFAULTS CLOSED. The local path fails OPEN by design: `catch`
6480
- // returns false, an unset `linkedHub` returns false, and a fully writable
6481
- // studio is the correct answer for a tool running on your own laptop. On
6482
- // the internet it is the whole ballgame — so in a cloud build read-only is
6483
- // the default and an edit role requires positive proof.
6484
- if (isWorkspaceMode()) {
6485
- return req?.headers.get('x-maude-readonly') !== '0';
6486
- }
6487
- return ctx.cfg.linkedHub ? isHubReadOnly(ctx.cfg.linkedHub.url) : false;
7829
+ return !accessOf(req).can('edit', null);
7830
+ }
7831
+
7832
+ // The closure of a session's grants is computed HERE, from this child's own disk
7833
+ // (V2-1.7 G4), cached per (grants, generation); every file change bumps it. S9.10 —
7834
+ // one source per project (access/filters.ts), shared with api.ts's read filters.
7835
+ const designRel = relative(ctx.paths.repoRoot, ctx.paths.designRoot).split(sep).join('/');
7836
+ const tableSession = {
7837
+ exact: new Set(laneRoutes.readOnlyAllowed.exact),
7838
+ patterns: laneRoutes.readOnlyAllowed.patterns,
7839
+ };
7840
+ function gateInput(access: Access): GateInput {
7841
+ return {
7842
+ access,
7843
+ designRel,
7844
+ tableSession,
7845
+ closure: access.grants.length > 0 ? () => visibility.closureOf(access) : undefined,
7846
+ // S8.15 — a per-use photo edit that already holds these bytes is no overwrite
7847
+ exists: (rel, body) =>
7848
+ body === undefined
7849
+ ? existsSync(join(ctx.paths.designRoot, rel))
7850
+ : photoStore.holdsOther(rel, body),
7851
+ // S9.7b — a table route's own target (a reply by comment id: the thread's canvas);
7852
+ // S8.15 — /_api/photo-edit names its sidecar (the per-use one by the bytes it writes)
7853
+ targetFor: (req, pathname) =>
7854
+ pathname === '/_api/photo-edit'
7855
+ ? photoStore.gateTarget(req)
7856
+ : laneRoutes.targetFor(req, pathname),
7857
+ bodyFor: (req) => photoStore.gateBody(req),
7858
+ };
6488
7859
  }
6489
7860
 
6490
7861
  /**
6491
7862
  * V2-1.12 §5.6 — read-only for the ROLE, or because this build does not
6492
- * edit this project's FORMAT (format.ts `formatGate`: a 1.x build on a
6493
- * format-2 project). Every in-handler `projectReadOnly` check therefore
6494
- * covers both.
7863
+ * edit this project's FORMAT (format.ts `formatGate`: a v2 build on a
7864
+ * format-1 project until "Update project", a 1.x build on a format-2 one).
7865
+ * Every in-handler `projectReadOnly` check therefore covers both.
6495
7866
  */
6496
7867
  function projectReadOnly(req?: Request): boolean {
6497
7868
  return roleReadOnly(req) || gateNow() !== null;
@@ -6504,55 +7875,326 @@ export function createHttp(
6504
7875
  return gate ? formatRefusalResponse(gate) : readOnlyRefusalResponse();
6505
7876
  }
6506
7877
 
6507
- function readOnlyRefusal(req: Request): Response | null {
7878
+ // S9.9 (V2-1.7 §5.7) — the local gate. Was binary (read-only or not); now ONE
7879
+ // capability per write (access/request.ts `writeCapability`), checked against the
7880
+ // session's access — on the request's target canvas when the session has grants.
7881
+ // A canvas-only session naming a target outside its grants + closure is refused
7882
+ // with `not-in-scope` on ANY method (`canvasScopeRefusal`), the same 403 a missing
7883
+ // file gets.
7884
+ /** S9.11 — the session's seer (null = a project session, the identity). */
7885
+ function seerFor(req?: Request): Seer | null {
7886
+ const access = accessOf(req);
7887
+ return seerOf(access, () => closureOf(access));
7888
+ }
7889
+
7890
+ // gate-b-c4e — the design root in both spellings (the bundler reports real paths).
7891
+ const designRoots = [ctx.paths.designRoot];
7892
+ try {
7893
+ const real = realpathSync(ctx.paths.designRoot);
7894
+ if (real !== ctx.paths.designRoot) designRoots.push(real);
7895
+ } catch {
7896
+ /* gone — the logical spelling only */
7897
+ }
7898
+ /**
7899
+ * gate-b-c4e — a built canvas module reaches a canvas-only session (every frame on the canvas
7900
+ * and capture listeners is one) only when every design-root file it inlined is in that
7901
+ * session's closure (access/frame.ts `inputsRefusal`). A project session: no gate.
7902
+ */
7903
+ function canvasInputsGate(req: Request): CanvasInputsGate | undefined {
7904
+ const see = seerFor(req);
7905
+ if (see === null) return undefined;
7906
+ const gate: CanvasInputsGate = (inputs, entry) =>
7907
+ inputsRefusal(inputs, designRoots, see, { entry });
7908
+ // gate-b-c4l (L-b) — a canvas whose import walk the closure blocked is refused before the build.
7909
+ gate.before = (entry) => {
7910
+ const closure = closureOf(accessOf(req));
7911
+ if (!closure?.blocked.size) return null;
7912
+ for (const root of designRoots) {
7913
+ const rel = relative(root, resolve(entry)).split(sep).join('/');
7914
+ if (rel.startsWith('..') || rel === '') continue;
7915
+ return closure.blocked.has(rel) ? notInScopeResponse() : null;
7916
+ }
7917
+ return null;
7918
+ };
7919
+ return gate;
7920
+ }
7921
+
7922
+ function closureOf(access: Access): Closure | null {
7923
+ return access.grants.length > 0 ? visibility.closureOf(access) : null;
7924
+ }
7925
+
7926
+ // S9.21b — a canvas trashed while a tab has it open takes no writes (routes/trash.ts): a write the
7927
+ // access gate lets through but that names a canvas the shared Trash holds gets 409 in-trash.
7928
+ const trashWriteStop = createTrashWriteStop({
7929
+ control: () => ctx.syncControl?.current?.() ?? null,
7930
+ target: (req) => {
7931
+ let pathname = '';
7932
+ try {
7933
+ pathname = new URL(req.url).pathname;
7934
+ } catch {
7935
+ return Promise.resolve(null);
7936
+ }
7937
+ return laneRoutes.targetFor(req, pathname) ?? targetOf(req, designRel);
7938
+ },
7939
+ on: (e, fn) => ctx.bus.on(e, fn),
7940
+ emit: (e, p) => ctx.bus.emit(e, p),
7941
+ });
7942
+ const readOnlyRefusal = withTrashStop(accessRefusal, trashWriteStop, (req) => {
7943
+ try {
7944
+ return writeCapability(new URL(req.url).pathname, tableSession);
7945
+ } catch {
7946
+ return 'edit';
7947
+ }
7948
+ });
7949
+
7950
+ async function accessRefusal(req: Request): Promise<Response | null> {
7951
+ const access = accessOf(req);
7952
+ const g = gateInput(access);
7953
+ // S9.11 (V2-1.16 L15) — a file of the design root (the static lane, its `/assets/`
7954
+ // alias, `?sha=` builds) is judged on its PATH, before any query names a target: a
7955
+ // `?file=` of a visible canvas must not lend its answer to the module being served.
7956
+ if (access.canvasOnly) {
7957
+ let pathname = '';
7958
+ try {
7959
+ pathname = new URL(req.url).pathname;
7960
+ } catch {
7961
+ /* unparseable — the gates below refuse it */
7962
+ }
7963
+ const file = canvasOriginTarget(pathname, designRel);
7964
+ const see = seerOf(access, () => closureOf(access));
7965
+ if (file !== undefined && (file === null || see?.(file) !== true))
7966
+ return notInScopeResponse();
7967
+ }
7968
+ const scope = await canvasScopeRefusal(req, g);
7969
+ if (scope) return scope;
7970
+ // p8-c4 (403 sweep) — desktop-only project routes with no scope check of their own (U3).
7971
+ if (access.canvasOnly && canvasOnlyRefused(new URL(req.url).pathname))
7972
+ return notInScopeResponse();
6508
7973
  if (READ_ONLY_SAFE_METHODS.has(req.method)) return null;
6509
- const role = roleReadOnly(req);
6510
7974
  const gate = gateNow();
6511
- if (!role && !gate) return null;
6512
7975
  let pathname: string;
6513
7976
  try {
6514
7977
  pathname = new URL(req.url).pathname;
6515
7978
  } catch {
6516
7979
  return readOnlyRefusalFor(req);
6517
7980
  }
7981
+ // An editor passes every write it holds the capability for — not `delete` (S1.7b's Trash
7982
+ // clear-out is the owner's, V2-1.7 §5.2): that one goes on to `localGate`, which refuses it.
7983
+ if (!gate && access.can(writeCapability(pathname, g.tableSession), null)) return null;
6518
7984
  // The format gate: per-user runtime, export, reports and sign-in still
6519
- // work; comments are look-only (V2-1.12 §9 Q3).
7985
+ // work; comments are look-only (V2-1.12 §9 Q3); "Update project" is the
7986
+ // one write that leads out.
6520
7987
  if (gate && !formatGateAllowsWrite(pathname, readOnlyAllowed))
6521
7988
  return formatRefusalResponse(gate);
6522
- if (!role) return null;
6523
- if (readOnlyAllowed.exact.has(pathname)) return null;
6524
- // The dynamic half of the comment lane. An exact-match set cannot express
6525
- // it, and leaving it out would mean a viewer may leave a comment but not
6526
- // reply to one — a distinction nobody promised and nobody wants.
6527
- if (readOnlyAllowed.patterns.some((re) => re.test(pathname))) return null;
6528
- return readOnlyRefusalResponse();
7989
+ // S8.1 (V2-1.16 L7) — an ExportSpec v2 body names its target INSIDE `spec`, which the
7990
+ // generic target reader cannot see. For a session whose grants decide, the spec's own gate
7991
+ // answers (routes/export.ts `gateSpecV2`): Folder / Whole project and an ungranted canvas
7992
+ // are `not-in-scope` — the missing-file body — and every reached canvas must hold export.
7993
+ // S9.10 (V2-1.16 L7 / L10) — two write lanes whose TARGET is not a request param, for a
7994
+ // session whose grants (not its project role) decide: an export job's target is resolved
7995
+ // the way the exporter resolves it; a reply's canvas is its comment's, looked up among the
7996
+ // comments this session sees — so an invisible id is a missing one (U1).
7997
+ if (access.grants.length > 0 && req.method === 'POST') {
7998
+ // S8.4 — Retry names a job, not a canvas: the route gates every canvas its items reach
7999
+ if (pathname === '/_api/export-jobs/retry') return null;
8000
+ if (V2_EXPORT_DOORS.has(pathname)) {
8001
+ const body = (await req
8002
+ .clone()
8003
+ .json()
8004
+ .catch(() => null)) as { spec?: unknown } | null;
8005
+ if (pathname === '/_api/export-estimate' || isV2Body(body)) {
8006
+ const v2 = gateSpecV2(body?.spec, exportV2Deps, req);
8007
+ return v2.ok ? null : v2.response;
8008
+ }
8009
+ }
8010
+ const lane = await grantLaneRefusal(req, pathname, access);
8011
+ if (lane !== undefined) return lane;
8012
+ }
8013
+ const verdict = await localGate(req, pathname, g);
8014
+ if (verdict.ok) return null;
8015
+ return verdict.reason === 'not-in-scope' ? notInScopeResponse() : readOnlyRefusalResponse();
8016
+ }
8017
+
8018
+ /** S8.1 — the routes that take an ExportSpec v2 body (the estimate takes nothing else). */
8019
+ const V2_EXPORT_DOORS = new Set(['/_api/export', '/_api/export-jobs', '/_api/export-estimate']);
8020
+
8021
+ const EXPORT_TARGET_ROUTES = new Set(['/_api/export', '/_api/export-jobs']);
8022
+ const REPLY_RE = /^\/_api\/comments\/([A-Za-z0-9_]+)\/reply$/;
8023
+
8024
+ /** The refusal (or null = pass) for an export / reply by a grant session; undefined = not this lane. */
8025
+ async function grantLaneRefusal(
8026
+ req: Request,
8027
+ pathname: string,
8028
+ access: Access
8029
+ ): Promise<Response | null | undefined> {
8030
+ if (EXPORT_TARGET_ROUTES.has(pathname)) {
8031
+ if (access.can('export', null)) return undefined;
8032
+ const body = await req
8033
+ .clone()
8034
+ .json()
8035
+ .catch(() => null);
8036
+ const b = body && typeof body === 'object' ? (body as Record<string, unknown>) : {};
8037
+ if (!isScope(b.scope)) return undefined; // no target to judge: the role gate decides
8038
+ const options = b.options && typeof b.options === 'object' ? b.options : {};
8039
+ const targets =
8040
+ b.scope === 'project-raw'
8041
+ ? []
8042
+ : await resolveScope({
8043
+ scope: b.scope,
8044
+ activeJson: inspect().state as unknown as ActiveJsonShape,
8045
+ designRoot: ctx.paths.designRoot,
8046
+ repoRoot: ctx.paths.repoRoot,
8047
+ options: options as Record<string, unknown>,
8048
+ });
8049
+ const files = targets.flatMap((t) => (t.kind === 'element' ? [t.file] : []));
8050
+ const verdict = exportTargetVerdict(
8051
+ visibility.visibilityFor(access),
8052
+ b.scope,
8053
+ files,
8054
+ ctx.paths.designRel
8055
+ );
8056
+ if (verdict === 'ok') return null;
8057
+ return verdict === 'not-in-scope' ? notInScopeResponse() : readOnlyRefusalResponse();
8058
+ }
8059
+ const reply = REPLY_RE.exec(pathname);
8060
+ if (reply) {
8061
+ if (access.can('comment', null)) return undefined;
8062
+ // `loadAllComments` answers only the canvases this request's session sees.
8063
+ const all = await api.loadAllComments();
8064
+ const file = Object.entries(all).find(([, list]) => list.some((c) => c.id === reply[1]))?.[0];
8065
+ if (!file) return new Response('Not found', { status: 404 });
8066
+ const rel = toDesignRel(file, ctx.paths.designRel);
8067
+ return rel !== null && access.can('comment', rel) ? null : readOnlyRefusalResponse();
8068
+ }
8069
+ return undefined;
6529
8070
  }
6530
8071
 
6531
8072
  const guardedRoutes = Object.fromEntries(
6532
8073
  Object.entries(routes).map(([path, handler]) => [
6533
8074
  path,
6534
- (req: Request) => readOnlyRefusal(req) ?? handler(req),
8075
+ async (req: Request) => (await readOnlyRefusal(req)) ?? handler(req),
6535
8076
  ])
6536
- ) as typeof routes;
8077
+ ) as unknown as typeof routes;
6537
8078
 
6538
8079
  async function guardedFetch(req: Request): Promise<Response> {
6539
- return readOnlyRefusal(req) ?? handleFallthrough(req);
8080
+ return (await readOnlyRefusal(req)) ?? handleFallthrough(req);
8081
+ }
8082
+
8083
+ /**
8084
+ * DDR-242 §4 — the canvas write path: an op batch applied under the one merge rule.
8085
+ * Canvas-origin reachable (inert collab data, DDR-054) — every op is validated
8086
+ * element-by-element and the board stays capped.
8087
+ * POST body { file, actionId, ops: Op[] } → 200 { ok, changed, rejected[] }
8088
+ * T-S4.5b — `actionId: 'run:<runId>'` (contract S4-S5-ai-annotations §2) is accepted only on
8089
+ * the main listener, same-origin, while that run is open (annotations/run-tag.ts); a refused
8090
+ * tag writes nothing.
8091
+ */
8092
+ async function annotationOps(req: Request, listener: 'main' | 'canvas'): Promise<Response> {
8093
+ if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
8094
+ const body = await readJson<{ file?: unknown; actionId?: unknown; ops?: unknown }>(
8095
+ req,
8096
+ MAX_ANNOTATIONS_BYTES + 2048
8097
+ );
8098
+ if (!body || typeof body.file !== 'string' || !body.file) {
8099
+ return new Response('body must include { file, actionId, ops }', { status: 400 });
8100
+ }
8101
+ const tag = runTagGate(req, body.actionId, {
8102
+ listener,
8103
+ runs,
8104
+ sameOrigin: (r) => sameOriginWrite(r) && sameOriginRead(r) && isTrustedRequestHost(r),
8105
+ });
8106
+ if ('refusal' in tag) return runTagRefusalResponse(tag.refusal);
8107
+ if (
8108
+ tag.runId === null &&
8109
+ body.actionId !== undefined &&
8110
+ !validAnnotationWriteId(body.actionId)
8111
+ ) {
8112
+ return new Response('invalid actionId', { status: 400 });
8113
+ }
8114
+ if (!Array.isArray(body.ops)) return new Response('body.ops must be an array', { status: 400 });
8115
+ // Bounded to what a whole board can need (select-all + delete on a full
8116
+ // board) and REFUSED past it — never truncated, which would half-apply a
8117
+ // gesture. Batch cost is linear in the ops (ops.ts indexes).
8118
+ if (body.ops.length > MAX_ELEMENTS) {
8119
+ return new Response('too many ops in one batch', { status: 413 });
8120
+ }
8121
+ const { ops } = parseAnnotationOps(body.ops, MAX_ELEMENTS);
8122
+ // sec-a M1 — no HTTP caller (canvas or main origin) writes a vote or a ballot: those land
8123
+ // only through the vote door (routes/votes.ts → api.applyAnnotationOps in-process).
8124
+ const r = await api.applyAnnotationOps(body.file, ops, body.actionId as string | undefined, {
8125
+ guard: voteDoorOnly,
8126
+ });
8127
+ if (r.refused) {
8128
+ return Response.json(
8129
+ { ok: false, changed: false, rejected: [], error: VOTE_DOOR_REFUSAL },
8130
+ { status: 403, headers: { 'Cache-Control': 'no-store' } }
8131
+ );
8132
+ }
8133
+ return Response.json(r, {
8134
+ status: r.ok ? 200 : r.unreadable ? 409 : 413,
8135
+ headers: { 'Cache-Control': 'no-store' },
8136
+ });
6540
8137
  }
6541
8138
 
6542
8139
  const canvasRoutes: Http['canvasRoutes'] = {
8140
+ // T-S4.5b — the same op path, minus the `run:` tag (refused 400 here). A write: it keeps the
8141
+ // read-only refusal every `routes` entry carries (guardedRoutes).
8142
+ // S9.9 made the gate async: await it, or the pending Promise short-circuits `??`.
8143
+ '/_api/annotations/ops': async (req: Request) =>
8144
+ (await readOnlyRefusal(req)) ?? annotationOps(req, 'canvas'),
6543
8145
  // V2-2.8 S6 — the @mention feed without e-mails (see canvasCommitters).
6544
8146
  '/_api/git-committers': async (req: Request) => {
6545
8147
  if (req.method !== 'GET') return new Response('Method not allowed', { status: 405 });
6546
8148
  const committers = canvasCommitters(await api.gitCommitters());
6547
8149
  return Response.json({ committers }, { headers: { 'Cache-Control': 'no-store' } });
6548
8150
  },
8151
+ // V2-8.9 r2 L1 — the presence name without the OS-account fallback (see canvasUserName). In a cell
8152
+ // the proxy's vouched member name, as on the main origin.
8153
+ '/_api/git-user': async (req: Request) => {
8154
+ if (req.method !== 'GET') return new Response('Method not allowed', { status: 405 });
8155
+ const vouched = req.headers.get('x-maude-user');
8156
+ const name =
8157
+ isWorkspaceMode() && vouched ? vouched : canvasUserName(await api.gitCurrentUser());
8158
+ return Response.json({ name }, { headers: { 'Cache-Control': 'no-store' } });
8159
+ },
6549
8160
  };
6550
8161
 
6551
8162
  return {
6552
8163
  routes: guardedRoutes,
6553
8164
  canvasRoutes,
8165
+ tableCanvasPaths: laneRoutes.canvasPaths,
8166
+ accessOf,
8167
+ frameScopeOf,
8168
+ closureOf,
6554
8169
  fetch: guardedFetch,
6555
8170
  serveCanvasShell,
6556
8171
  isCanvasSafeRoute,
8172
+ askQueue,
6557
8173
  };
6558
8174
  }
8175
+
8176
+ // Exact API paths the canvas iframe needs (collab + display data). See
8177
+ // isCanvasSafeRoute for the trust rationale. Mutations are limited to inert
8178
+ // collab data (annotations SVG, comment replies via the dynamic route).
8179
+ // V2-2.5 — moved verbatim out of createHttp (exported for the parity test). Each entry needs its
8180
+ // MIRROR in routes/canvas-origin.ts; a NEW canvas-safe route is an `origin: 'canvas'` table spec
8181
+ // instead, which both lists derive.
8182
+ export const CANVAS_SAFE_API: ReadonlySet<string> = new Set([
8183
+ '/_api/git-user', // presence display name
8184
+ '/_api/canvas-meta', // layout/viewport sidecar (GET + PATCH)
8185
+ '/_api/annotations', // annotation board (GET + whole-board PUT) — drives the collab bridge
8186
+ '/_api/annotations/ops', // DDR-242 annotation op batches (POST). MIRROR in routes/canvas-origin.ts.
8187
+ '/_api/asset', // Phase 23 — capped binary image upload (sniff+category cap+sha8 name+no-SVG)
8188
+ // Issue #126 — chunked video/audio upload (fixed chunks, session cap, budget
8189
+ // reserved at start, sniff on the reassembled stream). MIRROR in routes/canvas-origin.ts.
8190
+ '/_api/asset/chunk-start',
8191
+ '/_api/asset/chunk',
8192
+ '/_api/asset/chunk-finish',
8193
+ '/_api/photo-edit', // feature-photo-editor — PhotoEdit sidecar GET/PUT (cap-stack gated). MIRROR in routes/canvas-origin.ts.
8194
+ '/_api/git-committers', // @mention autocomplete — a no-e-mail projection here (V2-2.8 S6)
8195
+ '/_comments', // per-file comment list (renders pins)
8196
+ ]);
8197
+
8198
+ /** The canvas origins' ONE dynamic path (fetch-handled, in no routes map): POST
8199
+ * /_api/comments/<id>/reply. A new dynamic canvas route is not added here. */
8200
+ export const CANVAS_SAFE_DYNAMIC: readonly RegExp[] = [/^\/_api\/comments\/[A-Za-z0-9_]+\/reply$/];