@dexhq/canvas 0.17.0 → 0.18.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 (174) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/app/canvas/canvas-commands.ts +2 -10
  3. package/app/canvas/canvas-context.tsx +11 -2
  4. package/app/canvas/canvas-document.ts +5 -1
  5. package/app/canvas/canvas-keys.ts +1 -1
  6. package/app/canvas/canvas-model.ts +195 -20
  7. package/app/canvas/canvas-scene.ts +176 -171
  8. package/app/canvas/canvas-ui.ts +4 -11
  9. package/app/canvas/canvas.css +159 -179
  10. package/app/canvas/change-pictures.tsx +156 -0
  11. package/app/canvas/comment-drafts.ts +31 -0
  12. package/app/canvas/comment-layer.tsx +125 -71
  13. package/app/canvas/comments.tsx +38 -2
  14. package/app/canvas/element-picker.ts +20 -0
  15. package/app/canvas/engine/canvas-gestures.ts +15 -3
  16. package/app/canvas/engine/canvas-store.ts +5 -0
  17. package/app/canvas/engine/canvas-view.tsx +22 -5
  18. package/app/canvas/find-bar.tsx +57 -41
  19. package/app/canvas/flow-canvas.tsx +147 -272
  20. package/app/canvas/frame-copies.ts +14 -17
  21. package/app/canvas/frame-drops.ts +15 -7
  22. package/app/canvas/frame-inspector.ts +192 -41
  23. package/app/canvas/frame-node.tsx +123 -75
  24. package/app/canvas/frame-resize.tsx +321 -83
  25. package/app/canvas/insert-hint.tsx +5 -15
  26. package/app/canvas/inspect-layer.tsx +73 -19
  27. package/app/canvas/label-action.tsx +13 -2
  28. package/app/canvas/layout.ts +233 -98
  29. package/app/canvas/live-page.ts +5 -0
  30. package/app/canvas/new-frame.ts +10 -25
  31. package/app/canvas/note-placing.ts +55 -84
  32. package/app/canvas/picked-box.tsx +5 -0
  33. package/app/canvas/picks-menu.tsx +3 -9
  34. package/app/canvas/readable-colour.ts +52 -0
  35. package/app/canvas/request-node.tsx +19 -10
  36. package/app/canvas/scrolling-page.ts +45 -0
  37. package/app/canvas/section-node.tsx +36 -53
  38. package/app/canvas/settle.ts +21 -0
  39. package/app/canvas/snapping.ts +96 -8
  40. package/app/canvas/spec-frame.tsx +8 -5
  41. package/app/canvas/spot-pins.tsx +15 -3
  42. package/app/canvas/stack-frame.tsx +13 -57
  43. package/app/canvas/stack-model.ts +5 -0
  44. package/app/canvas/stack-toggle.tsx +89 -0
  45. package/app/canvas/styles-layer.tsx +23 -43
  46. package/app/canvas/text-layer.tsx +26 -10
  47. package/app/canvas/thread-focus.tsx +18 -1
  48. package/app/canvas/tool-cursors.ts +2 -2
  49. package/app/canvas/toolbar-parts.tsx +48 -8
  50. package/app/canvas/toolbar.tsx +12 -10
  51. package/app/canvas/use-canvas-clipboard.tsx +13 -5
  52. package/app/canvas/use-reveal.ts +86 -0
  53. package/app/editor/extensions.ts +2 -0
  54. package/app/editor/line-break-caret.ts +57 -0
  55. package/app/git/branch-panel.tsx +61 -20
  56. package/app/i18n/locales/en/messages.po +64 -17
  57. package/app/i18n/locales/en/messages.ts +1 -1
  58. package/app/i18n/locales/pseudo/messages.po +64 -17
  59. package/app/i18n/locales/pseudo/messages.ts +1 -1
  60. package/app/icons/glyphs.tsx +2 -0
  61. package/app/live/studio-live.ts +29 -9
  62. package/app/pages/canvas.tsx +1 -1
  63. package/app/pages/commands-settings.tsx +70 -76
  64. package/app/pages/play-bar.tsx +6 -11
  65. package/app/pages/play.tsx +52 -33
  66. package/app/shell/feedback-form.tsx +29 -5
  67. package/app/ui/prompt-editor.tsx +2 -0
  68. package/app/ui/use-field-list.ts +90 -0
  69. package/dist/cli/commands/mcp.mjs +6 -4
  70. package/dist/cli/mcp-relay.mjs +10 -6
  71. package/dist/content/content.d.mts +26 -9
  72. package/dist/content/content.mjs +65 -8
  73. package/dist/content/screenshot.d.mts +2 -0
  74. package/dist/content/screenshot.mjs +3 -0
  75. package/dist/content/snapshot-client.d.mts +2 -0
  76. package/dist/content/snapshot-client.mjs +12 -1
  77. package/dist/inspector.js +96 -19
  78. package/dist/paste/paste.d.mts +5 -0
  79. package/dist/paste/paste.mjs +7 -2
  80. package/dist/server/agent-tools.d.mts +1 -0
  81. package/dist/server/agent-tools.mjs +4 -3
  82. package/dist/server/change-picture-store.d.mts +13 -0
  83. package/dist/server/change-picture-store.mjs +42 -0
  84. package/dist/server/change-pictures.d.mts +25 -0
  85. package/dist/server/change-pictures.mjs +104 -0
  86. package/dist/server/close-check.d.mts +11 -0
  87. package/dist/server/close-check.mjs +37 -5
  88. package/dist/server/comments/agent-actions.d.mts +8 -4
  89. package/dist/server/comments/agent-actions.mjs +16 -7
  90. package/dist/server/comments/close-tools.mjs +7 -5
  91. package/dist/server/comments/files.d.mts +5 -1
  92. package/dist/server/comments/hand-out.d.mts +1 -1
  93. package/dist/server/comments/hand-out.mjs +4 -1
  94. package/dist/server/comments/push.d.mts +19 -10
  95. package/dist/server/comments/push.mjs +45 -30
  96. package/dist/server/comments/studio-files.d.mts +14 -1
  97. package/dist/server/comments/studio-files.mjs +44 -31
  98. package/dist/server/comments/tools.d.mts +1 -1
  99. package/dist/server/comments/workspace.mjs +1 -0
  100. package/dist/server/dev-server.mjs +34 -0
  101. package/dist/server/own-copies.mjs +4 -23
  102. package/dist/server/requests.mjs +57 -3
  103. package/dist/server/response-budget.d.mts +2 -1
  104. package/dist/server/response-budget.mjs +4 -3
  105. package/dist/server/roster.d.mts +19 -8
  106. package/dist/server/roster.mjs +50 -22
  107. package/dist/server/studio-for.d.mts +7 -0
  108. package/dist/server/studio-for.mjs +23 -7
  109. package/dist/server/thread-forms.d.mts +3 -0
  110. package/dist/server/thread-forms.mjs +21 -1
  111. package/dist/server/tools/place-frame.d.mts +1 -0
  112. package/dist/server/tools/place-frame.mjs +33 -9
  113. package/dist/server/tools/result.mjs +2 -2
  114. package/dist/server/tools/snapshot.d.mts +1 -1
  115. package/dist/server/tools/snapshot.mjs +2 -1
  116. package/dist/server/tools/studio-context.d.mts +2 -1
  117. package/dist/server/tools/studio-context.mjs +2 -1
  118. package/dist/server/tools/watch.mjs +29 -12
  119. package/dist/server/work-groups.mjs +1 -1
  120. package/dist/shared/canvas-core.d.mts +39 -5
  121. package/dist/shared/canvas-core.mjs +60 -15
  122. package/dist/shared/canvas-file.d.mts +7 -4
  123. package/dist/shared/change-pictures-core.d.mts +6 -0
  124. package/dist/shared/change-pictures-core.mjs +5 -0
  125. package/dist/shared/page-looks.d.mts +12 -0
  126. package/dist/shared/page-looks.mjs +49 -0
  127. package/dist/shared/snapshot-clipboard.d.mts +6 -0
  128. package/dist/shared/studio-routes.d.mts +11 -0
  129. package/extension/dist/manifest.json +1 -1
  130. package/extension/dist/picker.js +114 -108
  131. package/package.json +4 -3
  132. package/src/cli/commands/mcp.ts +18 -8
  133. package/src/cli/mcp-relay.ts +13 -6
  134. package/src/content/content.ts +90 -16
  135. package/src/content/screenshot.ts +9 -1
  136. package/src/content/snapshot-client.ts +17 -0
  137. package/src/paste/paste.ts +18 -1
  138. package/src/server/agent-tools.ts +5 -4
  139. package/src/server/change-picture-store.ts +71 -0
  140. package/src/server/change-pictures.ts +244 -0
  141. package/src/server/close-check.ts +69 -6
  142. package/src/server/comments/agent-actions.ts +51 -12
  143. package/src/server/comments/close-tools.ts +20 -10
  144. package/src/server/comments/files.ts +10 -2
  145. package/src/server/comments/hand-out.ts +2 -2
  146. package/src/server/comments/push.ts +94 -46
  147. package/src/server/comments/studio-files.ts +77 -46
  148. package/src/server/comments/workspace.ts +1 -0
  149. package/src/server/dev-server.ts +70 -0
  150. package/src/server/own-copies.ts +5 -33
  151. package/src/server/requests.ts +84 -4
  152. package/src/server/response-budget.ts +5 -3
  153. package/src/server/roster.ts +78 -28
  154. package/src/server/studio-for.ts +32 -7
  155. package/src/server/thread-forms.ts +41 -1
  156. package/src/server/tools/place-frame.ts +71 -14
  157. package/src/server/tools/result.ts +2 -2
  158. package/src/server/tools/snapshot.ts +2 -1
  159. package/src/server/tools/studio-context.ts +24 -14
  160. package/src/server/tools/watch.ts +38 -13
  161. package/src/server/work-groups.ts +1 -1
  162. package/src/shared/canvas-core.ts +119 -27
  163. package/src/shared/canvas-file.ts +7 -4
  164. package/src/shared/change-pictures-core.ts +8 -0
  165. package/src/shared/page-looks.ts +133 -0
  166. package/src/shared/snapshot-clipboard.ts +6 -0
  167. package/src/shared/studio-routes.ts +7 -1
  168. package/templates/agents/dex-worker.md +9 -7
  169. package/templates/feedback-workflow.md +1 -1
  170. package/templates/methods/review.md +7 -6
  171. package/templates/rules/canvas-frames.md +8 -7
  172. package/templates/rules/canvas.md +10 -8
  173. package/templates/rules/prototypes.md +5 -3
  174. package/app/canvas/stack-node.tsx +0 -100
@@ -25,16 +25,46 @@ import {
25
25
  import type { AgentSession } from "../agent-session.ts";
26
26
  import { yoursGroups } from "../own-copies.ts";
27
27
  import { firstOf, RESPONSE_BUDGETS } from "../response-budget.ts";
28
- import { FOR_WORK, type Form, SHORT, describedIn } from "../thread-forms.ts";
29
28
  import {
30
- describeAt,
31
- placeThreads,
32
- type ThreadPlace,
33
- } from "../thread-source.ts";
29
+ type Described,
30
+ describedIn,
31
+ FOR_WORK,
32
+ type Form,
33
+ SHORT,
34
+ sharedPlace,
35
+ withoutSaid,
36
+ } from "../thread-forms.ts";
37
+ import { describeAt } from "../thread-source.ts";
34
38
  import { groupWork, splitLine, type WorkGroup } from "../work-groups.ts";
39
+ import type { CommentFiles } from "./files.ts";
35
40
  import { openHandOut } from "./hand-out.ts";
41
+ import { type DescribedInStudio, describeInStudio } from "./studio-files.ts";
36
42
  import { FORKED_COMMAND_HOW } from "./workflow.ts";
37
43
 
44
+ /**
45
+ * The event for what a session won, in the studio's folder at `root`, each
46
+ * file shown from `from`: on someone else's view, the person's copy is what
47
+ * is handed out.
48
+ */
49
+ export const claimedEvent = async (
50
+ root: string,
51
+ claimed: ThreadWithPrototype[],
52
+ from: string
53
+ ): Promise<ChannelEvent> => {
54
+ const groups = await yoursGroups(root, await groupWork(root, claimed));
55
+ const show = (path: string) => shownFrom(from, join(root, path));
56
+
57
+ return channelEvent(
58
+ groups,
59
+ await describeInStudio(
60
+ root,
61
+ groups.flatMap((group) => group.threads),
62
+ show
63
+ ),
64
+ show
65
+ );
66
+ };
67
+
38
68
  /** A thread's state, so each change is sent once. */
39
69
  const stamp = (thread: ThreadWithPrototype) =>
40
70
  `${thread.id}:${thread.messages.length}:${thread.status}`;
@@ -49,10 +79,16 @@ export function commentsToPush(
49
79
  root: string,
50
80
  threads: ThreadModule,
51
81
  session: Pick<AgentSession, "act" | "claimAll" | "hasNews" | "id" | "take">,
52
- { from = process.cwd() }: { from?: string } = {}
82
+ {
83
+ from = process.cwd(),
84
+ pictureBefore = () => Promise.resolve(),
85
+ }: {
86
+ from?: string;
87
+ pictureBefore?: CommentFiles["pictureBefore"];
88
+ } = {}
53
89
  ): ChannelWork {
54
90
  const handOut = openHandOut({
55
- files: { group: (found) => groupWork(root, found) },
91
+ files: { group: (found) => groupWork(root, found), pictureBefore },
56
92
  session,
57
93
  threads,
58
94
  });
@@ -83,25 +119,6 @@ export function commentsToPush(
83
119
  }
84
120
  };
85
121
 
86
- /**
87
- * The event for what the session won: on someone else's view, the
88
- * person's copy is what is handed out.
89
- */
90
- const eventFor = async (
91
- claimed: ThreadWithPrototype[]
92
- ): Promise<ChannelEvent> => {
93
- const groups = await yoursGroups(root, await groupWork(root, claimed));
94
-
95
- return channelEvent(
96
- groups,
97
- await placeThreads(
98
- root,
99
- groups.flatMap((group) => group.threads)
100
- ),
101
- (path) => shownFrom(from, join(root, path))
102
- );
103
- };
104
-
105
122
  return {
106
123
  async listen(heard) {
107
124
  let listed = false;
@@ -216,7 +233,7 @@ export function commentsToPush(
216
233
  }
217
234
 
218
235
  return {
219
- event: () => eventFor(claimed),
236
+ event: () => claimedEvent(root, claimed, from),
220
237
  // Claimed and never sent: they wait for an agent again, instead of
221
238
  // showing 👀 until the session ends.
222
239
  release: async () => {
@@ -235,6 +252,7 @@ export function commentsToPush(
235
252
  const SAID_ELSEWHERE = new Set([
236
253
  "id",
237
254
  "prototype",
255
+ "fileTitle",
238
256
  "for",
239
257
  "status",
240
258
  "messages",
@@ -250,15 +268,18 @@ const asText = (value: unknown): string => {
250
268
  : text;
251
269
  };
252
270
 
253
- /** One thread as the event shows it, in `form`: where it is, then what was said. */
271
+ /** One thread as the event shows it, in `form`: where it is, less what its group shares, then what was said. */
254
272
  const threadLines = (
255
273
  thread: ThreadWithPrototype,
256
- place: ThreadPlace | undefined,
257
- show: ((path: string) => string) | undefined,
258
- form: Form
274
+ description: DescribedInStudio,
275
+ form: Form,
276
+ shared: Described = {}
259
277
  ): string[] => {
260
- const described = describedIn(describeAt(thread, place, show), form).thread;
261
- const lines = [`- Thread ${thread.id} (for ${described.for}):`];
278
+ const described = withoutSaid(describedIn(description, form).thread, shared);
279
+
280
+ const lines = [
281
+ `- Thread ${thread.id}${described.for === "people" ? " (for people)" : ""}:`,
282
+ ];
262
283
 
263
284
  for (const [key, value] of Object.entries(described)) {
264
285
  if (!SAID_ELSEWHERE.has(key) && value !== undefined) {
@@ -356,20 +377,24 @@ function eventForms(
356
377
  const textLength = (parts: string[]): number => parts.join("\n").length + 1;
357
378
 
358
379
  /**
359
- * Threads as one event: each with what describeThread gives (where it is,
360
- * any wireframe, whether someone asked) and its messages, by prototype and
361
- * then by unit of work (work-groups.ts) with the files it may change, ending
362
- * with how to work on them. Each file is given as `show` gives it, from its
363
- * path in the studio's folder: as the agent opens it from where it works.
364
- * Within the event's budget (response-budget.ts): threads there is no room
365
- * for go short, then by id alone, and the event says which.
380
+ * Threads as one event: each as `described` has it by id (studio-files.ts:
381
+ * where it is, its spec, whether someone asked) and its messages, by
382
+ * prototype and then by unit of work (work-groups.ts) with the files it may
383
+ * change, ending with how to work on them. Each file is as `show` gives it:
384
+ * as the agent opens it from where it works. Within the event's budget
385
+ * (response-budget.ts): threads there is no room for go short, then by id
386
+ * alone, and the event says which.
366
387
  */
367
388
  export function channelEvent(
368
389
  groups: WorkGroup[],
369
- places = new Map<string, ThreadPlace>(),
390
+ described: ReadonlyMap<string, DescribedInStudio>,
370
391
  show: (path: string) => string = (path) => path
371
392
  ): ChannelEvent {
372
393
  const threads = groups.flatMap((group) => group.threads);
394
+
395
+ const descriptionOf = (thread: ThreadWithPrototype): DescribedInStudio =>
396
+ described.get(thread.id) ?? describeAt(thread, {}, show);
397
+
373
398
  const count = threads.length;
374
399
  const side = groups.filter((group) => group.parallel).length;
375
400
 
@@ -386,8 +411,16 @@ export function channelEvent(
386
411
  )
387
412
  );
388
413
 
414
+ const sharedOf = new Map(
415
+ groups.map((group) => [
416
+ group,
417
+ sharedPlace(group.threads.map((thread) => descriptionOf(thread))),
418
+ ])
419
+ );
420
+
389
421
  const heading = (group: WorkGroup): string[] => {
390
422
  const files = group.files.map(show);
423
+ const shared = Object.entries(sharedOf.get(group) ?? {});
391
424
 
392
425
  return [
393
426
  "",
@@ -396,16 +429,33 @@ export function channelEvent(
396
429
  ...(files.length > 0
397
430
  ? [`Changes only: ${someIn(files, MAX_EVENT_FILES)}`]
398
431
  : []),
432
+ ...(shared.length > 0
433
+ ? [
434
+ "Shared by every thread below:",
435
+ ...shared.map(([key, value]) => ` ${key}: ${asText(value)}`),
436
+ ]
437
+ : []),
399
438
  ];
400
439
  };
401
440
 
441
+ const linesOf = (thread: ThreadWithPrototype, form: Form) => {
442
+ const group = groupOf.get(thread.id);
443
+
444
+ return threadLines(
445
+ thread,
446
+ descriptionOf(thread),
447
+ form,
448
+ group && sharedOf.get(group)
449
+ );
450
+ };
451
+
402
452
  const ids = threads.map((thread) => thread.id);
403
453
  // What the client matches on: the ids, while they are few.
404
454
  const threadIds = ids.slice(0, MAX_EVENT_IDS).join(",");
405
455
 
406
456
  // How to run a forked command, said only in an event that has one.
407
457
  const forked = threads.some((thread) =>
408
- places.get(thread.id)?.commands?.some((command) => command.run === "fork")
458
+ descriptionOf(thread).commands?.some((command) => command.run === "fork")
409
459
  );
410
460
 
411
461
  const forkLines = forked ? ["", FORKED_COMMAND_HOW] : [];
@@ -422,7 +472,7 @@ export function channelEvent(
422
472
  const first = group && !group.threads.some((each) => shown.has(each.id));
423
473
 
424
474
  return (
425
- textLength(threadLines(thread, places.get(thread.id), show, form)) +
475
+ textLength(linesOf(thread, form)) +
426
476
  (group && first
427
477
  ? textLength(heading(group)) + group.prototype.length + 40
428
478
  : 0)
@@ -449,9 +499,7 @@ export function channelEvent(
449
499
  ...group.threads.flatMap((thread) => {
450
500
  const form = forms.get(thread.id);
451
501
 
452
- return form
453
- ? threadLines(thread, places.get(thread.id), show, form)
454
- : [];
502
+ return form ? linesOf(thread, form) : [];
455
503
  })
456
504
  );
457
505
  }
@@ -1,8 +1,8 @@
1
1
  // The comment tools' files (files.ts) in a studio: its folder on disk. A
2
- // comment is described where it is in its view's code, work is grouped by
3
- // the files views import, a change is checked before it is closed, the
4
- // person's copy of someone else's view is settled, and the Watch switch and
5
- // the open page are the studio's.
2
+ // comment is described where it is in its view's code, as the channel
3
+ // describes it too (push.ts), work is grouped by the files views import, a
4
+ // change is checked before it is closed, the person's copy of someone else's
5
+ // view is settled, and the Watch switch and the open page are the studio's.
6
6
 
7
7
  import { writeFile } from "node:fs/promises";
8
8
 
@@ -10,15 +10,19 @@ import { isWatching } from "@dexhq/harness/channel";
10
10
 
11
11
  import type { ResolvedDesignSystem } from "../../config/design-system.ts";
12
12
  import { threadFlowSpec } from "../../content/flow-specs.ts";
13
- import { ownTitle, prototypeTitle } from "../../content/prototypes.ts";
13
+ import { prototypeTitles } from "../../content/prototypes.ts";
14
14
  import { shownFrom } from "../../paths.ts";
15
15
  import type { ThreadWithPrototype } from "../../shared/threads-core.ts";
16
16
  import { agentsPlace } from "../agents-place.ts";
17
- import { errorsBeforeClose, filesChangedSincePickup } from "../close-check.ts";
17
+ import { type FindStudio, pictureBefore } from "../change-pictures.ts";
18
+ import {
19
+ errorsBeforeClose,
20
+ filesChangedSincePickup,
21
+ lookAtChange,
22
+ } from "../close-check.ts";
18
23
  import { openPageFirst } from "../open-page.ts";
19
24
  import { onCopyIfAny, settleCopy, yoursGroups } from "../own-copies.ts";
20
25
  import { prepareState, readFocus, studioState } from "../state.ts";
21
- import type { Described } from "../thread-forms.ts";
22
26
  import { changePlaceFor } from "../thread-place.ts";
23
27
  import { describeAt, placeThreads } from "../thread-source.ts";
24
28
  import { someOf } from "../tools/result.ts";
@@ -28,69 +32,95 @@ import type { CommentFiles } from "./files.ts";
28
32
  /** The longest a studio's `watch` waits, in seconds. */
29
33
  const STUDIO_LONGEST_WAIT = 1800;
30
34
 
35
+ export type DescribedInStudio = ReturnType<typeof describeAt> & {
36
+ flowSpec?: string;
37
+ moreFlowSpecs?: string[];
38
+ };
39
+
40
+ /**
41
+ * Threads as an agent reads them, by id: where each is in the code, its
42
+ * file's title, and its section's spec to read first.
43
+ */
44
+ export async function describeInStudio(
45
+ root: string,
46
+ threads: ThreadWithPrototype[],
47
+ show: (path: string) => string = (path) => path
48
+ ): Promise<Map<string, DescribedInStudio>> {
49
+ const places = await placeThreads(root, threads);
50
+ const titleOf = await prototypeTitles(root, threads);
51
+ const described = new Map<string, DescribedInStudio>();
52
+
53
+ for (const thread of threads) {
54
+ const at = describeAt(
55
+ thread,
56
+ { ...places.get(thread.id), fileTitle: titleOf(thread) },
57
+ show
58
+ );
59
+
60
+ const flowSpec = await threadFlowSpec(root, thread).catch(() => undefined);
61
+
62
+ described.set(
63
+ thread.id,
64
+ flowSpec
65
+ ? {
66
+ ...at,
67
+ flowSpec: show(flowSpec.file),
68
+ ...(flowSpec.more && {
69
+ moreFlowSpecs: someOf(flowSpec.more.map(show)),
70
+ }),
71
+ }
72
+ : at
73
+ );
74
+ }
75
+
76
+ return described;
77
+ }
78
+
31
79
  /** The comment tools' files in the studio whose content folder is `root`. */
32
80
  export function studioCommentFiles({
33
81
  designSystem,
82
+ findStudio,
34
83
  from,
35
84
  inRoot,
36
85
  root,
37
86
  }: {
38
87
  /** The project's design system, as it is when an agent closes a comment. */
39
88
  designSystem: () => Promise<ResolvedDesignSystem | undefined>;
89
+ findStudio: FindStudio;
40
90
  /** Where the agent works: the files its problems name are shown from here. */
41
91
  from: string;
42
92
  /** A file in the studio's folder, as the agent opens it from where it works. */
43
93
  inRoot: (path: string) => string;
44
94
  root: string;
45
95
  }): CommentFiles {
46
- /**
47
- * A thread as an agent reads it: where its element is in the code, the
48
- * title of its file, and the spec of the section it is on, by its path, to
49
- * read before answering it, when that section has one.
50
- */
51
- const describe = async (thread: ThreadWithPrototype): Promise<Described> => {
52
- const places = await placeThreads(root, [thread]);
53
- const place = places.get(thread.id);
54
-
55
- const fileTitle = ownTitle(
56
- thread.slug,
57
- await prototypeTitle(root, thread.slug).catch(() => thread.slug)
58
- );
59
-
60
- const described = describeAt(thread, { ...place, fileTitle }, inRoot);
61
- const flowSpec = await threadFlowSpec(root, thread).catch(() => undefined);
62
-
63
- if (!flowSpec) {
64
- return described;
65
- }
66
-
67
- const withSpec: Described = {
68
- ...described,
69
- flowSpec: inRoot(flowSpec.file),
70
- };
71
-
72
- if (flowSpec.more) {
73
- withSpec.moreFlowSpecs = someOf(flowSpec.more.map(inRoot));
74
- }
75
-
76
- return withSpec;
77
- };
78
-
79
96
  return {
80
- beforeDone: async (thread) => {
97
+ beforeDone: async (thread, taken) => {
81
98
  // On someone else's view, the change is in the person's copy.
99
+ const changed = await onCopyIfAny(root, thread);
100
+
82
101
  const broken = await errorsBeforeClose(
83
102
  root,
84
- await onCopyIfAny(root, thread),
103
+ changed,
85
104
  await designSystem(),
86
105
  from
87
106
  );
88
107
 
89
- return broken.length > 0
90
- ? { broken, files: [] }
91
- : { broken, files: await filesChangedSincePickup(root, thread) };
108
+ if (broken.length > 0) {
109
+ return { broken, files: [] };
110
+ }
111
+
112
+ const look = await lookAtChange(changed, { findStudio, taken });
113
+
114
+ const files = await filesChangedSincePickup(root, thread);
115
+
116
+ return { broken, files, ...(look && { look }) };
117
+ },
118
+ describe: async (thread) => {
119
+ const described = await describeInStudio(root, [thread], inRoot);
120
+ const [only] = described.values();
121
+
122
+ return only;
92
123
  },
93
- describe,
94
124
  describeClosed: async (thread) => {
95
125
  const places = await placeThreads(root, [thread]);
96
126
 
@@ -117,6 +147,7 @@ export function studioCommentFiles({
117
147
  };
118
148
  },
119
149
  longestWait: STUDIO_LONGEST_WAIT,
150
+ pictureBefore: (threads) => pictureBefore(root, threads, findStudio),
120
151
  settle: async (thread) => {
121
152
  const settled = await settleCopy(root, thread).catch(() => undefined);
122
153
 
@@ -71,6 +71,7 @@ export function workspaceFiles({
71
71
  landing: () => Promise.resolve({ unplaced: NO_WORKSPACE_PLACES }),
72
72
  longestWait,
73
73
  settle: () => Promise.resolve(undefined),
74
+ pictureBefore: () => Promise.resolve(),
74
75
  watching: () => Promise.resolve(true),
75
76
  yours: (groups) => Promise.resolve(groups),
76
77
  };
@@ -14,6 +14,7 @@
14
14
  // - the request module is mounted on Vite's server.
15
15
 
16
16
  import { existsSync, realpathSync, type Stats } from "node:fs";
17
+ import { readdir } from "node:fs/promises";
17
18
  import type { ServerResponse } from "node:http";
18
19
  import { basename, dirname, join, relative, sep } from "node:path";
19
20
 
@@ -21,6 +22,7 @@ import { localSessions } from "@dexhq/harness/channel";
21
22
  import {
22
23
  type Connect,
23
24
  type EnvironmentModuleNode,
25
+ type FSWatcher,
24
26
  isCSSRequest,
25
27
  type Plugin,
26
28
  } from "vite";
@@ -135,6 +137,70 @@ const isSvgRequest = (url = ""): boolean => {
135
137
  }
136
138
  };
137
139
 
140
+ type BundledChokidarAddReportingAsNew = (
141
+ this: FSWatcher,
142
+ path: string,
143
+ origAdd: undefined,
144
+ internal: true
145
+ ) => FSWatcher;
146
+
147
+ const reportAsAdded = (watcher: FSWatcher, path: string): void => {
148
+ // SAFETY: Vite bundles chokidar 3, whose `add` takes these two arguments after the path; its types leave them out.
149
+ (watcher.add as BundledChokidarAddReportingAsNew).call(
150
+ watcher,
151
+ path,
152
+ undefined,
153
+ true
154
+ );
155
+ };
156
+
157
+ const namesInFolderIfStillThere = (folder: string): Promise<string[]> =>
158
+ readdir(folder).catch((): string[] => []);
159
+
160
+ const watcherClosed = (watcher: FSWatcher): boolean =>
161
+ watcher.listenerCount("addDir") === 0;
162
+
163
+ const catchUpNewFolders = (watcher: FSWatcher): void => {
164
+ const settling = new Set<string>();
165
+ let timer: ReturnType<typeof setTimeout> | undefined;
166
+
167
+ const catchUp = async (folders: string[]): Promise<void> => {
168
+ const listings = await Promise.all(
169
+ folders.map(async (folder) => ({
170
+ folder,
171
+ names: await namesInFolderIfStillThere(folder),
172
+ }))
173
+ );
174
+
175
+ const watchedAfterReading = watcher.getWatched();
176
+
177
+ for (const { folder, names } of listings) {
178
+ const known = new Set(watchedAfterReading[folder]);
179
+
180
+ for (const name of names) {
181
+ if (known.has(name) || watcherClosed(watcher)) {
182
+ continue;
183
+ }
184
+
185
+ reportAsAdded(watcher, join(folder, name));
186
+ }
187
+ }
188
+ };
189
+
190
+ watcher.on("addDir", (folder) => {
191
+ settling.add(folder);
192
+ clearTimeout(timer);
193
+ timer = setTimeout(() => {
194
+ const folders = [...settling];
195
+ settling.clear();
196
+
197
+ if (!watcherClosed(watcher)) {
198
+ catchUp(folders).catch(() => undefined);
199
+ }
200
+ }, SETTLE_MS);
201
+ });
202
+ };
203
+
138
204
  /** The project as the development server needs it. */
139
205
  type StudioDevProject = ProjectFolders & { ui?: { title?: string } };
140
206
 
@@ -286,6 +352,10 @@ export function studioDev(project: StudioDevProject): Plugin {
286
352
  configFile ? [...studioPaths, configFile] : studioPaths
287
353
  );
288
354
 
355
+ if (!server.watcher.options.useFsEvents) {
356
+ catchUpNewFolders(server.watcher);
357
+ }
358
+
289
359
  const onFile = (file: string) => {
290
360
  if (workspaceFiles.has(file)) {
291
361
  events.send(studioEvent.workspace());
@@ -16,6 +16,7 @@ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
16
16
  import { dirname, join, relative, resolve, sep } from "node:path";
17
17
 
18
18
  import {
19
+ cellOfFrame,
19
20
  currentPerson,
20
21
  identify,
21
22
  joinCurrentPerson,
@@ -28,13 +29,9 @@ import {
28
29
  viewFiles,
29
30
  } from "../content/prototypes.ts";
30
31
  import { openThreads } from "../content/thread-module.ts";
31
- import { canvasFrames, stepsOf } from "../shared/canvas-core.ts";
32
+ import { stepsOf } from "../shared/canvas-core.ts";
32
33
  import { youOf } from "../shared/studio-routes.ts";
33
- import {
34
- type Thread,
35
- type ThreadWithPrototype,
36
- targetFrameKey,
37
- } from "../shared/threads-core.ts";
34
+ import type { Thread, ThreadWithPrototype } from "../shared/threads-core.ts";
38
35
  import { groupWork, type WorkGroup } from "./work-groups.ts";
39
36
 
40
37
  const TSX_RE = /\.tsx$/u;
@@ -88,37 +85,12 @@ const viewOf = (thread: Pick<Thread, "target">) =>
88
85
  }
89
86
  : undefined;
90
87
 
91
- /**
92
- * The step a frame is at in its row, found by its uid first, then its key;
93
- * none when it is gone.
94
- */
88
+ /** The cell a frame is in now (cellOfFrame); none when it is gone. */
95
89
  const cellOf = async (
96
90
  slug: string,
97
91
  target: { frame: string; uid?: string },
98
92
  root: string
99
- ) => {
100
- const canvas = await readCanvas(slug, root);
101
-
102
- const frames = canvasFrames(canvas).map(({ key, frame }) => ({
103
- key,
104
- uid: frame.uid,
105
- }));
106
-
107
- const key = targetFrameKey(target, frames) ?? target.frame;
108
- const [section, row, frame] = key.split("/");
109
-
110
- const found = canvas.sections
111
- .find((each) => each.id === section)
112
- ?.rows.find((each) => each.id === row);
113
-
114
- const at = found?.frames.findIndex((each) => each.id === frame) ?? -1;
115
-
116
- if (!(found && section && row) || at === -1) {
117
- return;
118
- }
119
-
120
- return { section, row, step: stepsOf(found.frames)[at] ?? at + 1 };
121
- };
93
+ ) => cellOfFrame(await readCanvas(slug, root), target);
122
94
 
123
95
  /** The thread a copy is made for: where it is, and when it was left. */
124
96
  type CopyFor = Pick<ThreadWithPrototype, "created" | "slug">;