@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.
- package/CHANGELOG.md +31 -0
- package/app/canvas/canvas-commands.ts +2 -10
- package/app/canvas/canvas-context.tsx +11 -2
- package/app/canvas/canvas-document.ts +5 -1
- package/app/canvas/canvas-keys.ts +1 -1
- package/app/canvas/canvas-model.ts +195 -20
- package/app/canvas/canvas-scene.ts +176 -171
- package/app/canvas/canvas-ui.ts +4 -11
- package/app/canvas/canvas.css +159 -179
- package/app/canvas/change-pictures.tsx +156 -0
- package/app/canvas/comment-drafts.ts +31 -0
- package/app/canvas/comment-layer.tsx +125 -71
- package/app/canvas/comments.tsx +38 -2
- package/app/canvas/element-picker.ts +20 -0
- package/app/canvas/engine/canvas-gestures.ts +15 -3
- package/app/canvas/engine/canvas-store.ts +5 -0
- package/app/canvas/engine/canvas-view.tsx +22 -5
- package/app/canvas/find-bar.tsx +57 -41
- package/app/canvas/flow-canvas.tsx +147 -272
- package/app/canvas/frame-copies.ts +14 -17
- package/app/canvas/frame-drops.ts +15 -7
- package/app/canvas/frame-inspector.ts +192 -41
- package/app/canvas/frame-node.tsx +123 -75
- package/app/canvas/frame-resize.tsx +321 -83
- package/app/canvas/insert-hint.tsx +5 -15
- package/app/canvas/inspect-layer.tsx +73 -19
- package/app/canvas/label-action.tsx +13 -2
- package/app/canvas/layout.ts +233 -98
- package/app/canvas/live-page.ts +5 -0
- package/app/canvas/new-frame.ts +10 -25
- package/app/canvas/note-placing.ts +55 -84
- package/app/canvas/picked-box.tsx +5 -0
- package/app/canvas/picks-menu.tsx +3 -9
- package/app/canvas/readable-colour.ts +52 -0
- package/app/canvas/request-node.tsx +19 -10
- package/app/canvas/scrolling-page.ts +45 -0
- package/app/canvas/section-node.tsx +36 -53
- package/app/canvas/settle.ts +21 -0
- package/app/canvas/snapping.ts +96 -8
- package/app/canvas/spec-frame.tsx +8 -5
- package/app/canvas/spot-pins.tsx +15 -3
- package/app/canvas/stack-frame.tsx +13 -57
- package/app/canvas/stack-model.ts +5 -0
- package/app/canvas/stack-toggle.tsx +89 -0
- package/app/canvas/styles-layer.tsx +23 -43
- package/app/canvas/text-layer.tsx +26 -10
- package/app/canvas/thread-focus.tsx +18 -1
- package/app/canvas/tool-cursors.ts +2 -2
- package/app/canvas/toolbar-parts.tsx +48 -8
- package/app/canvas/toolbar.tsx +12 -10
- package/app/canvas/use-canvas-clipboard.tsx +13 -5
- package/app/canvas/use-reveal.ts +86 -0
- package/app/editor/extensions.ts +2 -0
- package/app/editor/line-break-caret.ts +57 -0
- package/app/git/branch-panel.tsx +61 -20
- package/app/i18n/locales/en/messages.po +64 -17
- package/app/i18n/locales/en/messages.ts +1 -1
- package/app/i18n/locales/pseudo/messages.po +64 -17
- package/app/i18n/locales/pseudo/messages.ts +1 -1
- package/app/icons/glyphs.tsx +2 -0
- package/app/live/studio-live.ts +29 -9
- package/app/pages/canvas.tsx +1 -1
- package/app/pages/commands-settings.tsx +70 -76
- package/app/pages/play-bar.tsx +6 -11
- package/app/pages/play.tsx +52 -33
- package/app/shell/feedback-form.tsx +29 -5
- package/app/ui/prompt-editor.tsx +2 -0
- package/app/ui/use-field-list.ts +90 -0
- package/dist/cli/commands/mcp.mjs +6 -4
- package/dist/cli/mcp-relay.mjs +10 -6
- package/dist/content/content.d.mts +26 -9
- package/dist/content/content.mjs +65 -8
- package/dist/content/screenshot.d.mts +2 -0
- package/dist/content/screenshot.mjs +3 -0
- package/dist/content/snapshot-client.d.mts +2 -0
- package/dist/content/snapshot-client.mjs +12 -1
- package/dist/inspector.js +96 -19
- package/dist/paste/paste.d.mts +5 -0
- package/dist/paste/paste.mjs +7 -2
- package/dist/server/agent-tools.d.mts +1 -0
- package/dist/server/agent-tools.mjs +4 -3
- package/dist/server/change-picture-store.d.mts +13 -0
- package/dist/server/change-picture-store.mjs +42 -0
- package/dist/server/change-pictures.d.mts +25 -0
- package/dist/server/change-pictures.mjs +104 -0
- package/dist/server/close-check.d.mts +11 -0
- package/dist/server/close-check.mjs +37 -5
- package/dist/server/comments/agent-actions.d.mts +8 -4
- package/dist/server/comments/agent-actions.mjs +16 -7
- package/dist/server/comments/close-tools.mjs +7 -5
- package/dist/server/comments/files.d.mts +5 -1
- package/dist/server/comments/hand-out.d.mts +1 -1
- package/dist/server/comments/hand-out.mjs +4 -1
- package/dist/server/comments/push.d.mts +19 -10
- package/dist/server/comments/push.mjs +45 -30
- package/dist/server/comments/studio-files.d.mts +14 -1
- package/dist/server/comments/studio-files.mjs +44 -31
- package/dist/server/comments/tools.d.mts +1 -1
- package/dist/server/comments/workspace.mjs +1 -0
- package/dist/server/dev-server.mjs +34 -0
- package/dist/server/own-copies.mjs +4 -23
- package/dist/server/requests.mjs +57 -3
- package/dist/server/response-budget.d.mts +2 -1
- package/dist/server/response-budget.mjs +4 -3
- package/dist/server/roster.d.mts +19 -8
- package/dist/server/roster.mjs +50 -22
- package/dist/server/studio-for.d.mts +7 -0
- package/dist/server/studio-for.mjs +23 -7
- package/dist/server/thread-forms.d.mts +3 -0
- package/dist/server/thread-forms.mjs +21 -1
- package/dist/server/tools/place-frame.d.mts +1 -0
- package/dist/server/tools/place-frame.mjs +33 -9
- package/dist/server/tools/result.mjs +2 -2
- package/dist/server/tools/snapshot.d.mts +1 -1
- package/dist/server/tools/snapshot.mjs +2 -1
- package/dist/server/tools/studio-context.d.mts +2 -1
- package/dist/server/tools/studio-context.mjs +2 -1
- package/dist/server/tools/watch.mjs +29 -12
- package/dist/server/work-groups.mjs +1 -1
- package/dist/shared/canvas-core.d.mts +39 -5
- package/dist/shared/canvas-core.mjs +60 -15
- package/dist/shared/canvas-file.d.mts +7 -4
- package/dist/shared/change-pictures-core.d.mts +6 -0
- package/dist/shared/change-pictures-core.mjs +5 -0
- package/dist/shared/page-looks.d.mts +12 -0
- package/dist/shared/page-looks.mjs +49 -0
- package/dist/shared/snapshot-clipboard.d.mts +6 -0
- package/dist/shared/studio-routes.d.mts +11 -0
- package/extension/dist/manifest.json +1 -1
- package/extension/dist/picker.js +114 -108
- package/package.json +4 -3
- package/src/cli/commands/mcp.ts +18 -8
- package/src/cli/mcp-relay.ts +13 -6
- package/src/content/content.ts +90 -16
- package/src/content/screenshot.ts +9 -1
- package/src/content/snapshot-client.ts +17 -0
- package/src/paste/paste.ts +18 -1
- package/src/server/agent-tools.ts +5 -4
- package/src/server/change-picture-store.ts +71 -0
- package/src/server/change-pictures.ts +244 -0
- package/src/server/close-check.ts +69 -6
- package/src/server/comments/agent-actions.ts +51 -12
- package/src/server/comments/close-tools.ts +20 -10
- package/src/server/comments/files.ts +10 -2
- package/src/server/comments/hand-out.ts +2 -2
- package/src/server/comments/push.ts +94 -46
- package/src/server/comments/studio-files.ts +77 -46
- package/src/server/comments/workspace.ts +1 -0
- package/src/server/dev-server.ts +70 -0
- package/src/server/own-copies.ts +5 -33
- package/src/server/requests.ts +84 -4
- package/src/server/response-budget.ts +5 -3
- package/src/server/roster.ts +78 -28
- package/src/server/studio-for.ts +32 -7
- package/src/server/thread-forms.ts +41 -1
- package/src/server/tools/place-frame.ts +71 -14
- package/src/server/tools/result.ts +2 -2
- package/src/server/tools/snapshot.ts +2 -1
- package/src/server/tools/studio-context.ts +24 -14
- package/src/server/tools/watch.ts +38 -13
- package/src/server/work-groups.ts +1 -1
- package/src/shared/canvas-core.ts +119 -27
- package/src/shared/canvas-file.ts +7 -4
- package/src/shared/change-pictures-core.ts +8 -0
- package/src/shared/page-looks.ts +133 -0
- package/src/shared/snapshot-clipboard.ts +6 -0
- package/src/shared/studio-routes.ts +7 -1
- package/templates/agents/dex-worker.md +9 -7
- package/templates/feedback-workflow.md +1 -1
- package/templates/methods/review.md +7 -6
- package/templates/rules/canvas-frames.md +8 -7
- package/templates/rules/canvas.md +10 -8
- package/templates/rules/prototypes.md +5 -3
- 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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
{
|
|
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: () =>
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
274
|
+
description: DescribedInStudio,
|
|
275
|
+
form: Form,
|
|
276
|
+
shared: Described = {}
|
|
259
277
|
): string[] => {
|
|
260
|
-
const described = describedIn(
|
|
261
|
-
|
|
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
|
|
360
|
-
*
|
|
361
|
-
* then by unit of work (work-groups.ts) with the files it may
|
|
362
|
-
* with how to work on them. Each file is
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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,
|
|
3
|
-
//
|
|
4
|
-
// person's copy of someone else's
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
103
|
+
changed,
|
|
85
104
|
await designSystem(),
|
|
86
105
|
from
|
|
87
106
|
);
|
|
88
107
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
};
|
package/src/server/dev-server.ts
CHANGED
|
@@ -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());
|
package/src/server/own-copies.ts
CHANGED
|
@@ -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 {
|
|
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">;
|