@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
@@ -0,0 +1,244 @@
1
+ import type { ViewShot } from "../content/screenshot.ts";
2
+ import {
3
+ SnapshotError,
4
+ type SnapshotRequest,
5
+ snapshotView,
6
+ } from "../content/snapshot-client.ts";
7
+ import {
8
+ type KeptPictures,
9
+ MOMENTS,
10
+ type Moment,
11
+ } from "../shared/change-pictures-core.ts";
12
+ import { isFiniteNumber, isRecord } from "../shared/checks.ts";
13
+ import { framePage, prototypeFiles } from "../shared/prototypes-core.ts";
14
+ import { claimOf, type ThreadWithPrototype } from "../shared/threads-core.ts";
15
+ import { latestChange } from "./pictures.ts";
16
+ import { type StudioFor, whyNotRunning } from "./studio-for.ts";
17
+
18
+ export type FindStudio = () => Promise<StudioFor>;
19
+
20
+ export type Picture = ViewShot | { missing: string };
21
+
22
+ export type PicturesTaken = Map<string, Promise<Picture>>;
23
+
24
+ const NEVER_RENDERED = 409;
25
+
26
+ export const startedAt = (thread: ThreadWithPrototype): number =>
27
+ Date.parse(claimOf(thread)?.at ?? thread.created);
28
+
29
+ const viewOf = ({ target }: ThreadWithPrototype): string | undefined =>
30
+ target.kind === "element" || target.kind === "frame"
31
+ ? target.view
32
+ : undefined;
33
+
34
+ export function pictureRequest(
35
+ thread: ThreadWithPrototype
36
+ ): SnapshotRequest | undefined {
37
+ const view = viewOf(thread);
38
+ const { target } = thread;
39
+
40
+ if (!view || (target.kind !== "element" && target.kind !== "frame")) {
41
+ return;
42
+ }
43
+
44
+ const search = new URLSearchParams(target.params ?? {});
45
+
46
+ const href = framePage(
47
+ thread.slug,
48
+ view,
49
+ search.size > 0 ? `?${search}` : ""
50
+ );
51
+
52
+ return href
53
+ ? {
54
+ href,
55
+ viewport: target.viewport ?? "desktop",
56
+ scheme: "light",
57
+ scale: 1,
58
+ }
59
+ : undefined;
60
+ }
61
+
62
+ export async function viewChangedAt(
63
+ root: string,
64
+ thread: ThreadWithPrototype
65
+ ): Promise<number> {
66
+ const folder = prototypeFiles(thread.slug)?.folder;
67
+ const view = viewOf(thread);
68
+
69
+ return folder && view
70
+ ? await latestChange(root, folder, view).catch(
71
+ () => Number.POSITIVE_INFINITY
72
+ )
73
+ : Number.POSITIVE_INFINITY;
74
+ }
75
+
76
+ export async function runningStudio(
77
+ findStudio: FindStudio
78
+ ): Promise<{ url: string } | { missing: string }> {
79
+ try {
80
+ const studio = await findStudio();
81
+
82
+ return studio.kind === "running"
83
+ ? { url: studio.url }
84
+ : { missing: whyNotRunning(studio).why };
85
+ } catch (error) {
86
+ return { missing: error instanceof Error ? error.message : String(error) };
87
+ }
88
+ }
89
+
90
+ async function takePicture(
91
+ studio: string,
92
+ request: SnapshotRequest
93
+ ): Promise<Picture> {
94
+ try {
95
+ return await snapshotView(studio, request);
96
+ } catch (error) {
97
+ if (error instanceof SnapshotError && error.status === NEVER_RENDERED) {
98
+ return {
99
+ missing: `Dex couldn't render the view's page: ${error.message}`,
100
+ };
101
+ }
102
+
103
+ return { missing: error instanceof Error ? error.message : String(error) };
104
+ }
105
+ }
106
+
107
+ export function takePictureOnce(
108
+ taken: PicturesTaken,
109
+ studio: string,
110
+ request: SnapshotRequest
111
+ ): Promise<Picture> {
112
+ const page = JSON.stringify(request);
113
+ const known = taken.get(page);
114
+
115
+ if (known) {
116
+ return known;
117
+ }
118
+
119
+ const picture = takePicture(studio, request);
120
+ taken.set(page, picture);
121
+
122
+ return picture;
123
+ }
124
+
125
+ const pictureOf = (studio: string, id: string, moment: Moment): string =>
126
+ `${studio}/__studio/change-picture?${new URLSearchParams({ thread: id, moment })}`;
127
+
128
+ async function askStudio(url: string, init?: RequestInit): Promise<Response> {
129
+ const response = await fetch(url, init);
130
+
131
+ if (!response.ok) {
132
+ const said = await response.text();
133
+ throw new Error(`Dex answered ${response.status}: ${said.slice(0, 200)}`);
134
+ }
135
+
136
+ return response;
137
+ }
138
+
139
+ export async function keptPictures(
140
+ studio: string,
141
+ id: string
142
+ ): Promise<KeptPictures> {
143
+ const response = await askStudio(
144
+ `${studio}/__studio/change-pictures?${new URLSearchParams({ thread: id })}`
145
+ );
146
+
147
+ const said: unknown = await response.json();
148
+
149
+ return isRecord(said)
150
+ ? Object.fromEntries(
151
+ MOMENTS.flatMap((moment) => {
152
+ const at = said[moment];
153
+
154
+ return isFiniteNumber(at) ? [[moment, at]] : [];
155
+ })
156
+ )
157
+ : {};
158
+ }
159
+
160
+ export async function keepPicture(
161
+ studio: string,
162
+ id: string,
163
+ moment: Moment,
164
+ image: Buffer
165
+ ): Promise<void> {
166
+ await askStudio(pictureOf(studio, id, moment), {
167
+ method: "PUT",
168
+ headers: { "content-type": "application/json" },
169
+ body: JSON.stringify({ data: image.toString("base64") }),
170
+ });
171
+ }
172
+
173
+ export async function dropPicture(
174
+ studio: string,
175
+ id: string,
176
+ moment: Moment
177
+ ): Promise<void> {
178
+ await askStudio(pictureOf(studio, id, moment), { method: "DELETE" });
179
+ }
180
+
181
+ const lastWordAt = (thread: ThreadWithPrototype): number =>
182
+ Math.max(
183
+ Date.parse(thread.created),
184
+ ...thread.messages.map(({ at }) => Date.parse(at)),
185
+ thread.resolution ? Date.parse(thread.resolution.at) : 0
186
+ );
187
+
188
+ async function beforeFromThisStart(
189
+ studio: string,
190
+ thread: ThreadWithPrototype
191
+ ): Promise<boolean> {
192
+ const { before } = await keptPictures(studio, thread.id);
193
+
194
+ return before !== undefined && before > lastWordAt(thread);
195
+ }
196
+
197
+ async function pictureOneBefore(
198
+ root: string,
199
+ thread: ThreadWithPrototype,
200
+ studio: string,
201
+ taken: PicturesTaken
202
+ ): Promise<void> {
203
+ const request = pictureRequest(thread);
204
+
205
+ if (!request || (await beforeFromThisStart(studio, thread))) {
206
+ return;
207
+ }
208
+
209
+ await dropPicture(studio, thread.id, "before");
210
+ const picture = await takePictureOnce(taken, studio, request);
211
+
212
+ if (
213
+ "missing" in picture ||
214
+ (await viewChangedAt(root, thread)) > startedAt(thread)
215
+ ) {
216
+ return;
217
+ }
218
+
219
+ await keepPicture(studio, thread.id, "before", picture.image);
220
+ }
221
+
222
+ export async function pictureBefore(
223
+ root: string,
224
+ threads: ThreadWithPrototype[],
225
+ findStudio: FindStudio
226
+ ): Promise<void> {
227
+ if (!threads.some((thread) => pictureRequest(thread))) {
228
+ return;
229
+ }
230
+
231
+ const studio = await runningStudio(findStudio);
232
+
233
+ if ("missing" in studio) {
234
+ return;
235
+ }
236
+
237
+ const taken: PicturesTaken = new Map();
238
+
239
+ await Promise.all(
240
+ threads.map((thread) =>
241
+ pictureOneBefore(root, thread, studio.url, taken).catch(() => undefined)
242
+ )
243
+ );
244
+ }
@@ -21,8 +21,19 @@ import {
21
21
  } from "../content/prototype-checks.ts";
22
22
  import { shownFrom } from "../paths.ts";
23
23
  import { babel } from "../setup/design-system-checks.ts";
24
+ import type { PageLooks } from "../shared/page-looks.ts";
24
25
  import { prototypeFiles } from "../shared/prototypes-core.ts";
25
- import { claimOf, type ThreadWithPrototype } from "../shared/threads-core.ts";
26
+ import type { ThreadWithPrototype } from "../shared/threads-core.ts";
27
+ import {
28
+ dropPicture,
29
+ type FindStudio,
30
+ keepPicture,
31
+ type PicturesTaken,
32
+ pictureRequest,
33
+ runningStudio,
34
+ startedAt,
35
+ takePictureOnce,
36
+ } from "./change-pictures.ts";
26
37
  import { stylesheetOf } from "./thread-source.ts";
27
38
  import { groupWork } from "./work-groups.ts";
28
39
 
@@ -130,10 +141,6 @@ async function prototypeCode(
130
141
  );
131
142
  }
132
143
 
133
- /** When the thread was picked up: its claim's 👀, else when it was posted. */
134
- const pickedUpAt = (thread: ThreadWithPrototype): number =>
135
- Date.parse(claimOf(thread)?.at ?? thread.created);
136
-
137
144
  /**
138
145
  * The prototype's code and style that changed since the thread was picked
139
146
  * up, absolute.
@@ -148,7 +155,7 @@ async function pathsChangedSincePickup(
148
155
  return [];
149
156
  }
150
157
 
151
- const since = pickedUpAt(thread);
158
+ const since = startedAt(thread);
152
159
 
153
160
  const code = await prototypeCode(join(root, folder));
154
161
 
@@ -253,3 +260,59 @@ export async function errorsBeforeClose(
253
260
 
254
261
  return errors.flat();
255
262
  }
263
+
264
+ export interface ChangeLook {
265
+ missing?: string;
266
+ wrong: string[];
267
+ }
268
+
269
+ export const looksWrong = (looks: PageLooks | undefined): string[] => [
270
+ ...(looks?.error === undefined
271
+ ? []
272
+ : [`its view shows an error: ${looks.error}`]),
273
+ ...(looks?.blank ? ["its view renders nothing to see"] : []),
274
+ ];
275
+
276
+ export async function lookAtChange(
277
+ thread: ThreadWithPrototype,
278
+ { findStudio, taken }: { findStudio: FindStudio; taken: PicturesTaken }
279
+ ): Promise<ChangeLook | undefined> {
280
+ const request = pictureRequest(thread);
281
+
282
+ if (!request) {
283
+ return;
284
+ }
285
+
286
+ const studio = await runningStudio(findStudio);
287
+
288
+ if ("missing" in studio) {
289
+ return { missing: studio.missing, wrong: [] };
290
+ }
291
+
292
+ const picture = await takePictureOnce(taken, studio.url, request);
293
+
294
+ if ("missing" in picture) {
295
+ await dropPicture(studio.url, thread.id, "after").catch(() => undefined);
296
+
297
+ return { missing: picture.missing, wrong: [] };
298
+ }
299
+
300
+ const wrong = looksWrong(picture.looks);
301
+
302
+ if (wrong.length > 0) {
303
+ await dropPicture(studio.url, thread.id, "after").catch(() => undefined);
304
+
305
+ return { wrong };
306
+ }
307
+
308
+ try {
309
+ await keepPicture(studio.url, thread.id, "after", picture.image);
310
+
311
+ return { wrong };
312
+ } catch (error) {
313
+ const why = error instanceof Error ? error.message : String(error);
314
+ await dropPicture(studio.url, thread.id, "after").catch(() => undefined);
315
+
316
+ return { missing: `It couldn't be kept: ${why}`, wrong };
317
+ }
318
+ }
@@ -12,6 +12,8 @@ import type {
12
12
  ThreadWithPrototype,
13
13
  } from "../../shared/threads-core.ts";
14
14
  import type { AgentSession } from "../agent-session.ts";
15
+ import type { PicturesTaken } from "../change-pictures.ts";
16
+ import type { ChangeLook } from "../close-check.ts";
15
17
  import { type Outcome, refused } from "../outcome.ts";
16
18
  import type { CommentFiles } from "./files.ts";
17
19
 
@@ -22,7 +24,7 @@ import type { CommentFiles } from "./files.ts";
22
24
  */
23
25
  export interface AgentWork {
24
26
  /** What closing and answering need of the files the comments are on. */
25
- files: Pick<CommentFiles, "beforeDone" | "settle">;
27
+ files: Pick<CommentFiles, "beforeDone" | "pictureBefore" | "settle">;
26
28
  session: AgentSession;
27
29
  threads: Pick<ThreadModule, "find">;
28
30
  }
@@ -36,7 +38,13 @@ const noThread = (id: string): string => `No thread ${id}.`;
36
38
  * One another session holds is a conflict.
37
39
  */
38
40
  export async function claimComment(
39
- { session }: { session: Pick<AgentSession, "claim"> },
41
+ {
42
+ files,
43
+ session,
44
+ }: {
45
+ files: Pick<CommentFiles, "pictureBefore">;
46
+ session: Pick<AgentSession, "claim">;
47
+ },
40
48
  id: string
41
49
  ): Promise<Outcome<ThreadWithPrototype>> {
42
50
  const claimed = await session.claim(id);
@@ -45,9 +53,13 @@ export async function claimComment(
45
53
  return refused("not-found", [noThread(id)]);
46
54
  }
47
55
 
48
- return claimed.problems
49
- ? refused("conflict", claimed.problems)
50
- : { value: claimed.thread };
56
+ if (claimed.problems) {
57
+ return refused("conflict", claimed.problems);
58
+ }
59
+
60
+ files.pictureBefore([claimed.thread]).catch(() => undefined);
61
+
62
+ return { value: claimed.thread };
51
63
  }
52
64
 
53
65
  /**
@@ -56,14 +68,24 @@ export async function claimComment(
56
68
  * holds one or one is closed or gone, none is (a conflict).
57
69
  */
58
70
  export async function claimComments(
59
- { session }: { session: Pick<AgentSession, "claimAll"> },
71
+ {
72
+ files,
73
+ session,
74
+ }: {
75
+ files: Pick<CommentFiles, "pictureBefore">;
76
+ session: Pick<AgentSession, "claimAll">;
77
+ },
60
78
  group: ThreadWithPrototype[]
61
79
  ): Promise<Outcome<ThreadWithPrototype[]>> {
62
80
  const claimed = await session.claimAll(group);
63
81
 
64
- return claimed.problems
65
- ? refused("conflict", claimed.problems)
66
- : { value: claimed.thread };
82
+ if (claimed.problems) {
83
+ return refused("conflict", claimed.problems);
84
+ }
85
+
86
+ files.pictureBefore(claimed.thread).catch(() => undefined);
87
+
88
+ return { value: claimed.thread };
67
89
  }
68
90
 
69
91
  /**
@@ -92,6 +114,9 @@ export async function askOnComment(
92
114
  return { value: answered.thread };
93
115
  }
94
116
 
117
+ const heldForItsView = (id: string, { wrong }: ChangeLook): string =>
118
+ `${id}: not closed, ${wrong.join("; ")}. Fix it, then close it.`;
119
+
95
120
  /**
96
121
  * How an agent closes a comment it took: Done, with a summary of what
97
122
  * changed, or Not done, with why.
@@ -112,6 +137,7 @@ export interface Closing {
112
137
  */
113
138
  export interface Closed {
114
139
  copy?: string;
140
+ noPicture?: string;
115
141
  thread: ThreadWithPrototype;
116
142
  }
117
143
 
@@ -124,7 +150,8 @@ export interface Closed {
124
150
  */
125
151
  export async function closeComment(
126
152
  { files, session, threads }: AgentWork,
127
- { dismiss, id, summary, where }: Closing
153
+ { dismiss, id, summary, where }: Closing,
154
+ taken: PicturesTaken = new Map()
128
155
  ): Promise<Outcome<Closed>> {
129
156
  if (Boolean(summary) === Boolean(dismiss)) {
130
157
  return refused("invalid", [
@@ -133,6 +160,7 @@ export async function closeComment(
133
160
  }
134
161
 
135
162
  let changed: string[] = [];
163
+ let look: ChangeLook | undefined;
136
164
 
137
165
  if (summary) {
138
166
  const thread = await threads.find(id);
@@ -141,7 +169,7 @@ export async function closeComment(
141
169
  return refused("not-found", [noThread(id)]);
142
170
  }
143
171
 
144
- const checked = await files.beforeDone(thread);
172
+ const checked = await files.beforeDone(thread, taken);
145
173
 
146
174
  if (checked.broken.length > 0) {
147
175
  return refused("conflict", [
@@ -149,7 +177,12 @@ export async function closeComment(
149
177
  ]);
150
178
  }
151
179
 
180
+ if (checked.look?.wrong.length) {
181
+ return refused("conflict", [heldForItsView(id, checked.look)]);
182
+ }
183
+
152
184
  changed = checked.files;
185
+ ({ look } = checked);
153
186
  }
154
187
 
155
188
  const closed = await session.act(
@@ -174,5 +207,11 @@ export async function closeComment(
174
207
 
175
208
  const copy = await files.settle(closed.thread);
176
209
 
177
- return { value: { thread: closed.thread, ...(copy && { copy }) } };
210
+ return {
211
+ value: {
212
+ thread: closed.thread,
213
+ ...(copy && { copy }),
214
+ ...(look?.missing && { noPicture: look.missing }),
215
+ },
216
+ };
178
217
  }
@@ -12,6 +12,7 @@ import { z } from "zod";
12
12
 
13
13
  import { isString } from "../../shared/checks.ts";
14
14
  import type { ChangePlace } from "../../shared/threads-core.ts";
15
+ import type { PicturesTaken } from "../change-pictures.ts";
15
16
  import type { Problem } from "../outcome.ts";
16
17
  import {
17
18
  cutText,
@@ -72,23 +73,28 @@ const closeOne = async (
72
73
  id: string;
73
74
  summary?: string;
74
75
  where?: CanvasPlace;
75
- }
76
+ },
77
+ taken: PicturesTaken
76
78
  ) => {
77
79
  const landed =
78
80
  summary && where ? await landingOf(context, id, where) : undefined;
79
81
 
80
- const closed = await closeComment(context, {
81
- id,
82
- summary,
83
- dismiss,
84
- ...(landed?.place ? { where: landed.place } : undefined),
85
- });
82
+ const closed = await closeComment(
83
+ context,
84
+ {
85
+ id,
86
+ summary,
87
+ dismiss,
88
+ ...(landed?.place ? { where: landed.place } : undefined),
89
+ },
90
+ taken
91
+ );
86
92
 
87
93
  if (closed.problem) {
88
94
  return toAgent(closed.problem);
89
95
  }
90
96
 
91
- const { copy, thread } = closed.value;
97
+ const { copy, noPicture, thread } = closed.value;
92
98
 
93
99
  const { messages: _, ...shown } = describedIn(
94
100
  await context.files.describeClosed(thread),
@@ -100,6 +106,9 @@ const closeOne = async (
100
106
  ...(copy
101
107
  ? { copy: `Your copy's frame is under theirs: ${copy}.` }
102
108
  : undefined),
109
+ ...(noPicture
110
+ ? { noPicture: `Closed without a picture of the change: ${noPicture}` }
111
+ : undefined),
103
112
  ...(landed?.unplaced ? { unplaced: landed.unplaced } : undefined),
104
113
  };
105
114
  };
@@ -122,7 +131,7 @@ export function closeTool(context: CommentToolContext) {
122
131
  },
123
132
  title: "Close threads",
124
133
  description:
125
- "Close comments and requests, several at once: every thread you take ends here (or with `reply`); one you have not closed when your session ends goes back to waiting. The code each change touched is checked first (it parses, its stylesheet's braces close, it imports only what Dex allows): while it does not, the thread stays open and the result says why. Give each thread's `summary` as soon as its change is made, one short line on what changed (what people would look for, such as \"Header padding 24 to 12px; title now semibold\"): the thread gets ✅ and the line shows on it and as a note in Dex. Give `dismiss` instead to close one without acting on it (for example, the owner decided against it, or it is already so): it gets 🚫 with that line. A longer line is taken too, but Dex shows only its start until someone opens it, so keep it short. With a summary, give `where` too: the element your change landed on (a frame key or view, and a CSS selector, as `comment` takes them), above all when it is not the element the comment is on. People are taken there, and a pin marks it.",
134
+ "Close comments and requests, several at once: every thread you take ends here (or with `reply`); one you have not closed when your session ends goes back to waiting. The code each change touched is checked first (it parses, its stylesheet's braces close, it imports only what Dex allows), then, with Dex running, it pictures the comment's frame: while the code fails or the view shows an error or nothing, the thread stays open and the result says why, so a small change needs no `snapshot`. Give each thread's `summary` as soon as its change is made, one short line on what changed (what people would look for, such as \"Header padding 24 to 12px; title now semibold\"): the thread gets ✅ and the line shows on it and as a note in Dex. Give `dismiss` instead to close one without acting on it (for example, the owner decided against it, or it is already so): it gets 🚫 with that line. A longer line is taken too, but Dex shows only its start until someone opens it, so keep it short. With a summary, give `where` too: the element your change landed on (a frame key or view, and a CSS selector, as `comment` takes them), above all when it is not the element the comment is on. People are taken there, and a pin marks it.",
126
135
  inputSchema: {
127
136
  threads: z
128
137
  .array(
@@ -171,9 +180,10 @@ export function closeTool(context: CommentToolContext) {
171
180
  run: async (input) => {
172
181
  const closed: ClosedComment[] = [];
173
182
  const problems: string[] = [];
183
+ const taken: PicturesTaken = new Map();
174
184
 
175
185
  for (const request of input.threads) {
176
- const outcome = await closeOne(context, request);
186
+ const outcome = await closeOne(context, request, taken);
177
187
 
178
188
  if (isString(outcome)) {
179
189
  problems.push(outcome);
@@ -13,6 +13,8 @@ import type {
13
13
  ChangePlace,
14
14
  ThreadWithPrototype,
15
15
  } from "../../shared/threads-core.ts";
16
+ import type { PicturesTaken } from "../change-pictures.ts";
17
+ import type { ChangeLook } from "../close-check.ts";
16
18
  import type { PlacedThread } from "../open-page.ts";
17
19
  import type { Described } from "../thread-forms.ts";
18
20
  import type { CanvasPlace } from "../thread-place.ts";
@@ -26,8 +28,13 @@ export interface CommentFiles {
26
28
  * the comment, kept on the comment.
27
29
  */
28
30
  beforeDone: (
29
- thread: ThreadWithPrototype
30
- ) => Promise<{ broken: string[]; files: string[] }>;
31
+ thread: ThreadWithPrototype,
32
+ taken: PicturesTaken
33
+ ) => Promise<{
34
+ broken: string[];
35
+ files: string[];
36
+ look?: ChangeLook;
37
+ }>;
31
38
  /** A thread as an agent reads it, for work: where it is, its file's title, its spec. */
32
39
  describe: (thread: ThreadWithPrototype) => Promise<Described>;
33
40
  /** A thread as `close` gives it once closed: where it is, no more. */
@@ -50,6 +57,7 @@ export interface CommentFiles {
50
57
  ) => Promise<{ place: ChangePlace } | { unplaced: string }>;
51
58
  /** The longest `watch` waits here, in seconds. */
52
59
  longestWait: number;
60
+ pictureBefore: (threads: ThreadWithPrototype[]) => Promise<void>;
53
61
  /**
54
62
  * After an agent answers or closes a comment: the person's copy of
55
63
  * someone else's view, settled. The frame the copy now has in their row,
@@ -27,7 +27,7 @@ export type GroupClaim =
27
27
 
28
28
  /** What handing out needs: the session, its threads, and how they group. */
29
29
  export interface HandOutContext {
30
- files: Pick<CommentFiles, "group">;
30
+ files: Pick<CommentFiles, "group" | "pictureBefore">;
31
31
  session: Pick<AgentSession, "claimAll" | "id">;
32
32
  threads: Pick<ThreadModule, "list">;
33
33
  }
@@ -85,7 +85,7 @@ export function openHandOut({ files, session, threads }: HandOutContext) {
85
85
  * still wait for an agent, to hand out once what stopped it changes.
86
86
  */
87
87
  async claim(group: WorkGroup): Promise<GroupClaim> {
88
- const claimed = await claimComments({ session }, group.threads);
88
+ const claimed = await claimComments({ files, session }, group.threads);
89
89
 
90
90
  if (claimed.value) {
91
91
  return { won: claimed.value };