agent-canvas 0.9.0-cloudflare.2 → 0.9.0-cloudflare.3
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/review.js +3 -3
- package/daemon/review-widget/client.ts +16 -1
- package/daemon/review-widget/index.tsx +69 -11
- package/daemon/review-widget/remote-client.ts +117 -0
- package/daemon/review-widget/widget.tsx +3 -9
- package/daemon/src/review/model.ts +0 -5
- package/daemon/src/review/remote.ts +112 -0
- package/daemon/src/review/sealing.ts +35 -0
- package/daemon/src/review/server.ts +2 -1
- package/daemon/src/review/store.ts +16 -35
- package/daemon/src/review/threads.ts +63 -0
- 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
package/README.md
CHANGED
|
@@ -97,6 +97,16 @@ Threads are stored per project under the daemon's data directory. The daemon acc
|
|
|
97
97
|
origins (`localhost`, `127.0.0.1`, `*.localhost`) and agent requests only from clients that send no `Origin`, so a web
|
|
98
98
|
page cannot queue work for the agent.
|
|
99
99
|
|
|
100
|
+
#### Remote review
|
|
101
|
+
|
|
102
|
+
The same loop works on a deployed application. `bunx agent-canvas review share https://prototype.example.com --project my-app`
|
|
103
|
+
creates a project on the share worker and prints a `<script>` tag for the application and a link for the reviewer. The
|
|
104
|
+
link carries the project and an AES-GCM key in its fragment, which never reaches a server: the widget seals every
|
|
105
|
+
anchor, comment and screenshot before sending it, the CLI opens them, and the worker stores and relays ciphertext. The
|
|
106
|
+
widget mounts only for a browser that opened the link, so the tag can stay in a public deployment. The worker accepts
|
|
107
|
+
widget requests only from the origin the project was shared for, and agent requests only with the token `share`
|
|
108
|
+
stored on this machine. `watch`, `reply`, `fetch` and `list` work as above.
|
|
109
|
+
|
|
100
110
|
## Theming
|
|
101
111
|
|
|
102
112
|
Agent Canvas supports light and dark themes, automatically matching your system preference.
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import { exportShareKey, generateShareKey, importShareKey } from '../../../daemon/client/shareCrypto.ts'
|
|
5
|
+
import { REVIEWS_DIR } from '../../../daemon/src/paths.ts'
|
|
6
|
+
import { renderReviewRequests } from '../../../daemon/src/review/markdown.ts'
|
|
7
|
+
import { type ReviewThread, screenshotDataUrlSchema } from '../../../daemon/src/review/model.ts'
|
|
8
|
+
import {
|
|
9
|
+
AGENT_SOCKET_PROTOCOL,
|
|
10
|
+
createRemoteProjectResponseSchema,
|
|
11
|
+
formatReviewCredentials,
|
|
12
|
+
KEEPALIVE_PING,
|
|
13
|
+
REMOTE_PROJECT_ID_RE,
|
|
14
|
+
REVIEW_FRAGMENT_PARAM,
|
|
15
|
+
sealedScreenshotSchema,
|
|
16
|
+
type SealedThread,
|
|
17
|
+
sealedThreadSchema,
|
|
18
|
+
sealedThreadsSchema,
|
|
19
|
+
} from '../../../daemon/src/review/remote.ts'
|
|
20
|
+
import { openText, openThread, sealText } from '../../../daemon/src/review/sealing.ts'
|
|
21
|
+
import { loadShareConfig } from '../../../daemon/src/share.ts'
|
|
22
|
+
import { VERSION } from '../config.ts'
|
|
23
|
+
|
|
24
|
+
const KEEPALIVE_MS = 30_000
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A remote review project as this machine knows it: where it lives, the key that seals its threads and the token that
|
|
28
|
+
* lets the agent claim and answer them. Both secrets stay in this file; the worker holds only the token's hash.
|
|
29
|
+
*/
|
|
30
|
+
const remoteReviewSchema = z.object({
|
|
31
|
+
endpoint: z.string().url(),
|
|
32
|
+
projectId: z.string().regex(REMOTE_PROJECT_ID_RE),
|
|
33
|
+
key: z.string(),
|
|
34
|
+
agentToken: z.string(),
|
|
35
|
+
appUrl: z.string().url(),
|
|
36
|
+
})
|
|
37
|
+
export type RemoteReview = z.infer<typeof remoteReviewSchema>
|
|
38
|
+
|
|
39
|
+
const errorSchema = z.object({ error: z.string() })
|
|
40
|
+
const threadResponseSchema = z.object({ thread: sealedThreadSchema })
|
|
41
|
+
|
|
42
|
+
function projectDirectory(project: string): string {
|
|
43
|
+
return join(REVIEWS_DIR, project)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function remoteFile(project: string): string {
|
|
47
|
+
return join(projectDirectory(project), 'remote.json')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function loadRemoteReview(project: string): RemoteReview | undefined {
|
|
51
|
+
const path = remoteFile(project)
|
|
52
|
+
if (!existsSync(path)) return undefined
|
|
53
|
+
return remoteReviewSchema.parse(JSON.parse(readFileSync(path, 'utf-8')))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Creates the project on the share worker for the application at `appUrl` and keeps its secrets on this machine. */
|
|
57
|
+
export async function createRemoteReview(project: string, appUrl: URL): Promise<RemoteReview> {
|
|
58
|
+
const config = loadShareConfig(VERSION)
|
|
59
|
+
if (config === null) throw new Error('Set CANVAS_SHARE_ENDPOINT to the share worker that keeps remote reviews')
|
|
60
|
+
const response = await fetch(`${config.endpoint}/reviews`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { 'Content-Type': 'application/json', ...(config.authToken === undefined ? {} : { Authorization: `Bearer ${config.authToken}` }) },
|
|
63
|
+
body: JSON.stringify({ origins: [appUrl.origin] }),
|
|
64
|
+
})
|
|
65
|
+
const body: unknown = await response.json()
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const error = errorSchema.safeParse(body)
|
|
68
|
+
throw new Error(`The share worker refused the review project: ${error.success ? error.data.error : response.status}`)
|
|
69
|
+
}
|
|
70
|
+
const created = createRemoteProjectResponseSchema.parse(body)
|
|
71
|
+
const remote: RemoteReview = {
|
|
72
|
+
endpoint: config.endpoint,
|
|
73
|
+
projectId: created.projectId,
|
|
74
|
+
key: await exportShareKey(await generateShareKey()),
|
|
75
|
+
agentToken: created.agentToken,
|
|
76
|
+
appUrl: appUrl.href,
|
|
77
|
+
}
|
|
78
|
+
mkdirSync(projectDirectory(project), { recursive: true })
|
|
79
|
+
writeFileSync(remoteFile(project), `${JSON.stringify(remote, null, '\t')}\n`, { mode: 0o600 })
|
|
80
|
+
chmodSync(remoteFile(project), 0o600)
|
|
81
|
+
return remote
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The address the reviewer opens: the application, with the project and its key in the fragment. */
|
|
85
|
+
export function reviewerLink(remote: RemoteReview): string {
|
|
86
|
+
const app = new URL(remote.appUrl)
|
|
87
|
+
app.hash = `${REVIEW_FRAGMENT_PARAM}=${formatReviewCredentials({ projectId: remote.projectId, key: remote.key })}`
|
|
88
|
+
return app.href
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function remoteSnippet(remote: RemoteReview): string {
|
|
92
|
+
return `<script src="${remote.endpoint}/assets/review.js" defer></script>`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The agent's side of a remote project: every request carries the agent token, every thread is opened here. */
|
|
96
|
+
export class RemoteReviewBackend {
|
|
97
|
+
private key: Promise<CryptoKey> | null = null
|
|
98
|
+
|
|
99
|
+
constructor(private readonly project: string, private readonly remote: RemoteReview) {}
|
|
100
|
+
|
|
101
|
+
get waitUrl(): string {
|
|
102
|
+
return `${this.remote.endpoint.replace(/^http/, 'ws')}/review/${this.remote.projectId}/agent/ws`
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The agent's wait socket; it pings so an idle connection stays open between batches. */
|
|
106
|
+
createSocket(url: string): WebSocket {
|
|
107
|
+
const socket = new WebSocket(url, [AGENT_SOCKET_PROTOCOL, this.remote.agentToken])
|
|
108
|
+
let keepalive: ReturnType<typeof setInterval> | null = null
|
|
109
|
+
socket.addEventListener('open', () => {
|
|
110
|
+
keepalive = setInterval(() => socket.send(KEEPALIVE_PING), KEEPALIVE_MS)
|
|
111
|
+
})
|
|
112
|
+
socket.addEventListener('close', () => {
|
|
113
|
+
if (keepalive !== null) clearInterval(keepalive)
|
|
114
|
+
})
|
|
115
|
+
return socket
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Takes the sent threads, as markdown, or `undefined` when none are waiting. */
|
|
119
|
+
async claim(): Promise<string | undefined> {
|
|
120
|
+
const { threads } = sealedThreadsSchema.parse(await this.call('POST', '/claim'))
|
|
121
|
+
if (threads.length === 0) return undefined
|
|
122
|
+
const opened: ReviewThread[] = []
|
|
123
|
+
const unreadable: string[] = []
|
|
124
|
+
for (const thread of threads) {
|
|
125
|
+
try {
|
|
126
|
+
opened.push(await this.open(thread, true))
|
|
127
|
+
} catch {
|
|
128
|
+
unreadable.push(thread.id)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const markdown = opened.length === 0 ? '' : renderReviewRequests(this.project, opened)
|
|
132
|
+
if (unreadable.length === 0) return markdown
|
|
133
|
+
return `${markdown}\nThese threads did not open with this project's key, so they were not sealed by its reviewers: ${unreadable.join(', ')}\n`
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async threads(): Promise<ReviewThread[]> {
|
|
137
|
+
const { threads } = sealedThreadsSchema.parse(await this.call('GET', '/threads'))
|
|
138
|
+
const opened = await Promise.allSettled(threads.map((thread) => this.open(thread, false)))
|
|
139
|
+
return opened.flatMap((result) => (result.status === 'fulfilled' ? [result.value] : []))
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async reply(threadId: string, body: string, resolve: boolean): Promise<void> {
|
|
143
|
+
threadResponseSchema.parse(
|
|
144
|
+
await this.call('POST', `/threads/${encodeURIComponent(threadId)}/reply`, { body: await sealText(await this.cryptoKey(), body), resolve }),
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private async open(thread: SealedThread, withScreenshot: boolean): Promise<ReviewThread> {
|
|
149
|
+
const key = await this.cryptoKey()
|
|
150
|
+
const screenshot = withScreenshot && thread.screenshot ? await this.saveScreenshot(key, thread.id) : undefined
|
|
151
|
+
return openThread(key, thread, screenshot)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Writes the reviewer's screenshot where the agent can read it, as the daemon does for local threads. */
|
|
155
|
+
private async saveScreenshot(key: CryptoKey, threadId: string): Promise<string> {
|
|
156
|
+
const { screenshot } = sealedScreenshotSchema.parse(await this.call('GET', `/threads/${encodeURIComponent(threadId)}/screenshot`))
|
|
157
|
+
const png = screenshotDataUrlSchema.parse(await openText(key, screenshot))
|
|
158
|
+
const directory = join(projectDirectory(this.project), 'screenshots')
|
|
159
|
+
mkdirSync(directory, { recursive: true })
|
|
160
|
+
const path = join(directory, `${threadId}.png`)
|
|
161
|
+
writeFileSync(path, png)
|
|
162
|
+
return path
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private cryptoKey(): Promise<CryptoKey> {
|
|
166
|
+
this.key ??= importShareKey(this.remote.key)
|
|
167
|
+
return this.key
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private async call(method: string, path: string, body?: unknown): Promise<unknown> {
|
|
171
|
+
const response = await fetch(`${this.remote.endpoint}/review/${this.remote.projectId}/agent${path}`, {
|
|
172
|
+
method,
|
|
173
|
+
headers: {
|
|
174
|
+
Authorization: `Bearer ${this.remote.agentToken}`,
|
|
175
|
+
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
|
176
|
+
},
|
|
177
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
178
|
+
})
|
|
179
|
+
const result: unknown = await response.json()
|
|
180
|
+
if (!response.ok) {
|
|
181
|
+
const error = errorSchema.safeParse(result)
|
|
182
|
+
throw new Error(error.success ? error.data.error : `The share worker answered ${response.status}`)
|
|
183
|
+
}
|
|
184
|
+
return result
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -3,16 +3,21 @@ import { execFileSync } from 'child_process'
|
|
|
3
3
|
import { basename } from 'path'
|
|
4
4
|
import { parseArgs } from 'util'
|
|
5
5
|
import { z } from 'zod'
|
|
6
|
-
import { PROJECT_RE, reviewThreadSchema } from '../../../daemon/src/review/model.ts'
|
|
6
|
+
import { PROJECT_RE, type ReviewThread, reviewThreadSchema } from '../../../daemon/src/review/model.ts'
|
|
7
|
+
import { KEEPALIVE_PONG } from '../../../daemon/src/review/remote.ts'
|
|
7
8
|
import { BASE_URL, TIMEOUT_MS, WS_URL } from '../config.ts'
|
|
8
9
|
import { ensureDaemon } from '../daemon-lifecycle.ts'
|
|
9
10
|
import { openBrowser } from '../helpers.ts'
|
|
11
|
+
import { createRemoteReview, loadRemoteReview, RemoteReviewBackend, remoteSnippet, reviewerLink } from './review-remote.ts'
|
|
10
12
|
|
|
11
13
|
const USAGE = `agent-canvas review — comments on a running application
|
|
12
14
|
|
|
13
15
|
agent-canvas review open <url> [--follow] [--no-open]
|
|
14
16
|
Serve the app at <url> with the review widget, open it in the
|
|
15
17
|
browser and print the address; --follow then watches as below
|
|
18
|
+
agent-canvas review share <url> Make the project remote: the app deployed at <url> keeps its threads,
|
|
19
|
+
end-to-end encrypted, on the share worker. Prints the reviewer's link
|
|
20
|
+
and the <script> tag the app needs; run again to print them again
|
|
16
21
|
agent-canvas review snippet Print the <script> tag that adds the review widget to the app
|
|
17
22
|
agent-canvas review watch Wait for threads the reviewer sends (blocks)
|
|
18
23
|
agent-canvas review watch --follow Keep waiting; print every batch the reviewer sends
|
|
@@ -21,7 +26,8 @@ const USAGE = `agent-canvas review — comments on a running application
|
|
|
21
26
|
Answer a thread; --resolve closes it
|
|
22
27
|
agent-canvas review list Show every thread that is not resolved
|
|
23
28
|
|
|
24
|
-
Every command takes --project <name>; it defaults to CANVAS_REVIEW_PROJECT, then to the git repository's directory name
|
|
29
|
+
Every command takes --project <name>; it defaults to CANVAS_REVIEW_PROJECT, then to the git repository's directory name.
|
|
30
|
+
Once a project is shared, watch, fetch, reply and list talk to the share worker instead of the daemon.`
|
|
25
31
|
|
|
26
32
|
const claimSchema = z.union([z.object({ found: z.literal(false) }), z.object({ found: z.literal(true), markdown: z.string() })])
|
|
27
33
|
const threadsSchema = z.object({ threads: z.array(reviewThreadSchema) })
|
|
@@ -51,18 +57,55 @@ async function call(project: string, method: string, path: string, body?: unknow
|
|
|
51
57
|
return result
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
/** Where a project's threads live: the local daemon, or the share worker for a project made remote with `share`. */
|
|
61
|
+
interface ReviewBackend {
|
|
62
|
+
readonly waitUrl: string
|
|
63
|
+
createSocket(url: string): WebSocket
|
|
64
|
+
claim(): Promise<string | undefined>
|
|
65
|
+
threads(): Promise<ReviewThread[]>
|
|
66
|
+
reply(threadId: string, body: string, resolve: boolean): Promise<void>
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
|
|
69
|
+
class DaemonReviewBackend implements ReviewBackend {
|
|
70
|
+
constructor(private readonly project: string) {}
|
|
71
|
+
|
|
72
|
+
get waitUrl(): string {
|
|
73
|
+
return `${WS_URL}/ws/review-wait/${encodeURIComponent(this.project)}`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
createSocket(url: string): WebSocket {
|
|
77
|
+
return new WebSocket(url)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async claim(): Promise<string | undefined> {
|
|
81
|
+
const result = claimSchema.parse(await call(this.project, 'POST', '/claim'))
|
|
82
|
+
return result.found ? result.markdown : undefined
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async threads(): Promise<ReviewThread[]> {
|
|
86
|
+
return threadsSchema.parse(await call(this.project, 'GET', '/threads')).threads
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async reply(threadId: string, body: string, resolve: boolean): Promise<void> {
|
|
90
|
+
await call(this.project, 'POST', `/threads/${encodeURIComponent(threadId)}/reply`, { body, resolve })
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function backendOf(project: string): Promise<ReviewBackend> {
|
|
95
|
+
const remote = loadRemoteReview(project)
|
|
96
|
+
if (remote !== undefined) return new RemoteReviewBackend(project, remote)
|
|
97
|
+
await ensureDaemon()
|
|
98
|
+
return new DaemonReviewBackend(project)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function waitForRequests(backend: ReviewBackend): Promise<string> {
|
|
60
102
|
return waitForEvent<string>({
|
|
61
|
-
url:
|
|
103
|
+
url: backend.waitUrl,
|
|
104
|
+
createSocket: (url) => backend.createSocket(url),
|
|
62
105
|
// The frame only announces new threads; claiming them is what hands them over, exactly once.
|
|
63
106
|
onFrame: (frame) => (typeof frame === 'object' && frame !== null && 'type' in frame && frame.type === 'queued' ? { type: 'recheck' } : undefined),
|
|
64
107
|
probe: async () => {
|
|
65
|
-
const markdown = await claim(
|
|
108
|
+
const markdown = await backend.claim()
|
|
66
109
|
return markdown === undefined ? undefined : { value: markdown }
|
|
67
110
|
},
|
|
68
111
|
alreadyProbed: true,
|
|
@@ -84,13 +127,13 @@ const FOLLOW_GIVE_UP_MS = 60_000
|
|
|
84
127
|
* open, so the reviewer keeps seeing an agent listening between batches. Status goes to stderr; stdout carries only
|
|
85
128
|
* batches and the line that ends the watch, so every stdout event is worth acting on.
|
|
86
129
|
*/
|
|
87
|
-
function followRequests(project: string): Promise<never> {
|
|
130
|
+
function followRequests(project: string, backend: ReviewBackend): Promise<never> {
|
|
88
131
|
let claiming = Promise.resolve()
|
|
89
132
|
let unreachableSince: number | null = null
|
|
90
133
|
|
|
91
134
|
const claimAndPrint = () => {
|
|
92
135
|
claiming = claiming.then(async () => {
|
|
93
|
-
const markdown = await claim(
|
|
136
|
+
const markdown = await backend.claim()
|
|
94
137
|
if (markdown !== undefined) process.stdout.write(`${markdown}\n`)
|
|
95
138
|
}).catch((error: unknown) => {
|
|
96
139
|
console.error(`review watch: claim failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
@@ -98,7 +141,7 @@ function followRequests(project: string): Promise<never> {
|
|
|
98
141
|
}
|
|
99
142
|
|
|
100
143
|
const connect = () => {
|
|
101
|
-
const socket =
|
|
144
|
+
const socket = backend.createSocket(backend.waitUrl)
|
|
102
145
|
socket.onopen = () => {
|
|
103
146
|
unreachableSince = null
|
|
104
147
|
console.error(`review watch: listening for ${project}`)
|
|
@@ -106,12 +149,13 @@ function followRequests(project: string): Promise<never> {
|
|
|
106
149
|
}
|
|
107
150
|
socket.onmessage = (event) => {
|
|
108
151
|
// Any frame on the wait socket means "something was queued"; the claim reads what, so the frame needs no parsing.
|
|
109
|
-
|
|
152
|
+
// The share worker's keepalive answer is the one exception.
|
|
153
|
+
if (typeof event.data === 'string' && event.data !== KEEPALIVE_PONG) claimAndPrint()
|
|
110
154
|
}
|
|
111
155
|
socket.onclose = () => {
|
|
112
156
|
unreachableSince ??= Date.now()
|
|
113
157
|
if (Date.now() - unreachableSince > FOLLOW_GIVE_UP_MS) {
|
|
114
|
-
console.log(`review watch:
|
|
158
|
+
console.log(`review watch: ${backend.waitUrl} has been unreachable for a minute; stopped watching ${project}.`)
|
|
115
159
|
process.exit(1)
|
|
116
160
|
}
|
|
117
161
|
setTimeout(connect, FOLLOW_RECONNECT_MS)
|
|
@@ -140,26 +184,47 @@ export async function handleReview(args: string[]) {
|
|
|
140
184
|
switch (subcommand) {
|
|
141
185
|
case 'open': {
|
|
142
186
|
const [target] = positionals
|
|
187
|
+
const remote = loadRemoteReview(project)
|
|
188
|
+
if (remote !== undefined) {
|
|
189
|
+
const link = reviewerLink(remote)
|
|
190
|
+
console.log(`Review ${remote.appUrl} at ${link}`)
|
|
191
|
+
if (!values['no-open']) openBrowser(link)
|
|
192
|
+
if (values.follow) return followRequests(project, new RemoteReviewBackend(project, remote))
|
|
193
|
+
return
|
|
194
|
+
}
|
|
143
195
|
if (target === undefined) throw new Error('Usage: agent-canvas review open <url> [--follow] [--no-open]')
|
|
144
196
|
await ensureDaemon()
|
|
145
197
|
const { url } = proxySchema.parse(await call(project, 'POST', '/proxy', { target: new URL(target).href }))
|
|
146
198
|
console.log(`Review ${target} at ${url}`)
|
|
147
199
|
if (!values['no-open']) openBrowser(url)
|
|
148
|
-
if (values.follow) return followRequests(project)
|
|
200
|
+
if (values.follow) return followRequests(project, new DaemonReviewBackend(project))
|
|
201
|
+
return
|
|
202
|
+
}
|
|
203
|
+
case 'share': {
|
|
204
|
+
const [target] = positionals
|
|
205
|
+
const existing = loadRemoteReview(project)
|
|
206
|
+
if (existing === undefined && target === undefined) throw new Error('Usage: agent-canvas review share <url>')
|
|
207
|
+
if (existing !== undefined && target !== undefined && new URL(target).origin !== new URL(existing.appUrl).origin) {
|
|
208
|
+
throw new Error(`Project ${project} is already shared for ${new URL(existing.appUrl).origin}; pass another --project for ${target}`)
|
|
209
|
+
}
|
|
210
|
+
const remote = existing ?? await createRemoteReview(project, new URL(target ?? ''))
|
|
211
|
+
console.log(`Reviewer link (the key is in the fragment; send it only to reviewers):\n ${reviewerLink(remote)}\n`)
|
|
212
|
+
console.log(`Add the widget to every page of the deployed application:\n ${remoteSnippet(remote)}`)
|
|
149
213
|
return
|
|
150
214
|
}
|
|
151
|
-
case 'snippet':
|
|
152
|
-
|
|
215
|
+
case 'snippet': {
|
|
216
|
+
const remote = loadRemoteReview(project)
|
|
217
|
+
console.log(remote === undefined ? `<script src="${BASE_URL}/assets/review.js" data-project="${project}"></script>` : remoteSnippet(remote))
|
|
153
218
|
return
|
|
219
|
+
}
|
|
154
220
|
case 'watch': {
|
|
155
|
-
await
|
|
156
|
-
if (values.follow) return followRequests(project)
|
|
157
|
-
process.stdout.write((await claim(
|
|
221
|
+
const backend = await backendOf(project)
|
|
222
|
+
if (values.follow) return followRequests(project, backend)
|
|
223
|
+
process.stdout.write((await backend.claim()) ?? (await waitForRequests(backend)))
|
|
158
224
|
return
|
|
159
225
|
}
|
|
160
226
|
case 'fetch': {
|
|
161
|
-
await
|
|
162
|
-
const markdown = await claim(project)
|
|
227
|
+
const markdown = await (await backendOf(project)).claim()
|
|
163
228
|
process.stdout.write(markdown ?? 'No review requests are waiting.\n')
|
|
164
229
|
return
|
|
165
230
|
}
|
|
@@ -167,14 +232,12 @@ export async function handleReview(args: string[]) {
|
|
|
167
232
|
const [threadId, ...words] = positionals
|
|
168
233
|
const body = words.join(' ')
|
|
169
234
|
if (threadId === undefined || body.trim() === '') throw new Error('Usage: agent-canvas review reply <thread> <text> [--resolve]')
|
|
170
|
-
await
|
|
171
|
-
await call(project, 'POST', `/threads/${encodeURIComponent(threadId)}/reply`, { body, resolve: values.resolve })
|
|
235
|
+
await (await backendOf(project)).reply(threadId, body, values.resolve)
|
|
172
236
|
console.log(values.resolve ? `Replied to ${threadId} and resolved it.` : `Replied to ${threadId}.`)
|
|
173
237
|
return
|
|
174
238
|
}
|
|
175
239
|
case 'list': {
|
|
176
|
-
await
|
|
177
|
-
const { threads } = threadsSchema.parse(await call(project, 'GET', '/threads'))
|
|
240
|
+
const threads = await (await backendOf(project)).threads()
|
|
178
241
|
const pending = threads.filter((thread) => thread.state !== 'resolved')
|
|
179
242
|
if (pending.length === 0) console.log('No unresolved threads.')
|
|
180
243
|
for (const thread of pending) {
|
|
@@ -86,3 +86,34 @@ With the one-shot watcher, start `review watch` again for the next batch.
|
|
|
86
86
|
|
|
87
87
|
If the user says they already sent comments and no watcher was running, take them with `review fetch`. `review list`
|
|
88
88
|
shows every thread that is not resolved, notes included.
|
|
89
|
+
|
|
90
|
+
## Remote review — a deployed application
|
|
91
|
+
|
|
92
|
+
When the user wants comments on a deployed application (a prototype on a public URL, a staging site), make the project
|
|
93
|
+
remote. Its threads then live on the share worker, end-to-end encrypted: the reviewer's browser and this machine hold
|
|
94
|
+
the key, the worker stores ciphertext.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
bunx agent-canvas review share <deployed-url> --project <name>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
It prints two things:
|
|
101
|
+
|
|
102
|
+
1. The `<script>` tag the application needs on every page. Add it to the application's HTML and deploy it the way the
|
|
103
|
+
project deploys. The tag is inert for every visitor without the link, so it may stay in production.
|
|
104
|
+
2. The reviewer's link: the application with `#agent-canvas-review=<project>.<key>` in the fragment. The fragment never
|
|
105
|
+
reaches a server; the widget reads it, keeps it for that origin and removes it from the address bar. Give the link
|
|
106
|
+
to the user only; anyone holding it can read and write the threads. `#agent-canvas-review=off` makes a browser
|
|
107
|
+
forget it.
|
|
108
|
+
|
|
109
|
+
Running `share` again prints both again. The project allows only the origin of `<deployed-url>`; for another
|
|
110
|
+
deployment, share it under another `--project`.
|
|
111
|
+
|
|
112
|
+
The loop is the same as above: `review watch` (with `--follow` under Claude Code's Monitor), `review reply`,
|
|
113
|
+
`review fetch` and `review list` talk to the share worker once the project is remote, and need no daemon. A change
|
|
114
|
+
reaches the reviewer only after it is deployed, so deploy before you reply, and say in the reply when it is live.
|
|
115
|
+
Remote threads carry no `Source` positions unless the deployed build ships source maps.
|
|
116
|
+
|
|
117
|
+
`share` creates the project on `CANVAS_SHARE_ENDPOINT` (default `https://canvas.contember.com`); a worker that gates
|
|
118
|
+
share creation needs `CANVAS_SHARE_AUTH_TOKEN`. The project's key and agent token are stored in the agent-canvas data
|
|
119
|
+
directory under `reviews/<name>/remote.json`.
|
package/daemon/build.ts
CHANGED
package/daemon/client/App.tsx
CHANGED
|
@@ -1064,7 +1064,7 @@ function ResponseBanner({ markdown }: { markdown: string }) {
|
|
|
1064
1064
|
</svg>
|
|
1065
1065
|
<span className="text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body">Agent Response</span>
|
|
1066
1066
|
</div>
|
|
1067
|
-
{/*
|
|
1067
|
+
{/* oxlint-disable-next-line react/no-danger -- The response is the local agent's markdown, the same author whose canvas modules already execute as code here. */}
|
|
1068
1068
|
<div ref={contentRef} className="prose-canvas text-sm" dangerouslySetInnerHTML={{ __html: html }} />
|
|
1069
1069
|
</div>
|
|
1070
1070
|
|
|
@@ -43,7 +43,7 @@ function buildFileContext(range: Range): AnnotationContext {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function HighlightedLine({ html }: { html: string }) {
|
|
46
|
-
//
|
|
46
|
+
// oxlint-disable-next-line react/no-danger -- highlight.js escapes the file text and adds only its own span markup.
|
|
47
47
|
return <code className="py-px" dangerouslySetInnerHTML={{ __html: html }} />
|
|
48
48
|
}
|
|
49
49
|
|