@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.
- package/CHANGELOG.md +34 -0
- package/app/canvas/activity-parts.tsx +50 -6
- package/app/canvas/activity.tsx +2 -3
- package/app/canvas/agent-changes.ts +18 -8
- package/app/canvas/anchoring.ts +13 -3
- package/app/canvas/canvas-context.tsx +6 -2
- package/app/canvas/canvas-input.ts +35 -0
- package/app/canvas/canvas-model.ts +2 -2
- package/app/canvas/canvas-scene.ts +243 -24
- package/app/canvas/canvas-ui.ts +11 -2
- package/app/canvas/canvas.css +86 -3
- package/app/canvas/comments.tsx +66 -29
- package/app/canvas/element-link.ts +135 -0
- package/app/canvas/element-picker.ts +23 -0
- package/app/canvas/export-dialog.tsx +265 -0
- package/app/canvas/flow-canvas.tsx +65 -14
- package/app/canvas/frame-context-menu.tsx +61 -7
- package/app/canvas/frame-node.tsx +10 -11
- package/app/canvas/layout.ts +41 -22
- package/app/canvas/linked-element.tsx +196 -0
- package/app/canvas/live-page.ts +14 -0
- package/app/canvas/mentions.tsx +209 -0
- package/app/canvas/picked-box.tsx +21 -0
- package/app/canvas/removed-views-panel.tsx +4 -4
- package/app/canvas/request-node.tsx +151 -0
- package/app/canvas/review-panel.tsx +8 -3
- package/app/canvas/section-node.tsx +4 -133
- package/app/canvas/spec-margin.tsx +4 -1
- package/app/canvas/teammates-layer.tsx +205 -0
- package/app/canvas/text-layer.tsx +103 -17
- package/app/canvas/tool-cursors.ts +7 -6
- package/app/canvas/tool-icons.tsx +24 -56
- package/app/canvas/typing.ts +12 -0
- package/app/canvas/use-agent-changes.tsx +6 -2
- package/app/canvas/use-canvas-editor.ts +4 -2
- package/app/export/player-model.ts +159 -0
- package/app/export/player.tsx +198 -0
- package/app/export.html +31 -0
- package/app/export.tsx +9 -0
- package/app/frame/announce-refreshes.ts +21 -0
- package/app/frame/start-frame.tsx +50 -0
- package/app/frame/view-loads.ts +161 -0
- package/app/frame/views.ts +13 -49
- package/app/frame.tsx +2 -38
- package/app/i18n/locales/en/messages.po +145 -6
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +144 -5
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/dex-glyphs.tsx +219 -0
- package/app/icons/glyphs.tsx +76 -80
- package/app/kit/use-flow.ts +2 -1
- package/app/live/canvas-teammates.ts +90 -0
- package/app/live/studio-api.ts +30 -20
- package/app/pages/canvas.tsx +18 -6
- package/app/pages/commands-settings.tsx +1 -1
- package/app/pages/render.tsx +39 -11
- package/app/shell/bell.tsx +15 -5
- package/app/shell/presence.tsx +123 -26
- package/app/shell/thread-list.tsx +25 -8
- package/app/shell/working-on.tsx +35 -3
- package/app/ui/prompt-editor.tsx +39 -11
- package/app/ui/reference.tsx +21 -8
- package/bin/sudio.mjs +1 -1
- package/dist/cli/commands/create.d.mts +5 -5
- package/dist/cli/commands/create.mjs +4 -4
- package/dist/cli/commands/export.d.mts +40 -0
- package/dist/cli/commands/export.mjs +66 -0
- package/dist/cli/commands/init.d.mts +2 -2
- package/dist/cli/commands/upgrade.mjs +1 -1
- package/dist/cli/help.d.mts +1 -1
- package/dist/cli/help.mjs +13 -7
- package/dist/cli/main.d.mts +42 -5
- package/dist/cli/main.mjs +1 -0
- package/dist/config/load.mjs +14 -2
- package/dist/config/project-files.d.mts +5 -0
- package/dist/config/project-files.mjs +10 -1
- package/dist/config/renamed.d.mts +7 -0
- package/dist/config/renamed.mjs +13 -1
- package/dist/content/commands.d.mts +11 -9
- package/dist/content/commands.mjs +22 -16
- package/dist/content/comments-log.mjs +2 -1
- package/dist/content/content.d.mts +11 -3
- package/dist/content/content.mjs +49 -15
- package/dist/content/element-words.d.mts +42 -0
- package/dist/content/element-words.mjs +112 -0
- package/dist/content/hosted-person.d.mts +31 -0
- package/dist/content/hosted-person.mjs +68 -0
- package/dist/content/merge-rules.d.mts +5 -0
- package/dist/content/merge-rules.mjs +17 -1
- package/dist/content/screenshot.mjs +9 -0
- package/dist/content/text-edit.d.mts +24 -14
- package/dist/content/text-edit.mjs +92 -81
- package/dist/content/text-replace.mjs +2 -26
- package/dist/content/thread-module.d.mts +2 -4
- package/dist/content/thread-module.mjs +4 -5
- package/dist/server/agents.d.mts +10 -0
- package/dist/server/agents.mjs +21 -6
- package/dist/server/canvas-presence.d.mts +22 -0
- package/dist/server/canvas-presence.mjs +160 -0
- package/dist/server/command-settings.mjs +1 -1
- package/dist/server/comments/actions.d.mts +0 -8
- package/dist/server/comments/actions.mjs +1 -9
- package/dist/server/comments/routes.mjs +10 -31
- package/dist/server/dev-server.mjs +35 -13
- package/dist/server/export/build.d.mts +15 -0
- package/dist/server/export/build.mjs +220 -0
- package/dist/server/export/page.d.mts +25 -0
- package/dist/server/export/page.mjs +40 -0
- package/dist/server/export/plugin.d.mts +31 -0
- package/dist/server/export/plugin.mjs +69 -0
- package/dist/server/export/run.d.mts +9 -0
- package/dist/server/export/run.mjs +61 -0
- package/dist/server/export/save.d.mts +7 -0
- package/dist/server/export/save.mjs +29 -0
- package/dist/server/hosted.d.mts +8 -0
- package/dist/server/hosted.mjs +78 -0
- package/dist/server/live-mirror.mjs +66 -10
- package/dist/server/live.mjs +28 -1
- package/dist/server/mcp.mjs +2 -0
- package/dist/server/me.d.mts +2 -0
- package/dist/server/me.mjs +8 -2
- package/dist/server/notices.d.mts +1 -1
- package/dist/server/notices.mjs +1 -1
- package/dist/server/own-copies.mjs +1 -1
- package/dist/server/people.d.mts +7 -2
- package/dist/server/people.mjs +6 -2
- package/dist/server/pictures.d.mts +1 -1
- package/dist/server/pictures.mjs +2 -2
- package/dist/server/prebundle.d.mts +32 -0
- package/dist/server/prebundle.mjs +115 -0
- package/dist/server/problems.d.mts +8 -0
- package/dist/server/problems.mjs +13 -0
- package/dist/server/requests.mjs +43 -30
- package/dist/server/source-stamp.d.mts +4 -3
- package/dist/server/source-stamp.mjs +60 -31
- package/dist/server/state.d.mts +19 -10
- package/dist/server/state.mjs +27 -18
- package/dist/server/thread-source.d.mts +8 -0
- package/dist/server/thread-source.mjs +24 -5
- package/dist/server/tools/export.d.mts +5 -0
- package/dist/server/tools/export.mjs +35 -0
- package/dist/server/tools/place-frame.mjs +16 -16
- package/dist/server/tools/thread-list.mjs +1 -1
- package/dist/server/vite.d.mts +9 -4
- package/dist/server/vite.mjs +63 -61
- package/dist/server/welcome.mjs +2 -1
- package/dist/setup/apply.d.mts +4 -0
- package/dist/setup/apply.mjs +5 -4
- package/dist/setup/create.mjs +5 -5
- package/dist/setup/design-system-checks.mjs +1 -6
- package/dist/setup/detect/workspace.d.mts +10 -10
- package/dist/setup/detect/workspace.mjs +10 -12
- package/dist/setup/doctor.d.mts +4 -1
- package/dist/setup/doctor.mjs +7 -5
- package/dist/setup/migrate/dex-folder.d.mts +61 -0
- package/dist/setup/migrate/dex-folder.mjs +544 -0
- package/dist/setup/migrate/files-folder.mjs +1 -1
- package/dist/setup/migrate/guides.mjs +1 -1
- package/dist/setup/migrate/migrations.mjs +4 -0
- package/dist/setup/migrate/setup-files.d.mts +5 -0
- package/dist/setup/migrate/setup-files.mjs +115 -0
- package/dist/setup/migrate/studio-state.d.mts +2 -2
- package/dist/setup/migrate/studio-state.mjs +4 -4
- package/dist/setup/placement.d.mts +1 -1
- package/dist/setup/placement.mjs +5 -4
- package/dist/setup/plan.d.mts +5 -5
- package/dist/setup/plan.mjs +8 -12
- package/dist/setup/project.mjs +1 -1
- package/dist/setup/prompts.d.mts +2 -1
- package/dist/setup/prompts.mjs +4 -3
- package/dist/setup/questions.mjs +3 -2
- package/dist/setup/starters.d.mts +1 -1
- package/dist/setup/starters.mjs +2 -2
- package/dist/setup/write.d.mts +15 -3
- package/dist/setup/write.mjs +23 -3
- package/dist/shared/canvas-core.d.mts +22 -7
- package/dist/shared/canvas-core.mjs +38 -10
- package/dist/shared/comments/routes.d.mts +3 -1
- package/dist/shared/comments/routes.mjs +4 -2
- package/dist/shared/export-core.d.mts +62 -0
- package/dist/shared/export-core.mjs +101 -0
- package/dist/shared/live-core.d.mts +2 -0
- package/dist/shared/live-core.mjs +6 -1
- package/dist/shared/live-presence.d.mts +57 -2
- package/dist/shared/live-presence.mjs +90 -4
- package/dist/shared/page-messages.d.mts +14 -1
- package/dist/shared/page-messages.mjs +30 -3
- package/dist/shared/people-core.d.mts +28 -0
- package/dist/shared/people-core.mjs +27 -1
- package/dist/shared/presence-core.d.mts +2 -0
- package/dist/shared/references-core.d.mts +4 -0
- package/dist/shared/references-core.mjs +12 -4
- package/dist/shared/studio-files.d.mts +9 -0
- package/dist/shared/studio-files.mjs +11 -2
- package/dist/shared/studio-routes.d.mts +13 -1
- package/dist/shared/threads-core.d.mts +27 -4
- package/dist/shared/threads-core.mjs +67 -12
- package/extension/dist/feedback.js +104 -294
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +104 -294
- package/package.json +2 -2
- package/src/cli/commands/create.ts +4 -4
- package/src/cli/commands/export.ts +78 -0
- package/src/cli/commands/upgrade.ts +1 -1
- package/src/cli/help.ts +13 -7
- package/src/cli/main.ts +1 -0
- package/src/config/load.ts +26 -2
- package/src/config/project-files.ts +15 -0
- package/src/config/renamed.ts +19 -1
- package/src/content/commands.ts +30 -18
- package/src/content/comments-log.ts +4 -1
- package/src/content/content.ts +64 -16
- package/src/content/element-words.ts +175 -0
- package/src/content/hosted-person.ts +107 -0
- package/src/content/merge-rules.ts +29 -0
- package/src/content/screenshot.ts +14 -0
- package/src/content/text-edit.ts +172 -105
- package/src/content/text-replace.ts +3 -32
- package/src/content/thread-module.ts +2 -4
- package/src/content/trash.ts +1 -1
- package/src/server/agents.ts +48 -17
- package/src/server/canvas-presence.ts +237 -0
- package/src/server/channel.ts +1 -1
- package/src/server/command-settings.ts +1 -1
- package/src/server/comments/actions.ts +0 -19
- package/src/server/comments/routes.ts +9 -54
- package/src/server/dev-server.ts +66 -26
- package/src/server/export/build.ts +310 -0
- package/src/server/export/page.ts +85 -0
- package/src/server/export/plugin.ts +138 -0
- package/src/server/export/run.ts +79 -0
- package/src/server/export/save.ts +38 -0
- package/src/server/hosted.ts +113 -0
- package/src/server/live-mirror.ts +93 -8
- package/src/server/live.ts +46 -1
- package/src/server/machine-update.ts +3 -3
- package/src/server/mcp.ts +2 -0
- package/src/server/me.ts +10 -1
- package/src/server/notices.ts +2 -2
- package/src/server/people.ts +11 -2
- package/src/server/pictures.ts +2 -2
- package/src/server/prebundle.ts +230 -0
- package/src/server/presence.ts +1 -1
- package/src/server/problems.ts +11 -0
- package/src/server/requests.ts +55 -40
- package/src/server/roster.ts +1 -1
- package/src/server/saved.ts +1 -1
- package/src/server/source-stamp.ts +118 -37
- package/src/server/state.ts +53 -31
- package/src/server/thread-source.ts +35 -3
- package/src/server/tools/export.ts +56 -0
- package/src/server/tools/place-frame.ts +23 -15
- package/src/server/tools/thread-list.ts +1 -1
- package/src/server/updates.ts +2 -2
- package/src/server/vite.ts +106 -110
- package/src/server/welcome.ts +3 -1
- package/src/setup/apply.ts +8 -5
- package/src/setup/create.ts +10 -10
- package/src/setup/design-system-checks.ts +1 -6
- package/src/setup/detect/workspace.ts +20 -21
- package/src/setup/doctor.ts +13 -6
- package/src/setup/migrate/dex-folder.ts +842 -0
- package/src/setup/migrate/files-folder.ts +1 -1
- package/src/setup/migrate/guides.ts +3 -1
- package/src/setup/migrate/migrations.ts +8 -2
- package/src/setup/migrate/setup-files.ts +198 -0
- package/src/setup/migrate/studio-state.ts +12 -10
- package/src/setup/own-app.ts +1 -1
- package/src/setup/placement.ts +7 -6
- package/src/setup/plan.ts +13 -18
- package/src/setup/project.ts +2 -2
- package/src/setup/prompts.ts +5 -4
- package/src/setup/questions.ts +6 -3
- package/src/setup/starters.ts +3 -3
- package/src/setup/write.ts +34 -3
- package/src/shared/canvas-core.ts +48 -9
- package/src/shared/comments/routes.ts +3 -1
- package/src/shared/export-core.ts +198 -0
- package/src/shared/live-core.ts +8 -0
- package/src/shared/live-presence.ts +171 -2
- package/src/shared/page-messages.ts +38 -2
- package/src/shared/people-core.ts +44 -0
- package/src/shared/presence-core.ts +2 -0
- package/src/shared/references-core.ts +22 -3
- package/src/shared/studio-files.ts +15 -1
- package/src/shared/studio-routes.ts +11 -1
- package/src/shared/threads-core.ts +132 -10
- package/templates/methods/explore.md +1 -1
- package/templates/methods/handoff.md +1 -1
- package/templates/methods/review.md +2 -1
- package/templates/rules/canvas-frames.md +6 -3
- package/templates/rules/commands.md +1 -0
- package/templates/rules/prototypes.md +1 -1
- package/templates/rules/studio.md +17 -11
- package/templates/skills/comprehend/SKILL.md +56 -0
- package/templates/skills/distill/SKILL.md +172 -0
- package/templates/skills/export-prototype/SKILL.md +35 -0
- package/templates/skills/riff/SKILL.md +21 -0
- package/templates/skills/riff-deep/SKILL.md +40 -0
- package/templates/skills/riff-max/SKILL.md +46 -0
- package/templates/skills/riff-state/SKILL.md +45 -0
- package/templates/skills/riff-up/SKILL.md +38 -0
- package/templates/skills/riff-wide/SKILL.md +40 -0
- package/templates/starters/standalone/README.md +1 -1
- package/templates/starters/turborepo/README.md +2 -2
- package/templates/starters/turborepo/apps/web/src/app.tsx +2 -2
- package/templates/starters/vite/README.md +1 -1
package/dist/setup/doctor.mjs
CHANGED
|
@@ -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 (.
|
|
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
|
|
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;
|