@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
package/dist/server/roster.mjs
CHANGED
|
@@ -30,10 +30,10 @@ function isAlive(pid) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* When process `pid` started, as ps says
|
|
34
|
-
*
|
|
33
|
+
* When process `pid` started, as ps says it in the time zone and language
|
|
34
|
+
* `env` names. Undefined where there is no ps (Windows) or it can't say.
|
|
35
35
|
*/
|
|
36
|
-
async function
|
|
36
|
+
async function psStart(pid, env) {
|
|
37
37
|
if (process.platform === "win32") return;
|
|
38
38
|
try {
|
|
39
39
|
const { stdout } = await run("ps", [
|
|
@@ -41,18 +41,45 @@ async function startedAt(pid) {
|
|
|
41
41
|
"lstart=",
|
|
42
42
|
"-p",
|
|
43
43
|
String(pid)
|
|
44
|
-
], {
|
|
44
|
+
], {
|
|
45
|
+
env,
|
|
46
|
+
timeout: PS_MS
|
|
47
|
+
});
|
|
45
48
|
return stdout.trim() || void 0;
|
|
46
49
|
} catch {}
|
|
47
50
|
}
|
|
48
51
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
52
|
+
* When process `pid` started, as ps says: with its pid, which process it
|
|
53
|
+
* is. Asked in UTC and the C locale: ps writes the time in the time zone
|
|
54
|
+
* and language of whoever asks, and the Dexes on one roster start from
|
|
55
|
+
* different ones (a person's terminal, an agent's app), which must all read
|
|
56
|
+
* one start the same. Undefined where there is no ps (Windows) or it can't
|
|
57
|
+
* say.
|
|
51
58
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
const startedAt = (pid) => psStart(pid, {
|
|
60
|
+
...process.env,
|
|
61
|
+
LC_ALL: "C",
|
|
62
|
+
TZ: "UTC"
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Whether `pid` is still the process that joined with start `utc` (as
|
|
66
|
+
* startedAt says), or `local` (an older Dex's): "another" once it stopped
|
|
67
|
+
* or its start differs, "unknown" while that can't be told. An older Dex
|
|
68
|
+
* wrote its start as ps said it in the time zone and language it ran in,
|
|
69
|
+
* so it is asked of ps here as that Dex asked it, which agrees only when
|
|
70
|
+
* both run in the same: when it doesn't, nothing can tell. Without ps
|
|
71
|
+
* (Windows), "joined" while it runs, and the port says the rest.
|
|
72
|
+
*/
|
|
73
|
+
async function processNow(pid, utc, local) {
|
|
74
|
+
if (!isAlive(pid)) return "another";
|
|
75
|
+
if (process.platform === "win32") return "joined";
|
|
76
|
+
if (utc !== void 0) {
|
|
77
|
+
const now = await startedAt(pid);
|
|
78
|
+
if (now === void 0) return "unknown";
|
|
79
|
+
return now === utc ? "joined" : "another";
|
|
80
|
+
}
|
|
81
|
+
const here = local === void 0 ? void 0 : await psStart(pid, process.env);
|
|
82
|
+
return here !== void 0 && here === local ? "joined" : "unknown";
|
|
56
83
|
}
|
|
57
84
|
/**
|
|
58
85
|
* Join the roster of the studio at `content` as `entry`, and leave it when
|
|
@@ -67,8 +94,8 @@ async function joinRoster(content, entry) {
|
|
|
67
94
|
...entry,
|
|
68
95
|
pid,
|
|
69
96
|
since: (/* @__PURE__ */ new Date()).toISOString(),
|
|
70
|
-
...started && { started },
|
|
71
|
-
...supervisorStarted && { supervisorStarted }
|
|
97
|
+
...started && { startedUtc: started },
|
|
98
|
+
...supervisorStarted && { supervisorStartedUtc: supervisorStarted }
|
|
72
99
|
};
|
|
73
100
|
const file = state.rosterEntry(kept.pid);
|
|
74
101
|
const write = async () => {
|
|
@@ -115,8 +142,7 @@ async function readRoster(content) {
|
|
|
115
142
|
} catch {
|
|
116
143
|
continue;
|
|
117
144
|
}
|
|
118
|
-
|
|
119
|
-
if (now && now !== entry.started) {
|
|
145
|
+
if (await processNow(pid, entry.startedUtc) === "another") {
|
|
120
146
|
await rm(join(folder, name), { force: true });
|
|
121
147
|
continue;
|
|
122
148
|
}
|
|
@@ -163,22 +189,24 @@ async function askOthersToRestart(content, id, version, { ask = askToRestart, se
|
|
|
163
189
|
/**
|
|
164
190
|
* Stop other Dexes: ask every other development server for the project
|
|
165
191
|
* `id` names (projectId) to stop, through its supervisor when it has one,
|
|
166
|
-
* as Ctrl+C does. Only one
|
|
167
|
-
* pid is another process's now is dropped
|
|
168
|
-
* this project's Dex; nothing
|
|
169
|
-
* asked.
|
|
192
|
+
* as Ctrl+C does. Only one known to be the process that joined (an entry
|
|
193
|
+
* whose pid is another process's now is dropped; one that can't be told
|
|
194
|
+
* stays, unasked) and answering on its port as this project's Dex; nothing
|
|
195
|
+
* else is signalled. Answers how many were asked.
|
|
170
196
|
*/
|
|
171
197
|
async function stopOthers(content, id, { self = process.pid } = {}) {
|
|
172
198
|
const others = otherServers(await readRoster(content), self);
|
|
173
199
|
let asked = 0;
|
|
174
200
|
for (const entry of others) {
|
|
175
|
-
const { pid, port,
|
|
176
|
-
|
|
201
|
+
const { pid, port, supervisor } = entry;
|
|
202
|
+
const now = await processNow(pid, entry.startedUtc, entry.started);
|
|
203
|
+
if (now === "another") {
|
|
177
204
|
await rm(studioState(content).rosterEntry(pid), { force: true });
|
|
178
205
|
continue;
|
|
179
206
|
}
|
|
180
|
-
if (!await answersAs(port, id)) continue;
|
|
181
|
-
const
|
|
207
|
+
if (now === "unknown" || !await answersAs(port, id)) continue;
|
|
208
|
+
const recorded = entry.supervisorStartedUtc ?? entry.supervisorStarted;
|
|
209
|
+
const supervised = supervisor !== void 0 && recorded !== void 0 && await processNow(supervisor, entry.supervisorStartedUtc, entry.supervisorStarted) === "joined";
|
|
182
210
|
try {
|
|
183
211
|
process.kill(supervised ? supervisor : pid, "SIGTERM");
|
|
184
212
|
asked += 1;
|
|
@@ -56,6 +56,13 @@ export declare function studioFor({ content, root, port: configured }: StudioPla
|
|
|
56
56
|
* undefined when none is: what the app opens, and where it says to look.
|
|
57
57
|
*/
|
|
58
58
|
export declare function ownPort(found: StudioFor): number | undefined;
|
|
59
|
+
export interface NotRunning {
|
|
60
|
+
todo: string;
|
|
61
|
+
why: string;
|
|
62
|
+
}
|
|
63
|
+
export declare function whyNotRunning(found: Exclude<StudioFor, {
|
|
64
|
+
kind: "running";
|
|
65
|
+
}>): NotRunning;
|
|
59
66
|
/** Why there is no Dex to ask, in words a person can act on. */
|
|
60
67
|
export declare function notRunning(found: Exclude<StudioFor, {
|
|
61
68
|
kind: "running";
|
|
@@ -73,15 +73,31 @@ function ownPort(found) {
|
|
|
73
73
|
}
|
|
74
74
|
const START = "Start it with `npx dex dev` (or the project's own script, such as `npm run dex`), then try again.";
|
|
75
75
|
const ports = (tried) => tried.map((port) => `:${port}`).join(", ");
|
|
76
|
-
|
|
77
|
-
function notRunning(found) {
|
|
76
|
+
function whyNotRunning(found) {
|
|
78
77
|
switch (found.kind) {
|
|
79
|
-
case "none": return
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
case "none": return {
|
|
79
|
+
why: `Dex isn't running for this checkout (tried ${ports(found.tried)}).`,
|
|
80
|
+
todo: START
|
|
81
|
+
};
|
|
82
|
+
case "elsewhere": return {
|
|
83
|
+
why: `Dex isn't running for this checkout (tried ${ports(found.tried)}; :${found.port} is ${found.holder}).`,
|
|
84
|
+
todo: "Start this checkout's with `npx dex dev`, which moves on to a free port, then try again."
|
|
85
|
+
};
|
|
86
|
+
case "starting": return {
|
|
87
|
+
why: `Dex for this checkout is restarting on :${found.port}.`,
|
|
88
|
+
todo: "Try again in a moment."
|
|
89
|
+
};
|
|
90
|
+
case "failed": return {
|
|
91
|
+
why: "Dex for this checkout stopped just after it restarted.",
|
|
92
|
+
todo: `Its log and Try again are at http://localhost:${found.port}; once it is running, try again.`
|
|
93
|
+
};
|
|
83
94
|
default: return found;
|
|
84
95
|
}
|
|
85
96
|
}
|
|
97
|
+
/** Why there is no Dex to ask, in words a person can act on. */
|
|
98
|
+
function notRunning(found) {
|
|
99
|
+
const { why, todo } = whyNotRunning(found);
|
|
100
|
+
return `${why} ${todo}`;
|
|
101
|
+
}
|
|
86
102
|
//#endregion
|
|
87
|
-
export { notRunning, ownPort, studioFor };
|
|
103
|
+
export { notRunning, ownPort, studioFor, whyNotRunning };
|
|
@@ -29,6 +29,9 @@ export interface ThreadInForm {
|
|
|
29
29
|
* cut it.
|
|
30
30
|
*/
|
|
31
31
|
export declare function describedIn(described: Described, form: Form): ThreadInForm;
|
|
32
|
+
/** Where two or more threads are alike, to say once: a field one has not is not shared. */
|
|
33
|
+
export declare function sharedPlace(threads: Described[]): Described;
|
|
34
|
+
export declare const withoutSaid: (thread: Described, said: Described) => Described;
|
|
32
35
|
/**
|
|
33
36
|
* A thread's description in the fullest of `forms` that comes within
|
|
34
37
|
* `room`; in the last of them when none does.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cutText, plural, sizeOf } from "./response-budget.mjs";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
3
|
//#region src/server/thread-forms.ts
|
|
3
4
|
const IN_FULL = {
|
|
4
5
|
first: 2e3,
|
|
@@ -97,6 +98,25 @@ function describedIn(described, form) {
|
|
|
97
98
|
cut
|
|
98
99
|
};
|
|
99
100
|
}
|
|
101
|
+
const PLACE_FIELDS = [
|
|
102
|
+
"file",
|
|
103
|
+
"folder",
|
|
104
|
+
"canvas",
|
|
105
|
+
"section",
|
|
106
|
+
"frame",
|
|
107
|
+
"uid",
|
|
108
|
+
"state",
|
|
109
|
+
"viewport",
|
|
110
|
+
"flowSpec",
|
|
111
|
+
"moreFlowSpecs"
|
|
112
|
+
];
|
|
113
|
+
/** Where two or more threads are alike, to say once: a field one has not is not shared. */
|
|
114
|
+
function sharedPlace(threads) {
|
|
115
|
+
const [first, ...rest] = threads;
|
|
116
|
+
if (!first || rest.length === 0) return {};
|
|
117
|
+
return Object.fromEntries(PLACE_FIELDS.flatMap((key) => first[key] !== void 0 && rest.every((thread) => isDeepStrictEqual(thread[key], first[key])) ? [[key, first[key]]] : []));
|
|
118
|
+
}
|
|
119
|
+
const withoutSaid = (thread, said) => Object.fromEntries(Object.entries(thread).filter(([key, value]) => !(Object.hasOwn(said, key) && isDeepStrictEqual(value, said[key]))));
|
|
100
120
|
/**
|
|
101
121
|
* A thread's description in the fullest of `forms` that comes within
|
|
102
122
|
* `room`; in the last of them when none does.
|
|
@@ -155,4 +175,4 @@ async function fitThreads(found, describe, room, size = sizeOf) {
|
|
|
155
175
|
};
|
|
156
176
|
}
|
|
157
177
|
//#endregion
|
|
158
|
-
export { FOR_WORK, IN_FULL, SHORT, describedIn, describedWithin, fitThreads };
|
|
178
|
+
export { FOR_WORK, IN_FULL, SHORT, describedIn, describedWithin, fitThreads, sharedPlace, withoutSaid };
|
|
@@ -8,6 +8,7 @@ export declare function placeFrameTool({ refuse, root, threads, withNotice }: To
|
|
|
8
8
|
frames: z.ZodArray<z.ZodObject<{
|
|
9
9
|
view: z.ZodString;
|
|
10
10
|
thread: z.ZodOptional<z.ZodString>;
|
|
11
|
+
rightOf: z.ZodOptional<z.ZodString>;
|
|
11
12
|
section: z.ZodOptional<z.ZodString>;
|
|
12
13
|
row: z.ZodOptional<z.ZodString>;
|
|
13
14
|
above: z.ZodOptional<z.ZodString>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NOT_RECOGNISED } from "../../shared/studio-routes.mjs";
|
|
2
|
-
import { requestCell } from "../../shared/canvas-core.mjs";
|
|
2
|
+
import { requestCell, whereInRow } from "../../shared/canvas-core.mjs";
|
|
3
3
|
import { resolvePrototype } from "../../content/prototypes.mjs";
|
|
4
|
-
import { joinCurrentPerson, placeViewFrame } from "../../content/content.mjs";
|
|
4
|
+
import { frameKeyOn, joinCurrentPerson, placeViewFrame, readCanvas } from "../../content/content.mjs";
|
|
5
5
|
import { defineTool } from "../../harness/src/mcp/define-tool.mjs";
|
|
6
6
|
import { PROTOTYPE } from "./prototype-name.mjs";
|
|
7
7
|
import { json } from "./result.mjs";
|
|
@@ -11,9 +11,21 @@ import { z } from "zod";
|
|
|
11
11
|
const LARGE_CANVAS_NOTE = "The person's canvas.json is now over 400 KB. Live sync skips files over 512 KB, so their teammates may stop seeing their changes. Tell them, and suggest moving some sections to another file.";
|
|
12
12
|
/**
|
|
13
13
|
* Where `place_frame` puts a frame: a view request's cell, by its thread,
|
|
14
|
-
* at the size the person gave it; or the cell given
|
|
14
|
+
* at the size the person gave it; right of a frame; or the cell given, its
|
|
15
|
+
* step left out for the end of its row.
|
|
15
16
|
*/
|
|
16
17
|
async function placeFor(threads, input) {
|
|
18
|
+
if (input.rightOf) {
|
|
19
|
+
const { above, row, section, step, thread } = input;
|
|
20
|
+
if ([
|
|
21
|
+
above,
|
|
22
|
+
row,
|
|
23
|
+
section,
|
|
24
|
+
step,
|
|
25
|
+
thread
|
|
26
|
+
].some((given) => given !== void 0)) return { problem: "Give rightOf, or the cell (a thread, or a section with its row or step), not both: rightOf finds the frame's cell as the canvas is now." };
|
|
27
|
+
return { cell: { rightOf: input.rightOf } };
|
|
28
|
+
}
|
|
17
29
|
if (input.thread) {
|
|
18
30
|
const thread = await threads.find(input.thread);
|
|
19
31
|
if (!thread) return { problem: `No thread ${input.thread}. List them with \`threads\`.` };
|
|
@@ -24,7 +36,7 @@ async function placeFor(threads, input) {
|
|
|
24
36
|
size: thread.target.size
|
|
25
37
|
};
|
|
26
38
|
}
|
|
27
|
-
if (!
|
|
39
|
+
if (!input.section) return { problem: "Say where the frame goes: the thread of a request for a new view, a frame to go right of (rightOf), or a section (with a row and step, or neither for the end of its main path)." };
|
|
28
40
|
return { cell: requestCell({
|
|
29
41
|
...input,
|
|
30
42
|
section: input.section,
|
|
@@ -42,17 +54,18 @@ function placeFrameTool({ refuse, root, threads, withNotice }) {
|
|
|
42
54
|
idempotentHint: true
|
|
43
55
|
},
|
|
44
56
|
title: "Put views on the canvas",
|
|
45
|
-
description: "Add frames showing views you built to a file's canvas, several at once, each in a cell (a row and a step of a section): give the thread of a request for a new view (its target names the cell, and the size when the person set one), or the cell itself (section, step, and row for an existing row; leave row out for a new row at the end of the section, or give `above` for one right above that row). A cell's frames are one stack: with `stack`, the frame goes on top of the stack already in that cell, a variant of that step; without it, a frame already in the cell moves one step right, with the frames packed after it, and the new frame takes the cell. Every column starts at its row's top: never write `beside`. canvas.json is changed for you, safely while other agents change it too: do not edit it by hand for this. If a cell already shows the view, its frame is returned as it is. Returns each frame's key (\"section/row/frame\")
|
|
57
|
+
description: "Add frames showing views you built to a file's canvas, several at once, each in a cell (a row and a step of a section): give the thread of a request for a new view (its target names the cell, and the size when the person set one); or `rightOf`, a frame's uid or key, for the step right after that frame in its row, wherever the person has moved it since (in someone else's row, your own row right below it); use it to put a frame right of another, never a step worked out from an earlier read; or the cell itself (section, step, and row for an existing row; leave step out for the free step at the end of the row; leave row out for a new row at the end of the section, or give `above` for one right above that row; leave both out for the end of the section's first row, its main path). A cell's frames are one stack: with `stack`, the frame goes on top of the stack already in that cell, a variant of that step; without it, a frame already in the cell moves one step right, with the frames packed after it, and the new frame takes the cell. Every column starts at its row's top: never write `beside`. canvas.json is changed for you, safely while other agents change it too: do not edit it by hand for this. If a cell already shows the view, its frame is returned as it is, and so is the view's frame already in the row past `rightOf`, or anywhere in it with no step. Returns each frame's key (\"section/row/frame\"), its uid, which picks follow, and, once all are placed, its step and `rightOf`, the key of the frame on its left in its row (none at the row's start): say where it went from these.",
|
|
46
58
|
inputSchema: {
|
|
47
59
|
prototype: PROTOTYPE,
|
|
48
60
|
frames: z.array(z.object({
|
|
49
61
|
view: z.string().min(1).describe("The view's name, as in views/<name>.tsx."),
|
|
50
62
|
thread: z.string().optional().describe("A request for a new view: its cell is used."),
|
|
63
|
+
rightOf: z.string().min(1).optional().describe("A frame's uid or key (\"section/row/frame\"): the frame goes on the step right after it, in its row, where it is now. Leave out thread, section, row, above and step."),
|
|
51
64
|
section: z.string().optional().describe("The section's id."),
|
|
52
65
|
row: z.string().optional().describe("An existing row's id; leave out for a new row."),
|
|
53
66
|
above: z.string().optional().describe("With no row: the row the new row goes right above; leave out for the end of the section."),
|
|
54
|
-
step: z.number().int().min(1).optional().describe("The
|
|
55
|
-
stack: z.boolean().optional().describe("With a row and a step: put the frame on top of the stack in that cell, rather than moving what is there one step right.")
|
|
67
|
+
step: z.number().int().min(1).optional().describe("The step, from 1; leave out for the free step at the end of the row."),
|
|
68
|
+
stack: z.boolean().optional().describe("With a row and a step, or rightOf: put the frame on top of the stack in that cell, rather than moving what is there one step right.")
|
|
56
69
|
})).min(1)
|
|
57
70
|
}
|
|
58
71
|
},
|
|
@@ -98,8 +111,19 @@ function placeFrameTool({ refuse, root, threads, withNotice }) {
|
|
|
98
111
|
added: placed.added
|
|
99
112
|
});
|
|
100
113
|
}
|
|
101
|
-
|
|
102
|
-
|
|
114
|
+
const problems = frames.flatMap((answer) => "problem" in answer ? [answer.problem] : []);
|
|
115
|
+
if (problems.length === frames.length) return refuse(problems.join(" "));
|
|
116
|
+
const placedAll = await readCanvas(slug, root);
|
|
117
|
+
const answers = frames.map((answer) => {
|
|
118
|
+
if ("problem" in answer) return answer;
|
|
119
|
+
const key = frameKeyOn(placedAll, answer) ?? answer.frame;
|
|
120
|
+
return {
|
|
121
|
+
...answer,
|
|
122
|
+
frame: key,
|
|
123
|
+
...whereInRow(placedAll, key)
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
const result = json({ frames: answers });
|
|
103
127
|
return withNotice(large ? { content: [...result.content, {
|
|
104
128
|
type: "text",
|
|
105
129
|
text: LARGE_CANVAS_NOTE
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { firstOf } from "../response-budget.mjs";
|
|
1
|
+
import { firstOf, jsonText } from "../response-budget.mjs";
|
|
2
2
|
//#region src/server/tools/result.ts
|
|
3
3
|
/** Words as a part of a tool's result. */
|
|
4
4
|
const textPart = (text) => ({
|
|
@@ -7,7 +7,7 @@ const textPart = (text) => ({
|
|
|
7
7
|
});
|
|
8
8
|
const json = (value) => ({ content: [{
|
|
9
9
|
type: "text",
|
|
10
|
-
text:
|
|
10
|
+
text: jsonText(value)
|
|
11
11
|
}] });
|
|
12
12
|
/** A result with a line after its answer: what the answer left out. */
|
|
13
13
|
const noted = (result, note) => note ? {
|
|
@@ -3,6 +3,7 @@ import { prototypeTitle } from "../../content/prototypes.mjs";
|
|
|
3
3
|
import { notRunning } from "../studio-for.mjs";
|
|
4
4
|
import { SnapshotError, snapshotView } from "../../content/snapshot-client.mjs";
|
|
5
5
|
import { defineTool } from "../../harness/src/mcp/define-tool.mjs";
|
|
6
|
+
import { jsonText } from "../response-budget.mjs";
|
|
6
7
|
import { PROTOTYPE, prototypeFor } from "./prototype-name.mjs";
|
|
7
8
|
import { z } from "zod";
|
|
8
9
|
//#region src/server/tools/snapshot.ts
|
|
@@ -61,7 +62,7 @@ function snapshotTool({ refuse, root, withNotice }, findStudio) {
|
|
|
61
62
|
mimeType: "image/png"
|
|
62
63
|
}, {
|
|
63
64
|
type: "text",
|
|
64
|
-
text:
|
|
65
|
+
text: jsonText({
|
|
65
66
|
prototype: found.slug,
|
|
66
67
|
title: await prototypeTitle(root, found.slug),
|
|
67
68
|
view: input.view,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ToolSetup } from "../studio-server.mjs";
|
|
2
|
+
import { FindStudio } from "../change-pictures.mjs";
|
|
2
3
|
import { ToolContext } from "./context.mjs";
|
|
3
4
|
//#region src/server/tools/studio-context.d.ts
|
|
4
5
|
/** What openToolContext builds the tools' context from: what the server shares. */
|
|
5
6
|
export type ToolContextOptions = ToolSetup;
|
|
6
7
|
/** The context the tools of one server share. */
|
|
7
|
-
export declare function openToolContext({ agentName, briefing, channel, claudeSession, designSystem, from, onUpdateReady, receipt, root, session, threads }: ToolContextOptions): ToolContext;
|
|
8
|
+
export declare function openToolContext({ agentName, briefing, channel, claudeSession, designSystem, from, onUpdateReady, receipt, root, session, threads }: ToolContextOptions, findStudio: FindStudio): ToolContext;
|
|
8
9
|
//#endregion
|
|
@@ -7,7 +7,7 @@ import { noPushNotice, sayOnce } from "../push-notice.mjs";
|
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
//#region src/server/tools/studio-context.ts
|
|
9
9
|
/** The context the tools of one server share. */
|
|
10
|
-
function openToolContext({ agentName, briefing, channel, claudeSession, designSystem, from, onUpdateReady, receipt, root, session, threads }) {
|
|
10
|
+
function openToolContext({ agentName, briefing, channel, claudeSession, designSystem, from, onUpdateReady, receipt, root, session, threads }, findStudio) {
|
|
11
11
|
const toldOnce = sayOnce([() => noPushNotice(channel ? receipt : void 0), async () => componentsLine(await designSystem())]);
|
|
12
12
|
/** A file in the studio's folder, as the agent opens it from where it works. */
|
|
13
13
|
const inRoot = (path) => shownFrom(from, join(root, path));
|
|
@@ -21,6 +21,7 @@ function openToolContext({ agentName, briefing, channel, claudeSession, designSy
|
|
|
21
21
|
designSystem,
|
|
22
22
|
files: studioCommentFiles({
|
|
23
23
|
designSystem,
|
|
24
|
+
findStudio,
|
|
24
25
|
from,
|
|
25
26
|
inRoot,
|
|
26
27
|
root
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { needsAgent } from "../../shared/threads-core.mjs";
|
|
2
2
|
import { defineTool } from "../../harness/src/mcp/define-tool.mjs";
|
|
3
3
|
import { RESPONSE_BUDGETS, plural, sizeOf } from "../response-budget.mjs";
|
|
4
|
-
import { FOR_WORK, describedIn, fitThreads } from "../thread-forms.mjs";
|
|
4
|
+
import { FOR_WORK, describedIn, fitThreads, sharedPlace, withoutSaid } from "../thread-forms.mjs";
|
|
5
5
|
import { describeForWork } from "./describe.mjs";
|
|
6
6
|
import { PROTOTYPE } from "./prototype-name.mjs";
|
|
7
7
|
import { someOf } from "./result.mjs";
|
|
@@ -24,6 +24,10 @@ const WATCH_ROOM = 3e3;
|
|
|
24
24
|
const MAX_PASSED = 3;
|
|
25
25
|
/** The most threads a result names by id alone, beside those it describes. */
|
|
26
26
|
const MAX_IDS = 60;
|
|
27
|
+
const SAID_OF_EVERY_THREAD = {
|
|
28
|
+
for: "agent",
|
|
29
|
+
status: "acknowledged"
|
|
30
|
+
};
|
|
27
31
|
/**
|
|
28
32
|
* What `watch` says of the threads it could not describe for work:
|
|
29
33
|
* nothing when it could describe them all.
|
|
@@ -35,21 +39,29 @@ const watchLeftOut = (short, left) => {
|
|
|
35
39
|
return parts.length > 0 ? `${parts.join(", and ")}: \`threads\` with \`id\` gives one with its messages and the code around it.` : "";
|
|
36
40
|
};
|
|
37
41
|
/**
|
|
38
|
-
* Each group with its threads as described
|
|
39
|
-
*
|
|
40
|
-
*
|
|
42
|
+
* Each group with its threads as described (`shown`, in order; any past them
|
|
43
|
+
* named in `more`), its files as `show` gives them, where they are alike said
|
|
44
|
+
* once (`shared`), and each thread less what its group or `watch` says of it.
|
|
41
45
|
*/
|
|
42
46
|
const groupsWith = (groups, shown, show) => {
|
|
43
47
|
let at = 0;
|
|
44
|
-
return groups.map((group) => {
|
|
48
|
+
return groups.map(({ threads, ...group }) => {
|
|
45
49
|
const from = at;
|
|
46
|
-
at +=
|
|
50
|
+
at += threads.length;
|
|
47
51
|
const described = shown.slice(from, at);
|
|
48
|
-
const named =
|
|
52
|
+
const named = threads.slice(described.length).map(({ id }) => id);
|
|
53
|
+
const shared = sharedPlace(described);
|
|
54
|
+
const said = {
|
|
55
|
+
prototype: group.prototype,
|
|
56
|
+
fileTitle: group.fileTitle,
|
|
57
|
+
...SAID_OF_EVERY_THREAD,
|
|
58
|
+
...shared
|
|
59
|
+
};
|
|
49
60
|
return {
|
|
50
61
|
...group,
|
|
51
62
|
files: someOf(group.files.map(show)),
|
|
52
|
-
|
|
63
|
+
...Object.keys(shared).length > 0 ? { shared } : void 0,
|
|
64
|
+
threads: described.map((thread) => withoutSaid(thread, said)),
|
|
53
65
|
...named.length > 0 ? { more: {
|
|
54
66
|
threads: named.length,
|
|
55
67
|
ids: named.slice(0, MAX_IDS)
|
|
@@ -69,8 +81,12 @@ const claimAll = async (context, found) => {
|
|
|
69
81
|
}
|
|
70
82
|
return claimed;
|
|
71
83
|
};
|
|
72
|
-
/** What threads come to in `watch`'s result, as
|
|
73
|
-
const inGroups = (
|
|
84
|
+
/** What the threads shown come to in `watch`'s result, as `groupsWith` gives them in `groups`. */
|
|
85
|
+
const inGroups = (groups, show) => {
|
|
86
|
+
const size = (shown) => sizeOf({ groups: groupsWith(groups, shown, show) });
|
|
87
|
+
const none = size([]);
|
|
88
|
+
return (shown) => size(shown) - none;
|
|
89
|
+
};
|
|
74
90
|
/**
|
|
75
91
|
* What a group comes to in `watch`'s result as an agent works from it: its
|
|
76
92
|
* heading and files, and each thread described for work.
|
|
@@ -97,8 +113,9 @@ const describeGroups = async (context, groups, more) => {
|
|
|
97
113
|
known.set(thread.id, described);
|
|
98
114
|
return described;
|
|
99
115
|
};
|
|
116
|
+
const measure = inGroups(groups, inRoot);
|
|
100
117
|
const build = async (room) => {
|
|
101
|
-
const fit = await fitThreads(all, describe, room,
|
|
118
|
+
const fit = await fitThreads(all, describe, room, measure);
|
|
102
119
|
const leftOut = watchLeftOut(fit.short, fit.left);
|
|
103
120
|
return {
|
|
104
121
|
...side > 1 ? { split: splitLine(side) } : void 0,
|
|
@@ -225,7 +242,7 @@ function watchTool(context) {
|
|
|
225
242
|
destructiveHint: false
|
|
226
243
|
},
|
|
227
244
|
title: "Wait for studio feedback",
|
|
228
|
-
description: `Wait for comments or requests that need an agent and take them: each thread returned is yours (👀). They come in groups, each with the files it may change: one view's threads, one request for a new view, or comments on the whole file. Returns at once when some are waiting; takes as many groups as it has room to describe and says how many are left, for the next call. With \`split\`, give each group to its own sub-agent, all at once, where you can. ${FEEDBACK_WORKFLOW} Where one has \`commands\`, it runs skills: do what each \`follow\` (a SKILL.md, files beside it) says, the comment's words its arguments. ${FORKED_COMMAND_HOW} \`groups: 1\` takes one group; \`ids\` takes threads by id. It keeps waiting while Dex's Watch switch is off. ${WATCH_HOW} ${LOOP_HOW}`,
|
|
245
|
+
description: `Wait for comments or requests that need an agent and take them: each thread returned is yours (👀). They come in groups, each with the files it may change: one view's threads, one request for a new view, or comments on the whole file. What a group's \`threads\` share (file, frame, spec) is in its \`shared\`. Returns at once when some are waiting; takes as many groups as it has room to describe and says how many are left, for the next call. With \`split\`, give each group to its own sub-agent, all at once, where you can. ${FEEDBACK_WORKFLOW} Where one has \`commands\`, it runs skills: do what each \`follow\` (a SKILL.md, files beside it) says, the comment's words its arguments. ${FORKED_COMMAND_HOW} \`groups: 1\` takes one group; \`ids\` takes threads by id. It keeps waiting while Dex's Watch switch is off. ${WATCH_HOW} ${LOOP_HOW}`,
|
|
229
246
|
inputSchema: {
|
|
230
247
|
prototype: PROTOTYPE.optional(),
|
|
231
248
|
timeout_seconds: z.number().int().min(1).max(MAX_WATCH_SECONDS).default(DEFAULT_WATCH_SECONDS),
|
|
@@ -271,7 +271,7 @@ function groupOnPaths(paths, threads) {
|
|
|
271
271
|
* What to do with `count` groups that can run side by side: split them
|
|
272
272
|
* between sub-agents where the agent can run them, else take them in turn.
|
|
273
273
|
*/
|
|
274
|
-
const splitLine = (count) => `Split this work first: these ${count} groups change separate files, so they run side by side. If you can run sub-agents, start one per group now (\`dex-worker\` if you have it), all at once in one message, each with its group's threads and files, to change only those files and close its own threads (a sub-agent that shares your context needs no brief). Then do any group marked as the whole file yourself. Only without sub-agents take the groups one after another.`;
|
|
274
|
+
const splitLine = (count) => `Split this work first: these ${count} groups change separate files, so they run side by side. If you can run sub-agents, start one per group now (\`dex-worker\` if you have it), all at once in one message, each with its group's threads, what they share and its files, to change only those files and close its own threads (a sub-agent that shares your context needs no brief). Then do any group marked as the whole file yourself. Only without sub-agents take the groups one after another.`;
|
|
275
275
|
const groupSummary = (group) => ({
|
|
276
276
|
prototype: group.prototype,
|
|
277
277
|
...group.fileTitle && { fileTitle: group.fileTitle },
|
|
@@ -204,13 +204,16 @@ export declare const kinded: <F extends KindKeys>(frame: F) => Kinded<F>;
|
|
|
204
204
|
/** Whether a frame is a note: a spec frame whose file is a note's. */
|
|
205
205
|
export declare const isNoteFrame: (frame: KindKeys) => boolean;
|
|
206
206
|
/**
|
|
207
|
-
* Whether a frame is a section header: a note marked `header`,
|
|
208
|
-
*
|
|
207
|
+
* Whether a frame is a section header: a note marked `header`, its words
|
|
208
|
+
* large, placed as any note is and filling what it is in (layout.ts).
|
|
209
209
|
*/
|
|
210
210
|
export declare const isHeaderFrame: (frame: KindKeys & {
|
|
211
211
|
header?: unknown;
|
|
212
212
|
}) => boolean;
|
|
213
|
-
/**
|
|
213
|
+
/**
|
|
214
|
+
* Whether a section is a section header standing on its own: a band across
|
|
215
|
+
* the canvas's content, splitting it into parts (layout.ts).
|
|
216
|
+
*/
|
|
214
217
|
export declare const isHeaderSection: (section: {
|
|
215
218
|
at?: unknown;
|
|
216
219
|
rows: readonly {
|
|
@@ -399,9 +402,40 @@ export declare function stackPiles<C extends WalkedCanvas<F>, F extends Piled>(c
|
|
|
399
402
|
/**
|
|
400
403
|
* The cell a request for a new view fills: a step in its row, or in a new
|
|
401
404
|
* row, right above the row `above` names (a step in a row has no row to go
|
|
402
|
-
* above), else at the end of the section.
|
|
405
|
+
* above), else at the end of the section. An agent's may leave the step out
|
|
406
|
+
* (AskedCell).
|
|
407
|
+
*/
|
|
408
|
+
export declare const requestCell: <S extends number | undefined>({ above, row, section, step }: Pick<Cell, "above" | "row" | "section"> & {
|
|
409
|
+
step: S;
|
|
410
|
+
}) => Omit<Cell, "step"> & {
|
|
411
|
+
step: S;
|
|
412
|
+
};
|
|
413
|
+
/**
|
|
414
|
+
* A cell as an agent asks for it: its step may be left out, for the free
|
|
415
|
+
* step at the end of its row, or right of `after`, a step of its row
|
|
416
|
+
* (stepAsked).
|
|
403
417
|
*/
|
|
404
|
-
export
|
|
418
|
+
export type AskedCell = Omit<Cell, "step"> & {
|
|
419
|
+
after?: number;
|
|
420
|
+
step?: number;
|
|
421
|
+
};
|
|
422
|
+
/**
|
|
423
|
+
* The step of a cell an agent asks for: its own, when given; else the step
|
|
424
|
+
* right of `after`, or the free step at the end of its row and of `past`
|
|
425
|
+
* (the row it was asked in, when the frame goes in a row of the person's
|
|
426
|
+
* own below it). A frame for the view already in the row from there on is
|
|
427
|
+
* kept where it is, so asking again finds it. A new row's free step is its
|
|
428
|
+
* first.
|
|
429
|
+
*/
|
|
430
|
+
export declare function stepAsked<F extends CellFrame>(canvas: WalkedCanvas<F>, cell: AskedCell, view: string, past?: string): number;
|
|
431
|
+
/** Where a frame is in its row: its step, and the frame it is right of. */
|
|
432
|
+
export interface WhereInRow {
|
|
433
|
+
/** The key of the top of the nearest stack to its left; none at the row's start. */
|
|
434
|
+
rightOf?: string;
|
|
435
|
+
step: number;
|
|
436
|
+
}
|
|
437
|
+
/** Where the frame with a key is in its row; undefined when none has it. */
|
|
438
|
+
export declare const whereInRow: <F extends CellFrame>(canvas: WalkedCanvas<F>, key: string) => WhereInRow | undefined;
|
|
405
439
|
/**
|
|
406
440
|
* Put a new row among a section's rows: right above the row `above` names,
|
|
407
441
|
* as the + on the line between two rows asks, else below the others.
|