@dexhq/canvas 0.16.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 (1176) hide show
  1. package/CHANGELOG.md +58 -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 +30 -8
  8. package/app/canvas/activity.tsx +153 -35
  9. package/app/canvas/add-to-spec.ts +14 -5
  10. package/app/canvas/agent-changes.ts +59 -4
  11. package/app/canvas/anchoring.ts +165 -49
  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 +17 -2
  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 +277 -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 +253 -213
  24. package/app/canvas/canvas-panels.ts +10 -0
  25. package/app/canvas/canvas-scene.ts +526 -96
  26. package/app/canvas/canvas-ui.ts +68 -6
  27. package/app/canvas/canvas.css +398 -31
  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 +331 -127
  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 +25 -6
  40. package/app/canvas/element-picker.ts +103 -481
  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 +17 -3
  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 +341 -99
  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 +267 -31
  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 +297 -69
  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 +699 -306
  75. package/app/canvas/linked-element.tsx +24 -1
  76. package/app/canvas/live-page.ts +226 -29
  77. package/app/canvas/measure-box.tsx +1 -0
  78. package/app/canvas/mentions.tsx +12 -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 +1 -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 +39 -8
  99. package/app/canvas/request-node.tsx +22 -8
  100. package/app/canvas/review-marker.tsx +9 -2
  101. package/app/canvas/review-panel.tsx +145 -42
  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 +73 -14
  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 +32 -7
  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 +21 -3
  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 +55 -14
  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 +15 -1
  143. package/app/canvas/tool-icons.tsx +17 -4
  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 +6 -1
  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 +60 -15
  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 +39 -14
  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 +37 -9
  174. package/app/export/player.tsx +21 -4
  175. package/app/frame/file-errors.ts +4 -0
  176. package/app/frame/frame-app.tsx +15 -1
  177. package/app/frame/frame-history.ts +9 -0
  178. package/app/frame/frame-links.ts +7 -0
  179. package/app/frame/hold-window-focus.ts +4 -0
  180. package/app/frame/left-view.tsx +6 -0
  181. package/app/frame/start-frame.tsx +8 -2
  182. package/app/frame/studio-view.tsx +2 -0
  183. package/app/frame/view-exports.ts +240 -0
  184. package/app/frame/view-loads.ts +37 -11
  185. package/app/frame/views.ts +79 -8
  186. package/app/git/branch-panel.tsx +71 -25
  187. package/app/git/change-list.tsx +15 -6
  188. package/app/git/clash.tsx +10 -5
  189. package/app/git/git-controls.tsx +78 -22
  190. package/app/git/git-state.ts +20 -0
  191. package/app/git/git-toasts.tsx +41 -2
  192. package/app/git/paused.tsx +28 -12
  193. package/app/git/saved-list.tsx +10 -3
  194. package/app/git/sync-panel.tsx +39 -18
  195. package/app/i18n/locales/en/messages.po +119 -6
  196. package/app/i18n/locales/en/messages.ts +1 -1
  197. package/app/i18n/locales/pseudo/messages.po +116 -3
  198. package/app/i18n/locales/pseudo/messages.ts +1 -1
  199. package/app/i18n/locales.ts +4 -0
  200. package/app/i18n/provider.tsx +9 -5
  201. package/app/icons/dex-glyphs.tsx +38 -0
  202. package/app/icons/glyphs.tsx +5 -0
  203. package/app/icons/index.tsx +3 -1
  204. package/app/icons/types.ts +1 -0
  205. package/app/kit/inspect-runtime.ts +50 -5
  206. package/app/kit/sample-people.ts +6 -0
  207. package/app/kit/use-simulated-load.ts +6 -2
  208. package/app/kit/use-simulated-stream.ts +8 -2
  209. package/app/kit/use-view-control.ts +1 -0
  210. package/app/live/canvas-teammates.ts +14 -1
  211. package/app/live/deployed-preview.ts +1 -0
  212. package/app/live/focus-reporter.ts +8 -0
  213. package/app/live/guest-review.ts +115 -23
  214. package/app/live/restart-wait.ts +14 -2
  215. package/app/live/server-connection.ts +21 -4
  216. package/app/live/studio-action.ts +6 -1
  217. package/app/live/studio-api.ts +191 -54
  218. package/app/live/studio-data.ts +26 -1
  219. package/app/live/studio-live.ts +44 -8
  220. package/app/live/studio-request.ts +15 -1
  221. package/app/live/thread-state.ts +8 -0
  222. package/app/live/use-devices.ts +11 -2
  223. package/app/live/use-focus.ts +5 -2
  224. package/app/live/use-last-edited.ts +2 -0
  225. package/app/live/use-show-requests.ts +3 -0
  226. package/app/live/use-workspace.ts +10 -2
  227. package/app/main.tsx +9 -3
  228. package/app/next/fonts.ts +1 -0
  229. package/app/next/image.tsx +17 -10
  230. package/app/next/navigation.ts +9 -6
  231. package/app/next/router.ts +4 -4
  232. package/app/pages/agent-settings.tsx +11 -3
  233. package/app/pages/ask-the-agent.tsx +2 -0
  234. package/app/pages/canvas-settings.tsx +3 -0
  235. package/app/pages/canvas.tsx +230 -71
  236. package/app/pages/chrome-extension.tsx +4 -2
  237. package/app/pages/commands-settings.tsx +74 -25
  238. package/app/pages/deployment-settings.tsx +9 -0
  239. package/app/pages/doc.tsx +4 -1
  240. package/app/pages/file-sort.ts +11 -4
  241. package/app/pages/git-checks.tsx +30 -10
  242. package/app/pages/guidelines.tsx +8 -4
  243. package/app/pages/home.tsx +41 -17
  244. package/app/pages/host.tsx +4 -0
  245. package/app/pages/markup-settings.tsx +11 -5
  246. package/app/pages/people.tsx +18 -10
  247. package/app/pages/play-bar.tsx +27 -9
  248. package/app/pages/play-size.ts +31 -11
  249. package/app/pages/play.tsx +115 -33
  250. package/app/pages/profile.tsx +6 -2
  251. package/app/pages/prototype.tsx +10 -4
  252. package/app/pages/render.tsx +33 -8
  253. package/app/pages/settings.tsx +5 -1
  254. package/app/pages/workspace-general.tsx +29 -5
  255. package/app/pages/workspace-git.tsx +38 -10
  256. package/app/pages/your-guidelines.tsx +7 -0
  257. package/app/pages/your-picture.tsx +33 -10
  258. package/app/registry-files.ts +6 -1
  259. package/app/registry.ts +73 -13
  260. package/app/renamed-storage.ts +8 -1
  261. package/app/shell/about.tsx +10 -4
  262. package/app/shell/agent-logos.tsx +4 -0
  263. package/app/shell/agent-manual.tsx +13 -5
  264. package/app/shell/avatar-pictures.ts +18 -6
  265. package/app/shell/avatar.tsx +11 -1
  266. package/app/shell/bell.tsx +27 -13
  267. package/app/shell/broke.tsx +1 -1
  268. package/app/shell/chrome-theme.tsx +4 -0
  269. package/app/shell/connect-agent.tsx +76 -38
  270. package/app/shell/copy-text.tsx +3 -1
  271. package/app/shell/deployed-preview-bar.tsx +4 -6
  272. package/app/shell/desktop-app.tsx +30 -15
  273. package/app/shell/empty-state.tsx +2 -2
  274. package/app/shell/feedback-details.ts +8 -1
  275. package/app/shell/feedback-form.tsx +38 -30
  276. package/app/shell/feedback-link.tsx +3 -0
  277. package/app/shell/file-bytes.ts +3 -1
  278. package/app/shell/host.ts +37 -8
  279. package/app/shell/info-tip.tsx +2 -1
  280. package/app/shell/install-prompt.ts +10 -1
  281. package/app/shell/instructions-editor.tsx +184 -78
  282. package/app/shell/instructions.tsx +7 -1
  283. package/app/shell/main-sidebar.tsx +27 -6
  284. package/app/shell/open-agent.tsx +8 -2
  285. package/app/shell/page-header.tsx +6 -3
  286. package/app/shell/page-title.ts +36 -14
  287. package/app/shell/presence-style.ts +8 -0
  288. package/app/shell/presence.tsx +74 -10
  289. package/app/shell/prototype-menu.tsx +84 -27
  290. package/app/shell/quick-start.tsx +21 -3
  291. package/app/shell/recents.ts +21 -2
  292. package/app/shell/report-issue.ts +29 -23
  293. package/app/shell/restart-toast.tsx +37 -4
  294. package/app/shell/save-state.tsx +4 -0
  295. package/app/shell/scaled-frame.tsx +22 -1
  296. package/app/shell/settings-sections.ts +12 -11
  297. package/app/shell/settings-sidebar.tsx +7 -1
  298. package/app/shell/settings-ui.tsx +11 -7
  299. package/app/shell/shell-bar.ts +2 -5
  300. package/app/shell/sidebar.tsx +2 -2
  301. package/app/shell/skeleton.ts +80 -22
  302. package/app/shell/status-badge.tsx +2 -0
  303. package/app/shell/studio-shell.tsx +11 -4
  304. package/app/shell/thread-list.tsx +18 -7
  305. package/app/shell/time-ago.ts +7 -0
  306. package/app/shell/toasts.tsx +20 -13
  307. package/app/shell/update-notice.tsx +241 -41
  308. package/app/shell/use-copied.ts +4 -0
  309. package/app/shell/use-space.ts +5 -0
  310. package/app/shell/watch-switch.tsx +4 -1
  311. package/app/shell/welcome.tsx +18 -3
  312. package/app/shell/window-buttons.tsx +17 -3
  313. package/app/shell/working-on.tsx +10 -2
  314. package/app/shell/workspace-mark.tsx +59 -25
  315. package/app/studio-ui.d.ts +2 -1
  316. package/app/styles.css +4 -12
  317. package/app/types.ts +8 -6
  318. package/app/ui/boundary.tsx +6 -1
  319. package/app/ui/file-drop.ts +32 -18
  320. package/app/ui/prompt-editor.tsx +81 -25
  321. package/app/ui/reference.tsx +6 -1
  322. package/app/ui/segmented.tsx +3 -1
  323. package/app/ui/theme-switch.tsx +1 -0
  324. package/app/ui/theme.css +17 -0
  325. package/app/ui/use-latest.ts +13 -0
  326. package/app/ui/use-once.ts +9 -0
  327. package/bin/dex.mjs +6 -1
  328. package/bin/sudio.mjs +1 -0
  329. package/dist/cli/banner.mjs +0 -1
  330. package/dist/cli/command.d.mts +237 -5
  331. package/dist/cli/command.mjs +8 -3
  332. package/dist/cli/commands/agents/add.mjs +1 -1
  333. package/dist/cli/commands/app.mjs +13 -16
  334. package/dist/cli/commands/claude.d.mts +3 -3
  335. package/dist/cli/commands/claude.mjs +10 -9
  336. package/dist/cli/commands/cloud/publish.mjs +1 -1
  337. package/dist/cli/commands/dev.mjs +64 -19
  338. package/dist/cli/commands/doctor.mjs +3 -1
  339. package/dist/cli/commands/hook.mjs +1 -1
  340. package/dist/cli/commands/mcp.mjs +10 -4
  341. package/dist/cli/commands/merge-canvas.d.mts +29 -0
  342. package/dist/cli/commands/merge-canvas.mjs +101 -0
  343. package/dist/cli/commands/merge-contributors.d.mts +0 -7
  344. package/dist/cli/commands/merge-contributors.mjs +2 -1
  345. package/dist/cli/commands/merge-spec.d.mts +0 -7
  346. package/dist/cli/commands/merge-spec.mjs +2 -1
  347. package/dist/cli/help.mjs +7 -13
  348. package/dist/cli/main.d.mts +26 -0
  349. package/dist/cli/main.mjs +4 -2
  350. package/dist/cli/mcp-relay.d.mts +5 -5
  351. package/dist/cli/mcp-relay.mjs +36 -24
  352. package/dist/cli/recovery-server.mjs +2 -2
  353. package/dist/cli/strict-flags.mjs +6 -6
  354. package/dist/cli/supervise.mjs +37 -26
  355. package/dist/cli/ui.d.mts +21 -21
  356. package/dist/cli/ui.mjs +2 -1
  357. package/dist/config/design-system.mjs +19 -14
  358. package/dist/config/load.mjs +10 -7
  359. package/dist/config/project-files.d.mts +3 -2
  360. package/dist/config/project-files.mjs +35 -41
  361. package/dist/config/renamed.d.mts +4 -8
  362. package/dist/config/renamed.mjs +4 -17
  363. package/dist/content/biome.mjs +15 -10
  364. package/dist/content/capture.mjs +43 -42
  365. package/dist/content/commands.d.mts +10 -4
  366. package/dist/content/commands.mjs +49 -21
  367. package/dist/content/comments-log.mjs +102 -19
  368. package/dist/content/component-props.mjs +6 -10
  369. package/dist/content/content.d.mts +269 -33
  370. package/dist/content/content.mjs +205 -146
  371. package/dist/content/devices.mjs +2 -2
  372. package/dist/content/element-words.mjs +7 -7
  373. package/dist/content/file-turns.mjs +1 -1
  374. package/dist/content/first-run.mjs +3 -5
  375. package/dist/content/flow-specs.mjs +18 -16
  376. package/dist/content/format-check.d.mts +46 -0
  377. package/dist/content/format-check.mjs +338 -0
  378. package/dist/content/hosted-person.mjs +4 -3
  379. package/dist/content/insert-edit.mjs +7 -6
  380. package/dist/content/jsx-source.d.mts +5 -1
  381. package/dist/content/jsx-source.mjs +8 -7
  382. package/dist/content/last-edited.mjs +1 -1
  383. package/dist/content/layout.d.mts +44 -2
  384. package/dist/content/layout.mjs +65 -6
  385. package/dist/content/merge-rules.d.mts +11 -4
  386. package/dist/content/merge-rules.mjs +31 -18
  387. package/dist/content/prop-edit.mjs +4 -4
  388. package/dist/content/prototype-checks.mjs +13 -12
  389. package/dist/content/prototype-summary.d.mts +1 -1
  390. package/dist/content/prototype-summary.mjs +8 -8
  391. package/dist/content/prototypes.d.mts +8 -1
  392. package/dist/content/prototypes.mjs +41 -27
  393. package/dist/content/review-import.mjs +1 -1
  394. package/dist/content/review-pages.mjs +19 -16
  395. package/dist/content/screenshot.d.mts +4 -1
  396. package/dist/content/screenshot.mjs +18 -14
  397. package/dist/content/snapshot-client.mjs +2 -3
  398. package/dist/content/store.d.mts +16 -8
  399. package/dist/content/store.mjs +99 -26
  400. package/dist/content/sub-agents.d.mts +12 -0
  401. package/dist/content/sub-agents.mjs +52 -0
  402. package/dist/content/text-edit.mjs +6 -6
  403. package/dist/content/text-replace.mjs +13 -15
  404. package/dist/content/thread-module.d.mts +9 -1
  405. package/dist/content/thread-module.mjs +19 -1
  406. package/dist/content/threads.d.mts +13 -0
  407. package/dist/content/threads.mjs +59 -14
  408. package/dist/content/trash.d.mts +4 -2
  409. package/dist/content/trash.mjs +31 -31
  410. package/dist/desktop/src/app.d.mts +40 -0
  411. package/dist/desktop/src/app.mjs +80 -0
  412. package/dist/desktop/src/contract.d.mts +7 -0
  413. package/dist/desktop/src/contract.mjs +22 -0
  414. package/dist/desktop/src/host.d.mts +48 -0
  415. package/dist/desktop/src/index.d.mts +32 -0
  416. package/dist/desktop/src/index.mjs +69 -0
  417. package/dist/desktop/src/mac/bundle.mjs +116 -0
  418. package/dist/desktop/src/mac/icon.mjs +53 -0
  419. package/dist/desktop/src/mac/launcher.mjs +69 -0
  420. package/dist/desktop/src/mac/plist.mjs +73 -0
  421. package/dist/desktop/src/mac/program/constants.mjs +62 -0
  422. package/dist/desktop/src/mac/program/delegate.mjs +214 -0
  423. package/dist/desktop/src/mac/program/downloads.mjs +19 -0
  424. package/dist/desktop/src/mac/program/index.mjs +26 -0
  425. package/dist/desktop/src/mac/program/menu.mjs +125 -0
  426. package/dist/desktop/src/mac/program/server-pages.mjs +140 -0
  427. package/dist/desktop/src/mac/program/web-view.mjs +59 -0
  428. package/dist/desktop/src/mac/program/window.mjs +197 -0
  429. package/dist/desktop/src/mac/services.mjs +28 -0
  430. package/dist/desktop/src/plug-in/http.d.mts +11 -0
  431. package/dist/desktop/src/plug-in/http.mjs +51 -0
  432. package/dist/desktop/src/plug-in/page-head.d.mts +8 -0
  433. package/dist/desktop/src/plug-in/page-head.mjs +31 -0
  434. package/dist/desktop/src/service.d.mts +15 -0
  435. package/dist/desktop/src/service.mjs +151 -0
  436. package/dist/desktop/src/start.d.mts +42 -0
  437. package/dist/{setup/desktop-app-start.mjs → desktop/src/start.mjs} +14 -39
  438. package/dist/harness/src/agents/adapter.d.mts +11 -0
  439. package/dist/harness/src/agents/adapter.mjs +6 -0
  440. package/dist/harness/src/agents/claude-code.mjs +179 -0
  441. package/dist/harness/src/agents/codex.mjs +189 -0
  442. package/dist/harness/src/agents/copilot.mjs +20 -0
  443. package/dist/harness/src/agents/cursor.mjs +21 -0
  444. package/dist/harness/src/agents/opencode.mjs +27 -0
  445. package/dist/harness/src/agents/other.mjs +21 -0
  446. package/dist/harness/src/agents/registry.mjs +21 -0
  447. package/dist/harness/src/agents/sub-agent.d.mts +14 -0
  448. package/dist/harness/src/agents.mjs +7 -0
  449. package/dist/harness/src/checks.mjs +9 -0
  450. package/dist/harness/src/connect/agent-config.mjs +252 -0
  451. package/dist/{server → harness/src/connect}/agent-env.mjs +3 -4
  452. package/dist/harness/src/connect/agent-root.mjs +30 -0
  453. package/dist/harness/src/connect/json-layout.mjs +52 -0
  454. package/dist/harness/src/connect/launch.mjs +67 -0
  455. package/dist/harness/src/connect/launched.d.mts +23 -0
  456. package/dist/harness/src/connect/package-manager.d.mts +1 -0
  457. package/dist/{config → harness/src/connect}/package-manager.mjs +17 -6
  458. package/dist/harness/src/connect/setups.d.mts +24 -0
  459. package/dist/harness/src/connect/setups.mjs +98 -0
  460. package/dist/harness/src/connect/workspace-root.d.mts +20 -0
  461. package/dist/harness/src/connect/workspace-root.mjs +110 -0
  462. package/dist/harness/src/events/channel-server.mjs +10 -0
  463. package/dist/harness/src/events/channel.d.mts +104 -0
  464. package/dist/harness/src/events/channel.mjs +457 -0
  465. package/dist/harness/src/events/connected-agent.d.mts +35 -0
  466. package/dist/harness/src/events/place.d.mts +21 -0
  467. package/dist/harness/src/mcp/define-tool.d.mts +26 -0
  468. package/dist/harness/src/mcp/define-tool.mjs +11 -0
  469. package/dist/harness/src/mcp/mcp-handover.d.mts +11 -0
  470. package/dist/{server → harness/src/mcp}/mcp-handover.mjs +6 -4
  471. package/dist/harness/src/mcp/mcp.d.mts +15 -0
  472. package/dist/harness/src/mcp/mcp.mjs +97 -0
  473. package/dist/harness/src/paths.d.mts +4 -0
  474. package/dist/harness/src/paths.mjs +15 -0
  475. package/dist/harness/src/project.d.mts +6 -0
  476. package/dist/harness/src/renamed.d.mts +9 -0
  477. package/dist/harness/src/renamed.mjs +22 -0
  478. package/dist/harness/src/session/session.d.mts +31 -0
  479. package/dist/harness/src/version.d.mts +13 -0
  480. package/dist/harness/src/version.mjs +47 -0
  481. package/dist/inspector.js +598 -0
  482. package/dist/paste/figma/captures.mjs +3 -3
  483. package/dist/paste/figma/decode.d.mts +14 -8
  484. package/dist/paste/figma/decode.mjs +11 -9
  485. package/dist/paste/figma/layout.d.mts +4 -3
  486. package/dist/paste/figma/layout.mjs +1 -1
  487. package/dist/paste/figma/paint.mjs +7 -5
  488. package/dist/paste/figma/render.mjs +1 -1
  489. package/dist/paste/figma/styles.d.mts +3 -1
  490. package/dist/paste/figma/styles.mjs +5 -9
  491. package/dist/paste/figma/text.mjs +21 -17
  492. package/dist/paste/figma/vector.mjs +9 -9
  493. package/dist/paste/fonts.mjs +7 -8
  494. package/dist/paste/paste.d.mts +2 -2
  495. package/dist/paste/paste.mjs +16 -15
  496. package/dist/paths.d.mts +22 -16
  497. package/dist/paths.mjs +28 -57
  498. package/dist/server/agent-session.d.mts +49 -3
  499. package/dist/server/agent-session.mjs +264 -20
  500. package/dist/server/agent-tools.d.mts +17 -0
  501. package/dist/server/agent-tools.mjs +31 -0
  502. package/dist/server/agents-place.d.mts +6 -0
  503. package/dist/server/agents-place.mjs +18 -0
  504. package/dist/server/allowed-request.mjs +1 -1
  505. package/dist/server/avatars.d.mts +3 -1
  506. package/dist/server/avatars.mjs +9 -7
  507. package/dist/server/brief.mjs +10 -10
  508. package/dist/server/briefing.d.mts +5 -5
  509. package/dist/server/briefing.mjs +5 -5
  510. package/dist/server/build-pictures.mjs +8 -8
  511. package/dist/server/build-settings.d.mts +1 -1
  512. package/dist/server/build-settings.mjs +4 -4
  513. package/dist/server/changelog.mjs +5 -4
  514. package/dist/server/claimed-presence.mjs +10 -7
  515. package/dist/server/close-check.mjs +17 -15
  516. package/dist/server/cloud.d.mts +1 -1
  517. package/dist/server/cloud.mjs +5 -4
  518. package/dist/server/command-settings.d.mts +4 -2
  519. package/dist/server/command-settings.mjs +11 -7
  520. package/dist/server/comments/actions.d.mts +17 -56
  521. package/dist/server/comments/actions.mjs +65 -59
  522. package/dist/server/comments/agent-actions.d.mts +73 -0
  523. package/dist/server/comments/agent-actions.mjs +76 -0
  524. package/dist/server/comments/close-tools.d.mts +31 -0
  525. package/dist/server/comments/close-tools.mjs +124 -0
  526. package/dist/server/comments/files.d.mts +53 -0
  527. package/dist/server/comments/files.mjs +1 -0
  528. package/dist/server/comments/hand-out.d.mts +42 -0
  529. package/dist/server/comments/hand-out.mjs +46 -0
  530. package/dist/server/comments/push.d.mts +26 -0
  531. package/dist/server/comments/push.mjs +238 -0
  532. package/dist/server/comments/routes.d.mts +12 -0
  533. package/dist/server/comments/routes.mjs +21 -11
  534. package/dist/server/comments/studio-files.d.mts +14 -0
  535. package/dist/server/comments/studio-files.mjs +80 -0
  536. package/dist/server/comments/tools.d.mts +35 -3
  537. package/dist/server/comments/tools.mjs +54 -147
  538. package/dist/server/comments/workflow.d.mts +13 -0
  539. package/dist/server/comments/workflow.mjs +15 -0
  540. package/dist/server/comments/workspace.d.mts +36 -0
  541. package/dist/server/comments/workspace.mjs +84 -0
  542. package/dist/server/component-catalogue.mjs +19 -21
  543. package/dist/server/config-settings.d.mts +1 -1
  544. package/dist/server/config-settings.mjs +3 -3
  545. package/dist/server/content-type.mjs +1 -1
  546. package/dist/server/dependency-clash.d.mts +6 -2
  547. package/dist/server/dependency-clash.mjs +23 -17
  548. package/dist/server/desktop.d.mts +20 -0
  549. package/dist/server/desktop.mjs +56 -0
  550. package/dist/server/dev-server.mjs +19 -37
  551. package/dist/server/export/build.mjs +3 -3
  552. package/dist/server/export/page.mjs +4 -4
  553. package/dist/server/export/plugin.d.mts +4 -2
  554. package/dist/server/export/plugin.mjs +4 -1
  555. package/dist/server/features.d.mts +0 -5
  556. package/dist/server/features.mjs +1 -6
  557. package/dist/server/file-errors.mjs +4 -4
  558. package/dist/server/file-lock.mjs +14 -9
  559. package/dist/server/git-host.mjs +6 -9
  560. package/dist/server/git-paused.mjs +4 -1
  561. package/dist/server/git-settings.d.mts +1 -1
  562. package/dist/server/git-settings.mjs +5 -5
  563. package/dist/server/git-sync.d.mts +8 -0
  564. package/dist/server/git-sync.mjs +77 -19
  565. package/dist/server/git.d.mts +0 -5
  566. package/dist/server/git.mjs +53 -48
  567. package/dist/server/instructions.mjs +9 -8
  568. package/dist/server/live-mirror.mjs +20 -13
  569. package/dist/server/live.mjs +8 -6
  570. package/dist/server/machine-update.mjs +32 -32
  571. package/dist/server/me.mjs +4 -2
  572. package/dist/server/merge-check.d.mts +14 -0
  573. package/dist/server/merge-check.mjs +80 -0
  574. package/dist/server/next.mjs +9 -6
  575. package/dist/server/notices.d.mts +6 -6
  576. package/dist/server/notices.mjs +11 -9
  577. package/dist/server/open-page.mjs +11 -10
  578. package/dist/server/outcome.d.mts +7 -8
  579. package/dist/server/own-copies.mjs +21 -11
  580. package/dist/server/people.mjs +4 -4
  581. package/dist/server/pictures.mjs +14 -8
  582. package/dist/server/port.mjs +5 -9
  583. package/dist/server/prebundle.mjs +16 -13
  584. package/dist/server/preferences.mjs +1 -1
  585. package/dist/server/presence.d.mts +3 -3
  586. package/dist/server/presence.mjs +2 -4
  587. package/dist/server/project-public.mjs +1 -1
  588. package/dist/server/prototype-brief.d.mts +36 -3
  589. package/dist/server/prototype-brief.mjs +6 -6
  590. package/dist/server/push-notice.d.mts +1 -1
  591. package/dist/server/quiet-run.mjs +1 -1
  592. package/dist/server/registry.mjs +9 -8
  593. package/dist/server/requests.d.mts +9 -20
  594. package/dist/server/requests.mjs +136 -130
  595. package/dist/server/response-budget.d.mts +16 -7
  596. package/dist/server/response-budget.mjs +6 -5
  597. package/dist/server/restart.mjs +3 -1
  598. package/dist/server/roster.d.mts +2 -2
  599. package/dist/server/roster.mjs +7 -8
  600. package/dist/server/source-stamp.d.mts +5 -4
  601. package/dist/server/source-stamp.mjs +43 -15
  602. package/dist/server/spec-decisions.mjs +2 -2
  603. package/dist/server/state.d.mts +6 -6
  604. package/dist/server/state.mjs +3 -5
  605. package/dist/server/studio-server.d.mts +92 -0
  606. package/dist/server/studio-server.mjs +77 -0
  607. package/dist/server/sync-install.mjs +2 -2
  608. package/dist/server/thread-forms.d.mts +7 -8
  609. package/dist/server/thread-forms.mjs +13 -14
  610. package/dist/server/thread-place.d.mts +2 -2
  611. package/dist/server/thread-place.mjs +28 -18
  612. package/dist/server/thread-source.d.mts +35 -5
  613. package/dist/server/thread-source.mjs +43 -40
  614. package/dist/server/tools/context.d.mts +53 -35
  615. package/dist/server/tools/context.mjs +17 -32
  616. package/dist/server/tools/describe.d.mts +3 -5
  617. package/dist/server/tools/describe.mjs +4 -24
  618. package/dist/server/tools/export.d.mts +14 -2
  619. package/dist/server/tools/export.mjs +30 -25
  620. package/dist/server/tools/feedback.d.mts +20 -4
  621. package/dist/server/tools/feedback.mjs +70 -62
  622. package/dist/server/tools/place-frame.d.mts +15 -3
  623. package/dist/server/tools/place-frame.mjs +70 -63
  624. package/dist/server/tools/prototype-name.mjs +3 -4
  625. package/dist/server/tools/reading.d.mts +4 -4
  626. package/dist/server/tools/reading.mjs +137 -114
  627. package/dist/server/tools/show.d.mts +9 -4
  628. package/dist/server/tools/show.mjs +39 -34
  629. package/dist/server/tools/snapshot.d.mts +19 -5
  630. package/dist/server/tools/snapshot.mjs +64 -59
  631. package/dist/server/tools/studio-context.d.mts +8 -0
  632. package/dist/server/tools/studio-context.mjs +44 -0
  633. package/dist/server/tools/thread-list.d.mts +19 -4
  634. package/dist/server/tools/thread-list.mjs +59 -61
  635. package/dist/server/tools/watch.d.mts +11 -4
  636. package/dist/server/tools/watch.mjs +165 -115
  637. package/dist/server/unresolved-imports.mjs +4 -1
  638. package/dist/server/update-branch.mjs +2 -2
  639. package/dist/server/update-studio.d.mts +3 -1
  640. package/dist/server/update-studio.mjs +30 -19
  641. package/dist/server/updates.mjs +10 -10
  642. package/dist/server/vite.mjs +29 -24
  643. package/dist/server/web-app.mjs +17 -30
  644. package/dist/server/welcome.mjs +4 -2
  645. package/dist/server/work-groups.d.mts +13 -2
  646. package/dist/server/work-groups.mjs +58 -23
  647. package/dist/server/workspace-settings.d.mts +9 -5
  648. package/dist/server/workspace-settings.mjs +40 -39
  649. package/dist/server/zip.mjs +1 -1
  650. package/dist/setup/apply.d.mts +6 -1
  651. package/dist/setup/apply.mjs +26 -23
  652. package/dist/setup/cancelled.d.mts +6 -0
  653. package/dist/setup/cancelled.mjs +10 -0
  654. package/dist/setup/commit-lint.d.mts +6 -4
  655. package/dist/setup/commit-lint.mjs +23 -27
  656. package/dist/setup/components.mjs +3 -3
  657. package/dist/setup/config-source.d.mts +16 -5
  658. package/dist/setup/config-source.mjs +36 -27
  659. package/dist/setup/create.mjs +64 -52
  660. package/dist/setup/design-md-setup.d.mts +6 -4
  661. package/dist/setup/design-md-setup.mjs +14 -12
  662. package/dist/setup/design-md.mjs +50 -52
  663. package/dist/setup/design-system-checks.mjs +8 -8
  664. package/dist/setup/detect/workspace.d.mts +3 -17
  665. package/dist/setup/detect/workspace.mjs +23 -126
  666. package/dist/setup/detect.mjs +24 -18
  667. package/dist/setup/doctor.d.mts +1 -1
  668. package/dist/setup/doctor.mjs +15 -14
  669. package/dist/setup/existing-setup.mjs +20 -15
  670. package/dist/setup/git-checks.mjs +5 -5
  671. package/dist/setup/hash.d.mts +4 -0
  672. package/dist/setup/hash.mjs +6 -0
  673. package/dist/setup/hints.mjs +5 -4
  674. package/dist/setup/host-format.mjs +2 -6
  675. package/dist/setup/json.d.mts +12 -0
  676. package/dist/setup/json.mjs +9 -0
  677. package/dist/setup/migrate/agent-files.mjs +8 -7
  678. package/dist/setup/migrate/config-name.mjs +1 -1
  679. package/dist/setup/migrate/design-system.mjs +37 -34
  680. package/dist/setup/migrate/dex-folder.d.mts +1 -1
  681. package/dist/setup/migrate/dex-folder.mjs +27 -23
  682. package/dist/setup/migrate/explorations.mjs +7 -5
  683. package/dist/setup/migrate/files-folder.mjs +35 -20
  684. package/dist/setup/migrate/frame-notes.d.mts +20 -0
  685. package/dist/setup/migrate/frame-notes.mjs +126 -0
  686. package/dist/setup/migrate/frame-uids.d.mts +24 -0
  687. package/dist/setup/migrate/frame-uids.mjs +144 -0
  688. package/dist/setup/migrate/guides.mjs +1 -1
  689. package/dist/setup/migrate/manifest-name.d.mts +23 -0
  690. package/dist/setup/migrate/manifest-name.mjs +93 -0
  691. package/dist/setup/migrate/migrations.mjs +12 -2
  692. package/dist/setup/migrate/people-folders.d.mts +3 -3
  693. package/dist/setup/migrate/people-folders.mjs +25 -36
  694. package/dist/setup/migrate/picks-file.d.mts +33 -0
  695. package/dist/setup/migrate/picks-file.mjs +172 -0
  696. package/dist/setup/migrate/project-files.mjs +10 -8
  697. package/dist/setup/migrate/row-titles.mjs +5 -2
  698. package/dist/setup/migrate/setup-files.mjs +18 -12
  699. package/dist/setup/migrate/studio-state.mjs +8 -6
  700. package/dist/setup/own-app.d.mts +2 -1
  701. package/dist/setup/own-app.mjs +17 -15
  702. package/dist/setup/placement.mjs +20 -18
  703. package/dist/setup/plan.d.mts +5 -3
  704. package/dist/setup/plan.mjs +7 -6
  705. package/dist/setup/project.mjs +11 -8
  706. package/dist/setup/prompts.d.mts +1 -5
  707. package/dist/setup/prompts.mjs +54 -53
  708. package/dist/setup/provider.mjs +3 -2
  709. package/dist/setup/questions.d.mts +13 -7
  710. package/dist/setup/questions.mjs +2 -4
  711. package/dist/setup/starters.mjs +6 -3
  712. package/dist/setup/templates.d.mts +3 -3
  713. package/dist/setup/templates.mjs +18 -14
  714. package/dist/setup/workspace-setup.mjs +4 -5
  715. package/dist/setup/write.d.mts +10 -2
  716. package/dist/setup/write.mjs +17 -16
  717. package/dist/shared/block-merge.d.mts +5 -4
  718. package/dist/shared/block-merge.mjs +5 -5
  719. package/dist/shared/built-pictures.d.mts +13 -4
  720. package/dist/shared/built-pictures.mjs +16 -8
  721. package/dist/shared/canvas-core.d.mts +117 -57
  722. package/dist/shared/canvas-core.mjs +192 -79
  723. package/dist/shared/canvas-file.d.mts +15 -6
  724. package/dist/shared/canvas-merge.d.mts +28 -0
  725. package/dist/shared/canvas-merge.mjs +384 -0
  726. package/dist/shared/checks.d.mts +8 -0
  727. package/dist/shared/checks.mjs +9 -1
  728. package/dist/shared/code-anchor.d.mts +16 -0
  729. package/dist/shared/code-anchor.mjs +33 -0
  730. package/dist/shared/commands-core.d.mts +25 -0
  731. package/dist/shared/commands-core.mjs +31 -7
  732. package/dist/shared/comments/routes.d.mts +4 -2
  733. package/dist/shared/comments/routes.mjs +6 -4
  734. package/dist/shared/comments/state.d.mts +71 -0
  735. package/dist/shared/comments/state.mjs +66 -0
  736. package/dist/shared/contributors-merge.mjs +4 -4
  737. package/dist/shared/devices.d.mts +5 -4
  738. package/dist/shared/devices.mjs +1 -1
  739. package/dist/shared/export-core.d.mts +0 -1
  740. package/dist/shared/export-core.mjs +20 -21
  741. package/dist/shared/feedback.mjs +5 -7
  742. package/dist/shared/file-errors.mjs +3 -3
  743. package/dist/shared/file-names.d.mts +6 -0
  744. package/dist/shared/file-names.mjs +521 -0
  745. package/dist/shared/fix-prompt.mjs +1 -1
  746. package/dist/shared/front-matter.mjs +8 -9
  747. package/dist/shared/generated-sections.mjs +7 -7
  748. package/dist/shared/git-core.mjs +11 -11
  749. package/dist/shared/json-style.mjs +5 -4
  750. package/dist/shared/live-core.d.mts +10 -5
  751. package/dist/shared/live-core.mjs +5 -4
  752. package/dist/shared/live-presence.mjs +12 -9
  753. package/dist/shared/markup-prompt.d.mts +7 -3
  754. package/dist/shared/markup-prompt.mjs +9 -5
  755. package/dist/shared/open-page-core.mjs +6 -5
  756. package/dist/shared/page-messages.d.mts +16 -4
  757. package/dist/shared/page-messages.mjs +26 -14
  758. package/dist/shared/page-review.mjs +8 -10
  759. package/dist/shared/people-core.d.mts +37 -29
  760. package/dist/shared/people-core.mjs +49 -24
  761. package/dist/shared/{annotations-core.d.mts → picks-core.d.mts} +24 -29
  762. package/dist/shared/{annotations-core.mjs → picks-core.mjs} +48 -62
  763. package/dist/shared/prototypes-core.d.mts +70 -15
  764. package/dist/shared/prototypes-core.mjs +184 -100
  765. package/dist/shared/references-core.mjs +5 -6
  766. package/dist/shared/removed-views-core.mjs +6 -6
  767. package/dist/shared/review-file.mjs +3 -3
  768. package/dist/shared/server-page.mjs +4 -4
  769. package/dist/shared/signup.mjs +3 -2
  770. package/dist/shared/sketch-core.mjs +7 -7
  771. package/dist/shared/snapshot-clipboard.d.mts +5 -4
  772. package/dist/shared/snapshot-clipboard.mjs +2 -2
  773. package/dist/shared/snapshot-images.d.mts +10 -1
  774. package/dist/shared/snapshot-images.mjs +62 -14
  775. package/dist/shared/spec-quote.mjs +4 -4
  776. package/dist/shared/studio-events.d.mts +5 -36
  777. package/dist/shared/studio-events.mjs +5 -5
  778. package/dist/shared/studio-files.d.mts +3 -3
  779. package/dist/shared/studio-files.mjs +7 -7
  780. package/dist/shared/studio-routes.d.mts +28 -30
  781. package/dist/shared/studio-routes.mjs +6 -1
  782. package/dist/shared/threads-core.d.mts +346 -32
  783. package/dist/shared/threads-core.mjs +223 -76
  784. package/dist/shared/unknown-fields.d.mts +10 -0
  785. package/dist/shared/unknown-fields.mjs +74 -0
  786. package/dist/shared/unzip.d.mts +4 -2
  787. package/dist/shared/unzip.mjs +9 -7
  788. package/dist/shared/word-diff.mjs +6 -6
  789. package/dist/shared/xray.d.mts +4 -0
  790. package/dist/shared/xray.mjs +11 -0
  791. package/extension/dist/background.js +1 -1
  792. package/extension/dist/manifest.json +2 -3
  793. package/extension/dist/picker.js +114 -104
  794. package/package.json +82 -60
  795. package/schema/canvas.json +390 -0
  796. package/schema/comment-event.json +441 -0
  797. package/schema/contributors.json +30 -0
  798. package/schema/defs.json +66 -0
  799. package/schema/file.json +59 -0
  800. package/schema/picks.json +45 -0
  801. package/src/cli/banner.ts +46 -5
  802. package/src/cli/command.ts +25 -12
  803. package/src/cli/commands/agents/add.ts +4 -1
  804. package/src/cli/commands/agents.ts +1 -0
  805. package/src/cli/commands/app.ts +33 -24
  806. package/src/cli/commands/build.ts +4 -0
  807. package/src/cli/commands/claude.ts +20 -10
  808. package/src/cli/commands/cloud/link.ts +2 -0
  809. package/src/cli/commands/cloud/live.ts +2 -0
  810. package/src/cli/commands/cloud/login.ts +1 -0
  811. package/src/cli/commands/cloud/publish.ts +23 -9
  812. package/src/cli/commands/cloud/push.ts +2 -0
  813. package/src/cli/commands/cloud/status.ts +2 -0
  814. package/src/cli/commands/cloud/unlink.ts +2 -0
  815. package/src/cli/commands/cloud.ts +1 -0
  816. package/src/cli/commands/components.ts +1 -0
  817. package/src/cli/commands/create.ts +3 -0
  818. package/src/cli/commands/dev.ts +148 -32
  819. package/src/cli/commands/doctor.ts +9 -1
  820. package/src/cli/commands/export.ts +10 -1
  821. package/src/cli/commands/extension.ts +1 -0
  822. package/src/cli/commands/hook.ts +17 -1
  823. package/src/cli/commands/init.ts +3 -0
  824. package/src/cli/commands/mcp.ts +23 -4
  825. package/src/cli/commands/merge-canvas.ts +134 -0
  826. package/src/cli/commands/merge-contributors.ts +10 -4
  827. package/src/cli/commands/merge-spec.ts +7 -1
  828. package/src/cli/commands/preview.ts +2 -0
  829. package/src/cli/commands/stop.ts +6 -0
  830. package/src/cli/commands/upgrade.ts +11 -0
  831. package/src/cli/commands/work/check.ts +2 -0
  832. package/src/cli/commands/work/contributor.ts +3 -1
  833. package/src/cli/commands/work/new.ts +3 -1
  834. package/src/cli/commands/work/presence.ts +3 -1
  835. package/src/cli/commands/work/scope.ts +3 -1
  836. package/src/cli/commands/work/snapshot.ts +3 -1
  837. package/src/cli/commands/work/thread.ts +3 -1
  838. package/src/cli/commands/work/threads.ts +3 -1
  839. package/src/cli/commands/work/whoami.ts +3 -1
  840. package/src/cli/help.ts +32 -10
  841. package/src/cli/main.ts +31 -3
  842. package/src/cli/mcp-relay.ts +150 -49
  843. package/src/cli/recovery-server.ts +23 -9
  844. package/src/cli/strict-flags.ts +41 -6
  845. package/src/cli/supervise.ts +119 -37
  846. package/src/cli/ui.ts +55 -26
  847. package/src/config/design-system.ts +65 -18
  848. package/src/config/index.ts +1 -0
  849. package/src/config/load.ts +37 -6
  850. package/src/config/project-files.ts +180 -43
  851. package/src/config/renamed.ts +15 -20
  852. package/src/config/schema.ts +8 -0
  853. package/src/content/biome.ts +31 -17
  854. package/src/content/capture.ts +200 -56
  855. package/src/content/commands.ts +85 -27
  856. package/src/content/comments-log.ts +183 -34
  857. package/src/content/component-props.ts +134 -23
  858. package/src/content/content.ts +707 -217
  859. package/src/content/devices.ts +12 -3
  860. package/src/content/element-words.ts +33 -8
  861. package/src/content/file-turns.ts +12 -4
  862. package/src/content/first-run.ts +10 -10
  863. package/src/content/flow-specs.ts +88 -40
  864. package/src/content/format-check.ts +599 -0
  865. package/src/content/hosted-person.ts +31 -7
  866. package/src/content/insert-edit.ts +52 -17
  867. package/src/content/jsx-source.ts +17 -6
  868. package/src/content/last-edited.ts +15 -4
  869. package/src/content/layout.ts +131 -9
  870. package/src/content/merge-rules.ts +71 -37
  871. package/src/content/prop-edit.ts +60 -4
  872. package/src/content/prototype-checks.ts +52 -18
  873. package/src/content/prototype-summary.ts +37 -20
  874. package/src/content/prototypes.ts +138 -52
  875. package/src/content/review-import.ts +8 -1
  876. package/src/content/review-pages.ts +63 -8
  877. package/src/content/screenshot.ts +82 -24
  878. package/src/content/snapshot-client.ts +25 -3
  879. package/src/content/store.ts +177 -55
  880. package/src/content/sub-agents.ts +107 -0
  881. package/src/content/text-edit.ts +41 -5
  882. package/src/content/text-replace.ts +130 -32
  883. package/src/content/thread-module.ts +84 -12
  884. package/src/content/threads.ts +146 -16
  885. package/src/content/trash.ts +100 -40
  886. package/src/paste/figma/appearance.ts +39 -6
  887. package/src/paste/figma/captures.ts +21 -6
  888. package/src/paste/figma/decode.ts +82 -15
  889. package/src/paste/figma/document.ts +73 -5
  890. package/src/paste/figma/layout.ts +44 -5
  891. package/src/paste/figma/paint.ts +52 -8
  892. package/src/paste/figma/render.ts +18 -3
  893. package/src/paste/figma/styles.ts +20 -5
  894. package/src/paste/figma/text.ts +97 -29
  895. package/src/paste/figma/vector.ts +74 -12
  896. package/src/paste/fonts.ts +30 -9
  897. package/src/paste/paste.ts +45 -15
  898. package/src/paths.ts +66 -87
  899. package/src/server/agent-session.ts +451 -20
  900. package/src/server/agent-tools.ts +52 -0
  901. package/src/server/agents-place.ts +22 -0
  902. package/src/server/allowed-request.ts +7 -1
  903. package/src/server/avatars.ts +18 -6
  904. package/src/server/brief.ts +75 -16
  905. package/src/server/briefing.ts +19 -9
  906. package/src/server/build-pictures.ts +57 -9
  907. package/src/server/build-settings.ts +10 -4
  908. package/src/server/canvas-presence.ts +31 -2
  909. package/src/server/changelog.ts +15 -3
  910. package/src/server/claimed-presence.ts +32 -8
  911. package/src/server/close-check.ts +56 -19
  912. package/src/server/cloud.ts +61 -12
  913. package/src/server/command-settings.ts +30 -12
  914. package/src/server/comments/actions.ts +137 -133
  915. package/src/server/comments/agent-actions.ts +178 -0
  916. package/src/server/comments/close-tools.ts +240 -0
  917. package/src/server/comments/files.ts +66 -0
  918. package/src/server/comments/hand-out.ts +105 -0
  919. package/src/server/comments/push.ts +503 -0
  920. package/src/server/comments/routes.ts +39 -9
  921. package/src/server/comments/studio-files.ts +128 -0
  922. package/src/server/comments/tools.ts +103 -301
  923. package/src/server/comments/workflow.ts +18 -0
  924. package/src/server/comments/workspace.ts +123 -0
  925. package/src/server/component-catalogue.ts +58 -20
  926. package/src/server/config-settings.ts +11 -3
  927. package/src/server/content-type.ts +3 -1
  928. package/src/server/dependency-clash.ts +86 -26
  929. package/src/server/desktop.ts +92 -0
  930. package/src/server/dev-server.ts +65 -61
  931. package/src/server/export/build.ts +37 -3
  932. package/src/server/export/page.ts +16 -7
  933. package/src/server/export/plugin.ts +28 -9
  934. package/src/server/export/run.ts +12 -0
  935. package/src/server/export/save.ts +5 -0
  936. package/src/server/features.ts +4 -6
  937. package/src/server/file-errors.ts +35 -5
  938. package/src/server/file-lock.ts +53 -19
  939. package/src/server/git-asks.ts +13 -4
  940. package/src/server/git-host.ts +51 -12
  941. package/src/server/git-paused.ts +39 -3
  942. package/src/server/git-settings.ts +15 -5
  943. package/src/server/git-sync.ts +229 -36
  944. package/src/server/git.ts +236 -116
  945. package/src/server/hosted.ts +11 -0
  946. package/src/server/instructions.ts +32 -7
  947. package/src/server/live-mirror.ts +109 -10
  948. package/src/server/live.ts +85 -16
  949. package/src/server/machine-update.ts +167 -35
  950. package/src/server/me.ts +8 -3
  951. package/src/server/merge-check.ts +125 -0
  952. package/src/server/next.ts +30 -8
  953. package/src/server/notices.ts +77 -15
  954. package/src/server/open-page.ts +44 -19
  955. package/src/server/outcome.ts +8 -7
  956. package/src/server/own-copies.ts +104 -13
  957. package/src/server/people.ts +22 -7
  958. package/src/server/personal-folder.ts +3 -0
  959. package/src/server/pictures.ts +76 -8
  960. package/src/server/port.ts +38 -6
  961. package/src/server/prebundle.ts +53 -18
  962. package/src/server/preferences.ts +6 -1
  963. package/src/server/presence.ts +17 -6
  964. package/src/server/problems.ts +2 -0
  965. package/src/server/project-id.ts +2 -0
  966. package/src/server/project-public.ts +12 -1
  967. package/src/server/prototype-brief.ts +36 -17
  968. package/src/server/push-notice.ts +11 -1
  969. package/src/server/quiet-run.ts +10 -3
  970. package/src/server/registry.ts +34 -7
  971. package/src/server/requests.ts +543 -252
  972. package/src/server/response-budget.ts +29 -6
  973. package/src/server/restart.ts +36 -3
  974. package/src/server/roster.ts +50 -8
  975. package/src/server/saved.ts +15 -5
  976. package/src/server/source-stamp.ts +116 -12
  977. package/src/server/spec-decisions.ts +11 -2
  978. package/src/server/state.ts +21 -9
  979. package/src/server/stop-studio.ts +9 -1
  980. package/src/server/studio-for.ts +38 -9
  981. package/src/server/studio-server.ts +233 -0
  982. package/src/server/sync-install.ts +8 -3
  983. package/src/server/thread-forms.ts +84 -27
  984. package/src/server/thread-place.ts +61 -19
  985. package/src/server/thread-source.ts +114 -50
  986. package/src/server/tools/context.ts +95 -112
  987. package/src/server/tools/describe.ts +10 -35
  988. package/src/server/tools/export.ts +13 -11
  989. package/src/server/tools/feedback.ts +47 -22
  990. package/src/server/tools/place-frame.ts +44 -15
  991. package/src/server/tools/prototype-name.ts +11 -7
  992. package/src/server/tools/reading.ts +215 -177
  993. package/src/server/tools/result.ts +3 -0
  994. package/src/server/tools/show.ts +35 -12
  995. package/src/server/tools/snapshot.ts +24 -12
  996. package/src/server/tools/studio-context.ts +72 -0
  997. package/src/server/tools/thread-list.ts +58 -43
  998. package/src/server/tools/watch.ts +230 -81
  999. package/src/server/unresolved-imports.ts +18 -3
  1000. package/src/server/update-branch.ts +29 -4
  1001. package/src/server/update-studio.ts +54 -20
  1002. package/src/server/updates.ts +55 -9
  1003. package/src/server/vite.ts +154 -29
  1004. package/src/server/web-app.ts +27 -46
  1005. package/src/server/welcome.ts +8 -3
  1006. package/src/server/work-groups.ts +150 -34
  1007. package/src/server/workspace-settings.ts +133 -45
  1008. package/src/server/zip.ts +21 -3
  1009. package/src/setup/apply.ts +132 -40
  1010. package/src/setup/cancelled.ts +7 -0
  1011. package/src/setup/commit-lint.ts +104 -28
  1012. package/src/setup/components.ts +18 -3
  1013. package/src/setup/config-choices.ts +7 -0
  1014. package/src/setup/config-source.ts +226 -61
  1015. package/src/setup/create.ts +281 -64
  1016. package/src/setup/design-md-setup.ts +48 -11
  1017. package/src/setup/design-md.ts +276 -80
  1018. package/src/setup/design-system-checks.ts +70 -12
  1019. package/src/setup/design-system-guide.ts +7 -0
  1020. package/src/setup/detect/workspace.ts +219 -192
  1021. package/src/setup/detect.ts +95 -26
  1022. package/src/setup/doctor.ts +86 -22
  1023. package/src/setup/existing-setup.ts +114 -22
  1024. package/src/setup/git-checks.ts +60 -7
  1025. package/src/setup/hash.ts +5 -0
  1026. package/src/setup/hints.ts +42 -4
  1027. package/src/setup/host-format.ts +31 -7
  1028. package/src/setup/json.ts +23 -0
  1029. package/src/setup/migrate/agent-files.ts +45 -9
  1030. package/src/setup/migrate/config-name.ts +13 -1
  1031. package/src/setup/migrate/design-system.ts +198 -50
  1032. package/src/setup/migrate/dex-folder.ts +145 -30
  1033. package/src/setup/migrate/explorations.ts +7 -3
  1034. package/src/setup/migrate/files-folder.ts +145 -43
  1035. package/src/setup/migrate/frame-notes.ts +253 -0
  1036. package/src/setup/migrate/frame-uids.ts +274 -0
  1037. package/src/setup/migrate/guides.ts +18 -15
  1038. package/src/setup/migrate/manifest-name.ts +183 -0
  1039. package/src/setup/migrate/migrations.ts +28 -6
  1040. package/src/setup/migrate/people-folders.ts +76 -48
  1041. package/src/setup/migrate/picks-file.ts +297 -0
  1042. package/src/setup/migrate/project-files.ts +8 -3
  1043. package/src/setup/migrate/row-titles.ts +8 -4
  1044. package/src/setup/migrate/setup-files.ts +41 -16
  1045. package/src/setup/migrate/studio-state.ts +26 -5
  1046. package/src/setup/own-app.ts +74 -20
  1047. package/src/setup/placement.ts +80 -21
  1048. package/src/setup/plan.ts +96 -17
  1049. package/src/setup/project.ts +75 -11
  1050. package/src/setup/prompts.ts +201 -54
  1051. package/src/setup/provider.ts +20 -2
  1052. package/src/setup/questions.ts +71 -23
  1053. package/src/setup/starters.ts +55 -14
  1054. package/src/setup/templates.ts +66 -20
  1055. package/src/setup/workspace-setup.ts +50 -5
  1056. package/src/setup/write.ts +63 -25
  1057. package/src/shared/agent-prompts.ts +1 -1
  1058. package/src/shared/block-merge.ts +65 -8
  1059. package/src/shared/built-pictures.ts +38 -9
  1060. package/src/shared/canvas-core.ts +596 -153
  1061. package/src/shared/canvas-file.ts +15 -6
  1062. package/src/shared/canvas-merge.ts +784 -0
  1063. package/src/shared/checks.ts +18 -0
  1064. package/src/shared/code-anchor.ts +73 -0
  1065. package/src/shared/commands-core.ts +62 -8
  1066. package/src/shared/comments/routes.ts +7 -5
  1067. package/src/shared/comments/state.ts +146 -0
  1068. package/src/shared/contributors-merge.ts +26 -12
  1069. package/src/shared/devices.ts +63 -16
  1070. package/src/shared/export-core.ts +51 -29
  1071. package/src/shared/feedback.ts +56 -8
  1072. package/src/shared/file-errors.ts +4 -4
  1073. package/src/shared/file-names.ts +528 -0
  1074. package/src/shared/fix-prompt.ts +3 -1
  1075. package/src/shared/frame-grids.ts +33 -8
  1076. package/src/shared/front-matter.ts +24 -7
  1077. package/src/shared/generated-sections.ts +30 -7
  1078. package/src/shared/git-core.ts +40 -14
  1079. package/src/shared/json-style.ts +24 -6
  1080. package/src/shared/listing.ts +1 -0
  1081. package/src/shared/live-core.ts +55 -12
  1082. package/src/shared/live-presence.ts +66 -15
  1083. package/src/shared/markup-prompt.ts +9 -4
  1084. package/src/shared/open-page-core.ts +15 -8
  1085. package/src/shared/page-messages.ts +57 -17
  1086. package/src/shared/page-review.ts +60 -35
  1087. package/src/shared/paste-arrangement.ts +4 -0
  1088. package/src/shared/people-core.ts +251 -59
  1089. package/src/shared/{annotations-core.ts → picks-core.ts} +125 -96
  1090. package/src/shared/prototypes-core.ts +323 -128
  1091. package/src/shared/references-core.ts +20 -8
  1092. package/src/shared/removed-views-core.ts +30 -7
  1093. package/src/shared/review-file.ts +38 -19
  1094. package/src/shared/server-page.ts +13 -5
  1095. package/src/shared/signup.ts +12 -2
  1096. package/src/shared/sketch-core.ts +55 -7
  1097. package/src/shared/snapshot-clipboard.ts +20 -3
  1098. package/src/shared/snapshot-images.ts +114 -14
  1099. package/src/shared/spec-quote.ts +36 -5
  1100. package/src/shared/studio-events.ts +24 -37
  1101. package/src/shared/studio-files.ts +28 -10
  1102. package/src/shared/studio-routes.ts +27 -31
  1103. package/src/shared/threads-core.ts +597 -164
  1104. package/src/shared/unknown-fields.ts +118 -0
  1105. package/src/shared/unzip.ts +22 -8
  1106. package/src/shared/update-core.ts +3 -0
  1107. package/src/shared/word-diff.ts +31 -6
  1108. package/src/shared/xray.ts +14 -0
  1109. package/templates/agents/dex-checker.md +25 -0
  1110. package/templates/agents/dex-riffer.md +16 -0
  1111. package/templates/agents/dex-worker.md +23 -0
  1112. package/templates/feedback-workflow.md +1 -1
  1113. package/templates/methods/handoff.md +1 -1
  1114. package/templates/methods/review.md +7 -3
  1115. package/templates/rules/always.md +1 -1
  1116. package/templates/rules/canvas-frames.md +9 -2
  1117. package/templates/rules/canvas.md +19 -11
  1118. package/templates/rules/prototypes.md +6 -5
  1119. package/templates/rules/scope.md +2 -2
  1120. package/templates/skills/boil/SKILL.md +40 -0
  1121. package/templates/skills/comprehend/SKILL.md +1 -0
  1122. package/templates/skills/distill/SKILL.md +1 -0
  1123. package/templates/skills/export-prototype/SKILL.md +1 -0
  1124. package/templates/skills/restrain/SKILL.md +76 -0
  1125. package/templates/skills/riff/SKILL.md +2 -0
  1126. package/templates/skills/riff-deep/SKILL.md +2 -0
  1127. package/templates/skills/riff-max/SKILL.md +2 -0
  1128. package/templates/skills/riff-state/SKILL.md +2 -0
  1129. package/templates/skills/riff-up/SKILL.md +2 -0
  1130. package/templates/skills/riff-wide/SKILL.md +2 -0
  1131. package/templates/starter-prototype/welcome.tsx +8 -4
  1132. package/templates/starters/standalone/package.json +1 -1
  1133. package/templates/starters/turborepo/apps/web/package.json +1 -1
  1134. package/templates/starters/turborepo/apps/web/src/app.tsx +3 -3
  1135. package/templates/starters/turborepo/apps/web/src/main.tsx +4 -1
  1136. package/templates/starters/turborepo/apps/web/vite.config.ts +2 -1
  1137. package/templates/starters/turborepo/package.json +2 -2
  1138. package/templates/starters/turborepo/packages/ui/package.json +3 -3
  1139. package/templates/starters/vite/package.json +1 -1
  1140. package/templates/starters/vite/src/app.tsx +3 -2
  1141. package/templates/starters/vite/src/components/ui/button.tsx +1 -1
  1142. package/templates/starters/vite/src/index.css +1 -1
  1143. package/templates/starters/vite/src/main.tsx +4 -1
  1144. package/templates/starters/vite/vite.config.ts +2 -1
  1145. package/app/canvas/pass-wheel.ts +0 -48
  1146. package/dist/config/package-manager.d.mts +0 -15
  1147. package/dist/server/agent-env.d.mts +0 -16
  1148. package/dist/server/agents.d.mts +0 -143
  1149. package/dist/server/agents.mjs +0 -786
  1150. package/dist/server/channel.d.mts +0 -239
  1151. package/dist/server/channel.mjs +0 -687
  1152. package/dist/server/mcp-handover.d.mts +0 -37
  1153. package/dist/server/mcp.d.mts +0 -61
  1154. package/dist/server/mcp.mjs +0 -157
  1155. package/dist/server/spec-suggestions.d.mts +0 -21
  1156. package/dist/server/spec-suggestions.mjs +0 -59
  1157. package/dist/setup/desktop-app-script.d.mts +0 -28
  1158. package/dist/setup/desktop-app-script.mjs +0 -775
  1159. package/dist/setup/desktop-app-start.d.mts +0 -65
  1160. package/dist/setup/desktop-app.d.mts +0 -174
  1161. package/dist/setup/desktop-app.mjs +0 -551
  1162. package/dist/shared/element-steps.d.mts +0 -38
  1163. package/dist/shared/element-steps.mjs +0 -40
  1164. package/extension/dist/feedback.html +0 -19
  1165. package/extension/dist/feedback.js +0 -519
  1166. package/src/config/package-manager.ts +0 -93
  1167. package/src/server/agent-env.ts +0 -70
  1168. package/src/server/agents.ts +0 -1251
  1169. package/src/server/channel.ts +0 -1161
  1170. package/src/server/mcp-handover.ts +0 -147
  1171. package/src/server/mcp.ts +0 -295
  1172. package/src/server/spec-suggestions.ts +0 -87
  1173. package/src/setup/desktop-app-script.ts +0 -815
  1174. package/src/setup/desktop-app-start.ts +0 -220
  1175. package/src/setup/desktop-app.ts +0 -849
  1176. package/src/shared/element-steps.ts +0 -99
@@ -2,7 +2,11 @@
2
2
  // snapshots. Every function takes the studio's content root, so they work in
3
3
  // any project. The CLI (cli/main.ts) wires them to `dex <command>`.
4
4
 
5
- import { execFile, execFileSync } from "node:child_process";
5
+ import {
6
+ type ExecFileException,
7
+ execFile,
8
+ execFileSync,
9
+ } from "node:child_process";
6
10
  import { createHash } from "node:crypto";
7
11
  import { existsSync } from "node:fs";
8
12
  import {
@@ -16,19 +20,14 @@ import {
16
20
  } from "node:fs/promises";
17
21
  import { homedir } from "node:os";
18
22
  import { join, relative, resolve, sep } from "node:path";
23
+ import { promisify } from "node:util";
24
+
25
+ import { dexRunner, packageManager } from "@dexhq/harness/project";
26
+
19
27
  import type { ResolvedDesignSystem } from "../config/design-system.ts";
20
- import { dexRunner, packageManager } from "../config/package-manager.ts";
21
- import { features } from "../server/features.ts";
22
28
  import { openPresence } from "../server/presence.ts";
23
29
  import { prepareState, studioState } from "../server/state.ts";
24
30
  import { notRunning, studioFor } from "../server/studio-for.ts";
25
- import {
26
- type Authored,
27
- checkFrameAnchor,
28
- readAnnotations,
29
- withAnnotation,
30
- withoutAnnotation,
31
- } from "../shared/annotations-core.ts";
32
31
  import { TWO_VERSIONS_LEAD } from "../shared/block-merge.ts";
33
32
  import {
34
33
  appendOwnFrame,
@@ -38,8 +37,8 @@ import {
38
37
  canvasProblems,
39
38
  type PageSize,
40
39
  placeViewInCell,
41
- rowTitleProblems,
42
- shapeProblems,
40
+ canvasFormProblems,
41
+ stackPiles,
43
42
  uniqueId,
44
43
  type Viewport,
45
44
  viewOf,
@@ -47,7 +46,7 @@ import {
47
46
  import type { Canvas, Section, ViewFrame } from "../shared/canvas-file.ts";
48
47
  import { isOneOf, isRecord, isText } from "../shared/checks.ts";
49
48
  import { defaultDevice } from "../shared/devices.ts";
50
- import { formattedJson } from "../shared/json-style.ts";
49
+ import { jsonInLayout } from "../shared/json-style.ts";
51
50
  import { LARGE_CANVAS_BYTES } from "../shared/live-core.ts";
52
51
  import { targetForPath } from "../shared/live-presence.ts";
53
52
  import {
@@ -62,6 +61,13 @@ import {
62
61
  savedPart,
63
62
  withFrameUids,
64
63
  } from "../shared/people-core.ts";
64
+ import {
65
+ type Authored,
66
+ checkFrameAnchor,
67
+ readPicks,
68
+ withoutPick,
69
+ withPick,
70
+ } from "../shared/picks-core.ts";
65
71
  import type { PresenceTarget } from "../shared/presence-core.ts";
66
72
  import {
67
73
  framePage,
@@ -69,6 +75,7 @@ import {
69
75
  newFileId,
70
76
  PROTOTYPES_FOLDER,
71
77
  type PrototypeFiles,
78
+ placeOf,
72
79
  prototypeFiles,
73
80
  prototypePage,
74
81
  slugify,
@@ -86,10 +93,13 @@ import {
86
93
  describeThread,
87
94
  type ThreadChange,
88
95
  } from "../shared/threads-core.ts";
96
+ import { withUnknownFields } from "../shared/unknown-fields.ts";
89
97
  import { findBiome, formatText } from "./biome.ts";
90
98
  import { loadDevices } from "./devices.ts";
91
99
  import { inTurn, replaceFile } from "./file-turns.ts";
100
+ import { fileFolderFindings, studioFindings } from "./format-check.ts";
92
101
  import { hostedPerson, isHosted } from "./hosted-person.ts";
102
+ import { LAYOUT_FILE, type LayoutState, studioLayout } from "./layout.ts";
93
103
  import { checkPrototype, errorLines, findingLine } from "./prototype-checks.ts";
94
104
  import {
95
105
  clashingViews,
@@ -172,6 +182,8 @@ export interface CommandValues {
172
182
  }
173
183
 
174
184
  /** A path as people see it: relative to where they ran the command. */
185
+ const execFileAsync = promisify(execFile);
186
+
175
187
  const display = (path: string): string => relative(process.cwd(), path) || ".";
176
188
 
177
189
  const shownIn = (root: string, file: string): string =>
@@ -179,43 +191,78 @@ const shownIn = (root: string, file: string): string =>
179
191
 
180
192
  export const STATUSES = ["exploring", "in-review", "handed-off", "archived"];
181
193
 
182
- const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
194
+ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/u;
195
+
183
196
  // A GitHub username, and after it the `_company` that an enterprise's own
184
197
  // accounts end with (ana_acme): the only place GitHub puts an underscore.
185
198
  const GITHUB_LOGIN_RE =
186
- /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?:_[a-z\d]+)?$/i;
187
- const GITHUB_NOREPLY_RE = /^(?:\d+\+)?([^@]+)@users\.noreply\.github\.com$/i;
188
- const LEADING_AT_RE = /^@/;
199
+ /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?:_[a-z\d]+)?$/iu;
200
+
201
+ const GITHUB_NOREPLY_RE =
202
+ /^(?:\d+\+)?(?<login>[^@]+)@users\.noreply\.github\.com$/iu;
203
+
204
+ const LEADING_AT_RE = /^@/u;
189
205
  const GH_TIMEOUT_MS = 5000;
190
- const DOC_FILE_RE = /\.md$/;
206
+ const DOC_FILE_RE = /\.md$/u;
191
207
 
192
208
  /** A JSON file, as the shape the caller reads it into. */
193
209
  const readJson = async <T>(path: string): Promise<T> => {
194
210
  try {
195
211
  return JSON.parse(await readFile(path, "utf8"));
196
212
  } catch (error) {
197
- throw new Error(`${display(path)}: ${(error as Error).message}`);
213
+ // SAFETY: readFile and JSON.parse fail with Errors.
214
+ throw new Error(`${display(path)}: ${(error as Error).message}`, {
215
+ cause: error,
216
+ });
198
217
  }
199
218
  };
200
219
 
201
- const writeJson = (path: string, value: unknown): Promise<void> =>
202
- writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
220
+ /**
221
+ * One of the format's JSON files, laid out as jsonInLayout lays out every
222
+ * one Dex writes: as it was, or as Biome and Prettier would lay a new one.
223
+ */
224
+ // oxlint-disable-next-line anti-slop/no-unknown-parameters -- any JSON value: jsonInLayout writes whatever it is given
225
+ const writeJson = async (path: string, value: unknown): Promise<void> =>
226
+ writeFile(
227
+ path,
228
+ jsonInLayout(value, await readFile(path, "utf8").catch(() => undefined))
229
+ );
203
230
 
204
231
  const listFiles = async (path: string, pattern: RegExp): Promise<string[]> => {
205
232
  if (!existsSync(path)) {
206
233
  return [];
207
234
  }
235
+
208
236
  const entries = await readdir(path, { withFileTypes: true });
237
+
209
238
  return entries
210
239
  .filter((entry) => entry.isFile() && pattern.test(entry.name))
211
240
  .map((entry) => entry.name.replace(pattern, ""))
212
- .sort();
241
+ .toSorted();
213
242
  };
214
243
 
215
244
  // --- Validation -------------------------------------------------------------
216
245
 
217
- /** Any of an object's fields, as read from JSON before it is checked. */
218
- type Unchecked = Record<string, unknown> | null | undefined;
246
+ /** A contributor's fields, as read from JSON before they are checked. */
247
+ interface UncheckedContributor {
248
+ discipline?: unknown;
249
+ git?: unknown;
250
+ github?: unknown;
251
+ name?: unknown;
252
+ slug?: unknown;
253
+ }
254
+
255
+ /** A file's manifest fields, as read from JSON before they are checked. */
256
+ interface UncheckedManifest {
257
+ cover?: unknown;
258
+ created?: unknown;
259
+ description?: unknown;
260
+ status?: unknown;
261
+ tags?: unknown;
262
+ title?: unknown;
263
+ }
264
+
265
+ /* oxlint-disable anti-slop/no-unknown-parameters -- these check JSON as it is read, before it is trusted */
219
266
 
220
267
  /**
221
268
  * What is wrong with a contributor's `github`, or undefined: not a GitHub
@@ -229,13 +276,17 @@ function githubProblem(
229
276
  if (github === undefined) {
230
277
  return;
231
278
  }
279
+
232
280
  if (!(isText(github) && GITHUB_LOGIN_RE.test(github))) {
233
281
  return '"github" must be a GitHub username';
234
282
  }
283
+
235
284
  const account = github.toLowerCase();
285
+
236
286
  if (accounts.has(account)) {
237
287
  return `"github" (${github}) is another contributor's too`;
238
288
  }
289
+
239
290
  accounts.add(account);
240
291
  }
241
292
 
@@ -243,66 +294,97 @@ export function contributorProblems(contributors: unknown): string[] {
243
294
  if (!Array.isArray(contributors)) {
244
295
  return ["contributors.json must be an array"];
245
296
  }
297
+
246
298
  const problems: string[] = [];
247
299
  const slugs = new Set<unknown>();
248
300
  const accounts = new Set<string>();
249
- for (const contributor of contributors as Unchecked[]) {
301
+
302
+ // SAFETY: each field is checked before it is trusted, and an entry that is
303
+ // null or not an object reads as one with no fields.
304
+ for (const contributor of contributors as (
305
+ | UncheckedContributor
306
+ | null
307
+ | undefined
308
+ )[]) {
250
309
  const label = contributor?.slug ?? "(no slug)";
310
+
251
311
  if (!isSlug(contributor?.slug)) {
252
312
  problems.push(`contributor ${label}: "slug" must be kebab-case`);
253
313
  } else if (slugs.has(contributor.slug)) {
254
314
  problems.push(`contributor ${label} is listed twice`);
255
315
  }
316
+
256
317
  slugs.add(contributor?.slug);
318
+
257
319
  if (!isText(contributor?.name)) {
258
320
  problems.push(`contributor ${label}: "name" is required`);
259
321
  }
322
+
260
323
  if (!isOneOf(DISCIPLINES, contributor?.discipline)) {
261
324
  problems.push(
262
325
  `contributor ${label}: "discipline" must be one of ${DISCIPLINES.join(", ")}`
263
326
  );
264
327
  }
328
+
265
329
  const git = contributor?.git;
330
+
266
331
  if (!(Array.isArray(git) && git.every(isText))) {
267
332
  problems.push(
268
333
  `contributor ${label}: "git" must be a list of git user names`
269
334
  );
270
335
  }
336
+
271
337
  const github = githubProblem(contributor?.github, accounts);
338
+
272
339
  if (github) {
273
340
  problems.push(`contributor ${label}: ${github}`);
274
341
  }
275
342
  }
343
+
276
344
  return problems;
277
345
  }
278
346
 
279
347
  export function manifestProblems(manifest: unknown): string[] {
280
- const fields = manifest as Unchecked;
348
+ // SAFETY: each field is checked before it is trusted, and a manifest that
349
+ // is null or not an object reads as one with no fields.
350
+ const fields = manifest as UncheckedManifest | null | undefined;
281
351
  const problems: string[] = [];
282
- for (const field of ["title", "description"]) {
283
- if (!isText(fields?.[field])) {
284
- problems.push(`"${field}" must be a non-empty string`);
285
- }
352
+
353
+ if (!isText(fields?.title)) {
354
+ problems.push('"title" must be a non-empty string');
286
355
  }
356
+
357
+ // The question the file answers, when there is one to put in it.
358
+ if (fields?.description !== undefined && !isText(fields.description)) {
359
+ problems.push('"description" must be a non-empty string when given');
360
+ }
361
+
287
362
  if (!isOneOf(STATUSES, fields?.status)) {
288
363
  problems.push(`"status" must be one of ${STATUSES.join(", ")}`);
289
364
  }
365
+
290
366
  // test() reads whatever it is given as a string.
291
367
  if (!DATE_RE.test(String(fields?.created ?? ""))) {
292
368
  problems.push('"created" must be a YYYY-MM-DD date');
293
369
  }
370
+
294
371
  const tags = fields?.tags;
372
+
295
373
  if (tags !== undefined && !(Array.isArray(tags) && tags.every(isText))) {
296
374
  problems.push('"tags" must be a list of strings');
297
375
  }
376
+
298
377
  if (fields?.cover !== undefined) {
299
378
  const cover = checkFrameAnchor(fields.cover, "cover");
379
+
300
380
  if ("problems" in cover) {
301
381
  problems.push(...cover.problems);
302
382
  }
303
383
  }
384
+
304
385
  return problems;
305
386
  }
387
+ /* oxlint-enable anti-slop/no-unknown-parameters */
306
388
 
307
389
  /** contributors.json is missing until Dex first starts there or someone joins. */
308
390
  const readContributors = (path: string): Promise<Contributor[]> =>
@@ -312,14 +394,18 @@ export async function loadStudio(
312
394
  root: string
313
395
  ): Promise<{ contributors: Contributor[]; root: string }> {
314
396
  const contributors = await readContributors(join(root, "contributors.json"));
397
+
315
398
  return { root, contributors };
316
399
  }
317
400
 
318
401
  /** The views and docs a prototype's canvas may point at. */
319
402
  export async function knownFor(slug: string, root: string): Promise<Known> {
320
403
  const paths = prototypePaths(root, slug);
404
+
405
+ const views = await viewFiles(root, slug);
406
+
321
407
  return {
322
- views: [...(await viewFiles(root, slug)).keys()].sort(),
408
+ views: [...views.keys()].toSorted(),
323
409
  docs: await listFiles(paths.docs, DOC_FILE_RE),
324
410
  };
325
411
  }
@@ -334,35 +420,65 @@ export interface CheckReport {
334
420
  async function prototypeIssues(
335
421
  root: string,
336
422
  { slug, path, manifest, problem }: PrototypeFolder,
337
- designSystem: ResolvedDesignSystem | undefined
423
+ designSystem: ResolvedDesignSystem | undefined,
424
+ layout: LayoutState
338
425
  ): Promise<CheckReport> {
339
426
  // A bad name, or a manifest that is missing or cannot be read.
340
427
  if (problem) {
341
428
  return { problems: [`${path}: ${problem}`], warnings: [] };
342
429
  }
430
+
343
431
  // Where each part is on disk, and as the problems name it. prototypePaths
344
432
  // has thrown for any name prototypeFiles refuses.
345
433
  const paths = prototypePaths(root, slug);
434
+ // SAFETY: prototypePaths has thrown for any name prototypeFiles refuses.
346
435
  const files = prototypeFiles(slug) as PrototypeFiles;
436
+
437
+ // The manifest the folder has, prototype.json in one from before.
438
+ const manifestPath =
439
+ paths.manifest === join(root, files.manifest)
440
+ ? files.manifest
441
+ : files.legacyManifest;
442
+
347
443
  const problems = manifestProblems(manifest).map(
348
- (problem) => `${files.manifest}: ${problem}`
444
+ (each) => `${manifestPath}: ${each}`
349
445
  );
446
+
447
+ // Files whose own checks found a problem: the schema needn't say it too.
448
+ const quiet = new Set(problems.length > 0 ? [manifestPath] : []);
449
+ const warnings: string[] = [];
450
+
451
+ // An older studio is said once, of its .layout; a file left behind in a
452
+ // studio that is in this version is said of itself.
453
+ if (manifestPath === files.legacyManifest && layout === "known") {
454
+ warnings.push(
455
+ `${manifestPath}: the manifest's name before file.json; \`npx dex upgrade\` renames it.`
456
+ );
457
+ }
458
+
350
459
  const { views, docs } = await knownFor(slug, root);
460
+
351
461
  for (const [name, people] of await clashingViews(root, slug)) {
352
462
  problems.push(
353
463
  `${path}: ${people.join(" and ")} each have a view named "${name}"; the canvas shows only ${people[0]}'s. Rename one, and the frames that show it.`
354
464
  );
355
465
  }
466
+
356
467
  // A new file has no view until its first frame is drawn: that is no
357
468
  // problem.
358
469
  const copied: string[] = [];
470
+
359
471
  for (const part of await canvasParts(slug, root)) {
472
+ const found = canvasProblems(part.canvas, { views, docs });
473
+
474
+ if (found.length > 0) {
475
+ quiet.add(shownIn(root, part.file));
476
+ }
477
+
360
478
  problems.push(
361
- ...[
362
- ...canvasProblems(part.canvas, { views, docs }),
363
- ...rowTitleProblems(part.canvas),
364
- ].map((problem) => `${shownIn(root, part.file)}: ${problem}`)
479
+ ...found.map((each) => `${shownIn(root, part.file)}: ${each}`)
365
480
  );
481
+
366
482
  // The canvas still reads, at worst showing the row twice: only a warning.
367
483
  for (const { section, row, author } of othersRowsIn(
368
484
  part.canvas,
@@ -373,15 +489,28 @@ async function prototypeIssues(
373
489
  );
374
490
  }
375
491
  }
492
+
376
493
  // Picks never change what a prototype shows, so a broken file only warns.
377
- const annotations = (await readPrototypeAnnotations(slug, root)).problems;
494
+ const { problems: picks } = await readPrototypePicks(slug, root);
495
+
496
+ // Each line names its file first: "files/…/picks.json: …".
497
+ for (const line of picks) {
498
+ quiet.add(line.slice(0, line.indexOf(": ")));
499
+ }
500
+
378
501
  const findings = await checkPrototype(root, paths.folder, designSystem);
379
502
  problems.push(...errorLines(findings));
503
+ // Each path's place, and each file against the published schemas.
504
+ const format = await fileFolderFindings(root, paths.folder, quiet);
505
+ problems.push(...format.problems);
506
+
380
507
  return {
381
508
  problems,
382
509
  warnings: [
510
+ ...warnings,
511
+ ...format.warnings,
383
512
  ...copied,
384
- ...annotations,
513
+ ...picks,
385
514
  ...findings
386
515
  .filter((finding) => finding.level === "warning")
387
516
  .map(findingLine),
@@ -400,54 +529,103 @@ export async function checkStudio(
400
529
  { designSystem }: { designSystem?: ResolvedDesignSystem } = {}
401
530
  ): Promise<CheckReport> {
402
531
  const { contributors } = await loadStudio(root);
532
+ const devices = await loadDevices(root);
533
+
403
534
  const report: CheckReport = {
404
535
  problems: contributorProblems(contributors).map(
405
536
  (problem) => `contributors.json: ${problem}`
406
537
  ),
407
538
  // The studio reads past them, so they are only warned of.
408
- warnings: (await loadDevices(root)).problems,
539
+ warnings: devices.problems,
409
540
  };
541
+
542
+ // files/ itself, the .layout's text and contributors.json, as published.
543
+ const studio = await studioFindings(root, {
544
+ quiet: report.problems.length > 0,
545
+ });
546
+
547
+ report.problems.push(...studio.problems);
548
+ report.warnings.push(...studio.warnings);
549
+ // Files newer than this Dex reads can't be checked by it; older ones are
550
+ // read all the same, and upgrade moves them on.
551
+ const layout = await studioLayout(root);
552
+
553
+ if (layout.state === "newer" && layout.message) {
554
+ report.problems.push(`${LAYOUT_FILE}: ${layout.message}`);
555
+
556
+ return report;
557
+ }
558
+
559
+ const unreadable = studio.problems.some((line) =>
560
+ line.startsWith(LAYOUT_FILE)
561
+ );
562
+
563
+ if (layout.state === "older" && layout.message && !unreadable) {
564
+ report.warnings.push(`${LAYOUT_FILE}: ${layout.message}`);
565
+ }
566
+
410
567
  for (const folder of await walkPrototypes(root)) {
411
568
  const { problems, warnings } = await prototypeIssues(
412
569
  root,
413
570
  folder,
414
- designSystem
571
+ designSystem,
572
+ layout.state
415
573
  );
574
+
416
575
  report.problems.push(...problems);
417
576
  report.warnings.push(
418
577
  ...warnings,
419
578
  ...(await twoVersionsIn(root, folder.folder))
420
579
  );
421
580
  }
581
+
422
582
  return report;
423
583
  }
424
584
 
425
- const SPEC_FILE_RE = /(^|\/)people\/[^/]+\/specs\/[^/]+\.md$/;
585
+ /** Whether Dex's spec merge merges a path in a file's folder. */
586
+ const mergedBySpecs = (path: string): boolean =>
587
+ ["spec", "doc"].includes(placeOf(path)?.part ?? "");
426
588
 
427
- /** Specs in a prototype's folder still holding two versions to choose from. */
589
+ /**
590
+ * Specs, notes, slides and docs in a prototype's folder still holding two
591
+ * versions to choose from.
592
+ */
428
593
  async function twoVersionsIn(root: string, folder: string): Promise<string[]> {
429
594
  const names = await readdir(folder, { recursive: true }).catch(
430
- () => [] as string[]
595
+ (): string[] => []
431
596
  );
432
- const warnings: string[] = [];
433
- for (const name of names.filter((each) => SPEC_FILE_RE.test(each)).sort()) {
434
- const file = join(folder, name);
435
- const text = await readFile(file, "utf8").catch(() => "");
436
- const pairs = text.split(TWO_VERSIONS_LEAD).length - 1;
437
- if (pairs > 0) {
438
- warnings.push(
439
- `${relative(root, file)}: ${pairs === 1 ? "a paragraph has" : `${pairs} paragraphs have`} two versions, written at the same time: keep one in the spec.`
440
- );
441
- }
442
- }
443
- return warnings;
597
+
598
+ const merged = names
599
+ .map((name) => name.split(sep).join("/"))
600
+ .filter(mergedBySpecs)
601
+ .toSorted();
602
+
603
+ const warnings = await Promise.all(
604
+ merged.map(async (name) => {
605
+ const file = join(folder, name);
606
+ const text = await readFile(file, "utf8").catch(() => "");
607
+ const pairs = text.split(TWO_VERSIONS_LEAD).length - 1;
608
+
609
+ return pairs > 0
610
+ ? [
611
+ `${relative(root, file)}: ${pairs === 1 ? "a paragraph has" : `${pairs} paragraphs have`} two versions, written at the same time: keep one in the spec.`,
612
+ ]
613
+ : [];
614
+ })
615
+ );
616
+
617
+ return warnings.flat();
444
618
  }
445
619
 
446
620
  /** Every problem in the studio (checkStudio's), without the warnings. */
447
621
  export const check = async (
448
622
  root: string,
449
623
  options: { designSystem?: ResolvedDesignSystem } = {}
450
- ): Promise<string[]> => (await checkStudio(root, options)).problems;
624
+ ): Promise<string[]> => {
625
+ const { problems } = await checkStudio(root, options);
626
+
627
+ return problems;
628
+ };
451
629
 
452
630
  // --- Saving the canvas --------------------------------------------------------
453
631
  //
@@ -464,9 +642,11 @@ interface CanvasPart {
464
642
  }
465
643
 
466
644
  /**
467
- * Each person's canvas.json in a prototype. A canvas.json beside
468
- * prototype.json, from before people/, is not read: `dex upgrade` moves
469
- * it into its person's folder (people-folders.ts).
645
+ * Each person's canvas.json in a prototype, as this Dex reads it: with the
646
+ * piles a development Dex marked made stacks (stackPiles), which their next
647
+ * save writes. A canvas.json beside the manifest, from before people/, is
648
+ * not read: `dex upgrade` moves it into its person's folder
649
+ * (people-folders.ts).
470
650
  */
471
651
  export async function canvasParts(
472
652
  slug: string,
@@ -474,12 +654,16 @@ export async function canvasParts(
474
654
  ): Promise<CanvasPart[]> {
475
655
  const paths = prototypePaths(root, slug);
476
656
  const parts: CanvasPart[] = [];
657
+
477
658
  for (const person of await peopleOf(root, slug)) {
478
659
  const file = paths.person(person)?.canvas;
660
+
479
661
  if (file && existsSync(file)) {
480
- parts.push({ person, file, canvas: await readJson<Canvas>(file) });
662
+ const canvas = stackPiles(await readJson<Canvas>(file));
663
+ parts.push({ person, file, canvas });
481
664
  }
482
665
  }
666
+
483
667
  return parts;
484
668
  }
485
669
 
@@ -491,9 +675,11 @@ export async function canvasParts(
491
675
  */
492
676
  const revisionOf = (parts: CanvasPart[], person: string) => {
493
677
  const part = parts.find((each) => each.person === person);
678
+
494
679
  const hash = part
495
680
  ? createHash("sha1").update(JSON.stringify(part.canvas)).digest("hex")
496
681
  : "";
682
+
497
683
  return `${person}:${hash}`;
498
684
  };
499
685
 
@@ -504,6 +690,7 @@ export async function readCanvasRevision(
504
690
  root: string
505
691
  ): Promise<CanvasRevision> {
506
692
  const parts = await canvasParts(slug, root);
693
+
507
694
  return {
508
695
  canvas: combineCanvases(parts),
509
696
  person,
@@ -521,6 +708,7 @@ export async function readCanvas(slug: string, root: string): Promise<Canvas> {
521
708
 
522
709
  // A save formats with Biome, which may take its whole timeout.
523
710
  const CANVAS_LOCK_STALE_MS = 15_000;
711
+
524
712
  /** Run `work` in turn with a prototype's canvas saves (trash.ts too). */
525
713
  export const queued = <T>(
526
714
  root: string,
@@ -576,9 +764,16 @@ const rowBefore = <R extends { id: string }>(
576
764
  above?: string
577
765
  ): R | undefined => {
578
766
  const at = rows.findIndex((row) => row.id === above);
579
- return at < 0 ? rows.at(-1) : rows[Math.max(0, at - 1)];
767
+
768
+ return at === -1 ? rows.at(-1) : rows[Math.max(0, at - 1)];
580
769
  };
581
770
 
771
+ /** A canvas and a cell on it. */
772
+ export interface CanvasCell {
773
+ canvas: Canvas;
774
+ cell: Cell;
775
+ }
776
+
582
777
  /**
583
778
  * A cell the person may add to: theirs, or, in someone else's row, the same
584
779
  * step of the person's own row right below it (ownRow; a new one with
@@ -590,24 +785,32 @@ export function ownCell(
590
785
  cell: Cell,
591
786
  person: string,
592
787
  { newRow = false }: { newRow?: boolean } = {}
593
- ): { canvas: Canvas; cell: Cell } {
788
+ ): CanvasCell {
594
789
  const section = canvas.sections.find((entry) => entry.id === cell.section);
595
790
  const row = section?.rows.find((entry) => entry.id === cell.row);
791
+
596
792
  const theirs = row
597
793
  ? section && isOthersRow(section, row, person)
598
794
  : section && isOthers(section, person);
795
+
599
796
  if (!(section && theirs)) {
600
797
  return { canvas, cell };
601
798
  }
799
+
602
800
  const anchor = row ?? rowBefore(section.rows, cell.above);
801
+
603
802
  // A new row's place is the person's own row already: it goes in that.
604
803
  if (!row && anchor && !isOthersRow(section, anchor, person)) {
605
804
  return { canvas, cell: { ...cell, row: anchor.id } };
606
805
  }
806
+
607
807
  const own = ownRow(section, anchor?.id ?? "main", person, { newRow });
808
+
608
809
  return {
609
810
  canvas: {
610
811
  sections: canvas.sections.map((entry) =>
812
+ // SAFETY: ownRow gives back the section it was given, a Section,
813
+ // with its rows changed.
611
814
  entry === section ? (own.section as Section) : entry
612
815
  ),
613
816
  },
@@ -630,6 +833,7 @@ export function placeViewFrame(
630
833
  size,
631
834
  person,
632
835
  newRow,
836
+ stack,
633
837
  }: {
634
838
  cell: Cell;
635
839
  /**
@@ -642,6 +846,8 @@ export function placeViewFrame(
642
846
  /** The size asked for it: a request's, set on the canvas. */
643
847
  size?: PageSize;
644
848
  slug: string;
849
+ /** On top of the stack in the cell, rather than a column of its own. */
850
+ stack?: boolean;
645
851
  view: string;
646
852
  viewport?: Viewport;
647
853
  },
@@ -652,24 +858,31 @@ export function placeViewFrame(
652
858
  > {
653
859
  return queued(root, slug, async () => {
654
860
  const saver = person;
861
+
655
862
  const { canvas, cell: own } = ownCell(
656
863
  await readCanvas(slug, root),
657
864
  cell,
658
865
  saver,
659
866
  { newRow }
660
867
  );
868
+
661
869
  const { devices } = await loadDevices(root);
870
+
662
871
  const placed = placeViewInCell(canvas, own, {
663
872
  view,
664
873
  viewport,
665
874
  size,
875
+ stack,
666
876
  fallback: defaultDevice(devices),
667
877
  });
878
+
668
879
  if ("problem" in placed) {
669
880
  return { problems: [placed.problem] };
670
881
  }
882
+
671
883
  const uidAt = (on: Canvas | undefined) =>
672
884
  canvasFrames(on).find((entry) => entry.key === placed.key)?.frame.uid;
885
+
673
886
  if (!placed.added) {
674
887
  return {
675
888
  key: placed.key,
@@ -678,13 +891,16 @@ export function placeViewFrame(
678
891
  uid: uidAt(canvas),
679
892
  };
680
893
  }
894
+
681
895
  const saved = await saveCanvasNow(
682
896
  { slug, canvas: placed.canvas, person: saver },
683
897
  root
684
898
  );
899
+
685
900
  if (saved.problems) {
686
901
  return { problems: saved.problems };
687
902
  }
903
+
688
904
  return {
689
905
  key: placed.key,
690
906
  added: true,
@@ -694,6 +910,13 @@ export function placeViewFrame(
694
910
  });
695
911
  }
696
912
 
913
+ /** A save's canvas and files, its views renamed where they clash. */
914
+ interface FreedNames {
915
+ canvas: Canvas;
916
+ stylesheets: Record<string, string>;
917
+ views: Record<string, string>;
918
+ }
919
+
697
920
  /**
698
921
  * New views by names someone else's views already have, renamed to the next
699
922
  * free name, with the frames in the person's own sections that show them.
@@ -703,13 +926,10 @@ function freeViewNames(
703
926
  { views = {}, stylesheets = {} }: CanvasSave,
704
927
  existing: Map<string, ViewFile>,
705
928
  person: string
706
- ): {
707
- canvas: Canvas;
708
- stylesheets: Record<string, string>;
709
- views: Record<string, string>;
710
- } {
929
+ ): FreedNames {
711
930
  const taken = new Set([...existing.keys(), ...Object.keys(views)]);
712
931
  const renamed = new Map<string, string>();
932
+
713
933
  for (const name of Object.keys(views)) {
714
934
  if ((existing.get(name)?.person ?? person) !== person) {
715
935
  const free = uniqueId(name, taken);
@@ -717,14 +937,18 @@ function freeViewNames(
717
937
  renamed.set(name, free);
718
938
  }
719
939
  }
940
+
720
941
  if (renamed.size === 0) {
721
942
  return { canvas, views, stylesheets };
722
943
  }
944
+
723
945
  const to = (name: string) => renamed.get(name) ?? name;
946
+
724
947
  const rename = (files: Record<string, string>) =>
725
948
  Object.fromEntries(
726
949
  Object.entries(files).map(([name, text]) => [to(name), text])
727
950
  );
951
+
728
952
  return {
729
953
  views: rename(views),
730
954
  stylesheets: rename(stylesheets),
@@ -738,6 +962,7 @@ function freeViewNames(
738
962
  ...row,
739
963
  frames: row.frames.map((frame) => {
740
964
  const view = viewOf(frame);
965
+
741
966
  return view ? { ...view, view: to(view.view) } : frame;
742
967
  }),
743
968
  }
@@ -756,18 +981,23 @@ async function saveCanvasNow(
756
981
  const paths = prototypePaths(root, slug);
757
982
  const { person } = save;
758
983
  const own = paths.person(person);
984
+
759
985
  if (!own) {
760
986
  return { problems: [`"${person}" is not a contributor's slug.`] };
761
987
  }
988
+
762
989
  const parts = await canvasParts(slug, root);
990
+
763
991
  if (
764
992
  save.revision !== undefined &&
765
993
  save.revision !== revisionOf(parts, person)
766
994
  ) {
767
995
  return { stale: true };
768
996
  }
997
+
769
998
  const existing = await viewFiles(root, slug);
770
999
  const onDisk = combineCanvases(parts);
1000
+
771
1001
  // Whose each row is, from disk only: by its own author, else its
772
1002
  // section's. What the body claims is not asked, and a row that is not on
773
1003
  // disk yet is the saver's.
@@ -779,14 +1009,20 @@ async function saveCanvasNow(
779
1009
  ])
780
1010
  )
781
1011
  );
782
- const malformed = shapeProblems(save.canvas, (section, row) => {
1012
+
1013
+ const malformed = canvasFormProblems(save.canvas, (section, row) => {
783
1014
  const owner = owners.get(`${section.id}/${row.id}`);
1015
+
784
1016
  return owner !== undefined && owner !== person;
785
1017
  });
1018
+
786
1019
  if (malformed.length > 0) {
787
1020
  return { problems: malformed };
788
1021
  }
1022
+
1023
+ // SAFETY: canvasFormProblems found nothing wrong with it, so it is a Canvas.
789
1024
  const sent = (save.canvas as Canvas).sections;
1025
+
790
1026
  const labelled: Canvas = {
791
1027
  sections: labelAuthors(
792
1028
  sent,
@@ -795,12 +1031,15 @@ async function saveCanvasNow(
795
1031
  save.revision !== undefined
796
1032
  ),
797
1033
  };
1034
+
798
1035
  const renamed = Object.fromEntries(
799
1036
  sent.flatMap((section, index) => {
800
1037
  const id = labelled.sections[index]?.id;
1038
+
801
1039
  return id === undefined || id === section.id ? [] : [[section.id, id]];
802
1040
  })
803
1041
  );
1042
+
804
1043
  // Nobody picks names: a new view by a name someone else has takes the
805
1044
  // next free one, and the person's frames follow it.
806
1045
  const {
@@ -808,75 +1047,97 @@ async function saveCanvasNow(
808
1047
  views,
809
1048
  stylesheets,
810
1049
  } = freeViewNames(labelled, save, existing, person);
1050
+
811
1051
  // A change to someone else's section goes into a copy of it that is the
812
1052
  // saver's; then only the saver's sections are written, without others'
813
1053
  // rows, and everyone else's stay as their files have them.
814
1054
  const now = new Date().toISOString();
1055
+
815
1056
  const lifted = liftRows(
816
1057
  savedPart(onDisk, named, person, {
817
1058
  onRevision: save.revision !== undefined,
818
1059
  }),
819
1060
  person
820
1061
  );
821
- // Uids keep a frame the same frame when it moves, so picks follow it: with
822
- // them off, a save writes none. With them on, the file is marked as having
823
- // given its frames uids, and the mark stays.
1062
+
1063
+ // Uids keep a frame the same frame when it moves, so picks and comments
1064
+ // follow it: each save gives the saver's frames theirs, and marks the file
1065
+ // as having given them.
824
1066
  const given =
825
1067
  parts.find((part) => part.person === person)?.canvas.frameUids === true;
826
- const uids = features().uids;
1068
+
827
1069
  const sections = ownSections(
828
- uids ? withFrameUids(lifted, person, { given, previous: onDisk }) : lifted,
1070
+ withFrameUids(lifted, person, { given, previous: onDisk }),
829
1071
  person,
830
1072
  now
831
1073
  );
832
- const mine: Canvas =
833
- uids || given ? { frameUids: true, ...sections } : sections;
1074
+
1075
+ const mine: Canvas = { frameUids: true, ...sections };
834
1076
  // A teammate's frame, such as one made in a newer Dex, never stops
835
1077
  // anyone else saving.
836
1078
  const known = await knownFor(slug, root);
1079
+
837
1080
  const problems = canvasProblems(mine, {
838
1081
  ...known,
839
1082
  views: [...known.views, ...Object.keys(views)],
840
1083
  });
1084
+
841
1085
  if (problems.length > 0) {
842
1086
  return { problems };
843
1087
  }
1088
+
844
1089
  const images = save.images ?? {};
1090
+
845
1091
  // What the save takes off their canvas, so a removed view can say where it was.
846
- const before = (await canvasParts(slug, root)).find(
847
- (part) => part.person === person
848
- )?.canvas;
1092
+ const current = await canvasParts(slug, root);
1093
+ const before = current.find((part) => part.person === person)?.canvas;
1094
+
849
1095
  const removed = nextRemovals(
850
1096
  before?.sections ?? [],
851
1097
  mine.sections,
852
1098
  removalsOf(before),
853
1099
  { by: person, now }
854
1100
  );
1101
+
855
1102
  const file = own.canvas;
856
1103
  const biome = findBiome(root);
1104
+
857
1105
  const text: string = await formatText(
858
1106
  biome,
859
1107
  file,
860
- `${JSON.stringify(removed.length > 0 ? { ...mine, removed } : mine, null, 2)}\n`
1108
+ jsonInLayout(
1109
+ // What a newer Dex wrote that this one doesn't know stays as it was.
1110
+ withUnknownFields(
1111
+ before,
1112
+ removed.length > 0 ? { ...mine, removed } : mine
1113
+ ),
1114
+ await readFile(file, "utf8").catch(() => undefined)
1115
+ )
861
1116
  );
1117
+
862
1118
  // Parsed before anything is written, so a bad format never lands on disk.
863
1119
  JSON.parse(text);
864
1120
  // The views first, so the canvas never points at a view not yet there,
865
1121
  // and each view's images and stylesheet before the view that imports them.
866
1122
  const pictures = Object.entries(images);
1123
+
867
1124
  if (pictures.length > 0) {
868
1125
  await mkdir(paths.images, { recursive: true });
869
1126
  }
870
- for (const [file, bytes] of pictures) {
871
- await writeFile(paths.image(file), bytes);
1127
+
1128
+ for (const [name, bytes] of pictures) {
1129
+ await writeFile(paths.image(name), bytes);
872
1130
  }
1131
+
873
1132
  // A view saved again stays where it is; a new one goes in their views/.
874
1133
  const viewFile = (name: string, extension = ".tsx") => {
875
1134
  const found = existing.get(name)?.file;
1135
+
876
1136
  return found
877
1137
  ? `${found.slice(0, -".tsx".length)}${extension}`
878
1138
  : own.view(name, extension);
879
1139
  };
1140
+
880
1141
  const unformatted = [
881
1142
  ...Object.entries(stylesheets).map(([name, css]) => [
882
1143
  viewFile(name, ".css"),
@@ -884,9 +1145,11 @@ async function saveCanvasNow(
884
1145
  ]),
885
1146
  ...Object.entries(views).map(([name, source]) => [viewFile(name), source]),
886
1147
  ];
1148
+
887
1149
  if (unformatted.length > 0) {
888
1150
  await mkdir(own.views, { recursive: true });
889
1151
  }
1152
+
890
1153
  // Written formatted: a rewrite of a view no page has loaded yet makes Vite
891
1154
  // reload every page, the canvas and all its frames.
892
1155
  const files = await Promise.all(
@@ -895,11 +1158,14 @@ async function saveCanvasNow(
895
1158
  await formatText(biome, path, source),
896
1159
  ])
897
1160
  );
1161
+
898
1162
  for (const [path, contents] of files) {
899
1163
  await writeFile(path, contents);
900
1164
  }
1165
+
901
1166
  await mkdir(own.folder, { recursive: true });
902
1167
  await replaceFile(file, text);
1168
+
903
1169
  return {
904
1170
  ...(await readCanvasRevision(slug, person, root)),
905
1171
  renamed,
@@ -907,76 +1173,95 @@ async function saveCanvasNow(
907
1173
  };
908
1174
  }
909
1175
 
910
- // --- Annotations (picks) -----------------------------------------------------
1176
+ // --- Picks --------------------------------------------------------------------
911
1177
 
912
- /** Everyone's annotations (picks) on a prototype, each with its author. */
913
- export interface PrototypeAnnotations {
914
- annotations: Authored[];
1178
+ /** Everyone's picks on a prototype, each with its author. */
1179
+ export interface PrototypePicks {
1180
+ picks: Authored[];
915
1181
  /** What is wrong with each file, by its path in the studio. */
916
1182
  problems: string[];
917
1183
  }
918
1184
 
919
- export type SavedAnnotations =
920
- | { annotations: Authored[]; problems?: undefined }
921
- | { annotations?: undefined; problems: string[] };
1185
+ export type SavedPicks =
1186
+ | { picks: Authored[]; problems?: undefined }
1187
+ | { picks?: undefined; problems: string[] };
1188
+
1189
+ const PICKS_LOCK_STALE_MS = 5000;
1190
+ const NOT_PICKS = 'must be { "picks": [...] }.';
922
1191
 
923
- const ANNOTATIONS_LOCK_STALE_MS = 5000;
924
- const NOT_ANNOTATIONS = 'must be { "annotations": [...] }.';
1192
+ // oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- the file as read: fields Dex doesn't know are written back as they were
1193
+ type PicksJson = Record<string, unknown>;
925
1194
 
926
- async function annotationsFile(
1195
+ async function picksFile(
927
1196
  file: string
928
- ): Promise<{ file?: Record<string, unknown> } | { problem: string }> {
1197
+ ): Promise<{ file?: PicksJson } | { problem: string }> {
929
1198
  let text: string;
1199
+
930
1200
  try {
931
1201
  text = await readFile(file, "utf8");
932
1202
  } catch (error) {
933
- return (error as NodeJS.ErrnoException).code === "ENOENT"
934
- ? {}
935
- : { problem: (error as Error).message };
1203
+ // SAFETY: readFile fails with a Node system error, an Error with a code.
1204
+ const { code, message } = error as NodeJS.ErrnoException;
1205
+
1206
+ return code === "ENOENT" ? {} : { problem: message };
936
1207
  }
1208
+
937
1209
  try {
938
1210
  const parsed: unknown = JSON.parse(text);
939
- return isRecord(parsed) && Array.isArray(parsed.annotations)
1211
+
1212
+ return isRecord(parsed) && Array.isArray(parsed.picks)
940
1213
  ? { file: parsed }
941
- : { problem: NOT_ANNOTATIONS };
1214
+ : { problem: NOT_PICKS };
942
1215
  } catch (error) {
1216
+ // SAFETY: JSON.parse fails with a SyntaxError.
943
1217
  return { problem: (error as Error).message };
944
1218
  }
945
1219
  }
946
1220
 
947
1221
  /**
948
- * Every person's annotations (picks) on a prototype, by person, each with
949
- * its author. A file that cannot be read gives problems, never an error,
950
- * so one person's broken file hides only their picks. Notes and arrows, which
951
- * older Dex wrote, are left in the file and not read.
1222
+ * Every person's picks on a prototype, by person, each with its author. A
1223
+ * file that cannot be read gives problems, never an error, so one person's
1224
+ * broken file hides only their picks.
952
1225
  */
953
- export async function readPrototypeAnnotations(
1226
+ export async function readPrototypePicks(
954
1227
  slug: string,
955
1228
  root: string
956
- ): Promise<PrototypeAnnotations> {
1229
+ ): Promise<PrototypePicks> {
957
1230
  const paths = prototypePaths(root, slug);
958
- const read: PrototypeAnnotations = { annotations: [], problems: [] };
959
- for (const person of await peopleOf(root, slug)) {
960
- const file = paths.person(person)?.annotations;
961
- if (!file) {
962
- continue;
963
- }
964
- const found = await annotationsFile(file);
1231
+ const read: PrototypePicks = { picks: [], problems: [] };
1232
+
1233
+ const people = await peopleOf(root, slug);
1234
+
1235
+ const files = people.flatMap((person) => {
1236
+ const file = paths.person(person)?.picks;
1237
+
1238
+ return file ? [{ file, person }] : [];
1239
+ });
1240
+
1241
+ const opened = await Promise.all(
1242
+ files.map(async (each) => ({
1243
+ ...each,
1244
+ found: await picksFile(each.file),
1245
+ }))
1246
+ );
1247
+
1248
+ for (const { file, found, person } of opened) {
965
1249
  if ("problem" in found) {
966
1250
  read.problems.push(`${shownIn(root, file)}: ${found.problem}`);
967
1251
  continue;
968
1252
  }
1253
+
969
1254
  if (!found.file) {
970
1255
  continue;
971
1256
  }
972
- const { annotations, problems } = readAnnotations(found.file);
973
- read.annotations.push(
974
- ...annotations.map((annotation) => ({ ...annotation, author: person }))
975
- );
1257
+
1258
+ const { picks, problems } = readPicks(found.file);
1259
+ read.picks.push(...picks.map((pick) => ({ ...pick, author: person })));
976
1260
  read.problems.push(
977
1261
  ...problems.map((problem) => `${shownIn(root, file)}: ${problem}`)
978
1262
  );
979
1263
  }
1264
+
980
1265
  return read;
981
1266
  }
982
1267
 
@@ -986,73 +1271,87 @@ interface PicksOf {
986
1271
  slug: string;
987
1272
  }
988
1273
 
989
- async function changeAnnotations(
1274
+ async function changePicks(
990
1275
  { slug, person }: PicksOf,
991
1276
  change: (
992
- file: Record<string, unknown> | undefined
993
- ) => { annotations: unknown[] } | { problems: string[] },
1277
+ file: PicksJson | undefined
1278
+ ) => { picks: unknown[] } | { problems: string[] },
994
1279
  root: string
995
- ): Promise<SavedAnnotations> {
1280
+ ): Promise<SavedPicks> {
996
1281
  if (person === undefined) {
997
- return Promise.resolve({ problems: [NOT_RECOGNISED] });
1282
+ return { problems: [NOT_RECOGNISED] };
998
1283
  }
1284
+
999
1285
  const own = prototypePaths(root, slug).person(person);
1286
+
1000
1287
  if (!own) {
1001
- return Promise.resolve({
1288
+ return {
1002
1289
  problems: [`"${person}" is not a contributor's slug.`],
1003
- });
1290
+ };
1004
1291
  }
1292
+
1005
1293
  const written = await inTurn(
1006
1294
  root,
1007
- `annotations-${slug}-${person}`,
1008
- ANNOTATIONS_LOCK_STALE_MS,
1295
+ `picks-${slug}-${person}`,
1296
+ PICKS_LOCK_STALE_MS,
1009
1297
  async (): Promise<{ problems: string[] } | undefined> => {
1010
- const found = await annotationsFile(own.annotations);
1298
+ const found = await picksFile(own.picks);
1299
+
1011
1300
  if ("problem" in found) {
1012
1301
  return {
1013
1302
  problems: [
1014
- `${shownIn(root, own.annotations)}: ${found.problem} Fix it or remove it to pick frames.`,
1303
+ `${shownIn(root, own.picks)}: ${found.problem} Fix it or remove it to pick frames.`,
1015
1304
  ],
1016
1305
  };
1017
1306
  }
1307
+
1018
1308
  const changed = change(found.file);
1309
+
1019
1310
  if ("problems" in changed) {
1020
1311
  return changed;
1021
1312
  }
1022
- const before = found.file?.annotations ?? [];
1023
- if (JSON.stringify(changed.annotations) !== JSON.stringify(before)) {
1313
+
1314
+ const before = found.file?.picks ?? [];
1315
+
1316
+ if (JSON.stringify(changed.picks) !== JSON.stringify(before)) {
1024
1317
  await mkdir(own.folder, { recursive: true });
1025
1318
  await replaceFile(
1026
- own.annotations,
1027
- `${JSON.stringify({ ...found.file, ...changed }, null, 2)}\n`
1319
+ own.picks,
1320
+ jsonInLayout(
1321
+ { ...found.file, ...changed },
1322
+ await readFile(own.picks, "utf8").catch(() => undefined)
1323
+ )
1028
1324
  );
1029
1325
  }
1030
1326
  }
1031
1327
  );
1032
- return (
1033
- written ?? {
1034
- annotations: (await readPrototypeAnnotations(slug, root)).annotations,
1035
- }
1036
- );
1328
+
1329
+ if (written) {
1330
+ return written;
1331
+ }
1332
+
1333
+ const { picks } = await readPrototypePicks(slug, root);
1334
+
1335
+ return { picks };
1037
1336
  }
1038
1337
 
1039
1338
  /**
1040
- * Put one of the person's picks in their annotations.json, in place of the
1041
- * one with its id or added, after checking it (annotationProblems).
1339
+ * Put one of the person's picks in their picks.json, in place of the one
1340
+ * with its id or added, after checking it (pickProblems).
1042
1341
  */
1043
- export const saveAnnotation = (
1044
- { annotation, ...whose }: PicksOf & { annotation: unknown },
1342
+ export const savePick = (
1343
+ { pick, ...whose }: PicksOf & { pick: unknown },
1045
1344
  root: string
1046
- ): Promise<SavedAnnotations> =>
1047
- changeAnnotations(whose, (file) => withAnnotation(file, annotation), root);
1345
+ ): Promise<SavedPicks> =>
1346
+ changePicks(whose, (file) => withPick(file, pick), root);
1048
1347
 
1049
- /** Take one of the person's picks out of their annotations.json. */
1050
- export const removeAnnotation = (
1348
+ /** Take one of the person's picks out of their picks.json. */
1349
+ export const removePick = (
1051
1350
  { id, ...whose }: PicksOf & { id: unknown },
1052
1351
  root: string
1053
- ): Promise<SavedAnnotations> =>
1352
+ ): Promise<SavedPicks> =>
1054
1353
  isText(id)
1055
- ? changeAnnotations(whose, (file) => withoutAnnotation(file, id), root)
1354
+ ? changePicks(whose, (file) => withoutPick(file, id), root)
1056
1355
  : Promise.resolve({ problems: ["Say which pick to remove."] });
1057
1356
 
1058
1357
  // --- Creating things ----------------------------------------------------------
@@ -1120,40 +1419,48 @@ export async function createPrototype(
1120
1419
  root: string
1121
1420
  ): Promise<{ folder: string; href: string | undefined; slug: string }> {
1122
1421
  const usage = 'Usage: npx dex new --title "<title>" [--person <slug>]';
1422
+
1123
1423
  if (!isText(title)) {
1124
1424
  throw new Error(`Name the file. ${usage}`);
1125
1425
  }
1426
+
1126
1427
  if (!isText(person)) {
1127
1428
  throw new Error(usage);
1128
1429
  }
1430
+
1129
1431
  const { contributors } = await loadStudio(root);
1432
+
1130
1433
  if (!contributors.some((contributor) => contributor.slug === person)) {
1131
1434
  throw new Error(
1132
1435
  `"${person}" is not a contributor. Run \`npx dex whoami\` or add them with \`npx dex contributor\`.`
1133
1436
  );
1134
1437
  }
1438
+
1135
1439
  const prototypeSlug = slug === undefined ? freeFileId(root) : slugify(slug);
1136
1440
  const paths = prototypePaths(root, prototypeSlug);
1441
+
1137
1442
  if (existsSync(paths.folder)) {
1138
1443
  throw new Error(`${prototypeFiles(prototypeSlug)?.folder} already exists.`);
1139
1444
  }
1445
+
1140
1446
  await mkdir(paths.docs, { recursive: true });
1141
1447
  // Where the person's views go, there before the first one is.
1142
1448
  const views = paths.person(person)?.views;
1449
+
1143
1450
  if (views) {
1144
1451
  await mkdir(views, { recursive: true });
1145
1452
  }
1146
1453
 
1147
1454
  await writeJson(paths.manifest, {
1148
1455
  title: title.trim(),
1149
- description: isText(description)
1150
- ? description.trim()
1151
- : "What question does this file answer?",
1456
+ // Only a question someone gave: never a placeholder for one.
1457
+ ...(isText(description) && { description: description.trim() }),
1152
1458
  status: "exploring",
1153
1459
  created: today ?? new Date().toISOString().slice(0, 10),
1154
1460
  createdBy: person,
1155
1461
  tags: [],
1156
1462
  });
1463
+
1157
1464
  const { problems } = await writeCanvas(
1158
1465
  {
1159
1466
  person,
@@ -1165,10 +1472,13 @@ export async function createPrototype(
1165
1472
  },
1166
1473
  root
1167
1474
  );
1475
+
1168
1476
  if (problems) {
1169
1477
  throw new Error(problems.join(" "));
1170
1478
  }
1479
+
1171
1480
  await writeFile(join(paths.docs, ".gitkeep"), "");
1481
+
1172
1482
  return {
1173
1483
  folder: paths.folder,
1174
1484
  slug: prototypeSlug,
@@ -1182,12 +1492,16 @@ const UNTITLED = "Untitled";
1182
1492
  const freeFileId = (root: string): string => {
1183
1493
  const taken = (candidate: string): boolean => {
1184
1494
  const files = prototypeFiles(candidate);
1495
+
1185
1496
  return files !== undefined && existsSync(join(root, files.folder));
1186
1497
  };
1498
+
1187
1499
  let id = newFileId();
1500
+
1188
1501
  while (taken(id)) {
1189
1502
  id = newFileId();
1190
1503
  }
1504
+
1191
1505
  return id;
1192
1506
  };
1193
1507
 
@@ -1208,6 +1522,7 @@ const existingPaths = (root: string, slug: string): PrototypeFiles => {
1208
1522
  if (!prototypeExists(root, slug)) {
1209
1523
  throw new Error("That file does not exist.");
1210
1524
  }
1525
+
1211
1526
  return prototypePaths(root, slug);
1212
1527
  };
1213
1528
 
@@ -1219,9 +1534,11 @@ export async function setPrototypeTitle(
1219
1534
  root: string
1220
1535
  ): Promise<void> {
1221
1536
  const name = String(title ?? "").trim();
1537
+
1222
1538
  if (!name) {
1223
1539
  throw new Error("Name the file.");
1224
1540
  }
1541
+
1225
1542
  const file = existingPaths(root, slug).manifest;
1226
1543
  await writeJson(file, {
1227
1544
  ...(await readJson<object>(file)),
@@ -1237,6 +1554,7 @@ export async function setPrototypeStatus(
1237
1554
  if (!isOneOf(STATUSES, status)) {
1238
1555
  throw new Error(`The status must be one of ${STATUSES.join(", ")}.`);
1239
1556
  }
1557
+
1240
1558
  const file = existingPaths(root, slug).manifest;
1241
1559
  await writeJson(file, { ...(await readJson<object>(file)), status });
1242
1560
  }
@@ -1251,17 +1569,23 @@ export async function setPrototypeCover(
1251
1569
  root: string
1252
1570
  ): Promise<void> {
1253
1571
  const file = existingPaths(root, slug).manifest;
1572
+
1254
1573
  const { cover: _old, ...manifest } = await readJson<{ cover?: unknown }>(
1255
1574
  file
1256
1575
  );
1576
+
1257
1577
  if (cover === null) {
1258
1578
  await writeJson(file, manifest);
1579
+
1259
1580
  return;
1260
1581
  }
1582
+
1261
1583
  const checked = checkFrameAnchor(cover, "cover");
1584
+
1262
1585
  if ("problems" in checked) {
1263
1586
  throw new Error(checked.problems.join(" "));
1264
1587
  }
1588
+
1265
1589
  await writeJson(file, { ...manifest, cover: checked.frame });
1266
1590
  }
1267
1591
 
@@ -1282,18 +1606,27 @@ export async function duplicatePrototype(
1282
1606
  recursive: true,
1283
1607
  filter: (path) => splitPrototypeFile(root, path)?.part !== "comments",
1284
1608
  });
1285
- // A copy was never anything else: no name from before files/.
1609
+ // A copy was never anything else: no name from before files/, and its
1610
+ // manifest is file.json, whatever the original's is called.
1611
+ const copied = prototypePaths(root, copy).manifest;
1612
+
1286
1613
  const { was: _was, ...manifest } = await readJson<{
1287
1614
  title?: unknown;
1288
1615
  was?: unknown;
1289
- }>(to.manifest);
1616
+ }>(copied);
1617
+
1618
+ if (copied !== to.manifest) {
1619
+ await rm(copied);
1620
+ }
1621
+
1290
1622
  await writeJson(to.manifest, {
1291
1623
  ...manifest,
1292
1624
  title: `${manifest.title} (copy)`,
1293
1625
  status: "exploring",
1294
1626
  created: today ?? new Date().toISOString().slice(0, 10),
1295
- ...(person ? { createdBy: person } : {}),
1627
+ ...(person && { createdBy: person }),
1296
1628
  });
1629
+
1297
1630
  return { href: prototypePage(copy) };
1298
1631
  }
1299
1632
 
@@ -1325,24 +1658,31 @@ export async function addContributor(
1325
1658
  `Usage: npx dex contributor --name "<name>" --git "<git user>" --discipline <${DISCIPLINES.join("|")}>`
1326
1659
  );
1327
1660
  }
1661
+
1328
1662
  const login = isText(github) ? github.trim().replace(LEADING_AT_RE, "") : "";
1663
+
1329
1664
  if (github !== undefined && !GITHUB_LOGIN_RE.test(login)) {
1330
1665
  throw new Error(`"${github}" is not a GitHub username.`);
1331
1666
  }
1667
+
1332
1668
  const slug = slugify(name);
1669
+
1333
1670
  const added: Contributor = {
1334
1671
  slug,
1335
1672
  name: name.trim(),
1336
1673
  git: [git.trim()],
1337
1674
  discipline,
1338
- ...(login ? { github: login } : {}),
1675
+ ...(login && { github: login }),
1339
1676
  };
1677
+
1340
1678
  await changeContributors(root, (contributors) => {
1341
1679
  if (contributors.some((contributor) => contributor.slug === slug)) {
1342
1680
  throw new Error(`"${slug}" is already a contributor.`);
1343
1681
  }
1682
+
1344
1683
  return { result: undefined, write: [...contributors, added] };
1345
1684
  });
1685
+
1346
1686
  return slug;
1347
1687
  }
1348
1688
 
@@ -1361,9 +1701,14 @@ const changeContributors = <T>(
1361
1701
  inTurn(root, "contributors", CONTRIBUTORS_LOCK_STALE_MS, async () => {
1362
1702
  const path = join(root, "contributors.json");
1363
1703
  const { result, write } = change(await readContributors(path));
1704
+
1364
1705
  if (write) {
1365
- await replaceFile(path, formattedJson(write));
1706
+ await replaceFile(
1707
+ path,
1708
+ jsonInLayout(write, await readFile(path, "utf8").catch(() => undefined))
1709
+ );
1366
1710
  }
1711
+
1367
1712
  return result;
1368
1713
  });
1369
1714
 
@@ -1393,7 +1738,7 @@ export const currentPerson = async (
1393
1738
  try {
1394
1739
  return youOf(await identify(root))?.slug;
1395
1740
  } catch {
1396
- return;
1741
+ // Dex can't tell who you are: undefined.
1397
1742
  }
1398
1743
  };
1399
1744
 
@@ -1406,19 +1751,23 @@ export const currentPerson = async (
1406
1751
  export async function joinCurrentPerson(
1407
1752
  root: string
1408
1753
  ): Promise<Contributor | undefined> {
1409
- const [git, github] = await Promise.all([
1754
+ const [gitUser, github] = await Promise.all([
1410
1755
  yourGitUser(root),
1411
1756
  githubAccountLogin(),
1412
1757
  ]);
1758
+
1413
1759
  const { contributors } = await loadStudio(root);
1414
- const known = identityFrom(contributors, git, github);
1760
+ const known = identityFrom(contributors, gitUser, github);
1761
+
1415
1762
  if (!known.newcomer) {
1416
1763
  return known.contributor;
1417
1764
  }
1765
+
1418
1766
  // Decided again from the file as it is now: another save, or another
1419
1767
  // process, may have added you, or taken the slug you would have.
1420
1768
  const joined = await changeContributors(root, (current) => {
1421
- const { contributor, newcomer } = identityFrom(current, git, github);
1769
+ const { contributor, newcomer } = identityFrom(current, gitUser, github);
1770
+
1422
1771
  return newcomer
1423
1772
  ? {
1424
1773
  result: { you: newcomer, added: true },
@@ -1426,10 +1775,12 @@ export async function joinCurrentPerson(
1426
1775
  }
1427
1776
  : { result: { you: contributor, added: false } };
1428
1777
  });
1778
+
1429
1779
  if (joined.added && joined.you) {
1430
1780
  // Afterwards: a slow or missing GitHub CLI never holds up joining.
1431
1781
  linkGithub(root).catch(() => undefined);
1432
1782
  }
1783
+
1433
1784
  return joined.you;
1434
1785
  }
1435
1786
 
@@ -1445,6 +1796,7 @@ const gitFolders = new Map<string, string[]>();
1445
1796
  */
1446
1797
  const gitConfigFiles = (root: string): string[] => {
1447
1798
  let folders = gitFolders.get(root);
1799
+
1448
1800
  if (!folders) {
1449
1801
  const found = git(["rev-parse", "--git-dir", "--git-common-dir"], root);
1450
1802
  folders = [
@@ -1455,12 +1807,15 @@ const gitConfigFiles = (root: string): string[] => {
1455
1807
  .map((folder) => resolve(root, folder))
1456
1808
  ),
1457
1809
  ];
1810
+
1458
1811
  if (folders.length > 0) {
1459
1812
  gitFolders.set(root, folders);
1460
1813
  }
1461
1814
  }
1815
+
1462
1816
  const home = homedir();
1463
1817
  const global = process.env.GIT_CONFIG_GLOBAL;
1818
+
1464
1819
  return [
1465
1820
  ...(global ? [resolve(root, global)] : []),
1466
1821
  join(home, ".gitconfig"),
@@ -1473,17 +1828,17 @@ const gitConfigFiles = (root: string): string[] => {
1473
1828
  };
1474
1829
 
1475
1830
  /** When and how big each file is, as one string: "" for a file not there. */
1476
- const stamp = async (files: string[]): Promise<string> =>
1477
- (
1478
- await Promise.all(
1479
- files.map((file) =>
1480
- stat(file).then(
1481
- ({ mtimeMs, size }) => `${mtimeMs}:${size}`,
1482
- () => ""
1483
- )
1484
- )
1831
+ const stamp = async (files: string[]): Promise<string> => {
1832
+ const stamps = await Promise.all(
1833
+ files.map((file) =>
1834
+ stat(file)
1835
+ .then(({ mtimeMs, size }) => `${mtimeMs}:${size}`)
1836
+ .catch(() => "")
1485
1837
  )
1486
- ).join("|");
1838
+ );
1839
+
1840
+ return stamps.join("|");
1841
+ };
1487
1842
 
1488
1843
  const FILE_ORIGIN = "file:";
1489
1844
 
@@ -1508,20 +1863,26 @@ const readGitUser = (root: string): GitUser & { files: string[] } => {
1508
1863
  const fields = git(["config", "--list", "--show-origin", "-z"], root).split(
1509
1864
  "\0"
1510
1865
  );
1866
+
1511
1867
  const files = new Set<string>();
1512
1868
  const found: Record<string, string> = {};
1869
+
1513
1870
  for (let at = 0; at + 1 < fields.length; at += 2) {
1514
1871
  const origin = fields[at] ?? "";
1515
1872
  const entry = fields[at + 1] ?? "";
1873
+
1516
1874
  if (origin.startsWith(FILE_ORIGIN)) {
1517
1875
  files.add(resolve(root, origin.slice(FILE_ORIGIN.length)));
1518
1876
  }
1877
+
1519
1878
  const split = entry.indexOf("\n");
1520
1879
  const key = split === -1 ? entry : entry.slice(0, split);
1880
+
1521
1881
  if (key === "user.name" || key === "user.email") {
1522
1882
  found[key] = split === -1 ? "" : entry.slice(split + 1);
1523
1883
  }
1524
1884
  }
1885
+
1525
1886
  return {
1526
1887
  name: found["user.name"]?.trim() ?? "",
1527
1888
  email: found["user.email"]?.trim() ?? "",
@@ -1543,21 +1904,27 @@ const gitUsers = new Map<
1543
1904
  async function yourGitUser(root: string): Promise<GitUser> {
1544
1905
  // Hosted, "you" is whoever this request is from, never the machine's git.
1545
1906
  const person = hostedPerson();
1907
+
1546
1908
  if (person) {
1547
1909
  return { name: person.name, email: person.email, accountEmail: true };
1548
1910
  }
1911
+
1549
1912
  const base = gitConfigFiles(root);
1550
1913
  const global = process.env.GIT_CONFIG_GLOBAL ?? "";
1551
1914
  const kept = gitUsers.get(root);
1915
+
1552
1916
  if (kept) {
1553
1917
  const now = `${global}>${await stamp([...base, ...kept.files])}`;
1918
+
1554
1919
  if (kept.stamp === now) {
1555
1920
  return kept;
1556
1921
  }
1557
1922
  }
1923
+
1558
1924
  const read = readGitUser(root);
1559
1925
  const at = `${global}>${await stamp([...base, ...read.files])}`;
1560
1926
  gitUsers.set(root, { ...read, stamp: at });
1927
+
1561
1928
  return read;
1562
1929
  }
1563
1930
 
@@ -1571,6 +1938,7 @@ const githubHostsFile = (): string => {
1571
1938
  (process.platform === "win32" && process.env.AppData
1572
1939
  ? join(process.env.AppData, "GitHub CLI")
1573
1940
  : join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "gh"));
1941
+
1574
1942
  return join(folder, "hosts.yml");
1575
1943
  };
1576
1944
 
@@ -1590,23 +1958,27 @@ const SIGNED_OUT_EXIT = 1;
1590
1958
  * signed out or no CLI; throws when the CLI could not answer (it timed out,
1591
1959
  * or was stopped), so that is never taken for signed out.
1592
1960
  */
1593
- const askGithubCli = (host: string): Promise<string | undefined> =>
1594
- new Promise((done, failed) =>
1595
- execFile(
1961
+ const askGithubCli = async (host: string): Promise<string | undefined> => {
1962
+ try {
1963
+ const { stdout } = await execFileAsync(
1596
1964
  "gh",
1597
1965
  ["config", "get", "user", "--host", host],
1598
- { timeout: GH_TIMEOUT_MS },
1599
- (error, out) => {
1600
- if (!error) {
1601
- done(String(out).trim() || undefined);
1602
- } else if (error.code === SIGNED_OUT_EXIT || error.code === "ENOENT") {
1603
- done(undefined);
1604
- } else {
1605
- failed(error);
1606
- }
1607
- }
1608
- )
1609
- );
1966
+ { timeout: GH_TIMEOUT_MS }
1967
+ );
1968
+
1969
+ return stdout.trim() || undefined;
1970
+ } catch (error) {
1971
+ // SAFETY: execFile fails with an ExecFileException: its code is the exit
1972
+ // code, or the system error's when gh could not start.
1973
+ const { code } = error as ExecFileException;
1974
+
1975
+ if (code === SIGNED_OUT_EXIT || code === "ENOENT") {
1976
+ return undefined;
1977
+ }
1978
+
1979
+ throw error;
1980
+ }
1981
+ };
1610
1982
 
1611
1983
  /**
1612
1984
  * The account the GitHub CLI is signed in to, or undefined when there is no
@@ -1620,23 +1992,28 @@ export async function githubAccountLogin(): Promise<string | undefined> {
1620
1992
  if (isHosted()) {
1621
1993
  return;
1622
1994
  }
1995
+
1623
1996
  const host = githubHost();
1624
1997
  const file = githubHostsFile();
1998
+
1625
1999
  const changed =
1626
2000
  (await stamp([file])) ||
1627
2001
  String(Math.floor(Date.now() / GITHUB_LOGIN_KEPT_MS));
2002
+
1628
2003
  const key = `${host}>${file}>${changed}`;
2004
+
1629
2005
  if (githubAccount?.key !== key) {
1630
2006
  githubAccount = { key, login: askGithubCli(host) };
1631
2007
  }
2008
+
1632
2009
  const asked = githubAccount;
2010
+
1633
2011
  try {
1634
2012
  return await asked.login;
1635
2013
  } catch {
1636
2014
  if (githubAccount === asked) {
1637
2015
  githubAccount = undefined;
1638
2016
  }
1639
- return;
1640
2017
  }
1641
2018
  }
1642
2019
 
@@ -1663,12 +2040,13 @@ export interface Identity {
1663
2040
 
1664
2041
  /** Who you are in this workspace (identityFrom). */
1665
2042
  export async function identify(root: string): Promise<Identity> {
1666
- const [{ contributors }, git, github] = await Promise.all([
2043
+ const [{ contributors }, gitUser, github] = await Promise.all([
1667
2044
  loadStudio(root),
1668
2045
  yourGitUser(root),
1669
2046
  githubAccountLogin(),
1670
2047
  ]);
1671
- return identityFrom(contributors, git, github);
2048
+
2049
+ return identityFrom(contributors, gitUser, github);
1672
2050
  }
1673
2051
 
1674
2052
  /** The contributor who has `value` among their git names and emails. */
@@ -1677,6 +2055,7 @@ const gitNamed = (
1677
2055
  value: string
1678
2056
  ): Contributor | undefined => {
1679
2057
  const said = value.trim().toLowerCase();
2058
+
1680
2059
  return said
1681
2060
  ? contributors.find((contributor) =>
1682
2061
  contributor.git.some((name) => name.trim().toLowerCase() === said)
@@ -1696,50 +2075,61 @@ const gitNamed = (
1696
2075
  */
1697
2076
  export function identityFrom(
1698
2077
  contributors: Contributor[],
1699
- git: GitUser,
2078
+ gitUser: GitUser,
1700
2079
  github: string | undefined
1701
2080
  ): Identity {
1702
2081
  const account = github?.toLowerCase();
2082
+
1703
2083
  const byGithub = account
1704
2084
  ? contributors.find(
1705
2085
  (contributor) => contributor.github?.toLowerCase() === account
1706
2086
  )
1707
2087
  : undefined;
1708
- const byEmail = gitNamed(contributors, git.email);
1709
- const byName = git.accountEmail
2088
+
2089
+ const byEmail = gitNamed(contributors, gitUser.email);
2090
+
2091
+ const byName = gitUser.accountEmail
1710
2092
  ? undefined
1711
- : gitNamed(contributors, git.name);
2093
+ : gitNamed(contributors, gitUser.name);
2094
+
1712
2095
  if (byGithub) {
1713
2096
  const byGit = byEmail ?? byName;
2097
+
1714
2098
  // Your git user is theirs when it names them too: two can share a
1715
2099
  // name, never an email.
1716
2100
  const theirs = byEmail
1717
2101
  ? byEmail.slug === byGithub.slug
1718
- : gitNamed([byGithub], git.name) !== undefined;
2102
+ : gitNamed([byGithub], gitUser.name) !== undefined;
2103
+
1719
2104
  return {
1720
2105
  contributor: byGithub,
1721
2106
  github,
1722
2107
  via: "github",
1723
- ...(byGit && !theirs ? { gitSays: byGit } : {}),
2108
+ ...(byGit && !theirs && { gitSays: byGit }),
1724
2109
  };
1725
2110
  }
2111
+
1726
2112
  if (byEmail) {
1727
2113
  return { contributor: byEmail, github, via: "git" };
1728
2114
  }
2115
+
1729
2116
  const nameIsAnothers =
1730
2117
  account !== undefined &&
1731
2118
  byName?.github !== undefined &&
1732
2119
  byName.github.toLowerCase() !== account;
2120
+
1733
2121
  if (byName && !nameIsAnothers) {
1734
2122
  return { contributor: byName, github, via: "git" };
1735
2123
  }
1736
- const newcomer = newcomerFrom(contributors, git, github);
2124
+
2125
+ const newcomer = newcomerFrom(contributors, gitUser, github);
2126
+
1737
2127
  return {
1738
2128
  contributor: undefined,
1739
2129
  github,
1740
2130
  via: undefined,
1741
- ...(byName ? { gitSays: byName } : {}),
1742
- ...(newcomer ? { newcomer } : {}),
2131
+ ...(byName && { gitSays: byName }),
2132
+ ...(newcomer && { newcomer }),
1743
2133
  };
1744
2134
  }
1745
2135
 
@@ -1754,7 +2144,7 @@ const UNNAMED_SLUG = "someone";
1754
2144
  * app's `name[bot]` and its noreply email, GitHub's own Actions and
1755
2145
  * Dependabot, and the address GitHub commits from on the web.
1756
2146
  */
1757
- const BOT_RE = /\[bot\]|^(?:github-actions|dependabot|noreply@github\.com)$/i;
2147
+ const BOT_RE = /\[bot\]|^(?:github-actions|dependabot|noreply@github\.com)$/iu;
1758
2148
 
1759
2149
  /**
1760
2150
  * The contributor someone with this git user and GitHub account would be:
@@ -1766,34 +2156,46 @@ const BOT_RE = /\[bot\]|^(?:github-actions|dependabot|noreply@github\.com)$/i;
1766
2156
  */
1767
2157
  function newcomerFrom(
1768
2158
  contributors: Contributor[],
1769
- git: GitUser,
2159
+ gitUser: GitUser,
1770
2160
  github: string | undefined
1771
2161
  ): Contributor | undefined {
1772
2162
  const login = github && GITHUB_LOGIN_RE.test(github) ? github : undefined;
1773
- if ([git.name, git.email, login].some((said) => said && BOT_RE.test(said))) {
2163
+
2164
+ if (
2165
+ [gitUser.name, gitUser.email, login].some(
2166
+ (said) => said && BOT_RE.test(said)
2167
+ )
2168
+ ) {
1774
2169
  return;
1775
2170
  }
1776
- const name = git.name || login;
2171
+
2172
+ const name = gitUser.name || login;
2173
+
1777
2174
  if (!name) {
1778
2175
  return;
1779
2176
  }
2177
+
1780
2178
  const base = slugify(name) || slugify(login ?? "") || UNNAMED_SLUG;
1781
2179
  const taken = new Set(contributors.map((contributor) => contributor.slug));
1782
2180
  let slug = base;
2181
+
1783
2182
  for (let count = 2; taken.has(slug); count += 1) {
1784
2183
  slug = `${base}-${count}`;
1785
2184
  }
2185
+
1786
2186
  return {
1787
2187
  slug,
1788
2188
  name,
1789
2189
  git: [name],
1790
2190
  discipline: NEWCOMER_DISCIPLINE,
1791
- ...(login ? { github: login } : {}),
2191
+ ...(login && { github: login }),
1792
2192
  };
1793
2193
  }
1794
2194
 
1795
2195
  export async function whoami(root: string): Promise<Contributor | undefined> {
1796
- return (await identify(root)).contributor;
2196
+ const { contributor } = await identify(root);
2197
+
2198
+ return contributor;
1797
2199
  }
1798
2200
 
1799
2201
  /**
@@ -1803,24 +2205,27 @@ export async function whoami(root: string): Promise<Contributor | undefined> {
1803
2205
  */
1804
2206
  export async function githubLogin(root: string): Promise<string | undefined> {
1805
2207
  const account = await githubAccountLogin();
2208
+
1806
2209
  if (account && GITHUB_LOGIN_RE.test(account)) {
1807
2210
  return account;
1808
2211
  }
2212
+
1809
2213
  const email = git(["config", "user.email"], root);
1810
2214
  const noreply = GITHUB_NOREPLY_RE.exec(email)?.[1];
2215
+
1811
2216
  if (noreply && GITHUB_LOGIN_RE.test(noreply)) {
1812
2217
  return noreply;
1813
2218
  }
2219
+
1814
2220
  // Signed in with a token alone (GH_TOKEN, as in a codespace), the CLI's
1815
2221
  // config names no one: GitHub itself is asked whose the token is.
1816
- const login = await new Promise<string>((done) =>
1817
- execFile(
1818
- "gh",
1819
- ["api", "user", "--jq", ".login"],
1820
- { cwd: root, timeout: GH_TIMEOUT_MS },
1821
- (error, out) => done(error ? "" : String(out).trim())
1822
- )
1823
- );
2222
+ const login = await execFileAsync("gh", ["api", "user", "--jq", ".login"], {
2223
+ cwd: root,
2224
+ timeout: GH_TIMEOUT_MS,
2225
+ })
2226
+ .then(({ stdout }) => stdout.trim())
2227
+ .catch(() => "");
2228
+
1824
2229
  return GITHUB_LOGIN_RE.test(login) ? login : undefined;
1825
2230
  }
1826
2231
 
@@ -1830,15 +2235,20 @@ export async function githubLogin(root: string): Promise<string | undefined> {
1830
2235
  */
1831
2236
  export async function linkGithub(root: string): Promise<string | undefined> {
1832
2237
  const contributor = await whoami(root);
2238
+
1833
2239
  if (!contributor || contributor.github) {
1834
2240
  return;
1835
2241
  }
2242
+
1836
2243
  const login = await githubLogin(root);
2244
+
1837
2245
  if (!login) {
1838
2246
  return;
1839
2247
  }
2248
+
1840
2249
  return changeContributors(root, (contributors) => {
1841
2250
  const entry = contributors.find(({ slug }) => slug === contributor.slug);
2251
+
1842
2252
  return entry && !entry.github
1843
2253
  ? {
1844
2254
  result: login,
@@ -1858,14 +2268,18 @@ export async function linkGithub(root: string): Promise<string | undefined> {
1858
2268
  */
1859
2269
  export const changedFiles = (base: string, root: string): string[] => {
1860
2270
  const mergeBase = git(["merge-base", "HEAD", base], root);
2271
+
1861
2272
  const committed = mergeBase
1862
2273
  ? git(["diff", "--name-only", mergeBase, "HEAD"], root).split("\n")
1863
2274
  : [];
2275
+
1864
2276
  const working = git(["diff", "--name-only", "HEAD"], root).split("\n");
2277
+
1865
2278
  const untracked = git(
1866
2279
  ["ls-files", "--others", "--exclude-standard", "--full-name"],
1867
2280
  root
1868
2281
  ).split("\n");
2282
+
1869
2283
  return [...new Set([...committed, ...working, ...untracked])].filter(Boolean);
1870
2284
  };
1871
2285
 
@@ -1879,10 +2293,12 @@ export function allowedPrefixes(person: string, root: string): string[] {
1879
2293
  if (!isSlug(person)) {
1880
2294
  return [];
1881
2295
  }
2296
+
1882
2297
  // Git reports paths from the repository root; the studio may sit anywhere in it.
1883
2298
  const repository = git(["rev-parse", "--show-toplevel"], root) || root;
1884
2299
  const folder = relative(repository, root);
1885
2300
  const studio = folder ? `${folder}/` : "";
2301
+
1886
2302
  return [
1887
2303
  `${studio}${PROTOTYPES_FOLDER}/*/`,
1888
2304
  `${studio}${PROTOTYPES_FOLDER}/*/people/${person}/`,
@@ -1890,9 +2306,9 @@ export function allowedPrefixes(person: string, root: string): string[] {
1890
2306
  ];
1891
2307
  }
1892
2308
 
1893
- const PEOPLE_FOLDER_RE = /\/people\/[^/]+\//;
1894
- const STAR_RE = /\*/g;
1895
- const SPECIAL_RE = /[.+?^${}()|[\]\\]/g;
2309
+ const PEOPLE_FOLDER_RE = /\/people\/[^/]+\//u;
2310
+ const STAR_RE = /\*/gu;
2311
+ const SPECIAL_RE = /[.+?^${}()|[\]\\]/gu;
1896
2312
 
1897
2313
  /**
1898
2314
  * Whether a file is under a prefix. Someone's people/ folder is theirs even
@@ -1900,12 +2316,16 @@ const SPECIAL_RE = /[.+?^${}()|[\]\\]/g;
1900
2316
  */
1901
2317
  const underPrefix = (file: string, prefix: string): boolean => {
1902
2318
  const pattern = new RegExp(
1903
- `^${prefix.replace(SPECIAL_RE, "\\$&").replace(STAR_RE, "[^/]+")}`
2319
+ `^${prefix.replaceAll(SPECIAL_RE, "\\$&").replaceAll(STAR_RE, "[^/]+")}`,
2320
+ "u"
1904
2321
  );
2322
+
1905
2323
  const match = pattern.exec(file);
2324
+
1906
2325
  if (!match) {
1907
2326
  return false;
1908
2327
  }
2328
+
1909
2329
  return (
1910
2330
  PEOPLE_FOLDER_RE.test(prefix) ||
1911
2331
  !PEOPLE_FOLDER_RE.test(file.slice(match[0].length - 1))
@@ -1938,6 +2358,7 @@ export function framePageOf(
1938
2358
  ): string | undefined {
1939
2359
  const query = new URLSearchParams(frame.params ?? {});
1940
2360
  const search = query.size > 0 ? `?${query}` : "";
2361
+
1941
2362
  return framePage(slug, frame.view, search);
1942
2363
  }
1943
2364
 
@@ -1965,9 +2386,11 @@ async function snapshotOf(
1965
2386
  slug: string
1966
2387
  ): Promise<ViewShot | { problem: string }> {
1967
2388
  const href = framePageOf(slug, frame);
2389
+
1968
2390
  if (!href) {
1969
2391
  return { problem: `no snapshot: "${frame.view}" is not a view's name` };
1970
2392
  }
2393
+
1971
2394
  try {
1972
2395
  return await snapshotView(url, {
1973
2396
  href,
@@ -1978,6 +2401,7 @@ async function snapshotOf(
1978
2401
  if (error instanceof SnapshotError && error.status !== undefined) {
1979
2402
  return { problem: `no snapshot (${error.status}): ${error.message}` };
1980
2403
  }
2404
+
1981
2405
  throw error;
1982
2406
  }
1983
2407
  }
@@ -2008,41 +2432,52 @@ export async function snapshot(
2008
2432
  "Usage: npx dex snapshot --slug <file> [--view <view>] [--url <address>]"
2009
2433
  );
2010
2434
  }
2435
+
2011
2436
  const canvas = await readCanvas(slug, root);
2437
+
2012
2438
  if (canvas.sections.length === 0) {
2013
2439
  throw new Error(`${slug} has nothing on its canvas to snapshot.`);
2014
2440
  }
2441
+
2015
2442
  const frames = canvasFrames(canvas).flatMap(({ address, frame }) => {
2016
2443
  const view = viewOf(frame);
2444
+
2017
2445
  return view && (!only || view.view === only)
2018
2446
  ? [{ address, frame: view }]
2019
2447
  : [];
2020
2448
  });
2449
+
2021
2450
  if (only && frames.length === 0) {
2022
2451
  throw new Error(
2023
2452
  `${slug} has no frame on its canvas showing the view "${only}".`
2024
2453
  );
2025
2454
  }
2455
+
2026
2456
  const out = studioState(root).snapshotsOf(slug);
2027
2457
  await prepareState(root, out);
2028
2458
  const shots: Shot[] = [];
2459
+
2029
2460
  for (const { address, frame } of frames) {
2030
2461
  for (const scheme of COLOR_SCHEMES) {
2031
2462
  const shot = await snapshotOf(url, frame, scheme, slug);
2032
2463
  const named = `${address.section}/${address.row}/${address.frame}, ${scheme}`;
2464
+
2033
2465
  if ("problem" in shot) {
2034
2466
  shots.push({ frame: named, problems: [shot.problem] });
2035
2467
  continue;
2036
2468
  }
2469
+
2037
2470
  // The whole address: frame ids are unique only within their row.
2038
2471
  const file = join(
2039
2472
  out,
2040
2473
  `${address.section}--${address.row}--${address.frame}--${scheme}.png`
2041
2474
  );
2475
+
2042
2476
  await writeFile(file, shot.image);
2043
2477
  shots.push({ file, frame: named, problems: shot.problems });
2044
2478
  }
2045
2479
  }
2480
+
2046
2481
  return shots;
2047
2482
  }
2048
2483
 
@@ -2055,6 +2490,7 @@ const THREAD_USAGE =
2055
2490
 
2056
2491
  /** An agent's action before it is signed with the agent's name. */
2057
2492
  type UnsignedAction = WithoutAuthor<AgentAction>;
2493
+
2058
2494
  /** Each kind of action without its author (Omit, taken one kind at a time). */
2059
2495
  type WithoutAuthor<Action> = Action extends unknown
2060
2496
  ? Omit<Action, "author">
@@ -2070,21 +2506,27 @@ const threadChange = (values: CommandValues): ThreadChange | undefined => {
2070
2506
  const flag = (["acknowledge", "resolve", "dismiss"] as const).find(
2071
2507
  (name) => values[name]
2072
2508
  );
2509
+
2073
2510
  const actions: UnsignedAction[] = [];
2511
+
2074
2512
  if (flag === "resolve" || flag === "dismiss") {
2075
2513
  actions.push({ action: flag, note: values.note });
2076
2514
  } else {
2077
2515
  if (flag) {
2078
2516
  actions.push({ action: flag });
2079
2517
  }
2518
+
2080
2519
  if (isText(values.note)) {
2081
2520
  actions.push({ action: "reply", message: values.note, ask: values.ask });
2082
2521
  }
2083
2522
  }
2523
+
2084
2524
  if (actions.length === 0) {
2085
2525
  return;
2086
2526
  }
2527
+
2087
2528
  const author = values.agent ?? "Agent";
2529
+
2088
2530
  return Object.assign(
2089
2531
  {},
2090
2532
  ...actions.map((action) => agentChange({ ...action, author }))
@@ -2106,29 +2548,41 @@ export function createContentCommands({
2106
2548
  root?: string;
2107
2549
  }) {
2108
2550
  const root = content;
2551
+
2109
2552
  /** Which Dex serves this checkout, never only the configured port. */
2110
2553
  const running = () =>
2111
2554
  studioFor({ content, root: projectRoot, port: Number(port) });
2555
+
2112
2556
  const presence = openPresence(root);
2557
+
2113
2558
  return {
2114
2559
  async whoami(): Promise<void> {
2115
2560
  const contributor = await joinCurrentPerson(root);
2561
+
2116
2562
  if (!contributor) {
2117
2563
  print(NOT_RECOGNISED);
2118
2564
  process.exitCode = 1;
2565
+
2119
2566
  return;
2120
2567
  }
2568
+
2121
2569
  print(
2122
2570
  `${contributor.slug} (${contributor.name}, ${contributor.discipline})`
2123
2571
  );
2124
2572
  },
2125
2573
  async new(values: CommandValues): Promise<void> {
2126
2574
  // Yours unless an agent names another contributor.
2127
- const person =
2128
- values.person ?? values.owner ?? (await joinCurrentPerson(root))?.slug;
2575
+ let person = values.person ?? values.owner;
2576
+
2577
+ if (person === undefined) {
2578
+ const joined = await joinCurrentPerson(root);
2579
+ person = joined?.slug;
2580
+ }
2581
+
2129
2582
  if (!person) {
2130
2583
  throw new Error(NOT_RECOGNISED);
2131
2584
  }
2585
+
2132
2586
  const { folder, slug } = await createPrototype(
2133
2587
  {
2134
2588
  title: values.title,
@@ -2138,6 +2592,7 @@ export function createContentCommands({
2138
2592
  },
2139
2593
  root
2140
2594
  );
2595
+
2141
2596
  const canvas = prototypePage(slug, "canvas");
2142
2597
  print(`Created ${display(folder)}`);
2143
2598
  const found = await running();
@@ -2157,12 +2612,15 @@ export function createContentCommands({
2157
2612
  async check(unresolved: string[] = []): Promise<void> {
2158
2613
  const { problems, warnings } = await checkStudio(root, { designSystem });
2159
2614
  problems.push(...unresolved);
2615
+
2160
2616
  for (const warning of warnings) {
2161
2617
  print(`! ${warning}`);
2162
2618
  }
2619
+
2163
2620
  if (problems.length > 0) {
2164
2621
  throw new Error(`Dex check failed:\n - ${problems.join("\n - ")}`);
2165
2622
  }
2623
+
2166
2624
  print(
2167
2625
  warnings.length > 0
2168
2626
  ? `Dex check passed, with ${warnings.length} warning${warnings.length === 1 ? "" : "s"} (the lines with !).`
@@ -2170,26 +2628,34 @@ export function createContentCommands({
2170
2628
  );
2171
2629
  },
2172
2630
  async snapshot(values: CommandValues): Promise<void> {
2173
- let url = values.url;
2631
+ let { url } = values;
2632
+
2174
2633
  if (!url) {
2175
2634
  const found = await running();
2635
+
2176
2636
  if (found.kind !== "running") {
2177
2637
  throw new Error(notRunning(found));
2178
2638
  }
2639
+
2179
2640
  url = found.url;
2180
2641
  }
2642
+
2181
2643
  const shots = await snapshot({ ...values, url }, root);
2182
2644
  let problems = 0;
2645
+
2183
2646
  for (const shot of shots) {
2184
2647
  print(shot.file ? display(shot.file) : shot.frame);
2648
+
2185
2649
  for (const problem of shot.problems) {
2186
2650
  problems += 1;
2187
2651
  print(` ! ${problem}`);
2188
2652
  }
2189
2653
  }
2654
+
2190
2655
  print(
2191
2656
  `${shots.length} snapshots. Open each one and look before you call the work done.`
2192
2657
  );
2658
+
2193
2659
  if (problems > 0) {
2194
2660
  process.exitCode = 1;
2195
2661
  }
@@ -2199,6 +2665,7 @@ export function createContentCommands({
2199
2665
  (values.view && `view:${values.view}`) ||
2200
2666
  (values.doc && `doc:${values.doc}`) ||
2201
2667
  (values.slug ? "prototype" : undefined);
2668
+
2202
2669
  if (values.clear) {
2203
2670
  await presence.clear({
2204
2671
  slug: values.slug,
@@ -2206,13 +2673,16 @@ export function createContentCommands({
2206
2673
  agent: values.agent,
2207
2674
  });
2208
2675
  print("Presence cleared.");
2676
+
2209
2677
  return;
2210
2678
  }
2679
+
2211
2680
  if (!(isSlug(values.slug) && target)) {
2212
2681
  throw new Error(
2213
2682
  'Usage: npx dex presence --slug <file> [--view <name> | --doc <name>] [--agent "<name>"] [--note "<what>"] [--clear]'
2214
2683
  );
2215
2684
  }
2685
+
2216
2686
  await presence.mark({
2217
2687
  slug: values.slug,
2218
2688
  target,
@@ -2224,57 +2694,77 @@ export function createContentCommands({
2224
2694
  /** Prints the threads waiting for an agent, or all, and returns them. */
2225
2695
  async threads(values: CommandValues) {
2226
2696
  const threads = openThreads(root);
2697
+
2227
2698
  const listed = await threads.list({
2228
- ...(values.slug ? { prototype: values.slug } : {}),
2699
+ ...(values.slug && { prototype: values.slug }),
2229
2700
  status: values.all ? "all" : "waiting",
2230
2701
  });
2702
+
2231
2703
  if (listed.length === 0) {
2232
2704
  print(
2233
2705
  values.all ? "No comments yet." : "No comments waiting for an agent."
2234
2706
  );
2707
+
2235
2708
  return [];
2236
2709
  }
2710
+
2237
2711
  // Each with its file's title beside its name: a folder may be an id.
2238
2712
  const titleOf = await prototypeTitles(root, listed);
2713
+
2239
2714
  const described = listed.map((thread) => {
2240
2715
  const { id, prototype, ...rest } = describeThread(thread);
2241
2716
  const fileTitle = titleOf(thread);
2242
- return { id, prototype, ...(fileTitle ? { fileTitle } : {}), ...rest };
2717
+
2718
+ return { id, prototype, ...(fileTitle && { fileTitle }), ...rest };
2243
2719
  });
2720
+
2244
2721
  print(JSON.stringify(described, null, 2));
2722
+
2245
2723
  return described;
2246
2724
  },
2247
2725
  async thread(values: CommandValues): Promise<void> {
2248
2726
  const change = threadChange(values);
2727
+
2249
2728
  if (!(values.id && change)) {
2250
2729
  throw new Error(THREAD_USAGE);
2251
2730
  }
2731
+
2252
2732
  const answered = await openThreads(root).change(values.id, change);
2733
+
2253
2734
  if (!answered) {
2254
2735
  throw new Error(THREAD_USAGE);
2255
2736
  }
2737
+
2256
2738
  if (answered.problems) {
2257
2739
  throw new Error(answered.problems.join(" "));
2258
2740
  }
2741
+
2259
2742
  print(`Updated ${values.id}.`);
2260
2743
  },
2261
2744
  scope(values: CommandValues): void {
2262
2745
  const person = values.person ?? values.owner;
2746
+
2263
2747
  if (!isSlug(person)) {
2264
2748
  throw new Error("Usage: npx dex scope --person <slug> [--base main]");
2265
2749
  }
2750
+
2266
2751
  const outside = outOfScope(
2267
2752
  changedFiles(values.base ?? "main", root),
2268
2753
  allowedPrefixes(person, root)
2269
2754
  );
2755
+
2270
2756
  if (outside.length === 0) {
2271
2757
  print(`All changes are inside ${person}'s scope.`);
2758
+
2272
2759
  return;
2273
2760
  }
2761
+
2274
2762
  print(`Changes outside ${person}'s scope (need studio review):`);
2763
+
2275
2764
  for (const file of outside) {
2276
2765
  print(` ${file}`);
2277
2766
  }
2767
+
2278
2768
  process.exitCode = 1;
2279
2769
  },
2280
2770
  };