@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
@@ -9,12 +9,12 @@
9
9
  import { randomUUID } from "node:crypto";
10
10
  import { readdir, readFile, writeFile } from "node:fs/promises";
11
11
  import { join, relative } from "node:path";
12
+ import { CODE_PROPS, isCodeProp, words } from "./element-words.ts";
12
13
  import { parseJsx } from "./jsx-source.ts";
13
14
 
14
15
  const SOURCE_RE = /\.(?:tsx|ts|jsx|js)$/;
15
16
  const SKIPPED = new Set(["comments", "docs", "node_modules"]);
16
17
  const JSX_UNSAFE_RE = /[{}<>]/;
17
- const SPACES_RE = /\s+/g;
18
18
  const REGEX_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
19
19
  const MAX_LENGTH = 2000;
20
20
  /** How many replacements can still be put back, newest kept. */
@@ -32,27 +32,6 @@ const CODE_CALLS = new Set([
32
32
  "twMerge",
33
33
  ]);
34
34
 
35
- /** Props whose strings say how something looks or works, not what it says. */
36
- const CODE_PROPS = new Set([
37
- "as",
38
- "className",
39
- "class",
40
- "href",
41
- "htmlFor",
42
- "icon",
43
- "id",
44
- "key",
45
- "name",
46
- "rel",
47
- "role",
48
- "size",
49
- "src",
50
- "style",
51
- "target",
52
- "type",
53
- "variant",
54
- ]);
55
-
56
35
  const COMPARISONS = new Set(["==", "===", "!=", "!=="]);
57
36
 
58
37
  /** One file as it was before a replacement and after it. */
@@ -103,8 +82,6 @@ async function sourceFiles(dir: string): Promise<string[]> {
103
82
  return files;
104
83
  }
105
84
 
106
- const words = (text: string) => text.replace(SPACES_RE, " ").trim();
107
-
108
85
  /** A node of Babel's tree, as far as the walk reads it. */
109
86
  interface Node {
110
87
  end?: number | null;
@@ -182,14 +159,8 @@ const isCode = (parent: Node, key: string): boolean => {
182
159
  return COMPARISONS.has(parent.operator as string);
183
160
  case "CallExpression":
184
161
  return CODE_CALLS.has(calleeName(parent) ?? "");
185
- case "JSXAttribute": {
186
- const name = propName(parent) ?? "";
187
- return (
188
- CODE_PROPS.has(name) ||
189
- name.startsWith("data-") ||
190
- name.startsWith("aria-")
191
- );
192
- }
162
+ case "JSXAttribute":
163
+ return isCodeProp(propName(parent) ?? "");
193
164
  default:
194
165
  return false;
195
166
  }
@@ -26,7 +26,6 @@ import {
26
26
  type AgentAction,
27
27
  agentChange,
28
28
  changeProblems,
29
- describeThread,
30
29
  type ListStatus,
31
30
  type NewThread,
32
31
  type PersonChange,
@@ -345,6 +344,7 @@ export function openThreads(
345
344
  for: audience,
346
345
  hidden,
347
346
  status,
347
+ target,
348
348
  }: PersonChange & { author: string }
349
349
  ): Promise<ThreadAnswer | undefined> =>
350
350
  change(id, {
@@ -358,11 +358,9 @@ export function openThreads(
358
358
  for: audience,
359
359
  hidden,
360
360
  status,
361
+ target,
361
362
  }),
362
363
 
363
- /** A thread as an agent should read it: what, where, and which file. */
364
- describe: describeThread,
365
-
366
364
  subscribe: feed.subscribe,
367
365
  };
368
366
  }
@@ -1,7 +1,7 @@
1
1
  // Tidying what a delete on the canvas leaves behind. A frame deleted from
2
2
  // the canvas leaves its view on disk (removed-views-core.ts); here a person
3
3
  // sees those views and moves their own to the trash, with the images only they
4
- // show. The trash is the studio's own state (.studio/trash/), on this
4
+ // show. The trash is the studio's own state (.local/trash/), on this
5
5
  // machine only: each tidy is one folder, named for when it happened, with
6
6
  // the files at their paths in the content folder, so copying one back is
7
7
  // all it takes. Nothing goes to the trash on its own, and anything there
@@ -61,6 +61,11 @@ export type Piece = "mcp" | "presence" | "instructions";
61
61
  interface PieceStatus {
62
62
  /** Whether anything of it is there, so nothing at all is "not set up". */
63
63
  found: boolean;
64
+ /**
65
+ * Whether it lacks only Dex's names: the studio wrote it under a name or
66
+ * command from before a rename, which adding renames and nothing else.
67
+ */
68
+ old?: boolean;
64
69
  piece: Piece;
65
70
  why?: string;
66
71
  }
@@ -81,6 +86,11 @@ export interface AgentSetup {
81
86
  launch?: AgentLaunch;
82
87
  manual: Manual;
83
88
  missing: { piece: Piece; why: string }[];
89
+ /**
90
+ * Whether all it lacks is Dex's names (a server or hook the studio wrote
91
+ * before a rename): `dex upgrade` adds it again, as the dialog does.
92
+ */
93
+ old: boolean;
84
94
  oneClick: boolean;
85
95
  status: SetupStatus;
86
96
  }
@@ -261,6 +271,11 @@ const lacking = (piece: Piece, why: string, found = false): PieceStatus => ({
261
271
  why,
262
272
  found,
263
273
  });
274
+ /** A piece the studio wrote under a name from before a rename. */
275
+ const named = (piece: Piece, why: string): PieceStatus => ({
276
+ ...lacking(piece, why, true),
277
+ old: true,
278
+ });
264
279
 
265
280
  /** An MCP server's command and arguments, as one list of words. */
266
281
  const words = (entry: unknown): string[] => {
@@ -334,6 +349,9 @@ const oldCommand = (server: readonly string[]): string | undefined => {
334
349
  }
335
350
  };
336
351
 
352
+ const isOldName = (name: string): boolean =>
353
+ (OLD_CHANNEL_SERVERS as readonly string[]).includes(name);
354
+
337
355
  /**
338
356
  * Why a server's command can't start, if it can't: a `dex` command at a
339
357
  * path, from where the agent starts, that isn't there. An install can move
@@ -423,7 +441,7 @@ export async function claudeChannelServer(
423
441
  renamedNotice(
424
442
  `the MCP server "${old}"`,
425
443
  `"${CHANNEL_SERVER}"`,
426
- "`npx dex doctor` says where it is; Connect in the studio renames it."
444
+ "`npx dex upgrade` renames it."
427
445
  );
428
446
  }
429
447
  return { found: true, name: old };
@@ -466,14 +484,27 @@ function serverPiece(
466
484
  place: Place
467
485
  ): PieceStatus {
468
486
  const studio = servers[CHANNEL_SERVER];
487
+ const copies = copiesOf(servers, place);
469
488
  if (studio) {
470
489
  if (servesHere(studio, place)) {
471
- const old = oldCommand(studio) ?? missingCommand(studio, place);
472
- return old
473
- ? lacking(
490
+ const old = oldCommand(studio);
491
+ if (old) {
492
+ return named("mcp", `the "${CHANNEL_SERVER}" server in ${file} ${old}`);
493
+ }
494
+ const moved = missingCommand(studio, place);
495
+ if (moved) {
496
+ return lacking(
497
+ "mcp",
498
+ `the "${CHANNEL_SERVER}" server in ${file} ${moved}`,
499
+ true
500
+ );
501
+ }
502
+ // A copy left under an old name lists the studio's tools twice.
503
+ const left = copies.find(isOldName);
504
+ return left
505
+ ? named(
474
506
  "mcp",
475
- `the "${CHANNEL_SERVER}" server in ${file} ${old}`,
476
- true
507
+ `the studio's server in ${file} is there as "${left}" too, its name from before`
477
508
  )
478
509
  : inPlace("mcp");
479
510
  }
@@ -488,14 +519,13 @@ function serverPiece(
488
519
  true
489
520
  );
490
521
  }
491
- const [other] = copiesOf(servers, place);
492
- return other
493
- ? lacking(
494
- "mcp",
495
- `the studio's server in ${file} is named "${other}", not "${CHANNEL_SERVER}"`,
496
- true
497
- )
498
- : lacking("mcp", `no "${CHANNEL_SERVER}" server in ${file}`);
522
+ const [other] = copies;
523
+ if (!other) {
524
+ return lacking("mcp", `no "${CHANNEL_SERVER}" server in ${file}`);
525
+ }
526
+ const why = `the studio's server in ${file} is named "${other}", not "${CHANNEL_SERVER}"`;
527
+ // Under a name of the person's own, renaming it is theirs to choose.
528
+ return isOldName(other) ? named("mcp", why) : lacking("mcp", why, true);
499
529
  }
500
530
 
501
531
  /** The servers in a JSON config, under `key`, by name. */
@@ -639,10 +669,9 @@ async function hookPieces(place: Place): Promise<PieceStatus[]> {
639
669
  .map((command) => OLD_HOOK_RE.exec(command)?.[1])
640
670
  .find(Boolean);
641
671
  if (old) {
642
- return lacking(
672
+ return named(
643
673
  piece,
644
- `the ${piece} hook in ${SETTINGS} ${runsOldCommand(old)}`,
645
- true
674
+ `the ${piece} hook in ${SETTINGS} ${runsOldCommand(old)}`
646
675
  );
647
676
  }
648
677
  const moved = events
@@ -1061,10 +1090,12 @@ export function agentSetups(
1061
1090
  const agent = AGENTS[id];
1062
1091
  const pieces = await agent.pieces(place);
1063
1092
  const status = statusOf(pieces);
1093
+ const missing = pieces.filter(({ why }) => why);
1064
1094
  return {
1065
1095
  id,
1066
1096
  status,
1067
1097
  configured: status === "set-up",
1098
+ old: missing.length > 0 && missing.every((piece) => piece.old),
1068
1099
  missing: pieces.flatMap(({ piece, why }) =>
1069
1100
  why ? [{ piece, why }] : []
1070
1101
  ),
@@ -0,0 +1,237 @@
1
+ // Teammates on the canvas, between the canvas in the browser and the live
2
+ // room. Each canvas sends where its person points and what they select over
3
+ // the dev server's own socket; `dex dev --live` shares it in the room and
4
+ // hands back everyone else's, which the dev server sends to every canvas
5
+ // open. Both ends run in the one `dex dev` process, so they meet here.
6
+ //
7
+ // On someone's own machine there is one person: you. Hosted for a workspace
8
+ // (content/hosted-person.ts) there are as many as have it open, each told
9
+ // apart by the person the preview host says each socket is from; each of
10
+ // them sees the room's teammates and everyone else in the browser.
11
+
12
+ import type { IncomingMessage } from "node:http";
13
+ import type { Plugin } from "vite";
14
+ import { isHosted, personFromHeader } from "../content/hosted-person.ts";
15
+ import {
16
+ CANVAS_HELLO_EVENT,
17
+ CANVAS_PRESENCE_EVENT,
18
+ CANVAS_TEAMMATES_EVENT,
19
+ type CanvasPresence,
20
+ type CanvasTeammate,
21
+ cleanCanvasPresence,
22
+ PERSON_HEADER,
23
+ type PresenceUser,
24
+ } from "../shared/live-presence.ts";
25
+
26
+ type Listener<T> = (value: T) => void;
27
+
28
+ /** Someone on a canvas here, and where: hosted, with who they are. */
29
+ interface CanvasPlace {
30
+ place: CanvasPresence;
31
+ user?: PresenceUser;
32
+ }
33
+
34
+ /** The one person of a Dex on someone's own machine. */
35
+ const YOU = "you";
36
+
37
+ interface Hub {
38
+ placeListeners: Set<() => void>;
39
+ places: Map<string, CanvasPlace>;
40
+ teammateListeners: Set<Listener<CanvasTeammate[]>>;
41
+ teammates: CanvasTeammate[];
42
+ }
43
+
44
+ // On globalThis, so the dev server and live sync share one hub even when the
45
+ // build puts them in different chunks.
46
+ const KEY = Symbol.for("dex.canvas-presence");
47
+
48
+ const hub = (): Hub => {
49
+ const holder = globalThis as unknown as Record<symbol, Hub | undefined>;
50
+ holder[KEY] ??= {
51
+ placeListeners: new Set(),
52
+ places: new Map(),
53
+ teammateListeners: new Set(),
54
+ teammates: [],
55
+ };
56
+ return holder[KEY];
57
+ };
58
+
59
+ const listen = <L>(listeners: Set<L>, listener: L) => {
60
+ listeners.add(listener);
61
+ return () => {
62
+ listeners.delete(listener);
63
+ };
64
+ };
65
+
66
+ /**
67
+ * Where someone here is on a canvas, or null when on none: you, on your own
68
+ * machine (no `who`), or a person in the browser, hosted.
69
+ */
70
+ function shareCanvasPlace(
71
+ place: CanvasPresence | null,
72
+ who?: { key: string; user: PresenceUser }
73
+ ): void {
74
+ const state = hub();
75
+ const key = who?.key ?? YOU;
76
+ if (place) {
77
+ state.places.set(key, { place, ...(who && { user: who.user }) });
78
+ } else {
79
+ state.places.delete(key);
80
+ }
81
+ for (const listener of state.placeListeners) {
82
+ listener();
83
+ }
84
+ }
85
+
86
+ /** Hear people here move: what live sync shares in the room. */
87
+ export const onCanvasPlaces = (listener: () => void) =>
88
+ listen(hub().placeListeners, listener);
89
+
90
+ /** What live sync shares in the room, now. */
91
+ export interface RoomCanvas {
92
+ /** Where you are, on your own machine; null when on no canvas, or hosted. */
93
+ canvas: CanvasPresence | null;
94
+ /** Hosted, everyone in the browser on a canvas, each as themselves. */
95
+ people: { canvas: CanvasPresence; user: PresenceUser }[];
96
+ }
97
+
98
+ /** Everyone here on a canvas, in the room's terms. */
99
+ export function roomCanvas(): RoomCanvas {
100
+ const room: RoomCanvas = { canvas: null, people: [] };
101
+ for (const [key, { place, user }] of hub().places) {
102
+ if (user) {
103
+ room.people.push({ canvas: place, user });
104
+ } else if (key === YOU) {
105
+ room.canvas = place;
106
+ }
107
+ }
108
+ return room;
109
+ }
110
+
111
+ /** Everyone in the room on a canvas, as the room says now. */
112
+ export function setCanvasTeammates(teammates: CanvasTeammate[]): void {
113
+ const state = hub();
114
+ state.teammates = teammates;
115
+ for (const listener of state.teammateListeners) {
116
+ listener(teammates);
117
+ }
118
+ }
119
+
120
+ /** Hear the room's teammates change. */
121
+ const onCanvasTeammates = (listener: Listener<CanvasTeammate[]>) =>
122
+ listen(hub().teammateListeners, listener);
123
+
124
+ /** Who a person here is, in the room's terms. */
125
+ const userOf = (person: {
126
+ color?: string;
127
+ id: string;
128
+ name: string;
129
+ }): PresenceUser => {
130
+ const color = person.color ?? "#3e63dd";
131
+ return { id: person.id, name: person.name, color, colorLight: `${color}33` };
132
+ };
133
+
134
+ /**
135
+ * Who a canvas sees: the room's teammates, and, hosted, everyone else here
136
+ * in the browser. `self` is the person whose canvas it is, when hosted.
137
+ */
138
+ function teammatesFor(self: string | undefined): CanvasTeammate[] {
139
+ const state = hub();
140
+ const here: CanvasTeammate[] = [];
141
+ for (const [key, { place, user }] of state.places) {
142
+ if (user && key !== self) {
143
+ here.push({ ...place, id: `here:${key}`, user });
144
+ }
145
+ }
146
+ const room = self
147
+ ? state.teammates.filter((teammate) => teammate.user.id !== self)
148
+ : state.teammates;
149
+ return here.length > 0 ? [...room, ...here] : room;
150
+ }
151
+
152
+ interface Socket {
153
+ once: (event: "close", run: () => void) => void;
154
+ }
155
+
156
+ /** The dev server's end: the canvas's socket messages, both ways. */
157
+ export const canvasPresence = (): Plugin => ({
158
+ name: "dex-canvas-presence",
159
+ configureServer(server) {
160
+ const hosted = isHosted();
161
+ /** Hosted: who each socket is from, as the preview host said. */
162
+ const people = new Map<unknown, { key: string; user: PresenceUser }>();
163
+ if (hosted) {
164
+ server.ws.on("connection", (socket: Socket, request: IncomingMessage) => {
165
+ const person = personFromHeader(request.headers[PERSON_HEADER]);
166
+ if (person) {
167
+ people.set(socket, { key: person.id, user: userOf(person) });
168
+ socket.once("close", () => people.delete(socket));
169
+ }
170
+ });
171
+ }
172
+
173
+ // On your own machine, the page that last moved: when it closes or
174
+ // reloads, you are off the canvas, whether or not it said so first.
175
+ // Hosted, each person by their own sockets.
176
+ let from: Socket | undefined;
177
+ const said = new WeakSet<Socket>();
178
+ /** Hosted, which of each person's tabs moved last: theirs is the place. */
179
+ const latest = new Map<string, Socket>();
180
+ server.ws.on(CANVAS_PRESENCE_EVENT, (data: unknown, client) => {
181
+ const place = cleanCanvasPresence(data) ?? null;
182
+ const socket = client.socket as unknown as Socket;
183
+ if (hosted) {
184
+ const who = people.get(socket);
185
+ if (!who) {
186
+ return;
187
+ }
188
+ shareCanvasPlace(place, who);
189
+ latest.set(who.key, socket);
190
+ if (!said.has(socket)) {
191
+ said.add(socket);
192
+ // Closing another of their tabs leaves them where they are.
193
+ socket.once("close", () => {
194
+ if (latest.get(who.key) === socket) {
195
+ latest.delete(who.key);
196
+ shareCanvasPlace(null, who);
197
+ }
198
+ });
199
+ }
200
+ return;
201
+ }
202
+ shareCanvasPlace(place);
203
+ if (socket !== from) {
204
+ from = socket;
205
+ socket.once("close", () => {
206
+ if (from === socket) {
207
+ from = undefined;
208
+ shareCanvasPlace(null);
209
+ }
210
+ });
211
+ }
212
+ });
213
+
214
+ /** Each canvas its own list: never itself among its teammates. */
215
+ const sendAll = () => {
216
+ if (!hosted) {
217
+ server.ws.send(CANVAS_TEAMMATES_EVENT, teammatesFor(undefined));
218
+ return;
219
+ }
220
+ for (const client of server.ws.clients) {
221
+ const who = people.get(client.socket);
222
+ client.send(CANVAS_TEAMMATES_EVENT, teammatesFor(who?.key));
223
+ }
224
+ };
225
+ server.ws.on(CANVAS_HELLO_EVENT, (_data: unknown, client) => {
226
+ const who = people.get(client.socket);
227
+ client.send(CANVAS_TEAMMATES_EVENT, teammatesFor(who?.key));
228
+ });
229
+ const stopRoom = onCanvasTeammates(sendAll);
230
+ // Hosted, people here see each other move without the room.
231
+ const stopHere = hosted ? onCanvasPlaces(sendAll) : () => undefined;
232
+ server.httpServer?.once("close", () => {
233
+ stopRoom();
234
+ stopHere();
235
+ });
236
+ },
237
+ });
@@ -18,7 +18,7 @@
18
18
  // its push only once that word has come back.
19
19
  //
20
20
  // Every MCP session also reports itself, whether or not it is a channel, in
21
- // .studio/agents/<pid>.json, so the canvas can show who is connected and
21
+ // .local/agents/<pid>.json, so the canvas can show who is connected and
22
22
  // whether feedback reaches them by itself.
23
23
 
24
24
  import { execFile } from "node:child_process";
@@ -90,7 +90,7 @@ export async function skillFolders(from: string): Promise<SkillFolders> {
90
90
  const project = await readConfig(from);
91
91
  const menu = project?.commands ?? {};
92
92
  return {
93
- team: teamSkillsIn(project?.root ?? from),
93
+ team: teamSkillsIn(project?.content ?? from, project?.root ?? from),
94
94
  codebase:
95
95
  project && switchOn(menu, "codebase")
96
96
  ? codebaseSkills(project.root).folders
@@ -212,25 +212,6 @@ export async function changeComment(
212
212
  : { value: changed.thread };
213
213
  }
214
214
 
215
- /** A person's reply: a closed comment opens again with it. */
216
- export const replyToComment = (
217
- context: PersonComments,
218
- id: string,
219
- body: string
220
- ) => changeComment(context, id, { body });
221
-
222
- /** A person resolves a comment. */
223
- export const resolveComment = (context: PersonComments, id: string) =>
224
- changeComment(context, id, { status: "resolved" });
225
-
226
- /** A person dismisses a comment: how one is deleted. */
227
- export const dismissComment = (context: PersonComments, id: string) =>
228
- changeComment(context, id, { status: "dismissed" });
229
-
230
- /** A person opens a closed comment again. */
231
- export const reopenComment = (context: PersonComments, id: string) =>
232
- changeComment(context, id, { status: "open" });
233
-
234
215
  /**
235
216
  * An agent starts on a comment (its 👀): claimed for its session, the
236
217
  * comment is that session's alone until it closes, asks or lets it go.
@@ -14,16 +14,12 @@ import {
14
14
  } from "../../shared/comments/routes.ts";
15
15
  import type { ThreadWithPrototype } from "../../shared/threads-core.ts";
16
16
  import { type Outcome, type ProblemKind, refused } from "../outcome.ts";
17
+ import { Problems } from "../problems.ts";
17
18
  import {
18
19
  changeComment,
19
20
  commentsOn,
20
- dismissComment,
21
21
  findPrototype,
22
22
  listComments,
23
- type PersonComments,
24
- reopenComment,
25
- replyToComment,
26
- resolveComment,
27
23
  startComment,
28
24
  } from "./actions.ts";
29
25
 
@@ -41,18 +37,6 @@ const STATUS: Record<ProblemKind, number> = {
41
37
  /** A request that names no file, or whose body is not as its schema says. */
42
38
  const BAD_REQUEST = 400;
43
39
 
44
- /** A refusal, as the request handler (requests.ts) sends one. */
45
- class Refusal extends Error {
46
- readonly problems: string[];
47
- readonly status: number;
48
-
49
- constructor(status: number, problems: string[]) {
50
- super(problems.join(" "));
51
- this.status = status;
52
- this.problems = problems;
53
- }
54
- }
55
-
56
40
  /** What a comment request is given: requests.ts's route context has it. */
57
41
  interface CommentRequest {
58
42
  body: unknown;
@@ -64,7 +48,7 @@ interface CommentRequest {
64
48
  /** What an action did, or its problem refused with the status for its kind. */
65
49
  const answer = <T>(outcome: Outcome<T>): T => {
66
50
  if (outcome.problem) {
67
- throw new Refusal(STATUS[outcome.problem.kind], outcome.problem.messages);
51
+ throw new Problems(STATUS[outcome.problem.kind], outcome.problem.messages);
68
52
  }
69
53
  return outcome.value;
70
54
  };
@@ -72,7 +56,7 @@ const answer = <T>(outcome: Outcome<T>): T => {
72
56
  /** What the request asks for, or a 400 saying what is wrong with it. */
73
57
  const asked = <T>(outcome: Outcome<T>): T => {
74
58
  if (outcome.problem) {
75
- throw new Refusal(BAD_REQUEST, outcome.problem.messages);
59
+ throw new Problems(BAD_REQUEST, outcome.problem.messages);
76
60
  }
77
61
  return outcome.value;
78
62
  };
@@ -101,35 +85,6 @@ const listThreads = ({ project, threads, url }: CommentRequest) =>
101
85
  : undefined
102
86
  );
103
87
 
104
- /** The person's actions that a change of one status alone is. */
105
- const BY_STATUS = new Map<
106
- string,
107
- (context: PersonComments, id: string) => Promise<Outcome<ThreadWithPrototype>>
108
- >([
109
- ["resolved", resolveComment],
110
- ["dismissed", dismissComment],
111
- ["open", reopenComment],
112
- ]);
113
-
114
- /**
115
- * A person's change, as the action it asks for: a reply alone, or a status
116
- * alone, is its own; anything else, or several at once, is one change.
117
- */
118
- const changeAsked = (
119
- context: PersonComments,
120
- { id, ...change }: z.output<typeof COMMENT_CHANGE>
121
- ): Promise<Outcome<ThreadWithPrototype>> => {
122
- const fields = Object.keys(change);
123
- if (fields.length === 1 && change.body !== undefined) {
124
- return replyToComment(context, id, change.body);
125
- }
126
- const status =
127
- fields.length === 1 && change.status !== undefined
128
- ? BY_STATUS.get(change.status)
129
- : undefined;
130
- return status ? status(context, id) : changeComment(context, id, change);
131
- };
132
-
133
88
  /** Start a comment, or change one by its id, as the person using Dex. */
134
89
  async function postThread({
135
90
  body,
@@ -138,7 +93,7 @@ async function postThread({
138
93
  url,
139
94
  }: CommentRequest): Promise<ThreadWithPrototype> {
140
95
  if (!body) {
141
- throw new Refusal(BAD_REQUEST, [
96
+ throw new Problems(BAD_REQUEST, [
142
97
  "Send a thread to start, or a change to one.",
143
98
  ]);
144
99
  }
@@ -155,11 +110,11 @@ async function postThread({
155
110
  { prototype: slugOf(url), by: { kind: "person" } }
156
111
  )
157
112
  );
158
- return answer(
159
- "id" in sent
160
- ? await changeAsked(context, sent)
161
- : await startComment(context, sent)
162
- );
113
+ if ("id" in sent) {
114
+ const { id, ...change } = sent;
115
+ return answer(await changeComment(context, id, change));
116
+ }
117
+ return answer(await startComment(context, sent));
163
118
  }
164
119
 
165
120
  /**