@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
@@ -148,16 +148,19 @@ const AGENT_NAMES = new Map(Object.entries(AGENTS).map(([id, agent]) => [id, age
148
148
  * Each agent's setup, as the studio's "Connect your agent" dialog shows it:
149
149
  * agent setup decides what counts, so the two always agree. Agents the
150
150
  * studio cannot add itself to have no config it can read, so are left out.
151
+ * One that lacks only Dex's names is upgrade's (migrate/setup-files.ts),
152
+ * which says so. Returns the setups it checked.
151
153
  */
152
154
  async function checkAgentSetups(root, content, { ok, note, warn }, agentRoot = root) {
153
155
  const setups = (await agentSetups(root, content, agentRoot)).filter((setup) => setup.oneClick);
154
- for (const { id, status, missing } of setups) {
156
+ for (const { id, status, missing, old } of setups) {
155
157
  const name = AGENT_NAMES.get(id) ?? id;
156
158
  if (status === "set-up") ok(`${name} is set up`);
157
- else if (status === "partly") warn(`${name} is not fully set up: ${[...new Set(missing.map((piece) => piece.why))].join("; ")}`, `To fix it, ${connectInStudio(name)}.`);
158
- else note(`${name} is not set up`);
159
+ else if (status === "partly" && !old) warn(`${name} is not fully set up: ${[...new Set(missing.map((piece) => piece.why))].join("; ")}`, `To fix it, ${connectInStudio(name)}.`);
160
+ else if (status === "not-set-up") note(`${name} is not set up`);
159
161
  }
160
162
  if (setups.every((setup) => setup.status === "not-set-up")) warn("Agents cannot read comments from the studio", `To connect one, ${connectInStudio()}.`);
163
+ return setups;
161
164
  }
162
165
  /**
163
166
  * The `studio` command Claude Code's hooks run, there once it is installed,
@@ -221,8 +224,7 @@ async function runChecks(cwd, log, probes) {
221
224
  else log.warn("No Playwright browser for `dex snapshot`", `Run \`${INSTALL_BROWSER}\`.`);
222
225
  const agentRoot = agentRootOf(project.root);
223
226
  if (agentRoot !== project.root) log.note(`Agents start at ${agentRoot}, where their configs are`);
224
- await checkAgentSetups(project.root, content, log, agentRoot);
225
- await checkHookCommand(project.root, agentRoot, log);
227
+ if (!(await checkAgentSetups(project.root, content, log, agentRoot)).some(({ id, old }) => id === "claude" && old)) await checkHookCommand(project.root, agentRoot, log);
226
228
  await checkMigrations(project, log);
227
229
  const problems = await check(content).catch((error) => [error.message]);
228
230
  if (problems.length === 0) log.ok("Content check passed");
@@ -0,0 +1,61 @@
1
+ import { StudioProject } from "../../config/load.mjs";
2
+ import { Migration } from "./migration.mjs";
3
+ //#region src/setup/migrate/dex-folder.d.ts
4
+ /** Where a project's Dex folder is, and where it goes. */
5
+ export interface DexFolderPlace {
6
+ /** Where agents start, and their configs are (server/agents.ts). */
7
+ agentRoot: string;
8
+ /** The Dex folder as the config names it now. */
9
+ content: string;
10
+ /** The config file. */
11
+ file: string;
12
+ /** Where the Dex folder goes: `dex/`, or where it is when it keeps its name. */
13
+ folder: string;
14
+ /** The folder before, when it is another one: `studio/`, still to move or left behind. */
15
+ old?: string;
16
+ /** The project, which holds the config. */
17
+ root: string;
18
+ }
19
+ /** Where the folder goes, from where the config says it is. */
20
+ export declare function dexFolderPlace({ root, content, file }: Pick<StudioProject, "content" | "file" | "root">): DexFolderPlace;
21
+ /**
22
+ * Move `from` to `to`, or into it when it is there: what `to` has already
23
+ * stays, and the rest joins it. A link that moved, pointing at something by
24
+ * a relative path (as skill installers link skills in), still points at it.
25
+ */
26
+ export declare function moveInto(from: string, to: string): Promise<void>;
27
+ /** Said above the old state line upgrade keeps. */
28
+ export declare const KEPT_STATE_COMMENT = "# Where Dex kept this machine's state before .local/: an older Dex still running may write there.";
29
+ /**
30
+ * A .gitignore's lines with the old folder's moved to the new one, and the
31
+ * state's line (`dex/.local/`) added where the old one (`studio/.studio/`)
32
+ * is. The old line stays, under a comment: a Dex from before still running
33
+ * (the one whose Update ran upgrade, which then commits every change) writes
34
+ * there until it restarts, and a teammate's pull leaves it there, so it is
35
+ * never committed. `from` and `to` are the folder before and after, from
36
+ * the .gitignore's own folder ("." in it).
37
+ */
38
+ export declare function movedIgnore(text: string, from: string, to: string): string;
39
+ /**
40
+ * `text` with a `--root` that names `from` naming `to`: as a server's
41
+ * arguments have it ("--root", "studio"), or a command
42
+ * (--root \"$CLAUDE_PROJECT_DIR/studio\", --root studio, --root=./studio).
43
+ */
44
+ export declare function movedRoot(text: string, from: string, to: string): string;
45
+ /** A script with what names `from` naming `to`: `--root`, `cd`, and paths in it. */
46
+ export declare function movedScript(script: string, from: string, to: string): string;
47
+ /**
48
+ * A root guide's pointer at the Dex folder ("Dex files live in studio/."),
49
+ * as this version and older ones wrote it, naming `to` for `from`.
50
+ */
51
+ export declare function movedPointer(text: string, from: string, to: string): string;
52
+ /**
53
+ * The config with its paths into the old folder pointing into the new one:
54
+ * `content: "./studio"`, and any "./studio/…" (a guide, a stylesheet). A
55
+ * plain "studio" is changed only as `content`, as `ui.theme` takes
56
+ * "studio" too.
57
+ */
58
+ export declare function movedConfig(source: string, oldPath: string, newPath: string): string;
59
+ /** studio/ moves to dex/, its state to .local/, and the team's skills into it. */
60
+ export declare const dexFolderMigration: Migration;
61
+ //#endregion
@@ -0,0 +1,544 @@
1
+ import { posix as posix$1 } from "../../paths.mjs";
2
+ import { OLD_STATE_FOLDER, STATE_FOLDER, prepareState, stateIgnoreLine } from "../../server/state.mjs";
3
+ import { UPGRADE_COMMAND } from "./migration.mjs";
4
+ import { OLD_DEX_FOLDER, STUDIO_FILES } from "../../shared/studio-files.mjs";
5
+ import { listing } from "../../shared/listing.mjs";
6
+ import { OLD_TEAM_SKILLS } from "../../content/commands.mjs";
7
+ import { ConfigNotEditable, configData } from "../config-source.mjs";
8
+ import { agentRootOf } from "../../server/agents.mjs";
9
+ import { AGENT_FILES } from "../plan.mjs";
10
+ import { editManifest } from "../apply.mjs";
11
+ import { existsSync } from "node:fs";
12
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
13
+ import { cp, lstat, readFile, readdir, readlink, rename, rm, symlink, unlink, writeFile } from "node:fs/promises";
14
+ //#region src/setup/migrate/dex-folder.ts
15
+ /** Both names the state has had, which a folder of Dex's may hold. */
16
+ const STATE_FOLDERS = [OLD_STATE_FOLDER, STATE_FOLDER];
17
+ /** Where the folder goes, from where the config says it is. */
18
+ function dexFolderPlace({ root, content, file }) {
19
+ const place = {
20
+ root,
21
+ content,
22
+ file,
23
+ agentRoot: agentRootOf(root)
24
+ };
25
+ if (resolve(content) === resolve(root)) return {
26
+ ...place,
27
+ folder: content
28
+ };
29
+ if (basename(content) === "studio") return {
30
+ ...place,
31
+ old: content,
32
+ folder: join(dirname(content), "dex")
33
+ };
34
+ const left = join(dirname(content), OLD_DEX_FOLDER);
35
+ const holdsState = STATE_FOLDERS.some((name) => existsSync(join(left, name)));
36
+ return basename(content) === "dex" && holdsState ? {
37
+ ...place,
38
+ old: left,
39
+ folder: content
40
+ } : {
41
+ ...place,
42
+ folder: content
43
+ };
44
+ }
45
+ const REGEXP_SPECIAL_RE = /[.*+?^${}()|[\]\\]/g;
46
+ const NEWLINE_RE = /\r?\n/;
47
+ /** A .gitignore line: a negation or anchor, its path, and spaces after. */
48
+ const IGNORE_LINE_RE = /^(\s*!?\/?)(.*?)(\s*)$/;
49
+ const CONTENT_KEY_RE = /\bcontent\s*:\s*$/;
50
+ const escaped = (text) => text.replace(REGEXP_SPECIAL_RE, "\\$&");
51
+ const readIfThere = async (file) => existsSync(file) ? await readFile(file, "utf8") : void 0;
52
+ /** Files that say nothing: what a Mac leaves in a folder. */
53
+ const NOTHING = /* @__PURE__ */ new Set([".DS_Store"]);
54
+ /** Whether `dir` holds any file but `skip` at its top and what says nothing. */
55
+ async function holdsFiles(dir, skip = []) {
56
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
57
+ for (const entry of entries) {
58
+ if (skip.includes(entry.name) || NOTHING.has(entry.name)) continue;
59
+ if (!entry.isDirectory() || await holdsFiles(join(dir, entry.name))) return true;
60
+ }
61
+ return false;
62
+ }
63
+ /** What a folder of Dex's has, any one of which says it is one. */
64
+ const DEX_MARKS = [
65
+ "files",
66
+ STUDIO_FILES.instructions,
67
+ STUDIO_FILES.contributors,
68
+ ...STATE_FOLDERS
69
+ ];
70
+ const looksLikeDexFolder = (dir) => DEX_MARKS.some((name) => existsSync(join(dir, name)));
71
+ /** The links at the top of `dir` that point by a relative path: name → target. */
72
+ async function relativeLinks(dir) {
73
+ const links = /* @__PURE__ */ new Map();
74
+ for (const name of await readdir(dir).catch(() => [])) {
75
+ const path = join(dir, name);
76
+ if (!(await lstat(path)).isSymbolicLink()) continue;
77
+ const link = await readlink(path);
78
+ if (!isAbsolute(link)) links.set(name, resolve(dir, link));
79
+ }
80
+ return links;
81
+ }
82
+ /**
83
+ * Move `from` to `to`, or into it when it is there: what `to` has already
84
+ * stays, and the rest joins it. A link that moved, pointing at something by
85
+ * a relative path (as skill installers link skills in), still points at it.
86
+ */
87
+ async function moveInto(from, to) {
88
+ const links = await relativeLinks(from);
89
+ const kept = new Set(await readdir(to).catch(() => []));
90
+ if (existsSync(to)) {
91
+ await cp(from, to, {
92
+ recursive: true,
93
+ force: false,
94
+ errorOnExist: false,
95
+ verbatimSymlinks: true
96
+ });
97
+ await rm(from, {
98
+ recursive: true,
99
+ force: true
100
+ });
101
+ } else await rename(from, to);
102
+ for (const [name, target] of links) {
103
+ const landed = join(to, name);
104
+ const pointing = relative(dirname(landed), target);
105
+ if (!kept.has(name) && await readlink(landed) !== pointing) {
106
+ await unlink(landed);
107
+ await symlink(pointing, landed);
108
+ }
109
+ }
110
+ }
111
+ /** Remove `dir` when nothing in it says anything. */
112
+ async function removeIfEmpty(dir) {
113
+ if (existsSync(dir) && !await holdsFiles(dir)) await rm(dir, {
114
+ recursive: true,
115
+ force: true
116
+ });
117
+ }
118
+ /** The whole folder, or why it can't move. */
119
+ async function folderChanges(plan, file) {
120
+ const { content, folder, old, moves, shown } = plan;
121
+ if (old === void 0 || old !== content) return [];
122
+ const oldThere = existsSync(old);
123
+ const taken = existsSync(folder);
124
+ if (oldThere && taken && await holdsFiles(old, STATE_FOLDERS)) return [{
125
+ kind: "stop",
126
+ does: `move ${shown(old)}/ to ${shown(folder)}/: ${shown(folder)}/ is there already, and upgrade never writes over it`,
127
+ detail: `Keep one of them: move what you want from ${shown(old)}/ into ${shown(folder)}/ and delete ${shown(old)}/, or rename ${shown(folder)}/. Then run ${UPGRADE_COMMAND} again.`,
128
+ path: old
129
+ }];
130
+ if (!oldThere && taken && !looksLikeDexFolder(folder)) return [{
131
+ kind: "stop",
132
+ does: `point the config at ${shown(folder)}/: it is there already, and isn't a Dex folder`,
133
+ detail: `Rename ${shown(folder)}/, or set content in ${basename(file)} to where Dex's files are. Then run ${UPGRADE_COMMAND} again.`,
134
+ path: folder
135
+ }];
136
+ return moves ? [{
137
+ kind: "change",
138
+ does: `move ${shown(old)}/ to ${shown(folder)}/`,
139
+ path: old,
140
+ apply: () => rename(old, folder)
141
+ }] : [];
142
+ }
143
+ /** The state, `.studio/` in the folder, as `.local/`; and any left behind. */
144
+ async function stateChanges(plan) {
145
+ const { folder, old, moves, now, shown } = plan;
146
+ const state = join(folder, STATE_FOLDER);
147
+ const changes = [];
148
+ if (existsSync(now(".studio"))) {
149
+ const joins = existsSync(now(STATE_FOLDER));
150
+ changes.push({
151
+ kind: "change",
152
+ does: `move ${shown(now(OLD_STATE_FOLDER))}/ ${joins ? "into" : "to"} ${shown(state)}/${joins ? " (keeping what is there)" : ""}`,
153
+ path: now(OLD_STATE_FOLDER),
154
+ apply: async () => {
155
+ await moveInto(join(folder, OLD_STATE_FOLDER), state);
156
+ await prepareState(folder);
157
+ }
158
+ });
159
+ }
160
+ if (old === void 0 || moves || !existsSync(old)) return changes;
161
+ for (const name of STATE_FOLDERS) {
162
+ const left = join(old, name);
163
+ if (existsSync(left)) changes.push({
164
+ kind: "change",
165
+ does: `move ${shown(left)}/ into ${shown(state)}/ (keeping what is there)`,
166
+ path: left,
167
+ apply: async () => {
168
+ await moveInto(left, state);
169
+ await prepareState(folder);
170
+ }
171
+ });
172
+ }
173
+ if (await holdsFiles(old, STATE_FOLDERS)) changes.push({
174
+ kind: "keep",
175
+ does: `${shown(old)}/ still holds files Dex no longer reads`,
176
+ detail: `Move what you want to keep into ${shown(folder)}/, then delete ${shown(old)}/.`,
177
+ path: old
178
+ });
179
+ else changes.push({
180
+ kind: "change",
181
+ does: `delete ${shown(old)}/, empty once its state moved`,
182
+ path: old,
183
+ apply: () => removeIfEmpty(old)
184
+ });
185
+ return changes;
186
+ }
187
+ /** The team's skills: `.dex/skills/` at the root, as `skills/` in the folder. */
188
+ function skillsChanges({ folder, now, root, shown }) {
189
+ const skills = OLD_TEAM_SKILLS.map((name) => join(root, name)).find((path) => existsSync(path));
190
+ if (!skills) return [];
191
+ const target = join(folder, STUDIO_FILES.skills);
192
+ const joins = existsSync(now(STUDIO_FILES.skills));
193
+ return [{
194
+ kind: "change",
195
+ does: `move ${shown(skills)}/ ${joins ? "into" : "to"} ${shown(target)}/${joins ? " (keeping the skills there)" : ""}`,
196
+ path: skills,
197
+ apply: async () => {
198
+ await moveInto(skills, target);
199
+ await removeIfEmpty(dirname(skills));
200
+ }
201
+ }];
202
+ }
203
+ /** Said above the old state line upgrade keeps. */
204
+ const KEPT_STATE_COMMENT = "# Where Dex kept this machine's state before .local/: an older Dex still running may write there.";
205
+ /**
206
+ * A .gitignore's lines with the old folder's moved to the new one, and the
207
+ * state's line (`dex/.local/`) added where the old one (`studio/.studio/`)
208
+ * is. The old line stays, under a comment: a Dex from before still running
209
+ * (the one whose Update ran upgrade, which then commits every change) writes
210
+ * there until it restarts, and a teammate's pull leaves it there, so it is
211
+ * never committed. `from` and `to` are the folder before and after, from
212
+ * the .gitignore's own folder ("." in it).
213
+ */
214
+ function movedIgnore(text, from, to) {
215
+ const prefix = (folder) => folder === "." ? "" : `${folder}/`;
216
+ const state = stateIgnoreLine(to);
217
+ const oldStates = new Set([prefix(from), prefix(to)].flatMap((at) => [`${at}${OLD_STATE_FOLDER}`, `${at}${OLD_STATE_FOLDER}/`]));
218
+ const moves = from !== to && from !== ".";
219
+ const movedPath = (path) => moves && path.startsWith(prefix(from)) ? `${prefix(to)}${path.slice(prefix(from).length)}` : path;
220
+ const lines = text.split(NEWLINE_RE).map((line) => {
221
+ const [, head = "", path = "", tail = ""] = IGNORE_LINE_RE.exec(line) ?? [];
222
+ return {
223
+ line,
224
+ head,
225
+ path,
226
+ tail
227
+ };
228
+ });
229
+ const isState = (path) => movedPath(path) === state;
230
+ let placed = lines.some(({ path }) => isState(path));
231
+ const kept = [];
232
+ for (const { line, head, path, tail } of lines) if (!path || path.startsWith("#")) kept.push(line);
233
+ else if (oldStates.has(path)) {
234
+ if (!placed) {
235
+ kept.push(`${head}${state}${tail}`, KEPT_STATE_COMMENT);
236
+ placed = true;
237
+ }
238
+ kept.push(line);
239
+ } else if (!(isState(path) && kept.some((each) => each.trim() === state))) kept.push(`${head}${movedPath(path)}${tail}`);
240
+ return kept.join(text.includes("\r\n") ? "\r\n" : "\n");
241
+ }
242
+ /** Every folder from `dir` up to `top`, nearest first (`dir` alone outside it). */
243
+ function foldersUpTo(dir, top) {
244
+ const folders = [resolve(dir)];
245
+ if (relative(top, dir).startsWith("..")) return folders;
246
+ for (let up = folders[0]; up !== resolve(top) && dirname(up) !== up;) {
247
+ up = dirname(up);
248
+ folders.push(up);
249
+ }
250
+ return folders;
251
+ }
252
+ /** The .gitignore files that name the old folder or the state's old name. */
253
+ async function ignoreChanges(plan) {
254
+ const { agentRoot, folder, old, root, now, shown } = plan;
255
+ const dirs = /* @__PURE__ */ new Set([
256
+ folder,
257
+ ...foldersUpTo(dirname(folder), agentRoot),
258
+ resolve(root)
259
+ ]);
260
+ const changes = [];
261
+ for (const dir of dirs) {
262
+ const inFolder = dir === folder;
263
+ const path = inFolder ? now(".gitignore") : join(dir, ".gitignore");
264
+ const text = await readIfThere(path);
265
+ const from = inFolder ? "." : posix$1(relative(dir, old ?? folder));
266
+ const to = inFolder ? "." : posix$1(relative(dir, folder));
267
+ const updated = text === void 0 ? text : movedIgnore(text, from, to);
268
+ if (updated !== void 0 && updated !== text) {
269
+ const target = join(dir, ".gitignore");
270
+ changes.push({
271
+ kind: "change",
272
+ does: `ignore ${stateIgnoreLine(to)} in ${shown(target)}${from === to ? "" : `, and ${to}/ where it said ${from}/`}`,
273
+ path,
274
+ apply: () => writeFile(target, updated)
275
+ });
276
+ }
277
+ }
278
+ return changes;
279
+ }
280
+ const TSCONFIG_STATE_RE = new RegExp(`(["'])(\\./)?${escaped(OLD_STATE_FOLDER)}(/[^"']*)?\\1`, "g");
281
+ /** The folder's tsconfig, which leaves the state out of type checks. */
282
+ async function tsconfigChanges({ folder, now, shown }) {
283
+ const path = now("tsconfig.json");
284
+ const text = await readIfThere(path);
285
+ const updated = text?.replace(TSCONFIG_STATE_RE, (_match, quote, dot = "", rest = "") => `${quote}${dot}${STATE_FOLDER}${rest}${quote}`);
286
+ if (updated === void 0 || updated === text) return [];
287
+ const target = join(folder, "tsconfig.json");
288
+ return [{
289
+ kind: "change",
290
+ does: `exclude ${STATE_FOLDER} in ${shown(target)}, not ${OLD_STATE_FOLDER}`,
291
+ path,
292
+ apply: () => writeFile(target, updated)
293
+ }];
294
+ }
295
+ /**
296
+ * `text` with a `--root` that names `from` naming `to`: as a server's
297
+ * arguments have it ("--root", "studio"), or a command
298
+ * (--root \"$CLAUDE_PROJECT_DIR/studio\", --root studio, --root=./studio).
299
+ */
300
+ function movedRoot(text, from, to) {
301
+ const root = new RegExp(`(--root(?:\\\\?["'])?(?:\\s*,\\s*|\\s+|=)(?:\\\\?["'])?(?:\\$CLAUDE_PROJECT_DIR/)?(?:\\./)?)${escaped(from)}(?=\\\\?["']|[\\s,\\]]|$)`, "g");
302
+ return text.replace(root, (_match, head) => `${head}${to}`);
303
+ }
304
+ /** A script with what names `from` naming `to`: `--root`, `cd`, and paths in it. */
305
+ function movedScript(script, from, to) {
306
+ const cd = new RegExp(`(\\bcd\\s+(?:\\./)?)${escaped(from)}(?=/|\\s|$|[&;|])`, "g");
307
+ const path = new RegExp(`(^|[\\s"'=])(\\./)?${escaped(from)}/`, "g");
308
+ return movedRoot(script, from, to).replace(cd, (_match, head) => `${head}${to}`).replace(path, (_match, head, dot = "") => `${head}${dot}${to}/`);
309
+ }
310
+ /** The guides at the agent root that setup points at the Dex folder. */
311
+ const ROOT_GUIDES = ["AGENTS.md", "CLAUDE.md"];
312
+ /**
313
+ * A root guide's pointer at the Dex folder ("Dex files live in studio/."),
314
+ * as this version and older ones wrote it, naming `to` for `from`.
315
+ */
316
+ function movedPointer(text, from, to) {
317
+ const place = new RegExp(`((?:Dex files live in|Sudio files live in|Prototyping happens in) )${escaped(from)}(?=/\\.)|(Read )${escaped(from)}(?=/AGENTS\\.md)`, "g");
318
+ return text.replace(place, (_match, sentence, read) => `${sentence ?? read ?? ""}${to}`);
319
+ }
320
+ /** Whether the config still names the old folder, so what names it moves. */
321
+ const stillNamed = ({ content, folder, old }) => old !== void 0 && old !== folder && old === content;
322
+ /**
323
+ * Where agents' configs and the root guide may be: the agent root, and the
324
+ * project itself, which keeps its own when it was set up before agents'
325
+ * configs moved to the workspace's root.
326
+ */
327
+ const agentFolders = ({ agentRoot, root }) => [.../* @__PURE__ */ new Set([resolve(agentRoot), resolve(root)])];
328
+ /** The agent configs that start Dex at the old folder. */
329
+ async function agentChanges(plan) {
330
+ const { folder, old, shown } = plan;
331
+ if (!stillNamed(plan) || old === void 0) return [];
332
+ const changes = [];
333
+ for (const dir of agentFolders(plan)) {
334
+ const from = posix$1(relative(dir, old));
335
+ const to = posix$1(relative(dir, folder));
336
+ for (const name of new Set(Object.values(AGENT_FILES).flat())) {
337
+ const path = join(dir, name);
338
+ const text = await readIfThere(path);
339
+ const updated = text === void 0 ? text : movedRoot(movedRoot(text, from, to), old, folder);
340
+ if (updated !== void 0 && updated !== text) changes.push({
341
+ kind: "change",
342
+ does: `start Dex at ${to} in ${shown(path)}`,
343
+ path,
344
+ apply: () => writeFile(path, updated)
345
+ });
346
+ }
347
+ }
348
+ return changes;
349
+ }
350
+ /** The root guides whose pointer names the old folder. */
351
+ async function guideChanges(plan) {
352
+ const { folder, old, shown } = plan;
353
+ if (!stillNamed(plan) || old === void 0) return [];
354
+ const changes = [];
355
+ for (const dir of agentFolders(plan)) {
356
+ const from = posix$1(relative(dir, old));
357
+ const to = posix$1(relative(dir, folder));
358
+ for (const name of ROOT_GUIDES) {
359
+ const path = join(dir, name);
360
+ const text = await readIfThere(path);
361
+ const updated = text === void 0 ? text : movedPointer(text, from, to);
362
+ if (updated !== void 0 && updated !== text) changes.push({
363
+ kind: "change",
364
+ does: `point ${shown(path)} at ${to}/`,
365
+ path,
366
+ apply: () => writeFile(path, updated)
367
+ });
368
+ }
369
+ }
370
+ return changes;
371
+ }
372
+ /** The scripts in `dir`'s package.json that would name the old folder. */
373
+ async function scriptsIn(dir, old, folder) {
374
+ let scripts = {};
375
+ try {
376
+ const text = await readIfThere(join(dir, "package.json"));
377
+ scripts = JSON.parse(text ?? "{}").scripts ?? {};
378
+ } catch {
379
+ return {};
380
+ }
381
+ const from = posix$1(relative(dir, old));
382
+ const to = posix$1(relative(dir, folder));
383
+ return Object.fromEntries(Object.entries(scripts).flatMap(([name, script]) => {
384
+ if (typeof script !== "string") return [];
385
+ const updated = movedScript(script, from, to);
386
+ return updated === script ? [] : [[name, updated]];
387
+ }));
388
+ }
389
+ /** The scripts that name the old folder, in the project and the agent root. */
390
+ async function scriptChanges(plan) {
391
+ const { folder, old, shown } = plan;
392
+ if (!stillNamed(plan) || old === void 0) return [];
393
+ const changes = [];
394
+ for (const dir of agentFolders(plan)) {
395
+ const path = join(dir, "package.json");
396
+ const moved = await scriptsIn(dir, old, folder);
397
+ const names = Object.keys(moved).map((name) => `"${name}"`);
398
+ if (names.length > 0) changes.push({
399
+ kind: "change",
400
+ does: `point ${shown(path)} ${names.length === 1 ? "script" : "scripts"} ${listing(names)} at ${shown(folder)}`,
401
+ path,
402
+ apply: () => editManifest(path, (manifest) => {
403
+ manifest.scripts = {
404
+ ...manifest.scripts,
405
+ ...moved
406
+ };
407
+ })
408
+ });
409
+ }
410
+ return changes;
411
+ }
412
+ /**
413
+ * The config with its paths into the old folder pointing into the new one:
414
+ * `content: "./studio"`, and any "./studio/…" (a guide, a stylesheet). A
415
+ * plain "studio" is changed only as `content`, as `ui.theme` takes
416
+ * "studio" too.
417
+ */
418
+ function movedConfig(source, oldPath, newPath) {
419
+ const literal = new RegExp(`(["'\`])(\\./)?${escaped(oldPath)}(/[^"'\`\\n]*)?\\1`, "g");
420
+ return source.replace(literal, (match, quote, dot, rest, offset) => {
421
+ const isContent = CONTENT_KEY_RE.test(source.slice(0, offset));
422
+ return dot || rest || isContent ? `${quote}${dot ?? ""}${newPath}${rest ?? ""}${quote}` : match;
423
+ });
424
+ }
425
+ /** The config pointed at the new folder, or why upgrade can't. */
426
+ async function configChanges(plan) {
427
+ const { file, root, content, folder, old } = plan;
428
+ if (old === void 0 || old !== content) return [];
429
+ const source = await readFile(file, "utf8");
430
+ const to = posix$1(relative(root, folder));
431
+ const name = basename(file);
432
+ const updated = movedConfig(source, posix$1(relative(root, content)), to);
433
+ let pointed;
434
+ try {
435
+ pointed = configData(updated).data.content;
436
+ } catch (error) {
437
+ if (!(error instanceof ConfigNotEditable)) throw error;
438
+ }
439
+ if (typeof pointed !== "string" || resolve(root, pointed) !== folder) return [{
440
+ kind: "stop",
441
+ does: `point ${name} at ./${to}: upgrade can't edit how ${name} sets content`,
442
+ detail: `Set content in ${name} to "./${to}", then run ${UPGRADE_COMMAND} again.`,
443
+ path: file
444
+ }];
445
+ return [{
446
+ kind: "change",
447
+ does: `point ${name} at ./${to}`,
448
+ path: file,
449
+ apply: () => writeFile(file, updated)
450
+ }];
451
+ }
452
+ /** What a plan reads against: the place, and where things are until the move. */
453
+ function planning(project) {
454
+ const place = dexFolderPlace(project);
455
+ const { agentRoot, content, folder, old } = place;
456
+ const moves = old !== void 0 && old === content && existsSync(old) && !existsSync(folder);
457
+ return {
458
+ ...place,
459
+ moves,
460
+ now: (name) => join(moves && old ? old : folder, name),
461
+ shown: (path) => posix$1(relative(agentRoot, path)) || "."
462
+ };
463
+ }
464
+ /**
465
+ * Every change the move makes, in the order upgrade makes them: the
466
+ * folder, what is in it, what names it, and last the config. A plan that
467
+ * stops is that alone.
468
+ */
469
+ async function changesFor(project) {
470
+ const plan = planning(project);
471
+ const steps = [
472
+ ...await folderChanges(plan, project.file),
473
+ ...await stateChanges(plan),
474
+ ...skillsChanges(plan),
475
+ ...await ignoreChanges(plan),
476
+ ...await tsconfigChanges(plan),
477
+ ...await agentChanges(plan),
478
+ ...await guideChanges(plan),
479
+ ...await scriptChanges(plan),
480
+ ...await configChanges(plan)
481
+ ];
482
+ const stopped = steps.filter(({ kind }) => kind === "stop");
483
+ return stopped.length > 0 ? stopped : steps;
484
+ }
485
+ /** The move in a few words: "studio/ → dex/", or "dex/" when it stays. */
486
+ function moveSaid(project) {
487
+ const { old, folder, shown } = planning(project);
488
+ return old && old !== folder ? `${shown(old)}/ → ${shown(folder)}/` : `${shown(folder)}/`;
489
+ }
490
+ /** What the project still has from before, for doctor: "studio/, .dex/skills/". */
491
+ function leftFromBefore(project) {
492
+ const { content, folder, old, now, root, shown } = planning(project);
493
+ return [
494
+ ...old !== void 0 && old === content ? [`${shown(old)}/`] : [],
495
+ ...existsSync(now(".studio")) ? [`${shown(now(OLD_STATE_FOLDER))}/`] : [],
496
+ ...old !== void 0 && old !== content && existsSync(old) ? [`${shown(old)}/`] : [],
497
+ ...OLD_TEAM_SKILLS.map((name) => join(root, name)).filter((path) => existsSync(path)).map((path) => `${shown(path)}/`)
498
+ ].filter((path) => path !== `${shown(folder)}/`);
499
+ }
500
+ /**
501
+ * Whether the plan changes what the team shares: anything but this
502
+ * machine's state, and the old folder a pull left it in (once the config
503
+ * names dex/, a studio/ is only ever that). Read from the plan alone, as
504
+ * upgrade reports after the move.
505
+ */
506
+ function sharesAny(steps, { content }) {
507
+ const moved = basename(content) !== OLD_DEX_FOLDER;
508
+ return steps.some(({ kind, path = "" }) => {
509
+ const name = basename(path);
510
+ return kind === "change" && !STATE_FOLDERS.includes(name) && !(moved && name === "studio");
511
+ });
512
+ }
513
+ /** studio/ moves to dex/, its state to .local/, and the team's skills into it. */
514
+ const dexFolderMigration = {
515
+ name: "dex folder",
516
+ plan: async (project) => (await changesFor(project)).map(({ apply: _apply, ...step }) => step),
517
+ apply: async (project) => {
518
+ for (const change of await changesFor(project)) await change.apply?.();
519
+ },
520
+ report: (steps, { dryRun, project }) => {
521
+ if (steps.length === 0) return [];
522
+ const stopped = steps.some(({ kind }) => kind === "stop");
523
+ const lines = [
524
+ `Dex folder${dryRun ? " (would move)" : ""}: ${moveSaid(project)}`,
525
+ ...steps.flatMap(({ does, detail, kind }) => [` ${kind === "keep" ? "left: " : ""}${does}`, ...detail ? [` ${detail}`] : []]),
526
+ ""
527
+ ];
528
+ if (!(dryRun || stopped) && sharesAny(steps, project)) lines.push("Dex keeps a project's files in dex/ now. Commit the move so your team gets it: each machine moves its own .local/ as it next upgrades.", "");
529
+ return lines;
530
+ },
531
+ byHand: (steps) => steps.filter(({ kind }) => kind === "keep").map(({ does, detail }) => ({
532
+ message: does,
533
+ fix: detail ?? ""
534
+ })),
535
+ warning: (steps, project) => {
536
+ const left = leftFromBefore(project);
537
+ return {
538
+ message: `Dex's folder is dex/ now, with its state in .local/ and the team's skills in it${left.length > 0 ? `, and this project still has ${listing(left)}` : ": files here still name the folders from before"}`,
539
+ fix: `Run ${UPGRADE_COMMAND} to ${steps.filter(({ kind }) => kind !== "keep").map(({ does }) => does).join("; ")}.`
540
+ };
541
+ }
542
+ };
543
+ //#endregion
544
+ export { KEPT_STATE_COMMENT, dexFolderMigration, dexFolderPlace, moveInto, movedConfig, movedIgnore, movedPointer, movedRoot, movedScript };
@@ -172,7 +172,7 @@ async function moveOne(content, move) {
172
172
  await moveSnapshots(content, move);
173
173
  }
174
174
  /**
175
- * The file's screenshots, kept by owner too (.studio/snapshots/<owner>/
175
+ * The file's screenshots, kept by owner too (.local/snapshots/<owner>/
176
176
  * <slug>/), to where Dex looks for them now. They are this machine's
177
177
  * own, never shared, so none can be elsewhere already.
178
178
  */
@@ -37,7 +37,7 @@ const guidesMigration = {
37
37
  const kept = steps.filter(({ kind }) => kind === "keep");
38
38
  const lines = [];
39
39
  if (!dryRun) lines.push(`Rules and methods now come with @dexhq/canvas ${studioVersion()}, and update with it.`);
40
- else if (steps.length === 0) lines.push("Rules, methods and agent files: nothing to change.");
40
+ else if (steps.length === 0) lines.push("Rules, methods and the agent guides older versions wrote: nothing to change.");
41
41
  if (removed.length > 0) lines.push(` ${dryRun ? "Would remove" : "Removed"} what older versions wrote and nobody edited: ${listOf(removed)}`);
42
42
  if (kept.length > 0) lines.push(` ${dryRun ? "Would keep" : "Kept"} your own versions (rules and methods replace the installed ones): ${listOf(kept)}`);
43
43
  return lines;