agent-canvas 0.9.0-dev.1 → 0.9.0-dev.11
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/README.md +10 -0
- package/bin/lib/commands/review-remote.ts +186 -0
- package/bin/lib/commands/review.ts +88 -25
- package/bin/lib/instructions/app-review.md +31 -0
- package/daemon/build.ts +2 -0
- package/daemon/client/App.tsx +1 -1
- package/daemon/client/FileViewer.tsx +1 -1
- package/daemon/dist/client.css +2 -2
- package/daemon/dist/review.js +33 -3
- package/daemon/review-widget/anchor.ts +21 -4
- package/daemon/review-widget/browser.ts +46 -0
- package/daemon/review-widget/client.ts +23 -1
- package/daemon/review-widget/index.tsx +69 -11
- package/daemon/review-widget/remote-client.ts +117 -0
- package/daemon/review-widget/source.ts +43 -7
- package/daemon/review-widget/style.ts +51 -0
- package/daemon/review-widget/styles.css +30 -0
- package/daemon/review-widget/tsconfig.json +2 -1
- package/daemon/review-widget/widget.tsx +115 -17
- package/daemon/src/review/markdown.ts +6 -1
- package/daemon/src/review/model.ts +13 -1
- package/daemon/src/review/proxy.ts +30 -3
- package/daemon/src/review/remote.ts +112 -0
- package/daemon/src/review/sealing.ts +35 -0
- package/daemon/src/review/server.ts +16 -1
- package/daemon/src/review/store.ts +20 -28
- package/daemon/src/review/threads.ts +63 -0
- package/daemon/src/server.ts +1 -1
- package/daemon/tsconfig.json +1 -1
- package/package.json +23 -6
- package/skills/canvas/SKILL.md +2 -1
- package/types/bin/agent-canvas.d.ts +2 -0
- package/types/bin/lib/commands/daemon.d.ts +1 -0
- package/types/bin/lib/commands/exec.d.ts +7 -0
- package/types/bin/lib/commands/fetch.d.ts +1 -0
- package/types/bin/lib/commands/install.d.ts +1 -0
- package/types/bin/lib/commands/instructions.d.ts +1 -0
- package/types/bin/lib/commands/push.d.ts +1 -0
- package/types/bin/lib/commands/review-remote.d.ts +52 -0
- package/types/bin/lib/commands/review.d.ts +1 -0
- package/types/bin/lib/commands/watch.d.ts +1 -0
- package/types/bin/lib/config.d.ts +9 -0
- package/types/bin/lib/daemon-lifecycle.d.ts +4 -0
- package/types/bin/lib/helpers.d.ts +13 -0
- package/types/daemon/build.d.ts +1 -0
- package/types/daemon/client/App.d.ts +1 -0
- package/types/daemon/client/CompareView.d.ts +17 -0
- package/types/daemon/client/FileBrowser.d.ts +4 -0
- package/types/daemon/client/FileViewer.d.ts +6 -0
- package/types/daemon/client/OverviewView.d.ts +18 -0
- package/types/daemon/client/ReviewerIdentityDialog.d.ts +17 -0
- package/types/daemon/client/RevisionSelect.d.ts +10 -0
- package/types/daemon/client/SessionSwitcher.d.ts +6 -0
- package/types/daemon/client/ShareDialog.d.ts +30 -0
- package/types/daemon/client/apiSchemas.d.ts +1311 -0
- package/types/daemon/client/canvas-runtime.d.ts +1 -0
- package/types/daemon/client/clientApi.d.ts +112 -0
- package/types/daemon/client/components/SecretInput.d.ts +10 -0
- package/types/daemon/client/components/index.d.ts +2 -0
- package/types/daemon/client/domDiff.d.ts +37 -0
- package/types/daemon/client/errorMessage.d.ts +1 -0
- package/types/daemon/client/exportMarkdown.d.ts +1 -0
- package/types/daemon/client/lcs.d.ts +2 -0
- package/types/daemon/client/shareCrypto.d.ts +40 -0
- package/types/daemon/client/unifiedDiff.d.ts +26 -0
- package/types/daemon/langMap.d.ts +2 -0
- package/types/daemon/review-widget/anchor.d.ts +18 -0
- package/types/daemon/review-widget/browser.d.ts +6 -0
- package/types/daemon/review-widget/client.d.ts +38 -0
- package/types/daemon/review-widget/index.d.ts +1 -0
- package/types/daemon/review-widget/markup.d.ts +4 -0
- package/types/daemon/review-widget/remote-client.d.ts +29 -0
- package/types/daemon/review-widget/screenshot.d.ts +8 -0
- package/types/daemon/review-widget/source.d.ts +17 -0
- package/types/daemon/review-widget/style.d.ts +7 -0
- package/types/daemon/review-widget/widget.d.ts +7 -0
- package/types/daemon/src/components.d.ts +10 -0
- package/types/daemon/src/handlers/api.d.ts +11 -0
- package/types/daemon/src/handlers/files.d.ts +3 -0
- package/types/daemon/src/handlers/static.d.ts +2 -0
- package/types/daemon/src/handlers/uploads.d.ts +3 -0
- package/types/daemon/src/paths.d.ts +12 -0
- package/types/daemon/src/remote-feedback.d.ts +4 -0
- package/types/daemon/src/review/markdown.d.ts +3 -0
- package/types/daemon/src/review/model.d.ts +1089 -0
- package/types/daemon/src/review/proxy.d.ts +30 -0
- package/types/daemon/src/review/remote.d.ts +258 -0
- package/types/daemon/src/review/sealing.d.ts +11 -0
- package/types/daemon/src/review/server.d.ts +24 -0
- package/types/daemon/src/review/store.d.ts +34 -0
- package/types/daemon/src/review/threads.d.ts +35 -0
- package/types/daemon/src/server.d.ts +7 -0
- package/types/daemon/src/share.d.ts +98 -0
- package/types/daemon/src/stubFetch.d.ts +2 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReviewStore } from './store';
|
|
2
|
+
/** The page path a Vite full reload names, or `undefined` for any other frame. */
|
|
3
|
+
export declare function viteFullReloadPath(frame: string): string | undefined;
|
|
4
|
+
/** Puts the widget's tag before `</body>`, or at the end of a document without one. */
|
|
5
|
+
export declare function withWidget(html: string, tag: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Review proxies: each project's application, served on a port of its own with the review widget added to every HTML
|
|
8
|
+
* page, so a reviewer opens a URL instead of editing the application. The proxy's origin is a loopback one, which the
|
|
9
|
+
* review routes accept; it forwards to applications on this machine only.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ReviewProxies {
|
|
12
|
+
private readonly store;
|
|
13
|
+
private readonly widgetScript;
|
|
14
|
+
private readonly onFullReload;
|
|
15
|
+
private readonly running;
|
|
16
|
+
/**
|
|
17
|
+
* `onFullReload` receives the full reloads the application's dev server asks for: the proxy holds them back from
|
|
18
|
+
* the page, so a reload does not take the comment the reviewer is writing.
|
|
19
|
+
*/
|
|
20
|
+
constructor(store: ReviewStore, widgetScript: string, onFullReload: (project: string, path: string) => void);
|
|
21
|
+
/** Serves the project's application at `target` and returns where the reviewer opens it, `target`'s path kept. */
|
|
22
|
+
open(project: string, target: string): string;
|
|
23
|
+
/** Serves every proxy a previous daemon served, on the same ports. */
|
|
24
|
+
restore(): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
private listen;
|
|
27
|
+
private serve;
|
|
28
|
+
/** Connects to the application first, so the browser gets the subprotocol the application chose. */
|
|
29
|
+
private upgrade;
|
|
30
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Remote review: the threads of an application deployed somewhere else, kept by the share worker. The reviewer's
|
|
4
|
+
* browser and the agent's CLI share a key the worker never sees, so the worker stores and relays ciphertext. It reads
|
|
5
|
+
* only what moves a thread through its lifecycle: ids, states, comment authors and timestamps.
|
|
6
|
+
*/
|
|
7
|
+
/** The worker's name for a remote project: 12 random bytes, hex. Knowing it, from an allowed origin, lets a browser write. */
|
|
8
|
+
export declare const REMOTE_PROJECT_ID_RE: RegExp;
|
|
9
|
+
/** The fragment that hands a reviewer the project and its key: `#agent-canvas-review=<projectId>.<key>`. */
|
|
10
|
+
export declare const REVIEW_FRAGMENT_PARAM = "agent-canvas-review";
|
|
11
|
+
export declare const MAX_ORIGINS = 5;
|
|
12
|
+
export declare const MAX_THREADS = 1000;
|
|
13
|
+
export declare const MAX_COMMENTS = 200;
|
|
14
|
+
/** Ciphertext limits: base64 of AES-GCM over the plaintext limits in `model.ts`, with room for multi-byte UTF-8. */
|
|
15
|
+
export declare const MAX_SEALED_ANCHOR = 160000;
|
|
16
|
+
export declare const MAX_SEALED_BODY = 110000;
|
|
17
|
+
export declare const MAX_SEALED_SCREENSHOT = 11000000;
|
|
18
|
+
/** A deployed application's origin, or one on this machine for trying the setup out. */
|
|
19
|
+
export declare const reviewOriginSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
20
|
+
export declare const sealedCommentSchema: z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
author: z.ZodEnum<["user", "agent"]>;
|
|
23
|
+
body: z.ZodString;
|
|
24
|
+
createdAt: z.ZodString;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
id: string;
|
|
27
|
+
author: "user" | "agent";
|
|
28
|
+
body: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
}, {
|
|
31
|
+
id: string;
|
|
32
|
+
author: "user" | "agent";
|
|
33
|
+
body: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
}>;
|
|
36
|
+
export type SealedComment = z.infer<typeof sealedCommentSchema>;
|
|
37
|
+
export declare const sealedThreadSchema: z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
/** The `ReviewAnchor` as JSON, sealed. */
|
|
40
|
+
anchor: z.ZodString;
|
|
41
|
+
state: z.ZodEnum<["open", "queued", "working", "resolved"]>;
|
|
42
|
+
comments: z.ZodArray<z.ZodObject<{
|
|
43
|
+
id: z.ZodString;
|
|
44
|
+
author: z.ZodEnum<["user", "agent"]>;
|
|
45
|
+
body: z.ZodString;
|
|
46
|
+
createdAt: z.ZodString;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
id: string;
|
|
49
|
+
author: "user" | "agent";
|
|
50
|
+
body: string;
|
|
51
|
+
createdAt: string;
|
|
52
|
+
}, {
|
|
53
|
+
id: string;
|
|
54
|
+
author: "user" | "agent";
|
|
55
|
+
body: string;
|
|
56
|
+
createdAt: string;
|
|
57
|
+
}>, "many">;
|
|
58
|
+
/** Whether the reviewer attached a screenshot; the agent fetches it separately. */
|
|
59
|
+
screenshot: z.ZodBoolean;
|
|
60
|
+
createdAt: z.ZodString;
|
|
61
|
+
updatedAt: z.ZodString;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
anchor: string;
|
|
64
|
+
id: string;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
state: "open" | "queued" | "working" | "resolved";
|
|
67
|
+
comments: {
|
|
68
|
+
id: string;
|
|
69
|
+
author: "user" | "agent";
|
|
70
|
+
body: string;
|
|
71
|
+
createdAt: string;
|
|
72
|
+
}[];
|
|
73
|
+
screenshot: boolean;
|
|
74
|
+
updatedAt: string;
|
|
75
|
+
}, {
|
|
76
|
+
anchor: string;
|
|
77
|
+
id: string;
|
|
78
|
+
createdAt: string;
|
|
79
|
+
state: "open" | "queued" | "working" | "resolved";
|
|
80
|
+
comments: {
|
|
81
|
+
id: string;
|
|
82
|
+
author: "user" | "agent";
|
|
83
|
+
body: string;
|
|
84
|
+
createdAt: string;
|
|
85
|
+
}[];
|
|
86
|
+
screenshot: boolean;
|
|
87
|
+
updatedAt: string;
|
|
88
|
+
}>;
|
|
89
|
+
export type SealedThread = z.infer<typeof sealedThreadSchema>;
|
|
90
|
+
export declare const sealedThreadsSchema: z.ZodObject<{
|
|
91
|
+
threads: z.ZodArray<z.ZodObject<{
|
|
92
|
+
id: z.ZodString;
|
|
93
|
+
/** The `ReviewAnchor` as JSON, sealed. */
|
|
94
|
+
anchor: z.ZodString;
|
|
95
|
+
state: z.ZodEnum<["open", "queued", "working", "resolved"]>;
|
|
96
|
+
comments: z.ZodArray<z.ZodObject<{
|
|
97
|
+
id: z.ZodString;
|
|
98
|
+
author: z.ZodEnum<["user", "agent"]>;
|
|
99
|
+
body: z.ZodString;
|
|
100
|
+
createdAt: z.ZodString;
|
|
101
|
+
}, "strip", z.ZodTypeAny, {
|
|
102
|
+
id: string;
|
|
103
|
+
author: "user" | "agent";
|
|
104
|
+
body: string;
|
|
105
|
+
createdAt: string;
|
|
106
|
+
}, {
|
|
107
|
+
id: string;
|
|
108
|
+
author: "user" | "agent";
|
|
109
|
+
body: string;
|
|
110
|
+
createdAt: string;
|
|
111
|
+
}>, "many">;
|
|
112
|
+
/** Whether the reviewer attached a screenshot; the agent fetches it separately. */
|
|
113
|
+
screenshot: z.ZodBoolean;
|
|
114
|
+
createdAt: z.ZodString;
|
|
115
|
+
updatedAt: z.ZodString;
|
|
116
|
+
}, "strip", z.ZodTypeAny, {
|
|
117
|
+
anchor: string;
|
|
118
|
+
id: string;
|
|
119
|
+
createdAt: string;
|
|
120
|
+
state: "open" | "queued" | "working" | "resolved";
|
|
121
|
+
comments: {
|
|
122
|
+
id: string;
|
|
123
|
+
author: "user" | "agent";
|
|
124
|
+
body: string;
|
|
125
|
+
createdAt: string;
|
|
126
|
+
}[];
|
|
127
|
+
screenshot: boolean;
|
|
128
|
+
updatedAt: string;
|
|
129
|
+
}, {
|
|
130
|
+
anchor: string;
|
|
131
|
+
id: string;
|
|
132
|
+
createdAt: string;
|
|
133
|
+
state: "open" | "queued" | "working" | "resolved";
|
|
134
|
+
comments: {
|
|
135
|
+
id: string;
|
|
136
|
+
author: "user" | "agent";
|
|
137
|
+
body: string;
|
|
138
|
+
createdAt: string;
|
|
139
|
+
}[];
|
|
140
|
+
screenshot: boolean;
|
|
141
|
+
updatedAt: string;
|
|
142
|
+
}>, "many">;
|
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
|
144
|
+
threads: {
|
|
145
|
+
anchor: string;
|
|
146
|
+
id: string;
|
|
147
|
+
createdAt: string;
|
|
148
|
+
state: "open" | "queued" | "working" | "resolved";
|
|
149
|
+
comments: {
|
|
150
|
+
id: string;
|
|
151
|
+
author: "user" | "agent";
|
|
152
|
+
body: string;
|
|
153
|
+
createdAt: string;
|
|
154
|
+
}[];
|
|
155
|
+
screenshot: boolean;
|
|
156
|
+
updatedAt: string;
|
|
157
|
+
}[];
|
|
158
|
+
}, {
|
|
159
|
+
threads: {
|
|
160
|
+
anchor: string;
|
|
161
|
+
id: string;
|
|
162
|
+
createdAt: string;
|
|
163
|
+
state: "open" | "queued" | "working" | "resolved";
|
|
164
|
+
comments: {
|
|
165
|
+
id: string;
|
|
166
|
+
author: "user" | "agent";
|
|
167
|
+
body: string;
|
|
168
|
+
createdAt: string;
|
|
169
|
+
}[];
|
|
170
|
+
screenshot: boolean;
|
|
171
|
+
updatedAt: string;
|
|
172
|
+
}[];
|
|
173
|
+
}>;
|
|
174
|
+
export declare const createRemoteProjectBodySchema: z.ZodObject<{
|
|
175
|
+
origins: z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">;
|
|
176
|
+
}, "strip", z.ZodTypeAny, {
|
|
177
|
+
origins: string[];
|
|
178
|
+
}, {
|
|
179
|
+
origins: string[];
|
|
180
|
+
}>;
|
|
181
|
+
export declare const createRemoteProjectResponseSchema: z.ZodObject<{
|
|
182
|
+
projectId: z.ZodString;
|
|
183
|
+
agentToken: z.ZodString;
|
|
184
|
+
}, "strip", z.ZodTypeAny, {
|
|
185
|
+
projectId: string;
|
|
186
|
+
agentToken: string;
|
|
187
|
+
}, {
|
|
188
|
+
projectId: string;
|
|
189
|
+
agentToken: string;
|
|
190
|
+
}>;
|
|
191
|
+
export declare const sealedCreateThreadBodySchema: z.ZodObject<{
|
|
192
|
+
anchor: z.ZodString;
|
|
193
|
+
body: z.ZodString;
|
|
194
|
+
send: z.ZodBoolean;
|
|
195
|
+
/** The PNG data URL, sealed. */
|
|
196
|
+
screenshot: z.ZodOptional<z.ZodString>;
|
|
197
|
+
}, "strip", z.ZodTypeAny, {
|
|
198
|
+
anchor: string;
|
|
199
|
+
body: string;
|
|
200
|
+
send: boolean;
|
|
201
|
+
screenshot?: string | undefined;
|
|
202
|
+
}, {
|
|
203
|
+
anchor: string;
|
|
204
|
+
body: string;
|
|
205
|
+
send: boolean;
|
|
206
|
+
screenshot?: string | undefined;
|
|
207
|
+
}>;
|
|
208
|
+
export declare const sealedCommentBodySchema: z.ZodObject<{
|
|
209
|
+
body: z.ZodString;
|
|
210
|
+
send: z.ZodBoolean;
|
|
211
|
+
}, "strip", z.ZodTypeAny, {
|
|
212
|
+
body: string;
|
|
213
|
+
send: boolean;
|
|
214
|
+
}, {
|
|
215
|
+
body: string;
|
|
216
|
+
send: boolean;
|
|
217
|
+
}>;
|
|
218
|
+
export declare const sealedAgentReplyBodySchema: z.ZodObject<{
|
|
219
|
+
body: z.ZodString;
|
|
220
|
+
resolve: z.ZodBoolean;
|
|
221
|
+
}, "strip", z.ZodTypeAny, {
|
|
222
|
+
body: string;
|
|
223
|
+
resolve: boolean;
|
|
224
|
+
}, {
|
|
225
|
+
body: string;
|
|
226
|
+
resolve: boolean;
|
|
227
|
+
}>;
|
|
228
|
+
export declare const sealedScreenshotSchema: z.ZodObject<{
|
|
229
|
+
screenshot: z.ZodString;
|
|
230
|
+
}, "strip", z.ZodTypeAny, {
|
|
231
|
+
screenshot: string;
|
|
232
|
+
}, {
|
|
233
|
+
screenshot: string;
|
|
234
|
+
}>;
|
|
235
|
+
/** Frames the worker sends to a project's browsers. */
|
|
236
|
+
export type RemoteBrowserFrame = {
|
|
237
|
+
type: 'threads';
|
|
238
|
+
threads: readonly SealedThread[];
|
|
239
|
+
} | {
|
|
240
|
+
type: 'agent-status';
|
|
241
|
+
watching: boolean;
|
|
242
|
+
};
|
|
243
|
+
/** Sockets send this to keep an idle connection open; the worker answers `pong` without waking the project. */
|
|
244
|
+
export declare const KEEPALIVE_PING = "ping";
|
|
245
|
+
export declare const KEEPALIVE_PONG = "pong";
|
|
246
|
+
export interface ReviewCredentials {
|
|
247
|
+
projectId: string;
|
|
248
|
+
/** The base64url AES-GCM key, as `exportShareKey` writes it. */
|
|
249
|
+
key: string;
|
|
250
|
+
}
|
|
251
|
+
/** `<projectId>.<key>`, the value of the fragment parameter. */
|
|
252
|
+
export declare function formatReviewCredentials(credentials: ReviewCredentials): string;
|
|
253
|
+
export declare function parseReviewCredentials(value: string): ReviewCredentials | null;
|
|
254
|
+
/**
|
|
255
|
+
* A WebSocket client cannot always set headers, so the agent's wait socket offers its token as a second subprotocol:
|
|
256
|
+
* `[AGENT_SOCKET_PROTOCOL, <agent token>]`. The worker answers with the first one only.
|
|
257
|
+
*/
|
|
258
|
+
export declare const AGENT_SOCKET_PROTOCOL = "agent-canvas-review";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReviewAnchor, type ReviewThread } from './model';
|
|
2
|
+
import type { SealedThread } from './remote';
|
|
3
|
+
/** What the reviewer's browser and the agent's CLI seal before a remote project's worker sees it, and open after. */
|
|
4
|
+
export declare function sealAnchor(key: CryptoKey, anchor: ReviewAnchor): Promise<string>;
|
|
5
|
+
export declare function sealText(key: CryptoKey, text: string): Promise<string>;
|
|
6
|
+
export declare function openText(key: CryptoKey, sealed: string): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Opens a thread into the shape the widget and the agent read. A thread that does not decrypt with the key or does not
|
|
9
|
+
* parse once open was not sealed by this project's browser or CLI; it throws.
|
|
10
|
+
*/
|
|
11
|
+
export declare function openThread(key: CryptoKey, thread: SealedThread, screenshot?: string): Promise<ReviewThread>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ChannelSocket } from '@fabrika/daemon-kit';
|
|
2
|
+
import type { ReviewProxies } from './proxy';
|
|
3
|
+
import type { ReviewStore } from './store';
|
|
4
|
+
export interface ReviewSocketData {
|
|
5
|
+
type: 'review';
|
|
6
|
+
role: 'browser' | 'wait';
|
|
7
|
+
project: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ReviewSocket extends ChannelSocket {
|
|
10
|
+
data: ReviewSocketData;
|
|
11
|
+
}
|
|
12
|
+
/** Review mode: threads a person leaves on a running application through the injected widget, and their delivery to the agent. */
|
|
13
|
+
export declare function createReviewServer(store: ReviewStore, proxies: ReviewProxies): {
|
|
14
|
+
channel: import("@fabrika/daemon-kit").NotificationChannel<ReviewSocket>;
|
|
15
|
+
/** Hands a full reload the application asked for to the project's widgets, which reload unless the reviewer is writing. */
|
|
16
|
+
fullReload(project: string, path: string): void;
|
|
17
|
+
/** Answers the request when it is review mode's: CORS preflight, a route, or a WebSocket upgrade. */
|
|
18
|
+
fetch(req: Request, url: URL, server: {
|
|
19
|
+
upgrade(req: Request, options: {
|
|
20
|
+
data: ReviewSocketData;
|
|
21
|
+
}): boolean;
|
|
22
|
+
}): Response | Promise<Response> | "upgraded" | null;
|
|
23
|
+
};
|
|
24
|
+
export type ReviewServer = ReturnType<typeof createReviewServer>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReviewAnchor, type ReviewProxy, type ReviewThread } from './model';
|
|
2
|
+
/**
|
|
3
|
+
* Review threads of each project: `<directory>/<project>/threads.json`, attached screenshots beside it, and the
|
|
4
|
+
* project's review proxy in `proxy.json`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ReviewStore {
|
|
7
|
+
private readonly directory;
|
|
8
|
+
private readonly now;
|
|
9
|
+
constructor(directory: string, now?: () => Date);
|
|
10
|
+
list(project: string): readonly ReviewThread[];
|
|
11
|
+
create(project: string, anchor: ReviewAnchor, body: string, send: boolean, screenshot?: Uint8Array): ReviewThread;
|
|
12
|
+
/** A comment from the person reopens a resolved thread; with `send` it goes to the agent. */
|
|
13
|
+
addUserComment(project: string, threadId: string, body: string, send: boolean): ReviewThread;
|
|
14
|
+
send(project: string, threadId: string): ReviewThread;
|
|
15
|
+
/** Sends every unsent note at once, so the agent picks them up as one batch. */
|
|
16
|
+
sendNotes(project: string): readonly ReviewThread[];
|
|
17
|
+
setResolved(project: string, threadId: string, resolved: boolean): ReviewThread;
|
|
18
|
+
delete(project: string, threadId: string): void;
|
|
19
|
+
/** Hands every queued thread to the agent: they become `working` and are returned in creation order. */
|
|
20
|
+
claimQueued(project: string): readonly ReviewThread[];
|
|
21
|
+
/** The agent's answer. Without `resolve` the thread goes back to the person as `open`. */
|
|
22
|
+
agentReply(project: string, threadId: string, body: string, resolve: boolean): ReviewThread;
|
|
23
|
+
proxyOf(project: string): ReviewProxy | undefined;
|
|
24
|
+
saveProxy(project: string, proxy: ReviewProxy): void;
|
|
25
|
+
/** Projects that have a review proxy, for a starting daemon to serve again. */
|
|
26
|
+
proxiedProjects(): string[];
|
|
27
|
+
private update;
|
|
28
|
+
private comment;
|
|
29
|
+
private writeScreenshot;
|
|
30
|
+
private save;
|
|
31
|
+
private writeJson;
|
|
32
|
+
private projectDirectory;
|
|
33
|
+
private timestamp;
|
|
34
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ReviewComment, ReviewThreadState } from './model';
|
|
2
|
+
/**
|
|
3
|
+
* The thread lifecycle, shared by the daemon's file store and the share worker's encrypted store. It reads and writes
|
|
4
|
+
* only state, comments and timestamps; the anchor and the screenshot are each store's own, so a comment body here may be
|
|
5
|
+
* plaintext or ciphertext.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ReviewError extends Error {
|
|
8
|
+
readonly status: 400 | 404 | 409;
|
|
9
|
+
constructor(message: string, status: 400 | 404 | 409);
|
|
10
|
+
}
|
|
11
|
+
export interface ThreadCore {
|
|
12
|
+
id: string;
|
|
13
|
+
state: ReviewThreadState;
|
|
14
|
+
comments: ReviewComment[];
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
}
|
|
17
|
+
/** A note the person saved and has not sent: open, with their own comment last rather than the agent's answer. */
|
|
18
|
+
export declare function isUnsentNote(thread: ThreadCore): boolean;
|
|
19
|
+
export declare function openingState(send: boolean): ReviewThreadState;
|
|
20
|
+
/** A comment from the person reopens a resolved thread; with `send` it goes to the agent. */
|
|
21
|
+
export declare function userCommented<T extends ThreadCore>(thread: T, comment: ReviewComment, send: boolean): T;
|
|
22
|
+
export declare function sent<T extends ThreadCore>(thread: T, now: string): T;
|
|
23
|
+
/** Sends every unsent note at once, so the agent picks them up as one batch. */
|
|
24
|
+
export declare function notesSent<T extends ThreadCore>(threads: readonly T[], now: string): {
|
|
25
|
+
threads: T[];
|
|
26
|
+
sent: T[];
|
|
27
|
+
};
|
|
28
|
+
export declare function resolvedAs<T extends ThreadCore>(thread: T, resolved: boolean, now: string): T;
|
|
29
|
+
/** Hands every queued thread to the agent: they become `working` and are returned in their original order. */
|
|
30
|
+
export declare function claimed<T extends ThreadCore>(threads: readonly T[], now: string): {
|
|
31
|
+
threads: T[];
|
|
32
|
+
claimed: T[];
|
|
33
|
+
};
|
|
34
|
+
/** The agent's answer. Without `resolve` the thread goes back to the person as `open`. */
|
|
35
|
+
export declare function agentReplied<T extends ThreadCore>(thread: T, comment: ReviewComment, resolve: boolean): T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SessionManager, type WSData } from '@fabrika/canvas-kernel/server';
|
|
2
|
+
import { type ReviewSocketData } from './review/server';
|
|
3
|
+
declare const sessionManager: SessionManager;
|
|
4
|
+
type SocketData = WSData | ReviewSocketData;
|
|
5
|
+
declare const server: Bun.Server<SocketData>;
|
|
6
|
+
export { server, sessionManager };
|
|
7
|
+
export declare const broadcastPlanUpdate: (sessionId: string) => void;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { SessionManager, ShareEntry } from '@fabrika/canvas-kernel/server';
|
|
2
|
+
import { type EncryptionMeta } from '../client/shareCrypto';
|
|
3
|
+
/**
|
|
4
|
+
* Canvas sharing: packages a specific revision into a self-contained
|
|
5
|
+
* snapshot and POSTs it to the configured cloud endpoint (CF Worker).
|
|
6
|
+
*
|
|
7
|
+
* The cloud endpoint stores the snapshot and returns a public capability
|
|
8
|
+
* URL that the author can send to reviewers. Runtime bundles
|
|
9
|
+
* (react/preact-compat, runtime.js, components.js) are NOT bundled into the
|
|
10
|
+
* payload — the worker serves matching runtime from its own deploy, keyed
|
|
11
|
+
* off `runtime.componentsVersion` in the payload. This keeps shares small
|
|
12
|
+
* while still guaranteeing version compatibility.
|
|
13
|
+
*
|
|
14
|
+
* End-to-end encryption (default on)
|
|
15
|
+
* ----------------------------------
|
|
16
|
+
* Unless `CANVAS_SHARE_ENCRYPTION=off`, each share is encrypted with a
|
|
17
|
+
* fresh AES-GCM-256 key generated client-side here. The key is embedded
|
|
18
|
+
* in the returned URL as a `#k=<base64url>` fragment, which browsers do
|
|
19
|
+
* not transmit to the worker. The worker stores opaque ciphertext and
|
|
20
|
+
* routing metadata only. The daemon retains the key on `ShareEntry` so it
|
|
21
|
+
* can also decrypt feedback polled from the worker.
|
|
22
|
+
*
|
|
23
|
+
* Legacy unencrypted shares remain supported: the worker accepts both
|
|
24
|
+
* formats, and the browser detects which one to use based on the URL
|
|
25
|
+
* fragment.
|
|
26
|
+
*/
|
|
27
|
+
export interface SharePayload {
|
|
28
|
+
version: 1;
|
|
29
|
+
/** Present iff payload fields below are ciphertext rather than plaintext. */
|
|
30
|
+
encryption?: EncryptionMeta;
|
|
31
|
+
origin: {
|
|
32
|
+
sessionId: string;
|
|
33
|
+
revision: number;
|
|
34
|
+
label?: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
};
|
|
37
|
+
canvasFiles: Array<{
|
|
38
|
+
filename: string;
|
|
39
|
+
compiledJs: string;
|
|
40
|
+
sourceJsx?: string;
|
|
41
|
+
}>;
|
|
42
|
+
runtime: {
|
|
43
|
+
componentsVersion: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface ShareResponse {
|
|
47
|
+
shareId: string;
|
|
48
|
+
url: string;
|
|
49
|
+
ownerToken?: string;
|
|
50
|
+
expiresAt?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface ShareConfig {
|
|
53
|
+
/** Base URL of the share worker, e.g. `https://canvas-share.example.workers.dev` */
|
|
54
|
+
endpoint: string;
|
|
55
|
+
/** Version of the @agent-canvas runtime bundles — worker uses this to pick matching runtime */
|
|
56
|
+
componentsVersion: string;
|
|
57
|
+
/** Optional bearer token. If the worker has SHARE_AUTH_TOKEN set, this
|
|
58
|
+
* must match. Loaded from CANVAS_SHARE_AUTH_TOKEN env var on the daemon. */
|
|
59
|
+
authToken?: string;
|
|
60
|
+
/** End-to-end encryption setting. Defaults to true. */
|
|
61
|
+
encryption?: boolean;
|
|
62
|
+
}
|
|
63
|
+
export declare function loadShareConfig(version: string): ShareConfig | null;
|
|
64
|
+
/**
|
|
65
|
+
* Build a SharePayload for the given session/revision. Reads the already
|
|
66
|
+
* compiled JS from the session's revision directory. Also includes the
|
|
67
|
+
* original JSX source for "view source" functionality on the shared canvas.
|
|
68
|
+
*/
|
|
69
|
+
export declare function buildSharePayload(sessionManager: SessionManager, sessionId: string, revision: number, componentsVersion: string): SharePayload;
|
|
70
|
+
/**
|
|
71
|
+
* Encrypt a plaintext SharePayload in-place semantics, returning a new
|
|
72
|
+
* payload whose secret fields are ciphertext + the `encryption` marker.
|
|
73
|
+
* Fields kept plaintext (and why):
|
|
74
|
+
* - `version`, `runtime.componentsVersion`: routing
|
|
75
|
+
* - `origin.revision`, `origin.createdAt`: indexing/display
|
|
76
|
+
* - `canvasFiles[].filename`: used as the route key by the worker
|
|
77
|
+
* Everything else (sessionId, label, compiledJs, sourceJsx) is encrypted.
|
|
78
|
+
*/
|
|
79
|
+
export declare function encryptSharePayload(payload: SharePayload, key: CryptoKey): Promise<SharePayload>;
|
|
80
|
+
/**
|
|
81
|
+
* POST the payload to the CF Worker. Returns the `shareId` + public URL
|
|
82
|
+
* assigned by the worker. Throws on any HTTP error — the caller is expected
|
|
83
|
+
* to surface the failure to the client (dialog) so the user can retry or
|
|
84
|
+
* fix their config.
|
|
85
|
+
*/
|
|
86
|
+
export declare function pushShareToWorker(payload: SharePayload, config: ShareConfig): Promise<ShareResponse>;
|
|
87
|
+
/**
|
|
88
|
+
* High-level: build payload, optionally encrypt it, push to worker, record
|
|
89
|
+
* the share on the session. The URL stored on the ShareEntry includes the
|
|
90
|
+
* `#k=...` fragment when encryption is on so the user can simply copy &
|
|
91
|
+
* paste it to reviewers.
|
|
92
|
+
*/
|
|
93
|
+
export declare function shareRevision(sessionManager: SessionManager, sessionId: string, revision: number, config: ShareConfig): Promise<ShareEntry>;
|
|
94
|
+
/**
|
|
95
|
+
* Revoke a share by calling the worker's owner-only delete endpoint. Removes
|
|
96
|
+
* it from the local session metadata on success.
|
|
97
|
+
*/
|
|
98
|
+
export declare function revokeShare(sessionManager: SessionManager, sessionId: string, shareId: string, config: ShareConfig): Promise<void>;
|