@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
@@ -0,0 +1,2725 @@
1
+ // The local home — the one op log for a project with no hub (S5.1b).
2
+ //
3
+ // The hub's acceptance kernel and store core (`apps/hub/src/project-
4
+ // transactions/kernel.mjs` + `store-core.mjs`) run here, in the studio process,
5
+ // over `bun:sqlite` at `<designRoot>/_state/project-store.sqlite` (V2-1.5 §5.6,
6
+ // S5-kernel-foundation §4). Nothing here forks the log: the same envelope, the
7
+ // same effects, the same undo — so `/_api/project/{history,undo,restore}` stop
8
+ // answering `legacy` for a local project and no route learns which home
9
+ // answered (foundation §5).
10
+ //
11
+ // What makes it different from a hub is only WHERE the content lives: the disk
12
+ // already holds it, so there is no projection. A change on disk is PROPOSED by
13
+ // the watcher feed (`observe`) as an ordinary action of `kind: 'outside'`; an
14
+ // accepted undo / restore is PUBLISHED by writing the files back
15
+ // (`applyAccepted`). Every file write here first checks the disk still holds
16
+ // what the store last recorded — an unrecorded byte on disk (a half-typed edit
17
+ // the source gate refused) is never overwritten.
18
+ //
19
+ // S1's four conditions for the local store (V2-1.9 §5.3) are part of it:
20
+ // C1 one machine per store — `store_meta.machine`; a copied store is renamed
21
+ // `project-store.<machine>.sqlite` and only ever opened read-only;
22
+ // C2 one writer — `_state/project-store.lock` `{ pid, bootId, machine, at }`;
23
+ // a second studio on the folder opens the store read-only;
24
+ // C3 baseline — one `migration.import` action per canvas on the first boot;
25
+ // C4 gzip bodies — `createStoreCore(sql, { codec: GZIP_CODEC })`.
26
+ //
27
+ // None of these paths is a new runtime class: `_state/` is already ignored in
28
+ // all four DDR-115 lists.
29
+
30
+ import { Database } from 'bun:sqlite';
31
+ import { randomUUID } from 'node:crypto';
32
+ import {
33
+ closeSync,
34
+ existsSync,
35
+ mkdirSync,
36
+ openSync,
37
+ readdirSync,
38
+ readFileSync,
39
+ renameSync,
40
+ statSync,
41
+ unlinkSync,
42
+ writeSync,
43
+ } from 'node:fs';
44
+ import { homedir, hostname, uptime } from 'node:os';
45
+ import path from 'node:path';
46
+ import { gunzipSync, gzipSync } from 'node:zlib';
47
+
48
+ import { MIGRATION_ACTOR } from '../../hub/src/project-transactions/baseline.mjs';
49
+ import { createKernel, EMPTY_HASH, PROTOCOL } from '../../hub/src/project-transactions/kernel.mjs';
50
+ import { laneHash, mergeLane } from '../../hub/src/project-transactions/lanes.mjs';
51
+ import { createStoreCore } from '../../hub/src/project-transactions/store-core.mjs';
52
+ import { claimWrite, currentWriteClaim, recordClaim } from '../ai/write-claim.ts';
53
+ import { serializeBoard } from '../annotations/schema.ts';
54
+ import {
55
+ boardTextSlots,
56
+ changedTextSlots,
57
+ createTextStepLedger,
58
+ } from '../annotations/text-steps.ts';
59
+ import { isDraftWriteId } from '../annotations/ui/text-session.ts';
60
+ import { attributeArtboards } from '../attribute-artboards.ts';
61
+ import { canvasSlugFromRel } from '../canvas-slug.ts';
62
+ import { bumpTrashSeq, type TrashListing } from '../history/trash.ts';
63
+ import { createActionStage, type RunFence, type RunStageSummary } from './action-stage.ts';
64
+ import { atomicWrite } from './atomic-write.ts';
65
+ import { validateCanvasPath } from './canvas-path.ts';
66
+ import { laneValueFromFile, mergeSharedMetaIntoLocal } from './codec.ts';
67
+ import { hashBytes } from './echo-guard.ts';
68
+ import { canvasLanes, namedField, type RowNamed } from './history-fields.ts';
69
+ import { type HubEffect, hubTextUndoConflict } from './hub-text-undo.ts';
70
+ import { mergeSource } from './source-merge.ts';
71
+ import { type ParkedCanvas, removeClearedCopies } from './trash-clear-copies.ts';
72
+ import {
73
+ asTarget,
74
+ chatActionIds,
75
+ originFields,
76
+ type UndoTarget,
77
+ undoLabel,
78
+ } from './undo-target.ts';
79
+
80
+ /* ------------------------------------------------------------------ files */
81
+
82
+ export const STORE_FILE = 'project-store.sqlite';
83
+ export const LOCK_FILE = 'project-store.lock';
84
+ /** S5.5b — this home's held AI runs (V2-1.5 §5.5), apart from the hub link's `ai-stage.json`. */
85
+ export const AI_STAGE_FILE = 'ai-stage-local.json';
86
+ /** S5.5b — how long a studio write's content note waits for the watcher to read it. */
87
+ export const WRITE_NOTE_MS = 30_000;
88
+ /** p8-e2e-fix-r12 — at most this many superseded studio writes of one canvas wait for the watcher. */
89
+ const MAX_SUPERSEDED = 16;
90
+
91
+ /** The studio said it wrote a lane (`noteWritten` / `noteLane`); `baseHash` = the bytes the write replaced. */
92
+ type Note = {
93
+ hash: string;
94
+ at: number;
95
+ label?: string;
96
+ early?: true;
97
+ content?: string;
98
+ baseHash?: string;
99
+ };
100
+ /** The label a person's studio edit carries (the hub link's `LANE_LABEL.html`). */
101
+ export const STUDIO_EDIT_LABEL = 'Edit canvas';
102
+ /** S2.20b (U20) — the hub link's `LANE_LABEL` per local lane: a layout move, an annotation stroke. */
103
+ export const STUDIO_LANE_LABEL = {
104
+ html: STUDIO_EDIT_LABEL,
105
+ meta: 'Edit layout',
106
+ annotations: 'Edit annotations',
107
+ } as const;
108
+ /** A foreign machine's store, kept read-only (C1). */
109
+ export const FOREIGN_STORE = /^project-store\.([A-Za-z0-9_-]{1,64})\.sqlite$/;
110
+ const SQLITE_SIDECARS = ['', '-wal', '-shm'] as const;
111
+
112
+ /** The lanes a local canvas carries. Comments stay per machine (`_comments/`). */
113
+ export const LOCAL_LANES = ['html', 'meta', 'annotations'] as const;
114
+ type LocalLane = (typeof LOCAL_LANES)[number];
115
+ /**
116
+ * The lanes the watcher records from disk. The board (and the comments a
117
+ * conversion touches) have a second writer — the collab room projects onto
118
+ * them — so, as on a hub link (projection.ts), they are never proposed from a
119
+ * file event: they reach the store only as an explicit action (S4.7
120
+ * `proposeLanes`), and an accepted undo merges back into what the disk holds.
121
+ */
122
+ const WATCHED_LANES = ['html', 'meta'] as const;
123
+ /** S4.7 — lanes only an explicit action writes; published three-way onto the disk. */
124
+ const EXPLICIT_LANES = ['annotations', 'comments'] as const;
125
+ type ExplicitLane = (typeof EXPLICIT_LANES)[number];
126
+ const isExplicit = (lane: string): lane is ExplicitLane =>
127
+ (EXPLICIT_LANES as readonly string[]).includes(lane);
128
+
129
+ /** What the watcher's actions say (V2-1.9 §5.2). */
130
+ export const OUTSIDE_KIND = 'outside';
131
+ export const BASELINE_KIND = 'migration.import';
132
+ export const BASELINE_LABEL = 'Version history starts here';
133
+ /** How long a burst of fs events on one canvas settles before it is proposed. */
134
+ export const OBSERVE_SETTLE_MS = 300;
135
+ /** How long a move the studio announced holds the watcher's view of its two paths. */
136
+ export const MOVE_HOLD_MS = 30_000;
137
+ /** How often a read-only studio asks whether the writer has gone (C2). */
138
+ export const LOCK_RETRY_MS = 5_000;
139
+
140
+ /* ------------------------------------------------------------- identities */
141
+
142
+ export interface MachineIdentity {
143
+ /** Stable for this install — never per project copy. */
144
+ id: string;
145
+ /** "History from <name>" (V2-1.9 §5.3 C1). */
146
+ name: string;
147
+ }
148
+
149
+ const MACHINE_ID = /^[A-Za-z0-9_-]{1,64}$/;
150
+
151
+ /** `~/.config/maude/machine.json` (XDG-aware; `MAUDE_MACHINE_FILE` overrides). */
152
+ export function machineIdentityPath(env: NodeJS.ProcessEnv = process.env): string {
153
+ if (env.MAUDE_MACHINE_FILE) return env.MAUDE_MACHINE_FILE;
154
+ const xdg = env.XDG_CONFIG_HOME;
155
+ const base = xdg && xdg.length > 0 ? xdg : path.join(homedir(), '.config');
156
+ return path.join(base, 'maude', 'machine.json');
157
+ }
158
+
159
+ /** This install's identity, created once. */
160
+ export function machineIdentity(file: string = machineIdentityPath()): MachineIdentity {
161
+ try {
162
+ const v = JSON.parse(readFileSync(file, 'utf8')) as Partial<MachineIdentity>;
163
+ if (typeof v.id === 'string' && MACHINE_ID.test(v.id)) {
164
+ return { id: v.id, name: typeof v.name === 'string' && v.name ? v.name : v.id };
165
+ }
166
+ } catch {
167
+ /* absent or unreadable — mint one below */
168
+ }
169
+ const id = `m_${randomUUID().replace(/-/g, '')}`;
170
+ let name = 'this Mac';
171
+ try {
172
+ name =
173
+ hostname()
174
+ .replace(/\.local$/i, '')
175
+ .slice(0, 64) || name;
176
+ } catch {
177
+ /* keep the default */
178
+ }
179
+ const ident = { id, name };
180
+ try {
181
+ atomicWrite(file, `${JSON.stringify(ident, null, 2)}\n`);
182
+ } catch (err) {
183
+ console.warn(`[local-kernel] could not save the machine id at ${file}:`, err);
184
+ }
185
+ return ident;
186
+ }
187
+
188
+ /**
189
+ * This boot of the operating system. A lock whose pid is alive but whose boot
190
+ * differs belongs to a pid from before a restart (a reused number).
191
+ */
192
+ export function bootIdentity(): string {
193
+ try {
194
+ if (process.platform === 'linux') {
195
+ return readFileSync('/proc/sys/kernel/random/boot_id', 'utf8').trim();
196
+ }
197
+ if (process.platform === 'darwin') {
198
+ const r = Bun.spawnSync(['sysctl', '-n', 'kern.bootsessionuuid'], { stderr: 'ignore' });
199
+ const out = r.stdout.toString().trim();
200
+ if (r.exitCode === 0 && out) return out;
201
+ }
202
+ } catch {
203
+ /* fall through to the uptime estimate */
204
+ }
205
+ // Boot time to the minute: stable across this boot, different after one.
206
+ return `t${Math.floor((Date.now() / 1000 - uptime()) / 60)}`;
207
+ }
208
+
209
+ /* ------------------------------------------------------------ sql + codec */
210
+
211
+ interface SqlAdapter {
212
+ exec(query: string, ...params: unknown[]): Record<string, unknown>[];
213
+ transaction<T>(fn: () => T): T;
214
+ }
215
+
216
+ /** The synchronous `{ exec, transaction }` interface store-core takes. */
217
+ export function bunSqliteAdapter(db: Database): SqlAdapter {
218
+ const cache = new Map<string, ReturnType<Database['query']>>();
219
+ const statement = (q: string) => {
220
+ let s = cache.get(q);
221
+ if (!s) {
222
+ s = db.query(q);
223
+ cache.set(q, s);
224
+ }
225
+ return s;
226
+ };
227
+ return {
228
+ exec(query, ...params) {
229
+ const s = statement(query);
230
+ const args = params as never[];
231
+ if (s.columnNames.length > 0) return s.all(...args) as Record<string, unknown>[];
232
+ s.run(...args);
233
+ return [];
234
+ },
235
+ transaction(fn) {
236
+ return db.transaction(fn)();
237
+ },
238
+ };
239
+ }
240
+
241
+ /** C4 — gzip lane bodies; a plain TEXT row written before the codec still reads. */
242
+ export const GZIP_CODEC = Object.freeze({
243
+ encode: (text: string): Uint8Array => gzipSync(Buffer.from(text, 'utf8')),
244
+ decode: (stored: unknown): string =>
245
+ typeof stored === 'string'
246
+ ? stored
247
+ : gunzipSync(Buffer.from(stored as Uint8Array)).toString('utf8'),
248
+ });
249
+
250
+ /* ------------------------------------------------------------------- lock */
251
+
252
+ export interface LockRecord {
253
+ pid: number;
254
+ bootId: string;
255
+ machine: string;
256
+ at: number;
257
+ token: string;
258
+ }
259
+
260
+ export type LockOutcome =
261
+ | { held: true; release(): void; record: LockRecord }
262
+ | { held: false; holder: LockRecord | null };
263
+
264
+ function pidAlive(pid: number): boolean {
265
+ try {
266
+ process.kill(pid, 0);
267
+ return true;
268
+ } catch (err) {
269
+ // EPERM: alive, someone else's. ESRCH: gone.
270
+ return (err as NodeJS.ErrnoException).code === 'EPERM';
271
+ }
272
+ }
273
+
274
+ function readLock(file: string): { raw: string; rec: LockRecord | null } | null {
275
+ let raw: string;
276
+ try {
277
+ raw = readFileSync(file, 'utf8');
278
+ } catch {
279
+ return null;
280
+ }
281
+ try {
282
+ const v = JSON.parse(raw) as LockRecord;
283
+ if (Number.isSafeInteger(v.pid) && typeof v.bootId === 'string') return { raw, rec: v };
284
+ } catch {
285
+ /* torn / foreign bytes — stale */
286
+ }
287
+ return { raw, rec: null };
288
+ }
289
+
290
+ /**
291
+ * C2 — take `project-store.lock`, exclusively. A lock held by a live process of
292
+ * this boot on this machine is respected; one whose pid is gone, whose boot
293
+ * differs, or which another machine wrote (a copied folder) is taken over.
294
+ */
295
+ export function acquireStoreLock(
296
+ file: string,
297
+ me: { pid: number; bootId: string; machine: string; now?: () => number }
298
+ ): LockOutcome {
299
+ const record: LockRecord = {
300
+ pid: me.pid,
301
+ bootId: me.bootId,
302
+ machine: me.machine,
303
+ at: (me.now ?? Date.now)(),
304
+ token: randomUUID(),
305
+ };
306
+ mkdirSync(path.dirname(file), { recursive: true });
307
+ for (let attempt = 0; attempt < 2; attempt++) {
308
+ try {
309
+ const fd = openSync(file, 'wx', 0o600);
310
+ writeSync(fd, `${JSON.stringify(record)}\n`);
311
+ closeSync(fd);
312
+ return {
313
+ held: true,
314
+ record,
315
+ release() {
316
+ // Only our own lock: a takeover after we hung must not be undone.
317
+ if (readLock(file)?.rec?.token === record.token) {
318
+ try {
319
+ unlinkSync(file);
320
+ } catch {
321
+ /* already gone */
322
+ }
323
+ }
324
+ },
325
+ };
326
+ } catch (err) {
327
+ if ((err as NodeJS.ErrnoException).code !== 'EEXIST') throw err;
328
+ }
329
+ const cur = readLock(file);
330
+ if (!cur) continue; // released between the two calls
331
+ const h = cur.rec;
332
+ const live =
333
+ h !== null && h.machine === me.machine && h.bootId === me.bootId && pidAlive(h.pid);
334
+ if (live) return { held: false, holder: h };
335
+ // Stale. Remove it only if it is still the bytes we judged.
336
+ if (readLock(file)?.raw === cur.raw) {
337
+ try {
338
+ unlinkSync(file);
339
+ } catch {
340
+ /* someone else took it over first */
341
+ }
342
+ }
343
+ }
344
+ return { held: false, holder: readLock(file)?.rec ?? null };
345
+ }
346
+
347
+ /* ------------------------------------------------------------------ store */
348
+
349
+ type AsyncStore = Record<string, (...args: unknown[]) => Promise<any>>;
350
+
351
+ /** The kernel as this module drives it (the `.mjs` carries no types). */
352
+ interface KernelLike {
353
+ submit(
354
+ bytes: string,
355
+ auth: { actor: string; can?: (cap: string) => boolean }
356
+ ): Promise<{ status: number; body: any }>;
357
+ }
358
+ const makeKernel = createKernel as unknown as (o: Record<string, unknown>) => KernelLike;
359
+
360
+ interface OpenedStore {
361
+ db: Database;
362
+ store: AsyncStore;
363
+ core: Record<string, (...args: unknown[]) => any>;
364
+ sql: SqlAdapter;
365
+ }
366
+
367
+ function openStore(
368
+ file: string,
369
+ { readonly, now }: { readonly: boolean; now: () => number }
370
+ ): OpenedStore {
371
+ const db = readonly
372
+ ? new Database(file, { readonly: true })
373
+ : new Database(file, { create: true, readwrite: true });
374
+ if (!readonly) {
375
+ db.exec('PRAGMA journal_mode = WAL');
376
+ db.exec('PRAGMA synchronous = FULL');
377
+ db.exec('PRAGMA foreign_keys = ON');
378
+ }
379
+ db.exec('PRAGMA busy_timeout = 2000');
380
+ const sql = bunSqliteAdapter(db);
381
+ const core = createStoreCore(sql, { now, codec: GZIP_CODEC }) as unknown as OpenedStore['core'];
382
+ if (!readonly) core.migrate();
383
+ const store: AsyncStore = {};
384
+ for (const [name, fn] of Object.entries(core)) {
385
+ if (name === 'migrate') continue;
386
+ store[name] = async (...args: unknown[]) => fn(...args);
387
+ }
388
+ return { db, store, core, sql };
389
+ }
390
+
391
+ function storeMachine(sql: SqlAdapter): string | null {
392
+ try {
393
+ const row = sql.exec(`SELECT v FROM store_meta WHERE k = 'machine'`)[0];
394
+ return row ? String(row.v) : null;
395
+ } catch {
396
+ return null; // a store with no schema yet
397
+ }
398
+ }
399
+
400
+ function setStoreMeta(sql: SqlAdapter, k: string, v: string): void {
401
+ sql.exec(
402
+ `INSERT INTO store_meta (k, v) VALUES (?, ?) ON CONFLICT(k) DO UPDATE SET v = excluded.v`,
403
+ k,
404
+ v
405
+ );
406
+ }
407
+
408
+ function readStoreMeta(sql: SqlAdapter, k: string): string | null {
409
+ const row = sql.exec(`SELECT v FROM store_meta WHERE k = ?`, k)[0];
410
+ return row ? String(row.v) : null;
411
+ }
412
+
413
+ const sanitizeMachine = (m: string) => m.replace(/[^A-Za-z0-9_-]/g, '_').slice(0, 64) || 'unknown';
414
+
415
+ /** Move a store (and its WAL sidecars) aside as a foreign machine's copy. */
416
+ function moveAside(stateDir: string, machine: string): string {
417
+ const base = `project-store.${sanitizeMachine(machine)}`;
418
+ let target = path.join(stateDir, `${base}.sqlite`);
419
+ for (let n = 2; existsSync(target); n++) {
420
+ target = path.join(stateDir, `${base}-${n}.sqlite`.slice(0, 80));
421
+ }
422
+ const from = path.join(stateDir, STORE_FILE);
423
+ for (const s of SQLITE_SIDECARS) {
424
+ if (existsSync(`${from}${s}`)) renameSync(`${from}${s}`, `${target}${s}`);
425
+ }
426
+ return target;
427
+ }
428
+
429
+ /* ------------------------------------------------------------- the runtime */
430
+
431
+ export interface LocalHistoryRow {
432
+ revision: number;
433
+ actionId: string;
434
+ actor: string;
435
+ mine: boolean;
436
+ kind: string;
437
+ label: string | null;
438
+ committedAt: number;
439
+ undoes: string | string[] | null;
440
+ /** Design-root-relative canvas paths the action touched. */
441
+ canvases: string[];
442
+ /** S1.12b — per canvas, the lanes the action touched there (additive). */
443
+ lanes: Record<string, string[]>;
444
+ /** S1.12b — a `name` action's target revision and name (`origin.named`; null clears). */
445
+ named?: RowNamed;
446
+ /** V2-1.5 §5.1 origin keys (S5.5). */
447
+ runId?: string;
448
+ chatId?: string;
449
+ madeAt?: number;
450
+ partial?: true;
451
+ }
452
+
453
+ export type LocalOutcome = {
454
+ status: 'accepted' | 'rejected';
455
+ code?: string;
456
+ actionId?: string;
457
+ revision?: number;
458
+ undoes?: string | string[];
459
+ skipped?: Array<{
460
+ doc?: string;
461
+ lane?: string;
462
+ id?: string;
463
+ reason: string;
464
+ conflictWith?: string;
465
+ }>;
466
+ /** S1.7 — trash.restore: where the canvas came back; trash.clear: the ids cleared. */
467
+ path?: string;
468
+ cleared?: string[];
469
+ };
470
+
471
+ /**
472
+ * S1.13 (V2-1.9 §5.8) — a restore that is not "the whole canvas at a revision": the studio computed
473
+ * the lanes (history/restore-artboard.ts, restore-object.ts, an aside body) and proposes them as ONE
474
+ * `kind: 'restore'` action, each `lane.replace` carrying `baseContent` = the head it read, so the
475
+ * kernel merges three-way onto whatever landed since. `label` alone relabels a whole restore.
476
+ */
477
+ export interface RestoreOptions {
478
+ label?: string;
479
+ lanes?: Array<{
480
+ lane: 'html' | 'css' | 'meta' | 'annotations';
481
+ content: string;
482
+ baseContent: string;
483
+ }>;
484
+ }
485
+
486
+ /** The `ctx.syncControl.current()` surface a local project answers through. */
487
+ export interface LocalRuntime {
488
+ cancelAssetSweep(): boolean;
489
+ /**
490
+ * S4.7 — several lanes of one canvas as ONE action (sync/index.ts `proposeLanes`). `o.origin`
491
+ * (S1.13b): envelope origin keys the kernel keeps, e.g. an artboard-trash action's
492
+ * `trashed` (S1-trash.md §2).
493
+ */
494
+ proposeLanes(
495
+ slug: string,
496
+ lanes: Array<{ lane: string; text: string; baseText: string }>,
497
+ o: { kind: string; label: string; origin?: Record<string, unknown> }
498
+ ): Promise<LocalOutcome>;
499
+ acceptedHistory(q: {
500
+ limit?: number;
501
+ before?: number | null;
502
+ path?: string | null;
503
+ chat?: string | null;
504
+ kind?: string | null;
505
+ mine?: boolean;
506
+ }): Promise<LocalHistoryRow[]>;
507
+ /**
508
+ * S1.11 — `lane`: the source (default), or its meta; the local store has no CSS lane (→ null).
509
+ * S1.13 — `{ aside: true }`: the body a `history.aside` at exactly `revision` kept for that lane.
510
+ */
511
+ acceptedVersion(
512
+ repoRel: string,
513
+ revision: number,
514
+ lane?: 'html' | 'css' | 'meta' | 'annotations',
515
+ o?: { aside?: boolean }
516
+ ): Promise<string | null>;
517
+ /** S1.13 — `o.lanes`: one artboard / object / kept-aside restore, ONE `restore` action. */
518
+ acceptedRestore(repoRel: string, revision: number, o?: RestoreOptions): Promise<LocalOutcome>;
519
+ /** S1.12b — `history.name` (V2-1.9 §5.4); `null` clears. */
520
+ acceptedName(repoRel: string, revision: number, name: string | null): Promise<LocalOutcome>;
521
+ /** S1.12b — `history.aside`: a version nobody kept, no head moves. */
522
+ acceptedAside(
523
+ repoRel: string,
524
+ lane: 'html' | 'css' | 'meta' | 'annotations',
525
+ content: string,
526
+ label?: string
527
+ ): Promise<LocalOutcome>;
528
+ /** S5.15 (U22) — always true: the in-process kernel takes `actionIds`. */
529
+ chatUndoReady(): boolean;
530
+ acceptedUndo(
531
+ target: string | UndoTarget,
532
+ redo?: boolean,
533
+ o?: { via?: 'keys' | 'panel' }
534
+ ): Promise<LocalOutcome>;
535
+ /**
536
+ * S10.2 — an app gesture that changes several canvas files (a design-system publish: metas +
537
+ * TSX) as ONE action. Each file's lane value is proposed against the store head; nothing is
538
+ * written here — on acceptance `publish` writes the files, exactly as for an undo. Files that
539
+ * already hold the value add nothing; none left → accepted with no action.
540
+ */
541
+ proposeFiles(
542
+ files: { rel: string; text: string }[],
543
+ action: { kind: string; label: string | null }
544
+ ): Promise<LocalOutcome>;
545
+ /** S1.7 — the shared Trash (history/trash.ts `TrashRuntime`). */
546
+ acceptedTrash(): Promise<TrashListing | null>;
547
+ acceptedTrashRestore(entry: string): Promise<LocalOutcome>;
548
+ acceptedTrashClear(items?: string[]): Promise<LocalOutcome>;
549
+ /** S1.18 — the manifest rows a stable link resolves over (history/links.ts). */
550
+ acceptedLinkDocs(): Promise<{ entry: string; path: string | null; retired: boolean }[] | null>;
551
+ /** S1.18 — is the entry in the shared Trash (cleared items excluded)? */
552
+ acceptedTrashed(entry: string): Promise<boolean>;
553
+ /** S5.5b (U21) — the same run-stage surface the hub runtime has (sync/index.ts). */
554
+ beginAiAction(
555
+ key: string,
556
+ label: string,
557
+ meta?: {
558
+ runId?: string;
559
+ chatId?: string;
560
+ actor?: string;
561
+ /** V2-8.9 round B A1 — a shell verb call's window (sync/action-stage.ts `claimOnly`). */
562
+ shell?: { call: string; open: boolean; files?: string[]; all?: boolean };
563
+ /** p8-a1-claims — begun by a claim: takes only claimed writes (sync/action-stage.ts). */
564
+ claimOnly?: boolean;
565
+ }
566
+ ): void;
567
+ claimAiWrite(key: string, repoRel: string, hash?: string | null): void;
568
+ /** p8-a1-claims (F17) — run `key` is about to delete canvas `repoRel`: the delete joins the run. */
569
+ claimAiDelete(key: string, repoRel: string): void;
570
+ /** p8-sec2-lows I1 — the delete claimed by `claimAiDelete` failed; drop the claim. */
571
+ unclaimAiDelete(key: string, repoRel: string): void;
572
+ /**
573
+ * S2.20b (U20) — server.ts calls this right after the studio wrote a canvas's layout
574
+ * (`onMetaChanged`) or its board (`onAnnotationsChanged`). A layout the local home only NOTES —
575
+ * the disk already holds it and the watcher records it as the person's `edit`. The board is an
576
+ * explicit lane the watcher never reads (S4.7): a stroke is PROPOSED here as an `edit` (based on
577
+ * `baseText`, the board it replaced). Either way it answers null, so the caller keeps its room
578
+ * bridge exactly as before.
579
+ */
580
+ proposeLane(
581
+ slug: string,
582
+ lane: 'comments' | 'annotations' | 'meta',
583
+ text: string,
584
+ /**
585
+ * `stageable` (S4.20 G3): a run-tagged board batch (annotations/run-tag.ts `stageRunAnnotations`)
586
+ * joins the run's stage when the stage claims it, so the run lands as ONE `ai` action.
587
+ */
588
+ opts?: {
589
+ baseText?: string;
590
+ writeId?: string;
591
+ stageable?: boolean;
592
+ /** p8-undo-collab-refuse — texts a collaborator changed during this stroke (collab room). */
593
+ contested?: readonly string[];
594
+ /**
595
+ * p8-fix-d F13 — only a text session's idle-typing drafts (a room's draft projection; on the
596
+ * disk path a `draft-…` write id says it): held back and recorded with the next stroke on
597
+ * that board, as one step.
598
+ */
599
+ draft?: boolean;
600
+ }
601
+ ): null;
602
+ /**
603
+ * p8-undo-collab-refuse (Michal option b2) — would this undo drop a collaborator's text? True for
604
+ * a board step a collaborator typed into while it was made, or (one target) whose text no longer
605
+ * holds what the step left; routes/project-undo.ts then answers 409 `undo-conflict`. Redo: false.
606
+ */
607
+ textUndoConflict(target: string | UndoTarget, redo?: boolean): Promise<boolean>;
608
+ endAiAction(
609
+ key: string,
610
+ outcome: 'done' | 'failed' | 'stopped',
611
+ o?: { fence?: RunFence }
612
+ ): Promise<AiActionOutcome | null>;
613
+ resolveAiAction(
614
+ choice: 'publish' | 'discard',
615
+ runId?: string
616
+ ): Promise<(AiActionOutcome & { canvases?: number }) | null>;
617
+ }
618
+
619
+ /** What a run's end answers: the action it landed as and the artboards it touched. */
620
+ export interface AiActionOutcome {
621
+ status: 'accepted' | 'rejected' | 'discarded';
622
+ code?: string;
623
+ actionId?: string;
624
+ /** design-root-relative canvas → artboards (V2-1.5 §5.7). */
625
+ touched?: Record<string, string[]>;
626
+ }
627
+
628
+ export interface LocalHomeOptions {
629
+ /** Absolute design root. */
630
+ designRoot: string;
631
+ /** Repo-relative design root (`.design`). */
632
+ designRel: string;
633
+ /** The project's canvas groups (live — config reloads). */
634
+ canvasGroups?: () => { path: string }[] | null;
635
+ machine?: MachineIdentity;
636
+ bootId?: string;
637
+ pid?: number;
638
+ now?: () => number;
639
+ settleMs?: number;
640
+ /** Retry the lock this often while read-only; 0 = never (tests). */
641
+ lockRetryMs?: number;
642
+ /** S5.5b — how long a run's last tool write gets to reach the watcher before the run ends. */
643
+ aiSettleMs?: number;
644
+ log?: Pick<Console, 'warn' | 'error'>;
645
+ /** S1.7b — ctx.bus.emit: `trash:changed` when an accepted action changed the Trash. */
646
+ emit?: (event: string, payload: unknown) => void;
647
+ }
648
+
649
+ export interface ForeignStore {
650
+ machine: string;
651
+ name: string | null;
652
+ file: string;
653
+ }
654
+
655
+ export interface LocalHome {
656
+ readonly file: string;
657
+ /** `writer` holds the lock; `read-only` waits for it (C2). */
658
+ mode(): 'writer' | 'read-only';
659
+ /** Baseline + boot reconcile finished. */
660
+ ready(): Promise<void>;
661
+ runtime: LocalRuntime;
662
+ /** The fs watcher feed: a design-root-relative path changed. */
663
+ observe(rel: string): void;
664
+ /**
665
+ * S5.5b — the studio itself wrote `content` to canvas `rel` (api.ts `source-written`): when
666
+ * the watcher reads exactly that content it is the person's `edit`, never `outside` and never
667
+ * an AI run's.
668
+ */
669
+ noteWritten(
670
+ rel: string,
671
+ content: string,
672
+ label?: string,
673
+ o?: { early?: boolean; base?: string }
674
+ ): void;
675
+ /**
676
+ * F5 — an early note (`source-writing`) whose write then threw: the bytes never landed, so the note is
677
+ * taken back — left for WRITE_NOTE_MS it would make a later outside write of the same bytes the person's.
678
+ */
679
+ withdrawWritten(rel: string, content: string): void;
680
+ /** S5.5b — the runs this home stages (open and held), no bytes. */
681
+ aiRuns(): RunStageSummary[];
682
+ /** A canvas moved on disk (the studio's own move). */
683
+ observeMove(fromRel: string, toRel: string): void;
684
+ /**
685
+ * The studio is ABOUT to move a canvas (`canvas-move-begin`, sent before the file is renamed). Until
686
+ * `observeMove` arrives — or {@link MOVE_HOLD_MS} passes — the watcher's view of the two paths is held:
687
+ * the old path vanishing is not a delete (it would sit in the Trash, and restoring it would bring the old
688
+ * name back beside the renamed canvas) and the new path appearing is not a second document.
689
+ */
690
+ expectMove(fromRel: string, toRel: string): void;
691
+ /** Propose every pending observation now. */
692
+ flush(): Promise<void>;
693
+ /** Other machines' stores in `_state/`, read-only (C1). */
694
+ foreignStores(): ForeignStore[];
695
+ /** Read-only history of one foreign store. */
696
+ foreignHistory(
697
+ machine: string,
698
+ q?: { limit?: number; before?: number | null }
699
+ ): Promise<LocalHistoryRow[] | null>;
700
+ /** The async store (runs, leases, fences) for the run registry. */
701
+ store(): AsyncStore;
702
+ /** This person's actor id in the store. */
703
+ actor: string;
704
+ close(): void;
705
+ }
706
+
707
+ const NAME = (rel: string) => path.posix.basename(rel).replace(/\.tsx$/i, '');
708
+
709
+ /** `.design/ui/a.tsx` → `ui/a.tsx` (null when outside the design root). */
710
+ function designRelOf(repoRel: string, designRel: string): string | null {
711
+ const p = String(repoRel).replace(/\\/g, '/').replace(/^\/+/, '');
712
+ const prefix = `${designRel.replace(/^\/+|\/+$/g, '')}/`;
713
+ if (prefix !== '/' && p.startsWith(prefix)) return p.slice(prefix.length);
714
+ return null;
715
+ }
716
+
717
+ /** The canvas a design-root-relative path belongs to (body / meta / board). */
718
+ export function canvasOfRel(rel: string): string | null {
719
+ const p = rel.replace(/\\/g, '/').replace(/^\/+/, '');
720
+ if (!p || p.split('/').some((c) => c.startsWith('_') || c.startsWith('.'))) return null;
721
+ if (/\.tsx$/i.test(p)) return p;
722
+ const m = /^(.*)\.(meta|annotations)\.json$/i.exec(p);
723
+ return m ? `${m[1]}.tsx` : null;
724
+ }
725
+
726
+ export function openLocalHome(opts: LocalHomeOptions): LocalHome {
727
+ const now = opts.now ?? Date.now;
728
+ const log = opts.log ?? console;
729
+ const machine = opts.machine ?? machineIdentity();
730
+ const bootId = opts.bootId ?? bootIdentity();
731
+ const pid = opts.pid ?? process.pid;
732
+ const settleMs = opts.settleMs ?? OBSERVE_SETTLE_MS;
733
+ const lockRetryMs = opts.lockRetryMs ?? LOCK_RETRY_MS;
734
+ const designRel = opts.designRel;
735
+ const stateDir = path.join(opts.designRoot, '_state');
736
+ const file = path.join(stateDir, STORE_FILE);
737
+ const lockFile = path.join(stateDir, LOCK_FILE);
738
+ const actor = `local:${machine.id}`;
739
+ mkdirSync(stateDir, { recursive: true });
740
+
741
+ let lock: Extract<LockOutcome, { held: true }> | null = null;
742
+ let opened: OpenedStore | null = null;
743
+ let kernel: KernelLike | null = null;
744
+ let projectId = '';
745
+ let readyP: Promise<void> = Promise.resolve();
746
+ let retryTimer: ReturnType<typeof setInterval> | null = null;
747
+ let closed = false;
748
+ const foreignOpen = new Map<string, OpenedStore>();
749
+ const aiSettleMs = opts.aiSettleMs ?? 250;
750
+
751
+ /* ------------------------------------------------------- S5.5b — AI runs */
752
+
753
+ // A run's tool writes are STAGED here (sync/action-stage.ts — the same stage the hub link
754
+ // uses), so the watcher never records a canvas a run covers as `outside`: the run lands as
755
+ // ONE `ai` action when it ends (V2-1.5 §5.5, U21). The disk stays the working copy, so it may
756
+ // hold staged bytes the store has not accepted; `seen` remembers what each lane held when the
757
+ // watcher last read it — the `d0` a change is composed from (`R.mine = merge3(d0, d1, mine)`)
758
+ // and the base a person's edit made on top of staged bytes is proposed from.
759
+ /** `${rel}|${lane}` → the lane's value on disk when last read (or written) here. */
760
+ const seen = new Map<string, string>();
761
+ /**
762
+ * `${canvas}|${lane}` → the studio's own write of that lane (api.ts `source-written` for the
763
+ * source, server.ts `proposeLane` for layout and board — S2.20b), until the watcher reads it.
764
+ */
765
+ const notes = new Map<string, Note>();
766
+ /**
767
+ * p8-e2e-fix-r12 — `${canvas}|html` → the studio's earlier writes of the source whose note a LATER write
768
+ * replaced before the watcher read the canvas (oldest first). One note slot per lane meant a look and its
769
+ * Reset (or two looks) said within one read reached the store as the final bytes only: nothing at all when
770
+ * they cancel, one step under the second's label otherwise. `syncCanvas` records each as its own `edit` —
771
+ * only while they chain: each write's bytes are what the next one replaced (`baseHash`).
772
+ */
773
+ const superseded = new Map<string, Array<Note & { content: string }>>();
774
+ /**
775
+ * S2.20b — an EARLY note (`source-writing`, said before the bytes land) the watcher already consumed:
776
+ * the same write's after-the-write `source-written` is then not a new note (it would sit for
777
+ * WRITE_NOTE_MS and claim a later outside write of the same bytes).
778
+ */
779
+ const takenEarly = new Map<string, { hash: string; at: number }>();
780
+ /** canvas slug → its design-root-relative path (the board file is named by the slug). */
781
+ const slugs = new Map<string, string>();
782
+ /** >0 while a proposal made FROM the disk is accepted: the disk already holds it. */
783
+ let fromDisk = 0;
784
+ let runTx = 0;
785
+ const stage = createActionStage({
786
+ designRoot: opts.designRoot,
787
+ stateFile: path.join(stateDir, AI_STAGE_FILE),
788
+ propose: async (a) => {
789
+ // The local store has no lease rows (the run registry's lease home is in process), so a
790
+ // fence would only ever mismatch: the publish goes without it.
791
+ const r = await serial(() =>
792
+ submit(a.operations, { kind: a.kind, label: a.label }, actor, a.origin ?? {}, true)
793
+ );
794
+ return {
795
+ protocol: PROTOCOL,
796
+ status: r.status,
797
+ transactionId: a.transactionId,
798
+ ...(r.code ? { code: r.code } : {}),
799
+ ...(r.actionId ? { actionId: r.actionId } : {}),
800
+ ...(r.revision !== undefined ? { revision: r.revision } : {}),
801
+ };
802
+ },
803
+ newTransactionId: () => `lt_run_${now().toString(36)}_${(++runTx).toString(36)}`,
804
+ attribute: (slug, before, after) =>
805
+ /\.tsx$/i.test(slug)
806
+ ? { canvas: slug, artboards: attributeArtboards(slug, before, after).artboards }
807
+ : null,
808
+ log: { log() {}, warn: (m: string) => log.warn(m) },
809
+ now,
810
+ // S5.15 — a run's write refused run-overlap leaves the disk: what the lane held before comes back
811
+ // (and is what `seen` says, so the watcher records nothing).
812
+ onRefused: (w) => {
813
+ if (!(LOCAL_LANES as readonly string[]).includes(w.lane)) return;
814
+ const lane = w.lane as LocalLane;
815
+ if (diskLane(w.slug, lane) === w.content) writeLane(w.slug, lane, w.base);
816
+ },
817
+ });
818
+
819
+ function noteWritten(
820
+ rel: string,
821
+ content: string,
822
+ label?: string,
823
+ o?: { early?: boolean; base?: string }
824
+ ): void {
825
+ const canvas = canvasOfRel(rel);
826
+ if (!canvas || canvas !== rel.replace(/\\/g, '/').replace(/^\/+/, '')) return;
827
+ const k = `${canvas}|html`;
828
+ const hash = hashBytes(content);
829
+ // S2.20b — the same write said twice (before its bytes landed, then after): one note, kept from
830
+ // the first saying (its time is when the person made the edit)
831
+ const live = notes.get(k);
832
+ if (live && live.hash === hash && now() - live.at <= WRITE_NOTE_MS) {
833
+ if (label && !live.label) live.label = label;
834
+ return;
835
+ }
836
+ // the after-the-write saying of a write a later one already superseded: not a new write
837
+ const older = (superseded.get(k) ?? []).filter((e) => now() - e.at <= WRITE_NOTE_MS);
838
+ if (!o?.early && older.some((e) => e.hash === hash)) return;
839
+ const taken = takenEarly.get(k);
840
+ if (taken) {
841
+ takenEarly.delete(k);
842
+ if (!o?.early && taken.hash === hash && now() - taken.at <= WRITE_NOTE_MS) return;
843
+ }
844
+ // p8-e2e-fix-r12 — a studio write the watcher has not read yet is kept, not overwritten
845
+ if (live && live.content !== undefined && now() - live.at <= WRITE_NOTE_MS) {
846
+ older.push({ ...live, content: live.content });
847
+ superseded.set(k, older.slice(-MAX_SUPERSEDED));
848
+ }
849
+ notes.set(k, {
850
+ hash,
851
+ at: now(),
852
+ content,
853
+ ...(typeof o?.base === 'string' ? { baseHash: hashBytes(o.base) } : {}),
854
+ ...(label ? { label } : {}),
855
+ ...(o?.early ? { early: true as const } : {}),
856
+ });
857
+ }
858
+
859
+ function withdrawWritten(rel: string, content: string): void {
860
+ const canvas = canvasOfRel(rel);
861
+ if (!canvas || canvas !== rel.replace(/\\/g, '/').replace(/^\/+/, '')) return;
862
+ const k = `${canvas}|html`;
863
+ const live = notes.get(k);
864
+ // only the failed write's own early note: a note the disk's bytes earned stays
865
+ if (!live?.early || live.hash !== hashBytes(content)) return;
866
+ notes.delete(k);
867
+ // the studio write this one replaced (still unread) is the live note again
868
+ const older = superseded.get(k);
869
+ const prev = older?.[older.length - 1];
870
+ if (older && prev && live.baseHash !== undefined && prev.hash === live.baseHash) {
871
+ older.pop();
872
+ if (!older.length) superseded.delete(k);
873
+ notes.set(k, prev);
874
+ }
875
+ }
876
+
877
+ /**
878
+ * p8-e2e-fix-r12 — before the watcher's read of `rel` is recorded: the studio's superseded source writes, each
879
+ * as its own `edit`, in order, up to the write the disk holds now (`disk`). Only a CHAIN counts — walking back
880
+ * from the write on disk, each earlier write's bytes are exactly what the next one replaced, and the first one
881
+ * replaced what the store holds. A note the watcher simply never consumed (an outside write landed on it first)
882
+ * breaks the chain and is dropped: replaying it would put bytes back that the disk no longer descends from.
883
+ */
884
+ async function recordSuperseded(rel: string, doc: string, disk: string, as: string) {
885
+ const k = `${rel}|html`;
886
+ const fresh = (n: Note) => now() - n.at <= WRITE_NOTE_MS;
887
+ const queue = (superseded.get(k) ?? []).filter(fresh);
888
+ superseded.delete(k);
889
+ if (!queue.length) return;
890
+ const cur = notes.get(k);
891
+ const line: Note[] = cur && fresh(cur) ? [...queue, cur] : [...queue];
892
+ const diskHash = hashBytes(disk);
893
+ let j = -1;
894
+ for (let i = line.length - 1; i >= 0; i--)
895
+ if (line[i].hash === diskHash) {
896
+ j = i;
897
+ break;
898
+ }
899
+ if (j < 0) return;
900
+ // the writes after the one on disk have not landed yet: they wait for a later read
901
+ if (j < queue.length - 1) superseded.set(k, queue.slice(j + 1));
902
+ let first = j;
903
+ while (
904
+ first > 0 &&
905
+ line[first].baseHash !== undefined &&
906
+ line[first - 1].hash === line[first].baseHash
907
+ )
908
+ first--;
909
+ const toRecord = queue.slice(first, Math.min(j + 1, queue.length));
910
+ if (!toRecord.length) return;
911
+ const store = (opened as NonNullable<typeof opened>).store;
912
+ const headOf = async () => {
913
+ const head = (await store.heads([doc]))[doc] as {
914
+ lanes: Record<string, { hash: string | null }>;
915
+ };
916
+ const headHash = hashOr(head?.lanes?.html?.hash);
917
+ const prev =
918
+ seen.get(k) ??
919
+ (headHash === EMPTY_HASH ? '' : (((await store.blob(headHash)) as string) ?? ''));
920
+ return { headHash, prev };
921
+ };
922
+ // the chain must start on what the store holds
923
+ if (
924
+ toRecord[0].baseHash === undefined ||
925
+ toRecord[0].baseHash !== hashBytes((await headOf()).prev)
926
+ )
927
+ return;
928
+ for (const e of toRecord) {
929
+ const { headHash, prev } = await headOf();
930
+ if (prev === e.content) continue;
931
+ const r = await submit(
932
+ [
933
+ laneHash(prev) === headHash
934
+ ? { op: 'lane.replace', doc, lane: 'html', content: e.content, base: headHash }
935
+ : { op: 'lane.replace', doc, lane: 'html', content: e.content, baseContent: prev },
936
+ ],
937
+ { kind: 'edit', label: e.label ?? STUDIO_LANE_LABEL.html },
938
+ as,
939
+ { madeAt: e.at },
940
+ true
941
+ );
942
+ if (r.status !== 'accepted') return;
943
+ seen.set(k, e.content);
944
+ if (e.early) takenEarly.set(k, { hash: e.hash, at: now() });
945
+ }
946
+ }
947
+
948
+ /** S2.20b — the studio wrote lane `lane` of the canvas named `slug` (server.ts `proposeLane`). */
949
+ function noteLane(slug: string, lane: string, text: string): void {
950
+ if (lane !== 'meta' && lane !== 'annotations') return;
951
+ const canvas = canvasForSlug(slug);
952
+ const value = canvas ? laneValueFromFile(lane, text) : null;
953
+ if (!canvas || value === null) return;
954
+ notes.set(`${canvas}|${lane}`, { hash: hashBytes(value), at: now() });
955
+ }
956
+
957
+ /** The studio's note for this lane value, consumed (null when the content is not the studio's). */
958
+ function takeNote(
959
+ rel: string,
960
+ lane: LocalLane,
961
+ value: string | undefined
962
+ ): { at: number; label?: string } | null {
963
+ const k = `${rel}|${lane}`;
964
+ const n = notes.get(k);
965
+ if (!n) return null;
966
+ if (now() - n.at > WRITE_NOTE_MS) {
967
+ notes.delete(k);
968
+ return null;
969
+ }
970
+ if (value === undefined || hashBytes(value) !== n.hash) return null;
971
+ notes.delete(k);
972
+ if (n.early) takenEarly.set(k, { hash: n.hash, at: now() });
973
+ return { at: n.at, ...(n.label ? { label: n.label } : {}) };
974
+ }
975
+
976
+ /** The canvas a slug names: the ones seen so far, else a walk of the disk. */
977
+ function canvasForSlug(slug: string): string | null {
978
+ const hit = slugs.get(slug);
979
+ if (hit) return hit;
980
+ for (const rel of diskCanvases()) slugs.set(canvasSlugFromRel(rel, designRel), rel);
981
+ return slugs.get(slug) ?? null;
982
+ }
983
+
984
+ /** The canvas a changed path belongs to — the board is `<designRoot>/<slug>.annotations.json`. */
985
+ function canvasOfPath(rel: string): string | null {
986
+ const p = rel.replace(/\\/g, '/').replace(/^\/+/, '');
987
+ const board = /^([^/]+)\.annotations\.json$/i.exec(p);
988
+ if (board && !board[1].startsWith('_') && !board[1].startsWith('.')) {
989
+ return canvasForSlug(board[1].toLowerCase()) ?? canvasOfRel(p);
990
+ }
991
+ return canvasOfRel(p);
992
+ }
993
+
994
+ /* ---------------------------------------------------------------- open */
995
+
996
+ function openWriter(): void {
997
+ // C1 — a store another machine wrote is never written by this one.
998
+ if (existsSync(file)) {
999
+ let other: string | null = null;
1000
+ try {
1001
+ const probe = new Database(file, { readonly: true });
1002
+ other = storeMachine(bunSqliteAdapter(probe));
1003
+ probe.close();
1004
+ } catch {
1005
+ other = null;
1006
+ }
1007
+ if (other !== null && other !== machine.id) {
1008
+ const moved = moveAside(stateDir, other);
1009
+ log.warn(`[local-kernel] ${file} came from another machine — kept read-only as ${moved}`);
1010
+ }
1011
+ }
1012
+ opened = openStore(file, { readonly: false, now });
1013
+ const sql = opened.sql;
1014
+ if (storeMachine(sql) === null) {
1015
+ setStoreMeta(sql, 'machine', machine.id);
1016
+ setStoreMeta(sql, 'machineName', machine.name);
1017
+ }
1018
+ projectId = readStoreMeta(sql, 'localProjectId') ?? '';
1019
+ if (!projectId) {
1020
+ projectId = `local_${randomUUID().replace(/-/g, '')}`;
1021
+ setStoreMeta(sql, 'localProjectId', projectId);
1022
+ }
1023
+ if (opened.core.state().mode !== 'transactions') {
1024
+ opened.core.setMode({ mode: 'transactions' });
1025
+ }
1026
+ kernel = makeKernel({
1027
+ store: opened.store,
1028
+ projectId,
1029
+ applyAccepted: publish,
1030
+ canvasGroups: () => opts.canvasGroups?.() ?? null,
1031
+ designRel,
1032
+ now,
1033
+ log,
1034
+ });
1035
+ // S5.5b (U14) — a run the last session left comes back HELD, before the boot reconcile
1036
+ // reads the disk: its bytes are its stage's, never an `outside` row.
1037
+ stage.restore();
1038
+ }
1039
+
1040
+ function openReadOnly(): void {
1041
+ opened = existsSync(file) ? openStore(file, { readonly: true, now }) : null;
1042
+ kernel = null;
1043
+ }
1044
+
1045
+ function start(): void {
1046
+ const got = acquireStoreLock(lockFile, { pid, bootId, machine: machine.id, now });
1047
+ if (got.held) {
1048
+ lock = got;
1049
+ openWriter();
1050
+ readyP = reconcile().catch((err) => log.error('[local-kernel] boot reconcile failed:', err));
1051
+ return;
1052
+ }
1053
+ openReadOnly();
1054
+ if (lockRetryMs > 0) {
1055
+ retryTimer = setInterval(() => {
1056
+ if (closed || lock) return;
1057
+ const again = acquireStoreLock(lockFile, { pid, bootId, machine: machine.id, now });
1058
+ if (!again.held) return;
1059
+ if (retryTimer) clearInterval(retryTimer);
1060
+ retryTimer = null;
1061
+ opened?.db.close();
1062
+ lock = again;
1063
+ openWriter();
1064
+ readyP = reconcile().catch((err) =>
1065
+ log.error('[local-kernel] reconcile after taking the lock failed:', err)
1066
+ );
1067
+ }, lockRetryMs);
1068
+ (retryTimer as { unref?: () => void }).unref?.();
1069
+ }
1070
+ }
1071
+
1072
+ /* -------------------------------------------------------------- submit */
1073
+
1074
+ let txn = 0;
1075
+ async function submit(
1076
+ operations: unknown[],
1077
+ action: { kind: string; label: string | null },
1078
+ as: string = actor,
1079
+ origin: Record<string, unknown> = {},
1080
+ /** The proposal IS what the disk holds: its acceptance writes nothing back. */
1081
+ disk = false
1082
+ ): Promise<LocalOutcome> {
1083
+ if (!kernel || !opened) return { status: 'rejected', code: 'store-locked' };
1084
+ const { epoch } = await opened.store.state();
1085
+ const bytes = JSON.stringify({
1086
+ protocol: PROTOCOL,
1087
+ projectId,
1088
+ epoch,
1089
+ transactionId: `lt_${now().toString(36)}_${(++txn).toString(36)}_${randomUUID().slice(0, 8)}`,
1090
+ origin: { deviceId: machine.id, client: 'studio-local', madeAt: now(), ...origin },
1091
+ action: { kind: action.kind, label: action.label, operations },
1092
+ });
1093
+ if (disk) fromDisk += 1;
1094
+ let body: any;
1095
+ try {
1096
+ // S1.6 — a local project is its owner's (S1 Q4): every per-op cap holds,
1097
+ // `trash.clear` (`delete`) included, which the kernel refuses without `can`.
1098
+ ({ body } = await kernel.submit(bytes, { actor: as, can: () => true }));
1099
+ } finally {
1100
+ if (disk) fromDisk -= 1;
1101
+ }
1102
+ if (body?.status === 'accepted') {
1103
+ return {
1104
+ status: 'accepted',
1105
+ ...(body.actionId ? { actionId: body.actionId } : {}),
1106
+ ...(Number.isSafeInteger(body.revision) ? { revision: body.revision } : {}),
1107
+ ...(typeof body.undoes === 'string' || Array.isArray(body.undoes)
1108
+ ? { undoes: body.undoes }
1109
+ : {}),
1110
+ ...(Array.isArray(body.skipped) && body.skipped.length ? { skipped: body.skipped } : {}),
1111
+ ...(Array.isArray(body.cleared) ? { cleared: body.cleared } : {}),
1112
+ };
1113
+ }
1114
+ return { status: 'rejected', code: String(body?.code ?? 'retryable') };
1115
+ }
1116
+
1117
+ /* ------------------------------------------------------------ disk ⇄ lanes */
1118
+
1119
+ const abs = (rel: string) => path.join(opts.designRoot, ...rel.split('/'));
1120
+ // The board is NOT a sibling: it sits at the design root under the canvas's
1121
+ // flat slug (`<slug>.annotations.json`, api.ts `annotationsPath`, DDR-242).
1122
+ const sibling = (rel: string, lane: LocalLane) =>
1123
+ lane === 'html'
1124
+ ? rel
1125
+ : lane === 'meta'
1126
+ ? rel.replace(/\.tsx$/i, '.meta.json')
1127
+ : `${canvasSlugFromRel(rel, designRel)}.annotations.json`;
1128
+ /** S4.7 — the file an explicit lane is published to. */
1129
+ const explicitFile = (rel: string, lane: ExplicitLane) =>
1130
+ lane === 'annotations'
1131
+ ? sibling(rel, 'annotations')
1132
+ : `_comments/${canvasSlugFromRel(rel, designRel)}.json`;
1133
+ const readText = (rel: string): string | null => {
1134
+ try {
1135
+ return readFileSync(abs(rel), 'utf8');
1136
+ } catch {
1137
+ return null;
1138
+ }
1139
+ };
1140
+
1141
+ /** A lane's value on disk: '' when its file is absent, null when unreadable as that lane. */
1142
+ function diskLane(rel: string, lane: LocalLane): string | null {
1143
+ const text = readText(sibling(rel, lane));
1144
+ if (text === null) return '';
1145
+ return laneValueFromFile(lane, text);
1146
+ }
1147
+
1148
+ const hashOr = (h: unknown) => (typeof h === 'string' && h ? h : EMPTY_HASH);
1149
+
1150
+ function inGroups(rel: string): boolean {
1151
+ const groups = (opts.canvasGroups?.() ?? []).map((g) => g.path).filter(Boolean);
1152
+ const verdict = validateCanvasPath({
1153
+ path: rel,
1154
+ slug: canvasSlugFromRel(rel, designRel),
1155
+ designRel,
1156
+ canvasGroups: groups.length ? groups.map((p) => ({ path: p })) : undefined,
1157
+ allowUndeclaredGroup: groups.length === 0,
1158
+ });
1159
+ return verdict.ok;
1160
+ }
1161
+
1162
+ /**
1163
+ * Propose what the disk holds for one canvas — the one function the baseline,
1164
+ * the boot reconcile and the watcher share. Returns null when nothing changed.
1165
+ */
1166
+ async function syncCanvas(
1167
+ rel: string,
1168
+ action: { kind: string; label: string | null },
1169
+ as: string = actor
1170
+ ): Promise<LocalOutcome | null> {
1171
+ if (!opened || !kernel) return null;
1172
+ const store = opened.store;
1173
+ const live: string | null = await store.docByPath(rel);
1174
+ const onDisk = existsSync(abs(rel));
1175
+ // A move the studio announced and has not finished: observeMove lands both halves in one op.
1176
+ if (holdLive(rel)) return null;
1177
+ if (!onDisk) {
1178
+ for (const lane of LOCAL_LANES) seen.delete(`${rel}|${lane}`);
1179
+ if (!live) return null;
1180
+ const st = (await store.heads([live]))[live];
1181
+ // p8-a1-claims (F17) — a delete an AI run claimed (`maude design trash move` → the studio's
1182
+ // `DELETE /_api/canvas` named the run) is that run's: staged, published with its other changes.
1183
+ if (action.kind === OUTSIDE_KIND && stage.stagesDelete(rel, live, st?.generation))
1184
+ return null;
1185
+ return submit(
1186
+ [{ op: 'doc.delete', doc: live, generation: st?.generation }],
1187
+ { ...action, label: action.label ?? NAME(rel) },
1188
+ as
1189
+ );
1190
+ }
1191
+ if (!inGroups(rel)) return null;
1192
+ slugs.set(canvasSlugFromRel(rel, designRel), rel);
1193
+ const values: Partial<Record<LocalLane, string>> = {};
1194
+ for (const lane of WATCHED_LANES) {
1195
+ const v = diskLane(rel, lane);
1196
+ if (v !== null) values[lane] = v;
1197
+ }
1198
+ if (!values.html) return null; // an empty or unreadable body is not a canvas yet
1199
+ if (!live) {
1200
+ // S12.16 — a canvas an AI run created (the studio's create route, claimed for the chat's live
1201
+ // run: ai/create-claim.ts) is that run's write: it is staged with the run's other changes and
1202
+ // published as ONE `ai` action with a `doc.create` in it, and the run's undo takes it back.
1203
+ // Only an explicit claim counts: a person's new canvas never lands in whichever run is open.
1204
+ if (action.kind === OUTSIDE_KIND && stage.captures(rel, true, values.html, true)) {
1205
+ const docId = canvasSlugFromRel(rel, designRel);
1206
+ for (const lane of WATCHED_LANES) {
1207
+ const v = values[lane];
1208
+ if (v === undefined || v === '') continue;
1209
+ const k = `${rel}|${lane}`;
1210
+ const prev = seen.get(k);
1211
+ if (prev === v) continue;
1212
+ seen.set(k, v);
1213
+ void stage
1214
+ .capture(rel, docId, {
1215
+ lane,
1216
+ content: v,
1217
+ baseContent: prev ?? '',
1218
+ transactionId: `lt_stage_${now().toString(36)}_${(++runTx).toString(36)}`,
1219
+ stageable: true,
1220
+ create: rel,
1221
+ })
1222
+ .catch(() => null);
1223
+ }
1224
+ return null;
1225
+ }
1226
+ const lanes = Object.fromEntries(Object.entries(values).filter(([, v]) => v !== ''));
1227
+ return submit(
1228
+ [{ op: 'doc.create', doc: canvasSlugFromRel(rel, designRel), path: rel, lanes }],
1229
+ { ...action, label: action.label ?? NAME(rel) },
1230
+ as
1231
+ );
1232
+ }
1233
+ if (action.kind === OUTSIDE_KIND) await recordSuperseded(rel, live, values.html, as);
1234
+ const head = (await store.heads([live]))[live] as {
1235
+ lanes: Record<string, { hash: string | null }>;
1236
+ };
1237
+ // S5.5b — the studio's own write is the person's edit; a write a run claims (or a run
1238
+ // covers) joins that run's stage; anything else is outside, as before. S2.20b (U20) — per
1239
+ // lane: a layout move the studio wrote is an `edit` too (the board is not watched — S4.7), labelled by
1240
+ // its lane like the hub link's `LANE_LABEL`, and a lane nobody noted in the same read stays
1241
+ // `outside` in its own action.
1242
+ type Group = { ops: unknown[]; seen: Array<[string, string]>; lanes: LocalLane[]; at: number };
1243
+ const edit: Group & { said?: string } = {
1244
+ ops: [],
1245
+ seen: [],
1246
+ lanes: [],
1247
+ at: Number.POSITIVE_INFINITY,
1248
+ };
1249
+ const other: Group = { ops: [], seen: [], lanes: [], at: 0 };
1250
+ for (const lane of WATCHED_LANES) {
1251
+ const v = values[lane];
1252
+ if (v === undefined) continue;
1253
+ const k = `${rel}|${lane}`;
1254
+ const headHash = hashOr(head?.lanes?.[lane]?.hash);
1255
+ const prev = seen.get(k);
1256
+ if (prev !== undefined ? prev === v : laneHash(v) === headHash) continue;
1257
+ const base =
1258
+ prev ?? (headHash === EMPTY_HASH ? '' : (((await store.blob(headHash)) as string) ?? ''));
1259
+ const noted = action.kind === OUTSIDE_KIND ? takeNote(rel, lane, v) : null;
1260
+ if (!noted && action.kind === OUTSIDE_KIND && stage.captures(rel, true, v)) {
1261
+ seen.set(k, v);
1262
+ void stage
1263
+ .capture(rel, live, {
1264
+ lane,
1265
+ content: v,
1266
+ baseContent: base,
1267
+ transactionId: `lt_stage_${now().toString(36)}_${(++runTx).toString(36)}`,
1268
+ stageable: true,
1269
+ })
1270
+ .catch(() => null);
1271
+ continue;
1272
+ }
1273
+ const g = noted ? edit : other;
1274
+ if (noted) {
1275
+ g.at = Math.min(g.at, noted.at);
1276
+ // S2.24 G3 — the studio said what the write was (edit-ops/op-label.ts): the row reads it
1277
+ if (noted.label && lane === 'html') edit.said = noted.label;
1278
+ }
1279
+ g.ops.push(
1280
+ laneHash(base) === headHash
1281
+ ? { op: 'lane.replace', doc: live, lane, content: v, base: headHash }
1282
+ : { op: 'lane.replace', doc: live, lane, content: v, baseContent: base }
1283
+ );
1284
+ g.seen.push([k, v]);
1285
+ g.lanes.push(lane);
1286
+ }
1287
+ let r: LocalOutcome | null = null;
1288
+ if (edit.ops.length) {
1289
+ const label = edit.lanes.includes('html')
1290
+ ? (edit.said ?? STUDIO_LANE_LABEL.html)
1291
+ : STUDIO_LANE_LABEL[edit.lanes[0]];
1292
+ r = await submit(edit.ops, { kind: 'edit', label }, as, { madeAt: edit.at }, true);
1293
+ if (r.status === 'accepted') for (const [k, v] of edit.seen) seen.set(k, v);
1294
+ }
1295
+ if (other.ops.length) {
1296
+ r = await submit(other.ops, { ...action, label: action.label ?? NAME(rel) }, as, {}, true);
1297
+ if (r.status === 'accepted') for (const [k, v] of other.seen) seen.set(k, v);
1298
+ }
1299
+ return r;
1300
+ }
1301
+
1302
+ /** Every canvas on disk under the groups, design-root-relative. */
1303
+ function diskCanvases(): string[] {
1304
+ const out: string[] = [];
1305
+ const groups = (opts.canvasGroups?.() ?? []).map((g) => g.path).filter(Boolean);
1306
+ const roots = groups.length
1307
+ ? groups
1308
+ : readdirSync(opts.designRoot, { withFileTypes: true })
1309
+ .filter((d) => d.isDirectory() && !d.name.startsWith('_') && !d.name.startsWith('.'))
1310
+ .map((d) => d.name);
1311
+ const walk = (dirRel: string, depth: number) => {
1312
+ if (depth > 8) return;
1313
+ let entries: import('node:fs').Dirent[];
1314
+ try {
1315
+ entries = readdirSync(abs(dirRel), { withFileTypes: true });
1316
+ } catch {
1317
+ return;
1318
+ }
1319
+ for (const e of entries) {
1320
+ if (e.name.startsWith('_') || e.name.startsWith('.') || e.name === 'node_modules') continue;
1321
+ const rel = `${dirRel}/${e.name}`;
1322
+ if (e.isDirectory()) walk(rel, depth + 1);
1323
+ else if (e.isFile() && /\.tsx$/i.test(e.name)) out.push(rel);
1324
+ }
1325
+ };
1326
+ for (const g of new Set(roots)) walk(g.replace(/^\/+|\/+$/g, ''), 1);
1327
+ return out.sort();
1328
+ }
1329
+
1330
+ /**
1331
+ * C3 + boot reconcile. A fresh store (or one whose import never finished)
1332
+ * gets one `migration.import` action per canvas; then whatever changed on
1333
+ * disk while no studio watched becomes `outside` rows.
1334
+ */
1335
+ async function reconcile(): Promise<void> {
1336
+ if (!opened) return;
1337
+ const store = opened.store;
1338
+ const st = await store.state();
1339
+ const baseline = st.importPending || st.revision === 0;
1340
+ for (const rel of diskCanvases()) {
1341
+ const action = baseline
1342
+ ? { kind: BASELINE_KIND, label: BASELINE_LABEL }
1343
+ : { kind: OUTSIDE_KIND, label: null };
1344
+ const r = await syncCanvas(rel, action, baseline ? MIGRATION_ACTOR : actor);
1345
+ if (r && r.status !== 'accepted') {
1346
+ log.warn(`[local-kernel] ${rel} not recorded (${r.code}) — kept on disk as it is`);
1347
+ }
1348
+ }
1349
+ if (baseline) await store.markImported();
1350
+ // Canvases deleted while no studio watched.
1351
+ const m = await store.manifest();
1352
+ for (const d of m.docs as { path: string; retired: boolean }[]) {
1353
+ if (!d.retired && d.path && !existsSync(abs(d.path))) {
1354
+ await syncCanvas(d.path, { kind: OUTSIDE_KIND, label: null });
1355
+ }
1356
+ }
1357
+ }
1358
+
1359
+ /* -------------------------------------------------------------- publish */
1360
+
1361
+ /**
1362
+ * The kernel's `applyAccepted` — an accepted action reaches the disk. The
1363
+ * echo returns through the watcher and finds the head already equal.
1364
+ */
1365
+ async function publish(p: {
1366
+ revision: number;
1367
+ changes: {
1368
+ doc: string;
1369
+ path: string | null;
1370
+ lanes: Record<string, string>;
1371
+ created: boolean;
1372
+ revived: boolean;
1373
+ deleted: boolean;
1374
+ retiredFor: string | null;
1375
+ movedFrom: string | null;
1376
+ }[];
1377
+ /** S1.6 — what a clear-out removed (kernel `extra.cleared`). */
1378
+ trashCleared?: {
1379
+ entry: string;
1380
+ artboard: string;
1381
+ rev: number;
1382
+ doc?: string;
1383
+ path?: string | null;
1384
+ }[];
1385
+ }): Promise<void> {
1386
+ const store = opened?.store;
1387
+ if (!store) return;
1388
+ try {
1389
+ // S5.5b — a proposal made from the disk (a watched write, a run landing): nothing to write.
1390
+ if (fromDisk === 0) await publishChanges(store, p);
1391
+ } finally {
1392
+ if (p.trashCleared?.length) await clearCopies(store, p.trashCleared);
1393
+ if (
1394
+ p.trashCleared?.length ||
1395
+ p.changes.some((c) => (c.deleted && !c.retiredFor) || c.revived)
1396
+ )
1397
+ bumpTrashSeq(opts.emit);
1398
+ }
1399
+ }
1400
+
1401
+ /**
1402
+ * S1.7b — the owner cleared items out (S1 Q4): this machine's own parked
1403
+ * copies of exactly those canvases go (sync/trash-clear-copies.ts). The
1404
+ * bytes compared are the canvas as the store held it when it was trashed.
1405
+ */
1406
+ async function clearCopies(
1407
+ store: NonNullable<typeof opened>['store'],
1408
+ cleared: NonNullable<Parameters<typeof publish>[0]['trashCleared']>
1409
+ ): Promise<void> {
1410
+ try {
1411
+ const bodyAt = async (doc: string, rev: number) => {
1412
+ const h = await store.laneAt(doc, 'html', Math.max(rev - 1, 0));
1413
+ return h ? ((await store.blob(h)) ?? '') : '';
1414
+ };
1415
+ const items: ParkedCanvas[] = [];
1416
+ for (const c of cleared)
1417
+ if (c.artboard === '' && c.doc && c.path)
1418
+ items.push({ path: c.path, body: await bodyAt(c.doc, c.rev) });
1419
+ if (!items.length) return;
1420
+ const paths = new Set(items.map((i) => i.path));
1421
+ const remaining: ParkedCanvas[] = [];
1422
+ if (typeof store.trash === 'function')
1423
+ for (const c of (await store.trash({})).canvases as {
1424
+ doc: string;
1425
+ path: string;
1426
+ rev: number;
1427
+ }[])
1428
+ if (paths.has(c.path)) remaining.push({ path: c.path, body: await bodyAt(c.doc, c.rev) });
1429
+ removeClearedCopies({
1430
+ designRoot: opts.designRoot,
1431
+ designRel,
1432
+ cleared: items,
1433
+ remaining,
1434
+ log: (line) => log.warn(line),
1435
+ });
1436
+ } catch (err) {
1437
+ log.warn(`[local-kernel] clear-out cleanup failed: ${(err as Error).message}`);
1438
+ }
1439
+ }
1440
+
1441
+ async function publishChanges(
1442
+ store: NonNullable<typeof opened>['store'],
1443
+ p: Parameters<typeof publish>[0]
1444
+ ): Promise<void> {
1445
+ // S5.5b — a proposal made from the disk (a watched write, a run landing): nothing to write.
1446
+ if (fromDisk > 0) return;
1447
+ // What the store held before this action, per lane — the disk must still
1448
+ // say that, or it carries a byte the store never accepted.
1449
+ const before = async (doc: string, lane: LocalLane) =>
1450
+ hashOr(await store.laneAt(doc, lane, p.revision - 1));
1451
+ const diskMatches = async (rel: string, doc: string, lane: LocalLane) => {
1452
+ const v = diskLane(rel, lane);
1453
+ return v !== null && laneHash(v) === (await before(doc, lane));
1454
+ };
1455
+ for (const c of p.changes) {
1456
+ if (!c.path) continue;
1457
+ if (c.deleted || c.retiredFor) {
1458
+ if (c.retiredFor) continue; // the move's new document carries the files
1459
+ if (!(await diskMatches(c.path, c.doc, 'html'))) {
1460
+ log.warn(`[local-kernel] ${c.path} changed on disk since — not deleted`);
1461
+ continue;
1462
+ }
1463
+ for (const lane of LOCAL_LANES) {
1464
+ try {
1465
+ unlinkSync(abs(sibling(c.path, lane)));
1466
+ } catch {
1467
+ /* absent */
1468
+ }
1469
+ }
1470
+ continue;
1471
+ }
1472
+ if (c.movedFrom && existsSync(abs(c.movedFrom)) && !existsSync(abs(c.path))) {
1473
+ for (const lane of LOCAL_LANES) {
1474
+ const from = abs(sibling(c.movedFrom, lane));
1475
+ if (!existsSync(from)) continue;
1476
+ mkdirSync(path.dirname(abs(sibling(c.path, lane))), { recursive: true });
1477
+ renameSync(from, abs(sibling(c.path, lane)));
1478
+ }
1479
+ }
1480
+ // A created or revived document lands whole: a revive carries no lane
1481
+ // change (a deleted document keeps its lanes), so read them from the head.
1482
+ const lanes: Record<string, string> = { ...c.lanes };
1483
+ if (c.created || c.revived) {
1484
+ const head = (await store.heads([c.doc]))[c.doc] as
1485
+ | { lanes?: Record<string, { hash: string | null }> }
1486
+ | undefined;
1487
+ for (const lane of LOCAL_LANES) {
1488
+ const h = head?.lanes?.[lane]?.hash;
1489
+ if (lanes[lane] === undefined && h) lanes[lane] = (await store.blob(h)) ?? '';
1490
+ }
1491
+ }
1492
+ for (const [lane, value] of Object.entries(lanes)) {
1493
+ if (isExplicit(lane)) {
1494
+ if (!c.created && !c.revived)
1495
+ await publishExplicit(c.path, c.doc, lane, value, p.revision);
1496
+ continue;
1497
+ }
1498
+ if (!(LOCAL_LANES as readonly string[]).includes(lane)) continue;
1499
+ const l = lane as LocalLane;
1500
+ const rel = sibling(c.path, l);
1501
+ const current = diskLane(c.path, l);
1502
+ if (current !== null && laneHash(current) === laneHash(value)) {
1503
+ seen.set(`${c.path}|${l}`, current);
1504
+ continue;
1505
+ }
1506
+ if (!c.created && !c.revived && !(await diskMatches(c.path, c.doc, l))) {
1507
+ // S5.15 — an open run's staged bytes are on disk over what the store held (⌘Z on your own
1508
+ // edit while the run works): the accepted change is replayed onto the disk three-way, so
1509
+ // your edit leaves and the run's bytes stay. Anything else unrecorded is left as it is.
1510
+ if (l === 'html' && current !== null && stage.accepted(c.path, 'html') !== null) {
1511
+ const h = await store.laneAt(c.doc, 'html', p.revision - 1);
1512
+ const before = h ? (((await store.blob(h)) as string | null) ?? '') : '';
1513
+ const m = mergeSource(before, value, current);
1514
+ if (m.ok) {
1515
+ if (m.merged !== current) writeLane(c.path, l, m.merged);
1516
+ continue;
1517
+ }
1518
+ }
1519
+ log.warn(`[local-kernel] ${rel} changed on disk since — left as it is`);
1520
+ continue;
1521
+ }
1522
+ writeLane(c.path, l, value);
1523
+ }
1524
+ }
1525
+ }
1526
+
1527
+ /**
1528
+ * S4.7 — an accepted change of an explicit lane reaches the disk THREE-WAY:
1529
+ * what the store held before → what it holds now, replayed onto what the disk
1530
+ * holds (by element / comment id — mergeLane). Nothing the store never saw is
1531
+ * overwritten: an unrecorded sticky edit or a new comment stays.
1532
+ */
1533
+ async function publishExplicit(
1534
+ rel: string,
1535
+ doc: string,
1536
+ lane: ExplicitLane,
1537
+ value: string,
1538
+ revision: number
1539
+ ): Promise<void> {
1540
+ const store = opened?.store;
1541
+ if (!store) return;
1542
+ const h = await store.laneAt(doc, lane, revision - 1);
1543
+ const before = h ? (((await store.blob(h)) as string | null) ?? '') : '';
1544
+ const fileRel = explicitFile(rel, lane);
1545
+ const raw = readText(fileRel);
1546
+ const disk = raw === null ? '' : laneValueFromFile(lane, raw);
1547
+ if (disk === null) {
1548
+ log.warn(`[local-kernel] ${fileRel} is unreadable — left as it is`);
1549
+ return;
1550
+ }
1551
+ const m = mergeLane(lane, before, value, disk);
1552
+ if (!m.ok) {
1553
+ log.warn(`[local-kernel] ${fileRel} changed on disk since — left as it is`);
1554
+ return;
1555
+ }
1556
+ if (m.content === disk) return;
1557
+ if (m.content === '') {
1558
+ if (lane === 'comments') {
1559
+ try {
1560
+ unlinkSync(abs(fileRel));
1561
+ } catch {
1562
+ /* absent */
1563
+ }
1564
+ } else atomicWrite(abs(fileRel), serializeBoard([]));
1565
+ return;
1566
+ }
1567
+ // The bytes the studio itself writes: api.ts `saveCommentsForFile` / the canonical board.
1568
+ const text = lane === 'comments' ? JSON.stringify(JSON.parse(m.content), null, 2) : m.content;
1569
+ mkdirSync(path.dirname(abs(fileRel)), { recursive: true });
1570
+ atomicWrite(abs(fileRel), text);
1571
+ }
1572
+
1573
+ /**
1574
+ * S4.7 — several lanes of one canvas as ONE action (a sticky ↔ comment
1575
+ * conversion). The studio writes the files itself (the room bridge, the
1576
+ * sidebar); this records what they became. An explicit lane the store has
1577
+ * fallen behind on (a board edit the watcher does not record) is first
1578
+ * brought up to the disk's `baseText` by an `outside` row, so the action's
1579
+ * before-content IS what the disk held — its undo takes back exactly it.
1580
+ */
1581
+ async function proposeLanes(
1582
+ slug: string,
1583
+ lanes: Array<{ lane: string; text: string; baseText: string | null }>,
1584
+ o: { kind: string; label: string; origin?: Record<string, unknown> }
1585
+ ): Promise<LocalOutcome> {
1586
+ // p8-fix-d F13 — a board this proposal carries starts after the typing held for it.
1587
+ if (draftsHeld.has(slug) && lanes.some((l) => l.lane === 'annotations')) releaseDrafts(slug);
1588
+ await readyP;
1589
+ return serial(() => proposeLanesNow(slug, lanes, o));
1590
+ }
1591
+
1592
+ /**
1593
+ * The body of `proposeLanes`, for a caller already holding the serial slot. A lane whose
1594
+ * `baseText` is null is based on what the store holds at its head (the stroke path: the studio
1595
+ * does not know what the board was before).
1596
+ */
1597
+ async function proposeLanesNow(
1598
+ slug: string,
1599
+ lanes: Array<{ lane: string; text: string; baseText: string | null }>,
1600
+ o: { kind: string; label: string; origin?: Record<string, unknown> }
1601
+ ): Promise<LocalOutcome> {
1602
+ if (!opened || !kernel) return { status: 'rejected', code: 'store-locked' } as LocalOutcome;
1603
+ const store = opened.store;
1604
+ const m = await store.manifest();
1605
+ const live = (m.docs as { doc: string; path: string; retired: boolean }[]).find(
1606
+ (d) => !d.retired && d.path && canvasSlugFromRel(d.path, designRel) === slug
1607
+ );
1608
+ if (!live) return { status: 'rejected', code: 'unknown-canvas' } as LocalOutcome;
1609
+ const head = (await store.heads([live.doc]))[live.doc] as {
1610
+ lanes: Record<string, { hash: string | null }>;
1611
+ };
1612
+ const catchUp: unknown[] = [];
1613
+ const ops: unknown[] = [];
1614
+ for (const l of lanes) {
1615
+ if (!isExplicit(l.lane) && !(LOCAL_LANES as readonly string[]).includes(l.lane))
1616
+ return { status: 'rejected', code: 'invalid' } as LocalOutcome;
1617
+ const lane = l.lane as LocalLane | ExplicitLane;
1618
+ const content = laneValueFromFile(lane, l.text);
1619
+ const headHash = hashOr(head?.lanes?.[lane]?.hash);
1620
+ // A stroke of unknown base on a board the store never recorded: what it replaces cannot be
1621
+ // known, and an undo to "empty" would wipe the board. Record the board as it is now
1622
+ // (`outside`, no undo of this one stroke); the next stroke has a base.
1623
+ if (l.baseText === null && headHash === EMPTY_HASH && content !== null && content !== '')
1624
+ return submit(
1625
+ [{ op: 'lane.replace', doc: live.doc, lane, content, base: EMPTY_HASH }],
1626
+ { kind: OUTSIDE_KIND, label: null },
1627
+ actor,
1628
+ {},
1629
+ true
1630
+ );
1631
+ const base =
1632
+ l.baseText === null
1633
+ ? headHash === EMPTY_HASH
1634
+ ? ''
1635
+ : (((await store.blob(headHash)) as string | null) ?? '')
1636
+ : laneValueFromFile(lane, l.baseText);
1637
+ if (content === null || base === null)
1638
+ return { status: 'rejected', code: 'invalid' } as LocalOutcome;
1639
+ // A stroke that leaves the store's head as it is (a room repeating the PUT) is no action —
1640
+ // a room projecting the board an artboard move's rider already
1641
+ // recorded reads its base from the not-yet-flushed file, and a catch-up + second edit there
1642
+ // made the move a two-step ⌘Z (S4.18 an-follow).
1643
+ if (lanes.length === 1 && laneHash(content) === headHash) {
1644
+ const baseHash = laneHash(base);
1645
+ // …when the base is a state the store already holds (the S4.18 replay: its base is the board
1646
+ // the rider's action started from).
1647
+ if (baseHash === headHash || (await store.blob(baseHash)) != null)
1648
+ return { status: 'accepted' } as LocalOutcome;
1649
+ // sec-a L1 — a base the store never saw is a passing OUTSIDE write that this stale PUT is about
1650
+ // to overwrite. Keep the catch-up `outside` row (history shows what passed), and record the
1651
+ // return to the head as `outside` too — never as the person's edit, so their ⌘Z stack is
1652
+ // what it was (one ⌘Z after an artboard drag still restores everything).
1653
+ const passed = await submit(
1654
+ [{ op: 'lane.replace', doc: live.doc, lane, content: base, base: headHash }],
1655
+ { kind: OUTSIDE_KIND, label: null },
1656
+ actor,
1657
+ {},
1658
+ true
1659
+ );
1660
+ if (passed.status !== 'accepted') return passed;
1661
+ return submit(
1662
+ [{ op: 'lane.replace', doc: live.doc, lane, content, base: baseHash }],
1663
+ { kind: OUTSIDE_KIND, label: null },
1664
+ actor,
1665
+ {},
1666
+ true
1667
+ );
1668
+ }
1669
+ if (laneHash(base) !== headHash)
1670
+ catchUp.push({ op: 'lane.replace', doc: live.doc, lane, content: base, base: headHash });
1671
+ ops.push({ op: 'lane.replace', doc: live.doc, lane, content, base: laneHash(base) });
1672
+ }
1673
+ if (catchUp.length) {
1674
+ const r = await submit(catchUp, { kind: OUTSIDE_KIND, label: null }, actor, {}, true);
1675
+ if (r.status !== 'accepted') return r;
1676
+ }
1677
+ const r = await submit(ops, { kind: o.kind, label: o.label }, actor, o.origin ?? {}, true);
1678
+ if (r.status === 'accepted') {
1679
+ for (const l of lanes) if (!isExplicit(l.lane)) seen.set(`${live.path}|${l.lane}`, l.text);
1680
+ }
1681
+ return r;
1682
+ }
1683
+
1684
+ /**
1685
+ * A studio annotation stroke (server.ts `onAnnotationsChanged`, or a room projecting its board):
1686
+ * the board is an explicit lane — the watcher never records it (S4.7) — so the stroke is proposed
1687
+ * here, as the person's `edit` ("Edit annotations"), and ⌘Z takes it back (U20, decision
1688
+ * v2-lead-annotations-lane-explicit-wins). The board file is already on disk; this records it.
1689
+ * Fire-and-forget, tracked in `strokes` so `flush()` / `settled()` see it (the 1 ms ⌘Z race).
1690
+ */
1691
+ const strokes = new Set<Promise<unknown>>();
1692
+ const lastStroke = new Map<string, string>();
1693
+ // p8-undo-collab-refuse — what each recorded stroke left in the text slots it changed, and the
1694
+ // texts a collaborator changed during it (annotations/text-steps.ts). Session scope, like ⌘Z.
1695
+ const textSteps = createTextStepLedger();
1696
+ /** The one dedupe key of a stroke — `proposeStroke` and `stageStroke` must agree on it. */
1697
+ const strokeKey = (text: string, baseText: string | undefined) =>
1698
+ `${baseText ?? '\u0000none'}\u0000${text}`;
1699
+ /**
1700
+ * p8-fix-d F13 — draft strokes held back per board (V2-1.5 §3: a text session is ONE gesture, one
1701
+ * step; DDR-242 AD7: drafts never reach undo). `base` is the board before the first held draft,
1702
+ * `text` the newest draft. The next stroke on that board (the session's commit) is recorded from
1703
+ * `base`, so its ⌘Z restores the text the session opened on. A session whose last draft already
1704
+ * was its final text sends no commit: `settled()` records what is held before anything reads the
1705
+ * log, so ⌘Z (which refreshes first) finds the session's step, and a ⌘Z mid-typing at worst splits
1706
+ * one session into two steps. In memory only, like the ⌘Z stack: after a restart a held draft is
1707
+ * on disk and the next stroke's catch-up records it as `outside`.
1708
+ */
1709
+ const draftsHeld = new Map<
1710
+ string,
1711
+ { base: string | undefined; text: string; contested: Set<string> }
1712
+ >();
1713
+ /** Record what is held for `slug` (or every board) as one step now. */
1714
+ function releaseDrafts(slug?: string): void {
1715
+ for (const [s, held] of [...draftsHeld]) {
1716
+ if (slug !== undefined && s !== slug) continue;
1717
+ draftsHeld.delete(s);
1718
+ proposeStroke(s, held.text, held.base, [...held.contested]);
1719
+ }
1720
+ }
1721
+ function proposeStroke(
1722
+ slug: string,
1723
+ text: string,
1724
+ baseText: string | undefined,
1725
+ contested: readonly string[] = [],
1726
+ draft = false
1727
+ ): void {
1728
+ const held = draftsHeld.get(slug);
1729
+ if (draft) {
1730
+ const c = new Set(held?.contested ?? []);
1731
+ for (const id of contested) c.add(id);
1732
+ draftsHeld.set(slug, { base: held ? held.base : baseText, text, contested: c });
1733
+ return;
1734
+ }
1735
+ if (held) {
1736
+ draftsHeld.delete(slug);
1737
+ baseText = held.base;
1738
+ contested = [...new Set([...held.contested, ...contested])];
1739
+ }
1740
+ // A room's projection repeats the board the PUT just proposed: the same bytes ON THE SAME BASE are
1741
+ // one stroke. sec-a L1: the base is part of the key — the same bytes over a base the last stroke
1742
+ // didn't name (an outside write in between) go on to proposeLanesNow, which keeps its outside row.
1743
+ const key = strokeKey(text, baseText);
1744
+ if (lastStroke.get(slug) === key) return;
1745
+ lastStroke.set(slug, key);
1746
+ const run: Promise<unknown> = readyP
1747
+ .then(() =>
1748
+ serial(async () => {
1749
+ const value = laneValueFromFile('annotations', text);
1750
+ if (value === null) return null;
1751
+ const live = canvasForSlug(slug);
1752
+ if (live === null) return null;
1753
+ const r = await proposeLanesNow(
1754
+ slug,
1755
+ [{ lane: 'annotations', text, baseText: baseText ?? null }],
1756
+ { kind: 'edit', label: STUDIO_LANE_LABEL.annotations }
1757
+ );
1758
+ if (r.status === 'accepted' && r.actionId) {
1759
+ textSteps.note(r.actionId, {
1760
+ slug,
1761
+ // an unknown base (null) records no slots: only the contest is known then
1762
+ slots: baseText === undefined ? new Map() : changedTextSlots(baseText, text),
1763
+ contested: [...contested],
1764
+ });
1765
+ }
1766
+ return r;
1767
+ })
1768
+ )
1769
+ .catch((err) => log.error(`[local-kernel] recording the ${slug} board failed:`, err))
1770
+ .finally(() => strokes.delete(run));
1771
+ strokes.add(run);
1772
+ }
1773
+
1774
+ /**
1775
+ * S4.20 G3 — a run-tagged board batch (server.ts onAnnotationsChanged → `stageRunAnnotations`) joins
1776
+ * the run's stage, like the hub's `proposeLane` honours `stageable`: the run's design change and its
1777
+ * resolves end as ONE `ai` action, so one ⌘Z takes back both. Answers false when no open run claims
1778
+ * this board (the caller records it as the person's stroke, as before). The same bytes are then
1779
+ * one stroke (`lastStroke`): server.ts's plain proposal right after — a local home answers null —
1780
+ * adds nothing. A board the store has not caught up with is first brought to `baseText` by an
1781
+ * `outside` row, so the run's undo takes back exactly its own change. The capture is not awaited:
1782
+ * it settles when the run ends, and `settled()` (which `endAiAction` waits on) must not wait for it.
1783
+ */
1784
+ function stageStroke(
1785
+ slug: string,
1786
+ text: string,
1787
+ baseText: string | undefined,
1788
+ writeId: string | undefined
1789
+ ): boolean {
1790
+ const value = laneValueFromFile('annotations', text);
1791
+ const canvas = value === null ? null : canvasForSlug(slug);
1792
+ if (value === null || canvas === null || !stage.captures(canvas, true, value)) return false;
1793
+ // The same key as proposeStroke (sec-a L1 keys on the base too): server.ts's plain proposal of the
1794
+ // same bytes on the same base right after is this stroke, not a second "Edit annotations".
1795
+ lastStroke.set(slug, strokeKey(text, baseText));
1796
+ const run: Promise<unknown> = readyP
1797
+ .then(() =>
1798
+ serial(async () => {
1799
+ if (!opened || !kernel) return null;
1800
+ const store = opened.store;
1801
+ const m = await store.manifest();
1802
+ const live = (m.docs as { doc: string; path: string; retired: boolean }[]).find(
1803
+ (d) => !d.retired && d.path === canvas
1804
+ );
1805
+ // The run ended (or the canvas went) meanwhile: the board is the person's stroke after all.
1806
+ if (!live || !stage.captures(canvas, true, value)) {
1807
+ return proposeLanesNow(
1808
+ slug,
1809
+ [{ lane: 'annotations', text, baseText: baseText ?? null }],
1810
+ { kind: 'edit', label: STUDIO_LANE_LABEL.annotations }
1811
+ );
1812
+ }
1813
+ const head = (await store.heads([live.doc]))[live.doc] as {
1814
+ lanes: Record<string, { hash: string | null }>;
1815
+ };
1816
+ const headHash = hashOr(head?.lanes?.annotations?.hash);
1817
+ const headValue =
1818
+ headHash === EMPTY_HASH ? '' : (((await store.blob(headHash)) as string | null) ?? '');
1819
+ const base =
1820
+ baseText === undefined ? headValue : laneValueFromFile('annotations', baseText);
1821
+ if (base === null) return null;
1822
+ if (laneHash(base) !== headHash) {
1823
+ const r = await submit(
1824
+ [
1825
+ {
1826
+ op: 'lane.replace',
1827
+ doc: live.doc,
1828
+ lane: 'annotations',
1829
+ content: base,
1830
+ base: headHash,
1831
+ },
1832
+ ],
1833
+ { kind: OUTSIDE_KIND, label: null },
1834
+ actor,
1835
+ {},
1836
+ true
1837
+ );
1838
+ if (r.status !== 'accepted') return r;
1839
+ }
1840
+ void stage
1841
+ .capture(canvas, live.doc, {
1842
+ lane: 'annotations',
1843
+ content: value,
1844
+ baseContent: base,
1845
+ transactionId: `lt_stage_${now().toString(36)}_${(++runTx).toString(36)}`,
1846
+ ...(writeId ? { writeId } : {}),
1847
+ stageable: true,
1848
+ })
1849
+ .catch(() => null);
1850
+ return null;
1851
+ })
1852
+ )
1853
+ .catch((err) => log.error(`[local-kernel] staging the ${slug} board failed:`, err))
1854
+ .finally(() => strokes.delete(run));
1855
+ strokes.add(run);
1856
+ return true;
1857
+ }
1858
+
1859
+ /** Write one lane's value to its file (an empty side lane removes the file). */
1860
+ function writeLane(canvasRel: string, l: LocalLane, value: string): void {
1861
+ const rel = sibling(canvasRel, l);
1862
+ if (value === '') {
1863
+ if (l !== 'html') {
1864
+ try {
1865
+ unlinkSync(abs(rel));
1866
+ } catch {
1867
+ /* absent */
1868
+ }
1869
+ seen.set(`${canvasRel}|${l}`, '');
1870
+ }
1871
+ return;
1872
+ }
1873
+ const text = l === 'meta' ? mergeSharedMetaIntoLocal(readText(rel), value) : value;
1874
+ if (text === null) return;
1875
+ atomicWrite(abs(rel), text);
1876
+ seen.set(`${canvasRel}|${l}`, value);
1877
+ }
1878
+
1879
+ /**
1880
+ * A discarded run's bytes leave the disk: its deltas are taken back out of what the disk holds
1881
+ * now (three-way — a person's edit made since stays). A lane that cannot be untangled is left
1882
+ * as it is, and the next watched change records it.
1883
+ */
1884
+ function unstage(l: {
1885
+ slug: string;
1886
+ lane: string;
1887
+ base: string;
1888
+ mine: string;
1889
+ create?: string;
1890
+ }): void {
1891
+ // S12.16 — a canvas the run created has no earlier bytes to put back, and a discard never
1892
+ // deletes a file: it stays, unrecorded, and the next watched change (or boot) records it.
1893
+ if (l.create) {
1894
+ seen.delete(`${l.slug}|${l.lane}`);
1895
+ return;
1896
+ }
1897
+ if (!(LOCAL_LANES as readonly string[]).includes(l.lane)) return;
1898
+ const lane = l.lane as LocalLane;
1899
+ const disk = diskLane(l.slug, lane);
1900
+ if (disk === null) return;
1901
+ let next: string | null = null;
1902
+ if (disk === l.mine) next = l.base;
1903
+ else if (lane === 'html') {
1904
+ const m = mergeSource(l.mine, l.base, disk);
1905
+ next = m.ok ? m.merged : null;
1906
+ }
1907
+ if (next === null) {
1908
+ log.warn(
1909
+ `[local-kernel] ${l.slug}: the discarded AI changes could not be taken out — left as it is`
1910
+ );
1911
+ return;
1912
+ }
1913
+ if (next !== disk) writeLane(l.slug, lane, next);
1914
+ }
1915
+
1916
+ /* -------------------------------------------------------------- watcher */
1917
+
1918
+ const pending = new Set<string>();
1919
+ /** Paths held for a move the studio announced: path → the time the hold lapses. */
1920
+ const moveHeld = new Map<string, number>();
1921
+ const holdLive = (rel: string): boolean => {
1922
+ const until = moveHeld.get(rel);
1923
+ if (until === undefined) return false;
1924
+ if (until > now()) return true;
1925
+ moveHeld.delete(rel);
1926
+ return false;
1927
+ };
1928
+ function expectMove(fromRel: string, toRel: string): void {
1929
+ const from = canvasOfRel(fromRel);
1930
+ const to = canvasOfRel(toRel);
1931
+ if (!from || !to || !/\.tsx$/i.test(fromRel)) return;
1932
+ const until = now() + MOVE_HOLD_MS;
1933
+ moveHeld.set(from, until);
1934
+ moveHeld.set(to, until);
1935
+ }
1936
+ let timer: ReturnType<typeof setTimeout> | null = null;
1937
+ let chain: Promise<unknown> = Promise.resolve();
1938
+ const serial = <T>(fn: () => Promise<T>): Promise<T> => {
1939
+ const run = chain.then(fn, fn);
1940
+ chain = run.catch(() => {});
1941
+ return run;
1942
+ };
1943
+
1944
+ function drain(): Promise<void> {
1945
+ if (timer) clearTimeout(timer);
1946
+ timer = null;
1947
+ const batch = [...pending];
1948
+ pending.clear();
1949
+ return serial(async () => {
1950
+ await readyP;
1951
+ for (const rel of batch) {
1952
+ try {
1953
+ await syncCanvas(rel, { kind: OUTSIDE_KIND, label: null });
1954
+ } catch (err) {
1955
+ log.error(`[local-kernel] recording ${rel} failed:`, err);
1956
+ }
1957
+ }
1958
+ });
1959
+ }
1960
+
1961
+ function observe(rel: string): void {
1962
+ if (closed || !lock) return;
1963
+ const canvas = canvasOfPath(rel);
1964
+ if (!canvas) return;
1965
+ pending.add(canvas);
1966
+ if (timer) clearTimeout(timer);
1967
+ timer = setTimeout(() => void drain(), settleMs);
1968
+ (timer as { unref?: () => void }).unref?.();
1969
+ }
1970
+
1971
+ function observeMove(fromRel: string, toRel: string): void {
1972
+ if (closed || !lock) return;
1973
+ const from = canvasOfRel(fromRel);
1974
+ const to = canvasOfRel(toRel);
1975
+ if (!from || !to || !/\.tsx$/i.test(fromRel)) return;
1976
+ moveHeld.delete(from);
1977
+ moveHeld.delete(to);
1978
+ pending.delete(from);
1979
+ pending.delete(to);
1980
+ void serial(async () => {
1981
+ await readyP;
1982
+ if (!opened) return;
1983
+ const live: string | null = await opened.store.docByPath(from);
1984
+ if (!live) return void (await syncCanvas(to, { kind: OUTSIDE_KIND, label: null }));
1985
+ const st = (await opened.store.heads([live]))[live];
1986
+ const r = await submit(
1987
+ [
1988
+ {
1989
+ op: 'doc.move',
1990
+ doc: live,
1991
+ generation: st?.generation,
1992
+ to: { path: to, doc: canvasSlugFromRel(to, designRel) },
1993
+ },
1994
+ ],
1995
+ { kind: OUTSIDE_KIND, label: NAME(to) }
1996
+ );
1997
+ // A move the kernel refused still lands its content as a create.
1998
+ if (r.status !== 'accepted') await syncCanvas(to, { kind: OUTSIDE_KIND, label: null });
1999
+ // Content edited in the same burst.
2000
+ await syncCanvas(to, { kind: OUTSIDE_KIND, label: null });
2001
+ });
2002
+ }
2003
+
2004
+ /* -------------------------------------------------------------- reading */
2005
+
2006
+ async function rowsOf(
2007
+ o: OpenedStore,
2008
+ q: {
2009
+ limit?: number;
2010
+ before?: number | null;
2011
+ entry?: string | null;
2012
+ chat?: string | null;
2013
+ kind?: string | null;
2014
+ actor?: string | null;
2015
+ }
2016
+ ): Promise<LocalHistoryRow[]> {
2017
+ const m = await o.store.manifest();
2018
+ const pathOf = new Map<string, string>(
2019
+ (m.docs as { doc: string; path: string }[]).map((d) => [d.doc, d.path])
2020
+ );
2021
+ const history = (await o.store.history({
2022
+ limit: Math.min(Math.max(q.limit ?? 50, 1), 200),
2023
+ before: q.before ?? null,
2024
+ entry: q.entry ?? null,
2025
+ chat: q.chat ?? null,
2026
+ kind: q.kind ?? null,
2027
+ actor: q.actor ?? null,
2028
+ })) as {
2029
+ revision: number;
2030
+ actionId: string;
2031
+ actor: string;
2032
+ kind: string;
2033
+ label: string | null;
2034
+ committedAt: number;
2035
+ undoes: string | string[] | null;
2036
+ origin?: Record<string, unknown> | null;
2037
+ effects: {
2038
+ doc: string | null;
2039
+ lane: string;
2040
+ beforePath: string | null;
2041
+ afterPath: string | null;
2042
+ }[];
2043
+ }[];
2044
+ return history.map((a) => {
2045
+ const { canvases, lanes } = canvasLanes(
2046
+ a.effects,
2047
+ (d) => pathOf.get(d),
2048
+ (p) => /\.tsx$/i.test(p)
2049
+ );
2050
+ const named = namedField(a.kind, a.origin);
2051
+ return {
2052
+ revision: a.revision,
2053
+ actionId: a.actionId,
2054
+ actor: a.actor,
2055
+ mine: a.actor === actor,
2056
+ kind: a.kind,
2057
+ label: a.label,
2058
+ committedAt: a.committedAt,
2059
+ undoes: a.undoes,
2060
+ canvases,
2061
+ lanes,
2062
+ ...(named ? { named } : {}),
2063
+ ...originFields(a.origin),
2064
+ };
2065
+ });
2066
+ }
2067
+
2068
+ /** The document a repo-relative canvas path names: the live one, else its slug's. */
2069
+ async function docOf(o: OpenedStore, repoRel: string): Promise<string | null> {
2070
+ const rel = designRelOf(repoRel, designRel);
2071
+ if (!rel) return null;
2072
+ return (await o.store.docByPath(rel)) ?? canvasSlugFromRel(rel, designRel);
2073
+ }
2074
+
2075
+ /**
2076
+ * Before answering, every observation already made is in the log — and so is every write the
2077
+ * studio NOTED whose fs event has not arrived yet (S2.20b: the write landed before its route
2078
+ * answered, so a ⌘Z the instant after it must undo it, never the edit before it).
2079
+ */
2080
+ async function settled(): Promise<void> {
2081
+ await readyP;
2082
+ // p8-fix-d F13 — a held text session is an observation already made.
2083
+ if (draftsHeld.size) releaseDrafts();
2084
+ if (lock && !closed) {
2085
+ for (const [k, n] of notes) {
2086
+ if (now() - n.at > WRITE_NOTE_MS) notes.delete(k);
2087
+ else pending.add(k.slice(0, k.lastIndexOf('|')));
2088
+ }
2089
+ }
2090
+ if (strokes.size) await Promise.allSettled([...strokes]);
2091
+ if (pending.size) await drain();
2092
+ else await serial(async () => {});
2093
+ }
2094
+
2095
+ const runtime: LocalRuntime = {
2096
+ cancelAssetSweep: () => false,
2097
+ // S5.15 (U22) — the in-process kernel always takes `actionIds` (Undo this chat as one version).
2098
+ chatUndoReady: () => true,
2099
+ proposeLanes: (slug, lanes, o) => proposeLanes(slug, lanes, o),
2100
+ async acceptedHistory(q) {
2101
+ await settled();
2102
+ const o = opened;
2103
+ if (!o) return [];
2104
+ let entry: string | null = null;
2105
+ if (q.path) {
2106
+ const doc = await docOf(o, q.path);
2107
+ const h = doc ? (await o.store.heads([doc]))[doc] : null;
2108
+ entry = (h as { entry?: string } | undefined)?.entry ?? null;
2109
+ if (!entry) return [];
2110
+ }
2111
+ return rowsOf(o, {
2112
+ limit: q.limit,
2113
+ before: q.before,
2114
+ entry,
2115
+ chat: q.chat ?? null,
2116
+ kind: q.kind ?? null,
2117
+ actor: q.mine ? actor : null,
2118
+ });
2119
+ },
2120
+ async acceptedVersion(repoRel, revision, lane = 'html', opt) {
2121
+ if (!(LOCAL_LANES as readonly string[]).includes(lane)) return null;
2122
+ await readyP;
2123
+ const o = opened;
2124
+ if (!o) return null;
2125
+ const doc = await docOf(o, repoRel);
2126
+ if (!doc) return null;
2127
+ if (opt?.aside) {
2128
+ // The `@aside` effect of that one action (kernel opHistoryAside): its body, by hash.
2129
+ const [r] = (await o.store.revisions({ after: revision - 1, limit: 1 })) as {
2130
+ revision: number;
2131
+ effects?: { doc: string; lane: string; op: string; afterHash: string | null }[];
2132
+ }[];
2133
+ const e =
2134
+ r?.revision === revision
2135
+ ? r.effects?.find(
2136
+ (x) => x.lane === '@aside' && x.doc === doc && x.op === `aside.${lane}`
2137
+ )
2138
+ : undefined;
2139
+ return e?.afterHash ? ((await o.store.blob(e.afterHash)) as string | null) || null : null;
2140
+ }
2141
+ const hash = await o.store.laneAt(doc, lane, revision);
2142
+ return hash ? ((await o.store.blob(hash)) as string | null) || null : null;
2143
+ },
2144
+ async acceptedRestore(repoRel, revision, opt) {
2145
+ await settled();
2146
+ if (!kernel || !opened) return { status: 'rejected', code: 'store-locked' };
2147
+ const doc = await docOf(opened, repoRel);
2148
+ if (!doc) return { status: 'rejected', code: 'unknown-canvas' };
2149
+ if (opt?.lanes) {
2150
+ // The local store keeps no CSS lane (LOCAL_LANES): a splice never carries one here.
2151
+ if (
2152
+ !opt.lanes.length ||
2153
+ opt.lanes.some((l) => !(LOCAL_LANES as readonly string[]).includes(l.lane))
2154
+ )
2155
+ return { status: 'rejected', code: 'invalid' };
2156
+ const lanes = opt.lanes;
2157
+ return serial(() =>
2158
+ submit(
2159
+ lanes.map((l) => ({
2160
+ op: 'lane.replace',
2161
+ doc,
2162
+ lane: l.lane,
2163
+ content: l.content,
2164
+ baseContent: l.baseContent,
2165
+ })),
2166
+ { kind: 'restore', label: opt.label ?? `Restore ${NAME(repoRel)}` }
2167
+ )
2168
+ );
2169
+ }
2170
+ return serial(() =>
2171
+ submit([{ op: 'history.restore', revision, docs: [doc] }], {
2172
+ kind: 'history.restore',
2173
+ label: opt?.label ?? `Restore ${NAME(repoRel)} to version ${revision}`,
2174
+ })
2175
+ );
2176
+ },
2177
+ async acceptedName(repoRel, revision, name) {
2178
+ await settled();
2179
+ if (!kernel || !opened) return { status: 'rejected', code: 'store-locked' };
2180
+ const doc = await docOf(opened, repoRel);
2181
+ if (!doc) return { status: 'rejected', code: 'unknown-canvas' };
2182
+ return serial(() =>
2183
+ submit([{ op: 'history.name', doc, revision, name }], {
2184
+ kind: 'name',
2185
+ label: name ?? 'Name cleared',
2186
+ })
2187
+ );
2188
+ },
2189
+ async acceptedAside(repoRel, lane, content, label) {
2190
+ await settled();
2191
+ if (!kernel || !opened) return { status: 'rejected', code: 'store-locked' };
2192
+ // The local store keeps no CSS lane (LOCAL_LANES): nothing to set aside there.
2193
+ if (!(LOCAL_LANES as readonly string[]).includes(lane))
2194
+ return { status: 'rejected', code: 'invalid' };
2195
+ const doc = await docOf(opened, repoRel);
2196
+ if (!doc) return { status: 'rejected', code: 'unknown-canvas' };
2197
+ return serial(() =>
2198
+ submit([{ op: 'history.aside', doc, lane, content, ...(label ? { label } : {}) }], {
2199
+ kind: 'aside',
2200
+ label: label ?? 'Version not kept',
2201
+ })
2202
+ );
2203
+ },
2204
+ async textUndoConflict(raw, redo = false) {
2205
+ if (redo) return false;
2206
+ await settled();
2207
+ const target = asTarget(raw);
2208
+ const o = opened;
2209
+ let ids: string[] =
2210
+ 'actionId' in target ? [target.actionId] : 'actionIds' in target ? target.actionIds : [];
2211
+ if ('chatId' in target && o) {
2212
+ const found = chatActionIds(
2213
+ await rowsOf(o, { limit: 200, chat: target.chatId, actor, kind: 'ai' }),
2214
+ target.chatId
2215
+ );
2216
+ ids = found.ok ? found.actionIds : [];
2217
+ }
2218
+ const ledger = textSteps.conflict(ids, (slug) => {
2219
+ if (!/^[a-z0-9][a-z0-9._-]*$/i.test(slug) || slug.includes('..')) return null;
2220
+ try {
2221
+ return boardTextSlots(readFileSync(abs(`${slug}.annotations.json`), 'utf8'));
2222
+ } catch {
2223
+ return new Map();
2224
+ }
2225
+ });
2226
+ if (ledger || ids.length < 2 || !o) return ledger;
2227
+ // p8-fix-d F12 — several targets as ONE action: the ledger cannot judge them (newer targets move
2228
+ // the text older ones are compared against), so the steps the store recorded are reverted in
2229
+ // turn onto the board's head, exactly as on a hub (sync/hub-text-undo.ts). Fail open.
2230
+ type StoreRow = { actionId: string; revision: number; effects: HubEffect[] };
2231
+ const rows = (await o.store.history({ limit: 200, actor })) as StoreRow[];
2232
+ return hubTextUndoConflict(
2233
+ { actionIds: ids },
2234
+ {
2235
+ action: async (id) => rows.find((r) => r.actionId === id) ?? null,
2236
+ blob: async (hash) => ((await o.store.blob(hash)) as string | null) ?? null,
2237
+ head: async (doc) => {
2238
+ const h = (await o.store.heads([doc]))[doc] as
2239
+ | { lanes?: Record<string, { hash: string | null }> }
2240
+ | undefined;
2241
+ const hash = hashOr(h?.lanes?.annotations?.hash);
2242
+ return hash === EMPTY_HASH
2243
+ ? ''
2244
+ : (((await o.store.blob(hash)) as string | null) ?? null);
2245
+ },
2246
+ }
2247
+ ).catch(() => false);
2248
+ },
2249
+ async acceptedUndo(raw, redo = false, o) {
2250
+ await settled();
2251
+ if (!kernel || !opened) return { status: 'rejected', code: 'store-locked' };
2252
+ const target = asTarget(raw);
2253
+ const label = undoLabel(target, redo, o?.via);
2254
+ let ids: { actionId: string } | { actionIds: string[] };
2255
+ if ('chatId' in target) {
2256
+ // "Undo this chat": this person's own `ai` actions of the chat, as ONE action.
2257
+ const rows = await rowsOf(opened, { limit: 200, chat: target.chatId, actor, kind: 'ai' });
2258
+ const found = chatActionIds(rows, target.chatId);
2259
+ if (!found.ok) return { status: 'rejected', code: found.code };
2260
+ ids = { actionIds: found.actionIds };
2261
+ } else ids = target;
2262
+ return serial(() =>
2263
+ submit([{ op: redo ? 'history.redo' : 'history.undo', ...ids }], {
2264
+ kind: redo ? 'redo' : 'undo',
2265
+ label,
2266
+ })
2267
+ );
2268
+ },
2269
+ async proposeFiles(files, action) {
2270
+ await settled();
2271
+ if (!kernel || !opened) return { status: 'rejected', code: 'store-locked' };
2272
+ const o = opened;
2273
+ return serial(async (): Promise<LocalOutcome> => {
2274
+ const ops: unknown[] = [];
2275
+ for (const f of files) {
2276
+ const rel = String(f.rel).replace(/\\/g, '/').replace(/^\/+/, '');
2277
+ const canvas = canvasOfRel(rel);
2278
+ if (!canvas || typeof f.text !== 'string') return { status: 'rejected', code: 'invalid' };
2279
+ const lane: LocalLane =
2280
+ rel === canvas ? 'html' : /\.meta\.json$/i.test(rel) ? 'meta' : 'annotations';
2281
+ const value = laneValueFromFile(lane, f.text);
2282
+ if (value === null) return { status: 'rejected', code: 'invalid' };
2283
+ const doc = await o.store.docByPath(canvas);
2284
+ if (!doc) return { status: 'rejected', code: 'unknown-canvas' };
2285
+ const head = (await o.store.heads([doc]))[doc] as {
2286
+ lanes?: Record<string, { hash: string | null }>;
2287
+ };
2288
+ const base = hashOr(head?.lanes?.[lane]?.hash);
2289
+ if (laneHash(value) === base) continue;
2290
+ ops.push({ op: 'lane.replace', doc, lane, content: value, base });
2291
+ }
2292
+ if (!ops.length) return { status: 'accepted' };
2293
+ return submit(ops, action);
2294
+ });
2295
+ },
2296
+ // S1.7 — the shared Trash over the store's readers (S1-trash.md §1). A local
2297
+ // project is its owner's, so `submit` passes every cap (S1.6).
2298
+ async acceptedTrash() {
2299
+ await settled();
2300
+ const o = opened;
2301
+ if (!o || typeof o.store.trash !== 'function') return null;
2302
+ const { canvases, artboards } = await o.store.trash({});
2303
+ const live: TrashListing['live'] = {};
2304
+ for (const entry of new Set((artboards as { entry: string }[]).map((a) => a.entry))) {
2305
+ const doc = await o.store.liveDocByEntry(entry);
2306
+ const h = doc ? (await o.store.heads([doc]))[doc] : null;
2307
+ if (doc && h?.path) live[entry] = { doc, path: h.path };
2308
+ }
2309
+ return { canvases, artboards, live, you: actor };
2310
+ },
2311
+ async acceptedTrashRestore(entry) {
2312
+ await settled();
2313
+ if (!kernel || !opened) return { status: 'rejected', code: 'store-locked' };
2314
+ const o = opened;
2315
+ const [item] = (await o.store.trash({ entry })).canvases as { path: string }[];
2316
+ const r = await serial(() =>
2317
+ submit([{ op: 'trash.restore', entry }], {
2318
+ kind: 'restore',
2319
+ label: item ? `Restored “${NAME(item.path)}” from the trash` : 'Restored from the trash',
2320
+ })
2321
+ );
2322
+ if (r.status !== 'accepted') return r;
2323
+ const doc = await o.store.liveDocByEntry(entry);
2324
+ const h = doc ? (await o.store.heads([doc]))[doc] : null;
2325
+ return h?.path ? { ...r, path: h.path } : r;
2326
+ },
2327
+ async acceptedTrashClear(items) {
2328
+ await settled();
2329
+ if (!kernel || !opened) return { status: 'rejected', code: 'store-locked' };
2330
+ return serial(() =>
2331
+ submit([{ op: 'trash.clear', ...(items ? { items } : {}) }], {
2332
+ kind: 'trash.clear',
2333
+ label: 'Cleared out the trash',
2334
+ })
2335
+ );
2336
+ },
2337
+ // S1.18 — the manifest rows a stable link resolves over (history/links.ts).
2338
+ async acceptedLinkDocs() {
2339
+ await settled();
2340
+ const o = opened;
2341
+ if (!o) return null;
2342
+ const m = await o.store.manifest();
2343
+ return (m.docs as { entry: string; path: string | null; retired: boolean }[]).map((d) => ({
2344
+ entry: d.entry,
2345
+ path: d.path,
2346
+ retired: !!d.retired,
2347
+ }));
2348
+ },
2349
+ async acceptedTrashed(entry) {
2350
+ await settled();
2351
+ const o = opened;
2352
+ if (!o) return false;
2353
+ const t = (await o.store.trash({ entry })) as { canvases?: unknown[] } | null;
2354
+ return (t?.canvases?.length ?? 0) > 0;
2355
+ },
2356
+ beginAiAction(key, label, meta) {
2357
+ if (!kernel) return;
2358
+ const { shell, ...rest } = meta ?? {};
2359
+ // p8-a1-claims — a window names its canvases repo-relative; the stage keys them by canvas rel
2360
+ const slugs = (shell?.files ?? [])
2361
+ .map((f) => {
2362
+ const rel = designRelOf(f, designRel) ?? String(f).replace(/^\/+/, '');
2363
+ return rel ? canvasOfRel(rel) : null;
2364
+ })
2365
+ .filter((c): c is string => !!c);
2366
+ stage.begin(key, label, {
2367
+ ...rest,
2368
+ ...(shell
2369
+ ? {
2370
+ shell: {
2371
+ call: shell.call,
2372
+ open: shell.open,
2373
+ slugs,
2374
+ ...(shell.all ? { all: true } : {}),
2375
+ },
2376
+ }
2377
+ : {}),
2378
+ });
2379
+ },
2380
+ proposeLane(slug, lane, text, o) {
2381
+ if (!lock || closed) return null;
2382
+ if (lane === 'annotations') {
2383
+ const draft = o?.draft === true || isDraftWriteId(o?.writeId);
2384
+ // p8-fix-d F13 — the person's held typing is their step, never part of an AI run's stage.
2385
+ if (!draft && o?.stageable === true && draftsHeld.has(slug)) releaseDrafts(slug);
2386
+ if (!(!draft && o?.stageable === true && stageStroke(slug, text, o.baseText, o.writeId)))
2387
+ proposeStroke(slug, text, o?.baseText, o?.contested, draft);
2388
+ } else noteLane(slug, lane, text);
2389
+ return null;
2390
+ },
2391
+ claimAiWrite(key, repoRel, hash) {
2392
+ const rel = designRelOf(repoRel, designRel) ?? String(repoRel).replace(/^\/+/, '');
2393
+ const canvas = rel ? canvasOfRel(rel) : null;
2394
+ if (canvas) stage.claim(key, canvas, hash ?? null);
2395
+ },
2396
+ claimAiDelete(key, repoRel) {
2397
+ const rel = designRelOf(repoRel, designRel) ?? String(repoRel).replace(/^\/+/, '');
2398
+ const canvas = rel ? canvasOfRel(rel) : null;
2399
+ if (canvas) stage.claimDelete(key, canvas);
2400
+ },
2401
+ unclaimAiDelete(key, repoRel) {
2402
+ const rel = designRelOf(repoRel, designRel) ?? String(repoRel).replace(/^\/+/, '');
2403
+ const canvas = rel ? canvasOfRel(rel) : null;
2404
+ if (canvas) stage.unclaimDelete(key, canvas);
2405
+ },
2406
+ async endAiAction(key, outcome) {
2407
+ if (!kernel) return null;
2408
+ // The watcher delivers the run's last tool write a beat after the tool returns.
2409
+ if (aiSettleMs > 0) await new Promise((r) => setTimeout(r, aiSettleMs));
2410
+ await settled();
2411
+ const touched = stage.summaryOf(key)?.touched;
2412
+ const r = await stage.end(key, outcome);
2413
+ return r ? aiOutcome(r, touched) : null;
2414
+ },
2415
+ async resolveAiAction(choice, runId) {
2416
+ if (!kernel) return null;
2417
+ await settled();
2418
+ const held = stage.runs().filter((r) => r.state === 'held' && (!runId || r.runId === runId));
2419
+ if (!held.length) return null;
2420
+ if (choice === 'discard') {
2421
+ const lanes = held.flatMap((r) => stage.lanesOf(r.runId));
2422
+ const canvases = stage.discard(runId);
2423
+ await serial(async () => {
2424
+ for (const l of lanes) unstage(l);
2425
+ });
2426
+ return { status: 'discarded', canvases };
2427
+ }
2428
+ const touched: Record<string, string[]> = {};
2429
+ for (const r of held)
2430
+ for (const [c, ids] of Object.entries(r.touched))
2431
+ touched[c] = [...new Set([...(touched[c] ?? []), ...ids])].sort();
2432
+ const r = await stage.publish(runId);
2433
+ return r ? aiOutcome(r, touched) : null;
2434
+ },
2435
+ };
2436
+
2437
+ function aiOutcome(
2438
+ r: { status: 'accepted' | 'rejected'; code?: string; actionId?: unknown },
2439
+ touched: Record<string, string[]> | undefined
2440
+ ): AiActionOutcome {
2441
+ return {
2442
+ status: r.status,
2443
+ ...(r.code ? { code: r.code } : {}),
2444
+ ...(typeof r.actionId === 'string' ? { actionId: r.actionId } : {}),
2445
+ ...(touched && Object.keys(touched).length ? { touched } : {}),
2446
+ };
2447
+ }
2448
+
2449
+ /* -------------------------------------------------------------- foreign */
2450
+
2451
+ function foreignStores(): ForeignStore[] {
2452
+ let names: string[] = [];
2453
+ try {
2454
+ names = readdirSync(stateDir);
2455
+ } catch {
2456
+ return [];
2457
+ }
2458
+ const out: ForeignStore[] = [];
2459
+ for (const n of names.sort()) {
2460
+ if (!FOREIGN_STORE.test(n)) continue;
2461
+ const f = path.join(stateDir, n);
2462
+ let mach: string | null = null;
2463
+ let name: string | null = null;
2464
+ try {
2465
+ if (!statSync(f).isFile()) continue;
2466
+ const db = new Database(f, { readonly: true });
2467
+ const sql = bunSqliteAdapter(db);
2468
+ mach = storeMachine(sql);
2469
+ name = readStoreMeta(sql, 'machineName');
2470
+ db.close();
2471
+ } catch {
2472
+ continue;
2473
+ }
2474
+ if (mach) out.push({ machine: mach, name, file: f });
2475
+ }
2476
+ return out;
2477
+ }
2478
+
2479
+ async function foreignHistory(
2480
+ mach: string,
2481
+ q: { limit?: number; before?: number | null } = {}
2482
+ ): Promise<LocalHistoryRow[] | null> {
2483
+ const hit = foreignStores().find((s) => s.machine === mach);
2484
+ if (!hit) return null;
2485
+ let o = foreignOpen.get(hit.file);
2486
+ if (!o) {
2487
+ o = openStore(hit.file, { readonly: true, now });
2488
+ foreignOpen.set(hit.file, o);
2489
+ }
2490
+ return (await rowsOf(o, q)).map((r) => ({ ...r, mine: false }));
2491
+ }
2492
+
2493
+ start();
2494
+
2495
+ return {
2496
+ file,
2497
+ actor,
2498
+ mode: () => (lock ? 'writer' : 'read-only'),
2499
+ ready: () => readyP,
2500
+ runtime,
2501
+ observe,
2502
+ observeMove,
2503
+ expectMove,
2504
+ noteWritten,
2505
+ withdrawWritten,
2506
+ aiRuns: () => stage.runs(),
2507
+ flush: async () => {
2508
+ if (strokes.size) await Promise.allSettled([...strokes]);
2509
+ await drain();
2510
+ },
2511
+ foreignStores,
2512
+ foreignHistory,
2513
+ store: () => {
2514
+ if (!opened) throw new Error('local store not open');
2515
+ return opened.store;
2516
+ },
2517
+ close() {
2518
+ if (closed) return;
2519
+ closed = true;
2520
+ if (timer) clearTimeout(timer);
2521
+ if (retryTimer) clearInterval(retryTimer);
2522
+ for (const o of foreignOpen.values()) o.db.close();
2523
+ foreignOpen.clear();
2524
+ try {
2525
+ opened?.db.close();
2526
+ } catch {
2527
+ /* already closed */
2528
+ }
2529
+ opened = null;
2530
+ kernel = null;
2531
+ lock?.release();
2532
+ lock = null;
2533
+ },
2534
+ };
2535
+ }
2536
+
2537
+ /* ------------------------------------------------------- syncControl wiring */
2538
+
2539
+ interface SupervisorLike {
2540
+ current(): unknown;
2541
+ }
2542
+
2543
+ /**
2544
+ * Foundation §5 — `ctx.syncControl.current()` answers with the hub runtime when
2545
+ * one runs, and with the local home when the project has no hub. A linked
2546
+ * project never sees the local home (its history is the hub's, as today), even
2547
+ * while its runtime is down: `isLocal()` is read on every call, so a project
2548
+ * linked or unlinked at runtime switches homes with no restart.
2549
+ */
2550
+ export function withLocalHome<S extends SupervisorLike>(
2551
+ supervisor: S,
2552
+ local: () => LocalHome | null,
2553
+ isLocal: () => boolean
2554
+ ): S {
2555
+ return new Proxy(supervisor, {
2556
+ get(target, prop, receiver) {
2557
+ if (prop === 'current') {
2558
+ return () => {
2559
+ const hub = target.current();
2560
+ if (hub) return hub;
2561
+ if (!isLocal()) return null;
2562
+ return local()?.runtime ?? null;
2563
+ };
2564
+ }
2565
+ const v = Reflect.get(target, prop, receiver);
2566
+ return typeof v === 'function' ? v.bind(target) : v;
2567
+ },
2568
+ });
2569
+ }
2570
+
2571
+ /* ------------------------------------------------------- the studio's home */
2572
+
2573
+ interface StudioLike {
2574
+ cfg: { linkedHub?: unknown; canvasGroups?: { path: string }[] };
2575
+ paths: { designRoot: string; designRel: string };
2576
+ bus: {
2577
+ on(event: string, fn: (payload: any) => void): unknown;
2578
+ emit?(e: string, p: unknown): void;
2579
+ };
2580
+ }
2581
+
2582
+ /**
2583
+ * Open the local home for a studio and feed it the watcher. A project with no
2584
+ * hub — not a cloud workspace, no `linkedHub` — answers history / undo /
2585
+ * restore from its own store; a linked project is exactly as before.
2586
+ * There is no opt-out: `MAUDE_LOCAL_STORE=0` (the legacy canvas stack's way back) went with p8-v1-drop.
2587
+ */
2588
+ export function attachLocalHome<S extends SupervisorLike>(
2589
+ ctx: StudioLike,
2590
+ supervisor: S,
2591
+ env: NodeJS.ProcessEnv = process.env
2592
+ ): { control: S; home(): LocalHome | null; close(): void } {
2593
+ const enabled = env.MAUDE_WORKSPACE_MODE !== '1';
2594
+ const isLocal = () => enabled && !ctx.cfg.linkedHub;
2595
+ let home: LocalHome | null = null;
2596
+ let failed = false;
2597
+ const get = (): LocalHome | null => {
2598
+ if (!isLocal() || failed) return null;
2599
+ if (!home) {
2600
+ try {
2601
+ home = openLocalHome({
2602
+ designRoot: ctx.paths.designRoot,
2603
+ designRel: ctx.paths.designRel,
2604
+ canvasGroups: () => ctx.cfg.canvasGroups ?? null,
2605
+ ...(ctx.bus.emit ? { emit: (e, p) => ctx.bus.emit?.(e, p) } : {}),
2606
+ });
2607
+ } catch (err) {
2608
+ // Never take the studio down: the project keeps working without
2609
+ // version history, exactly as it did before the local store existed.
2610
+ failed = true;
2611
+ console.error('[local-kernel] the local store could not open:', err);
2612
+ }
2613
+ }
2614
+ return home;
2615
+ };
2616
+ ctx.bus.on('fs:any', (rel: string) => {
2617
+ if (isLocal()) get()?.observe(rel);
2618
+ });
2619
+ /**
2620
+ * p8-a1-claims — inside an AI verb's route request (ai/write-claim.ts `withWriteClaim`), a studio
2621
+ * source write is that run's: claimed by its bytes before the watcher reads them, never noted as the
2622
+ * person's edit. True when it claimed.
2623
+ */
2624
+ const claimForRoute = (rel: string, content: string): boolean => {
2625
+ const run = currentWriteClaim();
2626
+ const home = run ? get() : null;
2627
+ if (!run || !home) return false;
2628
+ const posix = rel.replace(/\\/g, '/').replace(/^\/+/, '');
2629
+ claimWrite(home.runtime, run, `${ctx.paths.designRel}/${posix}`, content);
2630
+ recordClaim(run.chatId, posix);
2631
+ return true;
2632
+ };
2633
+ // S5.5b — the studio's own write (api.ts, after it landed): the person's edit, by content.
2634
+ ctx.bus.on(
2635
+ 'source-written',
2636
+ (p: { rel?: unknown; content?: unknown; label?: unknown; base?: unknown } | null) => {
2637
+ if (!isLocal() || typeof p?.rel !== 'string' || typeof p.content !== 'string') return;
2638
+ // p8-a1-claims — a route an AI verb called (X-Maude-Chat): the bytes are that run's, not the person's
2639
+ if (claimForRoute(p.rel, p.content)) return;
2640
+ // S2.24 G3: a studio write may say what it was; one line, bounded, so a planted label cannot flood a row
2641
+ const said = typeof p.label === 'string' ? p.label.trim().slice(0, 120) : '';
2642
+ // p8-e2e-fix-r12: the bytes the write replaced, when the writer knows them (routes/edit.ts)
2643
+ get()?.noteWritten(
2644
+ p.rel,
2645
+ p.content,
2646
+ said || undefined,
2647
+ typeof p.base === 'string' ? { base: p.base } : undefined
2648
+ );
2649
+ }
2650
+ );
2651
+ // S2.20b — the edit-op route says its bytes BEFORE they land (routes/edit.ts `writeSource`): the watcher
2652
+ // and a ⌘Z's undo-stack read can both arrive between the bytes and `source-written` (the rollback
2653
+ // snapshot is written in between), and the edit must already be the person's then, never `outside`.
2654
+ // Local home only: the hub path keeps `source-written`, which promises the bytes are on disk.
2655
+ ctx.bus.on(
2656
+ 'source-writing',
2657
+ (p: { rel?: unknown; content?: unknown; label?: unknown; base?: unknown } | null) => {
2658
+ if (!isLocal() || typeof p?.rel !== 'string' || typeof p.content !== 'string') return;
2659
+ if (claimForRoute(p.rel, p.content)) return;
2660
+ const said = typeof p.label === 'string' ? p.label.trim().slice(0, 120) : '';
2661
+ get()?.noteWritten(p.rel, p.content, said || undefined, {
2662
+ early: true,
2663
+ ...(typeof p.base === 'string' ? { base: p.base } : {}),
2664
+ });
2665
+ }
2666
+ );
2667
+ // F5 — a write said early (`source-writing`) that then threw: its bytes never landed, the note goes.
2668
+ ctx.bus.on('source-write-failed', (p: { rel?: unknown; content?: unknown } | null) => {
2669
+ if (!isLocal() || typeof p?.rel !== 'string' || typeof p.content !== 'string') return;
2670
+ get()?.withdrawWritten(p.rel, p.content);
2671
+ });
2672
+ // S2.20b (U20) — a collab room projecting its board (collab/index.ts): the person's strokes.
2673
+ ctx.bus.on(
2674
+ 'annotations-projected',
2675
+ (p: { slug?: unknown; board?: unknown; contested?: unknown; draft?: unknown } | null) => {
2676
+ if (!isLocal() || typeof p?.slug !== 'string' || typeof p.board !== 'string') return;
2677
+ // Emitted BEFORE the room's flush writes: the file still holds the board this stroke replaces.
2678
+ const safe = /^[a-z0-9][a-z0-9._-]*$/i.test(p.slug) && !p.slug.includes('..');
2679
+ let before: string | undefined;
2680
+ if (safe) {
2681
+ try {
2682
+ before = readFileSync(
2683
+ path.join(ctx.paths.designRoot, `${p.slug}.annotations.json`),
2684
+ 'utf8'
2685
+ );
2686
+ } catch {
2687
+ before = undefined;
2688
+ }
2689
+ }
2690
+ get()?.runtime.proposeLane(p.slug, 'annotations', p.board, {
2691
+ ...(before === undefined ? {} : { baseText: before }),
2692
+ ...(p.draft === true ? { draft: true } : {}),
2693
+ ...(Array.isArray(p.contested)
2694
+ ? {
2695
+ contested: p.contested
2696
+ .filter((x): x is string => typeof x === 'string')
2697
+ .slice(0, 5000),
2698
+ }
2699
+ : {}),
2700
+ });
2701
+ }
2702
+ );
2703
+ // The studio announces a move BEFORE it renames the file (api.ts moveCanvas), so the watcher cannot
2704
+ // record the old path vanishing as a delete while the sidecars are still moving.
2705
+ ctx.bus.on('canvas-move-begin', (change: { rel?: string; fromRel?: string } | null) => {
2706
+ if (!isLocal() || !change?.rel || !change.fromRel) return;
2707
+ get()?.expectMove(change.fromRel, change.rel);
2708
+ });
2709
+ ctx.bus.on(
2710
+ 'canvas-list-update',
2711
+ (change: { action?: string; rel?: string; fromRel?: string } | null) => {
2712
+ if (!isLocal() || change?.action !== 'moved' || !change.rel || !change.fromRel) return;
2713
+ get()?.observeMove(change.fromRel, change.rel);
2714
+ }
2715
+ );
2716
+ get();
2717
+ return {
2718
+ control: withLocalHome(supervisor, get, isLocal),
2719
+ home: () => home,
2720
+ close() {
2721
+ home?.close();
2722
+ home = null;
2723
+ },
2724
+ };
2725
+ }