@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
@@ -1,3 +1,4 @@
1
+ /* oxlint-disable anti-slop/no-runtime-typeof, anti-slop/no-unknown-parameters -- the studio's routes check request bodies, which come from outside */
1
2
  // What the development server answers under /__studio/. It is given the
2
3
  // project, its threads, an event hub and an agent launcher, so the Vite
3
4
  // plugin only mounts it and tests serve it from a plain Node server, without
@@ -5,8 +6,27 @@
5
6
 
6
7
  import { execFile } from "node:child_process";
7
8
  import { existsSync } from "node:fs";
9
+ import { readFile } from "node:fs/promises";
8
10
  import type { IncomingMessage, ServerResponse } from "node:http";
9
11
  import { dirname, isAbsolute, join, relative, sep } from "node:path";
12
+
13
+ import { noDesktop, type ProjectDesktop } from "@dexhq/desktop";
14
+ import {
15
+ agentRootOf,
16
+ isLaunchAgent,
17
+ launchAgent,
18
+ addAgent,
19
+ agentSetups,
20
+ } from "@dexhq/harness/agents";
21
+ import {
22
+ connectedAgents,
23
+ isWatching,
24
+ NotAnOldSessionError,
25
+ setWatching,
26
+ stopAgentServer,
27
+ trackAgents,
28
+ } from "@dexhq/harness/channel";
29
+
10
30
  import type { ResolvedDesignSystem } from "../config/design-system.ts";
11
31
  import { findBiome } from "../content/biome.ts";
12
32
  import { saveCaptures } from "../content/capture.ts";
@@ -23,10 +43,10 @@ import {
23
43
  duplicatePrototype,
24
44
  joinCurrentPerson,
25
45
  readCanvasRevision,
26
- readPrototypeAnnotations,
27
- removeAnnotation,
28
- type SavedAnnotations,
29
- saveAnnotation,
46
+ readPrototypePicks,
47
+ removePick,
48
+ type SavedPicks,
49
+ savePick,
30
50
  setPrototypeCover,
31
51
  setPrototypeStatus,
32
52
  setPrototypeTitle,
@@ -60,28 +80,18 @@ import { editText } from "../content/text-edit.ts";
60
80
  import { replaceText, undoReplace } from "../content/text-replace.ts";
61
81
  import type { ThreadModule } from "../content/thread-module.ts";
62
82
  import {
63
- dismissThreadsOn,
64
83
  emptyTrash,
65
84
  removedViewsWithComments,
66
85
  trashHolds,
67
86
  trashViews,
68
87
  } from "../content/trash.ts";
69
- import { type Pasted, PasteProblem, readPaste } from "../paste/paste.ts";
88
+ import { type Pasted, PasteProblemError, readPaste } from "../paste/paste.ts";
70
89
  import {
71
90
  EXTENSION_DIR,
72
91
  isOlder,
73
92
  PACKAGE_ROOT,
74
93
  runningVersion,
75
94
  } from "../paths.ts";
76
- import {
77
- bundlePath,
78
- type DesktopApp,
79
- type DesktopAppUnavailable,
80
- desktopAppState,
81
- installDesktopApp,
82
- type LaunchServices,
83
- removeDesktopApp,
84
- } from "../setup/desktop-app.ts";
85
95
  import { checkGitSetup, checkLog, realGitProbes } from "../setup/git-checks.ts";
86
96
  import {
87
97
  BUILD_DEFAULTS,
@@ -144,39 +154,43 @@ import {
144
154
  type StudioMethodOf,
145
155
  type StudioRouteName,
146
156
  } from "../shared/studio-routes.ts";
147
- import {
148
- addAgent,
149
- agentRootOf,
150
- agentSetups,
151
- isLaunchAgent,
152
- launchAgent,
153
- } from "./agents.ts";
157
+ import { agentsPlace } from "./agents-place.ts";
154
158
  import {
155
159
  isAllowedRequest,
156
160
  isFromThisMachine,
157
161
  isLoopbackHost,
158
162
  type ServedHosts,
159
163
  } from "./allowed-request.ts";
160
- import { AvatarRefused, removeAvatar, writeAvatar } from "./avatars.ts";
164
+ import { AvatarRefusedError, removeAvatar, writeAvatar } from "./avatars.ts";
161
165
  import { readBuildSettings, writeBuildSettings } from "./build-settings.ts";
162
166
  import { notesSince } from "./changelog.ts";
163
- import {
164
- connectedAgents,
165
- isWatching,
166
- NotAnOldSession,
167
- setWatching,
168
- stopAgentServer,
169
- trackAgents,
170
- } from "./channel.ts";
171
167
  import {
172
168
  codebaseSkills,
173
169
  readCommandMenu,
174
170
  skillFolders,
175
171
  writeCommandMenu,
176
172
  } from "./command-settings.ts";
177
- import { COMMENT_HANDLERS } from "./comments/routes.ts";
173
+ import {
174
+ acceptSuggestion,
175
+ dismissCommentsOnViews,
176
+ startComment,
177
+ } from "./comments/actions.ts";
178
+ import {
179
+ answer as commentAnswer,
180
+ COMMENT_HANDLERS,
181
+ personComments,
182
+ } from "./comments/routes.ts";
178
183
  import { exportInChild } from "./export/run.ts";
179
184
  import { type Feature, features } from "./features.ts";
185
+ import { gitAskBody } from "./git-asks.ts";
186
+ import { forgetPullRequests, mergePullRequest } from "./git-host.ts";
187
+ import { settlePaused, undoPaused } from "./git-paused.ts";
188
+ import { readGitSettings, writeGitSettings } from "./git-settings.ts";
189
+ import {
190
+ moveToPullRequest,
191
+ queueSync,
192
+ switchToSyncBranch,
193
+ } from "./git-sync.ts";
180
194
  import {
181
195
  branchPrototypes,
182
196
  clashesIn,
@@ -194,15 +208,6 @@ import {
194
208
  switchBranch,
195
209
  syncBranch,
196
210
  } from "./git.ts";
197
- import { gitAskBody } from "./git-asks.ts";
198
- import { forgetPullRequests, mergePullRequest } from "./git-host.ts";
199
- import { settlePaused, undoPaused } from "./git-paused.ts";
200
- import { readGitSettings, writeGitSettings } from "./git-settings.ts";
201
- import {
202
- moveToPullRequest,
203
- queueSync,
204
- switchToSyncBranch,
205
- } from "./git-sync.ts";
206
211
  import { writeInstructions } from "./instructions.ts";
207
212
  import {
208
213
  currentActivity,
@@ -211,7 +216,7 @@ import {
211
216
  ranBeforeThis,
212
217
  updateMachine,
213
218
  } from "./machine-update.ts";
214
- import { readAuthor, readMe } from "./me.ts";
219
+ import { readMe } from "./me.ts";
215
220
  import { loadPeople } from "./people.ts";
216
221
  import { framePictures, latestAround, latestChange } from "./pictures.ts";
217
222
  import { readPreferences, savePreferences } from "./preferences.ts";
@@ -227,14 +232,21 @@ import {
227
232
  } from "./restart.ts";
228
233
  import { otherServers, readRoster, stopOthers } from "./roster.ts";
229
234
  import { readSaved, restoreSaved } from "./saved.ts";
230
- import { acceptSuggestion } from "./spec-suggestions.ts";
231
235
  import { writeFocus } from "./state.ts";
232
236
  import { pullBaseAndUpdate, syncAndUpdate } from "./sync-install.ts";
233
- import { type Updated, UpdateStopped, updateStudio } from "./update-studio.ts";
234
- import { checkForUpdateWithin } from "./updates.ts";
237
+ import {
238
+ type Updated,
239
+ UpdateStoppedError,
240
+ updateStudio,
241
+ } from "./update-studio.ts";
242
+ import {
243
+ checkForUpdate,
244
+ checkForUpdateWithin,
245
+ updateCheckProblem,
246
+ } from "./updates.ts";
235
247
  import { markWelcomed, readWelcome } from "./welcome.ts";
236
248
  import {
237
- IconRefused,
249
+ IconRefusedError,
238
250
  readWorkspace,
239
251
  readWorkspaceIcon,
240
252
  removeWorkspaceIcon,
@@ -245,13 +257,16 @@ import { zipFolder } from "./zip.ts";
245
257
 
246
258
  const PREFIX = "/__studio/";
247
259
  const UPDATE_WAIT_MS = 3000;
248
- const TRAILING_SLASH_RE = /\/$/;
260
+ const TRAILING_SLASH_RE = /\/$/u;
249
261
  const METHODS = ["GET", "POST", "PUT", "DELETE"] as const;
250
262
  const WITH_BODY = new Set<string>(["POST", "PUT"]);
251
263
  export const MAX_BODY_BYTES = 1_000_000;
252
- // A snapshot copied with the extension brings its images, up to 6 MB of them
253
- // (extension/messages.ts); images pasted or dropped come in whole.
254
- export const MAX_CAPTURE_BYTES = 24_000_000;
264
+
265
+ // A snapshot copied with the extension brings its images, up to 18 MB of them
266
+ // (packages/extension/messages.ts), and the clipboard carries it all as
267
+ // base64, a third larger again; images pasted or dropped come in whole.
268
+ export const MAX_CAPTURE_BYTES = 40_000_000;
269
+
255
270
  // A Markup review brings a snapshot of each page commented on.
256
271
  export const MAX_REVIEW_BYTES = 120_000_000;
257
272
  const KEEP_ALIVE_MS = 25_000;
@@ -291,12 +306,14 @@ export type AgentLauncher = (
291
306
  export type Formatter = (file: string) => Promise<void>;
292
307
 
293
308
  /** Unchecked: each handler checks the fields it relies on. */
309
+ // oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- a request body, which each route checks
294
310
  type RequestBody = Record<string, unknown>;
295
311
 
296
312
  /**
297
313
  * For a body passed on as it came: each prototype change refuses a slug that
298
314
  * names none (prototypeExists).
299
315
  */
316
+ // oxlint-disable-next-line anti-slop/no-unknown-returns -- matches any function, to name its first argument's type
300
317
  type ArgumentOf<F extends (...args: never[]) => unknown> = Parameters<F>[0];
301
318
 
302
319
  type Method = (typeof METHODS)[number];
@@ -322,6 +339,7 @@ interface Failure {
322
339
  }
323
340
 
324
341
  /** The modules routes call throw only Errors. */
342
+ // SAFETY: a thrown value that is no Error reads undefined here, which the message still shows.
325
343
  const messageOf = (error: unknown): string => (error as Error).message;
326
344
 
327
345
  const sendJson = (
@@ -347,6 +365,7 @@ const send = (response: ServerResponse, answered: unknown): void => {
347
365
 
348
366
  export function eventHub(): EventHub {
349
367
  const listeners = new Set<(event: StudioEvent) => void>();
368
+
350
369
  return {
351
370
  send: (event) => {
352
371
  for (const listener of listeners) {
@@ -355,6 +374,7 @@ export function eventHub(): EventHub {
355
374
  },
356
375
  listen: (listener) => {
357
376
  listeners.add(listener);
377
+
358
378
  return () => {
359
379
  listeners.delete(listener);
360
380
  };
@@ -373,11 +393,13 @@ const readBody = (
373
393
  request: IncomingMessage,
374
394
  limit = MAX_BODY_BYTES
375
395
  ): Promise<string> =>
396
+ // oxlint-disable-next-line promise/avoid-new -- reads the stream to its end, keeping its size within the limit as it goes
376
397
  new Promise((resolve, reject) => {
377
398
  const chunks: Buffer[] = [];
378
399
  let size = 0;
379
400
  request.on("data", (chunk: Buffer) => {
380
401
  size += chunk.length;
402
+
381
403
  if (size <= limit) {
382
404
  chunks.push(chunk);
383
405
  }
@@ -397,9 +419,11 @@ const readJson = async (
397
419
  limit?: number
398
420
  ): Promise<RequestBody | undefined> => {
399
421
  const text = await readBody(request, limit);
422
+
400
423
  if (!text) {
401
424
  return;
402
425
  }
426
+
403
427
  try {
404
428
  return JSON.parse(text);
405
429
  } catch {
@@ -409,12 +433,16 @@ const readJson = async (
409
433
 
410
434
  const formatter = (content: string): Formatter => {
411
435
  const biome = findBiome(content);
436
+
412
437
  return (file) =>
438
+ // oxlint-disable-next-line promise/avoid-new -- resolves whether or not Biome formatted the file
413
439
  new Promise((done) => {
414
440
  if (!biome) {
415
441
  done();
442
+
416
443
  return;
417
444
  }
445
+
418
446
  execFile(biome, ["format", "--write", file], () => done());
419
447
  });
420
448
  };
@@ -435,9 +463,11 @@ const UNKNOWN_PROTOTYPE = "Unknown file.";
435
463
  */
436
464
  const whoChanges = async (content: string): Promise<string> => {
437
465
  const person = await joinCurrentPerson(content);
466
+
438
467
  if (!person) {
439
468
  throw new Problems(403, [NOT_RECOGNISED]);
440
469
  }
470
+
441
471
  return person.slug;
442
472
  };
443
473
 
@@ -447,9 +477,11 @@ const prototypeNamed = (
447
477
  { mustExist = true }: { mustExist?: boolean } = {}
448
478
  ): ResolvedPrototype => {
449
479
  const prototype = resolvePrototype(content, reference, { mustExist });
480
+
450
481
  if (!prototype) {
451
482
  throw new Problems(400, [UNKNOWN_PROTOTYPE]);
452
483
  }
484
+
453
485
  return prototype;
454
486
  };
455
487
 
@@ -460,8 +492,8 @@ type StudioPages = ReturnType<typeof studioPages>;
460
492
 
461
493
  interface RouteContext {
462
494
  body: RequestBody | undefined;
463
- /** Where this studio can make its app, asked as a desktop route answers. */
464
- desktop: () => DesktopAppHost;
495
+ /** This studio's app, asked as a desktop route answers. */
496
+ desktop: () => ProjectDesktop;
465
497
  events: EventHub;
466
498
  format: Formatter;
467
499
  launcher: AgentLauncher;
@@ -484,11 +516,13 @@ async function loadCanvas({ project, prototype }: PrototypeContext) {
484
516
  const { slug } = prototype;
485
517
  // Nobody's revision when Dex can't tell who this is: a save asks.
486
518
  const person = (await currentPerson(project.content)) ?? "";
519
+
487
520
  const { canvas, revision } = await readCanvasRevision(
488
521
  slug,
489
522
  person,
490
523
  project.content
491
524
  );
525
+
492
526
  return { ...canvas, person, revision };
493
527
  }
494
528
 
@@ -501,23 +535,28 @@ async function saveCanvas({ project, prototype, body, url }: PrototypeContext) {
501
535
  const { slug } = prototype;
502
536
  const person = await whoChanges(project.content);
503
537
  const revision = url.searchParams.get("revision") ?? undefined;
538
+
504
539
  const saved = await writeCanvas(
505
540
  { slug, person, canvas: body, revision },
506
541
  project.content
507
542
  );
543
+
508
544
  if (saved.stale) {
509
545
  throw new Problems(409, ["The canvas changed since it was read."]);
510
546
  }
547
+
511
548
  if (saved.problems) {
512
549
  throw new Problems(422, saved.problems);
513
550
  }
551
+
514
552
  const { renamed } = saved;
553
+
515
554
  return {
516
555
  ...saved.canvas,
517
556
  person: saved.person,
518
557
  revision: saved.revision,
519
- ...(Object.keys(renamed).length > 0 ? { renamed } : {}),
520
- ...(saved.large ? { large: true as const } : {}),
558
+ ...(Object.keys(renamed).length > 0 && { renamed }),
559
+ ...(saved.large && { large: true as const }),
521
560
  };
522
561
  }
523
562
 
@@ -539,60 +578,89 @@ const listRemovedViews = async (context: PrototypeContext) => ({
539
578
  trash: await trashHolds(context.project.content),
540
579
  });
541
580
 
581
+ /**
582
+ * A view's file as it is on disk, from whoever's folder it is in (viewFiles):
583
+ * what a frame's Copy as React copies.
584
+ */
585
+ async function loadViewSource({ project, prototype, url }: PrototypeContext) {
586
+ const view = url.searchParams.get("view") ?? "";
587
+ const views = await viewFiles(project.content, prototype.slug);
588
+ const found = views.get(view);
589
+
590
+ // Gone since it was listed: not there either.
591
+ const source =
592
+ found && (await readFile(found.file, "utf8").catch(() => undefined));
593
+
594
+ if (!(found && source !== undefined)) {
595
+ throw new Problems(404, ["That view is not there."]);
596
+ }
597
+
598
+ return { source };
599
+ }
600
+
542
601
  async function trashRemovedViews(context: PrototypeContext) {
543
602
  const { project, prototype, body, threads } = context;
544
603
  const { slug } = prototype;
604
+
605
+ // Who moves them, read once: the views go to their folder's owner only,
606
+ // and the comments on them are dismissed in their name.
607
+ const comments = await personComments({ project, threads }, { slug });
608
+ const person = comments.author.id;
609
+
610
+ if (!person) {
611
+ throw new Problems(403, [NOT_RECOGNISED]);
612
+ }
613
+
545
614
  const trashed = await trashViews(
546
- {
547
- slug,
548
- person: await whoChanges(project.content),
549
- views: body?.views,
550
- },
615
+ { slug, person, views: body?.views },
551
616
  project.content
552
617
  );
618
+
553
619
  if (trashed.problems) {
554
620
  throw new Problems(422, trashed.problems);
555
621
  }
622
+
556
623
  // The views moved whatever the comments do: a workspace out of reach
557
624
  // leaves its threads open, as they were.
558
- const dismissed = await dismissThreadsOn(threads, {
559
- author: (await readAuthor(project.content)).name,
560
- prototype: slug,
561
- views: trashed.views,
562
- }).catch(() => []);
625
+ const dismissed = await dismissCommentsOnViews(comments, trashed.views).catch(
626
+ () => []
627
+ );
628
+
563
629
  return { ...trashed, dismissed };
564
630
  }
565
631
 
566
632
  const emptyTheTrash = async ({ project }: RouteContext) => {
567
633
  await emptyTrash(project.content);
634
+
568
635
  return {};
569
636
  };
570
637
 
571
- const listConnectedAgents = async ({ project, threads }: RouteContext) => ({
572
- agents: await connectedAgents(project.content, { threads }),
638
+ const listConnectedAgents = async ({ project }: RouteContext) => ({
639
+ agents: await connectedAgents(agentsPlace(project.content)),
573
640
  });
574
641
 
575
642
  /** Only on this machine, where that process runs. */
576
- const stopOldAgent = async ({
577
- project,
578
- body,
579
- request,
580
- threads,
581
- }: RouteContext) => {
643
+ const stopOldAgent = async ({ project, body, request }: RouteContext) => {
582
644
  onlyFromThisMachine(request, "Stop agents from the machine Dex runs on.");
583
645
  const pid = body?.pid;
646
+
584
647
  if (!(typeof pid === "number" && Number.isInteger(pid))) {
585
648
  throw new Problems(422, ["Say which agent to stop, by its process."]);
586
649
  }
650
+
587
651
  try {
588
- await stopAgentServer(project.content, pid, threads);
652
+ await stopAgentServer(agentsPlace(project.content), pid);
589
653
  } catch (error) {
590
- if (error instanceof NotAnOldSession) {
654
+ if (error instanceof NotAnOldSessionError) {
591
655
  throw new Problems(409, [error.message]);
592
656
  }
657
+
593
658
  throw error;
594
659
  }
595
- return { agents: await connectedAgents(project.content, { threads }) };
660
+
661
+ return {
662
+ agents: await connectedAgents(agentsPlace(project.content)),
663
+ };
596
664
  };
597
665
 
598
666
  const listAgentSetups = async ({ project }: RouteContext) => ({
@@ -613,6 +681,7 @@ async function addAgentSetup(context: RouteContext) {
613
681
  agentRootOf(project.root)
614
682
  )
615
683
  );
684
+
616
685
  return listAgentSetups(context);
617
686
  }
618
687
 
@@ -620,10 +689,13 @@ async function addAgentSetup(context: RouteContext) {
620
689
  const openInTerminal = ({ project, launcher, body, request }: RouteContext) => {
621
690
  onlyFromThisMachine(request, "Open agents from the machine Dex runs on.");
622
691
  const agent = body?.agent;
692
+
623
693
  if (!isLaunchAgent(agent)) {
624
694
  throw cantOpen(agent);
625
695
  }
696
+
626
697
  const agentRoot = agentRootOf(project.root);
698
+
627
699
  return agentRoot === project.root
628
700
  ? launcher(agent, project.root)
629
701
  : launcher(agent, project.root, agentRoot);
@@ -637,16 +709,20 @@ const PREFERENCES_ELSEWHERE = "Choose your agent on the machine Dex runs on.";
637
709
 
638
710
  const loadPreferences = ({ request }: RouteContext) => {
639
711
  onlyFromThisMachine(request, PREFERENCES_ELSEWHERE);
712
+
640
713
  return readPreferences();
641
714
  };
642
715
 
643
716
  async function savePersonalPreferences({ body, request }: RouteContext) {
644
717
  onlyFromThisMachine(request, PREFERENCES_ELSEWHERE);
645
718
  const agent = body?.defaultAgent ?? null;
719
+
646
720
  if (!(agent === null || isLaunchAgent(agent))) {
647
721
  throw cantOpen(agent);
648
722
  }
723
+
649
724
  await savePreferences({ defaultAgent: agent });
725
+
650
726
  return readPreferences();
651
727
  }
652
728
 
@@ -655,12 +731,14 @@ const WELCOME_ELSEWHERE = "Dex welcomes you on the machine it runs on.";
655
731
 
656
732
  function loadWelcome({ project, request }: RouteContext) {
657
733
  onlyFromThisMachine(request, WELCOME_ELSEWHERE);
734
+
658
735
  return readWelcome(project.content);
659
736
  }
660
737
 
661
738
  async function answerWelcome({ body, request }: RouteContext) {
662
739
  onlyFromThisMachine(request, WELCOME_ELSEWHERE);
663
740
  await markWelcomed(body?.answer === "sent" ? "sent" : "skipped");
741
+
664
742
  return {};
665
743
  }
666
744
 
@@ -684,9 +762,13 @@ function onlyFromThisMachine(request: IncomingMessage, problem: string): void {
684
762
  }
685
763
  }
686
764
 
687
- async function loadUpdate({ project }: RouteContext) {
765
+ async function loadUpdate({ project, url }: RouteContext) {
688
766
  const machine = await machineState(project);
767
+ const current = machine.installed ?? machine.running;
768
+ // ?fresh=1, from Check for Updates: npm is asked now, and waited on.
769
+ const fresh = url.searchParams.get("fresh") === "1";
689
770
  const from = await ranBeforeThis(project.content);
771
+
690
772
  const updated =
691
773
  from && isOlder(from, runningVersion)
692
774
  ? {
@@ -694,35 +776,52 @@ async function loadUpdate({ project }: RouteContext) {
694
776
  notes: await notesSince(from, runningVersion),
695
777
  }
696
778
  : undefined;
779
+
697
780
  const remote = Boolean(await remoteOf(project.content));
698
781
  const share = shareOf(await readGitSettings(project.root));
782
+
699
783
  return {
700
784
  machine,
701
- ...(updated ? { updated } : {}),
785
+ ...(updated && { updated }),
702
786
  pullRequest: remote && share === "pull-requests",
703
787
  restarts: canRestart(),
704
788
  run: RUN_ID,
705
789
  running: runningVersion,
706
790
  syncs: remote && share === "sync",
707
- update: await checkForUpdateWithin(
708
- UPDATE_WAIT_MS,
709
- project.content,
710
- project.root,
711
- { current: machine.installed ?? machine.running }
712
- ),
791
+ update: fresh
792
+ ? await checkForUpdate(project.content, project.root, {
793
+ current,
794
+ fresh,
795
+ })
796
+ : await checkForUpdateWithin(
797
+ UPDATE_WAIT_MS,
798
+ project.content,
799
+ project.root,
800
+ { current }
801
+ ),
802
+ ...(fresh ? await freshProblem(project) : undefined),
713
803
  };
714
804
  }
715
805
 
806
+ /** Why npm could not say just now, for a fresh check that it could not. */
807
+ async function freshProblem({ content, root }: ProjectFolders) {
808
+ const problem = await updateCheckProblem(content, root);
809
+
810
+ return problem ? { checkProblem: problem } : {};
811
+ }
812
+
716
813
  async function updateThisMachine({ project, request }: RouteContext) {
717
814
  onlyFromThisMachine(
718
815
  request,
719
816
  "Open Dex at localhost on the machine it runs on to update it."
720
817
  );
818
+
721
819
  return await queueSync(project.content, "step", () => updateMachine(project));
722
820
  }
723
821
 
724
822
  const updateActivity = ({ project }: RouteContext) => {
725
823
  const doing = currentActivity(project.content);
824
+
726
825
  return doing ? { doing } : {};
727
826
  };
728
827
 
@@ -731,9 +830,10 @@ const updateActivity = ({ project }: RouteContext) => {
731
830
  * answers the same route while no Dex does.
732
831
  */
733
832
  async function restartStatus({ project }: RouteContext) {
734
- const working = (await openPresence(project.content).list()).some(
735
- (entry) => !isTeammate(entry)
736
- );
833
+ const listed = await openPresence(project.content).list();
834
+
835
+ const working = listed.some((entry) => !isTeammate(entry));
836
+
737
837
  return { state: "ready" as const, run: RUN_ID, agentWorking: working };
738
838
  }
739
839
 
@@ -742,15 +842,19 @@ async function restartStudio({ project, request }: RouteContext) {
742
842
  request,
743
843
  "Open Dex at localhost on the machine it runs on to restart it."
744
844
  );
845
+
745
846
  if (orphaned()) {
746
847
  throw new Problems(409, [ORPHANED_LINE]);
747
848
  }
849
+
748
850
  if (!canRestart()) {
749
851
  throw new Problems(409, [
750
852
  "This Dex can’t restart itself. Stop it and start it again.",
751
853
  ]);
752
854
  }
855
+
753
856
  await restartWhenIdle(project.content);
857
+
754
858
  return { restartingFrom: RUN_ID };
755
859
  }
756
860
 
@@ -765,6 +869,7 @@ async function stopOtherDexes({ project, request }: RouteContext) {
765
869
  request,
766
870
  "Open Dex at localhost on the machine it runs on to stop other Dexes."
767
871
  );
872
+
768
873
  return {
769
874
  stopped: await stopOthers(project.content, projectId(project.root)),
770
875
  };
@@ -777,12 +882,13 @@ async function updateFromNotice({ project, events, request }: RouteContext) {
777
882
  );
778
883
  const settings = await readGitSettings(project.root);
779
884
  let updated: Updated | null;
885
+
780
886
  try {
781
887
  updated = await queueSync(project.content, "step", () =>
782
888
  updateStudio({ content: project.content, root: project.root, settings })
783
889
  );
784
890
  } catch (error) {
785
- throw new Problems(error instanceof UpdateStopped ? 409 : 500, [
891
+ throw new Problems(error instanceof UpdateStoppedError ? 409 : 500, [
786
892
  messageOf(error),
787
893
  ]);
788
894
  } finally {
@@ -790,29 +896,18 @@ async function updateFromNotice({ project, events, request }: RouteContext) {
790
896
  // It synced: every page's branch and changes move.
791
897
  events.send(studioEvent.git());
792
898
  }
899
+
793
900
  if (!updated) {
794
901
  throw new Problems(409, ["Dex is already up to date."]);
795
902
  }
903
+
796
904
  if (updated.restartingFrom) {
797
905
  restartWhenIdle(project.content);
798
906
  }
907
+
799
908
  return updated;
800
909
  }
801
910
 
802
- /**
803
- * `home` is the folder whose Applications the app goes in; `launchServices`
804
- * registers its URL scheme, and forgets it on remove.
805
- */
806
- export type DesktopAppHost =
807
- | {
808
- app: DesktopApp;
809
- home: string;
810
- launchServices: LaunchServices;
811
- open: (path: string) => Promise<void>;
812
- reveal: (path: string) => Promise<void>;
813
- }
814
- | { unavailable: DesktopAppUnavailable };
815
-
816
911
  /**
817
912
  * The app writes outside the project and makes something that runs code, so
818
913
  * only this machine, addressed by a loopback name, may ask; and a change
@@ -821,73 +916,44 @@ export type DesktopAppHost =
821
916
  */
822
917
  function fromThisMac(request: IncomingMessage, change: boolean): void {
823
918
  onlyFromThisMachine(request, "Install the app from the Mac Dex runs on.");
919
+
824
920
  if (change && !request.headers.origin) {
825
921
  throw new Problems(403, ["Install the app from Dex's Settings."]);
826
922
  }
827
923
  }
828
924
 
829
- const desktopAnswer = async (
830
- desktop: DesktopAppHost
831
- ): Promise<DesktopAppAnswer> =>
832
- "unavailable" in desktop
833
- ? { available: false, why: desktop.unavailable }
834
- : {
835
- available: true,
836
- ...(await desktopAppState(desktop.app, desktop.home)),
837
- };
838
-
839
- const loadDesktopApp = ({ request, desktop }: RouteContext) => {
925
+ const loadDesktopApp = ({
926
+ request,
927
+ desktop,
928
+ }: RouteContext): Promise<DesktopAppAnswer> => {
840
929
  fromThisMac(request, false);
841
- return desktopAnswer(desktop());
930
+
931
+ return desktop().answer();
842
932
  };
843
933
 
844
- async function changeDesktopApp({ request, desktop, body }: RouteContext) {
934
+ const changeDesktopApp = ({
935
+ request,
936
+ desktop,
937
+ body,
938
+ }: RouteContext): Promise<DesktopAppAnswer> => {
845
939
  fromThisMac(request, true);
846
- const host = desktop();
847
- if ("unavailable" in host) {
848
- throw new Problems(409, [
849
- host.unavailable === "hosted"
850
- ? "A hosted studio can't install an app."
851
- : "Installing outside the browser is macOS-only for now.",
852
- ]);
853
- }
854
- const { app, home, reveal, open, launchServices } = host;
855
- switch (body?.action) {
856
- case "install": {
857
- const path = await refusable(() =>
858
- installDesktopApp(app, home, launchServices)
859
- );
860
- await reveal(path).catch(() => undefined);
861
- break;
862
- }
863
- case "open": {
864
- if (!(await desktopAppState(app, home)).installed) {
865
- throw new Problems(409, ["Install the app first."]);
866
- }
867
- await refusable(() => open(bundlePath(home)));
868
- break;
869
- }
870
- case "remove":
871
- await refusable(() => removeDesktopApp(app, home, launchServices));
872
- break;
873
- default:
874
- throw new Problems(400, [
875
- 'Send an action: "install", "open" or "remove".',
876
- ]);
877
- }
878
- return desktopAnswer(host);
879
- }
940
+ const action = body?.action;
941
+
942
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- a JSON body's action is whatever was sent
943
+ return desktop().change(typeof action === "string" ? action : undefined);
944
+ };
880
945
 
881
946
  const readWatch = async ({ project }: RouteContext) => ({
882
- on: await isWatching(project.content),
947
+ on: await isWatching(agentsPlace(project.content)),
883
948
  });
884
949
 
885
950
  /** Every open page hears it, so each switch shows the same. */
886
951
  const setWatch = ({ project, body, events, pages }: RouteContext) =>
887
952
  pages.inWatchOrder(async () => {
888
- await setWatching(project.content, Boolean(body?.on));
889
- const on = await isWatching(project.content);
953
+ await setWatching(agentsPlace(project.content), Boolean(body?.on));
954
+ const on = await isWatching(agentsPlace(project.content));
890
955
  events.send(studioEvent.watch(on));
956
+
891
957
  return { on };
892
958
  });
893
959
 
@@ -906,46 +972,55 @@ async function saveSnapshots(
906
972
  cell?: Cell
907
973
  ) {
908
974
  const person = await whoChanges(project.content);
909
- // No captured event: a paste lands where the pointer is, in view, so the
910
- // canvas does not move to it.
975
+
976
+ // No captured event: the page that pasted goes to what it made itself.
911
977
  return await refusable(() =>
912
978
  saveCaptures({ slug: target.slug, person, captures, cell }, project.content)
913
979
  );
914
980
  }
915
981
 
916
982
  const cellFrom = (value: unknown): Cell | undefined => {
983
+ // SAFETY: each field is checked below before the value is taken as a Cell.
984
+ // oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- a request body, checked field by field below
917
985
  const cell = value as Partial<Record<keyof Cell, unknown>> | undefined;
986
+
918
987
  const fits =
919
988
  typeof cell?.section === "string" &&
920
989
  (cell.row === undefined || typeof cell.row === "string") &&
921
990
  typeof cell.step === "number" &&
922
991
  Number.isInteger(cell.step) &&
923
992
  cell.step >= 1;
993
+
994
+ // SAFETY: fits checked every field a Cell has.
924
995
  return fits ? (cell as Cell) : undefined;
925
996
  };
926
997
 
927
998
  async function pasteSnapshots(context: RouteContext) {
928
999
  const { body } = context;
929
1000
  let pasted: Pasted;
1001
+
930
1002
  try {
931
1003
  pasted = await readPaste(body ?? {});
932
1004
  } catch (error) {
933
- if (error instanceof PasteProblem) {
1005
+ if (error instanceof PasteProblemError) {
934
1006
  throw new Problems(error.status, [error.message]);
935
1007
  }
1008
+
936
1009
  throw error;
937
1010
  }
1011
+
938
1012
  const { saved, large } = await saveSnapshots(
939
1013
  context,
940
1014
  body ?? {},
941
1015
  pasted.captures,
942
1016
  cellFrom(body?.cell)
943
1017
  );
1018
+
944
1019
  return {
945
1020
  from: pasted.from,
946
1021
  saved: saved.map(({ name, frame }) => ({ name, frame })),
947
1022
  images: pasted.images,
948
- ...(large ? { large: true as const } : {}),
1023
+ ...(large && { large: true as const }),
949
1024
  };
950
1025
  }
951
1026
 
@@ -957,10 +1032,13 @@ async function pasteSnapshots(context: RouteContext) {
957
1032
  function showOnCanvas({ project, events, pages, body }: RouteContext) {
958
1033
  const { slug } = prototypeNamed(project.content, body ?? {});
959
1034
  const frame = body?.frame;
1035
+
960
1036
  if (typeof frame !== "string" || frame.split("/").length !== 3) {
961
1037
  throw new Problems(400, ['Say which frame, as "section/row/frame".']);
962
1038
  }
1039
+
963
1040
  events.send(studioEvent.show(slug, frame));
1041
+
964
1042
  return { pages: pages.listening() };
965
1043
  }
966
1044
 
@@ -970,43 +1048,58 @@ function showOnCanvas({ project, events, pages, body }: RouteContext) {
970
1048
  */
971
1049
  async function addBlankFrame({ project, events, body }: RouteContext) {
972
1050
  const { slug, view, frame, canvas, component, reveal } = body ?? {};
1051
+
973
1052
  if (!(isSlug(slug) && isSlug(view)) || typeof frame !== "string") {
974
1053
  throw new Problems(400, ["Say where the frame goes."]);
975
1054
  }
1055
+
976
1056
  if (component !== undefined) {
977
1057
  needsFeature("stickers");
978
1058
  }
1059
+
979
1060
  if (
980
1061
  component !== undefined &&
1062
+ // SAFETY: isInsertable checks every field.
981
1063
  !isInsertable(component as Partial<InsertedComponent>)
982
1064
  ) {
983
1065
  throw new Problems(400, ["That is not a component the studio can add."]);
984
1066
  }
1067
+
1068
+ // SAFETY: isInsertable checked it just above.
985
1069
  const source =
986
1070
  component === undefined
987
1071
  ? BLANK_VIEW
988
1072
  : componentView(component as InsertedComponent);
1073
+
989
1074
  prototypeNamed(project.content, { slug });
990
- if ((await viewFiles(project.content, slug)).has(view)) {
1075
+
1076
+ const views = await viewFiles(project.content, slug);
1077
+
1078
+ if (views.has(view)) {
991
1079
  throw new Problems(409, ["That view already exists."]);
992
1080
  }
1081
+
993
1082
  const person = await whoChanges(project.content);
1083
+
994
1084
  const saved = await writeCanvas(
995
1085
  { slug, person, canvas, views: { [view]: source } },
996
1086
  project.content
997
1087
  );
1088
+
998
1089
  if (saved.problems) {
999
1090
  throw new Problems(422, saved.problems);
1000
1091
  }
1092
+
1001
1093
  // Before the studio reloads to find the view, so the canvas shows it; not
1002
1094
  // for a frame drawn where the person is looking.
1003
1095
  if (reveal !== false) {
1004
1096
  events.send(studioEvent.captured(slug, frame));
1005
1097
  }
1098
+
1006
1099
  return {
1007
1100
  view,
1008
1101
  frame,
1009
- ...(saved.canvas && saved.large ? { large: true as const } : {}),
1102
+ ...(saved.canvas && saved.large && { large: true as const }),
1010
1103
  };
1011
1104
  }
1012
1105
 
@@ -1017,11 +1110,13 @@ async function addBlankFrame({ project, events, body }: RouteContext) {
1017
1110
  */
1018
1111
  async function changeText({ project, body }: RouteContext) {
1019
1112
  const { folder, slug } = prototypeNamed(project.content, body ?? {});
1113
+
1020
1114
  const own = join(
1021
1115
  folder,
1022
1116
  STUDIO_FILES.people,
1023
1117
  await whoChanges(project.content)
1024
1118
  );
1119
+
1025
1120
  // The text as the canvas sends it; editText checks there is some.
1026
1121
  const result = await editText(
1027
1122
  { content: project.content, own, slug },
@@ -1031,9 +1126,11 @@ async function changeText({ project, body }: RouteContext) {
1031
1126
  place: typeof body?.place === "string" ? body.place : undefined,
1032
1127
  }
1033
1128
  );
1129
+
1034
1130
  if (!("file" in result)) {
1035
1131
  throw new Problems(409, [result.reason]);
1036
1132
  }
1133
+
1037
1134
  return result;
1038
1135
  }
1039
1136
 
@@ -1044,20 +1141,27 @@ async function changeText({ project, body }: RouteContext) {
1044
1141
  */
1045
1142
  async function replaceOnCanvas({ project, body }: RouteContext) {
1046
1143
  const { folder } = prototypeNamed(project.content, body ?? {});
1144
+
1047
1145
  const own = join(
1048
1146
  folder,
1049
1147
  STUDIO_FILES.people,
1050
1148
  await whoChanges(project.content)
1051
1149
  );
1150
+
1052
1151
  if (typeof body?.undo === "string") {
1053
1152
  return await undoReplace(own, body.undo);
1054
1153
  }
1154
+
1055
1155
  const { find, to, seen } = body ?? {};
1056
- if (
1057
- !(typeof find === "string" && typeof to === "string" && Array.isArray(seen))
1058
- ) {
1156
+
1157
+ if (!(
1158
+ typeof find === "string" &&
1159
+ typeof to === "string" &&
1160
+ Array.isArray(seen)
1161
+ )) {
1059
1162
  throw new Problems(400, ["Say what to find, and what to change it to."]);
1060
1163
  }
1164
+
1061
1165
  return await replaceText(
1062
1166
  own,
1063
1167
  find,
@@ -1072,36 +1176,35 @@ const needsFeature = (name: Feature) => {
1072
1176
  }
1073
1177
  };
1074
1178
 
1075
- async function loadAnnotations({ project, prototype }: PrototypeContext) {
1076
- const { annotations } = await readPrototypeAnnotations(
1077
- prototype.slug,
1078
- project.content
1079
- );
1080
- return { annotations };
1179
+ async function loadPicks({ project, prototype }: PrototypeContext) {
1180
+ const { picks } = await readPrototypePicks(prototype.slug, project.content);
1181
+
1182
+ return { picks };
1081
1183
  }
1082
1184
 
1083
- const savedAnnotations = (saved: SavedAnnotations) => {
1185
+ const savedPicks = (saved: SavedPicks) => {
1084
1186
  if (saved.problems) {
1085
1187
  throw new Problems(422, saved.problems);
1086
1188
  }
1087
- return { annotations: saved.annotations };
1189
+
1190
+ return { picks: saved.picks };
1088
1191
  };
1089
1192
 
1090
- const saveOwnAnnotation = async (context: PrototypeContext) =>
1091
- savedAnnotations(
1092
- await saveAnnotation(
1193
+ const saveOwnPick = async (context: PrototypeContext) =>
1194
+ savedPicks(
1195
+ await savePick(
1093
1196
  {
1094
1197
  slug: context.prototype.slug,
1095
1198
  person: await whoChanges(context.project.content),
1096
- annotation: context.body,
1199
+ pick: context.body,
1097
1200
  },
1098
1201
  context.project.content
1099
1202
  )
1100
1203
  );
1101
1204
 
1102
- const removeOwnAnnotation = async (context: PrototypeContext) =>
1103
- savedAnnotations(
1104
- await removeAnnotation(
1205
+ const removeOwnPick = async (context: PrototypeContext) =>
1206
+ savedPicks(
1207
+ await removePick(
1105
1208
  {
1106
1209
  slug: context.prototype.slug,
1107
1210
  person: await whoChanges(context.project.content),
@@ -1115,17 +1218,21 @@ const removeOwnAnnotation = async (context: PrototypeContext) =>
1115
1218
  async function changeProps({ project, body }: RouteContext) {
1116
1219
  needsFeature("inspector");
1117
1220
  const { folder } = prototypeNamed(project.content, body ?? {});
1221
+
1118
1222
  const result = await editProps(
1119
1223
  project.content,
1120
1224
  folder,
1121
1225
  typeof body?.place === "string" ? body.place : undefined,
1226
+ // SAFETY: an object of prop changes; editProps checks each.
1122
1227
  body?.props && typeof body.props === "object"
1123
1228
  ? (body.props as Record<string, PropChange>)
1124
1229
  : undefined
1125
1230
  );
1231
+
1126
1232
  if (!("file" in result)) {
1127
1233
  throw new Problems(409, [result.reason]);
1128
1234
  }
1235
+
1129
1236
  return result;
1130
1237
  }
1131
1238
 
@@ -1133,16 +1240,20 @@ async function changeProps({ project, body }: RouteContext) {
1133
1240
  async function insertIntoView({ project, body }: RouteContext) {
1134
1241
  needsFeature("stickers");
1135
1242
  const { folder } = prototypeNamed(project.content, body ?? {});
1243
+
1136
1244
  const result = await insertComponent(
1137
1245
  project.content,
1138
1246
  folder,
1139
1247
  typeof body?.place === "string" ? body.place : undefined,
1140
1248
  typeof body?.position === "string" ? body.position : undefined,
1249
+ // SAFETY: insertComponent checks it with isInsertable.
1141
1250
  body?.component as Partial<InsertedComponent> | undefined
1142
1251
  );
1252
+
1143
1253
  if (!("file" in result)) {
1144
1254
  throw new Problems(409, [result.reason]);
1145
1255
  }
1256
+
1146
1257
  return result;
1147
1258
  }
1148
1259
 
@@ -1150,16 +1261,21 @@ function shotOf({ request, body, pageBase }: RouteContext) {
1150
1261
  if (!body) {
1151
1262
  throw new Problems(400, ["Say which view to capture."]);
1152
1263
  }
1264
+
1153
1265
  const site = `http://localhost:${request.socket.localPort}${pageBase}`;
1266
+
1154
1267
  return screenshotFrame(site, body);
1155
1268
  }
1156
1269
 
1157
1270
  async function screenshotView(context: RouteContext) {
1158
- return new Reply(200, (await shotOf(context)).image, "image/png");
1271
+ const shot = await shotOf(context);
1272
+
1273
+ return new Reply(200, shot.image, "image/png");
1159
1274
  }
1160
1275
 
1161
1276
  async function snapshotOfView(context: RouteContext): Promise<SnapshotBody> {
1162
1277
  const { image, problems } = await shotOf(context);
1278
+
1163
1279
  return { image: image.toString("base64"), problems };
1164
1280
  }
1165
1281
 
@@ -1197,19 +1313,22 @@ async function pictureOfView({
1197
1313
  response,
1198
1314
  }: RouteContext) {
1199
1315
  const href = typeof body?.href === "string" ? body.href : "";
1316
+
1200
1317
  if (!(body && isViewPage(href))) {
1201
1318
  throw new Problems(400, ["Say which view to picture."]);
1202
1319
  }
1320
+
1203
1321
  const { folder } = prototypeNamed(project.content, href);
1204
1322
  const address = viewInFrame(href);
1205
- if (
1206
- !(
1207
- address &&
1208
- (await viewFiles(project.content, address.slug)).has(address.view)
1209
- )
1210
- ) {
1323
+
1324
+ const views = address
1325
+ ? await viewFiles(project.content, address.slug)
1326
+ : undefined;
1327
+
1328
+ if (!(address && views?.has(address.view))) {
1211
1329
  throw new Problems(NOT_THERE, ["That view is not there yet."]);
1212
1330
  }
1331
+
1213
1332
  const stamp = Math.max(
1214
1333
  await latestChange(
1215
1334
  project.content,
@@ -1220,19 +1339,26 @@ async function pictureOfView({
1220
1339
  skip: [project.content],
1221
1340
  })
1222
1341
  );
1342
+
1223
1343
  response.setHeader("X-Studio-Stamp", String(stamp));
1344
+
1224
1345
  if (Number(body.stamp) === stamp) {
1225
1346
  return new Reply(204, "", "image/jpeg");
1226
1347
  }
1348
+
1227
1349
  if (body.stamp === undefined) {
1228
1350
  const last = await pictures.last(body, project.content);
1351
+
1229
1352
  if (last && last.stamp !== stamp) {
1230
1353
  response.setHeader("X-Studio-Stamp", String(last.stamp));
1231
1354
  response.setHeader(STALE_PICTURE_HEADER, "1");
1355
+
1232
1356
  return new Reply(200, last.image, "image/jpeg");
1233
1357
  }
1234
1358
  }
1359
+
1235
1360
  const site = `http://localhost:${request.socket.localPort}${pageBase}`;
1361
+
1236
1362
  return new Reply(
1237
1363
  200,
1238
1364
  await pictures.picture(site, body, stamp, project.content),
@@ -1261,47 +1387,59 @@ async function reviewFileOf(
1261
1387
  > {
1262
1388
  if (!isPageReview(file)) {
1263
1389
  const read = parseReviewFile(file);
1390
+
1264
1391
  return read.review
1265
1392
  ? { review: read.review }
1266
1393
  : { problems: [REVIEW_FILE_PROBLEMS[read.problem]] };
1267
1394
  }
1395
+
1268
1396
  const read = parsePageReview(file);
1397
+
1269
1398
  if (!read.review) {
1270
1399
  return { problems: [PAGE_REVIEW_PROBLEMS[read.problem]] };
1271
1400
  }
1401
+
1272
1402
  const person = await whoChanges(content);
1403
+
1273
1404
  const placed = await refusable(() =>
1274
1405
  placeReviewPages({ slug, person, review: read.review }, content)
1275
1406
  );
1407
+
1276
1408
  return { review: placed.file, pages: placed.added };
1277
1409
  }
1278
1410
 
1279
1411
  async function importReviews({ project, url, body, threads }: RouteContext) {
1280
1412
  const { slug: prototype } = prototypeOf(project.content, url);
1281
1413
  const files: unknown = body?.reviews;
1414
+
1282
1415
  if (!Array.isArray(files) || files.length === 0) {
1283
1416
  throw new Problems(400, ["Send the reviews to import."]);
1284
1417
  }
1418
+
1285
1419
  const reviews: ReviewImported[] = [];
1420
+
1286
1421
  for (const file of files) {
1287
1422
  const read = await reviewFileOf(project.content, prototype, file);
1423
+
1288
1424
  if (!read.review) {
1289
1425
  reviews.push({ problems: read.problems });
1290
1426
  continue;
1291
1427
  }
1292
- const answer = await threads.importReview(prototype, read.review);
1428
+
1429
+ const imported = await threads.importReview(prototype, read.review);
1293
1430
  reviews.push(
1294
- answer.problems
1295
- ? { problems: answer.problems }
1431
+ imported.problems
1432
+ ? { problems: imported.problems }
1296
1433
  : {
1297
1434
  title: read.review.review.title,
1298
1435
  reviewer: read.review.reviewer.name,
1299
- added: answer.added,
1300
- skipped: answer.skipped,
1301
- ...(read.pages ? { pages: read.pages } : {}),
1436
+ added: imported.added,
1437
+ skipped: imported.skipped,
1438
+ ...(read.pages && { pages: read.pages }),
1302
1439
  }
1303
1440
  );
1304
1441
  }
1442
+
1305
1443
  return { reviews };
1306
1444
  }
1307
1445
 
@@ -1312,34 +1450,32 @@ async function acceptSpecSuggestion({
1312
1450
  threads,
1313
1451
  }: RouteContext) {
1314
1452
  const id = body?.id;
1453
+
1315
1454
  if (typeof id !== "string") {
1316
1455
  throw new Problems(400, ["Name the suggestion to accept."]);
1317
1456
  }
1318
- const person = await whoChanges(project.content);
1319
- const result = await acceptSuggestion({
1320
- author: (await readAuthor(project.content)).name,
1321
- id,
1322
- person,
1323
- prototype: prototypeOf(project.content, url).slug,
1324
- root: project.content,
1325
- threads,
1326
- });
1327
- if ("problems" in result) {
1328
- throw new Problems(result.status, result.problems);
1329
- }
1330
- return result.thread;
1457
+
1458
+ const comments = await personComments(
1459
+ { project, threads },
1460
+ { slug: url.searchParams.get("slug") }
1461
+ );
1462
+
1463
+ return commentAnswer(await acceptSuggestion(comments, id));
1331
1464
  }
1332
1465
 
1333
1466
  const instructionsPath = (url: URL): string => {
1334
1467
  const path = url.searchParams.get("path");
1468
+
1335
1469
  if (!(path && isEditableMarkdown(path))) {
1336
1470
  throw new Problems(400, ["That file is not one of the guidelines."]);
1337
1471
  }
1472
+
1338
1473
  return path;
1339
1474
  };
1340
1475
 
1341
1476
  const loadInstructions = async ({ project, url }: RouteContext) => {
1342
1477
  const path = instructionsPath(url);
1478
+
1343
1479
  return { path, source: await readText(join(project.content, path)) };
1344
1480
  };
1345
1481
 
@@ -1356,14 +1492,17 @@ async function saveInstructions({ project, url, body }: RouteContext) {
1356
1492
  const part = splitPrototypePath(path);
1357
1493
  const isSomeonesFile = owner !== undefined || part !== undefined;
1358
1494
  const person = isSomeonesFile ? await whoChanges(project.content) : undefined;
1495
+
1359
1496
  if (owner && owner !== person) {
1360
1497
  throw new Problems(403, ["Those are someone else's guidelines."]);
1361
1498
  }
1499
+
1362
1500
  // A spec or a document anyone edits: a change made meanwhile is merged
1363
1501
  // in, not lost.
1364
1502
  const source = await refusable(() =>
1365
1503
  writeInstructions(project.content, path, body?.source, body?.base)
1366
1504
  );
1505
+
1367
1506
  return { path, source };
1368
1507
  }
1369
1508
 
@@ -1378,19 +1517,23 @@ const GIT_ELSEWHERE =
1378
1517
  */
1379
1518
  async function loadGit({ project, url, request }: RouteContext) {
1380
1519
  const here = isThisMachine(request);
1520
+
1381
1521
  if (url.searchParams.get("fetch") === "1" && here) {
1382
1522
  await fetchRemote(project.content);
1383
1523
  forgetPullRequests();
1384
1524
  }
1525
+
1385
1526
  const state = await gitStatus(
1386
1527
  project.content,
1387
1528
  await readGitSettings(project.root)
1388
1529
  );
1530
+
1389
1531
  return here || !state.repo ? state : { ...state, folder: undefined };
1390
1532
  }
1391
1533
 
1392
1534
  async function loadGitBranches({ project, url }: RouteContext) {
1393
1535
  const prototype = url.searchParams.get("prototype");
1536
+
1394
1537
  return {
1395
1538
  branches: prototype
1396
1539
  ? await prototypeBranches(
@@ -1416,6 +1559,8 @@ const GIT_STEP_NAMES: Record<GitStepName, true> = {
1416
1559
  "undo-paused": true,
1417
1560
  ask: true,
1418
1561
  };
1562
+
1563
+ // SAFETY: GIT_STEP_NAMES has one key per GitStepName.
1419
1564
  const GIT_STEPS = Object.keys(GIT_STEP_NAMES) as GitStepName[];
1420
1565
 
1421
1566
  const oneOf = <T extends string>(
@@ -1423,6 +1568,7 @@ const oneOf = <T extends string>(
1423
1568
  value: unknown
1424
1569
  ): value is T => list.some((item) => item === value);
1425
1570
 
1571
+ // oxlint-disable-next-line anti-slop/no-unknown-returns -- git's problems or the error as it was, sent back as is
1426
1572
  const gitProblems = (error: unknown): unknown =>
1427
1573
  error instanceof GitError
1428
1574
  ? new Problems(409, [
@@ -1441,14 +1587,17 @@ async function takeGitStep({
1441
1587
  }: RouteContext) {
1442
1588
  onlyFromThisMachine(request, GIT_ELSEWHERE);
1443
1589
  const step: unknown = body?.step;
1590
+
1444
1591
  if (!oneOf<GitStepName>(GIT_STEPS, step)) {
1445
1592
  throw new Problems(400, [`A step is one of: ${GIT_STEPS.join(", ")}.`]);
1446
1593
  }
1594
+
1447
1595
  const settings = await readGitSettings(project.root);
1448
1596
  const cwd = project.content;
1597
+
1449
1598
  try {
1450
1599
  switch (step) {
1451
- case "branch":
1600
+ case "branch": {
1452
1601
  await queueSync(cwd, "step", () =>
1453
1602
  createBranch(
1454
1603
  cwd,
@@ -1458,43 +1607,62 @@ async function takeGitStep({
1458
1607
  )
1459
1608
  );
1460
1609
  break;
1461
- case "switch":
1610
+ }
1611
+
1612
+ case "switch": {
1462
1613
  await queueSync(cwd, "step", () =>
1463
1614
  switchBranch(cwd, String(body?.name ?? ""))
1464
1615
  );
1465
1616
  break;
1466
- case "switch-to-sync":
1617
+ }
1618
+
1619
+ case "switch-to-sync": {
1467
1620
  await switchToSyncBranch(cwd, settings);
1468
1621
  break;
1469
- case "commit":
1622
+ }
1623
+
1624
+ case "commit": {
1470
1625
  await queueSync(cwd, "step", () =>
1471
1626
  commitAll(cwd, String(body?.message ?? ""))
1472
1627
  );
1473
1628
  break;
1629
+ }
1630
+
1474
1631
  // Each moves the branch: one running beside a Sync could undo it.
1475
- case "push":
1632
+ case "push": {
1476
1633
  await queueSync(cwd, "step", () => pushBranch(cwd));
1477
1634
  break;
1478
- case "sync":
1635
+ }
1636
+
1637
+ case "sync": {
1479
1638
  await queueSync(cwd, "step", () => syncBranch(cwd));
1480
1639
  break;
1481
- case "merge":
1640
+ }
1641
+
1642
+ case "merge": {
1482
1643
  await queueSync(cwd, "step", () =>
1483
1644
  mergeBranchPullRequest(cwd, settings)
1484
1645
  );
1485
1646
  break;
1647
+ }
1648
+
1486
1649
  case "settle": {
1487
1650
  const keep = keepOf(body);
1651
+
1488
1652
  if (!keep) {
1489
1653
  throw new Problems(400, ["keep is mine or theirs."]);
1490
1654
  }
1655
+
1491
1656
  await queueSync(cwd, "step", () => settlePaused(cwd, keep));
1492
1657
  break;
1493
1658
  }
1494
- case "undo-paused":
1659
+
1660
+ case "undo-paused": {
1495
1661
  await queueSync(cwd, "step", () => undoPaused(cwd));
1496
1662
  break;
1497
- default:
1663
+ }
1664
+
1665
+ default: {
1498
1666
  return await askAgent({
1499
1667
  project,
1500
1668
  body,
@@ -1503,12 +1671,14 @@ async function takeGitStep({
1503
1671
  pageBase,
1504
1672
  settings,
1505
1673
  });
1674
+ }
1506
1675
  }
1507
1676
  } catch (error) {
1508
1677
  throw gitProblems(error);
1509
1678
  } finally {
1510
1679
  events.send(studioEvent.git());
1511
1680
  }
1681
+
1512
1682
  return gitStatus(cwd, settings);
1513
1683
  }
1514
1684
 
@@ -1523,8 +1693,10 @@ async function runSync({ project, body, events, request }: RouteContext) {
1523
1693
  const keep = keepOf(body);
1524
1694
  const move = typeof body?.move === "string" ? body.move : undefined;
1525
1695
  const kind = keep === undefined && move === undefined ? "press" : "choice";
1696
+
1526
1697
  return await queueSync(cwd, kind, async (): Promise<SyncResult> => {
1527
1698
  let gitError: GitError | undefined;
1699
+
1528
1700
  try {
1529
1701
  if (move === undefined) {
1530
1702
  ({ stopped: gitError } = await syncAndUpdate({
@@ -1540,10 +1712,12 @@ async function runSync({ project, body, events, request }: RouteContext) {
1540
1712
  if (!(error instanceof GitError)) {
1541
1713
  throw error;
1542
1714
  }
1715
+
1543
1716
  gitError = error;
1544
1717
  } finally {
1545
1718
  events.send(studioEvent.git());
1546
1719
  }
1720
+
1547
1721
  return await syncAnswer(cwd, settings, gitError);
1548
1722
  });
1549
1723
  }
@@ -1554,7 +1728,7 @@ const syncAnswer = async (
1554
1728
  stopped: GitError | undefined
1555
1729
  ): Promise<SyncResult> => ({
1556
1730
  git: await gitStatus(cwd, settings),
1557
- ...(stopped ? { stopped: await stoppedBy(cwd, stopped) } : {}),
1731
+ ...(stopped && { stopped: await stoppedBy(cwd, stopped) }),
1558
1732
  });
1559
1733
 
1560
1734
  async function stoppedBy(
@@ -1564,8 +1738,9 @@ async function stoppedBy(
1564
1738
  const stopped = {
1565
1739
  message: error.message,
1566
1740
  output: error.output,
1567
- ...(error.stop ? { stop: error.stop } : {}),
1741
+ ...(error.stop && { stop: error.stop }),
1568
1742
  };
1743
+
1569
1744
  return error.stop === "conflict"
1570
1745
  ? { ...stopped, clashes: await clashesIn(cwd, error.output.split("\n")) }
1571
1746
  : stopped;
@@ -1573,9 +1748,11 @@ async function stoppedBy(
1573
1748
 
1574
1749
  function keepOf(body: RequestBody | undefined): SyncKeep | undefined {
1575
1750
  const keep: unknown = body?.keep;
1751
+
1576
1752
  if (keep !== undefined && keep !== "mine" && keep !== "theirs") {
1577
1753
  throw new Problems(400, ["keep is mine or theirs."]);
1578
1754
  }
1755
+
1579
1756
  return keep;
1580
1757
  }
1581
1758
 
@@ -1589,8 +1766,10 @@ async function runPullBase({ project, body, events, request }: RouteContext) {
1589
1766
  const keep = keepOf(body);
1590
1767
  const settings = await readGitSettings(project.root);
1591
1768
  const cwd = project.content;
1769
+
1592
1770
  return await queueSync(cwd, "step", async (): Promise<SyncResult> => {
1593
1771
  let gitError: GitError | undefined;
1772
+
1594
1773
  try {
1595
1774
  ({ stopped: gitError } = await pullBaseAndUpdate({
1596
1775
  content: cwd,
@@ -1601,6 +1780,7 @@ async function runPullBase({ project, body, events, request }: RouteContext) {
1601
1780
  } finally {
1602
1781
  events.send(studioEvent.git());
1603
1782
  }
1783
+
1604
1784
  return await syncAnswer(cwd, settings, gitError);
1605
1785
  });
1606
1786
  }
@@ -1617,6 +1797,7 @@ async function restoreFromSaved({
1617
1797
  }: RouteContext) {
1618
1798
  onlyFromThisMachine(request, GIT_ELSEWHERE);
1619
1799
  const cwd = project.content;
1800
+
1620
1801
  try {
1621
1802
  await queueSync(cwd, "step", () =>
1622
1803
  restoreSaved(cwd, {
@@ -1627,7 +1808,9 @@ async function restoreFromSaved({
1627
1808
  } catch (error) {
1628
1809
  throw gitProblems(error);
1629
1810
  }
1811
+
1630
1812
  events.send(studioEvent.git());
1813
+
1631
1814
  return { saved: await readSaved(cwd) };
1632
1815
  }
1633
1816
 
@@ -1635,13 +1818,17 @@ async function mergeBranchPullRequest(cwd: string, settings: GitSettings) {
1635
1818
  forgetPullRequests();
1636
1819
  const state = await gitStatus(cwd, settings);
1637
1820
  const github = await githubOfRepository(cwd);
1821
+
1638
1822
  if (!(state.repo && state.pr?.state === "open" && github)) {
1639
1823
  throw new GitError("There is no open pull request to merge.");
1640
1824
  }
1825
+
1641
1826
  const merged = await mergePullRequest(cwd, github, state.pr.number);
1827
+
1642
1828
  if (!merged.merged) {
1643
1829
  throw new GitError("GitHub did not merge it.", merged.message);
1644
1830
  }
1831
+
1645
1832
  await fetchRemote(cwd);
1646
1833
  }
1647
1834
 
@@ -1657,43 +1844,50 @@ async function askAgent({
1657
1844
  "project" | "body" | "request" | "threads" | "pageBase"
1658
1845
  > & { settings: GitSettings }) {
1659
1846
  const ask: unknown = body?.ask;
1847
+
1660
1848
  if (!oneOf<GitAsk>(GIT_ASKS, ask)) {
1661
1849
  throw new Problems(400, [`Ask for one of: ${GIT_ASKS.join(", ")}.`]);
1662
1850
  }
1851
+
1663
1852
  const prototype = String(body?.prototype ?? "");
1664
1853
  const state = await gitStatus(project.content, settings);
1854
+
1665
1855
  if (!(state.repo && state.branch)) {
1666
1856
  throw new Problems(409, ["Switch to a branch first."]);
1667
1857
  }
1858
+
1668
1859
  const { host } = request.headers;
1669
1860
  const origin = isLoopbackHost(host) ? undefined : `http://${host}${pageBase}`;
1670
1861
  const changed = await branchPrototypes(project.content, settings);
1862
+
1671
1863
  const canvases = [...new Set([prototype, ...changed].filter(Boolean))].map(
1672
1864
  (name) => ({
1673
1865
  prototype: name,
1674
- ...(origin ? { url: `${origin}${prototypePage(name, "canvas")}` } : {}),
1866
+ ...(origin && { url: `${origin}${prototypePage(name, "canvas")}` }),
1675
1867
  })
1676
1868
  );
1869
+
1677
1870
  const text = gitAskBody(ask, {
1678
1871
  base: state.base,
1679
1872
  branch: state.branch,
1680
1873
  remote: state.remote ?? "origin",
1681
1874
  canvases,
1682
- ...(body?.error ? { error: String(body.error) } : {}),
1683
- ...(body?.failed ? { step: String(body.failed) } : {}),
1684
- });
1685
- const { name: author } = await readAuthor(project.content);
1686
- const result = await threads.start({
1687
- prototype,
1688
- target: { kind: "prototype" },
1689
- body: text,
1690
- for: "agent",
1691
- author,
1875
+ ...(Boolean(body?.error) && { error: String(body?.error) }),
1876
+ ...(Boolean(body?.failed) && { step: String(body?.failed) }),
1692
1877
  });
1693
- if (result.problems) {
1694
- throw new Problems(422, result.problems);
1695
- }
1696
- return { thread: result.thread };
1878
+
1879
+ // As sent: a name from before files/ finds the file it became.
1880
+ const comments = await personComments({ project, threads }, prototype);
1881
+
1882
+ const thread = commentAnswer(
1883
+ await startComment(comments, {
1884
+ target: { kind: "prototype" },
1885
+ body: text,
1886
+ for: "agent",
1887
+ })
1888
+ );
1889
+
1890
+ return { thread };
1697
1891
  }
1698
1892
 
1699
1893
  const loadGitSettings = async ({ project }: RouteContext) => ({
@@ -1707,6 +1901,7 @@ function sharingSent(
1707
1901
  saved: GitSettings
1708
1902
  ): Pick<GitSettings, "share" | "syncBranch"> {
1709
1903
  const share: unknown = body?.share;
1904
+
1710
1905
  return {
1711
1906
  share: share === "sync" || share === "pull-requests" ? share : saved.share,
1712
1907
  syncBranch:
@@ -1730,12 +1925,14 @@ async function runGitChecks({ project, body }: RouteContext) {
1730
1925
  realGitProbes,
1731
1926
  { beforePrototypes: "note" }
1732
1927
  );
1928
+
1733
1929
  return { checks };
1734
1930
  }
1735
1931
 
1736
1932
  async function saveGitSettings({ project, body, events }: RouteContext) {
1737
1933
  // Base and prefix are always sent.
1738
1934
  const saved = await readGitSettings(project.root);
1935
+
1739
1936
  const settings = await refusable(() =>
1740
1937
  writeGitSettings(project.root, {
1741
1938
  base: typeof body?.base === "string" ? body.base : undefined,
@@ -1743,7 +1940,9 @@ async function saveGitSettings({ project, body, events }: RouteContext) {
1743
1940
  ...sharingSent(body, saved),
1744
1941
  })
1745
1942
  );
1943
+
1746
1944
  events.send(studioEvent.git());
1945
+
1747
1946
  return { settings };
1748
1947
  }
1749
1948
 
@@ -1753,22 +1952,30 @@ const loadBuildSettings = ({ project }: RouteContext) =>
1753
1952
  /** Turn the build's settings that are sent on or off: `{ review: false }`. */
1754
1953
  async function saveBuildSettings({ project, body, events }: RouteContext) {
1755
1954
  const sent: Partial<BuildSettings> = {};
1955
+
1956
+ // SAFETY: BUILD_DEFAULTS has every BuildSettings key.
1756
1957
  for (const key of Object.keys(BUILD_DEFAULTS) as (keyof BuildSettings)[]) {
1757
1958
  const value = body?.[key];
1959
+
1758
1960
  if (typeof value === "boolean") {
1759
1961
  sent[key] = value;
1760
1962
  }
1761
1963
  }
1964
+
1762
1965
  if (Object.keys(sent).length === 0) {
1763
1966
  throw new Problems(400, [
1764
1967
  "Send comments, pictures or review, as true or false.",
1765
1968
  ]);
1766
1969
  }
1970
+
1767
1971
  const saved = await readBuildSettings(project.root);
1972
+
1768
1973
  const settings = await refusable(() =>
1769
1974
  writeBuildSettings(project.root, { ...saved, ...sent })
1770
1975
  );
1976
+
1771
1977
  events.send(studioEvent.workspace());
1978
+
1772
1979
  return settings;
1773
1980
  }
1774
1981
 
@@ -1776,11 +1983,13 @@ const commandsOf = async (project: ProjectFolders): Promise<CommandsAnswer> => {
1776
1983
  const menu = await readCommandMenu(project.root);
1777
1984
  const folders = await skillFolders(project.root);
1778
1985
  const commands = await listCommands({ folders, menu });
1986
+
1779
1987
  return {
1780
1988
  commands,
1781
1989
  quick: quickNames(commands, menu),
1782
1990
  folder: relative(project.root, folders.team).split(sep).join("/"),
1783
1991
  codebaseFolders: codebaseSkills(project.root).shown,
1992
+ // SAFETY: one entry per COMMAND_SWITCHES name, each a boolean.
1784
1993
  switches: Object.fromEntries(
1785
1994
  COMMAND_SWITCHES.map((which) => [which, switchOn(menu, which)])
1786
1995
  ) as CommandsAnswer["switches"],
@@ -1791,6 +2000,7 @@ const loadCommands = ({ project }: RouteContext) => commandsOf(project);
1791
2000
 
1792
2001
  async function saveCommandFile({ project, body }: RouteContext) {
1793
2002
  const { name, description, body: text, was } = body ?? {};
2003
+
1794
2004
  if (
1795
2005
  typeof name !== "string" ||
1796
2006
  typeof description !== "string" ||
@@ -1799,6 +2009,7 @@ async function saveCommandFile({ project, body }: RouteContext) {
1799
2009
  ) {
1800
2010
  throw new Problems(400, ["Send the command's name, description and body."]);
1801
2011
  }
2012
+
1802
2013
  const folders = await skillFolders(project.root);
1803
2014
  await refusable(() =>
1804
2015
  saveCommand(folders, {
@@ -1808,6 +2019,7 @@ async function saveCommandFile({ project, body }: RouteContext) {
1808
2019
  was,
1809
2020
  })
1810
2021
  );
2022
+
1811
2023
  // A renamed command keeps its switch.
1812
2024
  if (was && was !== name.trim()) {
1813
2025
  const menu = await readCommandMenu(project.root);
@@ -1815,6 +2027,7 @@ async function saveCommandFile({ project, body }: RouteContext) {
1815
2027
  writeCommandMenu(project.root, menuRenamed(menu, was, name.trim()))
1816
2028
  );
1817
2029
  }
2030
+
1818
2031
  return commandsOf(project);
1819
2032
  }
1820
2033
 
@@ -1827,47 +2040,62 @@ async function switchCommand({ project, body }: RouteContext) {
1827
2040
  if (body && "quick" in body) {
1828
2041
  return chooseQuick(project, body.quick);
1829
2042
  }
2043
+
1830
2044
  const which = COMMAND_SWITCHES.find((each) => body && each in body);
2045
+
1831
2046
  if (which) {
1832
2047
  const on = body?.[which];
2048
+
1833
2049
  if (typeof on !== "boolean") {
1834
2050
  throw new Problems(400, [`Send ${which} as true or false.`]);
1835
2051
  }
2052
+
1836
2053
  const menu = await readCommandMenu(project.root);
1837
2054
  await refusable(() =>
1838
2055
  writeCommandMenu(project.root, { ...menu, [which]: on })
1839
2056
  );
2057
+
1840
2058
  return commandsOf(project);
1841
2059
  }
2060
+
1842
2061
  const { name, on } = body ?? {};
2062
+
1843
2063
  if (typeof name !== "string" || typeof on !== "boolean") {
1844
2064
  throw new Problems(400, ["Send the command's name and on."]);
1845
2065
  }
1846
- const command = (await commandsOf(project)).commands.find(
1847
- (each) => each.name === name
1848
- );
2066
+
2067
+ const commands = await commandsOf(project);
2068
+
2069
+ const command = commands.commands.find((each) => each.name === name);
2070
+
1849
2071
  if (!command) {
1850
2072
  throw new Problems(404, [`No command is named ${name}.`]);
1851
2073
  }
2074
+
1852
2075
  const menu = await readCommandMenu(project.root);
1853
2076
  await refusable(() =>
1854
2077
  writeCommandMenu(project.root, menuWith(menu, command, on))
1855
2078
  );
2079
+
1856
2080
  return commandsOf(project);
1857
2081
  }
1858
2082
 
1859
2083
  async function chooseQuick(project: ProjectFolders, quick: unknown) {
1860
- const names = (await commandsOf(project)).commands.map(({ name }) => name);
2084
+ const available = await commandsOf(project);
2085
+ const names = new Set(available.commands.map(({ name }) => name));
2086
+
1861
2087
  if (
1862
2088
  !Array.isArray(quick) ||
1863
- quick.some((name) => typeof name !== "string" || !names.includes(name))
2089
+ quick.some((name) => typeof name !== "string" || !names.has(name))
1864
2090
  ) {
1865
2091
  throw new Problems(400, ["Send the quick bar's commands by name."]);
1866
2092
  }
2093
+
1867
2094
  const menu = await readCommandMenu(project.root);
1868
2095
  await refusable(() =>
1869
2096
  writeCommandMenu(project.root, { ...menu, quick: [...new Set(quick)] })
1870
2097
  );
2098
+
1871
2099
  return commandsOf(project);
1872
2100
  }
1873
2101
 
@@ -1877,12 +2105,14 @@ async function removeCommandFile({ project, url }: RouteContext) {
1877
2105
  const folders = await skillFolders(project.root);
1878
2106
  await refusable(() => removeCommand(folders, name));
1879
2107
  const left = await commandsOf(project);
2108
+
1880
2109
  if (!left.commands.some((command) => command.name === name)) {
1881
2110
  const menu = await readCommandMenu(project.root);
1882
2111
  await refusable(() =>
1883
2112
  writeCommandMenu(project.root, menuRenamed(menu, name, undefined))
1884
2113
  );
1885
2114
  }
2115
+
1886
2116
  return commandsOf(project);
1887
2117
  }
1888
2118
 
@@ -1891,14 +2121,18 @@ const loadTeamDevices = ({ project }: RouteContext) =>
1891
2121
 
1892
2122
  async function saveTeamDevices({ project, body, events }: RouteContext) {
1893
2123
  const saved = await saveDevices(project.content, body);
2124
+
1894
2125
  if (!saved.devices) {
1895
2126
  throw new Problems(400, saved.problems);
1896
2127
  }
2128
+
1897
2129
  events.send(studioEvent.devices());
2130
+
1898
2131
  return { devices: saved.devices, problems: [] };
1899
2132
  }
1900
2133
 
1901
- const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
2134
+ const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/u;
2135
+
1902
2136
  /**
1903
2137
  * The icon is served under its own address, so it is never a page: opened
1904
2138
  * directly, an SVG runs nothing and loads nothing.
@@ -1911,9 +2145,11 @@ async function saveWorkspace({ project, body, events }: RouteContext) {
1911
2145
  if (typeof body?.title !== "string") {
1912
2146
  throw new Problems(400, ["Send the workspace's name as title."]);
1913
2147
  }
1914
- const title = body.title;
2148
+
2149
+ const { title } = body;
1915
2150
  const workspace = await refusable(() => writeWorkspaceTitle(project, title));
1916
2151
  events.send(studioEvent.workspace());
2152
+
1917
2153
  return workspace;
1918
2154
  }
1919
2155
 
@@ -1927,11 +2163,13 @@ async function downloadExtension({ response }: RouteContext) {
1927
2163
  "The extension isn't built. Build Dex's package, then try again.",
1928
2164
  ]);
1929
2165
  }
2166
+
1930
2167
  response.setHeader(
1931
2168
  "Content-Disposition",
1932
2169
  `attachment; filename="${EXTENSION_FILE}"`
1933
2170
  );
1934
2171
  response.setHeader("Cache-Control", "no-cache");
2172
+
1935
2173
  return new Reply(200, await zipFolder(EXTENSION_DIR), "application/zip");
1936
2174
  }
1937
2175
 
@@ -1948,17 +2186,21 @@ async function exportFrames({
1948
2186
  `attachment; filename="${exported.name}"`
1949
2187
  );
1950
2188
  response.setHeader("Cache-Control", "no-store");
2189
+
1951
2190
  return new Reply(200, exported.bytes, "application/zip");
1952
2191
  }
1953
2192
 
1954
2193
  async function serveWorkspaceIcon({ project, response }: RouteContext) {
1955
2194
  const icon = await readWorkspaceIcon(project);
2195
+
1956
2196
  if (!icon) {
1957
2197
  throw new Problems(404, ["This workspace has no icon."]);
1958
2198
  }
2199
+
1959
2200
  response.setHeader("Content-Security-Policy", ICON_POLICY);
1960
2201
  response.setHeader("X-Content-Type-Options", "nosniff");
1961
2202
  response.setHeader("Cache-Control", "no-cache");
2203
+
1962
2204
  return new Reply(200, icon.bytes, icon.type);
1963
2205
  }
1964
2206
 
@@ -1970,18 +2212,22 @@ async function saveWorkspaceIcon({
1970
2212
  }: RouteContext) {
1971
2213
  onlyFromThisMachine(request, ICON_ELSEWHERE);
1972
2214
  const data = body?.data;
2215
+
1973
2216
  if (typeof data !== "string" || !BASE64_RE.test(data)) {
1974
2217
  throw new Problems(400, ["Send the icon's bytes in base64 as data."]);
1975
2218
  }
2219
+
1976
2220
  const workspace = await writeWorkspaceIcon(
1977
2221
  project,
1978
2222
  Buffer.from(data, "base64")
1979
2223
  ).catch((error: unknown) => {
1980
- throw new Problems(error instanceof IconRefused ? 415 : 422, [
2224
+ throw new Problems(error instanceof IconRefusedError ? 415 : 422, [
1981
2225
  messageOf(error),
1982
2226
  ]);
1983
2227
  });
2228
+
1984
2229
  events.send(studioEvent.workspace());
2230
+
1985
2231
  return workspace;
1986
2232
  }
1987
2233
 
@@ -1989,6 +2235,7 @@ async function deleteWorkspaceIcon({ project, request, events }: RouteContext) {
1989
2235
  onlyFromThisMachine(request, ICON_ELSEWHERE);
1990
2236
  const workspace = await refusable(() => removeWorkspaceIcon(project));
1991
2237
  events.send(studioEvent.workspace());
2238
+
1992
2239
  return workspace;
1993
2240
  }
1994
2241
 
@@ -1997,30 +2244,35 @@ function pictureOwner({ project, request }: RouteContext) {
1997
2244
  request,
1998
2245
  "Change your picture on the machine Dex runs on."
1999
2246
  );
2247
+
2000
2248
  return whoChanges(project.content);
2001
2249
  }
2002
2250
 
2003
2251
  async function saveAvatar(context: RouteContext) {
2004
2252
  const slug = await pictureOwner(context);
2005
2253
  const data = context.body?.data;
2254
+
2006
2255
  if (typeof data !== "string" || !BASE64_RE.test(data)) {
2007
2256
  throw new Problems(400, ["Send the picture's bytes in base64 as data."]);
2008
2257
  }
2258
+
2009
2259
  const file = await writeAvatar(
2010
2260
  context.project.content,
2011
2261
  slug,
2012
2262
  Buffer.from(data, "base64")
2013
2263
  ).catch((error: unknown) => {
2014
- throw new Problems(error instanceof AvatarRefused ? 415 : 422, [
2264
+ throw new Problems(error instanceof AvatarRefusedError ? 415 : 422, [
2015
2265
  messageOf(error),
2016
2266
  ]);
2017
2267
  });
2268
+
2018
2269
  return { file };
2019
2270
  }
2020
2271
 
2021
2272
  async function deleteAvatar(context: RouteContext) {
2022
2273
  const slug = await pictureOwner(context);
2023
2274
  await refusable(() => removeAvatar(context.project.content, slug));
2275
+
2024
2276
  return {};
2025
2277
  }
2026
2278
 
@@ -2028,20 +2280,25 @@ async function recordFocus({ project, body }: RouteContext) {
2028
2280
  const { slug } = prototypeNamed(project.content, body ?? {}, {
2029
2281
  mustExist: false,
2030
2282
  });
2283
+
2031
2284
  await writeFocus(project.content, {
2032
2285
  slug,
2033
2286
  page: body?.page === "canvas" ? "canvas" : "prototype",
2034
2287
  ...openPlace(body),
2035
2288
  });
2289
+
2036
2290
  return {};
2037
2291
  }
2038
2292
 
2039
2293
  const loadMe = ({ project }: RouteContext) => readMe(project.content);
2040
2294
 
2041
- const PROTOTYPE_CHANGES: Record<
2042
- string,
2043
- (body: RequestBody, root: string) => Promise<unknown>
2044
- > = {
2295
+ /** A change to a file, as a request asks for it. */
2296
+ // oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type, anti-slop/no-unknown-returns -- a request body, which each change checks; what a change answers is sent as JSON, whatever it is
2297
+ type PrototypeChange = (body: RequestBody, root: string) => Promise<unknown>;
2298
+
2299
+ // SAFETY: each change checks the body's fields itself.
2300
+ // oxlint-disable-next-line anti-slop/no-known-value-widening -- looked up by the action a request names
2301
+ const PROTOTYPE_CHANGES: Record<string, PrototypeChange> = {
2045
2302
  rename: (body, root) =>
2046
2303
  setPrototypeTitle(body as ArgumentOf<typeof setPrototypeTitle>, root),
2047
2304
  status: (body, root) =>
@@ -2062,20 +2319,26 @@ async function changePrototypes({ project, body }: RouteContext) {
2062
2319
  if (!body) {
2063
2320
  throw new Problems(400, ["Send a title."]);
2064
2321
  }
2322
+
2065
2323
  const { action } = body;
2066
2324
  const known = isPrototypeChange(action);
2325
+
2067
2326
  if (action !== undefined && !known) {
2068
2327
  throw new Problems(400, [
2069
2328
  `This studio cannot "${action}" a file. Restart it after updating.`,
2070
2329
  ]);
2071
2330
  }
2331
+
2072
2332
  if (known) {
2073
2333
  const change = PROTOTYPE_CHANGES[action];
2334
+
2074
2335
  return (await refusable(() => change(body, project.content))) ?? {};
2075
2336
  }
2337
+
2076
2338
  // An agent may name any contributor (`owner` from before is the same).
2077
2339
  const person =
2078
2340
  body.person ?? body.owner ?? (await whoChanges(project.content));
2341
+
2079
2342
  const { href } = await refusable(() =>
2080
2343
  body.title === undefined
2081
2344
  ? createUntitledPrototype({ person }, project.content)
@@ -2084,6 +2347,7 @@ async function changePrototypes({ project, body }: RouteContext) {
2084
2347
  project.content
2085
2348
  )
2086
2349
  );
2350
+
2087
2351
  return { href };
2088
2352
  }
2089
2353
 
@@ -2108,9 +2372,11 @@ function studioPages({
2108
2372
  // Watch is read, changed and told to pages one step at a time, so a page
2109
2373
  // that opens while it changes never hears an older value after a newer one.
2110
2374
  let watchTurn: Promise<unknown> = Promise.resolve();
2375
+
2111
2376
  const inWatchOrder = <T>(step: () => Promise<T>): Promise<T> => {
2112
2377
  const next = watchTurn.then(step);
2113
2378
  watchTurn = next.catch(() => undefined);
2379
+
2114
2380
  return next;
2115
2381
  };
2116
2382
 
@@ -2126,10 +2392,12 @@ function studioPages({
2126
2392
  listening: () => open,
2127
2393
  async listen(response: ServerResponse): Promise<void> {
2128
2394
  const entries = await presence.list();
2395
+
2129
2396
  if (response.destroyed) {
2130
2397
  // Gone while its presence was read.
2131
2398
  return;
2132
2399
  }
2400
+
2133
2401
  response.writeHead(200, {
2134
2402
  "Content-Type": "text/event-stream",
2135
2403
  "Cache-Control": "no-cache",
@@ -2138,13 +2406,16 @@ function studioPages({
2138
2406
  const write = (event: StudioEvent) => response.write(eventMessage(event));
2139
2407
  write(studioEvent.presence(entries));
2140
2408
  const stopHearing = events.listen(write);
2409
+
2141
2410
  const stopAgents = agents.listen((list) =>
2142
2411
  write(studioEvent.agents(list))
2143
2412
  );
2413
+
2144
2414
  const keepAlive = setInterval(
2145
2415
  () => response.write(": keep-alive\n\n"),
2146
2416
  KEEP_ALIVE_MS
2147
2417
  );
2418
+
2148
2419
  open += 1;
2149
2420
  following ??= threads.subscribe(threadsChanged);
2150
2421
  response.on("close", () => {
@@ -2152,6 +2423,7 @@ function studioPages({
2152
2423
  stopHearing();
2153
2424
  stopAgents();
2154
2425
  open -= 1;
2426
+
2155
2427
  if (open === 0) {
2156
2428
  following?.then((stop) => stop());
2157
2429
  following = undefined;
@@ -2159,7 +2431,8 @@ function studioPages({
2159
2431
  });
2160
2432
  // In turn with the Watch changes it hears from here on.
2161
2433
  await inWatchOrder(async () => {
2162
- const on = await isWatching(project.content);
2434
+ const on = await isWatching(agentsPlace(project.content));
2435
+
2163
2436
  if (!response.destroyed) {
2164
2437
  write(studioEvent.watch(on));
2165
2438
  }
@@ -2195,14 +2468,14 @@ type DeclaredRoute<Name extends StudioRouteName> =
2195
2468
  | ({ prototype: true } & DeclaredMethods<PrototypeContext, Name>)
2196
2469
  | ({ prototype?: false } & DeclaredMethods<RouteContext, Name>);
2197
2470
 
2198
- const ROUTES: { [Name in StudioRouteName]: DeclaredRoute<Name> } = {
2471
+ const ROUTES = {
2199
2472
  ...COMMENT_HANDLERS,
2200
2473
  canvas: { prototype: true, GET: loadCanvas, PUT: saveCanvas },
2201
- annotations: {
2474
+ picks: {
2202
2475
  prototype: true,
2203
- GET: loadAnnotations,
2204
- PUT: saveOwnAnnotation,
2205
- DELETE: removeOwnAnnotation,
2476
+ GET: loadPicks,
2477
+ PUT: saveOwnPick,
2478
+ DELETE: removeOwnPick,
2206
2479
  },
2207
2480
  events: {
2208
2481
  streams: true,
@@ -2213,6 +2486,7 @@ const ROUTES: { [Name in StudioRouteName]: DeclaredRoute<Name> } = {
2213
2486
  GET: listRemovedViews,
2214
2487
  POST: trashRemovedViews,
2215
2488
  },
2489
+ "view-source": { prototype: true, GET: loadViewSource },
2216
2490
  trash: { DELETE: emptyTheTrash },
2217
2491
  reviews: { limit: MAX_REVIEW_BYTES, POST: importReviews },
2218
2492
  "spec-suggestion": { POST: acceptSpecSuggestion },
@@ -2278,7 +2552,7 @@ const ROUTES: { [Name in StudioRouteName]: DeclaredRoute<Name> } = {
2278
2552
  PUT: saveWorkspaceIcon,
2279
2553
  DELETE: deleteWorkspaceIcon,
2280
2554
  },
2281
- };
2555
+ } satisfies { [Name in StudioRouteName]: DeclaredRoute<Name> };
2282
2556
 
2283
2557
  const isRouteName = (name: string): name is StudioRouteName =>
2284
2558
  Object.hasOwn(ROUTES, name);
@@ -2286,23 +2560,30 @@ const isRouteName = (name: string): name is StudioRouteName =>
2286
2560
  async function answer(
2287
2561
  route: Route,
2288
2562
  context: Omit<RouteContext, "body">
2563
+ // oxlint-disable-next-line anti-slop/no-unknown-returns -- a route's answer is sent as JSON, whatever it is
2289
2564
  ): Promise<unknown> {
2290
2565
  const { request, response, url, project } = context;
2291
2566
  const methods = METHODS.filter((method) => route[method]);
2292
2567
  const method = methods.find((known) => known === request.method);
2568
+
2293
2569
  if (!method) {
2294
2570
  response.setHeader("Allow", methods.join(", "));
2295
2571
  throw new Problems(405, [`Use ${methods.join(" or ")}.`]);
2296
2572
  }
2573
+
2297
2574
  const bodyOf = () =>
2298
2575
  WITH_BODY.has(method) ? readJson(request, route.limit) : undefined;
2576
+
2299
2577
  // The prototype is checked before the body is read.
2300
2578
  if (route.prototype) {
2301
2579
  const prototype = prototypeOf(project.content, url);
2302
2580
  const body = await bodyOf();
2581
+
2303
2582
  return route[method]?.({ ...context, prototype, body });
2304
2583
  }
2584
+
2305
2585
  const body = await bodyOf();
2586
+
2306
2587
  return route[method]?.({ ...context, body });
2307
2588
  }
2308
2589
 
@@ -2310,10 +2591,10 @@ export interface StudioRequestOptions {
2310
2591
  agents?: AgentTracker;
2311
2592
  base?: string;
2312
2593
  /**
2313
- * Where the studio can make its app, asked each time: the dev server's
2314
- * port is known only once it listens.
2594
+ * The studio's app, asked each time: the dev server's port is known only
2595
+ * once it listens.
2315
2596
  */
2316
- desktop?: () => DesktopAppHost;
2597
+ desktop?: () => ProjectDesktop;
2317
2598
  events: EventHub;
2318
2599
  format?: Formatter;
2319
2600
  launcher?: AgentLauncher;
@@ -2335,31 +2616,38 @@ export function studioRequests({
2335
2616
  events,
2336
2617
  format = formatter(project.content),
2337
2618
  launcher = launchAgent,
2338
- agents = trackAgents(project.content, { threads }),
2619
+ agents = trackAgents(agentsPlace(project.content)),
2339
2620
  server = {},
2340
2621
  base = "/",
2341
- desktop = () => ({ unavailable: "platform" }),
2622
+ desktop = () => noDesktop("platform"),
2342
2623
  }: StudioRequestOptions): (
2343
2624
  request: IncomingMessage,
2344
2625
  response: ServerResponse
2345
2626
  ) => Promise<boolean> {
2346
2627
  const pages = studioPages({ project, events, threads, agents });
2347
2628
  const pageBase = base.replace(TRAILING_SLASH_RE, "");
2629
+
2348
2630
  return async (request, response) => {
2349
2631
  const url = new URL(request.url ?? "/", "http://studio.local");
2632
+
2350
2633
  if (!url.pathname.startsWith(PREFIX)) {
2351
2634
  return false;
2352
2635
  }
2636
+
2353
2637
  const name = url.pathname.slice(PREFIX.length);
2638
+
2354
2639
  try {
2355
2640
  // Other websites open in the same browser must not change files.
2356
2641
  if (!isAllowedRequest(request.headers, server)) {
2357
2642
  throw new Problems(403, ["Not allowed from this site."]);
2358
2643
  }
2644
+
2359
2645
  if (!isRouteName(name)) {
2360
2646
  throw new Problems(404, ["Not found."]);
2361
2647
  }
2648
+
2362
2649
  const route: Route = ROUTES[name];
2650
+
2363
2651
  const answered = await answer(route, {
2364
2652
  project,
2365
2653
  threads,
@@ -2373,6 +2661,7 @@ export function studioRequests({
2373
2661
  response,
2374
2662
  url,
2375
2663
  });
2664
+
2376
2665
  if (!route.streams) {
2377
2666
  send(response, answered);
2378
2667
  }
@@ -2381,12 +2670,14 @@ export function studioRequests({
2381
2670
  response.end();
2382
2671
  } else {
2383
2672
  // Cloud errors keep their status: 402 when the plan has lapsed.
2673
+ // SAFETY: route errors are Problems or CloudErrors, which have a status and problems; anything else has a message.
2384
2674
  const failure = error as Failure;
2385
2675
  sendJson(response, failure.status ?? 500, {
2386
2676
  problems: failure.problems ?? [failure.message],
2387
2677
  });
2388
2678
  }
2389
2679
  }
2680
+
2390
2681
  return true;
2391
2682
  };
2392
2683
  }