@dexhq/canvas 0.14.0 → 0.15.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 (229) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +5 -3
  3. package/app/canvas/activity.tsx +8 -15
  4. package/app/canvas/anchoring.ts +3 -5
  5. package/app/canvas/canvas-input.ts +151 -14
  6. package/app/canvas/canvas-keys.ts +9 -0
  7. package/app/canvas/canvas-model.ts +5 -42
  8. package/app/canvas/canvas-panels.ts +1 -17
  9. package/app/canvas/canvas-scene.ts +7 -3
  10. package/app/canvas/canvas-ui.ts +2 -1
  11. package/app/canvas/canvas.css +61 -26
  12. package/app/canvas/change-notice.tsx +10 -1
  13. package/app/canvas/comment-layer.tsx +2 -1
  14. package/app/canvas/comments.tsx +204 -82
  15. package/app/canvas/element-picker.ts +200 -27
  16. package/app/canvas/engine/canvas-gestures.ts +72 -17
  17. package/app/canvas/engine/canvas-store.ts +17 -1
  18. package/app/canvas/engine/engine.css +6 -3
  19. package/app/canvas/find-bar.tsx +817 -0
  20. package/app/canvas/find-model.ts +135 -0
  21. package/app/canvas/flow-canvas.tsx +18 -2
  22. package/app/canvas/follow-pin.ts +26 -6
  23. package/app/canvas/frame-node.tsx +9 -9
  24. package/app/canvas/imported-reviews.tsx +12 -22
  25. package/app/canvas/layout.ts +27 -0
  26. package/app/canvas/live-page.ts +142 -19
  27. package/app/canvas/page-find.ts +220 -0
  28. package/app/canvas/page-style.ts +23 -0
  29. package/app/canvas/section-node.tsx +2 -0
  30. package/app/canvas/spec-threads.ts +24 -23
  31. package/app/canvas/thread-focus.tsx +14 -12
  32. package/app/canvas/use-activity.ts +0 -8
  33. package/app/canvas/use-agent-changes.tsx +34 -40
  34. package/app/canvas/use-canvas-clipboard.tsx +11 -14
  35. package/app/canvas/xray.ts +3 -12
  36. package/app/frame.tsx +5 -0
  37. package/app/i18n/locales/en/messages.po +88 -8
  38. package/app/i18n/locales/en/messages.ts +1 -1
  39. package/app/i18n/locales/pseudo/messages.po +88 -8
  40. package/app/i18n/locales/pseudo/messages.ts +1 -1
  41. package/app/icons/glyphs.tsx +4 -0
  42. package/app/main.tsx +3 -0
  43. package/app/pages/canvas.tsx +27 -8
  44. package/app/pages/commands-settings.tsx +16 -2
  45. package/app/shell/feedback-form.tsx +10 -21
  46. package/app/shell/feedback-link.tsx +2 -1
  47. package/app/shell/scaled-frame.tsx +21 -9
  48. package/app/types.ts +21 -205
  49. package/app/ui/file-drop.ts +128 -0
  50. package/app/ui/shadcn/input-group.tsx +2 -2
  51. package/dist/cli/banner.d.mts +4 -2
  52. package/dist/cli/banner.mjs +34 -11
  53. package/dist/cli/commands/app.mjs +19 -11
  54. package/dist/cli/commands/hook.mjs +2 -1
  55. package/dist/config/project-files.d.mts +6 -0
  56. package/dist/config/project-files.mjs +14 -2
  57. package/dist/config/renamed.d.mts +0 -2
  58. package/dist/config/renamed.mjs +1 -3
  59. package/dist/content/capture.d.mts +2 -2
  60. package/dist/content/capture.mjs +2 -2
  61. package/dist/content/content.d.mts +3 -141
  62. package/dist/content/content.mjs +7 -62
  63. package/dist/content/flow-specs.mjs +1 -1
  64. package/dist/content/prototype-summary.d.mts +3 -39
  65. package/dist/content/prototype-summary.mjs +2 -3
  66. package/dist/content/prototypes.mjs +1 -1
  67. package/dist/content/text-replace.d.mts +30 -0
  68. package/dist/content/text-replace.mjs +309 -0
  69. package/dist/content/thread-module.mjs +1 -1
  70. package/dist/content/threads.mjs +1 -1
  71. package/dist/paste/paste.mjs +1 -1
  72. package/dist/paths.d.mts +0 -2
  73. package/dist/paths.mjs +1 -3
  74. package/dist/server/agent-env.d.mts +5 -1
  75. package/dist/server/agent-env.mjs +7 -2
  76. package/dist/server/agent-session.d.mts +14 -1
  77. package/dist/server/agent-session.mjs +84 -19
  78. package/dist/server/build-pictures.mjs +1 -1
  79. package/dist/server/channel.d.mts +13 -24
  80. package/dist/server/channel.mjs +55 -37
  81. package/dist/server/claimed-presence.d.mts +3 -2
  82. package/dist/server/claimed-presence.mjs +15 -7
  83. package/dist/server/close-check.mjs +2 -2
  84. package/dist/server/comments/actions.d.mts +153 -0
  85. package/dist/server/comments/actions.mjs +154 -0
  86. package/dist/server/comments/routes.d.mts +25 -0
  87. package/dist/server/comments/routes.mjs +88 -0
  88. package/dist/server/comments/tools.d.mts +6 -0
  89. package/dist/server/comments/tools.mjs +154 -0
  90. package/dist/server/dev-server.mjs +27 -13
  91. package/dist/server/file-lock.d.mts +2 -2
  92. package/dist/server/file-lock.mjs +130 -36
  93. package/dist/server/mcp.d.mts +0 -2
  94. package/dist/server/mcp.mjs +7 -8
  95. package/dist/server/me.d.mts +1 -1
  96. package/dist/server/open-page.d.mts +22 -0
  97. package/dist/server/open-page.mjs +20 -2
  98. package/dist/server/outcome.d.mts +22 -0
  99. package/dist/server/outcome.mjs +8 -0
  100. package/dist/server/own-copies.mjs +2 -2
  101. package/dist/server/people.d.mts +1 -1
  102. package/dist/server/port.d.mts +12 -0
  103. package/dist/server/port.mjs +66 -14
  104. package/dist/server/presence.d.mts +4 -1
  105. package/dist/server/presence.mjs +2 -2
  106. package/dist/server/requests.d.mts +5 -1
  107. package/dist/server/requests.mjs +33 -48
  108. package/dist/server/studio-for.d.mts +5 -0
  109. package/dist/server/studio-for.mjs +17 -3
  110. package/dist/server/sync-install.d.mts +8 -12
  111. package/dist/server/sync-install.mjs +12 -30
  112. package/dist/server/thread-source.mjs +2 -2
  113. package/dist/server/tools/describe.d.mts +1 -1
  114. package/dist/server/tools/describe.mjs +1 -1
  115. package/dist/server/tools/feedback.d.mts +1 -1
  116. package/dist/server/tools/reading.mjs +13 -4
  117. package/dist/server/tools/show.d.mts +1 -1
  118. package/dist/server/tools/snapshot.d.mts +1 -1
  119. package/dist/server/tools/thread-list.mjs +1 -1
  120. package/dist/server/tools/watch.mjs +5 -3
  121. package/dist/server/vite.mjs +2 -2
  122. package/dist/server/web-app.mjs +4 -7
  123. package/dist/server/work-groups.mjs +1 -1
  124. package/dist/setup/create.d.mts +4 -2
  125. package/dist/setup/create.mjs +67 -17
  126. package/dist/setup/design-system-checks.mjs +3 -12
  127. package/dist/setup/desktop-app-script.mjs +4 -3
  128. package/dist/setup/desktop-app-start.d.mts +8 -2
  129. package/dist/setup/desktop-app-start.mjs +64 -29
  130. package/dist/setup/desktop-app.d.mts +8 -0
  131. package/dist/setup/desktop-app.mjs +19 -3
  132. package/dist/setup/detect.d.mts +0 -2
  133. package/dist/setup/detect.mjs +1 -3
  134. package/dist/setup/doctor.mjs +1 -1
  135. package/dist/setup/migrate/row-titles.mjs +1 -1
  136. package/dist/setup/project.d.mts +6 -1
  137. package/dist/setup/project.mjs +9 -9
  138. package/dist/setup/starters.d.mts +2 -0
  139. package/dist/setup/starters.mjs +7 -1
  140. package/dist/shared/annotations-core.mjs +1 -1
  141. package/dist/shared/canvas-core.mjs +1 -1
  142. package/dist/shared/canvas-file.d.mts +201 -0
  143. package/dist/shared/canvas-file.mjs +1 -0
  144. package/dist/shared/comments/routes.d.mts +53 -0
  145. package/dist/shared/comments/routes.mjs +37 -0
  146. package/dist/shared/feedback.d.mts +8 -0
  147. package/dist/shared/feedback.mjs +10 -2
  148. package/dist/shared/page-review.d.mts +2 -11
  149. package/dist/shared/page-review.mjs +4 -13
  150. package/dist/shared/presence-core.d.mts +11 -0
  151. package/dist/shared/presence-core.mjs +11 -2
  152. package/dist/shared/review-file.d.mts +5 -0
  153. package/dist/shared/review-file.mjs +23 -13
  154. package/dist/shared/server-page.mjs +1 -1
  155. package/dist/shared/signup.d.mts +2 -5
  156. package/dist/shared/signup.mjs +2 -35
  157. package/dist/shared/studio-events.d.mts +0 -6
  158. package/dist/shared/studio-events.mjs +1 -5
  159. package/dist/shared/studio-files.d.mts +12 -0
  160. package/dist/shared/studio-files.mjs +6 -1
  161. package/dist/shared/studio-routes.d.mts +16 -62
  162. package/dist/shared/studio-routes.mjs +1 -69
  163. package/dist/shared/threads-core.d.mts +2 -2
  164. package/dist/shared/threads-core.mjs +1 -1
  165. package/extension/dist/feedback.js +148 -138
  166. package/extension/dist/manifest.json +1 -1
  167. package/extension/dist/picker.js +146 -136
  168. package/package.json +2 -2
  169. package/src/cli/banner.ts +45 -11
  170. package/src/cli/commands/app.ts +23 -8
  171. package/src/cli/commands/hook.ts +4 -1
  172. package/src/config/project-files.ts +21 -6
  173. package/src/config/renamed.ts +0 -3
  174. package/src/content/capture.ts +6 -12
  175. package/src/content/content.ts +7 -241
  176. package/src/content/flow-specs.ts +2 -1
  177. package/src/content/prototype-summary.ts +4 -44
  178. package/src/content/review-pages.ts +2 -1
  179. package/src/content/text-replace.ts +449 -0
  180. package/src/paths.ts +0 -8
  181. package/src/server/agent-env.ts +12 -2
  182. package/src/server/agent-session.ts +124 -34
  183. package/src/server/channel.ts +94 -52
  184. package/src/server/claimed-presence.ts +26 -10
  185. package/src/server/comments/actions.ts +352 -0
  186. package/src/server/comments/routes.ts +176 -0
  187. package/src/server/comments/tools.ts +317 -0
  188. package/src/server/dev-server.ts +36 -15
  189. package/src/server/file-lock.ts +205 -54
  190. package/src/server/mcp.ts +13 -14
  191. package/src/server/me.ts +2 -5
  192. package/src/server/open-page.ts +54 -4
  193. package/src/server/outcome.ts +26 -0
  194. package/src/server/people.ts +2 -1
  195. package/src/server/port.ts +94 -20
  196. package/src/server/presence.ts +11 -3
  197. package/src/server/requests.ts +60 -70
  198. package/src/server/studio-for.ts +26 -2
  199. package/src/server/sync-install.ts +35 -26
  200. package/src/server/thread-place.ts +2 -4
  201. package/src/server/tools/reading.ts +16 -3
  202. package/src/server/tools/watch.ts +7 -7
  203. package/src/server/web-app.ts +11 -9
  204. package/src/setup/create.ts +91 -17
  205. package/src/setup/design-system-checks.ts +7 -15
  206. package/src/setup/desktop-app-script.ts +4 -3
  207. package/src/setup/desktop-app-start.ts +94 -26
  208. package/src/setup/desktop-app.ts +23 -2
  209. package/src/setup/detect.ts +0 -4
  210. package/src/setup/project.ts +9 -8
  211. package/src/setup/starters.ts +8 -1
  212. package/src/shared/canvas-file.ts +205 -0
  213. package/src/shared/comments/routes.ts +79 -0
  214. package/src/shared/feedback.ts +14 -4
  215. package/src/shared/page-review.ts +11 -16
  216. package/src/shared/presence-core.ts +16 -2
  217. package/src/shared/review-file.ts +28 -12
  218. package/src/shared/server-page.ts +2 -1
  219. package/src/shared/signup.ts +4 -28
  220. package/src/shared/studio-events.ts +0 -13
  221. package/src/shared/studio-files.ts +14 -0
  222. package/src/shared/studio-routes.ts +21 -64
  223. package/src/shared/threads-core.ts +2 -2
  224. package/dist/server/tools/close-reply.d.mts +0 -6
  225. package/dist/server/tools/close-reply.mjs +0 -138
  226. package/dist/server/tools/comment.d.mts +0 -6
  227. package/dist/server/tools/comment.mjs +0 -49
  228. package/src/server/tools/close-reply.ts +0 -271
  229. package/src/server/tools/comment.ts +0 -96
@@ -9,43 +9,25 @@ import { lockfilePrint, updateMachine } from "./machine-update.mjs";
9
9
  * work is in by then. Why Sync stopped comes back with where the machine
10
10
  * stands, rather than thrown. Run it inside the repository's turn.
11
11
  */
12
- async function syncAndUpdate({ content, keep, message, root, settings }, { run = runStep, running } = {}) {
13
- const before = await lockfilePrint(content);
14
- let stopped;
15
- try {
16
- await syncWork(content, settings, {
17
- keep,
18
- message,
19
- run
20
- });
21
- } catch (error) {
22
- if (!(error instanceof GitError)) throw error;
23
- stopped = error;
24
- }
25
- return {
26
- machine: await updateMachine({
27
- content,
28
- root
29
- }, {
30
- before,
31
- run,
32
- ...running ? { running } : {}
33
- }),
34
- ...stopped ? { stopped } : {}
35
- };
36
- }
12
+ const syncAndUpdate = ({ keep, message, ...place }, steps = {}) => thenUpdate(place, (run) => syncWork(place.content, place.settings, {
13
+ keep,
14
+ message,
15
+ run
16
+ }), steps);
37
17
  /**
38
18
  * Pull from base, then bring the machine up to date with what it brought
39
19
  * in, as syncAndUpdate does for Sync. Run it inside the repository's turn.
40
20
  */
41
- async function pullBaseAndUpdate({ content, keep, root, settings }, { run = runStep, running } = {}) {
21
+ const pullBaseAndUpdate = ({ keep, ...place }, steps = {}) => thenUpdate(place, (run) => bringInBase(place.content, place.settings, {
22
+ keep,
23
+ run
24
+ }), steps);
25
+ /** Bring in the team's work, then update the machine, even if git stopped. */
26
+ async function thenUpdate({ content, root }, bringIn, { run = runStep, running }) {
42
27
  const before = await lockfilePrint(content);
43
28
  let stopped;
44
29
  try {
45
- await bringInBase(content, settings, {
46
- keep,
47
- run
48
- });
30
+ await bringIn(run);
49
31
  } catch (error) {
50
32
  if (!(error instanceof GitError)) throw error;
51
33
  stopped = error;
@@ -1,8 +1,8 @@
1
- import { viewFiles } from "../content/prototypes.mjs";
2
1
  import { describeThread } from "../shared/threads-core.mjs";
3
- import { threadView } from "../shared/removed-views-core.mjs";
2
+ import { viewFiles } from "../content/prototypes.mjs";
4
3
  import { commandWords } from "../shared/commands-core.mjs";
5
4
  import { commandsForComment } from "../content/commands.mjs";
5
+ import { threadView } from "../shared/removed-views-core.mjs";
6
6
  import { skillFolders } from "./command-settings.mjs";
7
7
  import { relative } from "node:path";
8
8
  import { readFile } from "node:fs/promises";
@@ -1,6 +1,6 @@
1
1
  import { ThreadWithPrototype } from "../../shared/threads-core.mjs";
2
- import { Described } from "../thread-forms.mjs";
3
2
  import { ToolContext } from "./context.mjs";
3
+ import { Described } from "../thread-forms.mjs";
4
4
  //#region src/server/tools/describe.d.ts
5
5
  /**
6
6
  * A thread as an agent reads it: where its element is in the code, the
@@ -1,6 +1,6 @@
1
1
  import { ownTitle, prototypeTitle } from "../../content/prototypes.mjs";
2
- import { shapedWithin } from "../thread-forms.mjs";
3
2
  import { describeAt, placeThreads } from "../thread-source.mjs";
3
+ import { shapedWithin } from "../thread-forms.mjs";
4
4
  import { releaseAbandoned } from "../channel.mjs";
5
5
  import { threadFlowSpec } from "../../content/flow-specs.mjs";
6
6
  import { someOf } from "./result.mjs";
@@ -1,5 +1,5 @@
1
- import { SendOptions } from "../../shared/feedback.mjs";
2
1
  import { ToolContext } from "./context.mjs";
2
+ import { SendOptions } from "../../shared/feedback.mjs";
3
3
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
4
  //#region src/server/tools/feedback.d.ts
5
5
  /** Register `feedback` on `server`: `relay` stands in for Dex's relay. */
@@ -1,4 +1,5 @@
1
1
  import { NOT_RECOGNISED } from "../../shared/studio-routes.mjs";
2
+ import { openPresence } from "../presence.mjs";
2
3
  import { joinCurrentPerson } from "../../content/content.mjs";
3
4
  import { RESPONSE_BUDGETS, cutText, fitting, plural, sizeOf } from "../response-budget.mjs";
4
5
  import { fitThreads } from "../thread-forms.mjs";
@@ -8,7 +9,7 @@ import { describeComponent, findComponents } from "../component-catalogue.mjs";
8
9
  import { json, noted } from "./result.mjs";
9
10
  import { describeForWork } from "./describe.mjs";
10
11
  import { PROTOTYPE, prototypeFor } from "./prototype-name.mjs";
11
- import { whereThePersonIs } from "../open-page.mjs";
12
+ import { atWorkOn, whereThePersonIs } from "../open-page.mjs";
12
13
  import { briefSummary } from "../prototype-brief.mjs";
13
14
  import { recordDecision } from "../spec-decisions.mjs";
14
15
  import { join } from "node:path";
@@ -48,7 +49,7 @@ function componentList(components, query) {
48
49
  * told of the studio (briefing.ts), from the same thread module.
49
50
  */
50
51
  function registerReadingTools(server, context, briefing) {
51
- const { agentName, designSystem, from, inRoot, notices, ok, okAboutCode, refuse, root, threads, withNotice } = context;
52
+ const { agentName, designSystem, from, inRoot, notices, ok, okAboutCode, refuse, root, session, threads, withNotice } = context;
52
53
  server.registerTool("brief", {
53
54
  annotations: { readOnlyHint: true },
54
55
  title: "Studio brief",
@@ -144,9 +145,17 @@ function registerReadingTools(server, context, briefing) {
144
145
  server.registerTool("where", {
145
146
  annotations: { readOnlyHint: true },
146
147
  title: "Where the person is",
147
- description: "Where the person is in Dex now: the file they have open (`prototype`, `fileTitle`), the `page` of it (\"canvas\"; \"play\", a section shown a frame at a time; \"view\", a view on a page of its own; or \"file\", its own page), the sections of the canvas in view (`flows`; none when they look at the canvas as a whole), the `frame` selected or playing, and when Dex last said so (`seen`, `ago`). `open` is false with a note when Dex is no longer on screen, or nobody has it open. Ask before starting on feedback, and again when the person says \"this\" or \"here\": work on what they are looking at first.",
148
+ description: "Where the person is in Dex now: the file they have open (`prototype`, `fileTitle`), the `page` of it (\"canvas\"; \"play\", a section shown a frame at a time; \"view\", a view on a page of its own; or \"file\", its own page), the sections of the canvas in view (`flows`; none when they look at the canvas as a whole), the `frame` selected or playing, and when Dex last said so (`seen`, `ago`). `open` is false with a note when Dex is no longer on screen, or nobody has it open. `atWork` is who the canvas shows at work on the file now, the view drawn in blocks: on which view or doc (`prototype` is its shared code, so every view), whose mark it is (`you`: yours end as you close or let go of your comment, or wait in `watch` with none), when it was last marked, and when it `ends` at the latest. Ask before starting on feedback, and again when the person says \"this\" or \"here\": work on what they are looking at first.",
148
149
  inputSchema: {}
149
- }, async () => ok(await whereThePersonIs(root)));
150
+ }, async () => {
151
+ const where = await whereThePersonIs(root);
152
+ if (!("prototype" in where)) return ok(where);
153
+ const atWork = atWorkOn(await openPresence(root).list(), where.prototype, session.marksUnder);
154
+ return ok(atWork.length > 0 ? {
155
+ ...where,
156
+ atWork
157
+ } : where);
158
+ });
150
159
  }
151
160
  //#endregion
152
161
  export { registerReadingTools };
@@ -1,5 +1,5 @@
1
- import { StudioFor } from "../studio-for.mjs";
2
1
  import { ToolContext } from "./context.mjs";
2
+ import { StudioFor } from "../studio-for.mjs";
3
3
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
4
  //#region src/server/tools/show.d.ts
5
5
  /** Register `show` on `server`: `findStudio` says which Dex serves this checkout. */
@@ -1,5 +1,5 @@
1
- import { StudioFor } from "../studio-for.mjs";
2
1
  import { ToolContext } from "./context.mjs";
2
+ import { StudioFor } from "../studio-for.mjs";
3
3
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
4
  //#region src/server/tools/snapshot.d.ts
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  import { shownFrom } from "../../paths.mjs";
2
- import { prepareState, readFocus, studioState } from "../state.mjs";
3
2
  import { claimOf } from "../../shared/threads-core.mjs";
3
+ import { prepareState, readFocus, studioState } from "../state.mjs";
4
4
  import { RESPONSE_BUDGETS, plural } from "../response-budget.mjs";
5
5
  import { fitThreads, shapedWithin } from "../thread-forms.mjs";
6
6
  import { json, noted } from "./result.mjs";
@@ -1,5 +1,6 @@
1
1
  import { groupSummary, groupWork, splitLine } from "../work-groups.mjs";
2
2
  import { yoursGroups } from "../own-copies.mjs";
3
+ import { claimComment } from "../comments/actions.mjs";
3
4
  import { RESPONSE_BUDGETS, plural, sizeOf } from "../response-budget.mjs";
4
5
  import { SHORT, fitThreads, shaped } from "../thread-forms.mjs";
5
6
  import { FEEDBACK_WORKFLOW, isWatching } from "../channel.mjs";
@@ -58,11 +59,11 @@ const groupsWith = (groups, shown, show) => {
58
59
  * Claim each thread for this session, in turn: the ones it won, as they
59
60
  * are after. One another session holds, or gone, is left out.
60
61
  */
61
- const claimAll = async ({ session }, found) => {
62
+ const claimAll = async (context, found) => {
62
63
  const claimed = [];
63
64
  for (const thread of found) {
64
- const result = await session.claim(thread.id);
65
- if (result?.thread) claimed.push(result.thread);
65
+ const result = await claimComment(context, thread.id);
66
+ if (result.value) claimed.push(result.value);
66
67
  }
67
68
  return claimed;
68
69
  };
@@ -219,6 +220,7 @@ function registerWatchTool(server, context) {
219
220
  receipt.confirm(word);
220
221
  await releaseGone(context);
221
222
  if (ids) return ok(await takeThreads(ids));
223
+ await context.session.waits();
222
224
  const filter = {
223
225
  prototype,
224
226
  status: "waiting"
@@ -1,21 +1,21 @@
1
1
  import { APP_DIR, PACKAGE_ROOT } from "../paths.mjs";
2
2
  import { ME_META } from "../shared/studio-routes.mjs";
3
+ import { publicThreads } from "../shared/threads-core.mjs";
3
4
  import { legacyState, prepareOutput, prepareState, studioOutput, studioState } from "./state.mjs";
4
5
  import { prototypesDir } from "../content/prototypes.mjs";
5
6
  import { renamedNotice } from "../config/renamed.mjs";
6
7
  import { canImport, dependenciesOf, projectAliases, projectBaseUrl, resolveAlias, tailwind3Config, tailwindSetup } from "../config/project-files.mjs";
7
8
  import { forInterface } from "../config/design-system.mjs";
8
- import { publicThreads } from "../shared/threads-core.mjs";
9
9
  import { CloudError } from "./cloud.mjs";
10
10
  import { features } from "./features.mjs";
11
11
  import { openThreads } from "../content/thread-module.mjs";
12
+ import { readMe } from "./me.mjs";
12
13
  import { WORKSPACE_META, workspaceName } from "../shared/workspace.mjs";
13
14
  import { EXAMPLE_FILES, OLD_EXAMPLE_FILES, findConfigFile } from "../config/load.mjs";
14
15
  import { componentFileProps, withConfiguredProps } from "../content/component-props.mjs";
15
16
  import { prepareContent } from "../content/first-run.mjs";
16
17
  import { lacksNext, next } from "./next.mjs";
17
18
  import { readBuildSettings } from "./build-settings.mjs";
18
- import { readMe } from "./me.mjs";
19
19
  import { findWorkspaceIcon, readWorkspace, workspaceIconBytes } from "./workspace-settings.mjs";
20
20
  import { studioDev } from "./dev-server.mjs";
21
21
  import { fileErrors } from "./file-errors.mjs";
@@ -2,7 +2,7 @@ import { runningVersion } from "../paths.mjs";
2
2
  import { DESKTOP_APP_INSTALLED, DESKTOP_APP_KEY, MANIFEST_FILE, OLD_PROJECT_ID_HEADER, PROJECT_ID_HEADER, START_LINK_META } from "../shared/studio-routes.mjs";
3
3
  import { projectId } from "./project-id.mjs";
4
4
  import { serverPage, shownPath } from "../shared/server-page.mjs";
5
- import { APP_NAME, desktopApp, desktopAppState, desktopAppUnavailable, urlScheme } from "../setup/desktop-app.mjs";
5
+ import { APP_NAME, desktopAppState, desktopAppUnavailable, servedApp, urlScheme } from "../setup/desktop-app.mjs";
6
6
  import { basename, sep } from "node:path";
7
7
  import { homedir } from "node:os";
8
8
  //#region src/server/web-app.ts
@@ -109,7 +109,7 @@ const rememberAppScript = (startsHere) => {
109
109
  function studioWebApp(project) {
110
110
  let base = "/";
111
111
  let serving = false;
112
- let app;
112
+ let devServer;
113
113
  const name = APP_NAME;
114
114
  const manifest = JSON.stringify(webAppManifest(name), null, 2);
115
115
  return {
@@ -117,13 +117,9 @@ function studioWebApp(project) {
117
117
  configResolved(config) {
118
118
  base = config.base;
119
119
  serving = config.command === "serve";
120
- app = serving && desktopAppUnavailable() === void 0 ? desktopApp({
121
- root: project.root,
122
- port: config.server.port,
123
- base
124
- }) : void 0;
125
120
  },
126
121
  configureServer(server) {
122
+ devServer = server;
127
123
  const worker = serviceWorker(project.root);
128
124
  const id = projectId(project.root);
129
125
  server.middlewares.use((request, response, next) => {
@@ -166,6 +162,7 @@ function studioWebApp(project) {
166
162
  })];
167
163
  if (!serving) return tags;
168
164
  tags.push(head("script", { type: "module" }, registration(base)));
165
+ const app = devServer && desktopAppUnavailable() === void 0 ? servedApp(project.root, devServer) : void 0;
169
166
  if (app) {
170
167
  const { startsHere } = await desktopAppState(app);
171
168
  tags.push(head("meta", {
@@ -1,6 +1,6 @@
1
1
  import { prototypeFiles } from "../shared/prototypes-core.mjs";
2
- import { ownTitle, prototypeTitle, viewFiles } from "../content/prototypes.mjs";
3
2
  import { specName } from "../shared/canvas-core.mjs";
3
+ import { ownTitle, prototypeTitle, viewFiles } from "../content/prototypes.mjs";
4
4
  import { existsSync } from "node:fs";
5
5
  import { dirname, extname, join, relative, resolve } from "node:path";
6
6
  import { readFile } from "node:fs/promises";
@@ -43,8 +43,10 @@ export declare function setUp(root: string, flags: CreateFlags, deps?: CreateDep
43
43
  workspaces?: boolean;
44
44
  }): Promise<SetupOutcome>;
45
45
  /**
46
- * `dex create [dir]`: a new project in an empty or missing folder, or the
47
- * studio added to the project in one with a package.json.
46
+ * `dex create [dir]`: the studio added to the project in a folder with a
47
+ * package.json, or else a new project. A folder with files but no project
48
+ * (an agent's `work/` and `outputs/`, notes) gets the new project beside
49
+ * them.
48
50
  */
49
51
  export declare function create(dir: string | undefined, flags?: CreateFlags, deps?: CreateDeps): Promise<SetupOutcome>;
50
52
  //#endregion
@@ -8,6 +8,7 @@ import { summaryLines } from "./design-md-setup.mjs";
8
8
  import { dexRunner, pmCommand } from "../config/package-manager.mjs";
9
9
  import { createPrototype, loadStudio, scratchView } from "../content/content.mjs";
10
10
  import { agentSetups } from "../server/agents.mjs";
11
+ import { runningAgent } from "./detect.mjs";
11
12
  import { AGENT_IDS, CREATE_COMMAND, agentName, connectInStudio, createCommandFor, findProject, resolvedStudio } from "./project.mjs";
12
13
  import { prepareContent } from "../content/first-run.mjs";
13
14
  import { nextPackage } from "../server/next.mjs";
@@ -20,7 +21,7 @@ import { doctor, realProbes, startProblems } from "./doctor.mjs";
20
21
  import { configChange, decideAgain, existingStudio, newStudioSpec, placementOf, refuseOwnFolder, studioUpgrade } from "./existing-setup.mjs";
21
22
  import { setupHints } from "./hints.mjs";
22
23
  import { PLACEMENT, decidePlacement, describePlacement, workspaceLines } from "./placement.mjs";
23
- import { DEFAULT_STARTER, STARTERS, STARTER_NAMES, TEMPLATE_FLAG, copyStarter, packageManagerVersion, starterNamed, starterPackageManager } from "./starters.mjs";
24
+ import { DEFAULT_STARTER, STARTERS, STARTER_NAMES, TEMPLATE_FLAG, copyStarter, packageManagerVersion, starterNamed, starterPackageManager, starterRootNames } from "./starters.mjs";
24
25
  import { findingsFor, targetFor, workspaceFor, workspaceSetup, workspaceWarnings } from "./workspace-setup.mjs";
25
26
  import { existsSync, readFileSync } from "node:fs";
26
27
  import { basename, join, relative, resolve } from "node:path";
@@ -720,6 +721,33 @@ function shownPath(root) {
720
721
  }
721
722
  /** Whether a folder can take a new project: missing, empty or near enough. */
722
723
  const isEmpty = async (root) => !existsSync(root) || (await readdir(root)).every((name) => ALLOWED_EXISTING.has(name));
724
+ /**
725
+ * A new project beside what a folder holds already (an agent's `work/`, a
726
+ * few notes): asked in a terminal, said without one. It stops, writing
727
+ * nothing, when the project would write over any of it.
728
+ */
729
+ async function besideKept(root, project, kept, { ui, ask }) {
730
+ const written = [
731
+ ...await starterRootNames(project.starter),
732
+ project.starter.workspace ? "apps" : project.dir,
733
+ "dex.config.ts"
734
+ ];
735
+ const clashes = kept.filter((name) => written.includes(name));
736
+ const shown = shownPath(root);
737
+ if (clashes.length > 0) throw new Error(`${shown} has no package.json, but it has ${clashes.join(", ")}, which a new project would write over. Move ${clashes.length === 1 ? "it" : "them"}, or start in another folder: dex create <folder>.`);
738
+ const list = kept.join(", ");
739
+ ui.event({
740
+ step: "decide",
741
+ key: "kept",
742
+ value: kept,
743
+ source: "the folder"
744
+ });
745
+ if (!ask) {
746
+ ui.step(`${shown} has no package.json: a new project goes here, beside ${list}, which stay as they are.`);
747
+ return;
748
+ }
749
+ if (!await ui.confirm(`${shown} has ${list} but no package.json. Start a new project here, beside ${kept.length === 1 ? "it" : "them"}?`, { initial: true })) throw new Cancelled();
750
+ }
723
751
  const WELCOME_IMPORT = "\"@/components/ui/";
724
752
  /**
725
753
  * A first prototype, by whoever is creating the project, importing the
@@ -754,8 +782,8 @@ async function chooseStarter(ui, ask) {
754
782
  }
755
783
  /**
756
784
  * `--agent`, parsed: the agents it names ("none" for none). Without it, a
757
- * new folder has no agent files to go by: asked in a terminal, else Claude
758
- * Code.
785
+ * new folder has no agent files to go by: asked in a terminal, else the
786
+ * agent running setup, else Claude Code.
759
787
  */
760
788
  function newProjectAgents(flag, ask) {
761
789
  if (flag !== void 0) return {
@@ -764,7 +792,7 @@ function newProjectAgents(flag, ask) {
764
792
  };
765
793
  return ask ? { kind: "ask" } : {
766
794
  kind: "given",
767
- ids: ["claude"]
795
+ ids: [runningAgent()?.id ?? "claude"]
768
796
  };
769
797
  }
770
798
  /** The agents as the plan names them. */
@@ -886,7 +914,8 @@ function readyLines(root, project, result) {
886
914
  * Turborepo's studio gets its own app. The agents are asked in a terminal,
887
915
  * as in any project; without one, Claude Code, unless --agent says otherwise.
888
916
  */
889
- async function newProject(root, flags, deps) {
917
+ async function newProject(root, flags, deps, names) {
918
+ const kept = names.filter((name) => !ALLOWED_EXISTING.has(name));
890
919
  const name = basename(root).toLowerCase().replace(NAME_RE, "-").replace(EDGE_RE, "") || "my-studio";
891
920
  const named = checkNewProjectFlags(flags);
892
921
  const ui = deps.ui ?? await createReporter({ json: flags.json });
@@ -912,6 +941,14 @@ async function newProject(root, flags, deps) {
912
941
  pm,
913
942
  starter
914
943
  };
944
+ if (kept.length > 0) try {
945
+ await besideKept(root, project, kept, {
946
+ ui,
947
+ ask
948
+ });
949
+ } catch (error) {
950
+ return stopped(ui, error);
951
+ }
915
952
  if (!(ask || named)) ui.step("A new project. Change it with its flag:", [`Template ${starter.name.padEnd(12)}${TEMPLATE_FLAG}`, `Package manager ${pm.padEnd(12)}--pm bun | pnpm | yarn | npm`]);
916
953
  ui.event({
917
954
  step: "decide",
@@ -943,7 +980,8 @@ async function newProject(root, flags, deps) {
943
980
  await trackWithGit(root, flags, {
944
981
  ui,
945
982
  exec,
946
- ask
983
+ ask,
984
+ kept
947
985
  });
948
986
  if (!flags.skipInstall) await check(ui, join(root, plan.target.package));
949
987
  ui.end("Ready.", readyLines(root, project, result));
@@ -957,12 +995,12 @@ const inRepository = async (dir, exec) => (await exec("git", ["rev-parse", "--is
957
995
  * in a terminal, done without one; skipped inside a repository, with
958
996
  * --no-git, or without git. It adds no remote: that is the person's.
959
997
  */
960
- async function trackWithGit(root, flags, { ask, exec, ui }) {
998
+ async function trackWithGit(root, flags, { ask, exec, ui, kept }) {
961
999
  if (flags.git === false || await inRepository(root, exec)) return;
962
1000
  if (ask) {
963
1001
  if (!await ui.confirm("Track this project with git?", { initial: true })) return;
964
1002
  }
965
- for (const { args, failed } of [
1003
+ const steps = [
966
1004
  {
967
1005
  args: ["init", "--quiet"],
968
1006
  failed: "Git didn’t start: run git init in the project to track it."
@@ -971,6 +1009,18 @@ async function trackWithGit(root, flags, { ask, exec, ui }) {
971
1009
  args: ["add", "--all"],
972
1010
  failed: "Git started, but the files weren’t added: run git add --all."
973
1011
  },
1012
+ ...kept.length > 0 ? [{
1013
+ args: [
1014
+ "rm",
1015
+ "-r",
1016
+ "--cached",
1017
+ "--quiet",
1018
+ "--ignore-unmatch",
1019
+ "--",
1020
+ ...kept
1021
+ ],
1022
+ failed: `Git started, but it holds what was here too: run git rm -r --cached ${kept.join(" ")} to leave it out.`
1023
+ }] : [],
974
1024
  {
975
1025
  args: [
976
1026
  "commit",
@@ -980,7 +1030,8 @@ async function trackWithGit(root, flags, { ask, exec, ui }) {
980
1030
  ],
981
1031
  failed: "Git started, but the first commit failed. If git doesn’t know who you are yet, set git config user.name and user.email, then commit."
982
1032
  }
983
- ]) {
1033
+ ];
1034
+ for (const { args, failed } of steps) {
984
1035
  const { ok } = await exec("git", args, { cwd: root });
985
1036
  if (!ok) {
986
1037
  ui.step(failed);
@@ -995,17 +1046,16 @@ async function trackWithGit(root, flags, { ask, exec, ui }) {
995
1046
  ui.step("Tracked with git, with a first commit.");
996
1047
  }
997
1048
  /**
998
- * `dex create [dir]`: a new project in an empty or missing folder, or the
999
- * studio added to the project in one with a package.json.
1049
+ * `dex create [dir]`: the studio added to the project in a folder with a
1050
+ * package.json, or else a new project. A folder with files but no project
1051
+ * (an agent's `work/` and `outputs/`, notes) gets the new project beside
1052
+ * them.
1000
1053
  */
1001
1054
  async function create(dir, flags = {}, deps = {}) {
1002
1055
  const root = resolve(dir ?? ".");
1003
- if (await isEmpty(root)) return newProject(root, flags, deps);
1004
- if (flags.template !== void 0) throw new Error(`--template starts a new project, in an empty folder, and ${shownPath(root)} has files. Leave it out to add a studio to the project here, or give an empty folder: dex create <folder> --template ${flags.template}.`);
1005
- if (!existsSync(join(root, "package.json"))) {
1006
- const shown = relative(process.cwd(), root) || ".";
1007
- throw new Error(`${shown} has files but no package.json. Run \`dex create\` in a project's folder (where its package.json is), or in an empty folder for a new project.`);
1008
- }
1056
+ if (await isEmpty(root)) return newProject(root, flags, deps, []);
1057
+ if (!existsSync(join(root, "package.json"))) return newProject(root, flags, deps, await readdir(root));
1058
+ if (flags.template !== void 0) throw new Error(`--template starts a new project, and ${shownPath(root)} has one already. Leave it out to add a studio to the project here, or give another folder: dex create <folder> --template ${flags.template}.`);
1009
1059
  return setUp(root, flags, {
1010
1060
  ...deps,
1011
1061
  workspaces: true
@@ -1,5 +1,5 @@
1
1
  import { posix as posix$1 } from "../paths.mjs";
2
- import { componentsJsonError, projectPaths } from "../config/project-files.mjs";
2
+ import { componentsJsonError, installedPackageDir, projectPaths } from "../config/project-files.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import { existsSync, readFileSync, readdirSync } from "node:fs";
5
5
  import { dirname, isAbsolute, join, relative } from "node:path";
@@ -43,15 +43,6 @@ const localTo = (root) => {
43
43
  const aliases = projectPaths(root).map(([pattern]) => pattern.replace(WILDCARD_RE, ""));
44
44
  return (name) => name.startsWith(".") || name.startsWith("@/") || aliases.some((alias) => name === alias || name.startsWith(`${alias}/`));
45
45
  };
46
- /** Where an installed package lives, looking up from `from`. */
47
- const packageDir = (from, name) => {
48
- let dir = from;
49
- while (dir !== dirname(dir)) {
50
- const candidate = join(dir, "node_modules", name);
51
- if (existsSync(join(candidate, "package.json"))) return candidate;
52
- dir = dirname(dir);
53
- }
54
- };
55
46
  const VITE_CONDITIONS = /* @__PURE__ */ new Set([
56
47
  "browser",
57
48
  "import",
@@ -109,7 +100,7 @@ function unbuiltPackages(project) {
109
100
  if (!project.designSystem) return [];
110
101
  const isLocal = localTo(project.root);
111
102
  return importedPackages(project.designSystem).filter((name) => !isLocal(name)).flatMap((name) => {
112
- const dir = packageDir(project.content, name);
103
+ const dir = installedPackageDir(project.content, name);
113
104
  const missing = dir ? missingExports(dir) : [];
114
105
  return missing.length > 0 ? [{
115
106
  name,
@@ -121,7 +112,7 @@ function checkImports({ content, root, designSystem }, { ok, warn }) {
121
112
  const isLocal = localTo(root);
122
113
  if (designSystem.imports.length === 0) warn("The design system lists no imports", "Fill in `designSystem.imports` in dex.config.ts so the audit can tell your components apart.");
123
114
  for (const name of importedPackages(designSystem)) {
124
- const dir = isLocal(name) ? void 0 : packageDir(content, name);
115
+ const dir = isLocal(name) ? void 0 : installedPackageDir(content, name);
125
116
  const resolves = isLocal(name) || canResolve(content, `${name}/package.json`) || canResolve(content, name) || dir !== void 0;
126
117
  const missing = dir ? missingExports(dir) : [];
127
118
  if (resolves && missing.length > 0) warn(`${name} is not built: ${missing.slice(0, 3).join(", ")} ${missing.length === 1 ? "is" : "are"} missing`, `Build it before starting the studio (in a monorepo, \`npx turbo run build --filter=${name}\`), or views cannot import it.`);
@@ -162,9 +162,10 @@ function startOutput() {
162
162
  ObjC.bindFunction("kill", ["int", ["int", "int"]]);
163
163
 
164
164
  /**
165
- * Whether the server the launcher started last still runs. The launcher
166
- * clears its process id before each start and writes it once started, so
167
- * without one, it gave up before starting anything.
165
+ * Whether the server the launcher started last still runs. The pid file
166
+ * names the start the window waits on; the launcher clears it when it
167
+ * gives up, and dex app start when the port is taken, so without one,
168
+ * nothing is starting.
168
169
  */
169
170
  function startAlive() {
170
171
  const pid = Number(readText(DEX.pidFile).trim());
@@ -18,10 +18,14 @@ export type AppStart =
18
18
  state: "gone";
19
19
  message: string;
20
20
  } |
21
- /** Something other than this project's Dex holds the port. */
21
+ /**
22
+ * Something other than this project's Dex holds the port. `ownUrl` is
23
+ * where this project's Dex answers instead, when it runs on another port.
24
+ */
22
25
  {
23
26
  state: "taken";
24
27
  taken: PortTaken;
28
+ ownUrl?: string;
25
29
  };
26
30
  export interface AppStartOptions {
27
31
  /** The `dex` to run `dev` with. */
@@ -53,7 +57,9 @@ export declare function loginShellPath(env: NodeJS.ProcessEnv): Promise<string |
53
57
  export declare const launchPath: (runtime: string, login: string | undefined) => string;
54
58
  /**
55
59
  * Show this project's Dex, or start it: never a server another project,
56
- * or anything else, put on the port.
60
+ * or anything else, put on the port. The app's start link asks again as
61
+ * the app opens: then the `dex dev` it started is still coming up, and
62
+ * it waits on that one rather than start another.
57
63
  */
58
64
  export declare function startForApp(options: AppStartOptions): Promise<AppStart>;
59
65
  //#endregion