@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
@@ -3,14 +3,25 @@ import { isString } from "../../shared/checks.mjs";
3
3
  import { fileLabel } from "../../shared/prototypes-core.mjs";
4
4
  import { mentionsAgent, needsAgent } from "../../shared/threads-core.mjs";
5
5
  import { RESPONSE_BUDGETS, firstOf } from "../response-budget.mjs";
6
- import { FOR_WORK, SHORT, describedIn } from "../thread-forms.mjs";
7
- import { describeAt, placeThreads } from "../thread-source.mjs";
6
+ import { FOR_WORK, SHORT, describedIn, sharedPlace, withoutSaid } from "../thread-forms.mjs";
7
+ import { describeAt } from "../thread-source.mjs";
8
8
  import { groupWork, splitLine } from "../work-groups.mjs";
9
9
  import { yoursGroups } from "../own-copies.mjs";
10
+ import { describeInStudio } from "./studio-files.mjs";
10
11
  import { FORKED_COMMAND_HOW } from "./workflow.mjs";
11
12
  import { openHandOut } from "./hand-out.mjs";
12
13
  import { join } from "node:path";
13
14
  //#region src/server/comments/push.ts
15
+ /**
16
+ * The event for what a session won, in the studio's folder at `root`, each
17
+ * file shown from `from`: on someone else's view, the person's copy is what
18
+ * is handed out.
19
+ */
20
+ const claimedEvent = async (root, claimed, from) => {
21
+ const groups = await yoursGroups(root, await groupWork(root, claimed));
22
+ const show = (path) => shownFrom(from, join(root, path));
23
+ return channelEvent(groups, await describeInStudio(root, groups.flatMap((group) => group.threads), show), show);
24
+ };
14
25
  /** A thread's state, so each change is sent once. */
15
26
  const stamp = (thread) => `${thread.id}:${thread.messages.length}:${thread.status}`;
16
27
  /**
@@ -19,9 +30,12 @@ const stamp = (thread) => `${thread.id}:${thread.messages.length}:${thread.statu
19
30
  * waiting when it starts listening are not pushed; `threads` lists them.
20
31
  * Each file in an event is shown from `from`, where the agent works.
21
32
  */
22
- function commentsToPush(root, threads, session, { from = process.cwd() } = {}) {
33
+ function commentsToPush(root, threads, session, { from = process.cwd(), pictureBefore = () => Promise.resolve() } = {}) {
23
34
  const handOut = openHandOut({
24
- files: { group: (found) => groupWork(root, found) },
35
+ files: {
36
+ group: (found) => groupWork(root, found),
37
+ pictureBefore
38
+ },
25
39
  session,
26
40
  threads
27
41
  });
@@ -34,14 +48,6 @@ function commentsToPush(root, threads, session, { from = process.cwd() } = {}) {
34
48
  for (const thread of changed) if ((needsAgent(thread) || session.hasNews(thread)) && !sent.has(stamp(thread))) held.set(thread.id, thread);
35
49
  else held.delete(thread.id);
36
50
  };
37
- /**
38
- * The event for what the session won: on someone else's view, the
39
- * person's copy is what is handed out.
40
- */
41
- const eventFor = async (claimed) => {
42
- const groups = await yoursGroups(root, await groupWork(root, claimed));
43
- return channelEvent(groups, await placeThreads(root, groups.flatMap((group) => group.threads)), (path) => shownFrom(from, join(root, path)));
44
- };
45
51
  return {
46
52
  async listen(heard) {
47
53
  let listed = false;
@@ -98,7 +104,7 @@ function commentsToPush(root, threads, session, { from = process.cwd() } = {}) {
98
104
  }
99
105
  if (claimed.length === 0) return;
100
106
  return {
101
- event: () => eventFor(claimed),
107
+ event: () => claimedEvent(root, claimed, from),
102
108
  release: async () => {
103
109
  await Promise.allSettled(claimed.map((thread) => session.act(thread.id, { action: "release" })));
104
110
  }
@@ -110,6 +116,7 @@ function commentsToPush(root, threads, session, { from = process.cwd() } = {}) {
110
116
  const SAID_ELSEWHERE = /* @__PURE__ */ new Set([
111
117
  "id",
112
118
  "prototype",
119
+ "fileTitle",
113
120
  "for",
114
121
  "status",
115
122
  "messages"
@@ -119,10 +126,10 @@ const asText = (value) => {
119
126
  const text = isString(value) ? value : JSON.stringify(value);
120
127
  return text.includes("\n") ? `\n ${text.replaceAll("\n", "\n ")}` : text;
121
128
  };
122
- /** One thread as the event shows it, in `form`: where it is, then what was said. */
123
- const threadLines = (thread, place, show, form) => {
124
- const described = describedIn(describeAt(thread, place, show), form).thread;
125
- const lines = [`- Thread ${thread.id} (for ${described.for}):`];
129
+ /** One thread as the event shows it, in `form`: where it is, less what its group shares, then what was said. */
130
+ const threadLines = (thread, description, form, shared = {}) => {
131
+ const described = withoutSaid(describedIn(description, form).thread, shared);
132
+ const lines = [`- Thread ${thread.id}${described.for === "people" ? " (for people)" : ""}:`];
126
133
  for (const [key, value] of Object.entries(described)) if (!SAID_ELSEWHERE.has(key) && value !== void 0) lines.push(` ${key}: ${asText(value)}`);
127
134
  lines.push(" messages:");
128
135
  for (const { body, from } of described.messages) lines.push(` ${from}: ${body.replaceAll("\n", "\n ")}`);
@@ -175,37 +182,45 @@ function eventForms(threads, room, cost) {
175
182
  /** How long lines are in an event, with the line break after them. */
176
183
  const textLength = (parts) => parts.join("\n").length + 1;
177
184
  /**
178
- * Threads as one event: each with what describeThread gives (where it is,
179
- * any wireframe, whether someone asked) and its messages, by prototype and
180
- * then by unit of work (work-groups.ts) with the files it may change, ending
181
- * with how to work on them. Each file is given as `show` gives it, from its
182
- * path in the studio's folder: as the agent opens it from where it works.
183
- * Within the event's budget (response-budget.ts): threads there is no room
184
- * for go short, then by id alone, and the event says which.
185
+ * Threads as one event: each as `described` has it by id (studio-files.ts:
186
+ * where it is, its spec, whether someone asked) and its messages, by
187
+ * prototype and then by unit of work (work-groups.ts) with the files it may
188
+ * change, ending with how to work on them. Each file is as `show` gives it:
189
+ * as the agent opens it from where it works. Within the event's budget
190
+ * (response-budget.ts): threads there is no room for go short, then by id
191
+ * alone, and the event says which.
185
192
  */
186
- function channelEvent(groups, places = /* @__PURE__ */ new Map(), show = (path) => path) {
193
+ function channelEvent(groups, described, show = (path) => path) {
187
194
  const threads = groups.flatMap((group) => group.threads);
195
+ const descriptionOf = (thread) => described.get(thread.id) ?? describeAt(thread, {}, show);
188
196
  const count = threads.length;
189
197
  const side = groups.filter((group) => group.parallel).length;
190
198
  const lines = [`${count} ${count === 1 ? "thread" : "threads"} from the studio, already acknowledged for you (👀), in ${groups.length} ${groups.length === 1 ? "group" : "groups"}.`, ...side > 1 ? [splitLine(side)] : []];
191
199
  const prototypes = [...new Set(groups.map((group) => group.prototype))];
192
200
  const groupOf = new Map(groups.flatMap((group) => group.threads.map((thread) => [thread.id, group])));
201
+ const sharedOf = new Map(groups.map((group) => [group, sharedPlace(group.threads.map((thread) => descriptionOf(thread)))]));
193
202
  const heading = (group) => {
194
203
  const files = group.files.map(show);
204
+ const shared = Object.entries(sharedOf.get(group) ?? {});
195
205
  return [
196
206
  "",
197
207
  `### ${group.place}`,
198
208
  ...group.copied ? [group.copied] : [],
199
- ...files.length > 0 ? [`Changes only: ${someIn(files, MAX_EVENT_FILES)}`] : []
209
+ ...files.length > 0 ? [`Changes only: ${someIn(files, MAX_EVENT_FILES)}`] : [],
210
+ ...shared.length > 0 ? ["Shared by every thread below:", ...shared.map(([key, value]) => ` ${key}: ${asText(value)}`)] : []
200
211
  ];
201
212
  };
213
+ const linesOf = (thread, form) => {
214
+ const group = groupOf.get(thread.id);
215
+ return threadLines(thread, descriptionOf(thread), form, group && sharedOf.get(group));
216
+ };
202
217
  const threadIds = threads.map((thread) => thread.id).slice(0, MAX_EVENT_IDS).join(",");
203
- const forked = threads.some((thread) => places.get(thread.id)?.commands?.some((command) => command.run === "fork"));
218
+ const forked = threads.some((thread) => descriptionOf(thread).commands?.some((command) => command.run === "fork"));
204
219
  const forkLines = forked ? ["", FORKED_COMMAND_HOW] : [];
205
220
  const forms = eventForms(threads, RESPONSE_BUDGETS.channel - textLength(lines) - (forked ? textLength(forkLines) : 0) - threadIds.length - LEFT_OUT_ROOM, (thread, form, shown) => {
206
221
  const group = groupOf.get(thread.id);
207
222
  const first = group && !group.threads.some((each) => shown.has(each.id));
208
- return textLength(threadLines(thread, places.get(thread.id), show, form)) + (group && first ? textLength(heading(group)) + group.prototype.length + 40 : 0);
223
+ return textLength(linesOf(thread, form)) + (group && first ? textLength(heading(group)) + group.prototype.length + 40 : 0);
209
224
  });
210
225
  for (const prototype of prototypes) {
211
226
  const inFile = groups.filter((group) => group.prototype === prototype && group.threads.some((thread) => forms.has(thread.id)));
@@ -213,7 +228,7 @@ function channelEvent(groups, places = /* @__PURE__ */ new Map(), show = (path)
213
228
  lines.push("", `## ${fileLabel(prototype, inFile[0].fileTitle)}`);
214
229
  for (const group of inFile) lines.push(...heading(group), ...group.threads.flatMap((thread) => {
215
230
  const form = forms.get(thread.id);
216
- return form ? threadLines(thread, places.get(thread.id), show, form) : [];
231
+ return form ? linesOf(thread, form) : [];
217
232
  }));
218
233
  }
219
234
  const short = threads.filter((thread) => forms.get(thread.id) === SHORT);
@@ -235,4 +250,4 @@ function channelEvent(groups, places = /* @__PURE__ */ new Map(), show = (path)
235
250
  };
236
251
  }
237
252
  //#endregion
238
- export { channelEvent, commentsToPush };
253
+ export { channelEvent, claimedEvent, commentsToPush };
@@ -1,10 +1,23 @@
1
+ import { ThreadWithPrototype } from "../../shared/threads-core.mjs";
1
2
  import { ResolvedDesignSystem } from "../../config/design-system.mjs";
3
+ import { FindStudio } from "../change-pictures.mjs";
2
4
  import { CommentFiles } from "./files.mjs";
5
+ import { describeAt } from "../thread-source.mjs";
3
6
  //#region src/server/comments/studio-files.d.ts
7
+ export type DescribedInStudio = ReturnType<typeof describeAt> & {
8
+ flowSpec?: string;
9
+ moreFlowSpecs?: string[];
10
+ };
11
+ /**
12
+ * Threads as an agent reads them, by id: where each is in the code, its
13
+ * file's title, and its section's spec to read first.
14
+ */
15
+ export declare function describeInStudio(root: string, threads: ThreadWithPrototype[], show?: (path: string) => string): Promise<Map<string, DescribedInStudio>>;
4
16
  /** The comment tools' files in the studio whose content folder is `root`. */
5
- export declare function studioCommentFiles({ designSystem, from, inRoot, root }: {
17
+ export declare function studioCommentFiles({ designSystem, findStudio, from, inRoot, root }: {
6
18
  /** The project's design system, as it is when an agent closes a comment. */
7
19
  designSystem: () => Promise<ResolvedDesignSystem | undefined>;
20
+ findStudio: FindStudio;
8
21
  /** Where the agent works: the files its problems name are shown from here. */
9
22
  from: string;
10
23
  /** A file in the studio's folder, as the agent opens it from where it works. */
@@ -1,55 +1,67 @@
1
1
  import { shownFrom } from "../../paths.mjs";
2
2
  import { prepareState, readFocus, studioState } from "../state.mjs";
3
- import { ownTitle, prototypeTitle } from "../../content/prototypes.mjs";
3
+ import { prototypeTitles } from "../../content/prototypes.mjs";
4
4
  import { threadFlowSpec } from "../../content/flow-specs.mjs";
5
5
  import { changePlaceFor } from "../thread-place.mjs";
6
6
  import { someOf } from "../tools/result.mjs";
7
7
  import { openPageFirst } from "../open-page.mjs";
8
8
  import { isWatching } from "../../harness/src/events/channel.mjs";
9
9
  import { agentsPlace } from "../agents-place.mjs";
10
+ import { pictureBefore } from "../change-pictures.mjs";
10
11
  import { describeAt, placeThreads } from "../thread-source.mjs";
11
12
  import { groupWork } from "../work-groups.mjs";
12
- import { errorsBeforeClose, filesChangedSincePickup } from "../close-check.mjs";
13
+ import { errorsBeforeClose, filesChangedSincePickup, lookAtChange } from "../close-check.mjs";
13
14
  import { onCopyIfAny, settleCopy, yoursGroups } from "../own-copies.mjs";
14
15
  import { writeFile } from "node:fs/promises";
15
16
  //#region src/server/comments/studio-files.ts
16
17
  /** The longest a studio's `watch` waits, in seconds. */
17
18
  const STUDIO_LONGEST_WAIT = 1800;
18
- /** The comment tools' files in the studio whose content folder is `root`. */
19
- function studioCommentFiles({ designSystem, from, inRoot, root }) {
20
- /**
21
- * A thread as an agent reads it: where its element is in the code, the
22
- * title of its file, and the spec of the section it is on, by its path, to
23
- * read before answering it, when that section has one.
24
- */
25
- const describe = async (thread) => {
26
- const place = (await placeThreads(root, [thread])).get(thread.id);
27
- const fileTitle = ownTitle(thread.slug, await prototypeTitle(root, thread.slug).catch(() => thread.slug));
28
- const described = describeAt(thread, {
29
- ...place,
30
- fileTitle
31
- }, inRoot);
19
+ /**
20
+ * Threads as an agent reads them, by id: where each is in the code, its
21
+ * file's title, and its section's spec to read first.
22
+ */
23
+ async function describeInStudio(root, threads, show = (path) => path) {
24
+ const places = await placeThreads(root, threads);
25
+ const titleOf = await prototypeTitles(root, threads);
26
+ const described = /* @__PURE__ */ new Map();
27
+ for (const thread of threads) {
28
+ const at = describeAt(thread, {
29
+ ...places.get(thread.id),
30
+ fileTitle: titleOf(thread)
31
+ }, show);
32
32
  const flowSpec = await threadFlowSpec(root, thread).catch(() => void 0);
33
- if (!flowSpec) return described;
34
- const withSpec = {
35
- ...described,
36
- flowSpec: inRoot(flowSpec.file)
37
- };
38
- if (flowSpec.more) withSpec.moreFlowSpecs = someOf(flowSpec.more.map(inRoot));
39
- return withSpec;
40
- };
33
+ described.set(thread.id, flowSpec ? {
34
+ ...at,
35
+ flowSpec: show(flowSpec.file),
36
+ ...flowSpec.more && { moreFlowSpecs: someOf(flowSpec.more.map(show)) }
37
+ } : at);
38
+ }
39
+ return described;
40
+ }
41
+ /** The comment tools' files in the studio whose content folder is `root`. */
42
+ function studioCommentFiles({ designSystem, findStudio, from, inRoot, root }) {
41
43
  return {
42
- beforeDone: async (thread) => {
43
- const broken = await errorsBeforeClose(root, await onCopyIfAny(root, thread), await designSystem(), from);
44
- return broken.length > 0 ? {
44
+ beforeDone: async (thread, taken) => {
45
+ const changed = await onCopyIfAny(root, thread);
46
+ const broken = await errorsBeforeClose(root, changed, await designSystem(), from);
47
+ if (broken.length > 0) return {
45
48
  broken,
46
49
  files: []
47
- } : {
50
+ };
51
+ const look = await lookAtChange(changed, {
52
+ findStudio,
53
+ taken
54
+ });
55
+ return {
48
56
  broken,
49
- files: await filesChangedSincePickup(root, thread)
57
+ files: await filesChangedSincePickup(root, thread),
58
+ ...look && { look }
50
59
  };
51
60
  },
52
- describe,
61
+ describe: async (thread) => {
62
+ const [only] = (await describeInStudio(root, [thread], inRoot)).values();
63
+ return only;
64
+ },
53
65
  describeClosed: async (thread) => {
54
66
  const places = await placeThreads(root, [thread]);
55
67
  return describeAt(thread, places.get(thread.id), inRoot);
@@ -68,6 +80,7 @@ function studioCommentFiles({ designSystem, from, inRoot, root }) {
68
80
  return "place" in found ? found : { unplaced: `\`where\` names no place on the canvas, so it was left out: ${found.problem}` };
69
81
  },
70
82
  longestWait: STUDIO_LONGEST_WAIT,
83
+ pictureBefore: (threads) => pictureBefore(root, threads, findStudio),
71
84
  settle: async (thread) => {
72
85
  const settled = await settleCopy(root, thread).catch(() => void 0);
73
86
  return settled && "placed" in settled ? settled.placed : void 0;
@@ -77,4 +90,4 @@ function studioCommentFiles({ designSystem, from, inRoot, root }) {
77
90
  };
78
91
  }
79
92
  //#endregion
80
- export { studioCommentFiles };
93
+ export { describeInStudio, studioCommentFiles };
@@ -23,8 +23,8 @@ export declare function commentTools(context: ToolContext): (Tool<{
23
23
  prototype: z.ZodString;
24
24
  message: z.ZodString;
25
25
  for: z.ZodDefault<z.ZodEnum<{
26
- people: "people";
27
26
  agent: "agent";
27
+ people: "people";
28
28
  }>>;
29
29
  frame: z.ZodOptional<z.ZodString>;
30
30
  view: z.ZodOptional<z.ZodString>;
@@ -43,6 +43,7 @@ function workspaceFiles({ longestWait = 300, paths }) {
43
43
  landing: () => Promise.resolve({ unplaced: NO_WORKSPACE_PLACES }),
44
44
  longestWait,
45
45
  settle: () => Promise.resolve(void 0),
46
+ pictureBefore: () => Promise.resolve(),
46
47
  watching: () => Promise.resolve(true),
47
48
  yours: (groups) => Promise.resolve(groups)
48
49
  };
@@ -21,6 +21,7 @@ import { eventsForFile, studioEvent } from "../shared/studio-events.mjs";
21
21
  import { eventHub, studioRequests } from "./requests.mjs";
22
22
  import { existsSync, realpathSync } from "node:fs";
23
23
  import { basename, dirname, join, relative, sep } from "node:path";
24
+ import { readdir } from "node:fs/promises";
24
25
  import { isCSSRequest } from "vite";
25
26
  //#region src/server/dev-server.ts
26
27
  const PRESENCE_TICK_MS = 3e4;
@@ -77,6 +78,38 @@ const isSvgRequest = (url = "") => {
77
78
  return false;
78
79
  }
79
80
  };
81
+ const reportAsAdded = (watcher, path) => {
82
+ watcher.add.call(watcher, path, void 0, true);
83
+ };
84
+ const namesInFolderIfStillThere = (folder) => readdir(folder).catch(() => []);
85
+ const watcherClosed = (watcher) => watcher.listenerCount("addDir") === 0;
86
+ const catchUpNewFolders = (watcher) => {
87
+ const settling = /* @__PURE__ */ new Set();
88
+ let timer;
89
+ const catchUp = async (folders) => {
90
+ const listings = await Promise.all(folders.map(async (folder) => ({
91
+ folder,
92
+ names: await namesInFolderIfStillThere(folder)
93
+ })));
94
+ const watchedAfterReading = watcher.getWatched();
95
+ for (const { folder, names } of listings) {
96
+ const known = new Set(watchedAfterReading[folder]);
97
+ for (const name of names) {
98
+ if (known.has(name) || watcherClosed(watcher)) continue;
99
+ reportAsAdded(watcher, join(folder, name));
100
+ }
101
+ }
102
+ };
103
+ watcher.on("addDir", (folder) => {
104
+ settling.add(folder);
105
+ clearTimeout(timer);
106
+ timer = setTimeout(() => {
107
+ const folders = [...settling];
108
+ settling.clear();
109
+ if (!watcherClosed(watcher)) catchUp(folders).catch(() => void 0);
110
+ }, SETTLE_MS);
111
+ });
112
+ };
80
113
  function studioDev(project) {
81
114
  const { content } = project;
82
115
  const prototypes = prototypesDir(content);
@@ -144,6 +177,7 @@ function studioDev(project) {
144
177
  ...icons
145
178
  ] : [content];
146
179
  server.watcher.add(configFile ? [...studioPaths, configFile] : studioPaths);
180
+ if (!server.watcher.options.useFsEvents) catchUpNewFolders(server.watcher);
147
181
  const onFile = (file) => {
148
182
  if (workspaceFiles.has(file)) {
149
183
  events.send(studioEvent.workspace());
@@ -1,9 +1,8 @@
1
1
  import { youOf } from "../shared/studio-routes.mjs";
2
- import { canvasFrames, stepsOf } from "../shared/canvas-core.mjs";
3
- import { targetFrameKey } from "../shared/threads-core.mjs";
2
+ import { stepsOf } from "../shared/canvas-core.mjs";
4
3
  import { prototypePaths, viewFiles } from "../content/prototypes.mjs";
5
4
  import { openThreads } from "../content/thread-module.mjs";
6
- import { currentPerson, identify, joinCurrentPerson, placeViewFrame, readCanvas } from "../content/content.mjs";
5
+ import { cellOfFrame, currentPerson, identify, joinCurrentPerson, placeViewFrame, readCanvas } from "../content/content.mjs";
7
6
  import { groupWork } from "./work-groups.mjs";
8
7
  import { existsSync } from "node:fs";
9
8
  import { dirname, join, relative, resolve, sep } from "node:path";
@@ -30,26 +29,8 @@ const viewOf = (thread) => (thread.target.kind === "element" || thread.target.ki
30
29
  frame: thread.target.frame,
31
30
  uid: thread.target.uid
32
31
  } : void 0;
33
- /**
34
- * The step a frame is at in its row, found by its uid first, then its key;
35
- * none when it is gone.
36
- */
37
- const cellOf = async (slug, target, root) => {
38
- const canvas = await readCanvas(slug, root);
39
- const frames = canvasFrames(canvas).map(({ key, frame }) => ({
40
- key,
41
- uid: frame.uid
42
- }));
43
- const [section, row, frame] = (targetFrameKey(target, frames) ?? target.frame).split("/");
44
- const found = canvas.sections.find((each) => each.id === section)?.rows.find((each) => each.id === row);
45
- const at = found?.frames.findIndex((each) => each.id === frame) ?? -1;
46
- if (!(found && section && row) || at === -1) return;
47
- return {
48
- section,
49
- row,
50
- step: stepsOf(found.frames)[at] ?? at + 1
51
- };
52
- };
32
+ /** The cell a frame is in now (cellOfFrame); none when it is gone. */
33
+ const cellOf = async (slug, target, root) => cellOfFrame(await readCanvas(slug, root), target);
53
34
  /**
54
35
  * Whether the person started a thread: by their slug where it says, else
55
36
  * by their name, as messages from before had only that. Never an agent's.
@@ -3,6 +3,7 @@ import { EXTENSION_DIR, PACKAGE_ROOT, runningVersion } from "../paths.mjs";
3
3
  import { EXTENSION_FILE, NOT_RECOGNISED, STALE_PICTURE_HEADER } from "../shared/studio-routes.mjs";
4
4
  import { projectId } from "./project-id.mjs";
5
5
  import { isSlug, prototypePage, splitPrototypePath, viewInFrame } from "../shared/prototypes-core.mjs";
6
+ import { THREAD_ID_RE } from "../shared/threads-core.mjs";
6
7
  import { writeFocus } from "./state.mjs";
7
8
  import { isTeammate, openPresence } from "./presence.mjs";
8
9
  import { isAllowedRequest, isFromThisMachine, isLoopbackHost } from "./allowed-request.mjs";
@@ -48,10 +49,13 @@ import { exportInChild } from "./export/run.mjs";
48
49
  import { openPlace } from "../shared/open-page-core.mjs";
49
50
  import { NotAnOldSessionError, connectedAgents, isWatching, setWatching, stopAgentServer, trackAgents } from "../harness/src/events/channel.mjs";
50
51
  import { agentsPlace } from "./agents-place.mjs";
52
+ import { isMoment } from "../shared/change-pictures-core.mjs";
53
+ import { framePictures, latestAround, latestChange } from "./pictures.mjs";
51
54
  import { codebaseSkills, readCommandMenu, skillFolders, writeCommandMenu } from "./command-settings.mjs";
52
55
  import { loadPeople } from "./people.mjs";
53
56
  import { AvatarRefusedError, removeAvatar, writeAvatar } from "./avatars.mjs";
54
57
  import { readBuildSettings, writeBuildSettings } from "./build-settings.mjs";
58
+ import { changePictureStore } from "./change-picture-store.mjs";
55
59
  import { notesSince } from "./changelog.mjs";
56
60
  import { noDesktop } from "../desktop/src/index.mjs";
57
61
  import { eventMessage, studioEvent } from "../shared/studio-events.mjs";
@@ -61,7 +65,6 @@ import { features } from "./features.mjs";
61
65
  import { gitAskBody } from "./git-asks.mjs";
62
66
  import { settlePaused, undoPaused } from "./git-paused.mjs";
63
67
  import { currentActivity, machineState, markActivity, ranBeforeThis, updateMachine } from "./machine-update.mjs";
64
- import { framePictures, latestAround, latestChange } from "./pictures.mjs";
65
68
  import { readPreferences, savePreferences } from "./preferences.mjs";
66
69
  import { pullBaseAndUpdate, syncAndUpdate } from "./sync-install.mjs";
67
70
  import { UpdateStoppedError, updateStudio } from "./update-studio.mjs";
@@ -76,6 +79,7 @@ import { readFile } from "node:fs/promises";
76
79
  const PREFIX = "/__studio/";
77
80
  const UPDATE_WAIT_MS = 3e3;
78
81
  const TRAILING_SLASH_RE = /\/$/u;
82
+ const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/u;
79
83
  const METHODS = [
80
84
  "GET",
81
85
  "POST",
@@ -495,6 +499,7 @@ async function pasteSnapshots(context) {
495
499
  frame
496
500
  })),
497
501
  images: pasted.images,
502
+ ...pasted.sizedByScripts && { sizedByScripts: pasted.sizedByScripts },
498
503
  ...large && { large: true }
499
504
  };
500
505
  }
@@ -616,12 +621,53 @@ async function screenshotView(context) {
616
621
  return new Reply(200, (await shotOf(context)).image, "image/png");
617
622
  }
618
623
  async function snapshotOfView(context) {
619
- const { image, problems } = await shotOf(context);
624
+ const { image, looks = { blank: false }, problems } = await shotOf(context);
620
625
  return {
621
626
  image: image.toString("base64"),
627
+ looks,
622
628
  problems
623
629
  };
624
630
  }
631
+ const threadIdIn = (url) => {
632
+ const id = url.searchParams.get("thread") ?? "";
633
+ if (!THREAD_ID_RE.test(id)) throw new Problems(400, ["Say which comment, by its id."]);
634
+ return id;
635
+ };
636
+ const momentIn = (url) => {
637
+ const moment = url.searchParams.get("moment");
638
+ if (!isMoment(moment)) throw new Problems(400, ["Say which picture: before or after."]);
639
+ return moment;
640
+ };
641
+ const loadChangePictures = ({ changePictures, url }) => changePictures.kept(threadIdIn(url));
642
+ function serveChangePicture({ changePictures, response, url }) {
643
+ const image = changePictures.image(threadIdIn(url), momentIn(url));
644
+ if (!image) throw new Problems(404, ["That comment has no such picture."]);
645
+ response.setHeader("Cache-Control", "no-store");
646
+ response.setHeader("X-Content-Type-Options", "nosniff");
647
+ return new Reply(200, image, "image/png");
648
+ }
649
+ const PNG_SIGNATURE = Buffer.from([
650
+ 137,
651
+ 80,
652
+ 78,
653
+ 71,
654
+ 13,
655
+ 10,
656
+ 26,
657
+ 10
658
+ ]);
659
+ function keepChangePicture({ body, changePictures, url }) {
660
+ const data = body?.data;
661
+ if (typeof data !== "string" || !BASE64_RE.test(data)) throw new Problems(400, ["Send the picture's bytes in base64 as data."]);
662
+ const image = Buffer.from(data, "base64");
663
+ if (!image.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) throw new Problems(415, ["A comment's picture is a PNG."]);
664
+ changePictures.keep(threadIdIn(url), momentIn(url), image);
665
+ return {};
666
+ }
667
+ function dropChangePicture({ changePictures, url }) {
668
+ changePictures.drop(threadIdIn(url), momentIn(url));
669
+ return {};
670
+ }
625
671
  const pictures = framePictures();
626
672
  /**
627
673
  * A picture kept on disk outlives the studio that made it, so it has to be
@@ -1111,7 +1157,6 @@ async function saveTeamDevices({ project, body, events }) {
1111
1157
  problems: []
1112
1158
  };
1113
1159
  }
1114
- const BASE64_RE = /^[A-Za-z0-9+/]*={0,2}$/u;
1115
1160
  /**
1116
1161
  * The icon is served under its own address, so it is never a page: opened
1117
1162
  * directly, an SVG runs nothing and loads nothing.
@@ -1322,6 +1367,13 @@ const ROUTES = {
1322
1367
  screenshot: { POST: screenshotView },
1323
1368
  snapshot: { POST: snapshotOfView },
1324
1369
  picture: { POST: pictureOfView },
1370
+ "change-pictures": { GET: loadChangePictures },
1371
+ "change-picture": {
1372
+ limit: MAX_CAPTURE_BYTES,
1373
+ GET: serveChangePicture,
1374
+ PUT: keepChangePicture,
1375
+ DELETE: dropChangePicture
1376
+ },
1325
1377
  agents: { GET: listConnectedAgents },
1326
1378
  "agent-stop": { POST: stopOldAgent },
1327
1379
  edited: { GET: ({ project }) => lastEdited(project.content) },
@@ -1451,6 +1503,7 @@ function studioRequests({ project, threads, events, format = formatter(project.c
1451
1503
  agents
1452
1504
  });
1453
1505
  const pageBase = base.replace(TRAILING_SLASH_RE, "");
1506
+ const changePictures = changePictureStore();
1454
1507
  return async (request, response) => {
1455
1508
  const url = new URL(request.url ?? "/", "http://studio.local");
1456
1509
  if (!url.pathname.startsWith(PREFIX)) return false;
@@ -1460,6 +1513,7 @@ function studioRequests({ project, threads, events, format = formatter(project.c
1460
1513
  if (!isRouteName(name)) throw new Problems(404, ["Not found."]);
1461
1514
  const route = ROUTES[name];
1462
1515
  const answered = await answer(route, {
1516
+ changePictures,
1463
1517
  project,
1464
1518
  threads,
1465
1519
  events,
@@ -42,7 +42,8 @@ export declare const RESPONSE_BUDGETS: {
42
42
  /** What changed since the last call, after a tool's answer. */
43
43
  readonly notice: 2500;
44
44
  };
45
- /** What a value comes to as a tool returns it: JSON, indented. */
45
+ /** A value as a tool sends it, and as its size is measured: compact JSON. */
46
+ export declare const jsonText: (value: unknown) => string;
46
47
  export declare const sizeOf: (value: unknown) => number;
47
48
  /** "1 thread", "1,200 threads"; `many` for a word that takes more than an s ("boxes"). */
48
49
  export declare const plural: (number: number, word: string, many?: string) => string;
@@ -42,8 +42,9 @@ const RESPONSE_BUDGETS = {
42
42
  /** What changed since the last call, after a tool's answer. */
43
43
  notice: NOTICE_BUDGET
44
44
  };
45
- /** What a value comes to as a tool returns it: JSON, indented. */
46
- const sizeOf = (value) => JSON.stringify(value, null, 2)?.length ?? 0;
45
+ /** A value as a tool sends it, and as its size is measured: compact JSON. */
46
+ const jsonText = (value) => JSON.stringify(value) ?? "";
47
+ const sizeOf = (value) => jsonText(value).length;
47
48
  const count = (number) => number.toLocaleString("en");
48
49
  /** "1 thread", "1,200 threads"; `many` for a word that takes more than an s ("boxes"). */
49
50
  const plural = (number, word, many = `${word}s`) => `${count(number)} ${number === 1 ? word : many}`;
@@ -76,4 +77,4 @@ function fitting(items, room, size = sizeOf) {
76
77
  };
77
78
  }
78
79
  //#endregion
79
- export { ADDED_BUDGET, BRIEF_BUDGET, NOTICE_BUDGET, ORDINARY_BRIEF, PEOPLES_WORDS, RESPONSE_BUDGETS, cutText, firstOf, fitting, plural, sizeOf };
80
+ export { ADDED_BUDGET, BRIEF_BUDGET, NOTICE_BUDGET, ORDINARY_BRIEF, PEOPLES_WORDS, RESPONSE_BUDGETS, cutText, firstOf, fitting, jsonText, plural, sizeOf };
@@ -11,12 +11,19 @@ export interface RosterEntry {
11
11
  role: RosterRole;
12
12
  /** When it joined. */
13
13
  since: string;
14
- /** When its process started, as ps says: which process `pid` was. */
14
+ /**
15
+ * When its process started, as an older Dex wrote it: as ps said it in
16
+ * the time zone and language that Dex ran in (see processNow).
17
+ */
15
18
  started?: string;
19
+ /** When its process started, as startedAt says: which process `pid` was. */
20
+ startedUtc?: string;
16
21
  /** The supervisor that runs a development server, when one does. */
17
22
  supervisor?: number;
18
- /** When the supervisor's process started, as ps says. */
23
+ /** When the supervisor's process started, as an older Dex wrote it. */
19
24
  supervisorStarted?: string;
25
+ /** When the supervisor's process started, as startedAt says. */
26
+ supervisorStartedUtc?: string;
20
27
  /** The Dex it runs. */
21
28
  version?: string;
22
29
  }
@@ -26,9 +33,13 @@ export declare const FROM_APP_ENV = "DEX_FROM_APP";
26
33
  export declare function isAlive(pid: number): boolean;
27
34
  /**
28
35
  * When process `pid` started, as ps says: with its pid, which process it
29
- * is. Undefined where there is no ps (Windows) or it can't say.
36
+ * is. Asked in UTC and the C locale: ps writes the time in the time zone
37
+ * and language of whoever asks, and the Dexes on one roster start from
38
+ * different ones (a person's terminal, an agent's app), which must all read
39
+ * one start the same. Undefined where there is no ps (Windows) or it can't
40
+ * say.
30
41
  */
31
- export declare function startedAt(pid: number): Promise<string | undefined>;
42
+ export declare const startedAt: (pid: number) => Promise<string | undefined>;
32
43
  /** What a process in the roster can change about itself, or end. */
33
44
  export interface Membership {
34
45
  leave: () => Promise<void>;
@@ -65,10 +76,10 @@ export declare function askOthersToRestart(content: string, id: string, version:
65
76
  /**
66
77
  * Stop other Dexes: ask every other development server for the project
67
78
  * `id` names (projectId) to stop, through its supervisor when it has one,
68
- * as Ctrl+C does. Only one still the process that joined (an entry whose
69
- * pid is another process's now is dropped) and answering on its port as
70
- * this project's Dex; nothing else is signalled. Answers how many were
71
- * asked.
79
+ * as Ctrl+C does. Only one known to be the process that joined (an entry
80
+ * whose pid is another process's now is dropped; one that can't be told
81
+ * stays, unasked) and answering on its port as this project's Dex; nothing
82
+ * else is signalled. Answers how many were asked.
72
83
  */
73
84
  export declare function stopOthers(content: string, id: string, { self }?: {
74
85
  self?: number;