@dexhq/canvas 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1222) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/README.md +4 -4
  3. package/app/app.tsx +21 -3
  4. package/app/base.ts +8 -3
  5. package/app/canvas/activity-bar.tsx +34 -14
  6. package/app/canvas/activity-model.ts +112 -53
  7. package/app/canvas/activity-parts.tsx +79 -13
  8. package/app/canvas/activity.tsx +155 -38
  9. package/app/canvas/add-to-spec.ts +14 -5
  10. package/app/canvas/agent-changes.ts +77 -12
  11. package/app/canvas/anchoring.ts +176 -50
  12. package/app/canvas/canvas-chrome.tsx +44 -13
  13. package/app/canvas/canvas-clipboard.ts +38 -8
  14. package/app/canvas/canvas-commands.ts +191 -20
  15. package/app/canvas/canvas-context-menu.tsx +3 -0
  16. package/app/canvas/canvas-context.tsx +23 -4
  17. package/app/canvas/canvas-corners.tsx +2 -0
  18. package/app/canvas/canvas-document.ts +140 -23
  19. package/app/canvas/canvas-input.ts +312 -36
  20. package/app/canvas/canvas-keys.ts +165 -68
  21. package/app/canvas/canvas-menus.tsx +29 -5
  22. package/app/canvas/canvas-merge.ts +141 -29
  23. package/app/canvas/canvas-model.ts +255 -215
  24. package/app/canvas/canvas-panels.ts +10 -0
  25. package/app/canvas/canvas-scene.ts +759 -110
  26. package/app/canvas/canvas-ui.ts +79 -8
  27. package/app/canvas/canvas.css +484 -34
  28. package/app/canvas/change-notice.tsx +16 -7
  29. package/app/canvas/command-menu.tsx +12 -0
  30. package/app/canvas/comment-layer.tsx +79 -120
  31. package/app/canvas/comments.tsx +391 -150
  32. package/app/canvas/device-edits.ts +19 -2
  33. package/app/canvas/device-icons.ts +1 -0
  34. package/app/canvas/device-picker.tsx +5 -2
  35. package/app/canvas/devices-panel.tsx +14 -8
  36. package/app/canvas/draw-layer.tsx +49 -10
  37. package/app/canvas/draw-model.ts +15 -12
  38. package/app/canvas/editable-text.tsx +36 -15
  39. package/app/canvas/element-link.ts +154 -0
  40. package/app/canvas/element-picker.ts +125 -480
  41. package/app/canvas/engine/camera.ts +24 -3
  42. package/app/canvas/engine/canvas-gestures.ts +223 -53
  43. package/app/canvas/engine/canvas-store.ts +36 -0
  44. package/app/canvas/engine/canvas-view.tsx +39 -3
  45. package/app/canvas/export-dialog.tsx +279 -0
  46. package/app/canvas/find-bar.tsx +114 -16
  47. package/app/canvas/find-model.ts +20 -4
  48. package/app/canvas/floating-panel.tsx +16 -0
  49. package/app/canvas/flow-canvas.tsx +396 -103
  50. package/app/canvas/flow-renames.ts +9 -0
  51. package/app/canvas/follow-pin.ts +11 -0
  52. package/app/canvas/forced-states.ts +25 -4
  53. package/app/canvas/frame-choices.tsx +4 -0
  54. package/app/canvas/frame-code.ts +139 -0
  55. package/app/canvas/frame-context-menu.tsx +325 -35
  56. package/app/canvas/frame-copies.ts +100 -29
  57. package/app/canvas/frame-drops.ts +56 -7
  58. package/app/canvas/frame-inspector.ts +154 -0
  59. package/app/canvas/frame-node.tsx +307 -80
  60. package/app/canvas/frame-pictures.ts +96 -13
  61. package/app/canvas/frame-resize.tsx +17 -0
  62. package/app/canvas/frame-shown.ts +5 -0
  63. package/app/canvas/frame-source.ts +19 -2
  64. package/app/canvas/frame-thumb.tsx +5 -4
  65. package/app/canvas/grid-overlay.tsx +4 -3
  66. package/app/canvas/grid-panel.tsx +24 -10
  67. package/app/canvas/imported-reviews.tsx +105 -41
  68. package/app/canvas/insert-hint.tsx +26 -0
  69. package/app/canvas/inspect-layer.tsx +85 -26
  70. package/app/canvas/inspect-tools.ts +15 -4
  71. package/app/canvas/jpeg-pdf.ts +30 -3
  72. package/app/canvas/label-action.tsx +2 -1
  73. package/app/canvas/large-canvas-notice.tsx +7 -1
  74. package/app/canvas/layout.ts +739 -327
  75. package/app/canvas/linked-element.tsx +219 -0
  76. package/app/canvas/live-page.ts +240 -29
  77. package/app/canvas/measure-box.tsx +1 -0
  78. package/app/canvas/mentions.tsx +221 -0
  79. package/app/canvas/new-frame.ts +73 -11
  80. package/app/canvas/note-placing.ts +187 -31
  81. package/app/canvas/number-field.tsx +3 -0
  82. package/app/canvas/open-page.ts +8 -1
  83. package/app/canvas/others-hidden.ts +140 -0
  84. package/app/canvas/page-find.ts +47 -5
  85. package/app/canvas/page-heights.tsx +21 -0
  86. package/app/canvas/page-scroll.ts +22 -4
  87. package/app/canvas/page-style.ts +3 -1
  88. package/app/canvas/pass-to-canvas.ts +81 -0
  89. package/app/canvas/pasted-cuts.ts +2 -0
  90. package/app/canvas/person-busy.ts +3 -0
  91. package/app/canvas/picked-box.tsx +22 -0
  92. package/app/canvas/picks-menu.tsx +26 -8
  93. package/app/canvas/picks.ts +36 -29
  94. package/app/canvas/point-menu.tsx +4 -0
  95. package/app/canvas/props-model.ts +27 -5
  96. package/app/canvas/props-panel.tsx +31 -6
  97. package/app/canvas/quick-bar.tsx +59 -15
  98. package/app/canvas/removed-views-panel.tsx +43 -12
  99. package/app/canvas/request-node.tsx +165 -0
  100. package/app/canvas/review-marker.tsx +9 -2
  101. package/app/canvas/review-panel.tsx +151 -43
  102. package/app/canvas/row-node.tsx +15 -3
  103. package/app/canvas/scene-context.tsx +16 -1
  104. package/app/canvas/section-node.tsx +72 -142
  105. package/app/canvas/selection.ts +3 -1
  106. package/app/canvas/server-notice.tsx +10 -4
  107. package/app/canvas/size-label.tsx +2 -1
  108. package/app/canvas/sketch-boxes.tsx +194 -139
  109. package/app/canvas/sketch-layer.tsx +88 -30
  110. package/app/canvas/sketch-model.ts +78 -9
  111. package/app/canvas/slide-frame.tsx +13 -1
  112. package/app/canvas/slide-full-screen.tsx +19 -3
  113. package/app/canvas/slide-page.tsx +9 -1
  114. package/app/canvas/slide-pdf.tsx +44 -5
  115. package/app/canvas/snapping.ts +26 -1
  116. package/app/canvas/spec-copies.ts +13 -2
  117. package/app/canvas/spec-frame.tsx +198 -60
  118. package/app/canvas/spec-full-screen.tsx +39 -17
  119. package/app/canvas/spec-margin.tsx +36 -8
  120. package/app/canvas/spec-mode.tsx +28 -20
  121. package/app/canvas/spec-placing.tsx +32 -7
  122. package/app/canvas/spec-threads.ts +14 -0
  123. package/app/canvas/spec-title.tsx +12 -5
  124. package/app/canvas/spot-pins.tsx +8 -0
  125. package/app/canvas/stack-frame.tsx +357 -0
  126. package/app/canvas/stack-model.ts +267 -0
  127. package/app/canvas/stack-node.tsx +19 -11
  128. package/app/canvas/state-store.ts +7 -0
  129. package/app/canvas/sticker-model.ts +16 -2
  130. package/app/canvas/sticker-sheet.tsx +63 -11
  131. package/app/canvas/stored-viewport.ts +14 -13
  132. package/app/canvas/styles-layer.tsx +70 -52
  133. package/app/canvas/teammates-layer.tsx +223 -0
  134. package/app/canvas/tell-open-page.tsx +12 -0
  135. package/app/canvas/testing/must.ts +11 -0
  136. package/app/canvas/testing/stand-in.ts +9 -0
  137. package/app/canvas/testing/waits.ts +17 -0
  138. package/app/canvas/text-layer.tsx +156 -29
  139. package/app/canvas/thread-focus.tsx +47 -17
  140. package/app/canvas/thread-place.ts +27 -3
  141. package/app/canvas/tip.tsx +4 -0
  142. package/app/canvas/tool-cursors.ts +22 -7
  143. package/app/canvas/tool-icons.tsx +37 -56
  144. package/app/canvas/toolbar-parts.tsx +11 -5
  145. package/app/canvas/toolbar.tsx +132 -83
  146. package/app/canvas/tools.ts +32 -9
  147. package/app/canvas/typing.ts +17 -0
  148. package/app/canvas/unknown-frame.tsx +39 -12
  149. package/app/canvas/use-activity.ts +57 -2
  150. package/app/canvas/use-agent-changes.tsx +66 -17
  151. package/app/canvas/use-canvas-clipboard.tsx +190 -64
  152. package/app/canvas/use-canvas-commands.ts +14 -0
  153. package/app/canvas/use-canvas-editor.ts +43 -16
  154. package/app/canvas/use-component-drops.ts +21 -5
  155. package/app/canvas/use-spec-copies.ts +29 -14
  156. package/app/canvas/viewports.ts +4 -1
  157. package/app/canvas/wireframe-panel.tsx +18 -2
  158. package/app/canvas/xray.ts +3 -10
  159. package/app/client.d.ts +6 -0
  160. package/app/content.d.ts +1 -0
  161. package/app/design-system/components-canvas.ts +58 -21
  162. package/app/design-system/components-prototype.tsx +56 -20
  163. package/app/design-system/pseudo-states.ts +45 -16
  164. package/app/editor/annotations.ts +60 -20
  165. package/app/editor/blocks.ts +99 -34
  166. package/app/editor/embed-arrange.tsx +59 -22
  167. package/app/editor/embed-box.ts +54 -28
  168. package/app/editor/extensions.ts +16 -5
  169. package/app/editor/markdown-source.ts +42 -8
  170. package/app/editor/node-views.tsx +39 -12
  171. package/app/editor/quote-bubble.tsx +10 -1
  172. package/app/editor/two-versions.ts +24 -9
  173. package/app/export/player-model.ts +187 -0
  174. package/app/export/player.tsx +215 -0
  175. package/app/export.html +31 -0
  176. package/app/export.tsx +9 -0
  177. package/app/frame/announce-refreshes.ts +21 -0
  178. package/app/frame/file-errors.ts +4 -0
  179. package/app/frame/frame-app.tsx +15 -1
  180. package/app/frame/frame-history.ts +9 -0
  181. package/app/frame/frame-links.ts +7 -0
  182. package/app/frame/hold-window-focus.ts +4 -0
  183. package/app/frame/left-view.tsx +6 -0
  184. package/app/frame/start-frame.tsx +56 -0
  185. package/app/frame/studio-view.tsx +2 -0
  186. package/app/frame/view-exports.ts +240 -0
  187. package/app/frame/view-loads.ts +187 -0
  188. package/app/frame/views.ts +86 -51
  189. package/app/frame.tsx +2 -38
  190. package/app/git/branch-panel.tsx +71 -25
  191. package/app/git/change-list.tsx +15 -6
  192. package/app/git/clash.tsx +10 -5
  193. package/app/git/git-controls.tsx +78 -22
  194. package/app/git/git-state.ts +20 -0
  195. package/app/git/git-toasts.tsx +41 -2
  196. package/app/git/paused.tsx +28 -12
  197. package/app/git/saved-list.tsx +10 -3
  198. package/app/git/sync-panel.tsx +39 -18
  199. package/app/i18n/locales/en/messages.po +264 -12
  200. package/app/i18n/locales/en/messages.ts +1 -1
  201. package/app/i18n/locales/pseudo/messages.po +260 -8
  202. package/app/i18n/locales/pseudo/messages.ts +1 -1
  203. package/app/i18n/locales.ts +4 -0
  204. package/app/i18n/provider.tsx +9 -5
  205. package/app/icons/dex-glyphs.tsx +257 -0
  206. package/app/icons/glyphs.tsx +80 -79
  207. package/app/icons/index.tsx +3 -1
  208. package/app/icons/types.ts +1 -0
  209. package/app/kit/inspect-runtime.ts +50 -5
  210. package/app/kit/sample-people.ts +6 -0
  211. package/app/kit/use-flow.ts +2 -1
  212. package/app/kit/use-simulated-load.ts +6 -2
  213. package/app/kit/use-simulated-stream.ts +8 -2
  214. package/app/kit/use-view-control.ts +1 -0
  215. package/app/live/canvas-teammates.ts +103 -0
  216. package/app/live/deployed-preview.ts +1 -0
  217. package/app/live/focus-reporter.ts +8 -0
  218. package/app/live/guest-review.ts +115 -23
  219. package/app/live/restart-wait.ts +14 -2
  220. package/app/live/server-connection.ts +21 -4
  221. package/app/live/studio-action.ts +6 -1
  222. package/app/live/studio-api.ts +218 -71
  223. package/app/live/studio-data.ts +26 -1
  224. package/app/live/studio-live.ts +44 -8
  225. package/app/live/studio-request.ts +15 -1
  226. package/app/live/thread-state.ts +8 -0
  227. package/app/live/use-devices.ts +11 -2
  228. package/app/live/use-focus.ts +5 -2
  229. package/app/live/use-last-edited.ts +2 -0
  230. package/app/live/use-show-requests.ts +3 -0
  231. package/app/live/use-workspace.ts +10 -2
  232. package/app/main.tsx +9 -3
  233. package/app/next/fonts.ts +1 -0
  234. package/app/next/image.tsx +17 -10
  235. package/app/next/navigation.ts +9 -6
  236. package/app/next/router.ts +4 -4
  237. package/app/pages/agent-settings.tsx +11 -3
  238. package/app/pages/ask-the-agent.tsx +2 -0
  239. package/app/pages/canvas-settings.tsx +3 -0
  240. package/app/pages/canvas.tsx +247 -76
  241. package/app/pages/chrome-extension.tsx +4 -2
  242. package/app/pages/commands-settings.tsx +75 -26
  243. package/app/pages/deployment-settings.tsx +9 -0
  244. package/app/pages/doc.tsx +4 -1
  245. package/app/pages/file-sort.ts +11 -4
  246. package/app/pages/git-checks.tsx +30 -10
  247. package/app/pages/guidelines.tsx +8 -4
  248. package/app/pages/home.tsx +41 -17
  249. package/app/pages/host.tsx +4 -0
  250. package/app/pages/markup-settings.tsx +11 -5
  251. package/app/pages/people.tsx +18 -10
  252. package/app/pages/play-bar.tsx +27 -9
  253. package/app/pages/play-size.ts +31 -11
  254. package/app/pages/play.tsx +115 -33
  255. package/app/pages/profile.tsx +6 -2
  256. package/app/pages/prototype.tsx +10 -4
  257. package/app/pages/render.tsx +72 -19
  258. package/app/pages/settings.tsx +5 -1
  259. package/app/pages/workspace-general.tsx +29 -5
  260. package/app/pages/workspace-git.tsx +38 -10
  261. package/app/pages/your-guidelines.tsx +7 -0
  262. package/app/pages/your-picture.tsx +33 -10
  263. package/app/registry-files.ts +6 -1
  264. package/app/registry.ts +73 -13
  265. package/app/renamed-storage.ts +8 -1
  266. package/app/shell/about.tsx +10 -4
  267. package/app/shell/agent-logos.tsx +4 -0
  268. package/app/shell/agent-manual.tsx +13 -5
  269. package/app/shell/avatar-pictures.ts +18 -6
  270. package/app/shell/avatar.tsx +11 -1
  271. package/app/shell/bell.tsx +41 -17
  272. package/app/shell/broke.tsx +1 -1
  273. package/app/shell/chrome-theme.tsx +4 -0
  274. package/app/shell/connect-agent.tsx +76 -38
  275. package/app/shell/copy-text.tsx +3 -1
  276. package/app/shell/deployed-preview-bar.tsx +4 -6
  277. package/app/shell/desktop-app.tsx +30 -15
  278. package/app/shell/empty-state.tsx +2 -2
  279. package/app/shell/feedback-details.ts +8 -1
  280. package/app/shell/feedback-form.tsx +38 -30
  281. package/app/shell/feedback-link.tsx +3 -0
  282. package/app/shell/file-bytes.ts +3 -1
  283. package/app/shell/host.ts +37 -8
  284. package/app/shell/info-tip.tsx +2 -1
  285. package/app/shell/install-prompt.ts +10 -1
  286. package/app/shell/instructions-editor.tsx +184 -78
  287. package/app/shell/instructions.tsx +7 -1
  288. package/app/shell/main-sidebar.tsx +27 -6
  289. package/app/shell/open-agent.tsx +8 -2
  290. package/app/shell/page-header.tsx +6 -3
  291. package/app/shell/page-title.ts +36 -14
  292. package/app/shell/presence-style.ts +8 -0
  293. package/app/shell/presence.tsx +196 -35
  294. package/app/shell/prototype-menu.tsx +84 -27
  295. package/app/shell/quick-start.tsx +21 -3
  296. package/app/shell/recents.ts +21 -2
  297. package/app/shell/report-issue.ts +29 -23
  298. package/app/shell/restart-toast.tsx +37 -4
  299. package/app/shell/save-state.tsx +4 -0
  300. package/app/shell/scaled-frame.tsx +22 -1
  301. package/app/shell/settings-sections.ts +12 -11
  302. package/app/shell/settings-sidebar.tsx +7 -1
  303. package/app/shell/settings-ui.tsx +11 -7
  304. package/app/shell/shell-bar.ts +2 -5
  305. package/app/shell/sidebar.tsx +2 -2
  306. package/app/shell/skeleton.ts +80 -22
  307. package/app/shell/status-badge.tsx +2 -0
  308. package/app/shell/studio-shell.tsx +11 -4
  309. package/app/shell/thread-list.tsx +40 -12
  310. package/app/shell/time-ago.ts +7 -0
  311. package/app/shell/toasts.tsx +20 -13
  312. package/app/shell/update-notice.tsx +241 -41
  313. package/app/shell/use-copied.ts +4 -0
  314. package/app/shell/use-space.ts +5 -0
  315. package/app/shell/watch-switch.tsx +4 -1
  316. package/app/shell/welcome.tsx +18 -3
  317. package/app/shell/window-buttons.tsx +17 -3
  318. package/app/shell/working-on.tsx +45 -5
  319. package/app/shell/workspace-mark.tsx +59 -25
  320. package/app/studio-ui.d.ts +2 -1
  321. package/app/styles.css +4 -12
  322. package/app/types.ts +8 -6
  323. package/app/ui/boundary.tsx +6 -1
  324. package/app/ui/file-drop.ts +32 -18
  325. package/app/ui/prompt-editor.tsx +112 -28
  326. package/app/ui/reference.tsx +27 -9
  327. package/app/ui/segmented.tsx +3 -1
  328. package/app/ui/theme-switch.tsx +1 -0
  329. package/app/ui/theme.css +17 -0
  330. package/app/ui/use-latest.ts +13 -0
  331. package/app/ui/use-once.ts +9 -0
  332. package/bin/dex.mjs +6 -1
  333. package/bin/sudio.mjs +2 -1
  334. package/dist/cli/banner.mjs +0 -1
  335. package/dist/cli/command.d.mts +237 -5
  336. package/dist/cli/command.mjs +8 -3
  337. package/dist/cli/commands/agents/add.mjs +1 -1
  338. package/dist/cli/commands/app.mjs +13 -16
  339. package/dist/cli/commands/claude.d.mts +3 -3
  340. package/dist/cli/commands/claude.mjs +10 -9
  341. package/dist/cli/commands/cloud/publish.mjs +1 -1
  342. package/dist/cli/commands/create.d.mts +5 -5
  343. package/dist/cli/commands/create.mjs +4 -4
  344. package/dist/cli/commands/dev.mjs +64 -19
  345. package/dist/cli/commands/doctor.mjs +3 -1
  346. package/dist/cli/commands/export.d.mts +40 -0
  347. package/dist/cli/commands/export.mjs +66 -0
  348. package/dist/cli/commands/hook.mjs +1 -1
  349. package/dist/cli/commands/init.d.mts +2 -2
  350. package/dist/cli/commands/mcp.mjs +10 -4
  351. package/dist/cli/commands/merge-canvas.d.mts +29 -0
  352. package/dist/cli/commands/merge-canvas.mjs +101 -0
  353. package/dist/cli/commands/merge-contributors.d.mts +0 -7
  354. package/dist/cli/commands/merge-contributors.mjs +2 -1
  355. package/dist/cli/commands/merge-spec.d.mts +0 -7
  356. package/dist/cli/commands/merge-spec.mjs +2 -1
  357. package/dist/cli/commands/upgrade.mjs +1 -1
  358. package/dist/cli/help.d.mts +1 -1
  359. package/dist/cli/help.mjs +20 -20
  360. package/dist/cli/main.d.mts +68 -5
  361. package/dist/cli/main.mjs +5 -2
  362. package/dist/cli/mcp-relay.d.mts +5 -5
  363. package/dist/cli/mcp-relay.mjs +36 -24
  364. package/dist/cli/recovery-server.mjs +2 -2
  365. package/dist/cli/strict-flags.mjs +6 -6
  366. package/dist/cli/supervise.mjs +37 -26
  367. package/dist/cli/ui.d.mts +21 -21
  368. package/dist/cli/ui.mjs +2 -1
  369. package/dist/config/design-system.mjs +19 -14
  370. package/dist/config/load.mjs +23 -8
  371. package/dist/config/project-files.d.mts +8 -2
  372. package/dist/config/project-files.mjs +44 -41
  373. package/dist/config/renamed.d.mts +9 -6
  374. package/dist/config/renamed.mjs +11 -12
  375. package/dist/content/biome.mjs +15 -10
  376. package/dist/content/capture.mjs +43 -42
  377. package/dist/content/commands.d.mts +21 -13
  378. package/dist/content/commands.mjs +69 -35
  379. package/dist/content/comments-log.mjs +104 -20
  380. package/dist/content/component-props.mjs +6 -10
  381. package/dist/content/content.d.mts +279 -35
  382. package/dist/content/content.mjs +247 -154
  383. package/dist/content/devices.mjs +2 -2
  384. package/dist/content/element-words.d.mts +42 -0
  385. package/dist/content/element-words.mjs +112 -0
  386. package/dist/content/file-turns.mjs +1 -1
  387. package/dist/content/first-run.mjs +3 -5
  388. package/dist/content/flow-specs.mjs +18 -16
  389. package/dist/content/format-check.d.mts +46 -0
  390. package/dist/content/format-check.mjs +338 -0
  391. package/dist/content/hosted-person.d.mts +31 -0
  392. package/dist/content/hosted-person.mjs +69 -0
  393. package/dist/content/insert-edit.mjs +7 -6
  394. package/dist/content/jsx-source.d.mts +5 -1
  395. package/dist/content/jsx-source.mjs +8 -7
  396. package/dist/content/last-edited.mjs +1 -1
  397. package/dist/content/layout.d.mts +44 -2
  398. package/dist/content/layout.mjs +65 -6
  399. package/dist/content/merge-rules.d.mts +16 -4
  400. package/dist/content/merge-rules.mjs +46 -17
  401. package/dist/content/prop-edit.mjs +4 -4
  402. package/dist/content/prototype-checks.mjs +13 -12
  403. package/dist/content/prototype-summary.d.mts +1 -1
  404. package/dist/content/prototype-summary.mjs +8 -8
  405. package/dist/content/prototypes.d.mts +8 -1
  406. package/dist/content/prototypes.mjs +41 -27
  407. package/dist/content/review-import.mjs +1 -1
  408. package/dist/content/review-pages.mjs +19 -16
  409. package/dist/content/screenshot.d.mts +4 -1
  410. package/dist/content/screenshot.mjs +26 -13
  411. package/dist/content/snapshot-client.mjs +2 -3
  412. package/dist/content/store.d.mts +16 -8
  413. package/dist/content/store.mjs +99 -26
  414. package/dist/content/sub-agents.d.mts +12 -0
  415. package/dist/content/sub-agents.mjs +52 -0
  416. package/dist/content/text-edit.d.mts +24 -14
  417. package/dist/content/text-edit.mjs +92 -81
  418. package/dist/content/text-replace.mjs +15 -41
  419. package/dist/content/thread-module.d.mts +11 -5
  420. package/dist/content/thread-module.mjs +23 -6
  421. package/dist/content/threads.d.mts +13 -0
  422. package/dist/content/threads.mjs +59 -14
  423. package/dist/content/trash.d.mts +4 -2
  424. package/dist/content/trash.mjs +31 -31
  425. package/dist/desktop/src/app.d.mts +40 -0
  426. package/dist/desktop/src/app.mjs +80 -0
  427. package/dist/desktop/src/contract.d.mts +7 -0
  428. package/dist/desktop/src/contract.mjs +22 -0
  429. package/dist/desktop/src/host.d.mts +48 -0
  430. package/dist/desktop/src/index.d.mts +32 -0
  431. package/dist/desktop/src/index.mjs +69 -0
  432. package/dist/desktop/src/mac/bundle.mjs +116 -0
  433. package/dist/desktop/src/mac/icon.mjs +53 -0
  434. package/dist/desktop/src/mac/launcher.mjs +69 -0
  435. package/dist/desktop/src/mac/plist.mjs +73 -0
  436. package/dist/desktop/src/mac/program/constants.mjs +62 -0
  437. package/dist/desktop/src/mac/program/delegate.mjs +214 -0
  438. package/dist/desktop/src/mac/program/downloads.mjs +19 -0
  439. package/dist/desktop/src/mac/program/index.mjs +26 -0
  440. package/dist/desktop/src/mac/program/menu.mjs +125 -0
  441. package/dist/desktop/src/mac/program/server-pages.mjs +140 -0
  442. package/dist/desktop/src/mac/program/web-view.mjs +59 -0
  443. package/dist/desktop/src/mac/program/window.mjs +197 -0
  444. package/dist/desktop/src/mac/services.mjs +28 -0
  445. package/dist/desktop/src/plug-in/http.d.mts +11 -0
  446. package/dist/desktop/src/plug-in/http.mjs +51 -0
  447. package/dist/desktop/src/plug-in/page-head.d.mts +8 -0
  448. package/dist/desktop/src/plug-in/page-head.mjs +31 -0
  449. package/dist/desktop/src/service.d.mts +15 -0
  450. package/dist/desktop/src/service.mjs +151 -0
  451. package/dist/desktop/src/start.d.mts +42 -0
  452. package/dist/{setup/desktop-app-start.mjs → desktop/src/start.mjs} +14 -39
  453. package/dist/harness/src/agents/adapter.d.mts +11 -0
  454. package/dist/harness/src/agents/adapter.mjs +6 -0
  455. package/dist/harness/src/agents/claude-code.mjs +179 -0
  456. package/dist/harness/src/agents/codex.mjs +189 -0
  457. package/dist/harness/src/agents/copilot.mjs +20 -0
  458. package/dist/harness/src/agents/cursor.mjs +21 -0
  459. package/dist/harness/src/agents/opencode.mjs +27 -0
  460. package/dist/harness/src/agents/other.mjs +21 -0
  461. package/dist/harness/src/agents/registry.mjs +21 -0
  462. package/dist/harness/src/agents/sub-agent.d.mts +14 -0
  463. package/dist/harness/src/agents.mjs +7 -0
  464. package/dist/harness/src/checks.mjs +9 -0
  465. package/dist/harness/src/connect/agent-config.mjs +252 -0
  466. package/dist/{server → harness/src/connect}/agent-env.mjs +3 -4
  467. package/dist/harness/src/connect/agent-root.mjs +30 -0
  468. package/dist/harness/src/connect/json-layout.mjs +52 -0
  469. package/dist/harness/src/connect/launch.mjs +67 -0
  470. package/dist/harness/src/connect/launched.d.mts +23 -0
  471. package/dist/harness/src/connect/package-manager.d.mts +1 -0
  472. package/dist/{config → harness/src/connect}/package-manager.mjs +17 -6
  473. package/dist/harness/src/connect/setups.d.mts +24 -0
  474. package/dist/harness/src/connect/setups.mjs +98 -0
  475. package/dist/harness/src/connect/workspace-root.d.mts +20 -0
  476. package/dist/harness/src/connect/workspace-root.mjs +110 -0
  477. package/dist/harness/src/events/channel-server.mjs +10 -0
  478. package/dist/harness/src/events/channel.d.mts +104 -0
  479. package/dist/harness/src/events/channel.mjs +457 -0
  480. package/dist/harness/src/events/connected-agent.d.mts +35 -0
  481. package/dist/harness/src/events/place.d.mts +21 -0
  482. package/dist/harness/src/mcp/define-tool.d.mts +26 -0
  483. package/dist/harness/src/mcp/define-tool.mjs +11 -0
  484. package/dist/harness/src/mcp/mcp-handover.d.mts +11 -0
  485. package/dist/{server → harness/src/mcp}/mcp-handover.mjs +6 -4
  486. package/dist/harness/src/mcp/mcp.d.mts +15 -0
  487. package/dist/harness/src/mcp/mcp.mjs +97 -0
  488. package/dist/harness/src/paths.d.mts +4 -0
  489. package/dist/harness/src/paths.mjs +15 -0
  490. package/dist/harness/src/project.d.mts +6 -0
  491. package/dist/harness/src/renamed.d.mts +9 -0
  492. package/dist/harness/src/renamed.mjs +22 -0
  493. package/dist/harness/src/session/session.d.mts +31 -0
  494. package/dist/harness/src/version.d.mts +13 -0
  495. package/dist/harness/src/version.mjs +47 -0
  496. package/dist/inspector.js +598 -0
  497. package/dist/paste/figma/captures.mjs +3 -3
  498. package/dist/paste/figma/decode.d.mts +14 -8
  499. package/dist/paste/figma/decode.mjs +11 -9
  500. package/dist/paste/figma/layout.d.mts +4 -3
  501. package/dist/paste/figma/layout.mjs +1 -1
  502. package/dist/paste/figma/paint.mjs +7 -5
  503. package/dist/paste/figma/render.mjs +1 -1
  504. package/dist/paste/figma/styles.d.mts +3 -1
  505. package/dist/paste/figma/styles.mjs +5 -9
  506. package/dist/paste/figma/text.mjs +21 -17
  507. package/dist/paste/figma/vector.mjs +9 -9
  508. package/dist/paste/fonts.mjs +7 -8
  509. package/dist/paste/paste.d.mts +2 -2
  510. package/dist/paste/paste.mjs +16 -15
  511. package/dist/paths.d.mts +22 -16
  512. package/dist/paths.mjs +28 -57
  513. package/dist/server/agent-session.d.mts +49 -3
  514. package/dist/server/agent-session.mjs +264 -20
  515. package/dist/server/agent-tools.d.mts +17 -0
  516. package/dist/server/agent-tools.mjs +31 -0
  517. package/dist/server/agents-place.d.mts +6 -0
  518. package/dist/server/agents-place.mjs +18 -0
  519. package/dist/server/allowed-request.mjs +1 -1
  520. package/dist/server/avatars.d.mts +3 -1
  521. package/dist/server/avatars.mjs +9 -7
  522. package/dist/server/brief.mjs +10 -10
  523. package/dist/server/briefing.d.mts +5 -5
  524. package/dist/server/briefing.mjs +5 -5
  525. package/dist/server/build-pictures.mjs +8 -8
  526. package/dist/server/build-settings.d.mts +1 -1
  527. package/dist/server/build-settings.mjs +4 -4
  528. package/dist/server/canvas-presence.d.mts +22 -0
  529. package/dist/server/canvas-presence.mjs +160 -0
  530. package/dist/server/changelog.mjs +5 -4
  531. package/dist/server/claimed-presence.mjs +10 -7
  532. package/dist/server/close-check.mjs +17 -15
  533. package/dist/server/cloud.d.mts +1 -1
  534. package/dist/server/cloud.mjs +5 -4
  535. package/dist/server/command-settings.d.mts +4 -2
  536. package/dist/server/command-settings.mjs +12 -8
  537. package/dist/server/comments/actions.d.mts +17 -64
  538. package/dist/server/comments/actions.mjs +65 -67
  539. package/dist/server/comments/agent-actions.d.mts +73 -0
  540. package/dist/server/comments/agent-actions.mjs +76 -0
  541. package/dist/server/comments/close-tools.d.mts +31 -0
  542. package/dist/server/comments/close-tools.mjs +124 -0
  543. package/dist/server/comments/files.d.mts +53 -0
  544. package/dist/server/comments/files.mjs +1 -0
  545. package/dist/server/comments/hand-out.d.mts +42 -0
  546. package/dist/server/comments/hand-out.mjs +46 -0
  547. package/dist/server/comments/push.d.mts +26 -0
  548. package/dist/server/comments/push.mjs +238 -0
  549. package/dist/server/comments/routes.d.mts +12 -0
  550. package/dist/server/comments/routes.mjs +27 -38
  551. package/dist/server/comments/studio-files.d.mts +14 -0
  552. package/dist/server/comments/studio-files.mjs +80 -0
  553. package/dist/server/comments/tools.d.mts +35 -3
  554. package/dist/server/comments/tools.mjs +54 -147
  555. package/dist/server/comments/workflow.d.mts +13 -0
  556. package/dist/server/comments/workflow.mjs +15 -0
  557. package/dist/server/comments/workspace.d.mts +36 -0
  558. package/dist/server/comments/workspace.mjs +84 -0
  559. package/dist/server/component-catalogue.mjs +19 -21
  560. package/dist/server/config-settings.d.mts +1 -1
  561. package/dist/server/config-settings.mjs +3 -3
  562. package/dist/server/content-type.mjs +1 -1
  563. package/dist/server/dependency-clash.d.mts +6 -2
  564. package/dist/server/dependency-clash.mjs +23 -17
  565. package/dist/server/desktop.d.mts +20 -0
  566. package/dist/server/desktop.mjs +56 -0
  567. package/dist/server/dev-server.mjs +53 -49
  568. package/dist/server/export/build.d.mts +15 -0
  569. package/dist/server/export/build.mjs +220 -0
  570. package/dist/server/export/page.d.mts +25 -0
  571. package/dist/server/export/page.mjs +40 -0
  572. package/dist/server/export/plugin.d.mts +33 -0
  573. package/dist/server/export/plugin.mjs +72 -0
  574. package/dist/server/export/run.d.mts +9 -0
  575. package/dist/server/export/run.mjs +61 -0
  576. package/dist/server/export/save.d.mts +7 -0
  577. package/dist/server/export/save.mjs +29 -0
  578. package/dist/server/features.d.mts +0 -5
  579. package/dist/server/features.mjs +1 -6
  580. package/dist/server/file-errors.mjs +4 -4
  581. package/dist/server/file-lock.mjs +14 -9
  582. package/dist/server/git-host.mjs +6 -9
  583. package/dist/server/git-paused.mjs +4 -1
  584. package/dist/server/git-settings.d.mts +1 -1
  585. package/dist/server/git-settings.mjs +5 -5
  586. package/dist/server/git-sync.d.mts +8 -0
  587. package/dist/server/git-sync.mjs +77 -19
  588. package/dist/server/git.d.mts +0 -5
  589. package/dist/server/git.mjs +53 -48
  590. package/dist/server/hosted.d.mts +8 -0
  591. package/dist/server/hosted.mjs +78 -0
  592. package/dist/server/instructions.mjs +9 -8
  593. package/dist/server/live-mirror.mjs +85 -22
  594. package/dist/server/live.mjs +35 -6
  595. package/dist/server/machine-update.mjs +32 -32
  596. package/dist/server/me.d.mts +2 -0
  597. package/dist/server/me.mjs +10 -2
  598. package/dist/server/merge-check.d.mts +14 -0
  599. package/dist/server/merge-check.mjs +80 -0
  600. package/dist/server/next.mjs +9 -6
  601. package/dist/server/notices.d.mts +7 -7
  602. package/dist/server/notices.mjs +12 -10
  603. package/dist/server/open-page.mjs +11 -10
  604. package/dist/server/outcome.d.mts +7 -8
  605. package/dist/server/own-copies.mjs +22 -12
  606. package/dist/server/people.d.mts +7 -2
  607. package/dist/server/people.mjs +10 -6
  608. package/dist/server/pictures.d.mts +1 -1
  609. package/dist/server/pictures.mjs +16 -10
  610. package/dist/server/port.mjs +5 -9
  611. package/dist/server/prebundle.d.mts +32 -0
  612. package/dist/server/prebundle.mjs +118 -0
  613. package/dist/server/preferences.mjs +1 -1
  614. package/dist/server/presence.d.mts +3 -3
  615. package/dist/server/presence.mjs +2 -4
  616. package/dist/server/problems.d.mts +8 -0
  617. package/dist/server/problems.mjs +13 -0
  618. package/dist/server/project-public.mjs +1 -1
  619. package/dist/server/prototype-brief.d.mts +36 -3
  620. package/dist/server/prototype-brief.mjs +6 -6
  621. package/dist/server/push-notice.d.mts +1 -1
  622. package/dist/server/quiet-run.mjs +1 -1
  623. package/dist/server/registry.mjs +9 -8
  624. package/dist/server/requests.d.mts +9 -20
  625. package/dist/server/requests.mjs +175 -156
  626. package/dist/server/response-budget.d.mts +16 -7
  627. package/dist/server/response-budget.mjs +6 -5
  628. package/dist/server/restart.mjs +3 -1
  629. package/dist/server/roster.d.mts +2 -2
  630. package/dist/server/roster.mjs +7 -8
  631. package/dist/server/source-stamp.d.mts +5 -3
  632. package/dist/server/source-stamp.mjs +92 -35
  633. package/dist/server/spec-decisions.mjs +2 -2
  634. package/dist/server/state.d.mts +25 -16
  635. package/dist/server/state.mjs +30 -23
  636. package/dist/server/studio-server.d.mts +92 -0
  637. package/dist/server/studio-server.mjs +77 -0
  638. package/dist/server/sync-install.mjs +2 -2
  639. package/dist/server/thread-forms.d.mts +7 -8
  640. package/dist/server/thread-forms.mjs +13 -14
  641. package/dist/server/thread-place.d.mts +2 -2
  642. package/dist/server/thread-place.mjs +28 -18
  643. package/dist/server/thread-source.d.mts +43 -5
  644. package/dist/server/thread-source.mjs +63 -41
  645. package/dist/server/tools/context.d.mts +53 -35
  646. package/dist/server/tools/context.mjs +17 -32
  647. package/dist/server/tools/describe.d.mts +3 -5
  648. package/dist/server/tools/describe.mjs +4 -24
  649. package/dist/server/tools/export.d.mts +17 -0
  650. package/dist/server/tools/export.mjs +40 -0
  651. package/dist/server/tools/feedback.d.mts +20 -4
  652. package/dist/server/tools/feedback.mjs +70 -62
  653. package/dist/server/tools/place-frame.d.mts +15 -3
  654. package/dist/server/tools/place-frame.mjs +80 -73
  655. package/dist/server/tools/prototype-name.mjs +3 -4
  656. package/dist/server/tools/reading.d.mts +4 -4
  657. package/dist/server/tools/reading.mjs +137 -114
  658. package/dist/server/tools/show.d.mts +9 -4
  659. package/dist/server/tools/show.mjs +39 -34
  660. package/dist/server/tools/snapshot.d.mts +19 -5
  661. package/dist/server/tools/snapshot.mjs +64 -59
  662. package/dist/server/tools/studio-context.d.mts +8 -0
  663. package/dist/server/tools/studio-context.mjs +44 -0
  664. package/dist/server/tools/thread-list.d.mts +19 -4
  665. package/dist/server/tools/thread-list.mjs +59 -61
  666. package/dist/server/tools/watch.d.mts +11 -4
  667. package/dist/server/tools/watch.mjs +165 -115
  668. package/dist/server/unresolved-imports.mjs +4 -1
  669. package/dist/server/update-branch.mjs +2 -2
  670. package/dist/server/update-studio.d.mts +3 -1
  671. package/dist/server/update-studio.mjs +30 -19
  672. package/dist/server/updates.mjs +10 -10
  673. package/dist/server/vite.d.mts +9 -4
  674. package/dist/server/vite.mjs +90 -83
  675. package/dist/server/web-app.mjs +17 -30
  676. package/dist/server/welcome.mjs +5 -2
  677. package/dist/server/work-groups.d.mts +13 -2
  678. package/dist/server/work-groups.mjs +58 -23
  679. package/dist/server/workspace-settings.d.mts +9 -5
  680. package/dist/server/workspace-settings.mjs +40 -39
  681. package/dist/server/zip.mjs +1 -1
  682. package/dist/setup/apply.d.mts +9 -0
  683. package/dist/setup/apply.mjs +30 -26
  684. package/dist/setup/cancelled.d.mts +6 -0
  685. package/dist/setup/cancelled.mjs +10 -0
  686. package/dist/setup/commit-lint.d.mts +6 -4
  687. package/dist/setup/commit-lint.mjs +23 -27
  688. package/dist/setup/components.mjs +3 -3
  689. package/dist/setup/config-source.d.mts +16 -5
  690. package/dist/setup/config-source.mjs +36 -27
  691. package/dist/setup/create.mjs +69 -57
  692. package/dist/setup/design-md-setup.d.mts +6 -4
  693. package/dist/setup/design-md-setup.mjs +14 -12
  694. package/dist/setup/design-md.mjs +50 -52
  695. package/dist/setup/design-system-checks.mjs +9 -14
  696. package/dist/setup/detect/workspace.d.mts +13 -27
  697. package/dist/setup/detect/workspace.mjs +33 -138
  698. package/dist/setup/detect.mjs +24 -18
  699. package/dist/setup/doctor.d.mts +4 -1
  700. package/dist/setup/doctor.mjs +21 -18
  701. package/dist/setup/existing-setup.mjs +20 -15
  702. package/dist/setup/git-checks.mjs +5 -5
  703. package/dist/setup/hash.d.mts +4 -0
  704. package/dist/setup/hash.mjs +6 -0
  705. package/dist/setup/hints.mjs +5 -4
  706. package/dist/setup/host-format.mjs +2 -6
  707. package/dist/setup/json.d.mts +12 -0
  708. package/dist/setup/json.mjs +9 -0
  709. package/dist/setup/migrate/agent-files.mjs +8 -7
  710. package/dist/setup/migrate/config-name.mjs +1 -1
  711. package/dist/setup/migrate/design-system.mjs +37 -34
  712. package/dist/setup/migrate/dex-folder.d.mts +61 -0
  713. package/dist/setup/migrate/dex-folder.mjs +548 -0
  714. package/dist/setup/migrate/explorations.mjs +7 -5
  715. package/dist/setup/migrate/files-folder.mjs +36 -21
  716. package/dist/setup/migrate/frame-notes.d.mts +20 -0
  717. package/dist/setup/migrate/frame-notes.mjs +126 -0
  718. package/dist/setup/migrate/frame-uids.d.mts +24 -0
  719. package/dist/setup/migrate/frame-uids.mjs +144 -0
  720. package/dist/setup/migrate/guides.mjs +2 -2
  721. package/dist/setup/migrate/manifest-name.d.mts +23 -0
  722. package/dist/setup/migrate/manifest-name.mjs +93 -0
  723. package/dist/setup/migrate/migrations.mjs +16 -2
  724. package/dist/setup/migrate/people-folders.d.mts +3 -3
  725. package/dist/setup/migrate/people-folders.mjs +25 -36
  726. package/dist/setup/migrate/picks-file.d.mts +33 -0
  727. package/dist/setup/migrate/picks-file.mjs +172 -0
  728. package/dist/setup/migrate/project-files.mjs +10 -8
  729. package/dist/setup/migrate/row-titles.mjs +5 -2
  730. package/dist/setup/migrate/setup-files.d.mts +5 -0
  731. package/dist/setup/migrate/setup-files.mjs +121 -0
  732. package/dist/setup/migrate/studio-state.d.mts +2 -2
  733. package/dist/setup/migrate/studio-state.mjs +12 -10
  734. package/dist/setup/own-app.d.mts +2 -1
  735. package/dist/setup/own-app.mjs +17 -15
  736. package/dist/setup/placement.d.mts +1 -1
  737. package/dist/setup/placement.mjs +25 -22
  738. package/dist/setup/plan.d.mts +10 -8
  739. package/dist/setup/plan.mjs +15 -18
  740. package/dist/setup/project.mjs +12 -9
  741. package/dist/setup/prompts.d.mts +3 -6
  742. package/dist/setup/prompts.mjs +58 -56
  743. package/dist/setup/provider.mjs +3 -2
  744. package/dist/setup/questions.d.mts +13 -7
  745. package/dist/setup/questions.mjs +5 -6
  746. package/dist/setup/starters.d.mts +1 -1
  747. package/dist/setup/starters.mjs +8 -5
  748. package/dist/setup/templates.d.mts +3 -3
  749. package/dist/setup/templates.mjs +18 -14
  750. package/dist/setup/workspace-setup.mjs +4 -5
  751. package/dist/setup/write.d.mts +24 -4
  752. package/dist/setup/write.mjs +40 -19
  753. package/dist/shared/block-merge.d.mts +5 -4
  754. package/dist/shared/block-merge.mjs +5 -5
  755. package/dist/shared/built-pictures.d.mts +13 -4
  756. package/dist/shared/built-pictures.mjs +16 -8
  757. package/dist/shared/canvas-core.d.mts +138 -63
  758. package/dist/shared/canvas-core.mjs +227 -86
  759. package/dist/shared/canvas-file.d.mts +15 -6
  760. package/dist/shared/canvas-merge.d.mts +28 -0
  761. package/dist/shared/canvas-merge.mjs +384 -0
  762. package/dist/shared/checks.d.mts +8 -0
  763. package/dist/shared/checks.mjs +9 -1
  764. package/dist/shared/code-anchor.d.mts +16 -0
  765. package/dist/shared/code-anchor.mjs +33 -0
  766. package/dist/shared/commands-core.d.mts +25 -0
  767. package/dist/shared/commands-core.mjs +31 -7
  768. package/dist/shared/comments/routes.d.mts +5 -1
  769. package/dist/shared/comments/routes.mjs +8 -4
  770. package/dist/shared/comments/state.d.mts +71 -0
  771. package/dist/shared/comments/state.mjs +66 -0
  772. package/dist/shared/contributors-merge.mjs +4 -4
  773. package/dist/shared/devices.d.mts +5 -4
  774. package/dist/shared/devices.mjs +1 -1
  775. package/dist/shared/export-core.d.mts +61 -0
  776. package/dist/shared/export-core.mjs +100 -0
  777. package/dist/shared/feedback.mjs +5 -7
  778. package/dist/shared/file-errors.mjs +3 -3
  779. package/dist/shared/file-names.d.mts +6 -0
  780. package/dist/shared/file-names.mjs +521 -0
  781. package/dist/shared/fix-prompt.mjs +1 -1
  782. package/dist/shared/front-matter.mjs +8 -9
  783. package/dist/shared/generated-sections.mjs +7 -7
  784. package/dist/shared/git-core.mjs +11 -11
  785. package/dist/shared/json-style.mjs +5 -4
  786. package/dist/shared/live-core.d.mts +12 -5
  787. package/dist/shared/live-core.mjs +11 -5
  788. package/dist/shared/live-presence.d.mts +57 -2
  789. package/dist/shared/live-presence.mjs +102 -13
  790. package/dist/shared/markup-prompt.d.mts +7 -3
  791. package/dist/shared/markup-prompt.mjs +9 -5
  792. package/dist/shared/open-page-core.mjs +6 -5
  793. package/dist/shared/page-messages.d.mts +29 -4
  794. package/dist/shared/page-messages.mjs +55 -16
  795. package/dist/shared/page-review.mjs +8 -10
  796. package/dist/shared/people-core.d.mts +61 -25
  797. package/dist/shared/people-core.mjs +74 -23
  798. package/dist/shared/{annotations-core.d.mts → picks-core.d.mts} +24 -29
  799. package/dist/shared/{annotations-core.mjs → picks-core.mjs} +48 -62
  800. package/dist/shared/presence-core.d.mts +2 -0
  801. package/dist/shared/prototypes-core.d.mts +70 -15
  802. package/dist/shared/prototypes-core.mjs +184 -100
  803. package/dist/shared/references-core.d.mts +4 -0
  804. package/dist/shared/references-core.mjs +15 -8
  805. package/dist/shared/removed-views-core.mjs +6 -6
  806. package/dist/shared/review-file.mjs +3 -3
  807. package/dist/shared/server-page.mjs +4 -4
  808. package/dist/shared/signup.mjs +3 -2
  809. package/dist/shared/sketch-core.mjs +7 -7
  810. package/dist/shared/snapshot-clipboard.d.mts +5 -4
  811. package/dist/shared/snapshot-clipboard.mjs +2 -2
  812. package/dist/shared/snapshot-images.d.mts +10 -1
  813. package/dist/shared/snapshot-images.mjs +62 -14
  814. package/dist/shared/spec-quote.mjs +4 -4
  815. package/dist/shared/studio-events.d.mts +5 -36
  816. package/dist/shared/studio-events.mjs +5 -5
  817. package/dist/shared/studio-files.d.mts +12 -3
  818. package/dist/shared/studio-files.mjs +18 -9
  819. package/dist/shared/studio-routes.d.mts +41 -31
  820. package/dist/shared/studio-routes.mjs +6 -1
  821. package/dist/shared/threads-core.d.mts +373 -36
  822. package/dist/shared/threads-core.mjs +286 -84
  823. package/dist/shared/unknown-fields.d.mts +10 -0
  824. package/dist/shared/unknown-fields.mjs +74 -0
  825. package/dist/shared/unzip.d.mts +4 -2
  826. package/dist/shared/unzip.mjs +9 -7
  827. package/dist/shared/word-diff.mjs +6 -6
  828. package/dist/shared/xray.d.mts +4 -0
  829. package/dist/shared/xray.mjs +11 -0
  830. package/extension/dist/background.js +1 -1
  831. package/extension/dist/manifest.json +2 -3
  832. package/extension/dist/picker.js +106 -286
  833. package/package.json +82 -60
  834. package/schema/canvas.json +390 -0
  835. package/schema/comment-event.json +441 -0
  836. package/schema/contributors.json +30 -0
  837. package/schema/defs.json +66 -0
  838. package/schema/file.json +59 -0
  839. package/schema/picks.json +45 -0
  840. package/src/cli/banner.ts +46 -5
  841. package/src/cli/command.ts +25 -12
  842. package/src/cli/commands/agents/add.ts +4 -1
  843. package/src/cli/commands/agents.ts +1 -0
  844. package/src/cli/commands/app.ts +33 -24
  845. package/src/cli/commands/build.ts +4 -0
  846. package/src/cli/commands/claude.ts +20 -10
  847. package/src/cli/commands/cloud/link.ts +2 -0
  848. package/src/cli/commands/cloud/live.ts +2 -0
  849. package/src/cli/commands/cloud/login.ts +1 -0
  850. package/src/cli/commands/cloud/publish.ts +23 -9
  851. package/src/cli/commands/cloud/push.ts +2 -0
  852. package/src/cli/commands/cloud/status.ts +2 -0
  853. package/src/cli/commands/cloud/unlink.ts +2 -0
  854. package/src/cli/commands/cloud.ts +1 -0
  855. package/src/cli/commands/components.ts +1 -0
  856. package/src/cli/commands/create.ts +7 -4
  857. package/src/cli/commands/dev.ts +148 -32
  858. package/src/cli/commands/doctor.ts +9 -1
  859. package/src/cli/commands/export.ts +87 -0
  860. package/src/cli/commands/extension.ts +1 -0
  861. package/src/cli/commands/hook.ts +17 -1
  862. package/src/cli/commands/init.ts +3 -0
  863. package/src/cli/commands/mcp.ts +23 -4
  864. package/src/cli/commands/merge-canvas.ts +134 -0
  865. package/src/cli/commands/merge-contributors.ts +10 -4
  866. package/src/cli/commands/merge-spec.ts +7 -1
  867. package/src/cli/commands/preview.ts +2 -0
  868. package/src/cli/commands/stop.ts +6 -0
  869. package/src/cli/commands/upgrade.ts +12 -1
  870. package/src/cli/commands/work/check.ts +2 -0
  871. package/src/cli/commands/work/contributor.ts +3 -1
  872. package/src/cli/commands/work/new.ts +3 -1
  873. package/src/cli/commands/work/presence.ts +3 -1
  874. package/src/cli/commands/work/scope.ts +3 -1
  875. package/src/cli/commands/work/snapshot.ts +3 -1
  876. package/src/cli/commands/work/thread.ts +3 -1
  877. package/src/cli/commands/work/threads.ts +3 -1
  878. package/src/cli/commands/work/whoami.ts +3 -1
  879. package/src/cli/help.ts +45 -17
  880. package/src/cli/main.ts +32 -3
  881. package/src/cli/mcp-relay.ts +150 -49
  882. package/src/cli/recovery-server.ts +23 -9
  883. package/src/cli/strict-flags.ts +41 -6
  884. package/src/cli/supervise.ts +119 -37
  885. package/src/cli/ui.ts +55 -26
  886. package/src/config/design-system.ts +65 -18
  887. package/src/config/index.ts +1 -0
  888. package/src/config/load.ts +63 -8
  889. package/src/config/project-files.ts +194 -42
  890. package/src/config/renamed.ts +25 -12
  891. package/src/config/schema.ts +8 -0
  892. package/src/content/biome.ts +31 -17
  893. package/src/content/capture.ts +200 -56
  894. package/src/content/commands.ts +115 -45
  895. package/src/content/comments-log.ts +187 -35
  896. package/src/content/component-props.ts +134 -23
  897. package/src/content/content.ts +768 -230
  898. package/src/content/devices.ts +12 -3
  899. package/src/content/element-words.ts +200 -0
  900. package/src/content/file-turns.ts +12 -4
  901. package/src/content/first-run.ts +10 -10
  902. package/src/content/flow-specs.ts +88 -40
  903. package/src/content/format-check.ts +599 -0
  904. package/src/content/hosted-person.ts +131 -0
  905. package/src/content/insert-edit.ts +52 -17
  906. package/src/content/jsx-source.ts +17 -6
  907. package/src/content/last-edited.ts +15 -4
  908. package/src/content/layout.ts +131 -9
  909. package/src/content/merge-rules.ts +96 -33
  910. package/src/content/prop-edit.ts +60 -4
  911. package/src/content/prototype-checks.ts +52 -18
  912. package/src/content/prototype-summary.ts +37 -20
  913. package/src/content/prototypes.ts +138 -52
  914. package/src/content/review-import.ts +8 -1
  915. package/src/content/review-pages.ts +63 -8
  916. package/src/content/screenshot.ts +95 -23
  917. package/src/content/snapshot-client.ts +25 -3
  918. package/src/content/store.ts +177 -55
  919. package/src/content/sub-agents.ts +107 -0
  920. package/src/content/text-edit.ts +209 -106
  921. package/src/content/text-replace.ts +130 -61
  922. package/src/content/thread-module.ts +86 -16
  923. package/src/content/threads.ts +146 -16
  924. package/src/content/trash.ts +101 -41
  925. package/src/paste/figma/appearance.ts +39 -6
  926. package/src/paste/figma/captures.ts +21 -6
  927. package/src/paste/figma/decode.ts +82 -15
  928. package/src/paste/figma/document.ts +73 -5
  929. package/src/paste/figma/layout.ts +44 -5
  930. package/src/paste/figma/paint.ts +52 -8
  931. package/src/paste/figma/render.ts +18 -3
  932. package/src/paste/figma/styles.ts +20 -5
  933. package/src/paste/figma/text.ts +97 -29
  934. package/src/paste/figma/vector.ts +74 -12
  935. package/src/paste/fonts.ts +30 -9
  936. package/src/paste/paste.ts +45 -15
  937. package/src/paths.ts +66 -87
  938. package/src/server/agent-session.ts +451 -20
  939. package/src/server/agent-tools.ts +52 -0
  940. package/src/server/agents-place.ts +22 -0
  941. package/src/server/allowed-request.ts +7 -1
  942. package/src/server/avatars.ts +18 -6
  943. package/src/server/brief.ts +75 -16
  944. package/src/server/briefing.ts +19 -9
  945. package/src/server/build-pictures.ts +57 -9
  946. package/src/server/build-settings.ts +10 -4
  947. package/src/server/canvas-presence.ts +266 -0
  948. package/src/server/changelog.ts +15 -3
  949. package/src/server/claimed-presence.ts +32 -8
  950. package/src/server/close-check.ts +56 -19
  951. package/src/server/cloud.ts +61 -12
  952. package/src/server/command-settings.ts +31 -13
  953. package/src/server/comments/actions.ts +137 -152
  954. package/src/server/comments/agent-actions.ts +178 -0
  955. package/src/server/comments/close-tools.ts +240 -0
  956. package/src/server/comments/files.ts +66 -0
  957. package/src/server/comments/hand-out.ts +105 -0
  958. package/src/server/comments/push.ts +503 -0
  959. package/src/server/comments/routes.ts +46 -61
  960. package/src/server/comments/studio-files.ts +128 -0
  961. package/src/server/comments/tools.ts +103 -301
  962. package/src/server/comments/workflow.ts +18 -0
  963. package/src/server/comments/workspace.ts +123 -0
  964. package/src/server/component-catalogue.ts +58 -20
  965. package/src/server/config-settings.ts +11 -3
  966. package/src/server/content-type.ts +3 -1
  967. package/src/server/dependency-clash.ts +86 -26
  968. package/src/server/desktop.ts +92 -0
  969. package/src/server/dev-server.ts +130 -86
  970. package/src/server/export/build.ts +344 -0
  971. package/src/server/export/page.ts +94 -0
  972. package/src/server/export/plugin.ts +157 -0
  973. package/src/server/export/run.ts +91 -0
  974. package/src/server/export/save.ts +43 -0
  975. package/src/server/features.ts +4 -6
  976. package/src/server/file-errors.ts +35 -5
  977. package/src/server/file-lock.ts +53 -19
  978. package/src/server/git-asks.ts +13 -4
  979. package/src/server/git-host.ts +51 -12
  980. package/src/server/git-paused.ts +39 -3
  981. package/src/server/git-settings.ts +15 -5
  982. package/src/server/git-sync.ts +229 -36
  983. package/src/server/git.ts +236 -116
  984. package/src/server/hosted.ts +124 -0
  985. package/src/server/instructions.ts +32 -7
  986. package/src/server/live-mirror.ts +202 -18
  987. package/src/server/live.ts +131 -17
  988. package/src/server/machine-update.ts +170 -38
  989. package/src/server/me.ts +18 -4
  990. package/src/server/merge-check.ts +125 -0
  991. package/src/server/next.ts +30 -8
  992. package/src/server/notices.ts +79 -17
  993. package/src/server/open-page.ts +44 -19
  994. package/src/server/outcome.ts +8 -7
  995. package/src/server/own-copies.ts +104 -13
  996. package/src/server/people.ts +33 -9
  997. package/src/server/personal-folder.ts +3 -0
  998. package/src/server/pictures.ts +78 -10
  999. package/src/server/port.ts +38 -6
  1000. package/src/server/prebundle.ts +265 -0
  1001. package/src/server/preferences.ts +6 -1
  1002. package/src/server/presence.ts +18 -7
  1003. package/src/server/problems.ts +13 -0
  1004. package/src/server/project-id.ts +2 -0
  1005. package/src/server/project-public.ts +12 -1
  1006. package/src/server/prototype-brief.ts +36 -17
  1007. package/src/server/push-notice.ts +11 -1
  1008. package/src/server/quiet-run.ts +10 -3
  1009. package/src/server/registry.ts +34 -7
  1010. package/src/server/requests.ts +597 -291
  1011. package/src/server/response-budget.ts +29 -6
  1012. package/src/server/restart.ts +36 -3
  1013. package/src/server/roster.ts +51 -9
  1014. package/src/server/saved.ts +16 -6
  1015. package/src/server/source-stamp.ts +224 -39
  1016. package/src/server/spec-decisions.ts +11 -2
  1017. package/src/server/state.ts +74 -40
  1018. package/src/server/stop-studio.ts +9 -1
  1019. package/src/server/studio-for.ts +38 -9
  1020. package/src/server/studio-server.ts +233 -0
  1021. package/src/server/sync-install.ts +8 -3
  1022. package/src/server/thread-forms.ts +84 -27
  1023. package/src/server/thread-place.ts +61 -19
  1024. package/src/server/thread-source.ts +143 -47
  1025. package/src/server/tools/context.ts +95 -112
  1026. package/src/server/tools/describe.ts +10 -35
  1027. package/src/server/tools/export.ts +58 -0
  1028. package/src/server/tools/feedback.ts +47 -22
  1029. package/src/server/tools/place-frame.ts +65 -28
  1030. package/src/server/tools/prototype-name.ts +11 -7
  1031. package/src/server/tools/reading.ts +215 -177
  1032. package/src/server/tools/result.ts +3 -0
  1033. package/src/server/tools/show.ts +35 -12
  1034. package/src/server/tools/snapshot.ts +24 -12
  1035. package/src/server/tools/studio-context.ts +72 -0
  1036. package/src/server/tools/thread-list.ts +58 -43
  1037. package/src/server/tools/watch.ts +230 -81
  1038. package/src/server/unresolved-imports.ts +18 -3
  1039. package/src/server/update-branch.ts +29 -4
  1040. package/src/server/update-studio.ts +54 -20
  1041. package/src/server/updates.ts +57 -11
  1042. package/src/server/vite.ts +254 -133
  1043. package/src/server/web-app.ts +27 -46
  1044. package/src/server/welcome.ts +11 -4
  1045. package/src/server/work-groups.ts +150 -34
  1046. package/src/server/workspace-settings.ts +133 -45
  1047. package/src/server/zip.ts +21 -3
  1048. package/src/setup/apply.ts +139 -44
  1049. package/src/setup/cancelled.ts +7 -0
  1050. package/src/setup/commit-lint.ts +104 -28
  1051. package/src/setup/components.ts +18 -3
  1052. package/src/setup/config-choices.ts +7 -0
  1053. package/src/setup/config-source.ts +226 -61
  1054. package/src/setup/create.ts +291 -74
  1055. package/src/setup/design-md-setup.ts +48 -11
  1056. package/src/setup/design-md.ts +276 -80
  1057. package/src/setup/design-system-checks.ts +71 -18
  1058. package/src/setup/design-system-guide.ts +7 -0
  1059. package/src/setup/detect/workspace.ts +239 -213
  1060. package/src/setup/detect.ts +95 -26
  1061. package/src/setup/doctor.ts +97 -26
  1062. package/src/setup/existing-setup.ts +114 -22
  1063. package/src/setup/git-checks.ts +60 -7
  1064. package/src/setup/hash.ts +5 -0
  1065. package/src/setup/hints.ts +42 -4
  1066. package/src/setup/host-format.ts +31 -7
  1067. package/src/setup/json.ts +23 -0
  1068. package/src/setup/migrate/agent-files.ts +45 -9
  1069. package/src/setup/migrate/config-name.ts +13 -1
  1070. package/src/setup/migrate/design-system.ts +198 -50
  1071. package/src/setup/migrate/dex-folder.ts +957 -0
  1072. package/src/setup/migrate/explorations.ts +7 -3
  1073. package/src/setup/migrate/files-folder.ts +146 -44
  1074. package/src/setup/migrate/frame-notes.ts +253 -0
  1075. package/src/setup/migrate/frame-uids.ts +274 -0
  1076. package/src/setup/migrate/guides.ts +21 -16
  1077. package/src/setup/migrate/manifest-name.ts +183 -0
  1078. package/src/setup/migrate/migrations.ts +35 -7
  1079. package/src/setup/migrate/people-folders.ts +76 -48
  1080. package/src/setup/migrate/picks-file.ts +297 -0
  1081. package/src/setup/migrate/project-files.ts +8 -3
  1082. package/src/setup/migrate/row-titles.ts +8 -4
  1083. package/src/setup/migrate/setup-files.ts +223 -0
  1084. package/src/setup/migrate/studio-state.ts +38 -15
  1085. package/src/setup/own-app.ts +75 -21
  1086. package/src/setup/placement.ts +87 -27
  1087. package/src/setup/plan.ts +109 -35
  1088. package/src/setup/project.ts +77 -13
  1089. package/src/setup/prompts.ts +206 -58
  1090. package/src/setup/provider.ts +20 -2
  1091. package/src/setup/questions.ts +77 -26
  1092. package/src/setup/starters.ts +58 -17
  1093. package/src/setup/templates.ts +66 -20
  1094. package/src/setup/workspace-setup.ts +50 -5
  1095. package/src/setup/write.ts +96 -27
  1096. package/src/shared/agent-prompts.ts +1 -1
  1097. package/src/shared/block-merge.ts +65 -8
  1098. package/src/shared/built-pictures.ts +38 -9
  1099. package/src/shared/canvas-core.ts +643 -161
  1100. package/src/shared/canvas-file.ts +15 -6
  1101. package/src/shared/canvas-merge.ts +784 -0
  1102. package/src/shared/checks.ts +18 -0
  1103. package/src/shared/code-anchor.ts +73 -0
  1104. package/src/shared/commands-core.ts +62 -8
  1105. package/src/shared/comments/routes.ts +8 -4
  1106. package/src/shared/comments/state.ts +146 -0
  1107. package/src/shared/contributors-merge.ts +26 -12
  1108. package/src/shared/devices.ts +63 -16
  1109. package/src/shared/export-core.ts +220 -0
  1110. package/src/shared/feedback.ts +56 -8
  1111. package/src/shared/file-errors.ts +4 -4
  1112. package/src/shared/file-names.ts +528 -0
  1113. package/src/shared/fix-prompt.ts +3 -1
  1114. package/src/shared/frame-grids.ts +33 -8
  1115. package/src/shared/front-matter.ts +24 -7
  1116. package/src/shared/generated-sections.ts +30 -7
  1117. package/src/shared/git-core.ts +40 -14
  1118. package/src/shared/json-style.ts +24 -6
  1119. package/src/shared/listing.ts +1 -0
  1120. package/src/shared/live-core.ts +63 -12
  1121. package/src/shared/live-presence.ts +234 -14
  1122. package/src/shared/markup-prompt.ts +9 -4
  1123. package/src/shared/open-page-core.ts +15 -8
  1124. package/src/shared/page-messages.ts +94 -18
  1125. package/src/shared/page-review.ts +60 -35
  1126. package/src/shared/paste-arrangement.ts +4 -0
  1127. package/src/shared/people-core.ts +290 -54
  1128. package/src/shared/{annotations-core.ts → picks-core.ts} +125 -96
  1129. package/src/shared/presence-core.ts +2 -0
  1130. package/src/shared/prototypes-core.ts +323 -128
  1131. package/src/shared/references-core.ts +39 -8
  1132. package/src/shared/removed-views-core.ts +30 -7
  1133. package/src/shared/review-file.ts +38 -19
  1134. package/src/shared/server-page.ts +13 -5
  1135. package/src/shared/signup.ts +12 -2
  1136. package/src/shared/sketch-core.ts +55 -7
  1137. package/src/shared/snapshot-clipboard.ts +20 -3
  1138. package/src/shared/snapshot-images.ts +114 -14
  1139. package/src/shared/spec-quote.ts +36 -5
  1140. package/src/shared/studio-events.ts +24 -37
  1141. package/src/shared/studio-files.ts +43 -11
  1142. package/src/shared/studio-routes.ts +38 -32
  1143. package/src/shared/threads-core.ts +725 -170
  1144. package/src/shared/unknown-fields.ts +118 -0
  1145. package/src/shared/unzip.ts +22 -8
  1146. package/src/shared/update-core.ts +3 -0
  1147. package/src/shared/word-diff.ts +31 -6
  1148. package/src/shared/xray.ts +14 -0
  1149. package/templates/agents/dex-checker.md +25 -0
  1150. package/templates/agents/dex-riffer.md +16 -0
  1151. package/templates/agents/dex-worker.md +23 -0
  1152. package/templates/feedback-workflow.md +1 -1
  1153. package/templates/methods/explore.md +1 -1
  1154. package/templates/methods/handoff.md +2 -2
  1155. package/templates/methods/review.md +9 -4
  1156. package/templates/rules/always.md +1 -1
  1157. package/templates/rules/canvas-frames.md +15 -5
  1158. package/templates/rules/canvas.md +19 -11
  1159. package/templates/rules/commands.md +1 -0
  1160. package/templates/rules/prototypes.md +7 -6
  1161. package/templates/rules/scope.md +2 -2
  1162. package/templates/rules/studio.md +17 -11
  1163. package/templates/skills/boil/SKILL.md +40 -0
  1164. package/templates/skills/comprehend/SKILL.md +57 -0
  1165. package/templates/skills/distill/SKILL.md +173 -0
  1166. package/templates/skills/export-prototype/SKILL.md +36 -0
  1167. package/templates/skills/restrain/SKILL.md +76 -0
  1168. package/templates/skills/riff/SKILL.md +23 -0
  1169. package/templates/skills/riff-deep/SKILL.md +42 -0
  1170. package/templates/skills/riff-max/SKILL.md +48 -0
  1171. package/templates/skills/riff-state/SKILL.md +47 -0
  1172. package/templates/skills/riff-up/SKILL.md +40 -0
  1173. package/templates/skills/riff-wide/SKILL.md +42 -0
  1174. package/templates/starter-prototype/welcome.tsx +8 -4
  1175. package/templates/starters/standalone/README.md +1 -1
  1176. package/templates/starters/standalone/package.json +1 -1
  1177. package/templates/starters/turborepo/README.md +2 -2
  1178. package/templates/starters/turborepo/apps/web/package.json +1 -1
  1179. package/templates/starters/turborepo/apps/web/src/app.tsx +4 -4
  1180. package/templates/starters/turborepo/apps/web/src/main.tsx +4 -1
  1181. package/templates/starters/turborepo/apps/web/vite.config.ts +2 -1
  1182. package/templates/starters/turborepo/package.json +2 -2
  1183. package/templates/starters/turborepo/packages/ui/package.json +3 -3
  1184. package/templates/starters/vite/README.md +1 -1
  1185. package/templates/starters/vite/package.json +1 -1
  1186. package/templates/starters/vite/src/app.tsx +3 -2
  1187. package/templates/starters/vite/src/components/ui/button.tsx +1 -1
  1188. package/templates/starters/vite/src/index.css +1 -1
  1189. package/templates/starters/vite/src/main.tsx +4 -1
  1190. package/templates/starters/vite/vite.config.ts +2 -1
  1191. package/app/canvas/pass-wheel.ts +0 -48
  1192. package/dist/config/package-manager.d.mts +0 -15
  1193. package/dist/server/agent-env.d.mts +0 -16
  1194. package/dist/server/agents.d.mts +0 -133
  1195. package/dist/server/agents.mjs +0 -771
  1196. package/dist/server/channel.d.mts +0 -239
  1197. package/dist/server/channel.mjs +0 -687
  1198. package/dist/server/mcp-handover.d.mts +0 -37
  1199. package/dist/server/mcp.d.mts +0 -61
  1200. package/dist/server/mcp.mjs +0 -155
  1201. package/dist/server/spec-suggestions.d.mts +0 -21
  1202. package/dist/server/spec-suggestions.mjs +0 -59
  1203. package/dist/setup/desktop-app-script.d.mts +0 -28
  1204. package/dist/setup/desktop-app-script.mjs +0 -775
  1205. package/dist/setup/desktop-app-start.d.mts +0 -65
  1206. package/dist/setup/desktop-app.d.mts +0 -174
  1207. package/dist/setup/desktop-app.mjs +0 -551
  1208. package/dist/shared/element-steps.d.mts +0 -38
  1209. package/dist/shared/element-steps.mjs +0 -40
  1210. package/extension/dist/feedback.html +0 -19
  1211. package/extension/dist/feedback.js +0 -709
  1212. package/src/config/package-manager.ts +0 -93
  1213. package/src/server/agent-env.ts +0 -70
  1214. package/src/server/agents.ts +0 -1220
  1215. package/src/server/channel.ts +0 -1161
  1216. package/src/server/mcp-handover.ts +0 -147
  1217. package/src/server/mcp.ts +0 -293
  1218. package/src/server/spec-suggestions.ts +0 -87
  1219. package/src/setup/desktop-app-script.ts +0 -815
  1220. package/src/setup/desktop-app-start.ts +0 -220
  1221. package/src/setup/desktop-app.ts +0 -849
  1222. package/src/shared/element-steps.ts +0 -99
@@ -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,38 +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";
183
+ import { exportInChild } from "./export/run.ts";
178
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";
179
194
  import {
180
195
  branchPrototypes,
181
196
  clashesIn,
@@ -193,15 +208,6 @@ import {
193
208
  switchBranch,
194
209
  syncBranch,
195
210
  } from "./git.ts";
196
- import { gitAskBody } from "./git-asks.ts";
197
- import { forgetPullRequests, mergePullRequest } from "./git-host.ts";
198
- import { settlePaused, undoPaused } from "./git-paused.ts";
199
- import { readGitSettings, writeGitSettings } from "./git-settings.ts";
200
- import {
201
- moveToPullRequest,
202
- queueSync,
203
- switchToSyncBranch,
204
- } from "./git-sync.ts";
205
211
  import { writeInstructions } from "./instructions.ts";
206
212
  import {
207
213
  currentActivity,
@@ -210,11 +216,12 @@ import {
210
216
  ranBeforeThis,
211
217
  updateMachine,
212
218
  } from "./machine-update.ts";
213
- import { readAuthor, readMe } from "./me.ts";
219
+ import { readMe } from "./me.ts";
214
220
  import { loadPeople } from "./people.ts";
215
221
  import { framePictures, latestAround, latestChange } from "./pictures.ts";
216
222
  import { readPreferences, savePreferences } from "./preferences.ts";
217
223
  import { isTeammate, openPresence } from "./presence.ts";
224
+ import { Problems } from "./problems.ts";
218
225
  import { projectId } from "./project-id.ts";
219
226
  import {
220
227
  canRestart,
@@ -225,14 +232,21 @@ import {
225
232
  } from "./restart.ts";
226
233
  import { otherServers, readRoster, stopOthers } from "./roster.ts";
227
234
  import { readSaved, restoreSaved } from "./saved.ts";
228
- import { acceptSuggestion } from "./spec-suggestions.ts";
229
235
  import { writeFocus } from "./state.ts";
230
236
  import { pullBaseAndUpdate, syncAndUpdate } from "./sync-install.ts";
231
- import { type Updated, UpdateStopped, updateStudio } from "./update-studio.ts";
232
- 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";
233
247
  import { markWelcomed, readWelcome } from "./welcome.ts";
234
248
  import {
235
- IconRefused,
249
+ IconRefusedError,
236
250
  readWorkspace,
237
251
  readWorkspaceIcon,
238
252
  removeWorkspaceIcon,
@@ -243,13 +257,16 @@ import { zipFolder } from "./zip.ts";
243
257
 
244
258
  const PREFIX = "/__studio/";
245
259
  const UPDATE_WAIT_MS = 3000;
246
- const TRAILING_SLASH_RE = /\/$/;
260
+ const TRAILING_SLASH_RE = /\/$/u;
247
261
  const METHODS = ["GET", "POST", "PUT", "DELETE"] as const;
248
262
  const WITH_BODY = new Set<string>(["POST", "PUT"]);
249
263
  export const MAX_BODY_BYTES = 1_000_000;
250
- // A snapshot copied with the extension brings its images, up to 6 MB of them
251
- // (extension/messages.ts); images pasted or dropped come in whole.
252
- 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
+
253
270
  // A Markup review brings a snapshot of each page commented on.
254
271
  export const MAX_REVIEW_BYTES = 120_000_000;
255
272
  const KEEP_ALIVE_MS = 25_000;
@@ -289,27 +306,18 @@ export type AgentLauncher = (
289
306
  export type Formatter = (file: string) => Promise<void>;
290
307
 
291
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
292
310
  type RequestBody = Record<string, unknown>;
293
311
 
294
312
  /**
295
313
  * For a body passed on as it came: each prototype change refuses a slug that
296
314
  * names none (prototypeExists).
297
315
  */
316
+ // oxlint-disable-next-line anti-slop/no-unknown-returns -- matches any function, to name its first argument's type
298
317
  type ArgumentOf<F extends (...args: never[]) => unknown> = Parameters<F>[0];
299
318
 
300
319
  type Method = (typeof METHODS)[number];
301
320
 
302
- class Problems extends Error {
303
- status: number;
304
- problems: string[];
305
-
306
- constructor(status: number, problems: string[]) {
307
- super(problems.join(" "));
308
- this.status = status;
309
- this.problems = problems;
310
- }
311
- }
312
-
313
321
  /** Returned by a handler to answer other than JSON with a 200. */
314
322
  class Reply {
315
323
  status: number;
@@ -331,6 +339,7 @@ interface Failure {
331
339
  }
332
340
 
333
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.
334
343
  const messageOf = (error: unknown): string => (error as Error).message;
335
344
 
336
345
  const sendJson = (
@@ -356,6 +365,7 @@ const send = (response: ServerResponse, answered: unknown): void => {
356
365
 
357
366
  export function eventHub(): EventHub {
358
367
  const listeners = new Set<(event: StudioEvent) => void>();
368
+
359
369
  return {
360
370
  send: (event) => {
361
371
  for (const listener of listeners) {
@@ -364,6 +374,7 @@ export function eventHub(): EventHub {
364
374
  },
365
375
  listen: (listener) => {
366
376
  listeners.add(listener);
377
+
367
378
  return () => {
368
379
  listeners.delete(listener);
369
380
  };
@@ -382,11 +393,13 @@ const readBody = (
382
393
  request: IncomingMessage,
383
394
  limit = MAX_BODY_BYTES
384
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
385
397
  new Promise((resolve, reject) => {
386
398
  const chunks: Buffer[] = [];
387
399
  let size = 0;
388
400
  request.on("data", (chunk: Buffer) => {
389
401
  size += chunk.length;
402
+
390
403
  if (size <= limit) {
391
404
  chunks.push(chunk);
392
405
  }
@@ -406,9 +419,11 @@ const readJson = async (
406
419
  limit?: number
407
420
  ): Promise<RequestBody | undefined> => {
408
421
  const text = await readBody(request, limit);
422
+
409
423
  if (!text) {
410
424
  return;
411
425
  }
426
+
412
427
  try {
413
428
  return JSON.parse(text);
414
429
  } catch {
@@ -418,12 +433,16 @@ const readJson = async (
418
433
 
419
434
  const formatter = (content: string): Formatter => {
420
435
  const biome = findBiome(content);
436
+
421
437
  return (file) =>
438
+ // oxlint-disable-next-line promise/avoid-new -- resolves whether or not Biome formatted the file
422
439
  new Promise((done) => {
423
440
  if (!biome) {
424
441
  done();
442
+
425
443
  return;
426
444
  }
445
+
427
446
  execFile(biome, ["format", "--write", file], () => done());
428
447
  });
429
448
  };
@@ -444,9 +463,11 @@ const UNKNOWN_PROTOTYPE = "Unknown file.";
444
463
  */
445
464
  const whoChanges = async (content: string): Promise<string> => {
446
465
  const person = await joinCurrentPerson(content);
466
+
447
467
  if (!person) {
448
468
  throw new Problems(403, [NOT_RECOGNISED]);
449
469
  }
470
+
450
471
  return person.slug;
451
472
  };
452
473
 
@@ -456,9 +477,11 @@ const prototypeNamed = (
456
477
  { mustExist = true }: { mustExist?: boolean } = {}
457
478
  ): ResolvedPrototype => {
458
479
  const prototype = resolvePrototype(content, reference, { mustExist });
480
+
459
481
  if (!prototype) {
460
482
  throw new Problems(400, [UNKNOWN_PROTOTYPE]);
461
483
  }
484
+
462
485
  return prototype;
463
486
  };
464
487
 
@@ -469,8 +492,8 @@ type StudioPages = ReturnType<typeof studioPages>;
469
492
 
470
493
  interface RouteContext {
471
494
  body: RequestBody | undefined;
472
- /** Where this studio can make its app, asked as a desktop route answers. */
473
- desktop: () => DesktopAppHost;
495
+ /** This studio's app, asked as a desktop route answers. */
496
+ desktop: () => ProjectDesktop;
474
497
  events: EventHub;
475
498
  format: Formatter;
476
499
  launcher: AgentLauncher;
@@ -493,11 +516,13 @@ async function loadCanvas({ project, prototype }: PrototypeContext) {
493
516
  const { slug } = prototype;
494
517
  // Nobody's revision when Dex can't tell who this is: a save asks.
495
518
  const person = (await currentPerson(project.content)) ?? "";
519
+
496
520
  const { canvas, revision } = await readCanvasRevision(
497
521
  slug,
498
522
  person,
499
523
  project.content
500
524
  );
525
+
501
526
  return { ...canvas, person, revision };
502
527
  }
503
528
 
@@ -510,23 +535,28 @@ async function saveCanvas({ project, prototype, body, url }: PrototypeContext) {
510
535
  const { slug } = prototype;
511
536
  const person = await whoChanges(project.content);
512
537
  const revision = url.searchParams.get("revision") ?? undefined;
538
+
513
539
  const saved = await writeCanvas(
514
540
  { slug, person, canvas: body, revision },
515
541
  project.content
516
542
  );
543
+
517
544
  if (saved.stale) {
518
545
  throw new Problems(409, ["The canvas changed since it was read."]);
519
546
  }
547
+
520
548
  if (saved.problems) {
521
549
  throw new Problems(422, saved.problems);
522
550
  }
551
+
523
552
  const { renamed } = saved;
553
+
524
554
  return {
525
555
  ...saved.canvas,
526
556
  person: saved.person,
527
557
  revision: saved.revision,
528
- ...(Object.keys(renamed).length > 0 ? { renamed } : {}),
529
- ...(saved.large ? { large: true as const } : {}),
558
+ ...(Object.keys(renamed).length > 0 && { renamed }),
559
+ ...(saved.large && { large: true as const }),
530
560
  };
531
561
  }
532
562
 
@@ -548,60 +578,89 @@ const listRemovedViews = async (context: PrototypeContext) => ({
548
578
  trash: await trashHolds(context.project.content),
549
579
  });
550
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
+
551
601
  async function trashRemovedViews(context: PrototypeContext) {
552
602
  const { project, prototype, body, threads } = context;
553
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
+
554
614
  const trashed = await trashViews(
555
- {
556
- slug,
557
- person: await whoChanges(project.content),
558
- views: body?.views,
559
- },
615
+ { slug, person, views: body?.views },
560
616
  project.content
561
617
  );
618
+
562
619
  if (trashed.problems) {
563
620
  throw new Problems(422, trashed.problems);
564
621
  }
622
+
565
623
  // The views moved whatever the comments do: a workspace out of reach
566
624
  // leaves its threads open, as they were.
567
- const dismissed = await dismissThreadsOn(threads, {
568
- author: (await readAuthor(project.content)).name,
569
- prototype: slug,
570
- views: trashed.views,
571
- }).catch(() => []);
625
+ const dismissed = await dismissCommentsOnViews(comments, trashed.views).catch(
626
+ () => []
627
+ );
628
+
572
629
  return { ...trashed, dismissed };
573
630
  }
574
631
 
575
632
  const emptyTheTrash = async ({ project }: RouteContext) => {
576
633
  await emptyTrash(project.content);
634
+
577
635
  return {};
578
636
  };
579
637
 
580
- const listConnectedAgents = async ({ project, threads }: RouteContext) => ({
581
- agents: await connectedAgents(project.content, { threads }),
638
+ const listConnectedAgents = async ({ project }: RouteContext) => ({
639
+ agents: await connectedAgents(agentsPlace(project.content)),
582
640
  });
583
641
 
584
642
  /** Only on this machine, where that process runs. */
585
- const stopOldAgent = async ({
586
- project,
587
- body,
588
- request,
589
- threads,
590
- }: RouteContext) => {
643
+ const stopOldAgent = async ({ project, body, request }: RouteContext) => {
591
644
  onlyFromThisMachine(request, "Stop agents from the machine Dex runs on.");
592
645
  const pid = body?.pid;
646
+
593
647
  if (!(typeof pid === "number" && Number.isInteger(pid))) {
594
648
  throw new Problems(422, ["Say which agent to stop, by its process."]);
595
649
  }
650
+
596
651
  try {
597
- await stopAgentServer(project.content, pid, threads);
652
+ await stopAgentServer(agentsPlace(project.content), pid);
598
653
  } catch (error) {
599
- if (error instanceof NotAnOldSession) {
654
+ if (error instanceof NotAnOldSessionError) {
600
655
  throw new Problems(409, [error.message]);
601
656
  }
657
+
602
658
  throw error;
603
659
  }
604
- return { agents: await connectedAgents(project.content, { threads }) };
660
+
661
+ return {
662
+ agents: await connectedAgents(agentsPlace(project.content)),
663
+ };
605
664
  };
606
665
 
607
666
  const listAgentSetups = async ({ project }: RouteContext) => ({
@@ -622,6 +681,7 @@ async function addAgentSetup(context: RouteContext) {
622
681
  agentRootOf(project.root)
623
682
  )
624
683
  );
684
+
625
685
  return listAgentSetups(context);
626
686
  }
627
687
 
@@ -629,10 +689,13 @@ async function addAgentSetup(context: RouteContext) {
629
689
  const openInTerminal = ({ project, launcher, body, request }: RouteContext) => {
630
690
  onlyFromThisMachine(request, "Open agents from the machine Dex runs on.");
631
691
  const agent = body?.agent;
692
+
632
693
  if (!isLaunchAgent(agent)) {
633
694
  throw cantOpen(agent);
634
695
  }
696
+
635
697
  const agentRoot = agentRootOf(project.root);
698
+
636
699
  return agentRoot === project.root
637
700
  ? launcher(agent, project.root)
638
701
  : launcher(agent, project.root, agentRoot);
@@ -646,16 +709,20 @@ const PREFERENCES_ELSEWHERE = "Choose your agent on the machine Dex runs on.";
646
709
 
647
710
  const loadPreferences = ({ request }: RouteContext) => {
648
711
  onlyFromThisMachine(request, PREFERENCES_ELSEWHERE);
712
+
649
713
  return readPreferences();
650
714
  };
651
715
 
652
716
  async function savePersonalPreferences({ body, request }: RouteContext) {
653
717
  onlyFromThisMachine(request, PREFERENCES_ELSEWHERE);
654
718
  const agent = body?.defaultAgent ?? null;
719
+
655
720
  if (!(agent === null || isLaunchAgent(agent))) {
656
721
  throw cantOpen(agent);
657
722
  }
723
+
658
724
  await savePreferences({ defaultAgent: agent });
725
+
659
726
  return readPreferences();
660
727
  }
661
728
 
@@ -664,12 +731,14 @@ const WELCOME_ELSEWHERE = "Dex welcomes you on the machine it runs on.";
664
731
 
665
732
  function loadWelcome({ project, request }: RouteContext) {
666
733
  onlyFromThisMachine(request, WELCOME_ELSEWHERE);
734
+
667
735
  return readWelcome(project.content);
668
736
  }
669
737
 
670
738
  async function answerWelcome({ body, request }: RouteContext) {
671
739
  onlyFromThisMachine(request, WELCOME_ELSEWHERE);
672
740
  await markWelcomed(body?.answer === "sent" ? "sent" : "skipped");
741
+
673
742
  return {};
674
743
  }
675
744
 
@@ -693,9 +762,13 @@ function onlyFromThisMachine(request: IncomingMessage, problem: string): void {
693
762
  }
694
763
  }
695
764
 
696
- async function loadUpdate({ project }: RouteContext) {
765
+ async function loadUpdate({ project, url }: RouteContext) {
697
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";
698
770
  const from = await ranBeforeThis(project.content);
771
+
699
772
  const updated =
700
773
  from && isOlder(from, runningVersion)
701
774
  ? {
@@ -703,35 +776,52 @@ async function loadUpdate({ project }: RouteContext) {
703
776
  notes: await notesSince(from, runningVersion),
704
777
  }
705
778
  : undefined;
779
+
706
780
  const remote = Boolean(await remoteOf(project.content));
707
781
  const share = shareOf(await readGitSettings(project.root));
782
+
708
783
  return {
709
784
  machine,
710
- ...(updated ? { updated } : {}),
785
+ ...(updated && { updated }),
711
786
  pullRequest: remote && share === "pull-requests",
712
787
  restarts: canRestart(),
713
788
  run: RUN_ID,
714
789
  running: runningVersion,
715
790
  syncs: remote && share === "sync",
716
- update: await checkForUpdateWithin(
717
- UPDATE_WAIT_MS,
718
- project.content,
719
- project.root,
720
- { current: machine.installed ?? machine.running }
721
- ),
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),
722
803
  };
723
804
  }
724
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
+
725
813
  async function updateThisMachine({ project, request }: RouteContext) {
726
814
  onlyFromThisMachine(
727
815
  request,
728
816
  "Open Dex at localhost on the machine it runs on to update it."
729
817
  );
818
+
730
819
  return await queueSync(project.content, "step", () => updateMachine(project));
731
820
  }
732
821
 
733
822
  const updateActivity = ({ project }: RouteContext) => {
734
823
  const doing = currentActivity(project.content);
824
+
735
825
  return doing ? { doing } : {};
736
826
  };
737
827
 
@@ -740,9 +830,10 @@ const updateActivity = ({ project }: RouteContext) => {
740
830
  * answers the same route while no Dex does.
741
831
  */
742
832
  async function restartStatus({ project }: RouteContext) {
743
- const working = (await openPresence(project.content).list()).some(
744
- (entry) => !isTeammate(entry)
745
- );
833
+ const listed = await openPresence(project.content).list();
834
+
835
+ const working = listed.some((entry) => !isTeammate(entry));
836
+
746
837
  return { state: "ready" as const, run: RUN_ID, agentWorking: working };
747
838
  }
748
839
 
@@ -751,15 +842,19 @@ async function restartStudio({ project, request }: RouteContext) {
751
842
  request,
752
843
  "Open Dex at localhost on the machine it runs on to restart it."
753
844
  );
845
+
754
846
  if (orphaned()) {
755
847
  throw new Problems(409, [ORPHANED_LINE]);
756
848
  }
849
+
757
850
  if (!canRestart()) {
758
851
  throw new Problems(409, [
759
852
  "This Dex can’t restart itself. Stop it and start it again.",
760
853
  ]);
761
854
  }
855
+
762
856
  await restartWhenIdle(project.content);
857
+
763
858
  return { restartingFrom: RUN_ID };
764
859
  }
765
860
 
@@ -774,6 +869,7 @@ async function stopOtherDexes({ project, request }: RouteContext) {
774
869
  request,
775
870
  "Open Dex at localhost on the machine it runs on to stop other Dexes."
776
871
  );
872
+
777
873
  return {
778
874
  stopped: await stopOthers(project.content, projectId(project.root)),
779
875
  };
@@ -786,12 +882,13 @@ async function updateFromNotice({ project, events, request }: RouteContext) {
786
882
  );
787
883
  const settings = await readGitSettings(project.root);
788
884
  let updated: Updated | null;
885
+
789
886
  try {
790
887
  updated = await queueSync(project.content, "step", () =>
791
888
  updateStudio({ content: project.content, root: project.root, settings })
792
889
  );
793
890
  } catch (error) {
794
- throw new Problems(error instanceof UpdateStopped ? 409 : 500, [
891
+ throw new Problems(error instanceof UpdateStoppedError ? 409 : 500, [
795
892
  messageOf(error),
796
893
  ]);
797
894
  } finally {
@@ -799,29 +896,18 @@ async function updateFromNotice({ project, events, request }: RouteContext) {
799
896
  // It synced: every page's branch and changes move.
800
897
  events.send(studioEvent.git());
801
898
  }
899
+
802
900
  if (!updated) {
803
901
  throw new Problems(409, ["Dex is already up to date."]);
804
902
  }
903
+
805
904
  if (updated.restartingFrom) {
806
905
  restartWhenIdle(project.content);
807
906
  }
907
+
808
908
  return updated;
809
909
  }
810
910
 
811
- /**
812
- * `home` is the folder whose Applications the app goes in; `launchServices`
813
- * registers its URL scheme, and forgets it on remove.
814
- */
815
- export type DesktopAppHost =
816
- | {
817
- app: DesktopApp;
818
- home: string;
819
- launchServices: LaunchServices;
820
- open: (path: string) => Promise<void>;
821
- reveal: (path: string) => Promise<void>;
822
- }
823
- | { unavailable: DesktopAppUnavailable };
824
-
825
911
  /**
826
912
  * The app writes outside the project and makes something that runs code, so
827
913
  * only this machine, addressed by a loopback name, may ask; and a change
@@ -830,73 +916,44 @@ export type DesktopAppHost =
830
916
  */
831
917
  function fromThisMac(request: IncomingMessage, change: boolean): void {
832
918
  onlyFromThisMachine(request, "Install the app from the Mac Dex runs on.");
919
+
833
920
  if (change && !request.headers.origin) {
834
921
  throw new Problems(403, ["Install the app from Dex's Settings."]);
835
922
  }
836
923
  }
837
924
 
838
- const desktopAnswer = async (
839
- desktop: DesktopAppHost
840
- ): Promise<DesktopAppAnswer> =>
841
- "unavailable" in desktop
842
- ? { available: false, why: desktop.unavailable }
843
- : {
844
- available: true,
845
- ...(await desktopAppState(desktop.app, desktop.home)),
846
- };
847
-
848
- const loadDesktopApp = ({ request, desktop }: RouteContext) => {
925
+ const loadDesktopApp = ({
926
+ request,
927
+ desktop,
928
+ }: RouteContext): Promise<DesktopAppAnswer> => {
849
929
  fromThisMac(request, false);
850
- return desktopAnswer(desktop());
930
+
931
+ return desktop().answer();
851
932
  };
852
933
 
853
- async function changeDesktopApp({ request, desktop, body }: RouteContext) {
934
+ const changeDesktopApp = ({
935
+ request,
936
+ desktop,
937
+ body,
938
+ }: RouteContext): Promise<DesktopAppAnswer> => {
854
939
  fromThisMac(request, true);
855
- const host = desktop();
856
- if ("unavailable" in host) {
857
- throw new Problems(409, [
858
- host.unavailable === "hosted"
859
- ? "A hosted studio can't install an app."
860
- : "Installing outside the browser is macOS-only for now.",
861
- ]);
862
- }
863
- const { app, home, reveal, open, launchServices } = host;
864
- switch (body?.action) {
865
- case "install": {
866
- const path = await refusable(() =>
867
- installDesktopApp(app, home, launchServices)
868
- );
869
- await reveal(path).catch(() => undefined);
870
- break;
871
- }
872
- case "open": {
873
- if (!(await desktopAppState(app, home)).installed) {
874
- throw new Problems(409, ["Install the app first."]);
875
- }
876
- await refusable(() => open(bundlePath(home)));
877
- break;
878
- }
879
- case "remove":
880
- await refusable(() => removeDesktopApp(app, home, launchServices));
881
- break;
882
- default:
883
- throw new Problems(400, [
884
- 'Send an action: "install", "open" or "remove".',
885
- ]);
886
- }
887
- return desktopAnswer(host);
888
- }
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
+ };
889
945
 
890
946
  const readWatch = async ({ project }: RouteContext) => ({
891
- on: await isWatching(project.content),
947
+ on: await isWatching(agentsPlace(project.content)),
892
948
  });
893
949
 
894
950
  /** Every open page hears it, so each switch shows the same. */
895
951
  const setWatch = ({ project, body, events, pages }: RouteContext) =>
896
952
  pages.inWatchOrder(async () => {
897
- await setWatching(project.content, Boolean(body?.on));
898
- const on = await isWatching(project.content);
953
+ await setWatching(agentsPlace(project.content), Boolean(body?.on));
954
+ const on = await isWatching(agentsPlace(project.content));
899
955
  events.send(studioEvent.watch(on));
956
+
900
957
  return { on };
901
958
  });
902
959
 
@@ -915,124 +972,165 @@ async function saveSnapshots(
915
972
  cell?: Cell
916
973
  ) {
917
974
  const person = await whoChanges(project.content);
918
- // No captured event: a paste lands where the pointer is, in view, so the
919
- // canvas does not move to it.
975
+
976
+ // No captured event: the page that pasted goes to what it made itself.
920
977
  return await refusable(() =>
921
978
  saveCaptures({ slug: target.slug, person, captures, cell }, project.content)
922
979
  );
923
980
  }
924
981
 
925
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
926
985
  const cell = value as Partial<Record<keyof Cell, unknown>> | undefined;
986
+
927
987
  const fits =
928
988
  typeof cell?.section === "string" &&
929
989
  (cell.row === undefined || typeof cell.row === "string") &&
930
990
  typeof cell.step === "number" &&
931
991
  Number.isInteger(cell.step) &&
932
992
  cell.step >= 1;
993
+
994
+ // SAFETY: fits checked every field a Cell has.
933
995
  return fits ? (cell as Cell) : undefined;
934
996
  };
935
997
 
936
998
  async function pasteSnapshots(context: RouteContext) {
937
999
  const { body } = context;
938
1000
  let pasted: Pasted;
1001
+
939
1002
  try {
940
1003
  pasted = await readPaste(body ?? {});
941
1004
  } catch (error) {
942
- if (error instanceof PasteProblem) {
1005
+ if (error instanceof PasteProblemError) {
943
1006
  throw new Problems(error.status, [error.message]);
944
1007
  }
1008
+
945
1009
  throw error;
946
1010
  }
1011
+
947
1012
  const { saved, large } = await saveSnapshots(
948
1013
  context,
949
1014
  body ?? {},
950
1015
  pasted.captures,
951
1016
  cellFrom(body?.cell)
952
1017
  );
1018
+
953
1019
  return {
954
1020
  from: pasted.from,
955
1021
  saved: saved.map(({ name, frame }) => ({ name, frame })),
956
1022
  images: pasted.images,
957
- ...(large ? { large: true as const } : {}),
1023
+ ...(large && { large: true as const }),
958
1024
  };
959
1025
  }
960
1026
 
961
- /**
962
- * The view and the canvas with its frame are written together, before the
963
- * studio reloads to find the view.
964
- */
965
1027
  /**
966
1028
  * Take every open studio page to a frame on a file's canvas: an agent's
967
1029
  * `show`, when the person asks to see what it made. The pages open the
968
1030
  * canvas and zoom to the frame once it is laid out.
969
1031
  */
970
1032
  function showOnCanvas({ project, events, pages, body }: RouteContext) {
971
- const { slug } = prototypeNamed(project.content, body ?? {}, {
972
- mustExist: true,
973
- });
1033
+ const { slug } = prototypeNamed(project.content, body ?? {});
974
1034
  const frame = body?.frame;
1035
+
975
1036
  if (typeof frame !== "string" || frame.split("/").length !== 3) {
976
1037
  throw new Problems(400, ['Say which frame, as "section/row/frame".']);
977
1038
  }
1039
+
978
1040
  events.send(studioEvent.show(slug, frame));
1041
+
979
1042
  return { pages: pages.listening() };
980
1043
  }
981
1044
 
1045
+ /**
1046
+ * The view and the canvas with its frame are written together, before the
1047
+ * studio reloads to find the view.
1048
+ */
982
1049
  async function addBlankFrame({ project, events, body }: RouteContext) {
983
1050
  const { slug, view, frame, canvas, component, reveal } = body ?? {};
1051
+
984
1052
  if (!(isSlug(slug) && isSlug(view)) || typeof frame !== "string") {
985
1053
  throw new Problems(400, ["Say where the frame goes."]);
986
1054
  }
1055
+
987
1056
  if (component !== undefined) {
988
1057
  needsFeature("stickers");
989
1058
  }
1059
+
990
1060
  if (
991
1061
  component !== undefined &&
1062
+ // SAFETY: isInsertable checks every field.
992
1063
  !isInsertable(component as Partial<InsertedComponent>)
993
1064
  ) {
994
1065
  throw new Problems(400, ["That is not a component the studio can add."]);
995
1066
  }
1067
+
1068
+ // SAFETY: isInsertable checked it just above.
996
1069
  const source =
997
1070
  component === undefined
998
1071
  ? BLANK_VIEW
999
1072
  : componentView(component as InsertedComponent);
1073
+
1000
1074
  prototypeNamed(project.content, { slug });
1001
- if ((await viewFiles(project.content, slug)).has(view)) {
1075
+
1076
+ const views = await viewFiles(project.content, slug);
1077
+
1078
+ if (views.has(view)) {
1002
1079
  throw new Problems(409, ["That view already exists."]);
1003
1080
  }
1081
+
1004
1082
  const person = await whoChanges(project.content);
1083
+
1005
1084
  const saved = await writeCanvas(
1006
1085
  { slug, person, canvas, views: { [view]: source } },
1007
1086
  project.content
1008
1087
  );
1088
+
1009
1089
  if (saved.problems) {
1010
1090
  throw new Problems(422, saved.problems);
1011
1091
  }
1092
+
1012
1093
  // Before the studio reloads to find the view, so the canvas shows it; not
1013
1094
  // for a frame drawn where the person is looking.
1014
1095
  if (reveal !== false) {
1015
1096
  events.send(studioEvent.captured(slug, frame));
1016
1097
  }
1098
+
1017
1099
  return {
1018
1100
  view,
1019
1101
  frame,
1020
- ...(saved.canvas && saved.large ? { large: true as const } : {}),
1102
+ ...(saved.canvas && saved.large && { large: true as const }),
1021
1103
  };
1022
1104
  }
1023
1105
 
1024
- /** A 409 says why not, and the canvas asks the agent instead. */
1106
+ /**
1107
+ * Text changed with the Text tool: { from, to } and the element's stamped
1108
+ * `place`, changed in the person's own code. A 409 says why not, and the
1109
+ * canvas asks the agent instead.
1110
+ */
1025
1111
  async function changeText({ project, body }: RouteContext) {
1026
- const { folder } = prototypeNamed(project.content, body ?? {});
1112
+ const { folder, slug } = prototypeNamed(project.content, body ?? {});
1113
+
1114
+ const own = join(
1115
+ folder,
1116
+ STUDIO_FILES.people,
1117
+ await whoChanges(project.content)
1118
+ );
1119
+
1027
1120
  // The text as the canvas sends it; editText checks there is some.
1028
1121
  const result = await editText(
1029
- folder,
1030
- body?.from as string | undefined,
1031
- body?.to as string | undefined
1122
+ { content: project.content, own, slug },
1123
+ {
1124
+ from: typeof body?.from === "string" ? body.from : undefined,
1125
+ to: typeof body?.to === "string" ? body.to : undefined,
1126
+ place: typeof body?.place === "string" ? body.place : undefined,
1127
+ }
1032
1128
  );
1129
+
1033
1130
  if (!("file" in result)) {
1034
1131
  throw new Problems(409, [result.reason]);
1035
1132
  }
1133
+
1036
1134
  return result;
1037
1135
  }
1038
1136
 
@@ -1043,20 +1141,27 @@ async function changeText({ project, body }: RouteContext) {
1043
1141
  */
1044
1142
  async function replaceOnCanvas({ project, body }: RouteContext) {
1045
1143
  const { folder } = prototypeNamed(project.content, body ?? {});
1144
+
1046
1145
  const own = join(
1047
1146
  folder,
1048
1147
  STUDIO_FILES.people,
1049
1148
  await whoChanges(project.content)
1050
1149
  );
1150
+
1051
1151
  if (typeof body?.undo === "string") {
1052
1152
  return await undoReplace(own, body.undo);
1053
1153
  }
1154
+
1054
1155
  const { find, to, seen } = body ?? {};
1055
- if (
1056
- !(typeof find === "string" && typeof to === "string" && Array.isArray(seen))
1057
- ) {
1156
+
1157
+ if (!(
1158
+ typeof find === "string" &&
1159
+ typeof to === "string" &&
1160
+ Array.isArray(seen)
1161
+ )) {
1058
1162
  throw new Problems(400, ["Say what to find, and what to change it to."]);
1059
1163
  }
1164
+
1060
1165
  return await replaceText(
1061
1166
  own,
1062
1167
  find,
@@ -1071,36 +1176,35 @@ const needsFeature = (name: Feature) => {
1071
1176
  }
1072
1177
  };
1073
1178
 
1074
- async function loadAnnotations({ project, prototype }: PrototypeContext) {
1075
- const { annotations } = await readPrototypeAnnotations(
1076
- prototype.slug,
1077
- project.content
1078
- );
1079
- return { annotations };
1179
+ async function loadPicks({ project, prototype }: PrototypeContext) {
1180
+ const { picks } = await readPrototypePicks(prototype.slug, project.content);
1181
+
1182
+ return { picks };
1080
1183
  }
1081
1184
 
1082
- const savedAnnotations = (saved: SavedAnnotations) => {
1185
+ const savedPicks = (saved: SavedPicks) => {
1083
1186
  if (saved.problems) {
1084
1187
  throw new Problems(422, saved.problems);
1085
1188
  }
1086
- return { annotations: saved.annotations };
1189
+
1190
+ return { picks: saved.picks };
1087
1191
  };
1088
1192
 
1089
- const saveOwnAnnotation = async (context: PrototypeContext) =>
1090
- savedAnnotations(
1091
- await saveAnnotation(
1193
+ const saveOwnPick = async (context: PrototypeContext) =>
1194
+ savedPicks(
1195
+ await savePick(
1092
1196
  {
1093
1197
  slug: context.prototype.slug,
1094
1198
  person: await whoChanges(context.project.content),
1095
- annotation: context.body,
1199
+ pick: context.body,
1096
1200
  },
1097
1201
  context.project.content
1098
1202
  )
1099
1203
  );
1100
1204
 
1101
- const removeOwnAnnotation = async (context: PrototypeContext) =>
1102
- savedAnnotations(
1103
- await removeAnnotation(
1205
+ const removeOwnPick = async (context: PrototypeContext) =>
1206
+ savedPicks(
1207
+ await removePick(
1104
1208
  {
1105
1209
  slug: context.prototype.slug,
1106
1210
  person: await whoChanges(context.project.content),
@@ -1114,17 +1218,21 @@ const removeOwnAnnotation = async (context: PrototypeContext) =>
1114
1218
  async function changeProps({ project, body }: RouteContext) {
1115
1219
  needsFeature("inspector");
1116
1220
  const { folder } = prototypeNamed(project.content, body ?? {});
1221
+
1117
1222
  const result = await editProps(
1118
1223
  project.content,
1119
1224
  folder,
1120
1225
  typeof body?.place === "string" ? body.place : undefined,
1226
+ // SAFETY: an object of prop changes; editProps checks each.
1121
1227
  body?.props && typeof body.props === "object"
1122
1228
  ? (body.props as Record<string, PropChange>)
1123
1229
  : undefined
1124
1230
  );
1231
+
1125
1232
  if (!("file" in result)) {
1126
1233
  throw new Problems(409, [result.reason]);
1127
1234
  }
1235
+
1128
1236
  return result;
1129
1237
  }
1130
1238
 
@@ -1132,16 +1240,20 @@ async function changeProps({ project, body }: RouteContext) {
1132
1240
  async function insertIntoView({ project, body }: RouteContext) {
1133
1241
  needsFeature("stickers");
1134
1242
  const { folder } = prototypeNamed(project.content, body ?? {});
1243
+
1135
1244
  const result = await insertComponent(
1136
1245
  project.content,
1137
1246
  folder,
1138
1247
  typeof body?.place === "string" ? body.place : undefined,
1139
1248
  typeof body?.position === "string" ? body.position : undefined,
1249
+ // SAFETY: insertComponent checks it with isInsertable.
1140
1250
  body?.component as Partial<InsertedComponent> | undefined
1141
1251
  );
1252
+
1142
1253
  if (!("file" in result)) {
1143
1254
  throw new Problems(409, [result.reason]);
1144
1255
  }
1256
+
1145
1257
  return result;
1146
1258
  }
1147
1259
 
@@ -1149,16 +1261,21 @@ function shotOf({ request, body, pageBase }: RouteContext) {
1149
1261
  if (!body) {
1150
1262
  throw new Problems(400, ["Say which view to capture."]);
1151
1263
  }
1264
+
1152
1265
  const site = `http://localhost:${request.socket.localPort}${pageBase}`;
1266
+
1153
1267
  return screenshotFrame(site, body);
1154
1268
  }
1155
1269
 
1156
1270
  async function screenshotView(context: RouteContext) {
1157
- 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");
1158
1274
  }
1159
1275
 
1160
1276
  async function snapshotOfView(context: RouteContext): Promise<SnapshotBody> {
1161
1277
  const { image, problems } = await shotOf(context);
1278
+
1162
1279
  return { image: image.toString("base64"), problems };
1163
1280
  }
1164
1281
 
@@ -1196,19 +1313,22 @@ async function pictureOfView({
1196
1313
  response,
1197
1314
  }: RouteContext) {
1198
1315
  const href = typeof body?.href === "string" ? body.href : "";
1316
+
1199
1317
  if (!(body && isViewPage(href))) {
1200
1318
  throw new Problems(400, ["Say which view to picture."]);
1201
1319
  }
1320
+
1202
1321
  const { folder } = prototypeNamed(project.content, href);
1203
1322
  const address = viewInFrame(href);
1204
- if (
1205
- !(
1206
- address &&
1207
- (await viewFiles(project.content, address.slug)).has(address.view)
1208
- )
1209
- ) {
1323
+
1324
+ const views = address
1325
+ ? await viewFiles(project.content, address.slug)
1326
+ : undefined;
1327
+
1328
+ if (!(address && views?.has(address.view))) {
1210
1329
  throw new Problems(NOT_THERE, ["That view is not there yet."]);
1211
1330
  }
1331
+
1212
1332
  const stamp = Math.max(
1213
1333
  await latestChange(
1214
1334
  project.content,
@@ -1219,19 +1339,26 @@ async function pictureOfView({
1219
1339
  skip: [project.content],
1220
1340
  })
1221
1341
  );
1342
+
1222
1343
  response.setHeader("X-Studio-Stamp", String(stamp));
1344
+
1223
1345
  if (Number(body.stamp) === stamp) {
1224
1346
  return new Reply(204, "", "image/jpeg");
1225
1347
  }
1348
+
1226
1349
  if (body.stamp === undefined) {
1227
1350
  const last = await pictures.last(body, project.content);
1351
+
1228
1352
  if (last && last.stamp !== stamp) {
1229
1353
  response.setHeader("X-Studio-Stamp", String(last.stamp));
1230
1354
  response.setHeader(STALE_PICTURE_HEADER, "1");
1355
+
1231
1356
  return new Reply(200, last.image, "image/jpeg");
1232
1357
  }
1233
1358
  }
1359
+
1234
1360
  const site = `http://localhost:${request.socket.localPort}${pageBase}`;
1361
+
1235
1362
  return new Reply(
1236
1363
  200,
1237
1364
  await pictures.picture(site, body, stamp, project.content),
@@ -1239,10 +1366,6 @@ async function pictureOfView({
1239
1366
  );
1240
1367
  }
1241
1368
 
1242
- /** Threads are never kept for a folder that is not a prototype. */
1243
- const threadsPrototype = (content: string, url: URL): string =>
1244
- prototypeOf(content, url).slug;
1245
-
1246
1369
  const REVIEW_FILE_PROBLEMS: Record<ReviewFileProblem, string> = {
1247
1370
  "not-a-review": "This is not a Dex review.",
1248
1371
  newer: "This review is from a newer Dex: update to import it.",
@@ -1255,7 +1378,8 @@ const PAGE_REVIEW_PROBLEMS: Record<"newer" | "unreadable", string> = {
1255
1378
  };
1256
1379
 
1257
1380
  async function reviewFileOf(
1258
- context: RouteContext,
1381
+ content: string,
1382
+ slug: string,
1259
1383
  file: unknown
1260
1384
  ): Promise<
1261
1385
  | { pages?: number; problems?: undefined; review: ReviewFile }
@@ -1263,52 +1387,59 @@ async function reviewFileOf(
1263
1387
  > {
1264
1388
  if (!isPageReview(file)) {
1265
1389
  const read = parseReviewFile(file);
1390
+
1266
1391
  return read.review
1267
1392
  ? { review: read.review }
1268
1393
  : { problems: [REVIEW_FILE_PROBLEMS[read.problem]] };
1269
1394
  }
1395
+
1270
1396
  const read = parsePageReview(file);
1397
+
1271
1398
  if (!read.review) {
1272
1399
  return { problems: [PAGE_REVIEW_PROBLEMS[read.problem]] };
1273
1400
  }
1274
- const { slug } = prototypeOf(context.project.content, context.url);
1275
- const person = await whoChanges(context.project.content);
1401
+
1402
+ const person = await whoChanges(content);
1403
+
1276
1404
  const placed = await refusable(() =>
1277
- placeReviewPages(
1278
- { slug, person, review: read.review },
1279
- context.project.content
1280
- )
1405
+ placeReviewPages({ slug, person, review: read.review }, content)
1281
1406
  );
1407
+
1282
1408
  return { review: placed.file, pages: placed.added };
1283
1409
  }
1284
1410
 
1285
- async function importReviews(context: RouteContext) {
1286
- const { project, url, body, threads } = context;
1287
- const prototype = threadsPrototype(project.content, url);
1411
+ async function importReviews({ project, url, body, threads }: RouteContext) {
1412
+ const { slug: prototype } = prototypeOf(project.content, url);
1288
1413
  const files: unknown = body?.reviews;
1414
+
1289
1415
  if (!Array.isArray(files) || files.length === 0) {
1290
1416
  throw new Problems(400, ["Send the reviews to import."]);
1291
1417
  }
1418
+
1292
1419
  const reviews: ReviewImported[] = [];
1420
+
1293
1421
  for (const file of files) {
1294
- const read = await reviewFileOf(context, file);
1422
+ const read = await reviewFileOf(project.content, prototype, file);
1423
+
1295
1424
  if (!read.review) {
1296
1425
  reviews.push({ problems: read.problems });
1297
1426
  continue;
1298
1427
  }
1299
- const answer = await threads.importReview(prototype, read.review);
1428
+
1429
+ const imported = await threads.importReview(prototype, read.review);
1300
1430
  reviews.push(
1301
- answer.problems
1302
- ? { problems: answer.problems }
1431
+ imported.problems
1432
+ ? { problems: imported.problems }
1303
1433
  : {
1304
1434
  title: read.review.review.title,
1305
1435
  reviewer: read.review.reviewer.name,
1306
- added: answer.added,
1307
- skipped: answer.skipped,
1308
- ...(read.pages ? { pages: read.pages } : {}),
1436
+ added: imported.added,
1437
+ skipped: imported.skipped,
1438
+ ...(read.pages && { pages: read.pages }),
1309
1439
  }
1310
1440
  );
1311
1441
  }
1442
+
1312
1443
  return { reviews };
1313
1444
  }
1314
1445
 
@@ -1319,34 +1450,32 @@ async function acceptSpecSuggestion({
1319
1450
  threads,
1320
1451
  }: RouteContext) {
1321
1452
  const id = body?.id;
1453
+
1322
1454
  if (typeof id !== "string") {
1323
1455
  throw new Problems(400, ["Name the suggestion to accept."]);
1324
1456
  }
1325
- const person = await whoChanges(project.content);
1326
- const result = await acceptSuggestion({
1327
- author: (await readAuthor(project.content)).name,
1328
- id,
1329
- person,
1330
- prototype: threadsPrototype(project.content, url),
1331
- root: project.content,
1332
- threads,
1333
- });
1334
- if ("problems" in result) {
1335
- throw new Problems(result.status, result.problems);
1336
- }
1337
- 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));
1338
1464
  }
1339
1465
 
1340
1466
  const instructionsPath = (url: URL): string => {
1341
1467
  const path = url.searchParams.get("path");
1468
+
1342
1469
  if (!(path && isEditableMarkdown(path))) {
1343
1470
  throw new Problems(400, ["That file is not one of the guidelines."]);
1344
1471
  }
1472
+
1345
1473
  return path;
1346
1474
  };
1347
1475
 
1348
1476
  const loadInstructions = async ({ project, url }: RouteContext) => {
1349
1477
  const path = instructionsPath(url);
1478
+
1350
1479
  return { path, source: await readText(join(project.content, path)) };
1351
1480
  };
1352
1481
 
@@ -1363,14 +1492,17 @@ async function saveInstructions({ project, url, body }: RouteContext) {
1363
1492
  const part = splitPrototypePath(path);
1364
1493
  const isSomeonesFile = owner !== undefined || part !== undefined;
1365
1494
  const person = isSomeonesFile ? await whoChanges(project.content) : undefined;
1495
+
1366
1496
  if (owner && owner !== person) {
1367
1497
  throw new Problems(403, ["Those are someone else's guidelines."]);
1368
1498
  }
1499
+
1369
1500
  // A spec or a document anyone edits: a change made meanwhile is merged
1370
1501
  // in, not lost.
1371
1502
  const source = await refusable(() =>
1372
1503
  writeInstructions(project.content, path, body?.source, body?.base)
1373
1504
  );
1505
+
1374
1506
  return { path, source };
1375
1507
  }
1376
1508
 
@@ -1385,19 +1517,23 @@ const GIT_ELSEWHERE =
1385
1517
  */
1386
1518
  async function loadGit({ project, url, request }: RouteContext) {
1387
1519
  const here = isThisMachine(request);
1520
+
1388
1521
  if (url.searchParams.get("fetch") === "1" && here) {
1389
1522
  await fetchRemote(project.content);
1390
1523
  forgetPullRequests();
1391
1524
  }
1525
+
1392
1526
  const state = await gitStatus(
1393
1527
  project.content,
1394
1528
  await readGitSettings(project.root)
1395
1529
  );
1530
+
1396
1531
  return here || !state.repo ? state : { ...state, folder: undefined };
1397
1532
  }
1398
1533
 
1399
1534
  async function loadGitBranches({ project, url }: RouteContext) {
1400
1535
  const prototype = url.searchParams.get("prototype");
1536
+
1401
1537
  return {
1402
1538
  branches: prototype
1403
1539
  ? await prototypeBranches(
@@ -1423,6 +1559,8 @@ const GIT_STEP_NAMES: Record<GitStepName, true> = {
1423
1559
  "undo-paused": true,
1424
1560
  ask: true,
1425
1561
  };
1562
+
1563
+ // SAFETY: GIT_STEP_NAMES has one key per GitStepName.
1426
1564
  const GIT_STEPS = Object.keys(GIT_STEP_NAMES) as GitStepName[];
1427
1565
 
1428
1566
  const oneOf = <T extends string>(
@@ -1430,6 +1568,7 @@ const oneOf = <T extends string>(
1430
1568
  value: unknown
1431
1569
  ): value is T => list.some((item) => item === value);
1432
1570
 
1571
+ // oxlint-disable-next-line anti-slop/no-unknown-returns -- git's problems or the error as it was, sent back as is
1433
1572
  const gitProblems = (error: unknown): unknown =>
1434
1573
  error instanceof GitError
1435
1574
  ? new Problems(409, [
@@ -1448,14 +1587,17 @@ async function takeGitStep({
1448
1587
  }: RouteContext) {
1449
1588
  onlyFromThisMachine(request, GIT_ELSEWHERE);
1450
1589
  const step: unknown = body?.step;
1590
+
1451
1591
  if (!oneOf<GitStepName>(GIT_STEPS, step)) {
1452
1592
  throw new Problems(400, [`A step is one of: ${GIT_STEPS.join(", ")}.`]);
1453
1593
  }
1594
+
1454
1595
  const settings = await readGitSettings(project.root);
1455
1596
  const cwd = project.content;
1597
+
1456
1598
  try {
1457
1599
  switch (step) {
1458
- case "branch":
1600
+ case "branch": {
1459
1601
  await queueSync(cwd, "step", () =>
1460
1602
  createBranch(
1461
1603
  cwd,
@@ -1465,43 +1607,62 @@ async function takeGitStep({
1465
1607
  )
1466
1608
  );
1467
1609
  break;
1468
- case "switch":
1610
+ }
1611
+
1612
+ case "switch": {
1469
1613
  await queueSync(cwd, "step", () =>
1470
1614
  switchBranch(cwd, String(body?.name ?? ""))
1471
1615
  );
1472
1616
  break;
1473
- case "switch-to-sync":
1617
+ }
1618
+
1619
+ case "switch-to-sync": {
1474
1620
  await switchToSyncBranch(cwd, settings);
1475
1621
  break;
1476
- case "commit":
1622
+ }
1623
+
1624
+ case "commit": {
1477
1625
  await queueSync(cwd, "step", () =>
1478
1626
  commitAll(cwd, String(body?.message ?? ""))
1479
1627
  );
1480
1628
  break;
1629
+ }
1630
+
1481
1631
  // Each moves the branch: one running beside a Sync could undo it.
1482
- case "push":
1632
+ case "push": {
1483
1633
  await queueSync(cwd, "step", () => pushBranch(cwd));
1484
1634
  break;
1485
- case "sync":
1635
+ }
1636
+
1637
+ case "sync": {
1486
1638
  await queueSync(cwd, "step", () => syncBranch(cwd));
1487
1639
  break;
1488
- case "merge":
1640
+ }
1641
+
1642
+ case "merge": {
1489
1643
  await queueSync(cwd, "step", () =>
1490
1644
  mergeBranchPullRequest(cwd, settings)
1491
1645
  );
1492
1646
  break;
1647
+ }
1648
+
1493
1649
  case "settle": {
1494
1650
  const keep = keepOf(body);
1651
+
1495
1652
  if (!keep) {
1496
1653
  throw new Problems(400, ["keep is mine or theirs."]);
1497
1654
  }
1655
+
1498
1656
  await queueSync(cwd, "step", () => settlePaused(cwd, keep));
1499
1657
  break;
1500
1658
  }
1501
- case "undo-paused":
1659
+
1660
+ case "undo-paused": {
1502
1661
  await queueSync(cwd, "step", () => undoPaused(cwd));
1503
1662
  break;
1504
- default:
1663
+ }
1664
+
1665
+ default: {
1505
1666
  return await askAgent({
1506
1667
  project,
1507
1668
  body,
@@ -1510,12 +1671,14 @@ async function takeGitStep({
1510
1671
  pageBase,
1511
1672
  settings,
1512
1673
  });
1674
+ }
1513
1675
  }
1514
1676
  } catch (error) {
1515
1677
  throw gitProblems(error);
1516
1678
  } finally {
1517
1679
  events.send(studioEvent.git());
1518
1680
  }
1681
+
1519
1682
  return gitStatus(cwd, settings);
1520
1683
  }
1521
1684
 
@@ -1530,8 +1693,10 @@ async function runSync({ project, body, events, request }: RouteContext) {
1530
1693
  const keep = keepOf(body);
1531
1694
  const move = typeof body?.move === "string" ? body.move : undefined;
1532
1695
  const kind = keep === undefined && move === undefined ? "press" : "choice";
1696
+
1533
1697
  return await queueSync(cwd, kind, async (): Promise<SyncResult> => {
1534
1698
  let gitError: GitError | undefined;
1699
+
1535
1700
  try {
1536
1701
  if (move === undefined) {
1537
1702
  ({ stopped: gitError } = await syncAndUpdate({
@@ -1547,10 +1712,12 @@ async function runSync({ project, body, events, request }: RouteContext) {
1547
1712
  if (!(error instanceof GitError)) {
1548
1713
  throw error;
1549
1714
  }
1715
+
1550
1716
  gitError = error;
1551
1717
  } finally {
1552
1718
  events.send(studioEvent.git());
1553
1719
  }
1720
+
1554
1721
  return await syncAnswer(cwd, settings, gitError);
1555
1722
  });
1556
1723
  }
@@ -1561,7 +1728,7 @@ const syncAnswer = async (
1561
1728
  stopped: GitError | undefined
1562
1729
  ): Promise<SyncResult> => ({
1563
1730
  git: await gitStatus(cwd, settings),
1564
- ...(stopped ? { stopped: await stoppedBy(cwd, stopped) } : {}),
1731
+ ...(stopped && { stopped: await stoppedBy(cwd, stopped) }),
1565
1732
  });
1566
1733
 
1567
1734
  async function stoppedBy(
@@ -1571,8 +1738,9 @@ async function stoppedBy(
1571
1738
  const stopped = {
1572
1739
  message: error.message,
1573
1740
  output: error.output,
1574
- ...(error.stop ? { stop: error.stop } : {}),
1741
+ ...(error.stop && { stop: error.stop }),
1575
1742
  };
1743
+
1576
1744
  return error.stop === "conflict"
1577
1745
  ? { ...stopped, clashes: await clashesIn(cwd, error.output.split("\n")) }
1578
1746
  : stopped;
@@ -1580,9 +1748,11 @@ async function stoppedBy(
1580
1748
 
1581
1749
  function keepOf(body: RequestBody | undefined): SyncKeep | undefined {
1582
1750
  const keep: unknown = body?.keep;
1751
+
1583
1752
  if (keep !== undefined && keep !== "mine" && keep !== "theirs") {
1584
1753
  throw new Problems(400, ["keep is mine or theirs."]);
1585
1754
  }
1755
+
1586
1756
  return keep;
1587
1757
  }
1588
1758
 
@@ -1596,8 +1766,10 @@ async function runPullBase({ project, body, events, request }: RouteContext) {
1596
1766
  const keep = keepOf(body);
1597
1767
  const settings = await readGitSettings(project.root);
1598
1768
  const cwd = project.content;
1769
+
1599
1770
  return await queueSync(cwd, "step", async (): Promise<SyncResult> => {
1600
1771
  let gitError: GitError | undefined;
1772
+
1601
1773
  try {
1602
1774
  ({ stopped: gitError } = await pullBaseAndUpdate({
1603
1775
  content: cwd,
@@ -1608,6 +1780,7 @@ async function runPullBase({ project, body, events, request }: RouteContext) {
1608
1780
  } finally {
1609
1781
  events.send(studioEvent.git());
1610
1782
  }
1783
+
1611
1784
  return await syncAnswer(cwd, settings, gitError);
1612
1785
  });
1613
1786
  }
@@ -1624,6 +1797,7 @@ async function restoreFromSaved({
1624
1797
  }: RouteContext) {
1625
1798
  onlyFromThisMachine(request, GIT_ELSEWHERE);
1626
1799
  const cwd = project.content;
1800
+
1627
1801
  try {
1628
1802
  await queueSync(cwd, "step", () =>
1629
1803
  restoreSaved(cwd, {
@@ -1634,7 +1808,9 @@ async function restoreFromSaved({
1634
1808
  } catch (error) {
1635
1809
  throw gitProblems(error);
1636
1810
  }
1811
+
1637
1812
  events.send(studioEvent.git());
1813
+
1638
1814
  return { saved: await readSaved(cwd) };
1639
1815
  }
1640
1816
 
@@ -1642,13 +1818,17 @@ async function mergeBranchPullRequest(cwd: string, settings: GitSettings) {
1642
1818
  forgetPullRequests();
1643
1819
  const state = await gitStatus(cwd, settings);
1644
1820
  const github = await githubOfRepository(cwd);
1821
+
1645
1822
  if (!(state.repo && state.pr?.state === "open" && github)) {
1646
1823
  throw new GitError("There is no open pull request to merge.");
1647
1824
  }
1825
+
1648
1826
  const merged = await mergePullRequest(cwd, github, state.pr.number);
1827
+
1649
1828
  if (!merged.merged) {
1650
1829
  throw new GitError("GitHub did not merge it.", merged.message);
1651
1830
  }
1831
+
1652
1832
  await fetchRemote(cwd);
1653
1833
  }
1654
1834
 
@@ -1664,43 +1844,50 @@ async function askAgent({
1664
1844
  "project" | "body" | "request" | "threads" | "pageBase"
1665
1845
  > & { settings: GitSettings }) {
1666
1846
  const ask: unknown = body?.ask;
1847
+
1667
1848
  if (!oneOf<GitAsk>(GIT_ASKS, ask)) {
1668
1849
  throw new Problems(400, [`Ask for one of: ${GIT_ASKS.join(", ")}.`]);
1669
1850
  }
1851
+
1670
1852
  const prototype = String(body?.prototype ?? "");
1671
1853
  const state = await gitStatus(project.content, settings);
1854
+
1672
1855
  if (!(state.repo && state.branch)) {
1673
1856
  throw new Problems(409, ["Switch to a branch first."]);
1674
1857
  }
1858
+
1675
1859
  const { host } = request.headers;
1676
1860
  const origin = isLoopbackHost(host) ? undefined : `http://${host}${pageBase}`;
1677
1861
  const changed = await branchPrototypes(project.content, settings);
1862
+
1678
1863
  const canvases = [...new Set([prototype, ...changed].filter(Boolean))].map(
1679
1864
  (name) => ({
1680
1865
  prototype: name,
1681
- ...(origin ? { url: `${origin}${prototypePage(name, "canvas")}` } : {}),
1866
+ ...(origin && { url: `${origin}${prototypePage(name, "canvas")}` }),
1682
1867
  })
1683
1868
  );
1869
+
1684
1870
  const text = gitAskBody(ask, {
1685
1871
  base: state.base,
1686
1872
  branch: state.branch,
1687
1873
  remote: state.remote ?? "origin",
1688
1874
  canvases,
1689
- ...(body?.error ? { error: String(body.error) } : {}),
1690
- ...(body?.failed ? { step: String(body.failed) } : {}),
1691
- });
1692
- const { name: author } = await readAuthor(project.content);
1693
- const result = await threads.start({
1694
- prototype,
1695
- target: { kind: "prototype" },
1696
- body: text,
1697
- for: "agent",
1698
- author,
1875
+ ...(Boolean(body?.error) && { error: String(body?.error) }),
1876
+ ...(Boolean(body?.failed) && { step: String(body?.failed) }),
1699
1877
  });
1700
- if (result.problems) {
1701
- throw new Problems(422, result.problems);
1702
- }
1703
- 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 };
1704
1891
  }
1705
1892
 
1706
1893
  const loadGitSettings = async ({ project }: RouteContext) => ({
@@ -1714,6 +1901,7 @@ function sharingSent(
1714
1901
  saved: GitSettings
1715
1902
  ): Pick<GitSettings, "share" | "syncBranch"> {
1716
1903
  const share: unknown = body?.share;
1904
+
1717
1905
  return {
1718
1906
  share: share === "sync" || share === "pull-requests" ? share : saved.share,
1719
1907
  syncBranch:
@@ -1737,12 +1925,14 @@ async function runGitChecks({ project, body }: RouteContext) {
1737
1925
  realGitProbes,
1738
1926
  { beforePrototypes: "note" }
1739
1927
  );
1928
+
1740
1929
  return { checks };
1741
1930
  }
1742
1931
 
1743
1932
  async function saveGitSettings({ project, body, events }: RouteContext) {
1744
1933
  // Base and prefix are always sent.
1745
1934
  const saved = await readGitSettings(project.root);
1935
+
1746
1936
  const settings = await refusable(() =>
1747
1937
  writeGitSettings(project.root, {
1748
1938
  base: typeof body?.base === "string" ? body.base : undefined,
@@ -1750,7 +1940,9 @@ async function saveGitSettings({ project, body, events }: RouteContext) {
1750
1940
  ...sharingSent(body, saved),
1751
1941
  })
1752
1942
  );
1943
+
1753
1944
  events.send(studioEvent.git());
1945
+
1754
1946
  return { settings };
1755
1947
  }
1756
1948
 
@@ -1760,22 +1952,30 @@ const loadBuildSettings = ({ project }: RouteContext) =>
1760
1952
  /** Turn the build's settings that are sent on or off: `{ review: false }`. */
1761
1953
  async function saveBuildSettings({ project, body, events }: RouteContext) {
1762
1954
  const sent: Partial<BuildSettings> = {};
1955
+
1956
+ // SAFETY: BUILD_DEFAULTS has every BuildSettings key.
1763
1957
  for (const key of Object.keys(BUILD_DEFAULTS) as (keyof BuildSettings)[]) {
1764
1958
  const value = body?.[key];
1959
+
1765
1960
  if (typeof value === "boolean") {
1766
1961
  sent[key] = value;
1767
1962
  }
1768
1963
  }
1964
+
1769
1965
  if (Object.keys(sent).length === 0) {
1770
1966
  throw new Problems(400, [
1771
1967
  "Send comments, pictures or review, as true or false.",
1772
1968
  ]);
1773
1969
  }
1970
+
1774
1971
  const saved = await readBuildSettings(project.root);
1972
+
1775
1973
  const settings = await refusable(() =>
1776
1974
  writeBuildSettings(project.root, { ...saved, ...sent })
1777
1975
  );
1976
+
1778
1977
  events.send(studioEvent.workspace());
1978
+
1779
1979
  return settings;
1780
1980
  }
1781
1981
 
@@ -1783,11 +1983,13 @@ const commandsOf = async (project: ProjectFolders): Promise<CommandsAnswer> => {
1783
1983
  const menu = await readCommandMenu(project.root);
1784
1984
  const folders = await skillFolders(project.root);
1785
1985
  const commands = await listCommands({ folders, menu });
1986
+
1786
1987
  return {
1787
1988
  commands,
1788
1989
  quick: quickNames(commands, menu),
1789
1990
  folder: relative(project.root, folders.team).split(sep).join("/"),
1790
1991
  codebaseFolders: codebaseSkills(project.root).shown,
1992
+ // SAFETY: one entry per COMMAND_SWITCHES name, each a boolean.
1791
1993
  switches: Object.fromEntries(
1792
1994
  COMMAND_SWITCHES.map((which) => [which, switchOn(menu, which)])
1793
1995
  ) as CommandsAnswer["switches"],
@@ -1798,6 +2000,7 @@ const loadCommands = ({ project }: RouteContext) => commandsOf(project);
1798
2000
 
1799
2001
  async function saveCommandFile({ project, body }: RouteContext) {
1800
2002
  const { name, description, body: text, was } = body ?? {};
2003
+
1801
2004
  if (
1802
2005
  typeof name !== "string" ||
1803
2006
  typeof description !== "string" ||
@@ -1806,6 +2009,7 @@ async function saveCommandFile({ project, body }: RouteContext) {
1806
2009
  ) {
1807
2010
  throw new Problems(400, ["Send the command's name, description and body."]);
1808
2011
  }
2012
+
1809
2013
  const folders = await skillFolders(project.root);
1810
2014
  await refusable(() =>
1811
2015
  saveCommand(folders, {
@@ -1815,6 +2019,7 @@ async function saveCommandFile({ project, body }: RouteContext) {
1815
2019
  was,
1816
2020
  })
1817
2021
  );
2022
+
1818
2023
  // A renamed command keeps its switch.
1819
2024
  if (was && was !== name.trim()) {
1820
2025
  const menu = await readCommandMenu(project.root);
@@ -1822,6 +2027,7 @@ async function saveCommandFile({ project, body }: RouteContext) {
1822
2027
  writeCommandMenu(project.root, menuRenamed(menu, was, name.trim()))
1823
2028
  );
1824
2029
  }
2030
+
1825
2031
  return commandsOf(project);
1826
2032
  }
1827
2033
 
@@ -1834,47 +2040,62 @@ async function switchCommand({ project, body }: RouteContext) {
1834
2040
  if (body && "quick" in body) {
1835
2041
  return chooseQuick(project, body.quick);
1836
2042
  }
2043
+
1837
2044
  const which = COMMAND_SWITCHES.find((each) => body && each in body);
2045
+
1838
2046
  if (which) {
1839
2047
  const on = body?.[which];
2048
+
1840
2049
  if (typeof on !== "boolean") {
1841
2050
  throw new Problems(400, [`Send ${which} as true or false.`]);
1842
2051
  }
2052
+
1843
2053
  const menu = await readCommandMenu(project.root);
1844
2054
  await refusable(() =>
1845
2055
  writeCommandMenu(project.root, { ...menu, [which]: on })
1846
2056
  );
2057
+
1847
2058
  return commandsOf(project);
1848
2059
  }
2060
+
1849
2061
  const { name, on } = body ?? {};
2062
+
1850
2063
  if (typeof name !== "string" || typeof on !== "boolean") {
1851
2064
  throw new Problems(400, ["Send the command's name and on."]);
1852
2065
  }
1853
- const command = (await commandsOf(project)).commands.find(
1854
- (each) => each.name === name
1855
- );
2066
+
2067
+ const commands = await commandsOf(project);
2068
+
2069
+ const command = commands.commands.find((each) => each.name === name);
2070
+
1856
2071
  if (!command) {
1857
2072
  throw new Problems(404, [`No command is named ${name}.`]);
1858
2073
  }
2074
+
1859
2075
  const menu = await readCommandMenu(project.root);
1860
2076
  await refusable(() =>
1861
2077
  writeCommandMenu(project.root, menuWith(menu, command, on))
1862
2078
  );
2079
+
1863
2080
  return commandsOf(project);
1864
2081
  }
1865
2082
 
1866
2083
  async function chooseQuick(project: ProjectFolders, quick: unknown) {
1867
- 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
+
1868
2087
  if (
1869
2088
  !Array.isArray(quick) ||
1870
- quick.some((name) => typeof name !== "string" || !names.includes(name))
2089
+ quick.some((name) => typeof name !== "string" || !names.has(name))
1871
2090
  ) {
1872
2091
  throw new Problems(400, ["Send the quick bar's commands by name."]);
1873
2092
  }
2093
+
1874
2094
  const menu = await readCommandMenu(project.root);
1875
2095
  await refusable(() =>
1876
2096
  writeCommandMenu(project.root, { ...menu, quick: [...new Set(quick)] })
1877
2097
  );
2098
+
1878
2099
  return commandsOf(project);
1879
2100
  }
1880
2101
 
@@ -1884,12 +2105,14 @@ async function removeCommandFile({ project, url }: RouteContext) {
1884
2105
  const folders = await skillFolders(project.root);
1885
2106
  await refusable(() => removeCommand(folders, name));
1886
2107
  const left = await commandsOf(project);
2108
+
1887
2109
  if (!left.commands.some((command) => command.name === name)) {
1888
2110
  const menu = await readCommandMenu(project.root);
1889
2111
  await refusable(() =>
1890
2112
  writeCommandMenu(project.root, menuRenamed(menu, name, undefined))
1891
2113
  );
1892
2114
  }
2115
+
1893
2116
  return commandsOf(project);
1894
2117
  }
1895
2118
 
@@ -1898,14 +2121,18 @@ const loadTeamDevices = ({ project }: RouteContext) =>
1898
2121
 
1899
2122
  async function saveTeamDevices({ project, body, events }: RouteContext) {
1900
2123
  const saved = await saveDevices(project.content, body);
2124
+
1901
2125
  if (!saved.devices) {
1902
2126
  throw new Problems(400, saved.problems);
1903
2127
  }
2128
+
1904
2129
  events.send(studioEvent.devices());
2130
+
1905
2131
  return { devices: saved.devices, problems: [] };
1906
2132
  }
1907
2133
 
1908
- const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/;
2134
+ const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/u;
2135
+
1909
2136
  /**
1910
2137
  * The icon is served under its own address, so it is never a page: opened
1911
2138
  * directly, an SVG runs nothing and loads nothing.
@@ -1918,9 +2145,11 @@ async function saveWorkspace({ project, body, events }: RouteContext) {
1918
2145
  if (typeof body?.title !== "string") {
1919
2146
  throw new Problems(400, ["Send the workspace's name as title."]);
1920
2147
  }
1921
- const title = body.title;
2148
+
2149
+ const { title } = body;
1922
2150
  const workspace = await refusable(() => writeWorkspaceTitle(project, title));
1923
2151
  events.send(studioEvent.workspace());
2152
+
1924
2153
  return workspace;
1925
2154
  }
1926
2155
 
@@ -1934,22 +2163,44 @@ async function downloadExtension({ response }: RouteContext) {
1934
2163
  "The extension isn't built. Build Dex's package, then try again.",
1935
2164
  ]);
1936
2165
  }
2166
+
1937
2167
  response.setHeader(
1938
2168
  "Content-Disposition",
1939
2169
  `attachment; filename="${EXTENSION_FILE}"`
1940
2170
  );
1941
2171
  response.setHeader("Cache-Control", "no-cache");
2172
+
1942
2173
  return new Reply(200, await zipFolder(EXTENSION_DIR), "application/zip");
1943
2174
  }
1944
2175
 
2176
+ /** Export prototype: the chosen frames as a zip, saved where the browser saves downloads. */
2177
+ async function exportFrames({
2178
+ project,
2179
+ prototype,
2180
+ body,
2181
+ response,
2182
+ }: PrototypeContext) {
2183
+ const exported = await exportInChild(project.root, prototype.slug, body);
2184
+ response.setHeader(
2185
+ "Content-Disposition",
2186
+ `attachment; filename="${exported.name}"`
2187
+ );
2188
+ response.setHeader("Cache-Control", "no-store");
2189
+
2190
+ return new Reply(200, exported.bytes, "application/zip");
2191
+ }
2192
+
1945
2193
  async function serveWorkspaceIcon({ project, response }: RouteContext) {
1946
2194
  const icon = await readWorkspaceIcon(project);
2195
+
1947
2196
  if (!icon) {
1948
2197
  throw new Problems(404, ["This workspace has no icon."]);
1949
2198
  }
2199
+
1950
2200
  response.setHeader("Content-Security-Policy", ICON_POLICY);
1951
2201
  response.setHeader("X-Content-Type-Options", "nosniff");
1952
2202
  response.setHeader("Cache-Control", "no-cache");
2203
+
1953
2204
  return new Reply(200, icon.bytes, icon.type);
1954
2205
  }
1955
2206
 
@@ -1961,18 +2212,22 @@ async function saveWorkspaceIcon({
1961
2212
  }: RouteContext) {
1962
2213
  onlyFromThisMachine(request, ICON_ELSEWHERE);
1963
2214
  const data = body?.data;
2215
+
1964
2216
  if (typeof data !== "string" || !BASE64_RE.test(data)) {
1965
2217
  throw new Problems(400, ["Send the icon's bytes in base64 as data."]);
1966
2218
  }
2219
+
1967
2220
  const workspace = await writeWorkspaceIcon(
1968
2221
  project,
1969
2222
  Buffer.from(data, "base64")
1970
2223
  ).catch((error: unknown) => {
1971
- throw new Problems(error instanceof IconRefused ? 415 : 422, [
2224
+ throw new Problems(error instanceof IconRefusedError ? 415 : 422, [
1972
2225
  messageOf(error),
1973
2226
  ]);
1974
2227
  });
2228
+
1975
2229
  events.send(studioEvent.workspace());
2230
+
1976
2231
  return workspace;
1977
2232
  }
1978
2233
 
@@ -1980,6 +2235,7 @@ async function deleteWorkspaceIcon({ project, request, events }: RouteContext) {
1980
2235
  onlyFromThisMachine(request, ICON_ELSEWHERE);
1981
2236
  const workspace = await refusable(() => removeWorkspaceIcon(project));
1982
2237
  events.send(studioEvent.workspace());
2238
+
1983
2239
  return workspace;
1984
2240
  }
1985
2241
 
@@ -1988,30 +2244,35 @@ function pictureOwner({ project, request }: RouteContext) {
1988
2244
  request,
1989
2245
  "Change your picture on the machine Dex runs on."
1990
2246
  );
2247
+
1991
2248
  return whoChanges(project.content);
1992
2249
  }
1993
2250
 
1994
2251
  async function saveAvatar(context: RouteContext) {
1995
2252
  const slug = await pictureOwner(context);
1996
2253
  const data = context.body?.data;
2254
+
1997
2255
  if (typeof data !== "string" || !BASE64_RE.test(data)) {
1998
2256
  throw new Problems(400, ["Send the picture's bytes in base64 as data."]);
1999
2257
  }
2258
+
2000
2259
  const file = await writeAvatar(
2001
2260
  context.project.content,
2002
2261
  slug,
2003
2262
  Buffer.from(data, "base64")
2004
2263
  ).catch((error: unknown) => {
2005
- throw new Problems(error instanceof AvatarRefused ? 415 : 422, [
2264
+ throw new Problems(error instanceof AvatarRefusedError ? 415 : 422, [
2006
2265
  messageOf(error),
2007
2266
  ]);
2008
2267
  });
2268
+
2009
2269
  return { file };
2010
2270
  }
2011
2271
 
2012
2272
  async function deleteAvatar(context: RouteContext) {
2013
2273
  const slug = await pictureOwner(context);
2014
2274
  await refusable(() => removeAvatar(context.project.content, slug));
2275
+
2015
2276
  return {};
2016
2277
  }
2017
2278
 
@@ -2019,20 +2280,25 @@ async function recordFocus({ project, body }: RouteContext) {
2019
2280
  const { slug } = prototypeNamed(project.content, body ?? {}, {
2020
2281
  mustExist: false,
2021
2282
  });
2283
+
2022
2284
  await writeFocus(project.content, {
2023
2285
  slug,
2024
2286
  page: body?.page === "canvas" ? "canvas" : "prototype",
2025
2287
  ...openPlace(body),
2026
2288
  });
2289
+
2027
2290
  return {};
2028
2291
  }
2029
2292
 
2030
2293
  const loadMe = ({ project }: RouteContext) => readMe(project.content);
2031
2294
 
2032
- const PROTOTYPE_CHANGES: Record<
2033
- string,
2034
- (body: RequestBody, root: string) => Promise<unknown>
2035
- > = {
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> = {
2036
2302
  rename: (body, root) =>
2037
2303
  setPrototypeTitle(body as ArgumentOf<typeof setPrototypeTitle>, root),
2038
2304
  status: (body, root) =>
@@ -2053,20 +2319,26 @@ async function changePrototypes({ project, body }: RouteContext) {
2053
2319
  if (!body) {
2054
2320
  throw new Problems(400, ["Send a title."]);
2055
2321
  }
2322
+
2056
2323
  const { action } = body;
2057
2324
  const known = isPrototypeChange(action);
2325
+
2058
2326
  if (action !== undefined && !known) {
2059
2327
  throw new Problems(400, [
2060
2328
  `This studio cannot "${action}" a file. Restart it after updating.`,
2061
2329
  ]);
2062
2330
  }
2331
+
2063
2332
  if (known) {
2064
2333
  const change = PROTOTYPE_CHANGES[action];
2334
+
2065
2335
  return (await refusable(() => change(body, project.content))) ?? {};
2066
2336
  }
2337
+
2067
2338
  // An agent may name any contributor (`owner` from before is the same).
2068
2339
  const person =
2069
2340
  body.person ?? body.owner ?? (await whoChanges(project.content));
2341
+
2070
2342
  const { href } = await refusable(() =>
2071
2343
  body.title === undefined
2072
2344
  ? createUntitledPrototype({ person }, project.content)
@@ -2075,6 +2347,7 @@ async function changePrototypes({ project, body }: RouteContext) {
2075
2347
  project.content
2076
2348
  )
2077
2349
  );
2350
+
2078
2351
  return { href };
2079
2352
  }
2080
2353
 
@@ -2099,9 +2372,11 @@ function studioPages({
2099
2372
  // Watch is read, changed and told to pages one step at a time, so a page
2100
2373
  // that opens while it changes never hears an older value after a newer one.
2101
2374
  let watchTurn: Promise<unknown> = Promise.resolve();
2375
+
2102
2376
  const inWatchOrder = <T>(step: () => Promise<T>): Promise<T> => {
2103
2377
  const next = watchTurn.then(step);
2104
2378
  watchTurn = next.catch(() => undefined);
2379
+
2105
2380
  return next;
2106
2381
  };
2107
2382
 
@@ -2117,10 +2392,12 @@ function studioPages({
2117
2392
  listening: () => open,
2118
2393
  async listen(response: ServerResponse): Promise<void> {
2119
2394
  const entries = await presence.list();
2395
+
2120
2396
  if (response.destroyed) {
2121
2397
  // Gone while its presence was read.
2122
2398
  return;
2123
2399
  }
2400
+
2124
2401
  response.writeHead(200, {
2125
2402
  "Content-Type": "text/event-stream",
2126
2403
  "Cache-Control": "no-cache",
@@ -2129,13 +2406,16 @@ function studioPages({
2129
2406
  const write = (event: StudioEvent) => response.write(eventMessage(event));
2130
2407
  write(studioEvent.presence(entries));
2131
2408
  const stopHearing = events.listen(write);
2409
+
2132
2410
  const stopAgents = agents.listen((list) =>
2133
2411
  write(studioEvent.agents(list))
2134
2412
  );
2413
+
2135
2414
  const keepAlive = setInterval(
2136
2415
  () => response.write(": keep-alive\n\n"),
2137
2416
  KEEP_ALIVE_MS
2138
2417
  );
2418
+
2139
2419
  open += 1;
2140
2420
  following ??= threads.subscribe(threadsChanged);
2141
2421
  response.on("close", () => {
@@ -2143,6 +2423,7 @@ function studioPages({
2143
2423
  stopHearing();
2144
2424
  stopAgents();
2145
2425
  open -= 1;
2426
+
2146
2427
  if (open === 0) {
2147
2428
  following?.then((stop) => stop());
2148
2429
  following = undefined;
@@ -2150,7 +2431,8 @@ function studioPages({
2150
2431
  });
2151
2432
  // In turn with the Watch changes it hears from here on.
2152
2433
  await inWatchOrder(async () => {
2153
- const on = await isWatching(project.content);
2434
+ const on = await isWatching(agentsPlace(project.content));
2435
+
2154
2436
  if (!response.destroyed) {
2155
2437
  write(studioEvent.watch(on));
2156
2438
  }
@@ -2186,14 +2468,14 @@ type DeclaredRoute<Name extends StudioRouteName> =
2186
2468
  | ({ prototype: true } & DeclaredMethods<PrototypeContext, Name>)
2187
2469
  | ({ prototype?: false } & DeclaredMethods<RouteContext, Name>);
2188
2470
 
2189
- const ROUTES: { [Name in StudioRouteName]: DeclaredRoute<Name> } = {
2471
+ const ROUTES = {
2190
2472
  ...COMMENT_HANDLERS,
2191
2473
  canvas: { prototype: true, GET: loadCanvas, PUT: saveCanvas },
2192
- annotations: {
2474
+ picks: {
2193
2475
  prototype: true,
2194
- GET: loadAnnotations,
2195
- PUT: saveOwnAnnotation,
2196
- DELETE: removeOwnAnnotation,
2476
+ GET: loadPicks,
2477
+ PUT: saveOwnPick,
2478
+ DELETE: removeOwnPick,
2197
2479
  },
2198
2480
  events: {
2199
2481
  streams: true,
@@ -2204,6 +2486,7 @@ const ROUTES: { [Name in StudioRouteName]: DeclaredRoute<Name> } = {
2204
2486
  GET: listRemovedViews,
2205
2487
  POST: trashRemovedViews,
2206
2488
  },
2489
+ "view-source": { prototype: true, GET: loadViewSource },
2207
2490
  trash: { DELETE: emptyTheTrash },
2208
2491
  reviews: { limit: MAX_REVIEW_BYTES, POST: importReviews },
2209
2492
  "spec-suggestion": { POST: acceptSpecSuggestion },
@@ -2211,7 +2494,12 @@ const ROUTES: { [Name in StudioRouteName]: DeclaredRoute<Name> } = {
2211
2494
  focus: { PUT: recordFocus },
2212
2495
  me: { GET: loadMe },
2213
2496
  people: {
2214
- GET: async ({ project }) => ({ people: await loadPeople(project.content) }),
2497
+ // ?commits=0: names only, as the @ menu asks, without git's log.
2498
+ GET: async ({ project, url }) => ({
2499
+ people: await loadPeople(project.content, {
2500
+ commits: url.searchParams.get("commits") !== "0",
2501
+ }),
2502
+ }),
2215
2503
  },
2216
2504
  prototypes: { POST: changePrototypes },
2217
2505
  paste: { limit: MAX_CAPTURE_BYTES, POST: pasteSnapshots },
@@ -2228,6 +2516,7 @@ const ROUTES: { [Name in StudioRouteName]: DeclaredRoute<Name> } = {
2228
2516
  "agent-stop": { POST: stopOldAgent },
2229
2517
  edited: { GET: ({ project }) => lastEdited(project.content) },
2230
2518
  extension: { GET: downloadExtension },
2519
+ export: { prototype: true, POST: exportFrames },
2231
2520
  "agent-setup": { GET: listAgentSetups, POST: addAgentSetup },
2232
2521
  "agent-launch": { POST: openInTerminal },
2233
2522
  preferences: {
@@ -2263,7 +2552,7 @@ const ROUTES: { [Name in StudioRouteName]: DeclaredRoute<Name> } = {
2263
2552
  PUT: saveWorkspaceIcon,
2264
2553
  DELETE: deleteWorkspaceIcon,
2265
2554
  },
2266
- };
2555
+ } satisfies { [Name in StudioRouteName]: DeclaredRoute<Name> };
2267
2556
 
2268
2557
  const isRouteName = (name: string): name is StudioRouteName =>
2269
2558
  Object.hasOwn(ROUTES, name);
@@ -2271,23 +2560,30 @@ const isRouteName = (name: string): name is StudioRouteName =>
2271
2560
  async function answer(
2272
2561
  route: Route,
2273
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
2274
2564
  ): Promise<unknown> {
2275
2565
  const { request, response, url, project } = context;
2276
2566
  const methods = METHODS.filter((method) => route[method]);
2277
2567
  const method = methods.find((known) => known === request.method);
2568
+
2278
2569
  if (!method) {
2279
2570
  response.setHeader("Allow", methods.join(", "));
2280
2571
  throw new Problems(405, [`Use ${methods.join(" or ")}.`]);
2281
2572
  }
2573
+
2282
2574
  const bodyOf = () =>
2283
2575
  WITH_BODY.has(method) ? readJson(request, route.limit) : undefined;
2576
+
2284
2577
  // The prototype is checked before the body is read.
2285
2578
  if (route.prototype) {
2286
2579
  const prototype = prototypeOf(project.content, url);
2287
2580
  const body = await bodyOf();
2581
+
2288
2582
  return route[method]?.({ ...context, prototype, body });
2289
2583
  }
2584
+
2290
2585
  const body = await bodyOf();
2586
+
2291
2587
  return route[method]?.({ ...context, body });
2292
2588
  }
2293
2589
 
@@ -2295,10 +2591,10 @@ export interface StudioRequestOptions {
2295
2591
  agents?: AgentTracker;
2296
2592
  base?: string;
2297
2593
  /**
2298
- * Where the studio can make its app, asked each time: the dev server's
2299
- * 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.
2300
2596
  */
2301
- desktop?: () => DesktopAppHost;
2597
+ desktop?: () => ProjectDesktop;
2302
2598
  events: EventHub;
2303
2599
  format?: Formatter;
2304
2600
  launcher?: AgentLauncher;
@@ -2320,31 +2616,38 @@ export function studioRequests({
2320
2616
  events,
2321
2617
  format = formatter(project.content),
2322
2618
  launcher = launchAgent,
2323
- agents = trackAgents(project.content, { threads }),
2619
+ agents = trackAgents(agentsPlace(project.content)),
2324
2620
  server = {},
2325
2621
  base = "/",
2326
- desktop = () => ({ unavailable: "platform" }),
2622
+ desktop = () => noDesktop("platform"),
2327
2623
  }: StudioRequestOptions): (
2328
2624
  request: IncomingMessage,
2329
2625
  response: ServerResponse
2330
2626
  ) => Promise<boolean> {
2331
2627
  const pages = studioPages({ project, events, threads, agents });
2332
2628
  const pageBase = base.replace(TRAILING_SLASH_RE, "");
2629
+
2333
2630
  return async (request, response) => {
2334
2631
  const url = new URL(request.url ?? "/", "http://studio.local");
2632
+
2335
2633
  if (!url.pathname.startsWith(PREFIX)) {
2336
2634
  return false;
2337
2635
  }
2636
+
2338
2637
  const name = url.pathname.slice(PREFIX.length);
2638
+
2339
2639
  try {
2340
2640
  // Other websites open in the same browser must not change files.
2341
2641
  if (!isAllowedRequest(request.headers, server)) {
2342
2642
  throw new Problems(403, ["Not allowed from this site."]);
2343
2643
  }
2644
+
2344
2645
  if (!isRouteName(name)) {
2345
2646
  throw new Problems(404, ["Not found."]);
2346
2647
  }
2648
+
2347
2649
  const route: Route = ROUTES[name];
2650
+
2348
2651
  const answered = await answer(route, {
2349
2652
  project,
2350
2653
  threads,
@@ -2358,6 +2661,7 @@ export function studioRequests({
2358
2661
  response,
2359
2662
  url,
2360
2663
  });
2664
+
2361
2665
  if (!route.streams) {
2362
2666
  send(response, answered);
2363
2667
  }
@@ -2366,12 +2670,14 @@ export function studioRequests({
2366
2670
  response.end();
2367
2671
  } else {
2368
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.
2369
2674
  const failure = error as Failure;
2370
2675
  sendJson(response, failure.status ?? 500, {
2371
2676
  problems: failure.problems ?? [failure.message],
2372
2677
  });
2373
2678
  }
2374
2679
  }
2680
+
2375
2681
  return true;
2376
2682
  };
2377
2683
  }