@dexhq/canvas 0.13.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 (341) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +21 -18
  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 +43 -26
  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/tool-cursors.ts +16 -16
  33. package/app/canvas/use-activity.ts +0 -8
  34. package/app/canvas/use-agent-changes.tsx +34 -40
  35. package/app/canvas/use-canvas-clipboard.tsx +11 -14
  36. package/app/canvas/xray.ts +3 -12
  37. package/app/frame.tsx +5 -0
  38. package/app/i18n/locales/en/messages.po +114 -12
  39. package/app/i18n/locales/en/messages.ts +1 -1
  40. package/app/i18n/locales/pseudo/messages.po +114 -12
  41. package/app/i18n/locales/pseudo/messages.ts +1 -1
  42. package/app/icons/{sets/lucide.tsx → glyphs.tsx} +7 -5
  43. package/app/icons/index.tsx +3 -3
  44. package/app/icons/types.ts +3 -10
  45. package/app/index.html +3 -3
  46. package/app/main.tsx +3 -0
  47. package/app/pages/canvas-settings.tsx +35 -0
  48. package/app/pages/canvas.tsx +27 -8
  49. package/app/pages/commands-settings.tsx +16 -2
  50. package/app/shell/about.tsx +5 -4
  51. package/app/shell/feedback-details.ts +0 -3
  52. package/app/shell/feedback-form.tsx +10 -21
  53. package/app/shell/feedback-link.tsx +2 -1
  54. package/app/shell/instructions-editor.tsx +1 -1
  55. package/app/shell/presence-style.ts +59 -0
  56. package/app/shell/presence.tsx +6 -3
  57. package/app/shell/scaled-frame.tsx +21 -9
  58. package/app/shell/settings-sections.ts +12 -0
  59. package/app/shell/sidebar.tsx +1 -1
  60. package/app/studio-ui.d.ts +0 -9
  61. package/app/types.ts +21 -205
  62. package/app/ui/file-drop.ts +128 -0
  63. package/app/ui/prompt-editor.tsx +1 -1
  64. package/app/ui/shadcn/input-group.tsx +2 -2
  65. package/dist/cli/banner.d.mts +4 -2
  66. package/dist/cli/banner.mjs +34 -11
  67. package/dist/cli/commands/app.mjs +19 -11
  68. package/dist/cli/commands/create.d.mts +26 -14
  69. package/dist/cli/commands/create.mjs +13 -7
  70. package/dist/cli/commands/dev.mjs +2 -3
  71. package/dist/cli/commands/hook.mjs +2 -1
  72. package/dist/cli/commands/init.d.mts +11 -6
  73. package/dist/cli/help.d.mts +1 -1
  74. package/dist/cli/help.mjs +3 -3
  75. package/dist/cli/main.d.mts +22 -12
  76. package/dist/config/index.d.mts +6 -5
  77. package/dist/config/project-files.d.mts +6 -3
  78. package/dist/config/project-files.mjs +14 -5
  79. package/dist/config/renamed.d.mts +0 -2
  80. package/dist/config/renamed.mjs +1 -3
  81. package/dist/config/schema.d.mts +0 -5
  82. package/dist/config/schema.mjs +0 -5
  83. package/dist/content/capture.d.mts +2 -2
  84. package/dist/content/capture.mjs +2 -2
  85. package/dist/content/content.d.mts +3 -141
  86. package/dist/content/content.mjs +7 -65
  87. package/dist/content/flow-specs.mjs +1 -1
  88. package/dist/content/prototype-summary.d.mts +3 -39
  89. package/dist/content/prototype-summary.mjs +2 -3
  90. package/dist/content/prototypes.mjs +1 -1
  91. package/dist/content/snapshot-client.mjs +1 -1
  92. package/dist/content/text-replace.d.mts +30 -0
  93. package/dist/content/text-replace.mjs +309 -0
  94. package/dist/content/thread-module.mjs +1 -1
  95. package/dist/content/threads.mjs +1 -1
  96. package/dist/paths.d.mts +0 -2
  97. package/dist/paths.mjs +1 -3
  98. package/dist/server/agent-env.d.mts +5 -1
  99. package/dist/server/agent-env.mjs +7 -2
  100. package/dist/server/agent-session.d.mts +14 -1
  101. package/dist/server/agent-session.mjs +84 -19
  102. package/dist/server/brief.mjs +3 -3
  103. package/dist/server/build-pictures.mjs +1 -1
  104. package/dist/server/channel.d.mts +19 -24
  105. package/dist/server/channel.mjs +70 -37
  106. package/dist/server/claimed-presence.d.mts +18 -0
  107. package/dist/server/claimed-presence.mjs +58 -0
  108. package/dist/server/close-check.mjs +2 -2
  109. package/dist/server/comments/actions.d.mts +153 -0
  110. package/dist/server/comments/actions.mjs +154 -0
  111. package/dist/server/comments/routes.d.mts +25 -0
  112. package/dist/server/comments/routes.mjs +88 -0
  113. package/dist/server/comments/tools.d.mts +6 -0
  114. package/dist/server/comments/tools.mjs +154 -0
  115. package/dist/server/dev-server.mjs +36 -13
  116. package/dist/server/file-errors.d.mts +7 -2
  117. package/dist/server/file-errors.mjs +31 -8
  118. package/dist/server/file-lock.d.mts +2 -2
  119. package/dist/server/file-lock.mjs +130 -36
  120. package/dist/server/mcp.d.mts +0 -2
  121. package/dist/server/mcp.mjs +7 -8
  122. package/dist/server/me.d.mts +1 -1
  123. package/dist/server/open-page.d.mts +22 -0
  124. package/dist/server/open-page.mjs +20 -2
  125. package/dist/server/outcome.d.mts +22 -0
  126. package/dist/server/outcome.mjs +8 -0
  127. package/dist/server/own-copies.mjs +2 -2
  128. package/dist/server/people.d.mts +1 -1
  129. package/dist/server/port.d.mts +12 -0
  130. package/dist/server/port.mjs +66 -14
  131. package/dist/server/presence.d.mts +4 -1
  132. package/dist/server/presence.mjs +2 -2
  133. package/dist/server/requests.d.mts +5 -1
  134. package/dist/server/requests.mjs +32 -47
  135. package/dist/server/studio-for.d.mts +5 -0
  136. package/dist/server/studio-for.mjs +18 -4
  137. package/dist/server/sync-install.d.mts +8 -12
  138. package/dist/server/sync-install.mjs +12 -30
  139. package/dist/server/thread-source.mjs +2 -2
  140. package/dist/server/tools/describe.d.mts +1 -1
  141. package/dist/server/tools/describe.mjs +1 -1
  142. package/dist/server/tools/feedback.d.mts +1 -1
  143. package/dist/server/tools/reading.mjs +13 -4
  144. package/dist/server/tools/show.d.mts +1 -1
  145. package/dist/server/tools/snapshot.d.mts +1 -1
  146. package/dist/server/tools/thread-list.mjs +1 -1
  147. package/dist/server/tools/watch.mjs +5 -3
  148. package/dist/server/vite.mjs +28 -31
  149. package/dist/server/web-app.mjs +7 -10
  150. package/dist/server/work-groups.mjs +1 -1
  151. package/dist/setup/apply.mjs +8 -14
  152. package/dist/setup/create.d.mts +4 -2
  153. package/dist/setup/create.mjs +118 -36
  154. package/dist/setup/design-system-checks.mjs +3 -12
  155. package/dist/setup/desktop-app-script.mjs +4 -3
  156. package/dist/setup/desktop-app-start.d.mts +8 -2
  157. package/dist/setup/desktop-app-start.mjs +64 -29
  158. package/dist/setup/desktop-app.d.mts +8 -0
  159. package/dist/setup/desktop-app.mjs +20 -4
  160. package/dist/setup/detect.d.mts +14 -7
  161. package/dist/setup/detect.mjs +56 -10
  162. package/dist/setup/doctor.mjs +2 -4
  163. package/dist/setup/existing-setup.d.mts +1 -3
  164. package/dist/setup/existing-setup.mjs +10 -11
  165. package/dist/setup/migrate/row-titles.mjs +1 -1
  166. package/dist/setup/own-app.d.mts +1 -2
  167. package/dist/setup/own-app.mjs +4 -5
  168. package/dist/setup/plan.d.mts +8 -6
  169. package/dist/setup/plan.mjs +64 -48
  170. package/dist/setup/project.d.mts +6 -17
  171. package/dist/setup/project.mjs +17 -61
  172. package/dist/setup/prompts.d.mts +5 -5
  173. package/dist/setup/prompts.mjs +28 -61
  174. package/dist/setup/questions.d.mts +12 -4
  175. package/dist/setup/questions.mjs +10 -25
  176. package/dist/setup/starters.d.mts +2 -0
  177. package/dist/setup/starters.mjs +26 -9
  178. package/dist/setup/workspace-setup.d.mts +1 -2
  179. package/dist/setup/workspace-setup.mjs +4 -6
  180. package/dist/setup/write.d.mts +15 -5
  181. package/dist/setup/write.mjs +35 -9
  182. package/dist/shared/annotations-core.mjs +1 -1
  183. package/dist/shared/canvas-core.mjs +1 -1
  184. package/dist/shared/canvas-file.d.mts +201 -0
  185. package/dist/shared/canvas-file.mjs +1 -0
  186. package/dist/shared/comments/routes.d.mts +53 -0
  187. package/dist/shared/comments/routes.mjs +37 -0
  188. package/dist/shared/feedback.d.mts +8 -0
  189. package/dist/shared/feedback.mjs +10 -2
  190. package/dist/shared/page-review.d.mts +2 -11
  191. package/dist/shared/page-review.mjs +4 -13
  192. package/dist/shared/presence-core.d.mts +11 -0
  193. package/dist/shared/presence-core.mjs +11 -2
  194. package/dist/shared/review-file.d.mts +5 -0
  195. package/dist/shared/review-file.mjs +23 -13
  196. package/dist/shared/server-page.mjs +7 -1
  197. package/dist/shared/signup.d.mts +2 -5
  198. package/dist/shared/signup.mjs +2 -35
  199. package/dist/shared/studio-events.d.mts +0 -6
  200. package/dist/shared/studio-events.mjs +1 -5
  201. package/dist/shared/studio-files.d.mts +12 -0
  202. package/dist/shared/studio-files.mjs +6 -1
  203. package/dist/shared/studio-routes.d.mts +16 -62
  204. package/dist/shared/studio-routes.mjs +1 -69
  205. package/dist/shared/threads-core.d.mts +2 -2
  206. package/dist/shared/threads-core.mjs +1 -1
  207. package/extension/dist/feedback.js +148 -138
  208. package/extension/dist/manifest.json +1 -1
  209. package/extension/dist/picker.js +146 -136
  210. package/package.json +3 -20
  211. package/src/cli/banner.ts +45 -11
  212. package/src/cli/commands/app.ts +23 -8
  213. package/src/cli/commands/create.ts +17 -9
  214. package/src/cli/commands/dev.ts +0 -3
  215. package/src/cli/commands/hook.ts +4 -1
  216. package/src/cli/help.ts +3 -3
  217. package/src/config/index.ts +6 -5
  218. package/src/config/project-files.ts +21 -11
  219. package/src/config/renamed.ts +0 -3
  220. package/src/config/schema.ts +0 -1
  221. package/src/content/capture.ts +6 -12
  222. package/src/content/content.ts +7 -244
  223. package/src/content/flow-specs.ts +2 -1
  224. package/src/content/prototype-summary.ts +4 -44
  225. package/src/content/review-pages.ts +2 -1
  226. package/src/content/snapshot-client.ts +1 -1
  227. package/src/content/text-replace.ts +449 -0
  228. package/src/paths.ts +0 -8
  229. package/src/server/agent-env.ts +12 -2
  230. package/src/server/agent-session.ts +124 -34
  231. package/src/server/brief.ts +8 -3
  232. package/src/server/channel.ts +121 -52
  233. package/src/server/claimed-presence.ts +93 -0
  234. package/src/server/comments/actions.ts +352 -0
  235. package/src/server/comments/routes.ts +176 -0
  236. package/src/server/comments/tools.ts +317 -0
  237. package/src/server/dev-server.ts +49 -15
  238. package/src/server/file-errors.ts +47 -13
  239. package/src/server/file-lock.ts +205 -54
  240. package/src/server/mcp.ts +13 -14
  241. package/src/server/me.ts +2 -5
  242. package/src/server/open-page.ts +54 -4
  243. package/src/server/outcome.ts +26 -0
  244. package/src/server/people.ts +2 -1
  245. package/src/server/port.ts +94 -20
  246. package/src/server/presence.ts +11 -3
  247. package/src/server/requests.ts +60 -70
  248. package/src/server/studio-for.ts +27 -3
  249. package/src/server/sync-install.ts +35 -26
  250. package/src/server/thread-place.ts +2 -4
  251. package/src/server/tools/reading.ts +16 -3
  252. package/src/server/tools/watch.ts +7 -7
  253. package/src/server/vite.ts +37 -40
  254. package/src/server/web-app.ts +14 -12
  255. package/src/setup/apply.ts +10 -16
  256. package/src/setup/create.ts +143 -37
  257. package/src/setup/design-system-checks.ts +7 -15
  258. package/src/setup/desktop-app-script.ts +4 -3
  259. package/src/setup/desktop-app-start.ts +94 -26
  260. package/src/setup/desktop-app.ts +24 -3
  261. package/src/setup/detect.ts +56 -14
  262. package/src/setup/doctor.ts +4 -4
  263. package/src/setup/existing-setup.ts +10 -12
  264. package/src/setup/own-app.ts +2 -5
  265. package/src/setup/plan.ts +93 -84
  266. package/src/setup/project.ts +25 -118
  267. package/src/setup/prompts.ts +44 -127
  268. package/src/setup/questions.ts +27 -29
  269. package/src/setup/starters.ts +35 -10
  270. package/src/setup/workspace-setup.ts +8 -18
  271. package/src/setup/write.ts +52 -9
  272. package/src/shared/canvas-file.ts +205 -0
  273. package/src/shared/comments/routes.ts +79 -0
  274. package/src/shared/feedback.ts +14 -4
  275. package/src/shared/page-review.ts +11 -16
  276. package/src/shared/presence-core.ts +16 -2
  277. package/src/shared/review-file.ts +28 -12
  278. package/src/shared/server-page.ts +11 -1
  279. package/src/shared/signup.ts +4 -28
  280. package/src/shared/studio-events.ts +0 -13
  281. package/src/shared/studio-files.ts +14 -0
  282. package/src/shared/studio-routes.ts +21 -64
  283. package/src/shared/threads-core.ts +2 -2
  284. package/templates/methods/review.md +2 -2
  285. package/templates/rules/canvas-frames.md +104 -0
  286. package/templates/rules/canvas.md +8 -142
  287. package/templates/rules/prototypes.md +1 -1
  288. package/templates/rules/snapshots.md +52 -0
  289. package/templates/starters/standalone/README.md +7 -7
  290. package/templates/starters/standalone/components.json +1 -1
  291. package/templates/starters/standalone/package.json +1 -2
  292. package/templates/starters/turborepo/README.md +6 -6
  293. package/templates/starters/turborepo/apps/web/components.json +1 -1
  294. package/templates/starters/turborepo/apps/web/package.json +1 -2
  295. package/templates/starters/turborepo/apps/web/src/app.tsx +4 -5
  296. package/templates/starters/turborepo/packages/ui/components.json +1 -1
  297. package/templates/starters/turborepo/packages/ui/package.json +1 -2
  298. package/templates/starters/vite/README.md +7 -6
  299. package/templates/starters/vite/components.json +1 -1
  300. package/templates/starters/vite/package.json +1 -2
  301. package/templates/starters/vite/src/app.tsx +3 -4
  302. package/templates/starters/vite/src/components/ui/accordion.tsx +71 -0
  303. package/templates/starters/vite/src/components/ui/attachment.tsx +1 -1
  304. package/templates/starters/vite/src/components/ui/badge.tsx +2 -2
  305. package/templates/starters/vite/src/components/ui/button.tsx +17 -12
  306. package/templates/starters/vite/src/components/ui/card.tsx +1 -1
  307. package/templates/starters/vite/src/components/ui/checkbox.tsx +28 -0
  308. package/templates/starters/vite/src/components/ui/dialog.tsx +5 -5
  309. package/templates/starters/vite/src/components/ui/dropdown-menu.tsx +17 -14
  310. package/templates/starters/vite/src/components/ui/field.tsx +3 -1
  311. package/templates/starters/vite/src/components/ui/input-group.tsx +5 -3
  312. package/templates/starters/vite/src/components/ui/input.tsx +1 -1
  313. package/templates/starters/vite/src/components/ui/label.tsx +2 -0
  314. package/templates/starters/vite/src/components/ui/native-select.tsx +3 -4
  315. package/templates/starters/vite/src/components/ui/popover.tsx +1 -1
  316. package/templates/starters/vite/src/components/ui/separator.tsx +2 -0
  317. package/templates/starters/vite/src/components/ui/spinner.tsx +3 -7
  318. package/templates/starters/vite/src/components/ui/switch.tsx +1 -1
  319. package/templates/starters/vite/src/components/ui/textarea.tsx +1 -1
  320. package/templates/starters/vite/src/components/ui/toggle.tsx +4 -2
  321. package/templates/starters/vite/src/index.css +533 -111
  322. package/app/icons/sets/hugeicons.tsx +0 -259
  323. package/app/icons/sets/phosphor.tsx +0 -251
  324. package/dist/server/icon-set.d.mts +0 -15
  325. package/dist/server/icon-set.mjs +0 -31
  326. package/dist/server/tools/close-reply.d.mts +0 -6
  327. package/dist/server/tools/close-reply.mjs +0 -138
  328. package/dist/server/tools/comment.d.mts +0 -6
  329. package/dist/server/tools/comment.mjs +0 -49
  330. package/dist/shared/icon-sets.d.mts +0 -9
  331. package/dist/shared/icon-sets.mjs +0 -21
  332. package/src/server/icon-set.ts +0 -56
  333. package/src/server/tools/close-reply.ts +0 -271
  334. package/src/server/tools/comment.ts +0 -96
  335. package/src/shared/icon-sets.ts +0 -23
  336. /package/app/public/{sudio-192.png → dex-192.png} +0 -0
  337. /package/app/public/{sudio-512.png → dex-512.png} +0 -0
  338. /package/app/public/{apple-touch-icon.png → dex-apple-touch-icon.png} +0 -0
  339. /package/app/public/{favicon-32.png → dex-icon-32.png} +0 -0
  340. /package/app/public/{favicon.svg → dex-icon.svg} +0 -0
  341. /package/app/public/{sudio-maskable-512.png → dex-maskable-512.png} +0 -0
@@ -2,10 +2,39 @@ import { MANIFEST_FILE } from "../shared/studio-routes.mjs";
2
2
  import { projectId } from "./project-id.mjs";
3
3
  import { promisify } from "node:util";
4
4
  import { execFile } from "node:child_process";
5
+ import { connect } from "node:net";
5
6
  //#region src/server/port.ts
6
7
  const IN_USE_RE = /already in use/;
7
8
  const ASK_TIMEOUT_MS = 1e3;
8
9
  const run = promisify(execFile);
10
+ /** Where `localhost` may reach a port: either family. */
11
+ const LOCALHOST_ADDRESSES = ["127.0.0.1", "::1"];
12
+ /**
13
+ * How long a connection on loopback may take: one is made at once, but
14
+ * Windows takes seconds to refuse one.
15
+ */
16
+ const CONNECT_TIMEOUT_MS = 250;
17
+ /** Whether anything accepts a connection on `port` at `host`. */
18
+ const accepts = (port, host) => new Promise((answer) => {
19
+ const socket = connect({
20
+ port,
21
+ host
22
+ });
23
+ const done = (listens) => {
24
+ socket.destroy();
25
+ answer(listens);
26
+ };
27
+ socket.once("connect", () => done(true));
28
+ socket.once("error", () => done(false));
29
+ socket.setTimeout(CONNECT_TIMEOUT_MS, () => setImmediate(() => done(false)));
30
+ });
31
+ /**
32
+ * Whether anything listens on `port` where `localhost` may reach it, on
33
+ * either address family.
34
+ */
35
+ async function heldOnLocalhost(port) {
36
+ return (await Promise.all(LOCALHOST_ADDRESSES.map((host) => accepts(port, host).catch(() => false)))).includes(true);
37
+ }
9
38
  /** The web app on the port, another Dex included, from its manifest. */
10
39
  async function appOn(port) {
11
40
  try {
@@ -43,6 +72,8 @@ async function lsofHolder(port) {
43
72
  return;
44
73
  }
45
74
  }
75
+ /** A Dex on a port that isn't this project's, as a person is told of it. */
76
+ const OTHER_DEX = "another checkout's Dex";
46
77
  /** The port `dex dev` keeps to is taken; `taken` says by what. */
47
78
  var PortInUseError = class extends Error {
48
79
  taken;
@@ -65,9 +96,36 @@ async function whatHolds(port, id, holderOf = lsofHolder) {
65
96
  sameProject: Boolean(id && app?.id === id)
66
97
  };
67
98
  }
99
+ /**
100
+ * The port `server` is served on, once it listens. listenOnPort may have
101
+ * moved it off the configured one.
102
+ */
103
+ function servedPort(server) {
104
+ const address = server.httpServer?.address();
105
+ return typeof address === "object" && address ? address.port : server.config.server.port;
106
+ }
68
107
  /** How many ports past a taken one `dex dev` tries. */
69
108
  const MOVE_TRIES = 20;
70
109
  /**
110
+ * Listen on `port`: false when anything holds it. Vite's listen fails
111
+ * only for a holder of the very address it takes (the one `localhost`
112
+ * resolves to first, or STUDIO_HOST's). Yet a browser, and Dex itself,
113
+ * reach the studio at `localhost`, where a holder on the other family,
114
+ * or (on macOS) on a narrower or wider address, would answer instead:
115
+ * that is taken too. Any other failure closes the server and throws.
116
+ */
117
+ async function listenIfFree(server, port) {
118
+ if (await heldOnLocalhost(port)) return false;
119
+ try {
120
+ await server.listen(port);
121
+ return true;
122
+ } catch (error) {
123
+ if (error instanceof Error && IN_USE_RE.test(error.message)) return false;
124
+ await server.close();
125
+ throw error;
126
+ }
127
+ }
128
+ /**
71
129
  * Listen on the configured port, or, while anything but this project's
72
130
  * Dex holds it, on the next free one: answers what held the port it moved
73
131
  * from, undefined when it did not move. Otherwise closes the server and
@@ -79,28 +137,22 @@ async function listenOnPort(server, { holderOf = lsofHolder, keepPort = false, r
79
137
  let movedFrom;
80
138
  for (let port = wanted; port < wanted + 20; port += 1) {
81
139
  server.config.server.port = port;
82
- try {
83
- await server.listen(port);
140
+ if (await listenIfFree(server, port)) {
84
141
  server.config.inlineConfig.server = {
85
142
  ...server.config.inlineConfig.server,
86
143
  port
87
144
  };
88
145
  return movedFrom;
89
- } catch (error) {
90
- if (!(error instanceof Error && IN_USE_RE.test(error.message))) {
91
- await server.close();
92
- throw error;
93
- }
94
- const taken = await whatHolds(port, id, holderOf);
95
- if (keepPort || taken.sameProject) {
96
- await server.close();
97
- throw new PortInUseError(taken);
98
- }
99
- movedFrom ??= taken;
100
146
  }
147
+ const taken = await whatHolds(port, id, holderOf);
148
+ if (keepPort || taken.sameProject) {
149
+ await server.close();
150
+ throw new PortInUseError(taken);
151
+ }
152
+ movedFrom ??= taken;
101
153
  }
102
154
  await server.close();
103
155
  throw new PortInUseError(movedFrom);
104
156
  }
105
157
  //#endregion
106
- export { MOVE_TRIES, PortInUseError, answersAs, appOn, listenOnPort, lsofHolder, whatHolds };
158
+ export { MOVE_TRIES, OTHER_DEX, PortInUseError, answersAs, appOn, heldOnLocalhost, listenOnPort, lsofHolder, servedPort, whatHolds };
@@ -1,7 +1,10 @@
1
1
  import { PresenceEntry, PresenceTarget } from "../shared/presence-core.mjs";
2
2
  //#region src/server/presence.d.ts
3
3
  /** What to clear entries by: any field left out matches every entry. */
4
- export type PresenceMatch = Partial<Pick<PresenceEntry, "agent" | "session" | "slug" | "target">>;
4
+ export type PresenceMatch = Partial<Pick<PresenceEntry, "agent" | "session" | "slug" | "target">> & {
5
+ /** A session: its own entries and its sub-agents' (workerSession). */
6
+ within?: string;
7
+ };
5
8
  /** A View, Doc or Prototype marked as worked on, and by whom. */
6
9
  export interface PresenceMark extends PresenceTarget {
7
10
  /** "Agent" when left out. */
@@ -1,5 +1,5 @@
1
1
  import { fromRoom, teammateSession as teammateSession$1 } from "../shared/live-presence.mjs";
2
- import { freshPresence } from "../shared/presence-core.mjs";
2
+ import { freshPresence, underSession } from "../shared/presence-core.mjs";
3
3
  import { withLock } from "./file-lock.mjs";
4
4
  import { legacyState, prepareState, studioState } from "./state.mjs";
5
5
  import { basename, join } from "node:path";
@@ -10,7 +10,7 @@ const teammateSession = teammateSession$1;
10
10
  /** Whether an entry was brought in from the live room, not marked here. */
11
11
  const isTeammate = fromRoom;
12
12
  const sameSlot = (a, b) => a.slug === b.slug && a.target === b.target && a.session === b.session;
13
- const matches = (entry, match) => Object.entries(match).every(([key, value]) => value === void 0 || entry[key] === value);
13
+ const matches = (entry, { within, ...fields }) => (within === void 0 || underSession(entry.session, within)) && Object.entries(fields).every(([key, value]) => value === void 0 || entry[key] === value);
14
14
  const readEntries = async (path) => {
15
15
  try {
16
16
  const entries = JSON.parse(await readFile(path, "utf8"));
@@ -44,7 +44,11 @@ export type DesktopAppHost = {
44
44
  export interface StudioRequestOptions {
45
45
  agents?: AgentTracker;
46
46
  base?: string;
47
- desktop?: DesktopAppHost;
47
+ /**
48
+ * Where the studio can make its app, asked each time: the dev server's
49
+ * port is known only once it listens.
50
+ */
51
+ desktop?: () => DesktopAppHost;
48
52
  events: EventHub;
49
53
  format?: Formatter;
50
54
  launcher?: AgentLauncher;
@@ -13,16 +13,17 @@ import { readSaved, restoreSaved } from "./saved.mjs";
13
13
  import { checkForUpdateWithin } from "./updates.mjs";
14
14
  import { moveToPullRequest, queueSync, switchToSyncBranch } from "./git-sync.mjs";
15
15
  import { ORPHANED_LINE, RUN_ID, canRestart, orphaned, restartWhenIdle } from "./restart.mjs";
16
- import { guidelinesPerson, isEditableMarkdown } from "../shared/studio-files.mjs";
16
+ import { STUDIO_FILES, guidelinesPerson, isEditableMarkdown } from "../shared/studio-files.mjs";
17
+ import { COMMAND_SWITCHES, menuRenamed, menuWith, quickNames, switchOn } from "../shared/commands-core.mjs";
18
+ import { listCommands, removeCommand, saveCommand } from "../content/commands.mjs";
19
+ import { codebaseSkills, readCommandMenu, skillFolders, writeCommandMenu } from "./command-settings.mjs";
17
20
  import { features } from "./features.mjs";
18
21
  import { otherServers, readRoster, stopOthers } from "./roster.mjs";
19
22
  import { findBiome } from "../content/biome.mjs";
20
23
  import { loadDevices, saveDevices } from "../content/devices.mjs";
21
24
  import { parseReviewFile } from "../shared/review-file.mjs";
22
25
  import { createPrototype, createUntitledPrototype, currentPerson, deletePrototype, duplicatePrototype, joinCurrentPerson, readCanvasRevision, readPrototypeAnnotations, removeAnnotation, saveAnnotation, setPrototypeCover, setPrototypeStatus, setPrototypeTitle, writeCanvas } from "../content/content.mjs";
23
- import { COMMAND_SWITCHES, menuRenamed, menuWith, quickNames, switchOn } from "../shared/commands-core.mjs";
24
- import { listCommands, removeCommand, saveCommand } from "../content/commands.mjs";
25
- import { codebaseSkills, readCommandMenu, skillFolders, writeCommandMenu } from "./command-settings.mjs";
26
+ import { readAuthor, readMe } from "./me.mjs";
26
27
  import { NotAnOldSession, connectedAgents, isWatching, setWatching, stopAgentServer, trackAgents } from "./channel.mjs";
27
28
  import { addAgent, agentRootOf, agentSetups, isLaunchAgent, launchAgent } from "./agents.mjs";
28
29
  import { BUILD_DEFAULTS } from "../shared/build-settings.mjs";
@@ -35,6 +36,7 @@ import { lastEdited } from "../content/last-edited.mjs";
35
36
  import { placeReviewPages } from "../content/review-pages.mjs";
36
37
  import { isViewPage, screenshotFrame } from "../content/screenshot.mjs";
37
38
  import { editText } from "../content/text-edit.mjs";
39
+ import { replaceText, undoReplace } from "../content/text-replace.mjs";
38
40
  import { dismissThreadsOn, emptyTrash, removedViewsWithComments, trashHolds, trashViews } from "../content/trash.mjs";
39
41
  import { PasteProblem, readPaste } from "../paste/paste.mjs";
40
42
  import { readGitSettings, writeGitSettings } from "./git-settings.mjs";
@@ -47,10 +49,10 @@ import { AvatarRefused, removeAvatar, writeAvatar } from "./avatars.mjs";
47
49
  import { writeInstructions } from "./instructions.mjs";
48
50
  import { readBuildSettings, writeBuildSettings } from "./build-settings.mjs";
49
51
  import { notesSince } from "./changelog.mjs";
52
+ import { COMMENT_HANDLERS } from "./comments/routes.mjs";
50
53
  import { gitAskBody } from "./git-asks.mjs";
51
54
  import { settlePaused, undoPaused } from "./git-paused.mjs";
52
55
  import { currentActivity, machineState, markActivity, ranBeforeThis, updateMachine } from "./machine-update.mjs";
53
- import { readAuthor, readMe } from "./me.mjs";
54
56
  import { loadPeople } from "./people.mjs";
55
57
  import { framePictures, latestAround, latestChange } from "./pictures.mjs";
56
58
  import { readPreferences, savePreferences } from "./preferences.mjs";
@@ -269,19 +271,19 @@ const emptyTheTrash = async ({ project }) => {
269
271
  await emptyTrash(project.content);
270
272
  return {};
271
273
  };
272
- const listConnectedAgents = async ({ project }) => ({ agents: await connectedAgents(project.content) });
274
+ const listConnectedAgents = async ({ project, threads }) => ({ agents: await connectedAgents(project.content, { threads }) });
273
275
  /** Only on this machine, where that process runs. */
274
- const stopOldAgent = async ({ project, body, request }) => {
276
+ const stopOldAgent = async ({ project, body, request, threads }) => {
275
277
  onlyFromThisMachine(request, "Stop agents from the machine Dex runs on.");
276
278
  const pid = body?.pid;
277
279
  if (!(typeof pid === "number" && Number.isInteger(pid))) throw new Problems(422, ["Say which agent to stop, by its process."]);
278
280
  try {
279
- await stopAgentServer(project.content, pid);
281
+ await stopAgentServer(project.content, pid, threads);
280
282
  } catch (error) {
281
283
  if (error instanceof NotAnOldSession) throw new Problems(409, [error.message]);
282
284
  throw error;
283
285
  }
284
- return { agents: await connectedAgents(project.content) };
286
+ return { agents: await connectedAgents(project.content, { threads }) };
285
287
  };
286
288
  const listAgentSetups = async ({ project }) => ({ agents: await agentSetups(project.root, project.content, agentRootOf(project.root)) });
287
289
  async function addAgentSetup(context) {
@@ -429,12 +431,13 @@ const desktopAnswer = async (desktop) => "unavailable" in desktop ? {
429
431
  };
430
432
  const loadDesktopApp = ({ request, desktop }) => {
431
433
  fromThisMac(request, false);
432
- return desktopAnswer(desktop);
434
+ return desktopAnswer(desktop());
433
435
  };
434
436
  async function changeDesktopApp({ request, desktop, body }) {
435
437
  fromThisMac(request, true);
436
- if ("unavailable" in desktop) throw new Problems(409, [desktop.unavailable === "hosted" ? "A hosted studio can't install an app." : "Installing outside the browser is macOS-only for now."]);
437
- const { app, home, reveal, open, launchServices } = desktop;
438
+ const host = desktop();
439
+ if ("unavailable" in host) throw new Problems(409, [host.unavailable === "hosted" ? "A hosted studio can't install an app." : "Installing outside the browser is macOS-only for now."]);
440
+ const { app, home, reveal, open, launchServices } = host;
438
441
  switch (body?.action) {
439
442
  case "install":
440
443
  await reveal(await refusable(() => installDesktopApp(app, home, launchServices))).catch(() => void 0);
@@ -448,7 +451,7 @@ async function changeDesktopApp({ request, desktop, body }) {
448
451
  break;
449
452
  default: throw new Problems(400, ["Send an action: \"install\", \"open\" or \"remove\"."]);
450
453
  }
451
- return desktopAnswer(desktop);
454
+ return desktopAnswer(host);
452
455
  }
453
456
  const readWatch = async ({ project }) => ({ on: await isWatching(project.content) });
454
457
  /** Every open page hears it, so each switch shows the same. */
@@ -541,6 +544,19 @@ async function changeText({ project, body }) {
541
544
  if (!("file" in result)) throw new Problems(409, [result.reason]);
542
545
  return result;
543
546
  }
547
+ /**
548
+ * Find and replace on the canvas: { find, to, seen } changes the words in
549
+ * the person's own folder of the file, where the frames showed them;
550
+ * { undo } puts a replacement back.
551
+ */
552
+ async function replaceOnCanvas({ project, body }) {
553
+ const { folder } = prototypeNamed(project.content, body ?? {});
554
+ const own = join(folder, STUDIO_FILES.people, await whoChanges(project.content));
555
+ if (typeof body?.undo === "string") return await undoReplace(own, body.undo);
556
+ const { find, to, seen } = body ?? {};
557
+ if (!(typeof find === "string" && typeof to === "string" && Array.isArray(seen))) throw new Problems(400, ["Say what to find, and what to change it to."]);
558
+ return await replaceText(own, find, to, seen.filter((text) => typeof text === "string"));
559
+ }
544
560
  const needsFeature = (name) => {
545
561
  if (!features()[name]) throw new Problems(404, ["That is not on in this studio."]);
546
562
  };
@@ -634,35 +650,6 @@ async function pictureOfView({ request, body, pageBase, project, response }) {
634
650
  }
635
651
  /** Threads are never kept for a folder that is not a prototype. */
636
652
  const threadsPrototype = (content, url) => prototypeOf(content, url).slug;
637
- const listThreads = ({ project, url, threads }) => url.searchParams.has("slug") ? threads.list({ prototype: threadsPrototype(project.content, url) }) : threads.list();
638
- /** A request for one prototype never changes another's thread. */
639
- const isThreadOf = async (threads, id, prototype) => {
640
- const thread = await threads.find(id);
641
- return thread !== void 0 && thread.slug === prototype;
642
- };
643
- async function postThread({ project, url, body, threads }) {
644
- const prototype = threadsPrototype(project.content, url);
645
- if (!body) throw new Problems(400, ["Send a thread to start, or a change to one."]);
646
- const { name: author, slug: authorId } = await readAuthor(project.content);
647
- const id = body.id;
648
- if (id && !await isThreadOf(threads, id, prototype)) throw new Problems(404, ["That thread is gone."]);
649
- const result = id ? await threads.respond(id, {
650
- ...body,
651
- author,
652
- authorId
653
- }) : await threads.start({
654
- prototype,
655
- target: body.target,
656
- body: body.body,
657
- for: body.for,
658
- sketch: body.sketch,
659
- author,
660
- authorId
661
- });
662
- if (!result) throw new Problems(404, ["That thread is gone."]);
663
- if (result.problems) throw new Problems(422, result.problems);
664
- return result.thread;
665
- }
666
653
  const REVIEW_FILE_PROBLEMS = {
667
654
  "not-a-review": "This is not a Dex review.",
668
655
  newer: "This review is from a newer Dex: update to import it.",
@@ -1272,6 +1259,7 @@ function studioPages({ project, events, threads, agents }) {
1272
1259
  };
1273
1260
  }
1274
1261
  const ROUTES = {
1262
+ ...COMMENT_HANDLERS,
1275
1263
  canvas: {
1276
1264
  prototype: true,
1277
1265
  GET: loadCanvas,
@@ -1293,10 +1281,6 @@ const ROUTES = {
1293
1281
  POST: trashRemovedViews
1294
1282
  },
1295
1283
  trash: { DELETE: emptyTheTrash },
1296
- threads: {
1297
- GET: listThreads,
1298
- POST: postThread
1299
- },
1300
1284
  reviews: {
1301
1285
  limit: MAX_REVIEW_BYTES,
1302
1286
  POST: importReviews
@@ -1317,6 +1301,7 @@ const ROUTES = {
1317
1301
  frame: { POST: addBlankFrame },
1318
1302
  show: { POST: showOnCanvas },
1319
1303
  text: { POST: changeText },
1304
+ replace: { POST: replaceOnCanvas },
1320
1305
  props: { POST: changeProps },
1321
1306
  insert: { POST: insertIntoView },
1322
1307
  screenshot: { POST: screenshotView },
@@ -1439,7 +1424,7 @@ async function answer(route, context) {
1439
1424
  * The handler resolves false for any other request, for whatever serves the
1440
1425
  * rest.
1441
1426
  */
1442
- function studioRequests({ project, threads, events, format = formatter(project.content), launcher = launchAgent, agents = trackAgents(project.content, { threads }), server = {}, base = "/", desktop = { unavailable: "platform" } }) {
1427
+ function studioRequests({ project, threads, events, format = formatter(project.content), launcher = launchAgent, agents = trackAgents(project.content, { threads }), server = {}, base = "/", desktop = () => ({ unavailable: "platform" }) }) {
1443
1428
  const pages = studioPages({
1444
1429
  project,
1445
1430
  events,
@@ -51,6 +51,11 @@ export interface StudioForOptions {
51
51
  }
52
52
  /** Which Dex is serving the checkout at `place` (see StudioFor). */
53
53
  export declare function studioFor({ content, root, port: configured }: StudioPlace, { holderOf }?: StudioForOptions): Promise<StudioFor>;
54
+ /**
55
+ * The port this checkout's Dex is on, also while it restarts there, or
56
+ * undefined when none is: what the app opens, and where it says to look.
57
+ */
58
+ export declare function ownPort(found: StudioFor): number | undefined;
54
59
  /** Why there is no Dex to ask, in words a person can act on. */
55
60
  export declare function notRunning(found: Exclude<StudioFor, {
56
61
  kind: "running";
@@ -1,5 +1,5 @@
1
1
  import { projectId } from "./project-id.mjs";
2
- import { answersAs, lsofHolder, whatHolds } from "./port.mjs";
2
+ import { OTHER_DEX, answersAs, lsofHolder, whatHolds } from "./port.mjs";
3
3
  import { RESTART_PATH } from "../shared/server-page.mjs";
4
4
  import { readRoster } from "./roster.mjs";
5
5
  //#region src/server/studio-for.ts
@@ -16,7 +16,7 @@ async function restartFailed(port) {
16
16
  }
17
17
  /** What holds a port, as an agent is told: "another checkout's Dex". */
18
18
  function holderName({ by, pid }) {
19
- if (by === "Dex") return "another checkout's Dex";
19
+ if (by === "Dex") return OTHER_DEX;
20
20
  return pid ? `${by} (pid ${pid})` : String(by);
21
21
  }
22
22
  /** The newest of `servers` that answers as the project `id` names. */
@@ -57,7 +57,21 @@ async function studioFor({ content, root, port: configured }, { holderOf = lsofH
57
57
  holder: holderName(holder)
58
58
  };
59
59
  }
60
- const START = "Start it with `npx dex dev` (or the project's own script, such as `npm run studio`), then try again.";
60
+ /**
61
+ * The port this checkout's Dex is on, also while it restarts there, or
62
+ * undefined when none is: what the app opens, and where it says to look.
63
+ */
64
+ function ownPort(found) {
65
+ switch (found.kind) {
66
+ case "running":
67
+ case "starting":
68
+ case "failed": return found.port;
69
+ case "none":
70
+ case "elsewhere": return;
71
+ default: return found;
72
+ }
73
+ }
74
+ const START = "Start it with `npx dex dev` (or the project's own script, such as `npm run dex`), then try again.";
61
75
  const ports = (tried) => tried.map((port) => `:${port}`).join(", ");
62
76
  /** Why there is no Dex to ask, in words a person can act on. */
63
77
  function notRunning(found) {
@@ -70,4 +84,4 @@ function notRunning(found) {
70
84
  }
71
85
  }
72
86
  //#endregion
73
- export { notRunning, studioFor };
87
+ export { notRunning, ownPort, studioFor };
@@ -17,28 +17,24 @@ export interface SyncPlace {
17
17
  * work is in by then. Why Sync stopped comes back with where the machine
18
18
  * stands, rather than thrown. Run it inside the repository's turn.
19
19
  */
20
- export declare function syncAndUpdate({ content, keep, message, root, settings }: SyncPlace & {
20
+ export declare const syncAndUpdate: ({ keep, message, ...place }: SyncPlace & {
21
21
  keep?: SyncKeep;
22
22
  /** The commit's message, in place of one written from the changes. */
23
23
  message?: string;
24
- }, { run, running }?: {
25
- run?: StepRunner;
26
- running?: string;
27
- }): Promise<{
28
- machine: MachineState;
29
- stopped?: GitError;
30
- }>;
24
+ }, steps?: UpdateSteps) => Promise<Updated>;
31
25
  /**
32
26
  * Pull from base, then bring the machine up to date with what it brought
33
27
  * in, as syncAndUpdate does for Sync. Run it inside the repository's turn.
34
28
  */
35
- export declare function pullBaseAndUpdate({ content, keep, root, settings }: SyncPlace & {
29
+ export declare const pullBaseAndUpdate: ({ keep, ...place }: SyncPlace & {
36
30
  keep?: SyncKeep;
37
- }, { run, running }?: {
31
+ }, steps?: UpdateSteps) => Promise<Updated>;
32
+ interface UpdateSteps {
38
33
  run?: StepRunner;
39
34
  running?: string;
40
- }): Promise<{
35
+ }
36
+ interface Updated {
41
37
  machine: MachineState;
42
38
  stopped?: GitError;
43
- }>;
39
+ }
44
40
  //#endregion
@@ -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"