@dexhq/canvas 0.15.0 → 0.16.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 (307) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/app/canvas/activity-parts.tsx +50 -6
  3. package/app/canvas/activity.tsx +2 -3
  4. package/app/canvas/agent-changes.ts +18 -8
  5. package/app/canvas/anchoring.ts +13 -3
  6. package/app/canvas/canvas-context.tsx +6 -2
  7. package/app/canvas/canvas-input.ts +35 -0
  8. package/app/canvas/canvas-model.ts +2 -2
  9. package/app/canvas/canvas-scene.ts +243 -24
  10. package/app/canvas/canvas-ui.ts +11 -2
  11. package/app/canvas/canvas.css +86 -3
  12. package/app/canvas/comments.tsx +66 -29
  13. package/app/canvas/element-link.ts +135 -0
  14. package/app/canvas/element-picker.ts +23 -0
  15. package/app/canvas/export-dialog.tsx +265 -0
  16. package/app/canvas/flow-canvas.tsx +65 -14
  17. package/app/canvas/frame-context-menu.tsx +61 -7
  18. package/app/canvas/frame-node.tsx +10 -11
  19. package/app/canvas/layout.ts +41 -22
  20. package/app/canvas/linked-element.tsx +196 -0
  21. package/app/canvas/live-page.ts +14 -0
  22. package/app/canvas/mentions.tsx +209 -0
  23. package/app/canvas/picked-box.tsx +21 -0
  24. package/app/canvas/removed-views-panel.tsx +4 -4
  25. package/app/canvas/request-node.tsx +151 -0
  26. package/app/canvas/review-panel.tsx +8 -3
  27. package/app/canvas/section-node.tsx +4 -133
  28. package/app/canvas/spec-margin.tsx +4 -1
  29. package/app/canvas/teammates-layer.tsx +205 -0
  30. package/app/canvas/text-layer.tsx +103 -17
  31. package/app/canvas/tool-cursors.ts +7 -6
  32. package/app/canvas/tool-icons.tsx +24 -56
  33. package/app/canvas/typing.ts +12 -0
  34. package/app/canvas/use-agent-changes.tsx +6 -2
  35. package/app/canvas/use-canvas-editor.ts +4 -2
  36. package/app/export/player-model.ts +159 -0
  37. package/app/export/player.tsx +198 -0
  38. package/app/export.html +31 -0
  39. package/app/export.tsx +9 -0
  40. package/app/frame/announce-refreshes.ts +21 -0
  41. package/app/frame/start-frame.tsx +50 -0
  42. package/app/frame/view-loads.ts +161 -0
  43. package/app/frame/views.ts +13 -49
  44. package/app/frame.tsx +2 -38
  45. package/app/i18n/locales/en/messages.po +145 -6
  46. package/app/i18n/locales/en/messages.ts +1 -1
  47. package/app/i18n/locales/pseudo/messages.po +144 -5
  48. package/app/i18n/locales/pseudo/messages.ts +1 -1
  49. package/app/icons/dex-glyphs.tsx +219 -0
  50. package/app/icons/glyphs.tsx +76 -80
  51. package/app/kit/use-flow.ts +2 -1
  52. package/app/live/canvas-teammates.ts +90 -0
  53. package/app/live/studio-api.ts +30 -20
  54. package/app/pages/canvas.tsx +18 -6
  55. package/app/pages/commands-settings.tsx +1 -1
  56. package/app/pages/render.tsx +39 -11
  57. package/app/shell/bell.tsx +15 -5
  58. package/app/shell/presence.tsx +123 -26
  59. package/app/shell/thread-list.tsx +25 -8
  60. package/app/shell/working-on.tsx +35 -3
  61. package/app/ui/prompt-editor.tsx +39 -11
  62. package/app/ui/reference.tsx +21 -8
  63. package/bin/sudio.mjs +1 -1
  64. package/dist/cli/commands/create.d.mts +5 -5
  65. package/dist/cli/commands/create.mjs +4 -4
  66. package/dist/cli/commands/export.d.mts +40 -0
  67. package/dist/cli/commands/export.mjs +66 -0
  68. package/dist/cli/commands/init.d.mts +2 -2
  69. package/dist/cli/commands/upgrade.mjs +1 -1
  70. package/dist/cli/help.d.mts +1 -1
  71. package/dist/cli/help.mjs +13 -7
  72. package/dist/cli/main.d.mts +42 -5
  73. package/dist/cli/main.mjs +1 -0
  74. package/dist/config/load.mjs +14 -2
  75. package/dist/config/project-files.d.mts +5 -0
  76. package/dist/config/project-files.mjs +10 -1
  77. package/dist/config/renamed.d.mts +7 -0
  78. package/dist/config/renamed.mjs +13 -1
  79. package/dist/content/commands.d.mts +11 -9
  80. package/dist/content/commands.mjs +22 -16
  81. package/dist/content/comments-log.mjs +2 -1
  82. package/dist/content/content.d.mts +11 -3
  83. package/dist/content/content.mjs +49 -15
  84. package/dist/content/element-words.d.mts +42 -0
  85. package/dist/content/element-words.mjs +112 -0
  86. package/dist/content/hosted-person.d.mts +31 -0
  87. package/dist/content/hosted-person.mjs +68 -0
  88. package/dist/content/merge-rules.d.mts +5 -0
  89. package/dist/content/merge-rules.mjs +17 -1
  90. package/dist/content/screenshot.mjs +9 -0
  91. package/dist/content/text-edit.d.mts +24 -14
  92. package/dist/content/text-edit.mjs +92 -81
  93. package/dist/content/text-replace.mjs +2 -26
  94. package/dist/content/thread-module.d.mts +2 -4
  95. package/dist/content/thread-module.mjs +4 -5
  96. package/dist/server/agents.d.mts +10 -0
  97. package/dist/server/agents.mjs +21 -6
  98. package/dist/server/canvas-presence.d.mts +22 -0
  99. package/dist/server/canvas-presence.mjs +160 -0
  100. package/dist/server/command-settings.mjs +1 -1
  101. package/dist/server/comments/actions.d.mts +0 -8
  102. package/dist/server/comments/actions.mjs +1 -9
  103. package/dist/server/comments/routes.mjs +10 -31
  104. package/dist/server/dev-server.mjs +35 -13
  105. package/dist/server/export/build.d.mts +15 -0
  106. package/dist/server/export/build.mjs +220 -0
  107. package/dist/server/export/page.d.mts +25 -0
  108. package/dist/server/export/page.mjs +40 -0
  109. package/dist/server/export/plugin.d.mts +31 -0
  110. package/dist/server/export/plugin.mjs +69 -0
  111. package/dist/server/export/run.d.mts +9 -0
  112. package/dist/server/export/run.mjs +61 -0
  113. package/dist/server/export/save.d.mts +7 -0
  114. package/dist/server/export/save.mjs +29 -0
  115. package/dist/server/hosted.d.mts +8 -0
  116. package/dist/server/hosted.mjs +78 -0
  117. package/dist/server/live-mirror.mjs +66 -10
  118. package/dist/server/live.mjs +28 -1
  119. package/dist/server/mcp.mjs +2 -0
  120. package/dist/server/me.d.mts +2 -0
  121. package/dist/server/me.mjs +8 -2
  122. package/dist/server/notices.d.mts +1 -1
  123. package/dist/server/notices.mjs +1 -1
  124. package/dist/server/own-copies.mjs +1 -1
  125. package/dist/server/people.d.mts +7 -2
  126. package/dist/server/people.mjs +6 -2
  127. package/dist/server/pictures.d.mts +1 -1
  128. package/dist/server/pictures.mjs +2 -2
  129. package/dist/server/prebundle.d.mts +32 -0
  130. package/dist/server/prebundle.mjs +115 -0
  131. package/dist/server/problems.d.mts +8 -0
  132. package/dist/server/problems.mjs +13 -0
  133. package/dist/server/requests.mjs +43 -30
  134. package/dist/server/source-stamp.d.mts +4 -3
  135. package/dist/server/source-stamp.mjs +60 -31
  136. package/dist/server/state.d.mts +19 -10
  137. package/dist/server/state.mjs +27 -18
  138. package/dist/server/thread-source.d.mts +8 -0
  139. package/dist/server/thread-source.mjs +24 -5
  140. package/dist/server/tools/export.d.mts +5 -0
  141. package/dist/server/tools/export.mjs +35 -0
  142. package/dist/server/tools/place-frame.mjs +16 -16
  143. package/dist/server/tools/thread-list.mjs +1 -1
  144. package/dist/server/vite.d.mts +9 -4
  145. package/dist/server/vite.mjs +63 -61
  146. package/dist/server/welcome.mjs +2 -1
  147. package/dist/setup/apply.d.mts +4 -0
  148. package/dist/setup/apply.mjs +5 -4
  149. package/dist/setup/create.mjs +5 -5
  150. package/dist/setup/design-system-checks.mjs +1 -6
  151. package/dist/setup/detect/workspace.d.mts +10 -10
  152. package/dist/setup/detect/workspace.mjs +10 -12
  153. package/dist/setup/doctor.d.mts +4 -1
  154. package/dist/setup/doctor.mjs +7 -5
  155. package/dist/setup/migrate/dex-folder.d.mts +61 -0
  156. package/dist/setup/migrate/dex-folder.mjs +544 -0
  157. package/dist/setup/migrate/files-folder.mjs +1 -1
  158. package/dist/setup/migrate/guides.mjs +1 -1
  159. package/dist/setup/migrate/migrations.mjs +4 -0
  160. package/dist/setup/migrate/setup-files.d.mts +5 -0
  161. package/dist/setup/migrate/setup-files.mjs +115 -0
  162. package/dist/setup/migrate/studio-state.d.mts +2 -2
  163. package/dist/setup/migrate/studio-state.mjs +4 -4
  164. package/dist/setup/placement.d.mts +1 -1
  165. package/dist/setup/placement.mjs +5 -4
  166. package/dist/setup/plan.d.mts +5 -5
  167. package/dist/setup/plan.mjs +8 -12
  168. package/dist/setup/project.mjs +1 -1
  169. package/dist/setup/prompts.d.mts +2 -1
  170. package/dist/setup/prompts.mjs +4 -3
  171. package/dist/setup/questions.mjs +3 -2
  172. package/dist/setup/starters.d.mts +1 -1
  173. package/dist/setup/starters.mjs +2 -2
  174. package/dist/setup/write.d.mts +15 -3
  175. package/dist/setup/write.mjs +23 -3
  176. package/dist/shared/canvas-core.d.mts +22 -7
  177. package/dist/shared/canvas-core.mjs +38 -10
  178. package/dist/shared/comments/routes.d.mts +3 -1
  179. package/dist/shared/comments/routes.mjs +4 -2
  180. package/dist/shared/export-core.d.mts +62 -0
  181. package/dist/shared/export-core.mjs +101 -0
  182. package/dist/shared/live-core.d.mts +2 -0
  183. package/dist/shared/live-core.mjs +6 -1
  184. package/dist/shared/live-presence.d.mts +57 -2
  185. package/dist/shared/live-presence.mjs +90 -4
  186. package/dist/shared/page-messages.d.mts +14 -1
  187. package/dist/shared/page-messages.mjs +30 -3
  188. package/dist/shared/people-core.d.mts +28 -0
  189. package/dist/shared/people-core.mjs +27 -1
  190. package/dist/shared/presence-core.d.mts +2 -0
  191. package/dist/shared/references-core.d.mts +4 -0
  192. package/dist/shared/references-core.mjs +12 -4
  193. package/dist/shared/studio-files.d.mts +9 -0
  194. package/dist/shared/studio-files.mjs +11 -2
  195. package/dist/shared/studio-routes.d.mts +13 -1
  196. package/dist/shared/threads-core.d.mts +27 -4
  197. package/dist/shared/threads-core.mjs +67 -12
  198. package/extension/dist/feedback.js +104 -294
  199. package/extension/dist/manifest.json +1 -1
  200. package/extension/dist/picker.js +104 -294
  201. package/package.json +2 -2
  202. package/src/cli/commands/create.ts +4 -4
  203. package/src/cli/commands/export.ts +78 -0
  204. package/src/cli/commands/upgrade.ts +1 -1
  205. package/src/cli/help.ts +13 -7
  206. package/src/cli/main.ts +1 -0
  207. package/src/config/load.ts +26 -2
  208. package/src/config/project-files.ts +15 -0
  209. package/src/config/renamed.ts +19 -1
  210. package/src/content/commands.ts +30 -18
  211. package/src/content/comments-log.ts +4 -1
  212. package/src/content/content.ts +64 -16
  213. package/src/content/element-words.ts +175 -0
  214. package/src/content/hosted-person.ts +107 -0
  215. package/src/content/merge-rules.ts +29 -0
  216. package/src/content/screenshot.ts +14 -0
  217. package/src/content/text-edit.ts +172 -105
  218. package/src/content/text-replace.ts +3 -32
  219. package/src/content/thread-module.ts +2 -4
  220. package/src/content/trash.ts +1 -1
  221. package/src/server/agents.ts +48 -17
  222. package/src/server/canvas-presence.ts +237 -0
  223. package/src/server/channel.ts +1 -1
  224. package/src/server/command-settings.ts +1 -1
  225. package/src/server/comments/actions.ts +0 -19
  226. package/src/server/comments/routes.ts +9 -54
  227. package/src/server/dev-server.ts +66 -26
  228. package/src/server/export/build.ts +310 -0
  229. package/src/server/export/page.ts +85 -0
  230. package/src/server/export/plugin.ts +138 -0
  231. package/src/server/export/run.ts +79 -0
  232. package/src/server/export/save.ts +38 -0
  233. package/src/server/hosted.ts +113 -0
  234. package/src/server/live-mirror.ts +93 -8
  235. package/src/server/live.ts +46 -1
  236. package/src/server/machine-update.ts +3 -3
  237. package/src/server/mcp.ts +2 -0
  238. package/src/server/me.ts +10 -1
  239. package/src/server/notices.ts +2 -2
  240. package/src/server/people.ts +11 -2
  241. package/src/server/pictures.ts +2 -2
  242. package/src/server/prebundle.ts +230 -0
  243. package/src/server/presence.ts +1 -1
  244. package/src/server/problems.ts +11 -0
  245. package/src/server/requests.ts +55 -40
  246. package/src/server/roster.ts +1 -1
  247. package/src/server/saved.ts +1 -1
  248. package/src/server/source-stamp.ts +118 -37
  249. package/src/server/state.ts +53 -31
  250. package/src/server/thread-source.ts +35 -3
  251. package/src/server/tools/export.ts +56 -0
  252. package/src/server/tools/place-frame.ts +23 -15
  253. package/src/server/tools/thread-list.ts +1 -1
  254. package/src/server/updates.ts +2 -2
  255. package/src/server/vite.ts +106 -110
  256. package/src/server/welcome.ts +3 -1
  257. package/src/setup/apply.ts +8 -5
  258. package/src/setup/create.ts +10 -10
  259. package/src/setup/design-system-checks.ts +1 -6
  260. package/src/setup/detect/workspace.ts +20 -21
  261. package/src/setup/doctor.ts +13 -6
  262. package/src/setup/migrate/dex-folder.ts +842 -0
  263. package/src/setup/migrate/files-folder.ts +1 -1
  264. package/src/setup/migrate/guides.ts +3 -1
  265. package/src/setup/migrate/migrations.ts +8 -2
  266. package/src/setup/migrate/setup-files.ts +198 -0
  267. package/src/setup/migrate/studio-state.ts +12 -10
  268. package/src/setup/own-app.ts +1 -1
  269. package/src/setup/placement.ts +7 -6
  270. package/src/setup/plan.ts +13 -18
  271. package/src/setup/project.ts +2 -2
  272. package/src/setup/prompts.ts +5 -4
  273. package/src/setup/questions.ts +6 -3
  274. package/src/setup/starters.ts +3 -3
  275. package/src/setup/write.ts +34 -3
  276. package/src/shared/canvas-core.ts +48 -9
  277. package/src/shared/comments/routes.ts +3 -1
  278. package/src/shared/export-core.ts +198 -0
  279. package/src/shared/live-core.ts +8 -0
  280. package/src/shared/live-presence.ts +171 -2
  281. package/src/shared/page-messages.ts +38 -2
  282. package/src/shared/people-core.ts +44 -0
  283. package/src/shared/presence-core.ts +2 -0
  284. package/src/shared/references-core.ts +22 -3
  285. package/src/shared/studio-files.ts +15 -1
  286. package/src/shared/studio-routes.ts +11 -1
  287. package/src/shared/threads-core.ts +132 -10
  288. package/templates/methods/explore.md +1 -1
  289. package/templates/methods/handoff.md +1 -1
  290. package/templates/methods/review.md +2 -1
  291. package/templates/rules/canvas-frames.md +6 -3
  292. package/templates/rules/commands.md +1 -0
  293. package/templates/rules/prototypes.md +1 -1
  294. package/templates/rules/studio.md +17 -11
  295. package/templates/skills/comprehend/SKILL.md +56 -0
  296. package/templates/skills/distill/SKILL.md +172 -0
  297. package/templates/skills/export-prototype/SKILL.md +35 -0
  298. package/templates/skills/riff/SKILL.md +21 -0
  299. package/templates/skills/riff-deep/SKILL.md +40 -0
  300. package/templates/skills/riff-max/SKILL.md +46 -0
  301. package/templates/skills/riff-state/SKILL.md +45 -0
  302. package/templates/skills/riff-up/SKILL.md +38 -0
  303. package/templates/skills/riff-wide/SKILL.md +40 -0
  304. package/templates/starters/standalone/README.md +1 -1
  305. package/templates/starters/turborepo/README.md +2 -2
  306. package/templates/starters/turborepo/apps/web/src/app.tsx +2 -2
  307. package/templates/starters/vite/README.md +1 -1
@@ -75,6 +75,8 @@ interface Me {
75
75
  loaded: boolean;
76
76
  /** Who you would join as, when Dex knows you but you are no contributor. */
77
77
  newcomer: Contributor | null;
78
+ /** A viewer, in Dex in the browser: they never change the files. */
79
+ viewer?: true;
78
80
  }
79
81
 
80
82
  /**
@@ -82,7 +84,7 @@ interface Me {
82
84
  * the page, so the first paint shows you and not a placeholder.
83
85
  */
84
86
  const meFromPage = ():
85
- | Pick<Me, "cloud" | "contributor" | "git" | "newcomer">
87
+ | Pick<Me, "cloud" | "contributor" | "git" | "newcomer" | "viewer">
86
88
  | undefined => {
87
89
  const content =
88
90
  typeof document === "undefined"
@@ -100,6 +102,7 @@ const meFromPage = ():
100
102
  contributor: me.contributor ?? null,
101
103
  git: typeof me.git === "string" ? me.git : "",
102
104
  newcomer: me.newcomer ?? null,
105
+ ...(me.viewer === true && { viewer: true as const }),
103
106
  };
104
107
  } catch {
105
108
  return;
@@ -234,20 +237,6 @@ export function useMe() {
234
237
  };
235
238
  }
236
239
 
237
- /**
238
- * Change a thread as the person using the studio: reply, react, hand it to
239
- * people or the agent, resolve, dismiss or reopen it.
240
- */
241
- export const changeThread = (
242
- { id, slug }: { id: string; slug: string },
243
- change: PersonChange
244
- ) =>
245
- studioRequest("threads", {
246
- method: "POST",
247
- query: { slug },
248
- body: { id, ...change },
249
- });
250
-
251
240
  /**
252
241
  * Everyone's annotations (picks) on one prototype, kept current. A pick saved
253
242
  * or removed shows at once; the server's answer then stands, and a refusal
@@ -487,11 +476,32 @@ export function useThreads(slug: string) {
487
476
  }
488
477
  return changeGuestThread(slug, current, change);
489
478
  }
490
- const thread = await changeThread({ id, slug }, change);
491
- shown.set((current = []) =>
492
- current.map((entry) => (entry.id === id ? thread : entry))
493
- );
494
- return thread;
479
+ const { target } = change;
480
+ // A request moved or resized on the canvas is there at once, as a frame
481
+ // dropped is; the threads as they are come back if it is refused.
482
+ if (target) {
483
+ shown.set((current = []) =>
484
+ current.map((entry) =>
485
+ entry.id === id ? { ...entry, target } : entry
486
+ )
487
+ );
488
+ }
489
+ try {
490
+ const thread = await studioRequest("threads", {
491
+ method: "POST",
492
+ query: { slug },
493
+ body: { id, ...change },
494
+ });
495
+ shown.set((current = []) =>
496
+ current.map((entry) => (entry.id === id ? thread : entry))
497
+ );
498
+ return thread;
499
+ } catch (error) {
500
+ if (target) {
501
+ await shown.reload();
502
+ }
503
+ throw error;
504
+ }
495
505
  },
496
506
  [slug, shown, threads]
497
507
  );
@@ -77,6 +77,7 @@ import { CommentsOrReviewsBody } from "../canvas/imported-reviews";
77
77
  import { useInspectTools } from "../canvas/inspect-tools";
78
78
  import { LargeCanvasNotice } from "../canvas/large-canvas-notice";
79
79
  import { openSpot, resolveLayout } from "../canvas/layout";
80
+ import { useElementLink } from "../canvas/linked-element";
80
81
  import {
81
82
  AFTER_RELOAD_KEY,
82
83
  keyOfFrame,
@@ -144,6 +145,7 @@ import { useDevices } from "../live/use-devices";
144
145
  import { findPrototype, type Prototype } from "../registry";
145
146
  import { ChromeTheme } from "../shell/chrome-theme";
146
147
  import { CanvasFeedback } from "../shell/feedback-link";
148
+ import { PresenceHidden } from "../shell/presence";
147
149
  import type { Canvas, SketchFrame, Thread } from "../types";
148
150
  import { NotFound } from "./not-found";
149
151
 
@@ -232,7 +234,12 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
232
234
  // Saves from a studio that doesn't know its person are its maker's. One
233
235
  // that cannot say who you are keeps the canvas to view until it can.
234
236
  const who = useMe();
235
- const editor = useCanvasEditor(prototype, who.known, who.contributor?.slug);
237
+ const editor = useCanvasEditor(
238
+ prototype,
239
+ who.known,
240
+ who.contributor?.slug,
241
+ Boolean(who.viewer)
242
+ );
236
243
  const connection = useServerConnection();
237
244
  // Who the studio saves as, as canvas.json's read said: what is yours here.
238
245
  const me = editor.person;
@@ -268,7 +275,8 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
268
275
  const interacting = useStateOf(ui, (state) => state.interacting);
269
276
  const [focused, setFocused] = useState(false);
270
277
  const toggleFocus = useCallback(() => setFocused((value) => !value), []);
271
- // With the panels hidden (⌘\), comments hide too, until ⇧C.
278
+ // With the panels hidden (⌘\), comments hide too, until ⇧C. No frame shows
279
+ // an agent at work either (PresenceHidden, below).
272
280
  useHideCommentsWhile(focused);
273
281
  const fullScreenSpec = useStateOf(ui, (state) => state.fullScreenSpec);
274
282
  const closeSpec = useCallback(() => ui.setFullScreenSpec(), [ui]);
@@ -324,6 +332,7 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
324
332
  editor.canvas,
325
333
  openAnyThread
326
334
  );
335
+ useElementLink(editor.canvas, { say: inspect.say, ui });
327
336
  useEffect(() => {
328
337
  if (resume.active) {
329
338
  sketches.setActive(resume.active);
@@ -425,6 +434,7 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
425
434
  file: prototype.slug,
426
435
  loaded: threads.loaded && who.loaded,
427
436
  me: who.contributor?.name,
437
+ mentionable: who.contributor?.slug,
428
438
  quiet:
429
439
  busy ||
430
440
  writing ||
@@ -673,10 +683,12 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
673
683
  <div className="flex h-dvh flex-col bg-background">
674
684
  <ChromeTheme />
675
685
  <div className="@container/canvas relative min-h-0 flex-1">
676
- <FlowCanvas
677
- selection={selection}
678
- setSelection={setSelection}
679
- />
686
+ <PresenceHidden when={focused}>
687
+ <FlowCanvas
688
+ selection={selection}
689
+ setSelection={setSelection}
690
+ />
691
+ </PresenceHidden>
680
692
  <DrawLayer kind={drawing} onEnd={stopDrawing} />
681
693
  <SlidePdf />
682
694
  <LeftPanels
@@ -563,7 +563,7 @@ const CommandEditor = ({
563
563
  onChange,
564
564
  }: {
565
565
  command: Command | undefined;
566
- /** Where the project's own skills are saved: ".dex/skills". */
566
+ /** Where the project's own skills are saved: "dex/skills". */
567
567
  folder: string;
568
568
  onBack: () => void;
569
569
  onChange: (answer: CommandsAnswer) => void;
@@ -4,6 +4,7 @@ import { type ComponentType, Suspense, useEffect, useMemo } from "react";
4
4
  import { type FileError, placeOf } from "../../src/shared/file-errors.ts";
5
5
  import { tellStudio, VIEW_RENDERED } from "../../src/shared/page-messages.ts";
6
6
  import { useFileErrors } from "../frame/file-errors";
7
+ import { isLoadFailure } from "../frame/view-loads";
7
8
  import { useInspectOverrides } from "../kit/inspect-runtime";
8
9
  import { Boundary } from "../ui/boundary";
9
10
 
@@ -51,7 +52,9 @@ const useReportHeight = () => {
51
52
  * Marks the page once its view has rendered, past the spinner: a canvas
52
53
  * frame shows its page only then, and pictures of views
53
54
  * (src/content/screenshot.ts) wait for it, so the page of a view that is not
54
- * there yet, which has only a note, is never pictured.
55
+ * there yet, which has only a note, is never pictured. Marked again for each
56
+ * other view it renders, such as one loaded again once fixed, so an agent's
57
+ * presence takes it as a page of its own (app/shell/presence.tsx).
55
58
  */
56
59
  const MarkRendered = () => {
57
60
  useEffect(() => {
@@ -62,10 +65,6 @@ const MarkRendered = () => {
62
65
  return null;
63
66
  };
64
67
 
65
- // How each browser says a module failed to load: Chromium, Firefox, Safari.
66
- const LOAD_FAILED_RE =
67
- /dynamically imported module|Importing a module script failed/;
68
-
69
68
  /**
70
69
  * Why the view's module didn't load, from the files the server can't read:
71
70
  * this prototype's first, as the address the browser names may be the view
@@ -78,17 +77,26 @@ const loadErrorOf = (
78
77
  (slug && errors.find((found) => found.path.startsWith(`files/${slug}/`))) ||
79
78
  errors[0];
80
79
 
80
+ /**
81
+ * What a view that couldn't load says when no file is to blame. With a
82
+ * development server it tries again as files change (frame/view-loads.ts);
83
+ * a built studio has none, and only a new page fetches the view again.
84
+ */
85
+ const UNLOADED_NOTE = import.meta.hot
86
+ ? "Something it imports didn’t load. It tries again when a file changes."
87
+ : "Something it imports didn’t load. Loading the page again may bring it back.";
88
+
81
89
  /**
82
90
  * A view that threw while rendering, or whose file couldn't load, with why.
83
91
  * A prototype's frame carries none of Dex's words: they load only for Dex's
84
92
  * own frame pages (frame/studio-view.tsx). So this says it plainly, in
85
- * English. It goes once the file is fixed (frame/views.ts).
93
+ * English. It goes once the file is fixed, or, when the server names no
94
+ * file, once a change lets it load (frame/view-loads.ts).
86
95
  */
87
96
  const ViewBroke = ({ error, slug }: { error: Error; slug?: string }) => {
88
97
  const errors = useFileErrors();
89
- const found = LOAD_FAILED_RE.test(error.message)
90
- ? loadErrorOf(errors, slug)
91
- : undefined;
98
+ const unloaded = isLoadFailure(error);
99
+ const found = unloaded ? loadErrorOf(errors, slug) : undefined;
92
100
  const where = found ? placeOf(found) : undefined;
93
101
  return (
94
102
  <div
@@ -96,7 +104,7 @@ const ViewBroke = ({ error, slug }: { error: Error; slug?: string }) => {
96
104
  role="alert"
97
105
  >
98
106
  <p className="font-medium">
99
- {found
107
+ {unloaded
100
108
  ? "This view can’t load."
101
109
  : "This view hit an error while rendering."}
102
110
  </p>
@@ -105,6 +113,9 @@ const ViewBroke = ({ error, slug }: { error: Error; slug?: string }) => {
105
113
  {where}
106
114
  </p>
107
115
  ) : null}
116
+ {unloaded && !found ? (
117
+ <p className="text-muted-foreground text-sm">{UNLOADED_NOTE}</p>
118
+ ) : null}
108
119
  <pre className="max-w-full overflow-auto whitespace-pre-wrap text-muted-foreground text-xs">
109
120
  {found?.message ?? error.message}
110
121
  </pre>
@@ -117,6 +128,23 @@ const ViewBroke = ({ error, slug }: { error: Error; slug?: string }) => {
117
128
  );
118
129
  };
119
130
 
131
+ /**
132
+ * A number for each view the page renders, its mark's key: another view
133
+ * mounts the mark afresh, which takes it off and puts it back.
134
+ */
135
+ const viewNumbers = new WeakMap<ComponentType, number>();
136
+ let viewsNumbered = 0;
137
+
138
+ const numberOf = (view: ComponentType): number => {
139
+ let number = viewNumbers.get(view);
140
+ if (number === undefined) {
141
+ viewsNumbered += 1;
142
+ number = viewsNumbered;
143
+ viewNumbers.set(view, number);
144
+ }
145
+ return number;
146
+ };
147
+
120
148
  /** One view, as a frame or a link shows it: on the page, in the provider. */
121
149
  export const RenderedView = ({
122
150
  Component,
@@ -155,7 +183,7 @@ export const RenderedView = ({
155
183
  <Component />
156
184
  </StudioProvider>
157
185
  </Boundary>
158
- <MarkRendered />
186
+ <MarkRendered key={numberOf(Component)} />
159
187
  </Suspense>
160
188
  </div>
161
189
  );
@@ -18,6 +18,7 @@ import {
18
18
  useSyncExternalStore,
19
19
  } from "react";
20
20
  import { isClosed, threadState } from "../../src/shared/threads-core.ts";
21
+ import { useMentionable } from "../canvas/mentions";
21
22
  import { Tip } from "../canvas/tip";
22
23
  import { CAN_WRITE, HAS_COMMENTS, useMe } from "../live/studio-api";
23
24
  import { findPrototype } from "../registry";
@@ -152,6 +153,7 @@ const BellPopover = ({
152
153
  count,
153
154
  filter,
154
155
  label,
156
+ canBeMentioned = false,
155
157
  name,
156
158
  onFilter,
157
159
  onOpenChange,
@@ -163,6 +165,8 @@ const BellPopover = ({
163
165
  filter: ThreadFilter;
164
166
  /** Its tip. */
165
167
  label: string;
168
+ /** Mentions among the filters: you are someone who can be mentioned. */
169
+ canBeMentioned?: boolean;
166
170
  /** What the button says it is, with what is new. */
167
171
  name: string;
168
172
  onFilter: (filter: ThreadFilter) => void;
@@ -199,12 +203,12 @@ const BellPopover = ({
199
203
  </Tip>
200
204
  <PopoverContent
201
205
  align="start"
202
- className="w-80 gap-0 p-1"
206
+ className={cn("gap-0 p-1", canBeMentioned ? "w-96" : "w-80")}
203
207
  side="bottom"
204
208
  sideOffset={6}
205
209
  >
206
210
  <div className="flex items-center justify-between gap-2 px-2 py-1.5">
207
- <PopoverTitle className="studio-small font-medium">
211
+ <PopoverTitle className="studio-small whitespace-nowrap font-medium">
208
212
  <Trans>Comments</Trans>
209
213
  {count > 0 ? (
210
214
  // How many are new: here, not on the bell, which has only a dot.
@@ -213,7 +217,11 @@ const BellPopover = ({
213
217
  </span>
214
218
  ) : null}
215
219
  </PopoverTitle>
216
- <ThreadFilterTabs onChange={onFilter} value={filter} />
220
+ <ThreadFilterTabs
221
+ canBeMentioned={canBeMentioned}
222
+ onChange={onFilter}
223
+ value={filter}
224
+ />
217
225
  </div>
218
226
  {children}
219
227
  </PopoverContent>
@@ -251,6 +259,7 @@ const NotificationsBell = ({
251
259
  const threads = every.filter((thread) => !thread.review);
252
260
  const { _ } = useLingui();
253
261
  const me = useMe().contributor?.name;
262
+ const mentionable = useMentionable();
254
263
  const seen = useSeen();
255
264
  // While open, the popover lists what was new when it opened.
256
265
  const [openedFrom, setOpenedFrom] = useState<number>();
@@ -264,8 +273,8 @@ const NotificationsBell = ({
264
273
  : threads
265
274
  .filter((thread) => !(isClosed(thread) || fresh.includes(thread)))
266
275
  .sort(newestFirst);
267
- const shownFresh = fresh.filter(byFilter(filter));
268
- const shownOthers = others.filter(byFilter(filter));
276
+ const shownFresh = fresh.filter(byFilter(filter, mentionable));
277
+ const shownOthers = others.filter(byFilter(filter, mentionable));
269
278
  const close = () => setOpenedFrom(undefined);
270
279
  const open = () => {
271
280
  setOpenedFrom(seen);
@@ -275,6 +284,7 @@ const NotificationsBell = ({
275
284
 
276
285
  return (
277
286
  <BellPopover
287
+ canBeMentioned={mentionable !== undefined}
278
288
  count={count}
279
289
  filter={filter}
280
290
  label={_(msg`Notifications`)}
@@ -1,10 +1,14 @@
1
1
  import {
2
2
  type CSSProperties,
3
+ createContext,
4
+ type ReactNode,
3
5
  type RefObject,
6
+ useContext,
4
7
  useEffect,
5
8
  useRef,
6
9
  useState,
7
10
  } from "react";
11
+ import { PAGE_REFRESH, VIEW_RENDERED } from "../../src/shared/page-messages.ts";
8
12
  import type { Sketch } from "../types";
9
13
  import { usePresenceStyle } from "./presence-style";
10
14
  import {
@@ -21,10 +25,11 @@ import {
21
25
 
22
26
  // While an agent changes a view, the view is drawn in blocks of the
23
27
  // presence colour, from its own layout (skeleton.ts): first the whole view,
24
- // pulsing, until its first change lands; then each element that changes,
25
- // outlined with ticks at its corners and drawn in blocks over itself for a
26
- // moment. A view with nothing on it yet is drawn as the page it will most
27
- // likely be (a `Guess`), else as a generic page. The
28
+ // pulsing, until its first change lands; then each element the agent
29
+ // changes, outlined with ticks at its corners and drawn in blocks over itself
30
+ // for a moment. What the view changes on its own, as it animates, is not the
31
+ // agent's and is never drawn. A view with nothing on it yet is drawn as the
32
+ // page it will most likely be (a `Guess`), else as a generic page. The
28
33
  // blocks move only by opacity, so the compositor runs them and the view's
29
34
  // own rendering never waits on them; the finished view shows through as
30
35
  // soon as it changes.
@@ -128,11 +133,18 @@ const usePresenceExit = (active: boolean) => {
128
133
  };
129
134
 
130
135
  /** A still edge round the view, so it is clear which frame is changing. */
131
- const PresenceEdge = ({ leaving }: { leaving: boolean }) => (
136
+ const PresenceEdge = ({
137
+ hidden,
138
+ leaving,
139
+ }: {
140
+ hidden: boolean;
141
+ leaving: boolean;
142
+ }) => (
132
143
  <div
133
144
  aria-hidden
134
145
  className="studio-presence studio-presence-edge pointer-events-none absolute inset-0 z-10"
135
146
  data-leaving={leaving || undefined}
147
+ hidden={hidden}
136
148
  />
137
149
  );
138
150
 
@@ -242,6 +254,64 @@ interface Focus {
242
254
 
243
255
  let focusIds = 0;
244
256
 
257
+ /**
258
+ * Calls `listener` with what changes on `page` as its view refreshes with
259
+ * changed code: the changes delivered next, in the same task as
260
+ * PAGE_REFRESH. What the page changes on its own (an animation, a timer)
261
+ * never comes. Returns a function that stops watching.
262
+ */
263
+ const watchRefreshes = (
264
+ page: Document,
265
+ listener: (records: MutationRecord[]) => void
266
+ ): (() => void) => {
267
+ let refreshing = false;
268
+ let settle: ReturnType<typeof setTimeout> | undefined;
269
+ const changes = new MutationObserver((records) => {
270
+ if (refreshing) {
271
+ refreshing = false;
272
+ listener(records);
273
+ }
274
+ });
275
+ const onRefresh = () => {
276
+ // What changed until now was the page's own.
277
+ changes.takeRecords();
278
+ refreshing = true;
279
+ // A refresh that changes nothing on this page delivers nothing.
280
+ clearTimeout(settle);
281
+ settle = setTimeout(() => {
282
+ refreshing = false;
283
+ });
284
+ };
285
+ page.addEventListener(PAGE_REFRESH, onRefresh);
286
+ changes.observe(page.body, {
287
+ attributeFilter: ["class", "src"],
288
+ characterData: true,
289
+ childList: true,
290
+ subtree: true,
291
+ });
292
+ return () => {
293
+ clearTimeout(settle);
294
+ page.removeEventListener(PAGE_REFRESH, onRefresh);
295
+ changes.disconnect();
296
+ };
297
+ };
298
+
299
+ /**
300
+ * Calls `listener` each time `page` renders a view (VIEW_RENDERED): once it
301
+ * has loaded, where it had none, or again once a view that broke loads.
302
+ * Returns a function that stops watching.
303
+ */
304
+ const watchRenders = (page: Document, listener: () => void): (() => void) => {
305
+ const root = page.documentElement;
306
+ const renders = new MutationObserver(() => {
307
+ if (root.hasAttribute(VIEW_RENDERED)) {
308
+ listener();
309
+ }
310
+ });
311
+ renders.observe(root, { attributeFilter: [VIEW_RENDERED] });
312
+ return () => renders.disconnect();
313
+ };
314
+
245
315
  /**
246
316
  * The view an agent is changing, in blocks. Its page is measured once, on
247
317
  * the frame after it loads, and each batch of changes once, just before the
@@ -249,10 +319,12 @@ let focusIds = 0;
249
319
  */
250
320
  const PresenceBlocks = ({
251
321
  guess,
322
+ hidden,
252
323
  iframe,
253
324
  leaving,
254
325
  }: {
255
326
  guess?: Guess;
327
+ hidden: boolean;
256
328
  iframe: HTMLIFrameElement | null;
257
329
  leaving: boolean;
258
330
  }) => {
@@ -261,14 +333,15 @@ const PresenceBlocks = ({
261
333
  const [revealed, setRevealed] = useState(false);
262
334
  const [focused, setFocused] = useState<Map<Element, Focus>>(new Map());
263
335
  const holder = useRef<HTMLDivElement>(null);
264
- // Each page the frame loads while the agent works: a new view's first, or
265
- // one loaded afresh. Each is measured and watched in its turn.
266
- const [loads, setLoads] = useState(0);
336
+ // Each page the frame shows while the agent works: each it loads (a new
337
+ // view's first, or one loaded afresh) and each view a page renders. Each
338
+ // is measured and watched in its turn.
339
+ const [pages, setPages] = useState(0);
267
340
  useEffect(() => {
268
341
  if (!iframe) {
269
342
  return;
270
343
  }
271
- const loaded = () => setLoads((count) => count + 1);
344
+ const loaded = () => setPages((count) => count + 1);
272
345
  iframe.addEventListener("load", loaded);
273
346
  return () => iframe.removeEventListener("load", loaded);
274
347
  }, [iframe]);
@@ -287,9 +360,9 @@ const PresenceBlocks = ({
287
360
  setSkeleton(
288
361
  empty ? { background: measured?.background ?? "" } : measured
289
362
  );
290
- // A page loaded while the agent works is what it made: shown at
291
- // once, unless there is nothing on it yet.
292
- if (loads > 0) {
363
+ // A page loaded, or a view rendered, while the agent works is what it
364
+ // made: shown at once, unless there is nothing on it yet.
365
+ if (pages > 0) {
293
366
  setRevealed(!empty);
294
367
  }
295
368
  });
@@ -339,30 +412,32 @@ const PresenceBlocks = ({
339
412
  }, FOCUS_MS);
340
413
  timers.add(timer);
341
414
  };
342
- const observer = new MutationObserver((records) => {
415
+ const stopRefreshes = watchRefreshes(page, (records) => {
343
416
  if (pending.length === 0) {
344
417
  cancelAnimationFrame(frame);
345
418
  frame = requestAnimationFrame(focus);
346
419
  }
347
420
  pending.push(...records);
348
421
  });
349
- observer.observe(page.body, {
350
- attributeFilter: ["class", "src"],
351
- characterData: true,
352
- childList: true,
353
- subtree: true,
354
- });
422
+ const stopRenders = watchRenders(page, () =>
423
+ setPages((count) => count + 1)
424
+ );
355
425
  return () => {
356
426
  cancelAnimationFrame(frame);
357
- observer.disconnect();
427
+ stopRefreshes();
428
+ stopRenders();
358
429
  for (const timer of timers) {
359
430
  clearTimeout(timer);
360
431
  }
432
+ // What was lit on this page goes with it, its timers gone too.
433
+ setFocused((current) => (current.size === 0 ? current : new Map()));
361
434
  };
362
- }, [iframe, loads]);
435
+ }, [iframe, pages]);
363
436
  const toCome = usePageToCome(holder, guess, skeleton?.bones === undefined);
364
437
  const bones = skeleton?.bones ?? toCome;
365
438
 
439
+ // Out of sight, what it draws hides and the holder keeps its size: the
440
+ // page to come is still laid out in it, and what changes is followed.
366
441
  return (
367
442
  <div
368
443
  aria-hidden
@@ -373,6 +448,7 @@ const PresenceBlocks = ({
373
448
  <div
374
449
  className="studio-presence-skeleton absolute inset-0"
375
450
  data-leaving={leaving || revealed || undefined}
451
+ hidden={hidden}
376
452
  style={{ backgroundColor: skeleton.background }}
377
453
  >
378
454
  <svg className="studio-presence-blocks studio-presence-pulse absolute top-0 left-0 h-full w-full">
@@ -381,7 +457,7 @@ const PresenceBlocks = ({
381
457
  </svg>
382
458
  </div>
383
459
  ) : null}
384
- {focused.size > 0 && !leaving ? (
460
+ {focused.size > 0 && !(leaving || hidden) ? (
385
461
  <svg className="studio-presence-blocks absolute top-0 left-0 h-full w-full">
386
462
  <title>Changing</title>
387
463
  {[...focused.values()].map((entry) => (
@@ -392,17 +468,19 @@ const PresenceBlocks = ({
392
468
  ))}
393
469
  </svg>
394
470
  ) : null}
395
- <PresenceEdge leaving={leaving} />
471
+ <PresenceEdge hidden={hidden} leaving={leaving} />
396
472
  </div>
397
473
  );
398
474
  };
399
475
 
476
+ const HiddenContext = createContext(false);
477
+
400
478
  /**
401
479
  * An agent at work on a view, while `active`. Given the frame's `iframe`,
402
480
  * the view in blocks from its layout; with `blank`, a page still to come,
403
481
  * in blocks as `guess` has it or as a generic page; with neither, only an
404
482
  * edge round it. Each person may have only the edge, or nothing
405
- * (presence-style.ts).
483
+ * (presence-style.ts); within PresenceHidden, it is out of sight.
406
484
  */
407
485
  export const Presence = ({
408
486
  active,
@@ -416,18 +494,37 @@ export const Presence = ({
416
494
  iframe?: HTMLIFrameElement | null;
417
495
  }) => {
418
496
  const style = usePresenceStyle();
497
+ const hidden = useContext(HiddenContext);
419
498
  const { leaving, shown } = usePresenceExit(active);
420
499
  if (!shown || style === "off") {
421
500
  return null;
422
501
  }
423
502
  if (style === "edge" || (iframe === undefined && !blank)) {
424
- return <PresenceEdge leaving={leaving} />;
503
+ return <PresenceEdge hidden={hidden} leaving={leaving} />;
425
504
  }
426
505
  return (
427
- <PresenceBlocks guess={guess} iframe={iframe ?? null} leaving={leaving} />
506
+ <PresenceBlocks
507
+ guess={guess}
508
+ hidden={hidden}
509
+ iframe={iframe ?? null}
510
+ leaving={leaving}
511
+ />
428
512
  );
429
513
  };
430
514
 
515
+ /**
516
+ * Agents at work show nowhere within while `when` is true: the canvas in
517
+ * zen mode (⌘\). Out of sight, presence still follows the work, so it comes
518
+ * back as it would have been; the style each person chose is left alone.
519
+ */
520
+ export const PresenceHidden = ({
521
+ children,
522
+ when,
523
+ }: {
524
+ children: ReactNode;
525
+ when: boolean;
526
+ }) => <HiddenContext value={when}>{children}</HiddenContext>;
527
+
431
528
  /** When a page still to come is guessed again, after the canvas opens. */
432
529
  const GUESS_RETRIES_MS = [0, 800, 2000, 5000];
433
530