@dexhq/canvas 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1222) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/README.md +4 -4
  3. package/app/app.tsx +21 -3
  4. package/app/base.ts +8 -3
  5. package/app/canvas/activity-bar.tsx +34 -14
  6. package/app/canvas/activity-model.ts +112 -53
  7. package/app/canvas/activity-parts.tsx +79 -13
  8. package/app/canvas/activity.tsx +155 -38
  9. package/app/canvas/add-to-spec.ts +14 -5
  10. package/app/canvas/agent-changes.ts +77 -12
  11. package/app/canvas/anchoring.ts +176 -50
  12. package/app/canvas/canvas-chrome.tsx +44 -13
  13. package/app/canvas/canvas-clipboard.ts +38 -8
  14. package/app/canvas/canvas-commands.ts +191 -20
  15. package/app/canvas/canvas-context-menu.tsx +3 -0
  16. package/app/canvas/canvas-context.tsx +23 -4
  17. package/app/canvas/canvas-corners.tsx +2 -0
  18. package/app/canvas/canvas-document.ts +140 -23
  19. package/app/canvas/canvas-input.ts +312 -36
  20. package/app/canvas/canvas-keys.ts +165 -68
  21. package/app/canvas/canvas-menus.tsx +29 -5
  22. package/app/canvas/canvas-merge.ts +141 -29
  23. package/app/canvas/canvas-model.ts +255 -215
  24. package/app/canvas/canvas-panels.ts +10 -0
  25. package/app/canvas/canvas-scene.ts +759 -110
  26. package/app/canvas/canvas-ui.ts +79 -8
  27. package/app/canvas/canvas.css +484 -34
  28. package/app/canvas/change-notice.tsx +16 -7
  29. package/app/canvas/command-menu.tsx +12 -0
  30. package/app/canvas/comment-layer.tsx +79 -120
  31. package/app/canvas/comments.tsx +391 -150
  32. package/app/canvas/device-edits.ts +19 -2
  33. package/app/canvas/device-icons.ts +1 -0
  34. package/app/canvas/device-picker.tsx +5 -2
  35. package/app/canvas/devices-panel.tsx +14 -8
  36. package/app/canvas/draw-layer.tsx +49 -10
  37. package/app/canvas/draw-model.ts +15 -12
  38. package/app/canvas/editable-text.tsx +36 -15
  39. package/app/canvas/element-link.ts +154 -0
  40. package/app/canvas/element-picker.ts +125 -480
  41. package/app/canvas/engine/camera.ts +24 -3
  42. package/app/canvas/engine/canvas-gestures.ts +223 -53
  43. package/app/canvas/engine/canvas-store.ts +36 -0
  44. package/app/canvas/engine/canvas-view.tsx +39 -3
  45. package/app/canvas/export-dialog.tsx +279 -0
  46. package/app/canvas/find-bar.tsx +114 -16
  47. package/app/canvas/find-model.ts +20 -4
  48. package/app/canvas/floating-panel.tsx +16 -0
  49. package/app/canvas/flow-canvas.tsx +396 -103
  50. package/app/canvas/flow-renames.ts +9 -0
  51. package/app/canvas/follow-pin.ts +11 -0
  52. package/app/canvas/forced-states.ts +25 -4
  53. package/app/canvas/frame-choices.tsx +4 -0
  54. package/app/canvas/frame-code.ts +139 -0
  55. package/app/canvas/frame-context-menu.tsx +325 -35
  56. package/app/canvas/frame-copies.ts +100 -29
  57. package/app/canvas/frame-drops.ts +56 -7
  58. package/app/canvas/frame-inspector.ts +154 -0
  59. package/app/canvas/frame-node.tsx +307 -80
  60. package/app/canvas/frame-pictures.ts +96 -13
  61. package/app/canvas/frame-resize.tsx +17 -0
  62. package/app/canvas/frame-shown.ts +5 -0
  63. package/app/canvas/frame-source.ts +19 -2
  64. package/app/canvas/frame-thumb.tsx +5 -4
  65. package/app/canvas/grid-overlay.tsx +4 -3
  66. package/app/canvas/grid-panel.tsx +24 -10
  67. package/app/canvas/imported-reviews.tsx +105 -41
  68. package/app/canvas/insert-hint.tsx +26 -0
  69. package/app/canvas/inspect-layer.tsx +85 -26
  70. package/app/canvas/inspect-tools.ts +15 -4
  71. package/app/canvas/jpeg-pdf.ts +30 -3
  72. package/app/canvas/label-action.tsx +2 -1
  73. package/app/canvas/large-canvas-notice.tsx +7 -1
  74. package/app/canvas/layout.ts +739 -327
  75. package/app/canvas/linked-element.tsx +219 -0
  76. package/app/canvas/live-page.ts +240 -29
  77. package/app/canvas/measure-box.tsx +1 -0
  78. package/app/canvas/mentions.tsx +221 -0
  79. package/app/canvas/new-frame.ts +73 -11
  80. package/app/canvas/note-placing.ts +187 -31
  81. package/app/canvas/number-field.tsx +3 -0
  82. package/app/canvas/open-page.ts +8 -1
  83. package/app/canvas/others-hidden.ts +140 -0
  84. package/app/canvas/page-find.ts +47 -5
  85. package/app/canvas/page-heights.tsx +21 -0
  86. package/app/canvas/page-scroll.ts +22 -4
  87. package/app/canvas/page-style.ts +3 -1
  88. package/app/canvas/pass-to-canvas.ts +81 -0
  89. package/app/canvas/pasted-cuts.ts +2 -0
  90. package/app/canvas/person-busy.ts +3 -0
  91. package/app/canvas/picked-box.tsx +22 -0
  92. package/app/canvas/picks-menu.tsx +26 -8
  93. package/app/canvas/picks.ts +36 -29
  94. package/app/canvas/point-menu.tsx +4 -0
  95. package/app/canvas/props-model.ts +27 -5
  96. package/app/canvas/props-panel.tsx +31 -6
  97. package/app/canvas/quick-bar.tsx +59 -15
  98. package/app/canvas/removed-views-panel.tsx +43 -12
  99. package/app/canvas/request-node.tsx +165 -0
  100. package/app/canvas/review-marker.tsx +9 -2
  101. package/app/canvas/review-panel.tsx +151 -43
  102. package/app/canvas/row-node.tsx +15 -3
  103. package/app/canvas/scene-context.tsx +16 -1
  104. package/app/canvas/section-node.tsx +72 -142
  105. package/app/canvas/selection.ts +3 -1
  106. package/app/canvas/server-notice.tsx +10 -4
  107. package/app/canvas/size-label.tsx +2 -1
  108. package/app/canvas/sketch-boxes.tsx +194 -139
  109. package/app/canvas/sketch-layer.tsx +88 -30
  110. package/app/canvas/sketch-model.ts +78 -9
  111. package/app/canvas/slide-frame.tsx +13 -1
  112. package/app/canvas/slide-full-screen.tsx +19 -3
  113. package/app/canvas/slide-page.tsx +9 -1
  114. package/app/canvas/slide-pdf.tsx +44 -5
  115. package/app/canvas/snapping.ts +26 -1
  116. package/app/canvas/spec-copies.ts +13 -2
  117. package/app/canvas/spec-frame.tsx +198 -60
  118. package/app/canvas/spec-full-screen.tsx +39 -17
  119. package/app/canvas/spec-margin.tsx +36 -8
  120. package/app/canvas/spec-mode.tsx +28 -20
  121. package/app/canvas/spec-placing.tsx +32 -7
  122. package/app/canvas/spec-threads.ts +14 -0
  123. package/app/canvas/spec-title.tsx +12 -5
  124. package/app/canvas/spot-pins.tsx +8 -0
  125. package/app/canvas/stack-frame.tsx +357 -0
  126. package/app/canvas/stack-model.ts +267 -0
  127. package/app/canvas/stack-node.tsx +19 -11
  128. package/app/canvas/state-store.ts +7 -0
  129. package/app/canvas/sticker-model.ts +16 -2
  130. package/app/canvas/sticker-sheet.tsx +63 -11
  131. package/app/canvas/stored-viewport.ts +14 -13
  132. package/app/canvas/styles-layer.tsx +70 -52
  133. package/app/canvas/teammates-layer.tsx +223 -0
  134. package/app/canvas/tell-open-page.tsx +12 -0
  135. package/app/canvas/testing/must.ts +11 -0
  136. package/app/canvas/testing/stand-in.ts +9 -0
  137. package/app/canvas/testing/waits.ts +17 -0
  138. package/app/canvas/text-layer.tsx +156 -29
  139. package/app/canvas/thread-focus.tsx +47 -17
  140. package/app/canvas/thread-place.ts +27 -3
  141. package/app/canvas/tip.tsx +4 -0
  142. package/app/canvas/tool-cursors.ts +22 -7
  143. package/app/canvas/tool-icons.tsx +37 -56
  144. package/app/canvas/toolbar-parts.tsx +11 -5
  145. package/app/canvas/toolbar.tsx +132 -83
  146. package/app/canvas/tools.ts +32 -9
  147. package/app/canvas/typing.ts +17 -0
  148. package/app/canvas/unknown-frame.tsx +39 -12
  149. package/app/canvas/use-activity.ts +57 -2
  150. package/app/canvas/use-agent-changes.tsx +66 -17
  151. package/app/canvas/use-canvas-clipboard.tsx +190 -64
  152. package/app/canvas/use-canvas-commands.ts +14 -0
  153. package/app/canvas/use-canvas-editor.ts +43 -16
  154. package/app/canvas/use-component-drops.ts +21 -5
  155. package/app/canvas/use-spec-copies.ts +29 -14
  156. package/app/canvas/viewports.ts +4 -1
  157. package/app/canvas/wireframe-panel.tsx +18 -2
  158. package/app/canvas/xray.ts +3 -10
  159. package/app/client.d.ts +6 -0
  160. package/app/content.d.ts +1 -0
  161. package/app/design-system/components-canvas.ts +58 -21
  162. package/app/design-system/components-prototype.tsx +56 -20
  163. package/app/design-system/pseudo-states.ts +45 -16
  164. package/app/editor/annotations.ts +60 -20
  165. package/app/editor/blocks.ts +99 -34
  166. package/app/editor/embed-arrange.tsx +59 -22
  167. package/app/editor/embed-box.ts +54 -28
  168. package/app/editor/extensions.ts +16 -5
  169. package/app/editor/markdown-source.ts +42 -8
  170. package/app/editor/node-views.tsx +39 -12
  171. package/app/editor/quote-bubble.tsx +10 -1
  172. package/app/editor/two-versions.ts +24 -9
  173. package/app/export/player-model.ts +187 -0
  174. package/app/export/player.tsx +215 -0
  175. package/app/export.html +31 -0
  176. package/app/export.tsx +9 -0
  177. package/app/frame/announce-refreshes.ts +21 -0
  178. package/app/frame/file-errors.ts +4 -0
  179. package/app/frame/frame-app.tsx +15 -1
  180. package/app/frame/frame-history.ts +9 -0
  181. package/app/frame/frame-links.ts +7 -0
  182. package/app/frame/hold-window-focus.ts +4 -0
  183. package/app/frame/left-view.tsx +6 -0
  184. package/app/frame/start-frame.tsx +56 -0
  185. package/app/frame/studio-view.tsx +2 -0
  186. package/app/frame/view-exports.ts +240 -0
  187. package/app/frame/view-loads.ts +187 -0
  188. package/app/frame/views.ts +86 -51
  189. package/app/frame.tsx +2 -38
  190. package/app/git/branch-panel.tsx +71 -25
  191. package/app/git/change-list.tsx +15 -6
  192. package/app/git/clash.tsx +10 -5
  193. package/app/git/git-controls.tsx +78 -22
  194. package/app/git/git-state.ts +20 -0
  195. package/app/git/git-toasts.tsx +41 -2
  196. package/app/git/paused.tsx +28 -12
  197. package/app/git/saved-list.tsx +10 -3
  198. package/app/git/sync-panel.tsx +39 -18
  199. package/app/i18n/locales/en/messages.po +264 -12
  200. package/app/i18n/locales/en/messages.ts +1 -1
  201. package/app/i18n/locales/pseudo/messages.po +260 -8
  202. package/app/i18n/locales/pseudo/messages.ts +1 -1
  203. package/app/i18n/locales.ts +4 -0
  204. package/app/i18n/provider.tsx +9 -5
  205. package/app/icons/dex-glyphs.tsx +257 -0
  206. package/app/icons/glyphs.tsx +80 -79
  207. package/app/icons/index.tsx +3 -1
  208. package/app/icons/types.ts +1 -0
  209. package/app/kit/inspect-runtime.ts +50 -5
  210. package/app/kit/sample-people.ts +6 -0
  211. package/app/kit/use-flow.ts +2 -1
  212. package/app/kit/use-simulated-load.ts +6 -2
  213. package/app/kit/use-simulated-stream.ts +8 -2
  214. package/app/kit/use-view-control.ts +1 -0
  215. package/app/live/canvas-teammates.ts +103 -0
  216. package/app/live/deployed-preview.ts +1 -0
  217. package/app/live/focus-reporter.ts +8 -0
  218. package/app/live/guest-review.ts +115 -23
  219. package/app/live/restart-wait.ts +14 -2
  220. package/app/live/server-connection.ts +21 -4
  221. package/app/live/studio-action.ts +6 -1
  222. package/app/live/studio-api.ts +218 -71
  223. package/app/live/studio-data.ts +26 -1
  224. package/app/live/studio-live.ts +44 -8
  225. package/app/live/studio-request.ts +15 -1
  226. package/app/live/thread-state.ts +8 -0
  227. package/app/live/use-devices.ts +11 -2
  228. package/app/live/use-focus.ts +5 -2
  229. package/app/live/use-last-edited.ts +2 -0
  230. package/app/live/use-show-requests.ts +3 -0
  231. package/app/live/use-workspace.ts +10 -2
  232. package/app/main.tsx +9 -3
  233. package/app/next/fonts.ts +1 -0
  234. package/app/next/image.tsx +17 -10
  235. package/app/next/navigation.ts +9 -6
  236. package/app/next/router.ts +4 -4
  237. package/app/pages/agent-settings.tsx +11 -3
  238. package/app/pages/ask-the-agent.tsx +2 -0
  239. package/app/pages/canvas-settings.tsx +3 -0
  240. package/app/pages/canvas.tsx +247 -76
  241. package/app/pages/chrome-extension.tsx +4 -2
  242. package/app/pages/commands-settings.tsx +75 -26
  243. package/app/pages/deployment-settings.tsx +9 -0
  244. package/app/pages/doc.tsx +4 -1
  245. package/app/pages/file-sort.ts +11 -4
  246. package/app/pages/git-checks.tsx +30 -10
  247. package/app/pages/guidelines.tsx +8 -4
  248. package/app/pages/home.tsx +41 -17
  249. package/app/pages/host.tsx +4 -0
  250. package/app/pages/markup-settings.tsx +11 -5
  251. package/app/pages/people.tsx +18 -10
  252. package/app/pages/play-bar.tsx +27 -9
  253. package/app/pages/play-size.ts +31 -11
  254. package/app/pages/play.tsx +115 -33
  255. package/app/pages/profile.tsx +6 -2
  256. package/app/pages/prototype.tsx +10 -4
  257. package/app/pages/render.tsx +72 -19
  258. package/app/pages/settings.tsx +5 -1
  259. package/app/pages/workspace-general.tsx +29 -5
  260. package/app/pages/workspace-git.tsx +38 -10
  261. package/app/pages/your-guidelines.tsx +7 -0
  262. package/app/pages/your-picture.tsx +33 -10
  263. package/app/registry-files.ts +6 -1
  264. package/app/registry.ts +73 -13
  265. package/app/renamed-storage.ts +8 -1
  266. package/app/shell/about.tsx +10 -4
  267. package/app/shell/agent-logos.tsx +4 -0
  268. package/app/shell/agent-manual.tsx +13 -5
  269. package/app/shell/avatar-pictures.ts +18 -6
  270. package/app/shell/avatar.tsx +11 -1
  271. package/app/shell/bell.tsx +41 -17
  272. package/app/shell/broke.tsx +1 -1
  273. package/app/shell/chrome-theme.tsx +4 -0
  274. package/app/shell/connect-agent.tsx +76 -38
  275. package/app/shell/copy-text.tsx +3 -1
  276. package/app/shell/deployed-preview-bar.tsx +4 -6
  277. package/app/shell/desktop-app.tsx +30 -15
  278. package/app/shell/empty-state.tsx +2 -2
  279. package/app/shell/feedback-details.ts +8 -1
  280. package/app/shell/feedback-form.tsx +38 -30
  281. package/app/shell/feedback-link.tsx +3 -0
  282. package/app/shell/file-bytes.ts +3 -1
  283. package/app/shell/host.ts +37 -8
  284. package/app/shell/info-tip.tsx +2 -1
  285. package/app/shell/install-prompt.ts +10 -1
  286. package/app/shell/instructions-editor.tsx +184 -78
  287. package/app/shell/instructions.tsx +7 -1
  288. package/app/shell/main-sidebar.tsx +27 -6
  289. package/app/shell/open-agent.tsx +8 -2
  290. package/app/shell/page-header.tsx +6 -3
  291. package/app/shell/page-title.ts +36 -14
  292. package/app/shell/presence-style.ts +8 -0
  293. package/app/shell/presence.tsx +196 -35
  294. package/app/shell/prototype-menu.tsx +84 -27
  295. package/app/shell/quick-start.tsx +21 -3
  296. package/app/shell/recents.ts +21 -2
  297. package/app/shell/report-issue.ts +29 -23
  298. package/app/shell/restart-toast.tsx +37 -4
  299. package/app/shell/save-state.tsx +4 -0
  300. package/app/shell/scaled-frame.tsx +22 -1
  301. package/app/shell/settings-sections.ts +12 -11
  302. package/app/shell/settings-sidebar.tsx +7 -1
  303. package/app/shell/settings-ui.tsx +11 -7
  304. package/app/shell/shell-bar.ts +2 -5
  305. package/app/shell/sidebar.tsx +2 -2
  306. package/app/shell/skeleton.ts +80 -22
  307. package/app/shell/status-badge.tsx +2 -0
  308. package/app/shell/studio-shell.tsx +11 -4
  309. package/app/shell/thread-list.tsx +40 -12
  310. package/app/shell/time-ago.ts +7 -0
  311. package/app/shell/toasts.tsx +20 -13
  312. package/app/shell/update-notice.tsx +241 -41
  313. package/app/shell/use-copied.ts +4 -0
  314. package/app/shell/use-space.ts +5 -0
  315. package/app/shell/watch-switch.tsx +4 -1
  316. package/app/shell/welcome.tsx +18 -3
  317. package/app/shell/window-buttons.tsx +17 -3
  318. package/app/shell/working-on.tsx +45 -5
  319. package/app/shell/workspace-mark.tsx +59 -25
  320. package/app/studio-ui.d.ts +2 -1
  321. package/app/styles.css +4 -12
  322. package/app/types.ts +8 -6
  323. package/app/ui/boundary.tsx +6 -1
  324. package/app/ui/file-drop.ts +32 -18
  325. package/app/ui/prompt-editor.tsx +112 -28
  326. package/app/ui/reference.tsx +27 -9
  327. package/app/ui/segmented.tsx +3 -1
  328. package/app/ui/theme-switch.tsx +1 -0
  329. package/app/ui/theme.css +17 -0
  330. package/app/ui/use-latest.ts +13 -0
  331. package/app/ui/use-once.ts +9 -0
  332. package/bin/dex.mjs +6 -1
  333. package/bin/sudio.mjs +2 -1
  334. package/dist/cli/banner.mjs +0 -1
  335. package/dist/cli/command.d.mts +237 -5
  336. package/dist/cli/command.mjs +8 -3
  337. package/dist/cli/commands/agents/add.mjs +1 -1
  338. package/dist/cli/commands/app.mjs +13 -16
  339. package/dist/cli/commands/claude.d.mts +3 -3
  340. package/dist/cli/commands/claude.mjs +10 -9
  341. package/dist/cli/commands/cloud/publish.mjs +1 -1
  342. package/dist/cli/commands/create.d.mts +5 -5
  343. package/dist/cli/commands/create.mjs +4 -4
  344. package/dist/cli/commands/dev.mjs +64 -19
  345. package/dist/cli/commands/doctor.mjs +3 -1
  346. package/dist/cli/commands/export.d.mts +40 -0
  347. package/dist/cli/commands/export.mjs +66 -0
  348. package/dist/cli/commands/hook.mjs +1 -1
  349. package/dist/cli/commands/init.d.mts +2 -2
  350. package/dist/cli/commands/mcp.mjs +10 -4
  351. package/dist/cli/commands/merge-canvas.d.mts +29 -0
  352. package/dist/cli/commands/merge-canvas.mjs +101 -0
  353. package/dist/cli/commands/merge-contributors.d.mts +0 -7
  354. package/dist/cli/commands/merge-contributors.mjs +2 -1
  355. package/dist/cli/commands/merge-spec.d.mts +0 -7
  356. package/dist/cli/commands/merge-spec.mjs +2 -1
  357. package/dist/cli/commands/upgrade.mjs +1 -1
  358. package/dist/cli/help.d.mts +1 -1
  359. package/dist/cli/help.mjs +20 -20
  360. package/dist/cli/main.d.mts +68 -5
  361. package/dist/cli/main.mjs +5 -2
  362. package/dist/cli/mcp-relay.d.mts +5 -5
  363. package/dist/cli/mcp-relay.mjs +36 -24
  364. package/dist/cli/recovery-server.mjs +2 -2
  365. package/dist/cli/strict-flags.mjs +6 -6
  366. package/dist/cli/supervise.mjs +37 -26
  367. package/dist/cli/ui.d.mts +21 -21
  368. package/dist/cli/ui.mjs +2 -1
  369. package/dist/config/design-system.mjs +19 -14
  370. package/dist/config/load.mjs +23 -8
  371. package/dist/config/project-files.d.mts +8 -2
  372. package/dist/config/project-files.mjs +44 -41
  373. package/dist/config/renamed.d.mts +9 -6
  374. package/dist/config/renamed.mjs +11 -12
  375. package/dist/content/biome.mjs +15 -10
  376. package/dist/content/capture.mjs +43 -42
  377. package/dist/content/commands.d.mts +21 -13
  378. package/dist/content/commands.mjs +69 -35
  379. package/dist/content/comments-log.mjs +104 -20
  380. package/dist/content/component-props.mjs +6 -10
  381. package/dist/content/content.d.mts +279 -35
  382. package/dist/content/content.mjs +247 -154
  383. package/dist/content/devices.mjs +2 -2
  384. package/dist/content/element-words.d.mts +42 -0
  385. package/dist/content/element-words.mjs +112 -0
  386. package/dist/content/file-turns.mjs +1 -1
  387. package/dist/content/first-run.mjs +3 -5
  388. package/dist/content/flow-specs.mjs +18 -16
  389. package/dist/content/format-check.d.mts +46 -0
  390. package/dist/content/format-check.mjs +338 -0
  391. package/dist/content/hosted-person.d.mts +31 -0
  392. package/dist/content/hosted-person.mjs +69 -0
  393. package/dist/content/insert-edit.mjs +7 -6
  394. package/dist/content/jsx-source.d.mts +5 -1
  395. package/dist/content/jsx-source.mjs +8 -7
  396. package/dist/content/last-edited.mjs +1 -1
  397. package/dist/content/layout.d.mts +44 -2
  398. package/dist/content/layout.mjs +65 -6
  399. package/dist/content/merge-rules.d.mts +16 -4
  400. package/dist/content/merge-rules.mjs +46 -17
  401. package/dist/content/prop-edit.mjs +4 -4
  402. package/dist/content/prototype-checks.mjs +13 -12
  403. package/dist/content/prototype-summary.d.mts +1 -1
  404. package/dist/content/prototype-summary.mjs +8 -8
  405. package/dist/content/prototypes.d.mts +8 -1
  406. package/dist/content/prototypes.mjs +41 -27
  407. package/dist/content/review-import.mjs +1 -1
  408. package/dist/content/review-pages.mjs +19 -16
  409. package/dist/content/screenshot.d.mts +4 -1
  410. package/dist/content/screenshot.mjs +26 -13
  411. package/dist/content/snapshot-client.mjs +2 -3
  412. package/dist/content/store.d.mts +16 -8
  413. package/dist/content/store.mjs +99 -26
  414. package/dist/content/sub-agents.d.mts +12 -0
  415. package/dist/content/sub-agents.mjs +52 -0
  416. package/dist/content/text-edit.d.mts +24 -14
  417. package/dist/content/text-edit.mjs +92 -81
  418. package/dist/content/text-replace.mjs +15 -41
  419. package/dist/content/thread-module.d.mts +11 -5
  420. package/dist/content/thread-module.mjs +23 -6
  421. package/dist/content/threads.d.mts +13 -0
  422. package/dist/content/threads.mjs +59 -14
  423. package/dist/content/trash.d.mts +4 -2
  424. package/dist/content/trash.mjs +31 -31
  425. package/dist/desktop/src/app.d.mts +40 -0
  426. package/dist/desktop/src/app.mjs +80 -0
  427. package/dist/desktop/src/contract.d.mts +7 -0
  428. package/dist/desktop/src/contract.mjs +22 -0
  429. package/dist/desktop/src/host.d.mts +48 -0
  430. package/dist/desktop/src/index.d.mts +32 -0
  431. package/dist/desktop/src/index.mjs +69 -0
  432. package/dist/desktop/src/mac/bundle.mjs +116 -0
  433. package/dist/desktop/src/mac/icon.mjs +53 -0
  434. package/dist/desktop/src/mac/launcher.mjs +69 -0
  435. package/dist/desktop/src/mac/plist.mjs +73 -0
  436. package/dist/desktop/src/mac/program/constants.mjs +62 -0
  437. package/dist/desktop/src/mac/program/delegate.mjs +214 -0
  438. package/dist/desktop/src/mac/program/downloads.mjs +19 -0
  439. package/dist/desktop/src/mac/program/index.mjs +26 -0
  440. package/dist/desktop/src/mac/program/menu.mjs +125 -0
  441. package/dist/desktop/src/mac/program/server-pages.mjs +140 -0
  442. package/dist/desktop/src/mac/program/web-view.mjs +59 -0
  443. package/dist/desktop/src/mac/program/window.mjs +197 -0
  444. package/dist/desktop/src/mac/services.mjs +28 -0
  445. package/dist/desktop/src/plug-in/http.d.mts +11 -0
  446. package/dist/desktop/src/plug-in/http.mjs +51 -0
  447. package/dist/desktop/src/plug-in/page-head.d.mts +8 -0
  448. package/dist/desktop/src/plug-in/page-head.mjs +31 -0
  449. package/dist/desktop/src/service.d.mts +15 -0
  450. package/dist/desktop/src/service.mjs +151 -0
  451. package/dist/desktop/src/start.d.mts +42 -0
  452. package/dist/{setup/desktop-app-start.mjs → desktop/src/start.mjs} +14 -39
  453. package/dist/harness/src/agents/adapter.d.mts +11 -0
  454. package/dist/harness/src/agents/adapter.mjs +6 -0
  455. package/dist/harness/src/agents/claude-code.mjs +179 -0
  456. package/dist/harness/src/agents/codex.mjs +189 -0
  457. package/dist/harness/src/agents/copilot.mjs +20 -0
  458. package/dist/harness/src/agents/cursor.mjs +21 -0
  459. package/dist/harness/src/agents/opencode.mjs +27 -0
  460. package/dist/harness/src/agents/other.mjs +21 -0
  461. package/dist/harness/src/agents/registry.mjs +21 -0
  462. package/dist/harness/src/agents/sub-agent.d.mts +14 -0
  463. package/dist/harness/src/agents.mjs +7 -0
  464. package/dist/harness/src/checks.mjs +9 -0
  465. package/dist/harness/src/connect/agent-config.mjs +252 -0
  466. package/dist/{server → harness/src/connect}/agent-env.mjs +3 -4
  467. package/dist/harness/src/connect/agent-root.mjs +30 -0
  468. package/dist/harness/src/connect/json-layout.mjs +52 -0
  469. package/dist/harness/src/connect/launch.mjs +67 -0
  470. package/dist/harness/src/connect/launched.d.mts +23 -0
  471. package/dist/harness/src/connect/package-manager.d.mts +1 -0
  472. package/dist/{config → harness/src/connect}/package-manager.mjs +17 -6
  473. package/dist/harness/src/connect/setups.d.mts +24 -0
  474. package/dist/harness/src/connect/setups.mjs +98 -0
  475. package/dist/harness/src/connect/workspace-root.d.mts +20 -0
  476. package/dist/harness/src/connect/workspace-root.mjs +110 -0
  477. package/dist/harness/src/events/channel-server.mjs +10 -0
  478. package/dist/harness/src/events/channel.d.mts +104 -0
  479. package/dist/harness/src/events/channel.mjs +457 -0
  480. package/dist/harness/src/events/connected-agent.d.mts +35 -0
  481. package/dist/harness/src/events/place.d.mts +21 -0
  482. package/dist/harness/src/mcp/define-tool.d.mts +26 -0
  483. package/dist/harness/src/mcp/define-tool.mjs +11 -0
  484. package/dist/harness/src/mcp/mcp-handover.d.mts +11 -0
  485. package/dist/{server → harness/src/mcp}/mcp-handover.mjs +6 -4
  486. package/dist/harness/src/mcp/mcp.d.mts +15 -0
  487. package/dist/harness/src/mcp/mcp.mjs +97 -0
  488. package/dist/harness/src/paths.d.mts +4 -0
  489. package/dist/harness/src/paths.mjs +15 -0
  490. package/dist/harness/src/project.d.mts +6 -0
  491. package/dist/harness/src/renamed.d.mts +9 -0
  492. package/dist/harness/src/renamed.mjs +22 -0
  493. package/dist/harness/src/session/session.d.mts +31 -0
  494. package/dist/harness/src/version.d.mts +13 -0
  495. package/dist/harness/src/version.mjs +47 -0
  496. package/dist/inspector.js +598 -0
  497. package/dist/paste/figma/captures.mjs +3 -3
  498. package/dist/paste/figma/decode.d.mts +14 -8
  499. package/dist/paste/figma/decode.mjs +11 -9
  500. package/dist/paste/figma/layout.d.mts +4 -3
  501. package/dist/paste/figma/layout.mjs +1 -1
  502. package/dist/paste/figma/paint.mjs +7 -5
  503. package/dist/paste/figma/render.mjs +1 -1
  504. package/dist/paste/figma/styles.d.mts +3 -1
  505. package/dist/paste/figma/styles.mjs +5 -9
  506. package/dist/paste/figma/text.mjs +21 -17
  507. package/dist/paste/figma/vector.mjs +9 -9
  508. package/dist/paste/fonts.mjs +7 -8
  509. package/dist/paste/paste.d.mts +2 -2
  510. package/dist/paste/paste.mjs +16 -15
  511. package/dist/paths.d.mts +22 -16
  512. package/dist/paths.mjs +28 -57
  513. package/dist/server/agent-session.d.mts +49 -3
  514. package/dist/server/agent-session.mjs +264 -20
  515. package/dist/server/agent-tools.d.mts +17 -0
  516. package/dist/server/agent-tools.mjs +31 -0
  517. package/dist/server/agents-place.d.mts +6 -0
  518. package/dist/server/agents-place.mjs +18 -0
  519. package/dist/server/allowed-request.mjs +1 -1
  520. package/dist/server/avatars.d.mts +3 -1
  521. package/dist/server/avatars.mjs +9 -7
  522. package/dist/server/brief.mjs +10 -10
  523. package/dist/server/briefing.d.mts +5 -5
  524. package/dist/server/briefing.mjs +5 -5
  525. package/dist/server/build-pictures.mjs +8 -8
  526. package/dist/server/build-settings.d.mts +1 -1
  527. package/dist/server/build-settings.mjs +4 -4
  528. package/dist/server/canvas-presence.d.mts +22 -0
  529. package/dist/server/canvas-presence.mjs +160 -0
  530. package/dist/server/changelog.mjs +5 -4
  531. package/dist/server/claimed-presence.mjs +10 -7
  532. package/dist/server/close-check.mjs +17 -15
  533. package/dist/server/cloud.d.mts +1 -1
  534. package/dist/server/cloud.mjs +5 -4
  535. package/dist/server/command-settings.d.mts +4 -2
  536. package/dist/server/command-settings.mjs +12 -8
  537. package/dist/server/comments/actions.d.mts +17 -64
  538. package/dist/server/comments/actions.mjs +65 -67
  539. package/dist/server/comments/agent-actions.d.mts +73 -0
  540. package/dist/server/comments/agent-actions.mjs +76 -0
  541. package/dist/server/comments/close-tools.d.mts +31 -0
  542. package/dist/server/comments/close-tools.mjs +124 -0
  543. package/dist/server/comments/files.d.mts +53 -0
  544. package/dist/server/comments/files.mjs +1 -0
  545. package/dist/server/comments/hand-out.d.mts +42 -0
  546. package/dist/server/comments/hand-out.mjs +46 -0
  547. package/dist/server/comments/push.d.mts +26 -0
  548. package/dist/server/comments/push.mjs +238 -0
  549. package/dist/server/comments/routes.d.mts +12 -0
  550. package/dist/server/comments/routes.mjs +27 -38
  551. package/dist/server/comments/studio-files.d.mts +14 -0
  552. package/dist/server/comments/studio-files.mjs +80 -0
  553. package/dist/server/comments/tools.d.mts +35 -3
  554. package/dist/server/comments/tools.mjs +54 -147
  555. package/dist/server/comments/workflow.d.mts +13 -0
  556. package/dist/server/comments/workflow.mjs +15 -0
  557. package/dist/server/comments/workspace.d.mts +36 -0
  558. package/dist/server/comments/workspace.mjs +84 -0
  559. package/dist/server/component-catalogue.mjs +19 -21
  560. package/dist/server/config-settings.d.mts +1 -1
  561. package/dist/server/config-settings.mjs +3 -3
  562. package/dist/server/content-type.mjs +1 -1
  563. package/dist/server/dependency-clash.d.mts +6 -2
  564. package/dist/server/dependency-clash.mjs +23 -17
  565. package/dist/server/desktop.d.mts +20 -0
  566. package/dist/server/desktop.mjs +56 -0
  567. package/dist/server/dev-server.mjs +53 -49
  568. package/dist/server/export/build.d.mts +15 -0
  569. package/dist/server/export/build.mjs +220 -0
  570. package/dist/server/export/page.d.mts +25 -0
  571. package/dist/server/export/page.mjs +40 -0
  572. package/dist/server/export/plugin.d.mts +33 -0
  573. package/dist/server/export/plugin.mjs +72 -0
  574. package/dist/server/export/run.d.mts +9 -0
  575. package/dist/server/export/run.mjs +61 -0
  576. package/dist/server/export/save.d.mts +7 -0
  577. package/dist/server/export/save.mjs +29 -0
  578. package/dist/server/features.d.mts +0 -5
  579. package/dist/server/features.mjs +1 -6
  580. package/dist/server/file-errors.mjs +4 -4
  581. package/dist/server/file-lock.mjs +14 -9
  582. package/dist/server/git-host.mjs +6 -9
  583. package/dist/server/git-paused.mjs +4 -1
  584. package/dist/server/git-settings.d.mts +1 -1
  585. package/dist/server/git-settings.mjs +5 -5
  586. package/dist/server/git-sync.d.mts +8 -0
  587. package/dist/server/git-sync.mjs +77 -19
  588. package/dist/server/git.d.mts +0 -5
  589. package/dist/server/git.mjs +53 -48
  590. package/dist/server/hosted.d.mts +8 -0
  591. package/dist/server/hosted.mjs +78 -0
  592. package/dist/server/instructions.mjs +9 -8
  593. package/dist/server/live-mirror.mjs +85 -22
  594. package/dist/server/live.mjs +35 -6
  595. package/dist/server/machine-update.mjs +32 -32
  596. package/dist/server/me.d.mts +2 -0
  597. package/dist/server/me.mjs +10 -2
  598. package/dist/server/merge-check.d.mts +14 -0
  599. package/dist/server/merge-check.mjs +80 -0
  600. package/dist/server/next.mjs +9 -6
  601. package/dist/server/notices.d.mts +7 -7
  602. package/dist/server/notices.mjs +12 -10
  603. package/dist/server/open-page.mjs +11 -10
  604. package/dist/server/outcome.d.mts +7 -8
  605. package/dist/server/own-copies.mjs +22 -12
  606. package/dist/server/people.d.mts +7 -2
  607. package/dist/server/people.mjs +10 -6
  608. package/dist/server/pictures.d.mts +1 -1
  609. package/dist/server/pictures.mjs +16 -10
  610. package/dist/server/port.mjs +5 -9
  611. package/dist/server/prebundle.d.mts +32 -0
  612. package/dist/server/prebundle.mjs +118 -0
  613. package/dist/server/preferences.mjs +1 -1
  614. package/dist/server/presence.d.mts +3 -3
  615. package/dist/server/presence.mjs +2 -4
  616. package/dist/server/problems.d.mts +8 -0
  617. package/dist/server/problems.mjs +13 -0
  618. package/dist/server/project-public.mjs +1 -1
  619. package/dist/server/prototype-brief.d.mts +36 -3
  620. package/dist/server/prototype-brief.mjs +6 -6
  621. package/dist/server/push-notice.d.mts +1 -1
  622. package/dist/server/quiet-run.mjs +1 -1
  623. package/dist/server/registry.mjs +9 -8
  624. package/dist/server/requests.d.mts +9 -20
  625. package/dist/server/requests.mjs +175 -156
  626. package/dist/server/response-budget.d.mts +16 -7
  627. package/dist/server/response-budget.mjs +6 -5
  628. package/dist/server/restart.mjs +3 -1
  629. package/dist/server/roster.d.mts +2 -2
  630. package/dist/server/roster.mjs +7 -8
  631. package/dist/server/source-stamp.d.mts +5 -3
  632. package/dist/server/source-stamp.mjs +92 -35
  633. package/dist/server/spec-decisions.mjs +2 -2
  634. package/dist/server/state.d.mts +25 -16
  635. package/dist/server/state.mjs +30 -23
  636. package/dist/server/studio-server.d.mts +92 -0
  637. package/dist/server/studio-server.mjs +77 -0
  638. package/dist/server/sync-install.mjs +2 -2
  639. package/dist/server/thread-forms.d.mts +7 -8
  640. package/dist/server/thread-forms.mjs +13 -14
  641. package/dist/server/thread-place.d.mts +2 -2
  642. package/dist/server/thread-place.mjs +28 -18
  643. package/dist/server/thread-source.d.mts +43 -5
  644. package/dist/server/thread-source.mjs +63 -41
  645. package/dist/server/tools/context.d.mts +53 -35
  646. package/dist/server/tools/context.mjs +17 -32
  647. package/dist/server/tools/describe.d.mts +3 -5
  648. package/dist/server/tools/describe.mjs +4 -24
  649. package/dist/server/tools/export.d.mts +17 -0
  650. package/dist/server/tools/export.mjs +40 -0
  651. package/dist/server/tools/feedback.d.mts +20 -4
  652. package/dist/server/tools/feedback.mjs +70 -62
  653. package/dist/server/tools/place-frame.d.mts +15 -3
  654. package/dist/server/tools/place-frame.mjs +80 -73
  655. package/dist/server/tools/prototype-name.mjs +3 -4
  656. package/dist/server/tools/reading.d.mts +4 -4
  657. package/dist/server/tools/reading.mjs +137 -114
  658. package/dist/server/tools/show.d.mts +9 -4
  659. package/dist/server/tools/show.mjs +39 -34
  660. package/dist/server/tools/snapshot.d.mts +19 -5
  661. package/dist/server/tools/snapshot.mjs +64 -59
  662. package/dist/server/tools/studio-context.d.mts +8 -0
  663. package/dist/server/tools/studio-context.mjs +44 -0
  664. package/dist/server/tools/thread-list.d.mts +19 -4
  665. package/dist/server/tools/thread-list.mjs +59 -61
  666. package/dist/server/tools/watch.d.mts +11 -4
  667. package/dist/server/tools/watch.mjs +165 -115
  668. package/dist/server/unresolved-imports.mjs +4 -1
  669. package/dist/server/update-branch.mjs +2 -2
  670. package/dist/server/update-studio.d.mts +3 -1
  671. package/dist/server/update-studio.mjs +30 -19
  672. package/dist/server/updates.mjs +10 -10
  673. package/dist/server/vite.d.mts +9 -4
  674. package/dist/server/vite.mjs +90 -83
  675. package/dist/server/web-app.mjs +17 -30
  676. package/dist/server/welcome.mjs +5 -2
  677. package/dist/server/work-groups.d.mts +13 -2
  678. package/dist/server/work-groups.mjs +58 -23
  679. package/dist/server/workspace-settings.d.mts +9 -5
  680. package/dist/server/workspace-settings.mjs +40 -39
  681. package/dist/server/zip.mjs +1 -1
  682. package/dist/setup/apply.d.mts +9 -0
  683. package/dist/setup/apply.mjs +30 -26
  684. package/dist/setup/cancelled.d.mts +6 -0
  685. package/dist/setup/cancelled.mjs +10 -0
  686. package/dist/setup/commit-lint.d.mts +6 -4
  687. package/dist/setup/commit-lint.mjs +23 -27
  688. package/dist/setup/components.mjs +3 -3
  689. package/dist/setup/config-source.d.mts +16 -5
  690. package/dist/setup/config-source.mjs +36 -27
  691. package/dist/setup/create.mjs +69 -57
  692. package/dist/setup/design-md-setup.d.mts +6 -4
  693. package/dist/setup/design-md-setup.mjs +14 -12
  694. package/dist/setup/design-md.mjs +50 -52
  695. package/dist/setup/design-system-checks.mjs +9 -14
  696. package/dist/setup/detect/workspace.d.mts +13 -27
  697. package/dist/setup/detect/workspace.mjs +33 -138
  698. package/dist/setup/detect.mjs +24 -18
  699. package/dist/setup/doctor.d.mts +4 -1
  700. package/dist/setup/doctor.mjs +21 -18
  701. package/dist/setup/existing-setup.mjs +20 -15
  702. package/dist/setup/git-checks.mjs +5 -5
  703. package/dist/setup/hash.d.mts +4 -0
  704. package/dist/setup/hash.mjs +6 -0
  705. package/dist/setup/hints.mjs +5 -4
  706. package/dist/setup/host-format.mjs +2 -6
  707. package/dist/setup/json.d.mts +12 -0
  708. package/dist/setup/json.mjs +9 -0
  709. package/dist/setup/migrate/agent-files.mjs +8 -7
  710. package/dist/setup/migrate/config-name.mjs +1 -1
  711. package/dist/setup/migrate/design-system.mjs +37 -34
  712. package/dist/setup/migrate/dex-folder.d.mts +61 -0
  713. package/dist/setup/migrate/dex-folder.mjs +548 -0
  714. package/dist/setup/migrate/explorations.mjs +7 -5
  715. package/dist/setup/migrate/files-folder.mjs +36 -21
  716. package/dist/setup/migrate/frame-notes.d.mts +20 -0
  717. package/dist/setup/migrate/frame-notes.mjs +126 -0
  718. package/dist/setup/migrate/frame-uids.d.mts +24 -0
  719. package/dist/setup/migrate/frame-uids.mjs +144 -0
  720. package/dist/setup/migrate/guides.mjs +2 -2
  721. package/dist/setup/migrate/manifest-name.d.mts +23 -0
  722. package/dist/setup/migrate/manifest-name.mjs +93 -0
  723. package/dist/setup/migrate/migrations.mjs +16 -2
  724. package/dist/setup/migrate/people-folders.d.mts +3 -3
  725. package/dist/setup/migrate/people-folders.mjs +25 -36
  726. package/dist/setup/migrate/picks-file.d.mts +33 -0
  727. package/dist/setup/migrate/picks-file.mjs +172 -0
  728. package/dist/setup/migrate/project-files.mjs +10 -8
  729. package/dist/setup/migrate/row-titles.mjs +5 -2
  730. package/dist/setup/migrate/setup-files.d.mts +5 -0
  731. package/dist/setup/migrate/setup-files.mjs +121 -0
  732. package/dist/setup/migrate/studio-state.d.mts +2 -2
  733. package/dist/setup/migrate/studio-state.mjs +12 -10
  734. package/dist/setup/own-app.d.mts +2 -1
  735. package/dist/setup/own-app.mjs +17 -15
  736. package/dist/setup/placement.d.mts +1 -1
  737. package/dist/setup/placement.mjs +25 -22
  738. package/dist/setup/plan.d.mts +10 -8
  739. package/dist/setup/plan.mjs +15 -18
  740. package/dist/setup/project.mjs +12 -9
  741. package/dist/setup/prompts.d.mts +3 -6
  742. package/dist/setup/prompts.mjs +58 -56
  743. package/dist/setup/provider.mjs +3 -2
  744. package/dist/setup/questions.d.mts +13 -7
  745. package/dist/setup/questions.mjs +5 -6
  746. package/dist/setup/starters.d.mts +1 -1
  747. package/dist/setup/starters.mjs +8 -5
  748. package/dist/setup/templates.d.mts +3 -3
  749. package/dist/setup/templates.mjs +18 -14
  750. package/dist/setup/workspace-setup.mjs +4 -5
  751. package/dist/setup/write.d.mts +24 -4
  752. package/dist/setup/write.mjs +40 -19
  753. package/dist/shared/block-merge.d.mts +5 -4
  754. package/dist/shared/block-merge.mjs +5 -5
  755. package/dist/shared/built-pictures.d.mts +13 -4
  756. package/dist/shared/built-pictures.mjs +16 -8
  757. package/dist/shared/canvas-core.d.mts +138 -63
  758. package/dist/shared/canvas-core.mjs +227 -86
  759. package/dist/shared/canvas-file.d.mts +15 -6
  760. package/dist/shared/canvas-merge.d.mts +28 -0
  761. package/dist/shared/canvas-merge.mjs +384 -0
  762. package/dist/shared/checks.d.mts +8 -0
  763. package/dist/shared/checks.mjs +9 -1
  764. package/dist/shared/code-anchor.d.mts +16 -0
  765. package/dist/shared/code-anchor.mjs +33 -0
  766. package/dist/shared/commands-core.d.mts +25 -0
  767. package/dist/shared/commands-core.mjs +31 -7
  768. package/dist/shared/comments/routes.d.mts +5 -1
  769. package/dist/shared/comments/routes.mjs +8 -4
  770. package/dist/shared/comments/state.d.mts +71 -0
  771. package/dist/shared/comments/state.mjs +66 -0
  772. package/dist/shared/contributors-merge.mjs +4 -4
  773. package/dist/shared/devices.d.mts +5 -4
  774. package/dist/shared/devices.mjs +1 -1
  775. package/dist/shared/export-core.d.mts +61 -0
  776. package/dist/shared/export-core.mjs +100 -0
  777. package/dist/shared/feedback.mjs +5 -7
  778. package/dist/shared/file-errors.mjs +3 -3
  779. package/dist/shared/file-names.d.mts +6 -0
  780. package/dist/shared/file-names.mjs +521 -0
  781. package/dist/shared/fix-prompt.mjs +1 -1
  782. package/dist/shared/front-matter.mjs +8 -9
  783. package/dist/shared/generated-sections.mjs +7 -7
  784. package/dist/shared/git-core.mjs +11 -11
  785. package/dist/shared/json-style.mjs +5 -4
  786. package/dist/shared/live-core.d.mts +12 -5
  787. package/dist/shared/live-core.mjs +11 -5
  788. package/dist/shared/live-presence.d.mts +57 -2
  789. package/dist/shared/live-presence.mjs +102 -13
  790. package/dist/shared/markup-prompt.d.mts +7 -3
  791. package/dist/shared/markup-prompt.mjs +9 -5
  792. package/dist/shared/open-page-core.mjs +6 -5
  793. package/dist/shared/page-messages.d.mts +29 -4
  794. package/dist/shared/page-messages.mjs +55 -16
  795. package/dist/shared/page-review.mjs +8 -10
  796. package/dist/shared/people-core.d.mts +61 -25
  797. package/dist/shared/people-core.mjs +74 -23
  798. package/dist/shared/{annotations-core.d.mts → picks-core.d.mts} +24 -29
  799. package/dist/shared/{annotations-core.mjs → picks-core.mjs} +48 -62
  800. package/dist/shared/presence-core.d.mts +2 -0
  801. package/dist/shared/prototypes-core.d.mts +70 -15
  802. package/dist/shared/prototypes-core.mjs +184 -100
  803. package/dist/shared/references-core.d.mts +4 -0
  804. package/dist/shared/references-core.mjs +15 -8
  805. package/dist/shared/removed-views-core.mjs +6 -6
  806. package/dist/shared/review-file.mjs +3 -3
  807. package/dist/shared/server-page.mjs +4 -4
  808. package/dist/shared/signup.mjs +3 -2
  809. package/dist/shared/sketch-core.mjs +7 -7
  810. package/dist/shared/snapshot-clipboard.d.mts +5 -4
  811. package/dist/shared/snapshot-clipboard.mjs +2 -2
  812. package/dist/shared/snapshot-images.d.mts +10 -1
  813. package/dist/shared/snapshot-images.mjs +62 -14
  814. package/dist/shared/spec-quote.mjs +4 -4
  815. package/dist/shared/studio-events.d.mts +5 -36
  816. package/dist/shared/studio-events.mjs +5 -5
  817. package/dist/shared/studio-files.d.mts +12 -3
  818. package/dist/shared/studio-files.mjs +18 -9
  819. package/dist/shared/studio-routes.d.mts +41 -31
  820. package/dist/shared/studio-routes.mjs +6 -1
  821. package/dist/shared/threads-core.d.mts +373 -36
  822. package/dist/shared/threads-core.mjs +286 -84
  823. package/dist/shared/unknown-fields.d.mts +10 -0
  824. package/dist/shared/unknown-fields.mjs +74 -0
  825. package/dist/shared/unzip.d.mts +4 -2
  826. package/dist/shared/unzip.mjs +9 -7
  827. package/dist/shared/word-diff.mjs +6 -6
  828. package/dist/shared/xray.d.mts +4 -0
  829. package/dist/shared/xray.mjs +11 -0
  830. package/extension/dist/background.js +1 -1
  831. package/extension/dist/manifest.json +2 -3
  832. package/extension/dist/picker.js +106 -286
  833. package/package.json +82 -60
  834. package/schema/canvas.json +390 -0
  835. package/schema/comment-event.json +441 -0
  836. package/schema/contributors.json +30 -0
  837. package/schema/defs.json +66 -0
  838. package/schema/file.json +59 -0
  839. package/schema/picks.json +45 -0
  840. package/src/cli/banner.ts +46 -5
  841. package/src/cli/command.ts +25 -12
  842. package/src/cli/commands/agents/add.ts +4 -1
  843. package/src/cli/commands/agents.ts +1 -0
  844. package/src/cli/commands/app.ts +33 -24
  845. package/src/cli/commands/build.ts +4 -0
  846. package/src/cli/commands/claude.ts +20 -10
  847. package/src/cli/commands/cloud/link.ts +2 -0
  848. package/src/cli/commands/cloud/live.ts +2 -0
  849. package/src/cli/commands/cloud/login.ts +1 -0
  850. package/src/cli/commands/cloud/publish.ts +23 -9
  851. package/src/cli/commands/cloud/push.ts +2 -0
  852. package/src/cli/commands/cloud/status.ts +2 -0
  853. package/src/cli/commands/cloud/unlink.ts +2 -0
  854. package/src/cli/commands/cloud.ts +1 -0
  855. package/src/cli/commands/components.ts +1 -0
  856. package/src/cli/commands/create.ts +7 -4
  857. package/src/cli/commands/dev.ts +148 -32
  858. package/src/cli/commands/doctor.ts +9 -1
  859. package/src/cli/commands/export.ts +87 -0
  860. package/src/cli/commands/extension.ts +1 -0
  861. package/src/cli/commands/hook.ts +17 -1
  862. package/src/cli/commands/init.ts +3 -0
  863. package/src/cli/commands/mcp.ts +23 -4
  864. package/src/cli/commands/merge-canvas.ts +134 -0
  865. package/src/cli/commands/merge-contributors.ts +10 -4
  866. package/src/cli/commands/merge-spec.ts +7 -1
  867. package/src/cli/commands/preview.ts +2 -0
  868. package/src/cli/commands/stop.ts +6 -0
  869. package/src/cli/commands/upgrade.ts +12 -1
  870. package/src/cli/commands/work/check.ts +2 -0
  871. package/src/cli/commands/work/contributor.ts +3 -1
  872. package/src/cli/commands/work/new.ts +3 -1
  873. package/src/cli/commands/work/presence.ts +3 -1
  874. package/src/cli/commands/work/scope.ts +3 -1
  875. package/src/cli/commands/work/snapshot.ts +3 -1
  876. package/src/cli/commands/work/thread.ts +3 -1
  877. package/src/cli/commands/work/threads.ts +3 -1
  878. package/src/cli/commands/work/whoami.ts +3 -1
  879. package/src/cli/help.ts +45 -17
  880. package/src/cli/main.ts +32 -3
  881. package/src/cli/mcp-relay.ts +150 -49
  882. package/src/cli/recovery-server.ts +23 -9
  883. package/src/cli/strict-flags.ts +41 -6
  884. package/src/cli/supervise.ts +119 -37
  885. package/src/cli/ui.ts +55 -26
  886. package/src/config/design-system.ts +65 -18
  887. package/src/config/index.ts +1 -0
  888. package/src/config/load.ts +63 -8
  889. package/src/config/project-files.ts +194 -42
  890. package/src/config/renamed.ts +25 -12
  891. package/src/config/schema.ts +8 -0
  892. package/src/content/biome.ts +31 -17
  893. package/src/content/capture.ts +200 -56
  894. package/src/content/commands.ts +115 -45
  895. package/src/content/comments-log.ts +187 -35
  896. package/src/content/component-props.ts +134 -23
  897. package/src/content/content.ts +768 -230
  898. package/src/content/devices.ts +12 -3
  899. package/src/content/element-words.ts +200 -0
  900. package/src/content/file-turns.ts +12 -4
  901. package/src/content/first-run.ts +10 -10
  902. package/src/content/flow-specs.ts +88 -40
  903. package/src/content/format-check.ts +599 -0
  904. package/src/content/hosted-person.ts +131 -0
  905. package/src/content/insert-edit.ts +52 -17
  906. package/src/content/jsx-source.ts +17 -6
  907. package/src/content/last-edited.ts +15 -4
  908. package/src/content/layout.ts +131 -9
  909. package/src/content/merge-rules.ts +96 -33
  910. package/src/content/prop-edit.ts +60 -4
  911. package/src/content/prototype-checks.ts +52 -18
  912. package/src/content/prototype-summary.ts +37 -20
  913. package/src/content/prototypes.ts +138 -52
  914. package/src/content/review-import.ts +8 -1
  915. package/src/content/review-pages.ts +63 -8
  916. package/src/content/screenshot.ts +95 -23
  917. package/src/content/snapshot-client.ts +25 -3
  918. package/src/content/store.ts +177 -55
  919. package/src/content/sub-agents.ts +107 -0
  920. package/src/content/text-edit.ts +209 -106
  921. package/src/content/text-replace.ts +130 -61
  922. package/src/content/thread-module.ts +86 -16
  923. package/src/content/threads.ts +146 -16
  924. package/src/content/trash.ts +101 -41
  925. package/src/paste/figma/appearance.ts +39 -6
  926. package/src/paste/figma/captures.ts +21 -6
  927. package/src/paste/figma/decode.ts +82 -15
  928. package/src/paste/figma/document.ts +73 -5
  929. package/src/paste/figma/layout.ts +44 -5
  930. package/src/paste/figma/paint.ts +52 -8
  931. package/src/paste/figma/render.ts +18 -3
  932. package/src/paste/figma/styles.ts +20 -5
  933. package/src/paste/figma/text.ts +97 -29
  934. package/src/paste/figma/vector.ts +74 -12
  935. package/src/paste/fonts.ts +30 -9
  936. package/src/paste/paste.ts +45 -15
  937. package/src/paths.ts +66 -87
  938. package/src/server/agent-session.ts +451 -20
  939. package/src/server/agent-tools.ts +52 -0
  940. package/src/server/agents-place.ts +22 -0
  941. package/src/server/allowed-request.ts +7 -1
  942. package/src/server/avatars.ts +18 -6
  943. package/src/server/brief.ts +75 -16
  944. package/src/server/briefing.ts +19 -9
  945. package/src/server/build-pictures.ts +57 -9
  946. package/src/server/build-settings.ts +10 -4
  947. package/src/server/canvas-presence.ts +266 -0
  948. package/src/server/changelog.ts +15 -3
  949. package/src/server/claimed-presence.ts +32 -8
  950. package/src/server/close-check.ts +56 -19
  951. package/src/server/cloud.ts +61 -12
  952. package/src/server/command-settings.ts +31 -13
  953. package/src/server/comments/actions.ts +137 -152
  954. package/src/server/comments/agent-actions.ts +178 -0
  955. package/src/server/comments/close-tools.ts +240 -0
  956. package/src/server/comments/files.ts +66 -0
  957. package/src/server/comments/hand-out.ts +105 -0
  958. package/src/server/comments/push.ts +503 -0
  959. package/src/server/comments/routes.ts +46 -61
  960. package/src/server/comments/studio-files.ts +128 -0
  961. package/src/server/comments/tools.ts +103 -301
  962. package/src/server/comments/workflow.ts +18 -0
  963. package/src/server/comments/workspace.ts +123 -0
  964. package/src/server/component-catalogue.ts +58 -20
  965. package/src/server/config-settings.ts +11 -3
  966. package/src/server/content-type.ts +3 -1
  967. package/src/server/dependency-clash.ts +86 -26
  968. package/src/server/desktop.ts +92 -0
  969. package/src/server/dev-server.ts +130 -86
  970. package/src/server/export/build.ts +344 -0
  971. package/src/server/export/page.ts +94 -0
  972. package/src/server/export/plugin.ts +157 -0
  973. package/src/server/export/run.ts +91 -0
  974. package/src/server/export/save.ts +43 -0
  975. package/src/server/features.ts +4 -6
  976. package/src/server/file-errors.ts +35 -5
  977. package/src/server/file-lock.ts +53 -19
  978. package/src/server/git-asks.ts +13 -4
  979. package/src/server/git-host.ts +51 -12
  980. package/src/server/git-paused.ts +39 -3
  981. package/src/server/git-settings.ts +15 -5
  982. package/src/server/git-sync.ts +229 -36
  983. package/src/server/git.ts +236 -116
  984. package/src/server/hosted.ts +124 -0
  985. package/src/server/instructions.ts +32 -7
  986. package/src/server/live-mirror.ts +202 -18
  987. package/src/server/live.ts +131 -17
  988. package/src/server/machine-update.ts +170 -38
  989. package/src/server/me.ts +18 -4
  990. package/src/server/merge-check.ts +125 -0
  991. package/src/server/next.ts +30 -8
  992. package/src/server/notices.ts +79 -17
  993. package/src/server/open-page.ts +44 -19
  994. package/src/server/outcome.ts +8 -7
  995. package/src/server/own-copies.ts +104 -13
  996. package/src/server/people.ts +33 -9
  997. package/src/server/personal-folder.ts +3 -0
  998. package/src/server/pictures.ts +78 -10
  999. package/src/server/port.ts +38 -6
  1000. package/src/server/prebundle.ts +265 -0
  1001. package/src/server/preferences.ts +6 -1
  1002. package/src/server/presence.ts +18 -7
  1003. package/src/server/problems.ts +13 -0
  1004. package/src/server/project-id.ts +2 -0
  1005. package/src/server/project-public.ts +12 -1
  1006. package/src/server/prototype-brief.ts +36 -17
  1007. package/src/server/push-notice.ts +11 -1
  1008. package/src/server/quiet-run.ts +10 -3
  1009. package/src/server/registry.ts +34 -7
  1010. package/src/server/requests.ts +597 -291
  1011. package/src/server/response-budget.ts +29 -6
  1012. package/src/server/restart.ts +36 -3
  1013. package/src/server/roster.ts +51 -9
  1014. package/src/server/saved.ts +16 -6
  1015. package/src/server/source-stamp.ts +224 -39
  1016. package/src/server/spec-decisions.ts +11 -2
  1017. package/src/server/state.ts +74 -40
  1018. package/src/server/stop-studio.ts +9 -1
  1019. package/src/server/studio-for.ts +38 -9
  1020. package/src/server/studio-server.ts +233 -0
  1021. package/src/server/sync-install.ts +8 -3
  1022. package/src/server/thread-forms.ts +84 -27
  1023. package/src/server/thread-place.ts +61 -19
  1024. package/src/server/thread-source.ts +143 -47
  1025. package/src/server/tools/context.ts +95 -112
  1026. package/src/server/tools/describe.ts +10 -35
  1027. package/src/server/tools/export.ts +58 -0
  1028. package/src/server/tools/feedback.ts +47 -22
  1029. package/src/server/tools/place-frame.ts +65 -28
  1030. package/src/server/tools/prototype-name.ts +11 -7
  1031. package/src/server/tools/reading.ts +215 -177
  1032. package/src/server/tools/result.ts +3 -0
  1033. package/src/server/tools/show.ts +35 -12
  1034. package/src/server/tools/snapshot.ts +24 -12
  1035. package/src/server/tools/studio-context.ts +72 -0
  1036. package/src/server/tools/thread-list.ts +58 -43
  1037. package/src/server/tools/watch.ts +230 -81
  1038. package/src/server/unresolved-imports.ts +18 -3
  1039. package/src/server/update-branch.ts +29 -4
  1040. package/src/server/update-studio.ts +54 -20
  1041. package/src/server/updates.ts +57 -11
  1042. package/src/server/vite.ts +254 -133
  1043. package/src/server/web-app.ts +27 -46
  1044. package/src/server/welcome.ts +11 -4
  1045. package/src/server/work-groups.ts +150 -34
  1046. package/src/server/workspace-settings.ts +133 -45
  1047. package/src/server/zip.ts +21 -3
  1048. package/src/setup/apply.ts +139 -44
  1049. package/src/setup/cancelled.ts +7 -0
  1050. package/src/setup/commit-lint.ts +104 -28
  1051. package/src/setup/components.ts +18 -3
  1052. package/src/setup/config-choices.ts +7 -0
  1053. package/src/setup/config-source.ts +226 -61
  1054. package/src/setup/create.ts +291 -74
  1055. package/src/setup/design-md-setup.ts +48 -11
  1056. package/src/setup/design-md.ts +276 -80
  1057. package/src/setup/design-system-checks.ts +71 -18
  1058. package/src/setup/design-system-guide.ts +7 -0
  1059. package/src/setup/detect/workspace.ts +239 -213
  1060. package/src/setup/detect.ts +95 -26
  1061. package/src/setup/doctor.ts +97 -26
  1062. package/src/setup/existing-setup.ts +114 -22
  1063. package/src/setup/git-checks.ts +60 -7
  1064. package/src/setup/hash.ts +5 -0
  1065. package/src/setup/hints.ts +42 -4
  1066. package/src/setup/host-format.ts +31 -7
  1067. package/src/setup/json.ts +23 -0
  1068. package/src/setup/migrate/agent-files.ts +45 -9
  1069. package/src/setup/migrate/config-name.ts +13 -1
  1070. package/src/setup/migrate/design-system.ts +198 -50
  1071. package/src/setup/migrate/dex-folder.ts +957 -0
  1072. package/src/setup/migrate/explorations.ts +7 -3
  1073. package/src/setup/migrate/files-folder.ts +146 -44
  1074. package/src/setup/migrate/frame-notes.ts +253 -0
  1075. package/src/setup/migrate/frame-uids.ts +274 -0
  1076. package/src/setup/migrate/guides.ts +21 -16
  1077. package/src/setup/migrate/manifest-name.ts +183 -0
  1078. package/src/setup/migrate/migrations.ts +35 -7
  1079. package/src/setup/migrate/people-folders.ts +76 -48
  1080. package/src/setup/migrate/picks-file.ts +297 -0
  1081. package/src/setup/migrate/project-files.ts +8 -3
  1082. package/src/setup/migrate/row-titles.ts +8 -4
  1083. package/src/setup/migrate/setup-files.ts +223 -0
  1084. package/src/setup/migrate/studio-state.ts +38 -15
  1085. package/src/setup/own-app.ts +75 -21
  1086. package/src/setup/placement.ts +87 -27
  1087. package/src/setup/plan.ts +109 -35
  1088. package/src/setup/project.ts +77 -13
  1089. package/src/setup/prompts.ts +206 -58
  1090. package/src/setup/provider.ts +20 -2
  1091. package/src/setup/questions.ts +77 -26
  1092. package/src/setup/starters.ts +58 -17
  1093. package/src/setup/templates.ts +66 -20
  1094. package/src/setup/workspace-setup.ts +50 -5
  1095. package/src/setup/write.ts +96 -27
  1096. package/src/shared/agent-prompts.ts +1 -1
  1097. package/src/shared/block-merge.ts +65 -8
  1098. package/src/shared/built-pictures.ts +38 -9
  1099. package/src/shared/canvas-core.ts +643 -161
  1100. package/src/shared/canvas-file.ts +15 -6
  1101. package/src/shared/canvas-merge.ts +784 -0
  1102. package/src/shared/checks.ts +18 -0
  1103. package/src/shared/code-anchor.ts +73 -0
  1104. package/src/shared/commands-core.ts +62 -8
  1105. package/src/shared/comments/routes.ts +8 -4
  1106. package/src/shared/comments/state.ts +146 -0
  1107. package/src/shared/contributors-merge.ts +26 -12
  1108. package/src/shared/devices.ts +63 -16
  1109. package/src/shared/export-core.ts +220 -0
  1110. package/src/shared/feedback.ts +56 -8
  1111. package/src/shared/file-errors.ts +4 -4
  1112. package/src/shared/file-names.ts +528 -0
  1113. package/src/shared/fix-prompt.ts +3 -1
  1114. package/src/shared/frame-grids.ts +33 -8
  1115. package/src/shared/front-matter.ts +24 -7
  1116. package/src/shared/generated-sections.ts +30 -7
  1117. package/src/shared/git-core.ts +40 -14
  1118. package/src/shared/json-style.ts +24 -6
  1119. package/src/shared/listing.ts +1 -0
  1120. package/src/shared/live-core.ts +63 -12
  1121. package/src/shared/live-presence.ts +234 -14
  1122. package/src/shared/markup-prompt.ts +9 -4
  1123. package/src/shared/open-page-core.ts +15 -8
  1124. package/src/shared/page-messages.ts +94 -18
  1125. package/src/shared/page-review.ts +60 -35
  1126. package/src/shared/paste-arrangement.ts +4 -0
  1127. package/src/shared/people-core.ts +290 -54
  1128. package/src/shared/{annotations-core.ts → picks-core.ts} +125 -96
  1129. package/src/shared/presence-core.ts +2 -0
  1130. package/src/shared/prototypes-core.ts +323 -128
  1131. package/src/shared/references-core.ts +39 -8
  1132. package/src/shared/removed-views-core.ts +30 -7
  1133. package/src/shared/review-file.ts +38 -19
  1134. package/src/shared/server-page.ts +13 -5
  1135. package/src/shared/signup.ts +12 -2
  1136. package/src/shared/sketch-core.ts +55 -7
  1137. package/src/shared/snapshot-clipboard.ts +20 -3
  1138. package/src/shared/snapshot-images.ts +114 -14
  1139. package/src/shared/spec-quote.ts +36 -5
  1140. package/src/shared/studio-events.ts +24 -37
  1141. package/src/shared/studio-files.ts +43 -11
  1142. package/src/shared/studio-routes.ts +38 -32
  1143. package/src/shared/threads-core.ts +725 -170
  1144. package/src/shared/unknown-fields.ts +118 -0
  1145. package/src/shared/unzip.ts +22 -8
  1146. package/src/shared/update-core.ts +3 -0
  1147. package/src/shared/word-diff.ts +31 -6
  1148. package/src/shared/xray.ts +14 -0
  1149. package/templates/agents/dex-checker.md +25 -0
  1150. package/templates/agents/dex-riffer.md +16 -0
  1151. package/templates/agents/dex-worker.md +23 -0
  1152. package/templates/feedback-workflow.md +1 -1
  1153. package/templates/methods/explore.md +1 -1
  1154. package/templates/methods/handoff.md +2 -2
  1155. package/templates/methods/review.md +9 -4
  1156. package/templates/rules/always.md +1 -1
  1157. package/templates/rules/canvas-frames.md +15 -5
  1158. package/templates/rules/canvas.md +19 -11
  1159. package/templates/rules/commands.md +1 -0
  1160. package/templates/rules/prototypes.md +7 -6
  1161. package/templates/rules/scope.md +2 -2
  1162. package/templates/rules/studio.md +17 -11
  1163. package/templates/skills/boil/SKILL.md +40 -0
  1164. package/templates/skills/comprehend/SKILL.md +57 -0
  1165. package/templates/skills/distill/SKILL.md +173 -0
  1166. package/templates/skills/export-prototype/SKILL.md +36 -0
  1167. package/templates/skills/restrain/SKILL.md +76 -0
  1168. package/templates/skills/riff/SKILL.md +23 -0
  1169. package/templates/skills/riff-deep/SKILL.md +42 -0
  1170. package/templates/skills/riff-max/SKILL.md +48 -0
  1171. package/templates/skills/riff-state/SKILL.md +47 -0
  1172. package/templates/skills/riff-up/SKILL.md +40 -0
  1173. package/templates/skills/riff-wide/SKILL.md +42 -0
  1174. package/templates/starter-prototype/welcome.tsx +8 -4
  1175. package/templates/starters/standalone/README.md +1 -1
  1176. package/templates/starters/standalone/package.json +1 -1
  1177. package/templates/starters/turborepo/README.md +2 -2
  1178. package/templates/starters/turborepo/apps/web/package.json +1 -1
  1179. package/templates/starters/turborepo/apps/web/src/app.tsx +4 -4
  1180. package/templates/starters/turborepo/apps/web/src/main.tsx +4 -1
  1181. package/templates/starters/turborepo/apps/web/vite.config.ts +2 -1
  1182. package/templates/starters/turborepo/package.json +2 -2
  1183. package/templates/starters/turborepo/packages/ui/package.json +3 -3
  1184. package/templates/starters/vite/README.md +1 -1
  1185. package/templates/starters/vite/package.json +1 -1
  1186. package/templates/starters/vite/src/app.tsx +3 -2
  1187. package/templates/starters/vite/src/components/ui/button.tsx +1 -1
  1188. package/templates/starters/vite/src/index.css +1 -1
  1189. package/templates/starters/vite/src/main.tsx +4 -1
  1190. package/templates/starters/vite/vite.config.ts +2 -1
  1191. package/app/canvas/pass-wheel.ts +0 -48
  1192. package/dist/config/package-manager.d.mts +0 -15
  1193. package/dist/server/agent-env.d.mts +0 -16
  1194. package/dist/server/agents.d.mts +0 -133
  1195. package/dist/server/agents.mjs +0 -771
  1196. package/dist/server/channel.d.mts +0 -239
  1197. package/dist/server/channel.mjs +0 -687
  1198. package/dist/server/mcp-handover.d.mts +0 -37
  1199. package/dist/server/mcp.d.mts +0 -61
  1200. package/dist/server/mcp.mjs +0 -155
  1201. package/dist/server/spec-suggestions.d.mts +0 -21
  1202. package/dist/server/spec-suggestions.mjs +0 -59
  1203. package/dist/setup/desktop-app-script.d.mts +0 -28
  1204. package/dist/setup/desktop-app-script.mjs +0 -775
  1205. package/dist/setup/desktop-app-start.d.mts +0 -65
  1206. package/dist/setup/desktop-app.d.mts +0 -174
  1207. package/dist/setup/desktop-app.mjs +0 -551
  1208. package/dist/shared/element-steps.d.mts +0 -38
  1209. package/dist/shared/element-steps.mjs +0 -40
  1210. package/extension/dist/feedback.html +0 -19
  1211. package/extension/dist/feedback.js +0 -709
  1212. package/src/config/package-manager.ts +0 -93
  1213. package/src/server/agent-env.ts +0 -70
  1214. package/src/server/agents.ts +0 -1220
  1215. package/src/server/channel.ts +0 -1161
  1216. package/src/server/mcp-handover.ts +0 -147
  1217. package/src/server/mcp.ts +0 -293
  1218. package/src/server/spec-suggestions.ts +0 -87
  1219. package/src/setup/desktop-app-script.ts +0 -815
  1220. package/src/setup/desktop-app-start.ts +0 -220
  1221. package/src/setup/desktop-app.ts +0 -849
  1222. package/src/shared/element-steps.ts +0 -99
@@ -0,0 +1,784 @@
1
+ // Two people's changes to one canvas.json, put together by what the canvas
2
+ // is made of rather than by its lines: sections by id, rows by their
3
+ // section and id, frames by uid (a frame without one by its section, row
4
+ // and id). A frame's row is one of its fields, so one side moving a frame
5
+ // while the other retitles it keeps both. Order: what neither side moved
6
+ // keeps its place; what a side moved or added goes after what it follows on
7
+ // that side. Fields merge one by one, unknown ones and unknown kinds of
8
+ // frame as any other, so nothing this Dex doesn't know is lost. What it
9
+ // can't settle, a field both sides changed differently or something one
10
+ // side deleted and the other changed, is a conflict for a person to
11
+ // resolve. Git merges canvases with it in Sync (`dex merge-canvas`); a merge
12
+ // without it (GitHub's button, a plain `git merge`) merges lines, so
13
+ // nothing Dex reads depends on it. No I/O.
14
+
15
+ /* oxlint-disable anti-slop/no-runtime-typeof, anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- parses outside input: merges three canvas.json trees read from git, fields it may not know included. */
16
+
17
+ import { isFrameUid } from "./canvas-core.ts";
18
+ import { isRecord } from "./checks.ts";
19
+ import { jsonInLayout } from "./json-style.ts";
20
+ import { REMOVED_LIMIT } from "./removed-views-core.ts";
21
+
22
+ type Rec = Record<string, unknown>;
23
+
24
+ /** Which side wins what both changed, when the person chose one. */
25
+ export type CanvasFavor = "ours" | "theirs";
26
+
27
+ export type CanvasMerge =
28
+ /** Merged: the text to write, laid out as yours is. */
29
+ | { kind: "merged"; text: string }
30
+ /** What it could not settle, each in a line a person can act on. */
31
+ | { kind: "conflict"; conflicts: string[] }
32
+ /** A side is not a canvas this merge can read: git's line merge decides. */
33
+ | { kind: "unreadable"; reason: string };
34
+
35
+ /** A value as one string, its keys sorted, to compare two values by. */
36
+ const canon = (value: unknown): string => {
37
+ if (Array.isArray(value)) {
38
+ return `[${value.map(canon).join(",")}]`;
39
+ }
40
+
41
+ if (isRecord(value)) {
42
+ return `{${Object.keys(value)
43
+ .toSorted()
44
+ .map((key) => `${JSON.stringify(key)}:${canon(value[key])}`)
45
+ .join(",")}}`;
46
+ }
47
+
48
+ return JSON.stringify(value) ?? "undefined";
49
+ };
50
+
51
+ const same = (a: unknown, b: unknown) => canon(a) === canon(b);
52
+
53
+ class UnreadableError extends Error {
54
+ constructor(message: string) {
55
+ super(message);
56
+ this.name = "UnreadableError";
57
+ }
58
+ }
59
+
60
+ /** One merge's state: what it could not settle, and who wins a clash. */
61
+ interface Merging {
62
+ conflicts: string[];
63
+ favor?: CanvasFavor;
64
+ }
65
+
66
+ /**
67
+ * A value from both sides against what it was: what one side changed takes
68
+ * that change; plain objects merge key by key, in your key order. What both
69
+ * changed differently is a conflict (yours stands meanwhile), or the
70
+ * favoured side's.
71
+ */
72
+ function merge3(
73
+ base: unknown,
74
+ ours: unknown,
75
+ theirs: unknown,
76
+ where: string,
77
+ merging: Merging
78
+ ): unknown {
79
+ if (same(ours, theirs) || same(base, theirs)) {
80
+ return ours;
81
+ }
82
+
83
+ if (same(base, ours)) {
84
+ return theirs;
85
+ }
86
+
87
+ if (isRecord(ours) && isRecord(theirs)) {
88
+ const was = isRecord(base) ? base : {};
89
+ const out: Rec = {};
90
+
91
+ for (const key of new Set([...Object.keys(ours), ...Object.keys(theirs)])) {
92
+ const value = merge3(
93
+ was[key],
94
+ ours[key],
95
+ theirs[key],
96
+ `${where} "${key}"`,
97
+ merging
98
+ );
99
+
100
+ if (value !== undefined) {
101
+ out[key] = value;
102
+ }
103
+ }
104
+
105
+ // oxlint-disable-next-line anti-slop/no-known-value-widening -- a merged value is as unknown as the values merged
106
+ return out;
107
+ }
108
+
109
+ if (merging.favor) {
110
+ return merging.favor === "ours" ? ours : theirs;
111
+ }
112
+
113
+ merging.conflicts.push(`${where}: changed differently on both sides`);
114
+
115
+ return ours;
116
+ }
117
+
118
+ // Keys of sections, rows and frames, in one namespace each. A row's key
119
+ // holds its section's id, so moving a row to another section is a delete
120
+ // and an add.
121
+ const rowKey = (section: string, row: string) => JSON.stringify([section, row]);
122
+
123
+ const placeKey = (section: string, row: string, frame: string) =>
124
+ `place:${JSON.stringify([section, row, frame])}`;
125
+
126
+ const uidKey = (uid: string) => `uid:${uid}`;
127
+
128
+ /** A section, row or frame, as a person reads where it is. */
129
+ const shown = (...ids: string[]) => ids.join("/");
130
+
131
+ /** A section with its rows taken out, a row with its frames: only fields. */
132
+ const ROWS_HERE = "\u0000rows";
133
+ const FRAMES_HERE = "\u0000frames";
134
+
135
+ interface Side {
136
+ /** Each frame, and its row's key, by uid (else by placeKey). */
137
+ frames: Map<string, { frame: Rec; row: string }>;
138
+ /** The top's keys in their order, to write them back so. */
139
+ keys: string[];
140
+ /** Frame labels for conflicts: section/row/frame. */
141
+ labels: Map<string, string>;
142
+ /** The order of sections (""), of each section's rows, each row's frames. */
143
+ order: Map<string, string[]>;
144
+ removed: unknown;
145
+ /** Each row's own fields, and its section, by rowKey. */
146
+ rows: Map<string, { row: Rec; section: string; label: string }>;
147
+ /** Each section's own fields, by id. */
148
+ sections: Map<string, Rec>;
149
+ /** Everything but sections and removed, at the top. */
150
+ top: Rec;
151
+ }
152
+
153
+ const idOf = (value: unknown, what: string): string => {
154
+ const id = isRecord(value) ? value.id : undefined;
155
+
156
+ if (typeof id !== "string") {
157
+ throw new UnreadableError(`${what} without an id`);
158
+ }
159
+
160
+ return id;
161
+ };
162
+
163
+ const listOf = (value: unknown, what: string): unknown[] => {
164
+ if (value === undefined) {
165
+ return [];
166
+ }
167
+
168
+ if (!Array.isArray(value)) {
169
+ throw new UnreadableError(`${what} is not a list`);
170
+ }
171
+
172
+ return value;
173
+ };
174
+
175
+ /** Frames that have a uid on any side, by where they are on that side. */
176
+ function uidsByPlace(canvases: Rec[]): Map<string, string> {
177
+ const uids = new Map<string, string>();
178
+
179
+ const rowsOf = (canvas: Rec) =>
180
+ listOf(canvas.sections, "sections").flatMap((section) =>
181
+ // SAFETY: idOf, which runs on each section in the same map, throws for
182
+ // anything but an object, so no row is read from one that isn't.
183
+ listOf((section as Rec).rows, "rows").map((row) => ({
184
+ section: idOf(section, "a section"),
185
+ // SAFETY: rows are read as objects here; frameKey and idOf throw for
186
+ // one that isn't before anything trusts its fields.
187
+ row: row as Rec,
188
+ }))
189
+ );
190
+
191
+ for (const { section, row } of canvases.flatMap(rowsOf)) {
192
+ for (const frame of listOf(row.frames, "frames")) {
193
+ // SAFETY: any value can be read for a key but null and undefined, and
194
+ // each field read here is checked before it is used.
195
+ const { uid, id } = frame as Rec;
196
+
197
+ const place =
198
+ typeof id === "string"
199
+ ? placeKey(section, idOf(row, "a row"), id)
200
+ : undefined;
201
+
202
+ if (isFrameUid(uid) && place && !uids.has(place)) {
203
+ uids.set(place, uid);
204
+ }
205
+ }
206
+ }
207
+
208
+ return uids;
209
+ }
210
+
211
+ /**
212
+ * A frame's key: its uid; one without, the uid a frame in its place has on
213
+ * another side (one side gave frames uids, as `dex upgrade` does, while the
214
+ * other changed one); else its place.
215
+ */
216
+ const frameKey = (
217
+ frame: Rec,
218
+ place: string,
219
+ uids: Map<string, string>
220
+ ): string => {
221
+ if (isFrameUid(frame.uid)) {
222
+ return uidKey(frame.uid);
223
+ }
224
+
225
+ const given = uids.get(place);
226
+
227
+ return given ? uidKey(given) : place;
228
+ };
229
+
230
+ function setOnce<V>(map: Map<string, V>, key: string, value: V, what: string) {
231
+ if (map.has(key)) {
232
+ throw new UnreadableError(`two of ${what}`);
233
+ }
234
+
235
+ map.set(key, value);
236
+ }
237
+
238
+ /** Each part of a canvas by its key, and the order of each list. */
239
+ function indexed(canvas: Rec, uids: Map<string, string>): Side {
240
+ const { sections: list, removed, ...top } = canvas;
241
+
242
+ const side: Side = {
243
+ sections: new Map(),
244
+ rows: new Map(),
245
+ frames: new Map(),
246
+ labels: new Map(),
247
+ order: new Map([["", []]]),
248
+ top,
249
+ removed,
250
+ keys: Object.keys(canvas),
251
+ };
252
+
253
+ for (const section of listOf(list, "sections")) {
254
+ const sectionId = idOf(section, "a section");
255
+ // SAFETY: idOf on the line before threw unless section is an object.
256
+ const { rows, ...fields } = section as Rec;
257
+ setOnce(
258
+ side.sections,
259
+ sectionId,
260
+ rows === undefined ? fields : { ...fields, rows: ROWS_HERE },
261
+ `section "${sectionId}"`
262
+ );
263
+ side.order.get("")?.push(sectionId);
264
+ const rowOrder: string[] = [];
265
+ side.order.set(`section:${sectionId}`, rowOrder);
266
+
267
+ for (const row of listOf(rows, `section "${sectionId}"'s rows`)) {
268
+ const rowId = idOf(row, `a row in "${sectionId}"`);
269
+ const key = rowKey(sectionId, rowId);
270
+ // SAFETY: idOf on the line before threw unless row is an object.
271
+ const { frames, ...rowFields } = row as Rec;
272
+ setOnce(
273
+ side.rows,
274
+ key,
275
+ {
276
+ row:
277
+ frames === undefined
278
+ ? rowFields
279
+ : { ...rowFields, frames: FRAMES_HERE },
280
+ section: sectionId,
281
+ label: shown(sectionId, rowId),
282
+ },
283
+ `row ${shown(sectionId, rowId)}`
284
+ );
285
+ rowOrder.push(key);
286
+ const frameOrder: string[] = [];
287
+ side.order.set(`row:${key}`, frameOrder);
288
+
289
+ for (const frame of listOf(frames, `row ${shown(sectionId, rowId)}`)) {
290
+ const frameId = idOf(frame, `a frame in ${shown(sectionId, rowId)}`);
291
+
292
+ const fkey = frameKey(
293
+ // SAFETY: idOf on the line before threw unless frame is an object.
294
+ frame as Rec,
295
+ placeKey(sectionId, rowId, frameId),
296
+ uids
297
+ );
298
+
299
+ setOnce(
300
+ side.frames,
301
+ fkey,
302
+ // SAFETY: idOf above threw unless frame is an object.
303
+ { frame: frame as Rec, row: key },
304
+ `frame ${shown(sectionId, rowId, frameId)}`
305
+ );
306
+ side.labels.set(fkey, shown(sectionId, rowId, frameId));
307
+ frameOrder.push(fkey);
308
+ }
309
+ }
310
+ }
311
+
312
+ return side;
313
+ }
314
+
315
+ /**
316
+ * One kind of part merged by key: added on either side, kept; deleted on
317
+ * one and left as it was on the other, gone; changed on both, merged field
318
+ * by field. Deleted on one side and changed on the other is a conflict.
319
+ */
320
+ function mergeParts<V>(
321
+ [base, ours, theirs]: Map<string, V>[],
322
+ label: (key: string) => string,
323
+ merging: Merging
324
+ ): Map<string, V> {
325
+ const out = new Map<string, V>();
326
+
327
+ for (const key of new Set([
328
+ ...base.keys(),
329
+ ...ours.keys(),
330
+ ...theirs.keys(),
331
+ ])) {
332
+ const inOurs = ours.has(key);
333
+ const inTheirs = theirs.has(key);
334
+
335
+ if (inOurs && inTheirs) {
336
+ out.set(
337
+ key,
338
+ // SAFETY: merging three of a kind of part gives one of that kind: one
339
+ // side's as it is, or both merged field by field.
340
+ merge3(
341
+ base.get(key),
342
+ ours.get(key),
343
+ theirs.get(key),
344
+ label(key),
345
+ merging
346
+ ) as V
347
+ );
348
+ continue;
349
+ }
350
+
351
+ if (!(inOurs || inTheirs)) {
352
+ continue;
353
+ }
354
+
355
+ // SAFETY: the key is in ours or theirs, so the map it is read from has it.
356
+ const kept = (inOurs ? ours.get(key) : theirs.get(key)) as V;
357
+
358
+ if (!base.has(key)) {
359
+ out.set(key, kept);
360
+ } else if (!same(base.get(key), kept)) {
361
+ if (merging.favor) {
362
+ if ((merging.favor === "ours") === inOurs) {
363
+ out.set(key, kept);
364
+ }
365
+
366
+ continue;
367
+ }
368
+
369
+ merging.conflicts.push(
370
+ `${label(key)}: deleted on one side, changed on the other`
371
+ );
372
+ out.set(key, kept);
373
+ }
374
+ }
375
+
376
+ return out;
377
+ }
378
+
379
+ /** The keys of `side` that keep their order from `base`. */
380
+ function staying(base: string[], side: string[]): Set<string> {
381
+ const lengths = Array.from({ length: base.length + 1 }, () =>
382
+ Array.from({ length: side.length + 1 }, () => 0)
383
+ );
384
+
385
+ for (let i = base.length - 1; i >= 0; i -= 1) {
386
+ for (let j = side.length - 1; j >= 0; j -= 1) {
387
+ lengths[i][j] =
388
+ base[i] === side[j]
389
+ ? lengths[i + 1][j + 1] + 1
390
+ : Math.max(lengths[i + 1][j], lengths[i][j + 1]);
391
+ }
392
+ }
393
+
394
+ const out = new Set<string>();
395
+ let i = 0;
396
+ let j = 0;
397
+
398
+ while (i < base.length && j < side.length) {
399
+ if (base[i] === side[j]) {
400
+ out.add(side[j]);
401
+ i += 1;
402
+ j += 1;
403
+ } else if (lengths[i + 1][j] >= lengths[i][j + 1]) {
404
+ i += 1;
405
+ } else {
406
+ j += 1;
407
+ }
408
+ }
409
+
410
+ return out;
411
+ }
412
+
413
+ /**
414
+ * A list's merged order: what neither side moved stays in base order; what
415
+ * a side moved or added goes after the nearest item before it on that side
416
+ * that the other side didn't move. Both moved one item: yours wins.
417
+ */
418
+ function mergeOrder(
419
+ [base, ours, theirs]: string[][],
420
+ keep: Set<string>
421
+ ): string[] {
422
+ const moved = [ours, theirs].map((side) => {
423
+ const stay = staying(base, side);
424
+
425
+ return new Set(side.filter((key) => !stay.has(key)));
426
+ });
427
+
428
+ const out = base.filter(
429
+ (key) => keep.has(key) && !moved[0].has(key) && !moved[1].has(key)
430
+ );
431
+
432
+ for (const [index, side] of [ours, theirs].entries()) {
433
+ const other = moved[1 - index];
434
+
435
+ for (const [at, key] of side.entries()) {
436
+ if (!(moved[index].has(key) && keep.has(key)) || out.includes(key)) {
437
+ continue;
438
+ }
439
+
440
+ const before = side
441
+ .slice(0, at)
442
+ .toReversed()
443
+ .find((each) => out.includes(each) && !other.has(each));
444
+
445
+ // After what yours put in the same place, so yours come first.
446
+ let place = before === undefined ? 0 : out.indexOf(before) + 1;
447
+
448
+ while (place < out.length && other.has(out[place])) {
449
+ place += 1;
450
+ }
451
+
452
+ out.splice(place, 0, key);
453
+ }
454
+ }
455
+
456
+ for (const key of keep) {
457
+ if (!out.includes(key)) {
458
+ out.push(key);
459
+ }
460
+ }
461
+
462
+ return out;
463
+ }
464
+
465
+ const removalView = (entry: unknown): string | undefined =>
466
+ isRecord(entry) && typeof entry.view === "string" ? entry.view : undefined;
467
+
468
+ const later = (a: unknown, b: unknown) =>
469
+ // SAFETY: mergeRemovals passes only entries removalView read, each an object
470
+ // with a view.
471
+ String((b as Rec).removedAt ?? "") > String((a as Rec).removedAt ?? "")
472
+ ? b
473
+ : a;
474
+
475
+ /**
476
+ * The views each side took off the canvas (`removed`), one entry a view:
477
+ * both sides' kept, the later of two, newest first. Never a conflict: it
478
+ * only remembers where a view was.
479
+ */
480
+ function mergeRemovals(
481
+ [base, ours, theirs]: unknown[],
482
+ merging: Merging
483
+ ): unknown {
484
+ const lists = [base, ours, theirs];
485
+
486
+ const readable = lists.every(
487
+ (list) =>
488
+ list === undefined ||
489
+ (Array.isArray(list) && list.every((entry) => removalView(entry)))
490
+ );
491
+
492
+ if (!readable) {
493
+ return merge3(base, ours, theirs, "removed", merging);
494
+ }
495
+
496
+ const byView = lists.map(
497
+ (list) =>
498
+ new Map(
499
+ // SAFETY: readable above: each list is a list or undefined.
500
+ ((list as unknown[] | undefined) ?? []).map((entry) => [
501
+ // SAFETY: readable above: removalView reads a view from every entry.
502
+ removalView(entry) as string,
503
+ entry,
504
+ ])
505
+ )
506
+ );
507
+
508
+ const out: unknown[] = [];
509
+ const [was, mine, yours] = byView;
510
+
511
+ for (const view of new Set([
512
+ ...mine.keys(),
513
+ ...yours.keys(),
514
+ ...was.keys(),
515
+ ])) {
516
+ const a = mine.get(view);
517
+ const b = yours.get(view);
518
+
519
+ if (a !== undefined && b !== undefined) {
520
+ out.push(later(a, b));
521
+ } else if (a !== undefined || b !== undefined) {
522
+ const kept = a ?? b;
523
+
524
+ // Gone on one side (the view is back on its canvas): gone, unless
525
+ // the other side changed it since.
526
+ if (!(was.has(view) && same(was.get(view), kept))) {
527
+ out.push(kept);
528
+ }
529
+ }
530
+ }
531
+
532
+ if (out.length === 0) {
533
+ return ours === undefined && theirs === undefined ? undefined : [];
534
+ }
535
+
536
+ return out
537
+ .map((entry, index) => ({ entry, index }))
538
+ .toSorted(
539
+ (a, b) =>
540
+ // SAFETY: every entry is a removal removalView read: an object with a
541
+ // view.
542
+ String((b.entry as Rec).removedAt ?? "").localeCompare(
543
+ String((a.entry as Rec).removedAt ?? "")
544
+ ) || a.index - b.index
545
+ )
546
+ .map(({ entry }) => entry)
547
+ .slice(0, REMOVED_LIMIT);
548
+ }
549
+
550
+ const ID_NUMBER_RE = /-\d+$/u;
551
+
552
+ /**
553
+ * A row's frames, each id once: a frame that came into the row (added or
554
+ * moved by either side) and has the id of one already there takes the next
555
+ * free number, as Dex names a copy.
556
+ */
557
+ function uniqueIds(frames: Rec[], wasHere: boolean[]): Rec[] {
558
+ const taken = new Set(
559
+ frames.flatMap((frame, index) => (wasHere[index] ? [frame.id] : []))
560
+ );
561
+
562
+ return frames.map((frame, index) => {
563
+ if (wasHere[index]) {
564
+ return frame;
565
+ }
566
+
567
+ // SAFETY: idOf threw for a frame without a string id when the canvas was
568
+ // indexed.
569
+ let id = frame.id as string;
570
+
571
+ for (let n = 2; taken.has(id); n += 1) {
572
+ // SAFETY: idOf threw for a frame without a string id when the canvas was
573
+ // indexed.
574
+ id = `${(frame.id as string).replace(ID_NUMBER_RE, "")}-${n}`;
575
+ }
576
+
577
+ taken.add(id);
578
+
579
+ return id === frame.id ? frame : { ...frame, id };
580
+ });
581
+ }
582
+
583
+ const parse = (text: string, which: string): Rec => {
584
+ if (!text.trim()) {
585
+ return {};
586
+ }
587
+
588
+ let value: unknown;
589
+
590
+ try {
591
+ value = JSON.parse(text);
592
+ } catch {
593
+ throw new UnreadableError(`${which} is not JSON`);
594
+ }
595
+
596
+ if (!isRecord(value)) {
597
+ throw new UnreadableError(`${which} is not a canvas`);
598
+ }
599
+
600
+ return value;
601
+ };
602
+
603
+ /** The merged canvas, or what stopped it. */
604
+ function mergeParsed(sides: Rec[], merging: Merging) {
605
+ const uids = uidsByPlace(sides);
606
+ const [base, ours, theirs] = sides.map((canvas) => indexed(canvas, uids));
607
+ const all = [base, ours, theirs];
608
+
609
+ const sections = mergeParts(
610
+ all.map((side) => side.sections),
611
+ (key) => `section ${key}`,
612
+ merging
613
+ );
614
+
615
+ const rows = mergeParts(
616
+ all.map((side) => side.rows),
617
+ (key) =>
618
+ `row ${ours.rows.get(key)?.label ?? theirs.rows.get(key)?.label ?? base.rows.get(key)?.label ?? key}`,
619
+ merging
620
+ );
621
+
622
+ const frames = mergeParts(
623
+ all.map((side) => side.frames),
624
+ (key) =>
625
+ `frame ${ours.labels.get(key) ?? theirs.labels.get(key) ?? base.labels.get(key) ?? key}`,
626
+ merging
627
+ );
628
+
629
+ const frameLabel = (key: string) =>
630
+ ours.labels.get(key) ?? theirs.labels.get(key) ?? key;
631
+
632
+ // A part whose section or row the other side deleted: stop, unless a
633
+ // side was chosen, whose deletion then takes it too.
634
+ for (const [key, { section, label }] of rows) {
635
+ if (!sections.has(section)) {
636
+ if (!merging.favor) {
637
+ merging.conflicts.push(
638
+ `row ${label}: added or changed on one side, its section deleted on the other`
639
+ );
640
+ }
641
+
642
+ rows.delete(key);
643
+ }
644
+ }
645
+
646
+ for (const [key, { row }] of frames) {
647
+ if (!rows.has(row)) {
648
+ if (!merging.favor) {
649
+ merging.conflicts.push(
650
+ `frame ${frameLabel(key)}: added or changed on one side, its row deleted on the other`
651
+ );
652
+ }
653
+
654
+ frames.delete(key);
655
+ }
656
+ }
657
+
658
+ const orderOf = (list: string, keep: Set<string>) =>
659
+ mergeOrder(
660
+ all.map((side) => side.order.get(list) ?? []),
661
+ keep
662
+ );
663
+
664
+ const merged = [...orderOf("", new Set(sections.keys()))].map((sectionId) => {
665
+ // SAFETY: orderOf gives only keys it is asked to keep: these, the keys of
666
+ // sections.
667
+ const { rows: hasRows, ...fields } = sections.get(sectionId) as Rec;
668
+ const here = [...rows].filter(([, row]) => row.section === sectionId);
669
+
670
+ const sectionRows = orderOf(
671
+ `section:${sectionId}`,
672
+ new Set(here.map(([key]) => key))
673
+ ).map((key) => {
674
+ // SAFETY: orderOf gives only keys it is asked to keep: these, keys of
675
+ // rows.
676
+ const { row } = rows.get(key) as { row: Rec };
677
+ const { frames: hasFrames, ...rowFields } = row;
678
+
679
+ const inRow = orderOf(
680
+ `row:${key}`,
681
+ new Set(
682
+ [...frames].flatMap(([k, frame]) => (frame.row === key ? [k] : []))
683
+ )
684
+ );
685
+
686
+ const rowFrames = uniqueIds(
687
+ // SAFETY: inRow holds only keys of frames, those whose row is this one.
688
+ inRow.map((k) => (frames.get(k) as { frame: Rec }).frame),
689
+ inRow.map((k) => base.frames.get(k)?.row === key)
690
+ );
691
+
692
+ return hasFrames === undefined && rowFrames.length === 0
693
+ ? rowFields
694
+ : { ...rowFields, frames: rowFrames };
695
+ });
696
+
697
+ return hasRows === undefined && sectionRows.length === 0
698
+ ? fields
699
+ : { ...fields, rows: sectionRows };
700
+ });
701
+
702
+ // SAFETY: each side's top is an object, and merging objects gives one.
703
+ const top = merge3(
704
+ base.top,
705
+ ours.top,
706
+ theirs.top,
707
+ "the canvas",
708
+ merging
709
+ ) as Rec;
710
+
711
+ const removed = mergeRemovals(
712
+ [base.removed, ours.removed, theirs.removed],
713
+ merging
714
+ );
715
+
716
+ // oxlint-disable-next-line anti-slop/no-known-value-widening -- read by any key below, as the top's fields are
717
+ const special: Rec = { sections: merged, removed };
718
+ // Written in your key order, then theirs', so only what changed moves.
719
+ const out: Rec = {};
720
+
721
+ for (const key of [
722
+ ...ours.keys,
723
+ ...theirs.keys,
724
+ ...Object.keys(top),
725
+ "sections",
726
+ "removed",
727
+ ]) {
728
+ if (key in out) {
729
+ continue;
730
+ }
731
+
732
+ const value = key in special ? special[key] : top[key];
733
+
734
+ if (value !== undefined) {
735
+ out[key] = value;
736
+ }
737
+ }
738
+
739
+ return out;
740
+ }
741
+
742
+ /**
743
+ * Three canvases' texts merged by structure, written as `mine` is laid
744
+ * out. `favor` settles what both changed, as Sync's Keep mine or Keep theirs
745
+ * does for lines.
746
+ */
747
+ export function mergeCanvases(
748
+ base: string,
749
+ mine: string,
750
+ theirs: string,
751
+ { favor }: { favor?: CanvasFavor } = {}
752
+ ): CanvasMerge {
753
+ if (mine === theirs || theirs === base) {
754
+ return { kind: "merged", text: mine };
755
+ }
756
+
757
+ if (mine === base) {
758
+ return { kind: "merged", text: theirs };
759
+ }
760
+
761
+ const merging: Merging = { conflicts: [], ...(favor && { favor }) };
762
+
763
+ try {
764
+ const sides = [
765
+ parse(base, "the common version"),
766
+ parse(mine, "yours"),
767
+ parse(theirs, "theirs"),
768
+ ];
769
+
770
+ const merged = mergeParsed(sides, merging);
771
+
772
+ if (merging.conflicts.length > 0) {
773
+ return { kind: "conflict", conflicts: merging.conflicts };
774
+ }
775
+
776
+ return { kind: "merged", text: jsonInLayout(merged, mine) };
777
+ } catch (error) {
778
+ if (error instanceof UnreadableError) {
779
+ return { kind: "unreadable", reason: error.message };
780
+ }
781
+
782
+ throw error;
783
+ }
784
+ }