@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
@@ -132,6 +132,11 @@ const lacking = (piece, why, found = false) => ({
132
132
  why,
133
133
  found
134
134
  });
135
+ /** A piece the studio wrote under a name from before a rename. */
136
+ const named = (piece, why) => ({
137
+ ...lacking(piece, why, true),
138
+ old: true
139
+ });
135
140
  /** An MCP server's command and arguments, as one list of words. */
136
141
  const words = (entry) => {
137
142
  const value = isRecord(entry) ? entry : {};
@@ -177,6 +182,7 @@ const oldCommand = (server) => {
177
182
  if (old) return runsOldCommand(old);
178
183
  if (server[0] === "npx" && runs === "dex" && !server.includes(NPX_PACKAGE)) return `runs \`npx dex\` without \`${NPX_PACKAGE}\`, which can fetch another package from npm`;
179
184
  };
185
+ const isOldName = (name) => OLD_CHANNEL_SERVERS.includes(name);
180
186
  /**
181
187
  * Why a server's command can't start, if it can't: a `dex` command at a
182
188
  * path, from where the agent starts, that isn't there. An install can move
@@ -230,7 +236,7 @@ async function claudeChannelServer(dir) {
230
236
  name: "dex"
231
237
  };
232
238
  for (const old of OLD_CHANNEL_SERVERS) if (names.has(old)) {
233
- if (old === "sudio") renamedNotice(`the MCP server "${old}"`, `"dex"`, "`npx dex doctor` says where it is; Connect in the studio renames it.");
239
+ if (old === "sudio") renamedNotice(`the MCP server "${old}"`, `"dex"`, "`npx dex upgrade` renames it.");
234
240
  return {
235
241
  found: true,
236
242
  name: old
@@ -260,17 +266,24 @@ const isStale = (current, wanted) => {
260
266
  /** The studio's MCP server, from an agent's servers by name, in `file`. */
261
267
  function serverPiece(servers, file, place) {
262
268
  const studio = servers["dex"];
269
+ const copies = copiesOf(servers, place);
263
270
  if (studio) {
264
271
  if (servesHere(studio, place)) {
265
- const old = oldCommand(studio) ?? missingCommand(studio, place);
266
- return old ? lacking("mcp", `the "dex" server in ${file} ${old}`, true) : inPlace("mcp");
272
+ const old = oldCommand(studio);
273
+ if (old) return named("mcp", `the "dex" server in ${file} ${old}`);
274
+ const moved = missingCommand(studio, place);
275
+ if (moved) return lacking("mcp", `the "dex" server in ${file} ${moved}`, true);
276
+ const left = copies.find(isOldName);
277
+ return left ? named("mcp", `the studio's server in ${file} is there as "${left}" too, its name from before`) : inPlace("mcp");
267
278
  }
268
279
  const at = rootArg(studio) ?? "";
269
280
  const here = isAbsolute(at) ? resolve(place.content) : shown(place.agentRoot, place.content);
270
281
  return lacking("mcp", `the "dex" server in ${file} points at ${at}, not ${here}`, true);
271
282
  }
272
- const [other] = copiesOf(servers, place);
273
- return other ? lacking("mcp", `the studio's server in ${file} is named "${other}", not "dex"`, true) : lacking("mcp", `no "dex" server in ${file}`);
283
+ const [other] = copies;
284
+ if (!other) return lacking("mcp", `no "dex" server in ${file}`);
285
+ const why = `the studio's server in ${file} is named "${other}", not "dex"`;
286
+ return isOldName(other) ? named("mcp", why) : lacking("mcp", why, true);
274
287
  }
275
288
  /** The servers in a JSON config, under `key`, by name. */
276
289
  const serversIn = (config, key) => Object.fromEntries(Object.entries(objectAt(config, key)).map(([name, entry]) => [name, words(entry)]));
@@ -332,7 +345,7 @@ async function hookPieces(place) {
332
345
  const missing = events.filter((event) => studioHooks(config, event).length === 0);
333
346
  if (missing.length > 0) return lacking(piece, `no ${piece} hook for ${missing.join(" or ")} in ${SETTINGS}`, missing.length < events.length);
334
347
  const old = events.flatMap((event) => studioHooks(config, event)).map((command) => OLD_HOOK_RE.exec(command)?.[1]).find(Boolean);
335
- if (old) return lacking(piece, `the ${piece} hook in ${SETTINGS} ${runsOldCommand(old)}`, true);
348
+ if (old) return named(piece, `the ${piece} hook in ${SETTINGS} ${runsOldCommand(old)}`);
336
349
  const moved = events.flatMap((event) => studioHooks(config, event)).map((command) => {
337
350
  const [, quoted, bare] = HOOK_COMMAND_RE.exec(command) ?? [];
338
351
  return missingCommand([quoted ?? bare ?? ""], place);
@@ -659,10 +672,12 @@ function agentSetups(root, content, agentRoot = root) {
659
672
  const agent = AGENTS[id];
660
673
  const pieces = await agent.pieces(place);
661
674
  const status = statusOf(pieces);
675
+ const missing = pieces.filter(({ why }) => why);
662
676
  return {
663
677
  id,
664
678
  status,
665
679
  configured: status === "set-up",
680
+ old: missing.length > 0 && missing.every((piece) => piece.old),
666
681
  missing: pieces.flatMap(({ piece, why }) => why ? [{
667
682
  piece,
668
683
  why
@@ -0,0 +1,22 @@
1
+ import { CanvasPresence, CanvasTeammate, PresenceUser } from "../shared/live-presence.mjs";
2
+ import { Plugin } from "vite";
3
+ //#region src/server/canvas-presence.d.ts
4
+ /** Hear people here move: what live sync shares in the room. */
5
+ export declare const onCanvasPlaces: (listener: () => void) => () => void;
6
+ /** What live sync shares in the room, now. */
7
+ export interface RoomCanvas {
8
+ /** Where you are, on your own machine; null when on no canvas, or hosted. */
9
+ canvas: CanvasPresence | null;
10
+ /** Hosted, everyone in the browser on a canvas, each as themselves. */
11
+ people: {
12
+ canvas: CanvasPresence;
13
+ user: PresenceUser;
14
+ }[];
15
+ }
16
+ /** Everyone here on a canvas, in the room's terms. */
17
+ export declare function roomCanvas(): RoomCanvas;
18
+ /** Everyone in the room on a canvas, as the room says now. */
19
+ export declare function setCanvasTeammates(teammates: CanvasTeammate[]): void;
20
+ /** The dev server's end: the canvas's socket messages, both ways. */
21
+ export declare const canvasPresence: () => Plugin;
22
+ //#endregion
@@ -0,0 +1,160 @@
1
+ import { CANVAS_HELLO_EVENT, CANVAS_PRESENCE_EVENT, CANVAS_TEAMMATES_EVENT, PERSON_HEADER, cleanCanvasPresence } from "../shared/live-presence.mjs";
2
+ import { isHosted, personFromHeader } from "../content/hosted-person.mjs";
3
+ //#region src/server/canvas-presence.ts
4
+ /** The one person of a Dex on someone's own machine. */
5
+ const YOU = "you";
6
+ const KEY = Symbol.for("dex.canvas-presence");
7
+ const hub = () => {
8
+ const holder = globalThis;
9
+ holder[KEY] ??= {
10
+ placeListeners: /* @__PURE__ */ new Set(),
11
+ places: /* @__PURE__ */ new Map(),
12
+ teammateListeners: /* @__PURE__ */ new Set(),
13
+ teammates: []
14
+ };
15
+ return holder[KEY];
16
+ };
17
+ const listen = (listeners, listener) => {
18
+ listeners.add(listener);
19
+ return () => {
20
+ listeners.delete(listener);
21
+ };
22
+ };
23
+ /**
24
+ * Where someone here is on a canvas, or null when on none: you, on your own
25
+ * machine (no `who`), or a person in the browser, hosted.
26
+ */
27
+ function shareCanvasPlace(place, who) {
28
+ const state = hub();
29
+ const key = who?.key ?? YOU;
30
+ if (place) state.places.set(key, {
31
+ place,
32
+ ...who && { user: who.user }
33
+ });
34
+ else state.places.delete(key);
35
+ for (const listener of state.placeListeners) listener();
36
+ }
37
+ /** Hear people here move: what live sync shares in the room. */
38
+ const onCanvasPlaces = (listener) => listen(hub().placeListeners, listener);
39
+ /** Everyone here on a canvas, in the room's terms. */
40
+ function roomCanvas() {
41
+ const room = {
42
+ canvas: null,
43
+ people: []
44
+ };
45
+ for (const [key, { place, user }] of hub().places) if (user) room.people.push({
46
+ canvas: place,
47
+ user
48
+ });
49
+ else if (key === YOU) room.canvas = place;
50
+ return room;
51
+ }
52
+ /** Everyone in the room on a canvas, as the room says now. */
53
+ function setCanvasTeammates(teammates) {
54
+ const state = hub();
55
+ state.teammates = teammates;
56
+ for (const listener of state.teammateListeners) listener(teammates);
57
+ }
58
+ /** Hear the room's teammates change. */
59
+ const onCanvasTeammates = (listener) => listen(hub().teammateListeners, listener);
60
+ /** Who a person here is, in the room's terms. */
61
+ const userOf = (person) => {
62
+ const color = person.color ?? "#3e63dd";
63
+ return {
64
+ id: person.id,
65
+ name: person.name,
66
+ color,
67
+ colorLight: `${color}33`
68
+ };
69
+ };
70
+ /**
71
+ * Who a canvas sees: the room's teammates, and, hosted, everyone else here
72
+ * in the browser. `self` is the person whose canvas it is, when hosted.
73
+ */
74
+ function teammatesFor(self) {
75
+ const state = hub();
76
+ const here = [];
77
+ for (const [key, { place, user }] of state.places) if (user && key !== self) here.push({
78
+ ...place,
79
+ id: `here:${key}`,
80
+ user
81
+ });
82
+ const room = self ? state.teammates.filter((teammate) => teammate.user.id !== self) : state.teammates;
83
+ return here.length > 0 ? [...room, ...here] : room;
84
+ }
85
+ /** The dev server's end: the canvas's socket messages, both ways. */
86
+ const canvasPresence = () => ({
87
+ name: "dex-canvas-presence",
88
+ configureServer(server) {
89
+ const hosted = isHosted();
90
+ /** Hosted: who each socket is from, as the preview host said. */
91
+ const people = /* @__PURE__ */ new Map();
92
+ if (hosted) server.ws.on("connection", (socket, request) => {
93
+ const person = personFromHeader(request.headers[PERSON_HEADER]);
94
+ if (person) {
95
+ people.set(socket, {
96
+ key: person.id,
97
+ user: userOf(person)
98
+ });
99
+ socket.once("close", () => people.delete(socket));
100
+ }
101
+ });
102
+ let from;
103
+ const said = /* @__PURE__ */ new WeakSet();
104
+ /** Hosted, which of each person's tabs moved last: theirs is the place. */
105
+ const latest = /* @__PURE__ */ new Map();
106
+ server.ws.on(CANVAS_PRESENCE_EVENT, (data, client) => {
107
+ const place = cleanCanvasPresence(data) ?? null;
108
+ const socket = client.socket;
109
+ if (hosted) {
110
+ const who = people.get(socket);
111
+ if (!who) return;
112
+ shareCanvasPlace(place, who);
113
+ latest.set(who.key, socket);
114
+ if (!said.has(socket)) {
115
+ said.add(socket);
116
+ socket.once("close", () => {
117
+ if (latest.get(who.key) === socket) {
118
+ latest.delete(who.key);
119
+ shareCanvasPlace(null, who);
120
+ }
121
+ });
122
+ }
123
+ return;
124
+ }
125
+ shareCanvasPlace(place);
126
+ if (socket !== from) {
127
+ from = socket;
128
+ socket.once("close", () => {
129
+ if (from === socket) {
130
+ from = void 0;
131
+ shareCanvasPlace(null);
132
+ }
133
+ });
134
+ }
135
+ });
136
+ /** Each canvas its own list: never itself among its teammates. */
137
+ const sendAll = () => {
138
+ if (!hosted) {
139
+ server.ws.send(CANVAS_TEAMMATES_EVENT, teammatesFor(void 0));
140
+ return;
141
+ }
142
+ for (const client of server.ws.clients) {
143
+ const who = people.get(client.socket);
144
+ client.send(CANVAS_TEAMMATES_EVENT, teammatesFor(who?.key));
145
+ }
146
+ };
147
+ server.ws.on(CANVAS_HELLO_EVENT, (_data, client) => {
148
+ const who = people.get(client.socket);
149
+ client.send(CANVAS_TEAMMATES_EVENT, teammatesFor(who?.key));
150
+ });
151
+ const stopRoom = onCanvasTeammates(sendAll);
152
+ const stopHere = hosted ? onCanvasPlaces(sendAll) : () => void 0;
153
+ server.httpServer?.once("close", () => {
154
+ stopRoom();
155
+ stopHere();
156
+ });
157
+ }
158
+ });
159
+ //#endregion
160
+ export { canvasPresence, onCanvasPlaces, roomCanvas, setCanvasTeammates };
@@ -50,7 +50,7 @@ async function skillFolders(from) {
50
50
  const project = await readConfig(from);
51
51
  const menu = project?.commands ?? {};
52
52
  return {
53
- team: teamSkillsIn(project?.root ?? from),
53
+ team: teamSkillsIn(project?.content ?? from, project?.root ?? from),
54
54
  codebase: project && switchOn(menu, "codebase") ? codebaseSkills(project.root).folders : [],
55
55
  ...switchOn(menu, "builtIn") ? { installed: INSTALLED_SKILLS } : {}
56
56
  };
@@ -95,14 +95,6 @@ export declare function startComment({ author, prototype, threads }: FileComment
95
95
  * another's comment: one there is not found.
96
96
  */
97
97
  export declare function changeComment({ author, prototype, threads }: PersonComments, id: string, change: Omit<PersonChange, "authorId">): Promise<Outcome<ThreadWithPrototype>>;
98
- /** A person's reply: a closed comment opens again with it. */
99
- export declare const replyToComment: (context: PersonComments, id: string, body: string) => Promise<Outcome<ThreadWithPrototype>>;
100
- /** A person resolves a comment. */
101
- export declare const resolveComment: (context: PersonComments, id: string) => Promise<Outcome<ThreadWithPrototype>>;
102
- /** A person dismisses a comment: how one is deleted. */
103
- export declare const dismissComment: (context: PersonComments, id: string) => Promise<Outcome<ThreadWithPrototype>>;
104
- /** A person opens a closed comment again. */
105
- export declare const reopenComment: (context: PersonComments, id: string) => Promise<Outcome<ThreadWithPrototype>>;
106
98
  /**
107
99
  * An agent starts on a comment (its 👀): claimed for its session, the
108
100
  * comment is that session's alone until it closes, asks or lets it go.
@@ -81,14 +81,6 @@ async function changeComment({ author, prototype, threads }, id, change) {
81
81
  if (!changed) return refused("not-found", [GONE]);
82
82
  return changed.problems ? refused("invalid", changed.problems) : { value: changed.thread };
83
83
  }
84
- /** A person's reply: a closed comment opens again with it. */
85
- const replyToComment = (context, id, body) => changeComment(context, id, { body });
86
- /** A person resolves a comment. */
87
- const resolveComment = (context, id) => changeComment(context, id, { status: "resolved" });
88
- /** A person dismisses a comment: how one is deleted. */
89
- const dismissComment = (context, id) => changeComment(context, id, { status: "dismissed" });
90
- /** A person opens a closed comment again. */
91
- const reopenComment = (context, id) => changeComment(context, id, { status: "open" });
92
84
  /**
93
85
  * An agent starts on a comment (its 👀): claimed for its session, the
94
86
  * comment is that session's alone until it closes, asks or lets it go.
@@ -151,4 +143,4 @@ async function closeComment({ designSystem, from, root, session, threads }, { di
151
143
  } };
152
144
  }
153
145
  //#endregion
154
- export { askOnComment, changeComment, claimComment, closeComment, commentsOn, dismissComment, findPrototype, listComments, reopenComment, replyToComment, resolveComment, startComment };
146
+ export { askOnComment, changeComment, claimComment, closeComment, commentsOn, findPrototype, listComments, startComment };
@@ -1,7 +1,8 @@
1
1
  import { isRecord } from "../../shared/checks.mjs";
2
2
  import { refused } from "../outcome.mjs";
3
- import { changeComment, commentsOn, dismissComment, findPrototype, listComments, reopenComment, replyToComment, resolveComment, startComment } from "./actions.mjs";
3
+ import { changeComment, commentsOn, findPrototype, listComments, startComment } from "./actions.mjs";
4
4
  import { COMMENT_CHANGE, NEW_COMMENT } from "../../shared/comments/routes.mjs";
5
+ import { Problems } from "../problems.mjs";
5
6
  //#region src/server/comments/routes.ts
6
7
  /**
7
8
  * Each kind of problem an action answers with, as a status. What the
@@ -16,24 +17,14 @@ const STATUS = {
16
17
  };
17
18
  /** A request that names no file, or whose body is not as its schema says. */
18
19
  const BAD_REQUEST = 400;
19
- /** A refusal, as the request handler (requests.ts) sends one. */
20
- var Refusal = class extends Error {
21
- problems;
22
- status;
23
- constructor(status, problems) {
24
- super(problems.join(" "));
25
- this.status = status;
26
- this.problems = problems;
27
- }
28
- };
29
20
  /** What an action did, or its problem refused with the status for its kind. */
30
21
  const answer = (outcome) => {
31
- if (outcome.problem) throw new Refusal(STATUS[outcome.problem.kind], outcome.problem.messages);
22
+ if (outcome.problem) throw new Problems(STATUS[outcome.problem.kind], outcome.problem.messages);
32
23
  return outcome.value;
33
24
  };
34
25
  /** What the request asks for, or a 400 saying what is wrong with it. */
35
26
  const asked = (outcome) => {
36
- if (outcome.problem) throw new Refusal(BAD_REQUEST, outcome.problem.messages);
27
+ if (outcome.problem) throw new Problems(BAD_REQUEST, outcome.problem.messages);
37
28
  return outcome.value;
38
29
  };
39
30
  /** A body as its schema reads it, or an invalid problem naming each field. */
@@ -47,25 +38,9 @@ const listThreads = ({ project, threads, url }) => listComments({
47
38
  root: project.content,
48
39
  threads
49
40
  }, url.searchParams.has("slug") ? asked(findPrototype(project.content, slugOf(url))) : void 0);
50
- /** The person's actions that a change of one status alone is. */
51
- const BY_STATUS = /* @__PURE__ */ new Map([
52
- ["resolved", resolveComment],
53
- ["dismissed", dismissComment],
54
- ["open", reopenComment]
55
- ]);
56
- /**
57
- * A person's change, as the action it asks for: a reply alone, or a status
58
- * alone, is its own; anything else, or several at once, is one change.
59
- */
60
- const changeAsked = (context, { id, ...change }) => {
61
- const fields = Object.keys(change);
62
- if (fields.length === 1 && change.body !== void 0) return replyToComment(context, id, change.body);
63
- const status = fields.length === 1 && change.status !== void 0 ? BY_STATUS.get(change.status) : void 0;
64
- return status ? status(context, id) : changeComment(context, id, change);
65
- };
66
41
  /** Start a comment, or change one by its id, as the person using Dex. */
67
42
  async function postThread({ body, project, threads, url }) {
68
- if (!body) throw new Refusal(BAD_REQUEST, ["Send a thread to start, or a change to one."]);
43
+ if (!body) throw new Problems(BAD_REQUEST, ["Send a thread to start, or a change to one."]);
69
44
  const sent = isRecord(body) && body.id !== void 0 ? asked(checked(COMMENT_CHANGE, body)) : asked(checked(NEW_COMMENT, body));
70
45
  const context = asked(await commentsOn({
71
46
  root: project.content,
@@ -74,7 +49,11 @@ async function postThread({ body, project, threads, url }) {
74
49
  prototype: slugOf(url),
75
50
  by: { kind: "person" }
76
51
  }));
77
- return answer("id" in sent ? await changeAsked(context, sent) : await startComment(context, sent));
52
+ if ("id" in sent) {
53
+ const { id, ...change } = sent;
54
+ return answer(await changeComment(context, id, change));
55
+ }
56
+ return answer(await startComment(context, sent));
78
57
  }
79
58
  /**
80
59
  * The comment requests, by name and method, for requests.ts's route table:
@@ -5,6 +5,7 @@ import { openPresence } from "./presence.mjs";
5
5
  import { prototypesDir } from "../content/prototypes.mjs";
6
6
  import { checkForUpdate } from "./updates.mjs";
7
7
  import { STUDIO_FILES, classify } from "../shared/studio-files.mjs";
8
+ import { isInside } from "../setup/detect/workspace.mjs";
8
9
  import { openThreads } from "../content/thread-module.mjs";
9
10
  import { localSessions } from "./channel.mjs";
10
11
  import { WORKSPACE_ICON_FILES } from "../shared/workspace.mjs";
@@ -19,6 +20,7 @@ import { eventHub, studioRequests } from "./requests.mjs";
19
20
  import { existsSync, realpathSync } from "node:fs";
20
21
  import { basename, dirname, join, relative, sep } from "node:path";
21
22
  import { homedir } from "node:os";
23
+ import { isCSSRequest } from "vite";
22
24
  //#region src/server/dev-server.ts
23
25
  const PRESENCE_TICK_MS = 3e4;
24
26
  const SETTLE_MS = 250;
@@ -34,6 +36,13 @@ const READ_FOLDERS = /* @__PURE__ */ new Set([
34
36
  const SVG_PATH_RE = /\.svgz?$/i;
35
37
  const SVG_POLICY = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox";
36
38
  /**
39
+ * Whether a page imports a module. A stylesheet's import is only Tailwind's
40
+ * scan: Tailwind makes a stylesheet depend on every file in the folders it
41
+ * scans for classes (the frame's, the files folder; the interface's, Dex's
42
+ * own app), and Vite records each as a module the stylesheet imports.
43
+ */
44
+ const importedByPage = (module) => [...module.importers].some((importer) => !isCSSRequest(importer.url));
45
+ /**
37
46
  * Whether a module is a file-only entry nothing imports any more. For each
38
47
  * file a stylesheet depends on, such as each view's stylesheet Tailwind
39
48
  * scans for classes, Vite makes a file-only entry (createFileOnlyEntry): a
@@ -41,9 +50,24 @@ const SVG_POLICY = "default-src 'none'; style-src 'unsafe-inline'; img-src data:
41
50
  * file is deleted and Tailwind scans again, nothing imports the entry, but
42
51
  * Vite keeps it; when a file is written at that path again (a review
43
52
  * imported again, a file restored), Vite finds nothing that takes the
44
- * update and reloads every page. No page imports it, so none needs it.
53
+ * update and reloads every page.
45
54
  */
46
55
  const orphanedFileOnlyEntry = (module) => module.id === null && module.importers.size === 0;
56
+ /**
57
+ * Whether only the stylesheets that scan a module import it, outside Dex's
58
+ * own app: a file Tailwind scans that no page loads, such as a new file's
59
+ * docs/.gitkeep, scanned and then reported again. Vite takes a module only
60
+ * stylesheets import for a page itself (an HTML template Tailwind scans),
61
+ * and reloads every page when it changes. Only Dex's own app has pages
62
+ * (index.html and frame.html, and the scripts they load, which only
63
+ * stylesheets import), so there Vite is right.
64
+ */
65
+ const onlyScanned = (module) => module.file !== null && !isInside(APP_DIR, module.file) && module.importers.size > 0 && !importedByPage(module);
66
+ /**
67
+ * Whether no page has a module, though Vite would reload every page for it
68
+ * (propagateUpdate's dead end).
69
+ */
70
+ const pageless = (module) => orphanedFileOnlyEntry(module) || onlyScanned(module);
47
71
  /** Whether a request is for an SVG file, as Vite reads its path. */
48
72
  const isSvgRequest = (url = "") => {
49
73
  try {
@@ -102,13 +126,13 @@ function studioDev(project) {
102
126
  /**
103
127
  * Whether `path` is a folder in the content folder the studio never reads,
104
128
  * as the watcher may name it: any but its own, and every folder in
105
- * .studio (pictures, the trash). A file never is, since Vite watches the
129
+ * .local (pictures, the trash). A file never is, since Vite watches the
106
130
  * files it imports wherever they are.
107
131
  */
108
132
  const unread = (path, stats) => {
109
133
  if (!stats?.isDirectory()) return false;
110
134
  const parent = dirname(path);
111
- return [content, realContent].some((root) => parent === join(root, ".studio") || parent === root && !READ_FOLDERS.has(basename(path)));
135
+ return [content, realContent].some((root) => parent === join(root, ".local") || parent === root && !READ_FOLDERS.has(basename(path)));
112
136
  };
113
137
  const markClaimed = claimedPresence({
114
138
  clear: presence.clear,
@@ -122,9 +146,8 @@ function studioDev(project) {
122
146
  name: "studio-dev",
123
147
  apply: "serve",
124
148
  hotUpdate({ file, modules }) {
125
- if (kindOf(file) !== "other" || isAvatar(file) || basename(file) === ".gitattributes") return [];
126
- const kept = modules.filter((module) => !orphanedFileOnlyEntry(module));
127
- if (kept.length < modules.length) return kept;
149
+ if (kindOf(file) !== "other" || isAvatar(file)) return [];
150
+ if (modules.some(pageless)) return [...new Set(modules.flatMap((module) => pageless(module) ? [...module.importers] : [module]))];
128
151
  },
129
152
  config: ({ server }) => server?.watch === null ? void 0 : { server: { watch: { ignored: [unread] } } },
130
153
  configureServer(server) {
@@ -160,10 +183,12 @@ function studioDev(project) {
160
183
  "unlink"
161
184
  ]) server.watcher.on(event, onFile);
162
185
  let refresh;
186
+ const reloadGlob = (id) => {
187
+ const glob = server.moduleGraph.getModuleById(id);
188
+ if (glob && importedByPage(glob)) server.reloadModule(glob);
189
+ };
163
190
  const onPicture = (file) => {
164
- if (!isAvatar(file)) return;
165
- const files = server.moduleGraph.getModuleById(REGISTRY_FILES_MODULE);
166
- if (files) server.reloadModule(files);
191
+ if (isAvatar(file)) reloadGlob(REGISTRY_FILES_MODULE);
167
192
  };
168
193
  server.watcher.on("add", onPicture);
169
194
  server.watcher.on("unlink", onPicture);
@@ -172,10 +197,7 @@ function studioDev(project) {
172
197
  if (!(file.startsWith(prototypes + sep) && CONTENT_FILE_RE.test(file)) || kind === "comments" || kind === "annotations") return;
173
198
  clearTimeout(refresh);
174
199
  refresh = setTimeout(() => {
175
- for (const id of CONTENT_GLOBS) {
176
- const files = server.moduleGraph.getModuleById(id);
177
- if (files) server.reloadModule(files);
178
- }
200
+ for (const id of CONTENT_GLOBS) reloadGlob(id);
179
201
  }, SETTLE_MS);
180
202
  };
181
203
  server.watcher.on("add", onAddOrRemove);
@@ -0,0 +1,15 @@
1
+ import { ExportChoice } from "../../shared/export-core.mjs";
2
+ import { StudioProject } from "../vite.mjs";
3
+ //#region src/server/export/build.d.ts
4
+ export interface ExportResult {
5
+ /** The zip, as its file would hold it. */
6
+ bytes: Buffer;
7
+ /** What the zip is called: the file's title. */
8
+ name: string;
9
+ }
10
+ /**
11
+ * Export frames of a file, as `choice` says. Throws, saying why, when the
12
+ * choice names frames the file does not have or nothing that shows a view.
13
+ */
14
+ export declare function exportPrototype(project: StudioProject, slug: string, choice: ExportChoice): Promise<ExportResult>;
15
+ //#endregion