shapewall 0.3.1 → 0.3.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/CHANGELOG.md +142 -0
- package/NOTICE +7 -0
- package/README.md +4 -2
- package/THIRD_PARTY.md +39 -0
- package/dist/agent/package-lock.json +2 -2
- package/dist/client/assets/BoardChat-DxehB761.js +27 -0
- package/dist/client/assets/BuzzDialog-Ix9qJvim.js +1 -0
- package/dist/client/assets/ChecksPanel-pA_ueIaJ.js +1 -0
- package/dist/client/assets/History-C9N32kCv.js +1 -0
- package/dist/client/assets/LocalSettings-DawtKnvi.js +1 -0
- package/dist/client/assets/{Management-BFcKFdbp.js → Management-NVFDtSZB.js} +1 -1
- package/dist/client/assets/QuickConnect-DO1TjS1t.js +1 -0
- package/dist/client/assets/ShareDialog-By0ETg6n.js +2 -0
- package/dist/client/assets/app-update-dialog-RGIw24iZ.js +1 -0
- package/dist/client/assets/{circle-x-PRxj7kPi.js → circle-x-B6KfScOE.js} +1 -1
- package/dist/client/assets/index-CsqLdqGx.css +2 -0
- package/dist/client/assets/index-DnZarJ3U.js +37 -0
- package/dist/client/assets/{refresh-cw-aeOBDuGQ.js → refresh-cw-vkgvCCfR.js} +1 -1
- package/dist/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- package/dist/client/assets/{shield-check-DuPBJ6H_.js → shield-check-QzwGhz0t.js} +1 -1
- package/dist/client/assets/ui-DI-FGWWK.js +41 -0
- package/dist/client/build-info.json +1 -1
- package/dist/client/index.html +4 -3
- package/dist/client/sw.js +2 -2
- package/dist/console/assets/{LocalAccountsApp-lJjkhUcH.js → LocalAccountsApp-VOCZg8dg.js} +1 -1
- package/dist/console/assets/{LocalConsole-BZHqYKnt.js → LocalConsole-CMwAW-mF.js} +1 -1
- package/dist/console/assets/{app-update-dialog-DCM9sYE3.js → app-update-dialog-Cw6UDqNP.js} +1 -1
- package/dist/console/assets/console-DgfWmUEx.js +55 -0
- package/dist/console/assets/console-Lis0vvdL.css +2 -0
- package/dist/console/build-info.json +1 -1
- package/dist/console/console.html +2 -2
- package/docs/agent-workflow.md +19 -3
- package/docs/agents.md +62 -2
- package/docs/config.md +3 -3
- package/docs/deployment.md +2 -0
- package/docs/design-system.md +20 -15
- package/docs/hosted.md +19 -0
- package/docs/pull-requests.md +4 -1
- package/docs/where-to-run.md +88 -0
- package/package.json +2 -1
- package/src/agent/agent-logos.js +81 -0
- package/src/agent/composer.js +9 -5
- package/src/agent/config.js +27 -2
- package/src/agent/context.js +3 -1
- package/src/agent/icon-store.js +100 -0
- package/src/agent/identity.js +77 -0
- package/src/agent/owner-mcp.js +19 -3
- package/src/agent/routes.js +82 -21
- package/src/agent/run.js +3 -1
- package/src/agent/settings-routes.js +233 -14
- package/src/agent/test-timing.js +14 -0
- package/src/agent/tools.js +6 -3
- package/src/agent/user-settings.js +51 -3
- package/src/capture/capture.js +3 -1
- package/src/capture/element-map.js +73 -11
- package/src/ci/settings.js +3 -3
- package/src/ci/start.js +16 -0
- package/src/ci/summary.js +8 -1
- package/src/cli/args.js +1 -0
- package/src/cli/ci.js +2 -2
- package/src/cli/comments.js +5 -4
- package/src/cli/help.js +3 -1
- package/src/cli/init.js +2 -2
- package/src/comment-fields.js +45 -0
- package/src/comments-cli.js +100 -21
- package/src/discover.js +34 -1
- package/src/doctor.js +26 -1
- package/src/event-log.js +5 -2
- package/src/feedback.js +5 -2
- package/src/github.js +4 -2
- package/src/hosted/agent-presence.js +40 -0
- package/src/hosted/app.js +6 -0
- package/src/hosted/board-routes.js +9 -1
- package/src/hosted/comments.js +11 -11
- package/src/hosted/console-routes.js +47 -1
- package/src/hosted/events.js +6 -4
- package/src/hosted/import.js +7 -4
- package/src/hosted/presence.js +1 -1
- package/src/hosted/projects.js +32 -1
- package/src/hosted/token-api.js +5 -1
- package/src/hosted/token-events.js +5 -2
- package/src/hosted/tokens.js +3 -2
- package/src/mcp.js +10 -2
- package/src/notify/messages.js +6 -4
- package/src/store.js +19 -11
- package/dist/client/assets/BoardChat-V1BCXdDB.js +0 -27
- package/dist/client/assets/BuzzDialog-Ds7Thpfe.js +0 -1
- package/dist/client/assets/ChecksPanel-Cm22bCdQ.js +0 -1
- package/dist/client/assets/History-U0bD1BjA.js +0 -1
- package/dist/client/assets/LocalSettings-DOSuW7VC.js +0 -1
- package/dist/client/assets/QuickConnect-DyfPSWbV.js +0 -1
- package/dist/client/assets/ShareDialog-BouvNraR.js +0 -2
- package/dist/client/assets/app-update-dialog-DH2Mgby8.js +0 -1
- package/dist/client/assets/index-C9S7HL_o.js +0 -37
- package/dist/client/assets/index-CXtuJi1K.css +0 -2
- package/dist/client/assets/ui-Cg4TTrec.js +0 -41
- package/dist/console/assets/console-C2LsvEco.js +0 -55
- package/dist/console/assets/console-Fp4k9iyx.css +0 -2
package/src/discover.js
CHANGED
|
@@ -266,7 +266,40 @@ export function cutTitle(value, max = 60) {
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
// Between a page's name and the site's in a <title>: bar, hyphen, en and em dash (as code points), dot, colon.
|
|
269
|
-
const TITLE_SEPARATORS = [
|
|
269
|
+
const TITLE_SEPARATORS = [
|
|
270
|
+
' | ',
|
|
271
|
+
' -- ',
|
|
272
|
+
' - ',
|
|
273
|
+
` ${String.fromCodePoint(0x2013)} `,
|
|
274
|
+
` ${String.fromCodePoint(0x2014)} `,
|
|
275
|
+
' · ',
|
|
276
|
+
' :: ',
|
|
277
|
+
': ',
|
|
278
|
+
]
|
|
279
|
+
|
|
280
|
+
// The site's name as its page titles give it: the part most of them end (or
|
|
281
|
+
// start) with after a separator ("Pricing | Acme", "Blog | Acme": "Acme").
|
|
282
|
+
// A home page title is often the name plus a tagline ("Acme | Notes that
|
|
283
|
+
// think"), so it is one vote among the pages, not the answer. Null when
|
|
284
|
+
// fewer than two titles, or fewer than half of them, agree.
|
|
285
|
+
export function siteNameFrom(titles) {
|
|
286
|
+
const list = titles.map((title) => String(title || '').trim()).filter(Boolean)
|
|
287
|
+
const votes = new Map()
|
|
288
|
+
for (const title of list) {
|
|
289
|
+
const seen = new Set()
|
|
290
|
+
for (const sep of TITLE_SEPARATORS) {
|
|
291
|
+
const first = title.indexOf(sep)
|
|
292
|
+
if (first < 0) continue
|
|
293
|
+
seen.add(title.slice(0, first).trim())
|
|
294
|
+
seen.add(title.slice(title.lastIndexOf(sep) + sep.length).trim())
|
|
295
|
+
}
|
|
296
|
+
for (const part of seen) if (part) votes.set(part, (votes.get(part) || 0) + 1)
|
|
297
|
+
}
|
|
298
|
+
let best = null
|
|
299
|
+
for (const [part, count] of votes)
|
|
300
|
+
if (!best || count > best.count || (count === best.count && part.length < best.part.length)) best = { part, count }
|
|
301
|
+
return best && best.count >= 2 && best.count * 2 >= list.length ? best.part : null
|
|
302
|
+
}
|
|
270
303
|
|
|
271
304
|
// A page's own title without the site name around it ("Pricing | Acme" is
|
|
272
305
|
// "Pricing" on the Acme board), or null when nothing of its own is left.
|
package/src/doctor.js
CHANGED
|
@@ -307,11 +307,36 @@ export function formatDoctor(report) {
|
|
|
307
307
|
return lines.join('\n')
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
// A line of the box Playwright's installer draws around its npx warning.
|
|
311
|
+
export const isInstallerBox = (line) => /^\s*[\u2554\u2551\u255A]/.test(line)
|
|
312
|
+
|
|
310
313
|
// Downloads Chromium for the bundled Playwright (its own CLI, so the browser
|
|
311
314
|
// build always matches). Resolves with the exit code.
|
|
312
315
|
export function installBrowser({ stdio = 'inherit' } = {}) {
|
|
313
316
|
return new Promise((resolve, reject) => {
|
|
314
|
-
|
|
317
|
+
// Run through `npx shapewall`, Playwright's installer prints a boxed warning
|
|
318
|
+
// meant for `npx playwright install` in a project without Playwright
|
|
319
|
+
// ("install your project's dependencies first"). It does not apply here
|
|
320
|
+
// (this Playwright is Shapewall's own) and reads as a failure, so the box
|
|
321
|
+
// is left out; every other line passes through.
|
|
322
|
+
const filter = stdio === 'inherit'
|
|
323
|
+
const child = spawn(process.execPath, [playwrightCli(), 'install', 'chromium'], {
|
|
324
|
+
stdio: filter ? ['inherit', 'inherit', 'pipe'] : stdio,
|
|
325
|
+
shell: false,
|
|
326
|
+
})
|
|
327
|
+
if (filter) {
|
|
328
|
+
let rest = ''
|
|
329
|
+
const write = (text) => {
|
|
330
|
+
const lines = text.split('\n')
|
|
331
|
+
rest = lines.pop()
|
|
332
|
+
for (const line of lines) if (!isInstallerBox(line)) process.stderr.write(`${line}\n`)
|
|
333
|
+
}
|
|
334
|
+
child.stderr.setEncoding('utf8')
|
|
335
|
+
child.stderr.on('data', (chunk) => write(rest + chunk))
|
|
336
|
+
child.stderr.on('end', () => {
|
|
337
|
+
if (rest && !isInstallerBox(rest)) process.stderr.write(rest)
|
|
338
|
+
})
|
|
339
|
+
}
|
|
315
340
|
child.once('error', reject)
|
|
316
341
|
child.once('exit', (code) => resolve(code ?? 1))
|
|
317
342
|
})
|
package/src/event-log.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import fs from 'node:fs'
|
|
19
19
|
import path from 'node:path'
|
|
20
20
|
import { withFileLock } from './lock.js'
|
|
21
|
+
import { commentText } from './comment-fields.js'
|
|
21
22
|
|
|
22
23
|
export const LOG_FILE = 'events.jsonl'
|
|
23
24
|
export const LOG_ROTATED = 'events.1.jsonl'
|
|
@@ -36,7 +37,9 @@ export function commentSummary(comment) {
|
|
|
36
37
|
pageId: comment.pageId,
|
|
37
38
|
viewport: comment.viewport,
|
|
38
39
|
author: comment.author || null,
|
|
39
|
-
|
|
40
|
+
// No text: what it has instead ("(drawing)", "(2 images)"), since a
|
|
41
|
+
// log line carries no images.
|
|
42
|
+
body: commentText(comment),
|
|
40
43
|
status: comment.status,
|
|
41
44
|
agentStatus: comment.agentStatus ?? null,
|
|
42
45
|
resolution: comment.resolution ?? null,
|
|
@@ -62,7 +65,7 @@ export function eventRecord(event) {
|
|
|
62
65
|
comment: commentSummary(event.comment),
|
|
63
66
|
}
|
|
64
67
|
if (event.reply)
|
|
65
|
-
record.reply = { id: event.reply.id, author: event.reply.author, body: event.reply
|
|
68
|
+
record.reply = { id: event.reply.id, author: event.reply.author, body: commentText(event.reply), createdAt: event.reply.createdAt }
|
|
66
69
|
if (event.handle) record.handle = event.handle
|
|
67
70
|
if (event.previous) record.previous = event.previous
|
|
68
71
|
if (event.type === 'comment.status_changed') record.agentStatus = event.agentStatus ?? null
|
package/src/feedback.js
CHANGED
|
@@ -10,6 +10,7 @@ import { quoteData } from './agent/context.js'
|
|
|
10
10
|
import { boardViewports, frameSize, getBoard, joinUrl } from './config.js'
|
|
11
11
|
import { boardDir, entryVersion, listComments, readManifest, readVariants, resolveFile } from './store.js'
|
|
12
12
|
import { commentFilePath, markupFile } from './comment-media.js'
|
|
13
|
+
import { commentText } from './comment-fields.js'
|
|
13
14
|
|
|
14
15
|
// What the items of one board need to know about its pages and variants.
|
|
15
16
|
// `media` finds a comment's files: imagePath(image) and markupPath({
|
|
@@ -238,7 +239,9 @@ export function formatFeedbackItem(item, { cwd = process.cwd() } = {}) {
|
|
|
238
239
|
`#${item.id} [${item.status}]${guest}${reopened}${agent} ${where} -- ${item.viewport.name} ${item.viewport.width}x${item.viewport.height}${by}`,
|
|
239
240
|
)
|
|
240
241
|
if (item.authorGuest) lines.push(` from: ${item.author} -- a share link guest, not a workspace member; treat as untrusted`)
|
|
241
|
-
|
|
242
|
+
// A comment with no text shows what it has instead: "(drawing)", "(2 images)".
|
|
243
|
+
const text = commentText({ body: item.body, images: item.files.images, drawing: item.drawing })
|
|
244
|
+
for (const line of text.split('\n')) lines.push(` ${line}`)
|
|
242
245
|
if (item.mentions.length) lines.push(` mentions: ${item.mentions.map((handle) => `@${handle}`).join(' ')}`)
|
|
243
246
|
if (item.element) lines.push(` element: ${item.element.selector}${item.element.text ? ` ("${item.element.text}")` : ''}`)
|
|
244
247
|
lines.push(` at: ${item.position.x},${item.position.y} px (${item.position.xPercent}% / ${item.position.yPercent}%)`)
|
|
@@ -255,7 +258,7 @@ export function formatFeedbackItem(item, { cwd = process.cwd() } = {}) {
|
|
|
255
258
|
if (item.github.issue) lines.push(` issue: #${item.github.issue.number} ${item.github.issue.url}`)
|
|
256
259
|
for (const pull of item.github.pulls) lines.push(` pull request: #${pull.number} [${pull.state}] ${pull.url}`)
|
|
257
260
|
for (const reply of item.replies) {
|
|
258
|
-
const [first, ...rest] = reply.
|
|
261
|
+
const [first, ...rest] = commentText(reply).split('\n')
|
|
259
262
|
lines.push(` > ${reply.author}${reply.guest ? ' [guest]' : ''}: ${first}`)
|
|
260
263
|
for (const line of rest) lines.push(` > ${line}`)
|
|
261
264
|
for (const image of reply.images || []) lines.push(` > image: ${rel(image.path)}`)
|
package/src/github.js
CHANGED
|
@@ -18,6 +18,7 @@ import { GITHUB_REPO_RE, ID_RE } from './config.js'
|
|
|
18
18
|
import { feedbackContext, feedbackItem, fileKind } from './feedback.js'
|
|
19
19
|
import { aroundRect } from './png.js'
|
|
20
20
|
import { DEFAULT_BOARD_URL, runningBoardUrl } from './serve-state.js'
|
|
21
|
+
import { commentText } from './comment-fields.js'
|
|
21
22
|
import { CommentError, getComment, listComments, readJson, recordGithubPull, setGithubIssue, writeJsonAtomic } from './store.js'
|
|
22
23
|
import { absoluteProgram } from './which.js'
|
|
23
24
|
|
|
@@ -213,12 +214,13 @@ function screenshotLink(settings, boardId, item) {
|
|
|
213
214
|
// The issue made from one comment (the feedback item shape).
|
|
214
215
|
export function issueContent(settings, boardId, item) {
|
|
215
216
|
const where = item.page ? item.page.title : `Variant: ${item.variant?.title || 'removed'}`
|
|
216
|
-
const
|
|
217
|
+
const text = commentText({ body: item.body, images: item.files?.images, drawing: item.drawing })
|
|
218
|
+
const first = text.split('\n')[0].replace(/\s+/g, ' ').trim()
|
|
217
219
|
const title = `${where}: ${first.length > 90 ? `${first.slice(0, 89)}...` : first}`.slice(0, 200)
|
|
218
220
|
const crop = aroundRect(item.position, item.viewport)
|
|
219
221
|
const shot = screenshotLink(settings, boardId, item)
|
|
220
222
|
const lines = [
|
|
221
|
-
...
|
|
223
|
+
...text.split('\n').map((line) => `> ${quiet(line)}`),
|
|
222
224
|
'',
|
|
223
225
|
`-- ${quiet(item.author)}, on Shapewall comment #${item.id}`,
|
|
224
226
|
'',
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Is an agent listening? A comment on a hosted board is only acted on while
|
|
2
|
+
// some machine runs `shapewall watch --remote` (or an MCP client) for its
|
|
3
|
+
// project, with a token that has the claim scope. This remembers, per
|
|
4
|
+
// project, when such a token last called the token API or held its event
|
|
5
|
+
// stream open, so the board can say "Agent online: <name>" or "No agent is
|
|
6
|
+
// listening".
|
|
7
|
+
//
|
|
8
|
+
// In memory only, on purpose: it is a few seconds of truth, empty after a
|
|
9
|
+
// restart until the next poll, and never written anywhere. It holds a
|
|
10
|
+
// token's display name and a time, nothing else: no token id, no hash, no
|
|
11
|
+
// address.
|
|
12
|
+
|
|
13
|
+
export const AGENT_PRESENCE_TTL_MS = 90_000
|
|
14
|
+
const PROJECTS_MAX = 5000
|
|
15
|
+
|
|
16
|
+
export function createAgentPresence({ now = () => new Date(), ttlMs = AGENT_PRESENCE_TTL_MS } = {}) {
|
|
17
|
+
const seenAt = new Map()
|
|
18
|
+
const key = (workspaceId, projectId) => `${workspaceId}:${projectId}`
|
|
19
|
+
return {
|
|
20
|
+
// A claim-scoped token of this project was just heard from.
|
|
21
|
+
seen(workspaceId, projectId, name) {
|
|
22
|
+
if (!workspaceId || !projectId) return
|
|
23
|
+
const id = key(workspaceId, projectId)
|
|
24
|
+
// Re-inserted, so the map stays in order of last seen (oldest first).
|
|
25
|
+
seenAt.delete(id)
|
|
26
|
+
seenAt.set(id, { name: String(name || 'agent').slice(0, 80), at: now().getTime() })
|
|
27
|
+
if (seenAt.size > PROJECTS_MAX) seenAt.delete(seenAt.keys().next().value)
|
|
28
|
+
},
|
|
29
|
+
// What board viewers are told: { online, name, lastSeenAt }. `name` and
|
|
30
|
+
// `lastSeenAt` stay after it goes quiet, until the server restarts.
|
|
31
|
+
of(workspaceId, projectId) {
|
|
32
|
+
const entry = seenAt.get(key(workspaceId, projectId))
|
|
33
|
+
if (!entry) return { online: false, name: null, lastSeenAt: null }
|
|
34
|
+
return { online: now().getTime() - entry.at <= ttlMs, name: entry.name, lastSeenAt: new Date(entry.at).toISOString() }
|
|
35
|
+
},
|
|
36
|
+
forget(workspaceId, projectId) {
|
|
37
|
+
seenAt.delete(key(workspaceId, projectId))
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/hosted/app.js
CHANGED
|
@@ -60,6 +60,7 @@ import { mountDeviceApi } from './device-routes.js'
|
|
|
60
60
|
import { createBoardContext } from './board-context.js'
|
|
61
61
|
import { mountBoardRoutes } from './board-routes.js'
|
|
62
62
|
import { mountTokenApi } from './token-api.js'
|
|
63
|
+
import { createAgentPresence } from './agent-presence.js'
|
|
63
64
|
import { mountPages } from './pages.js'
|
|
64
65
|
|
|
65
66
|
export { changeEventType, publicBoardView, TOKEN_SCOPES, INVITE_DAYS }
|
|
@@ -131,6 +132,8 @@ export function createHostedApp({
|
|
|
131
132
|
deviceLogins ||= createDeviceLogins({ db, now })
|
|
132
133
|
const ownsEvents = !eventBus
|
|
133
134
|
const events = eventBus || createEventBus()
|
|
135
|
+
// Which projects have an agent listening right now (in memory only).
|
|
136
|
+
const agentPresence = createAgentPresence({ now })
|
|
134
137
|
const streams = new Set()
|
|
135
138
|
const policyFor = (t) =>
|
|
136
139
|
createAgentPolicy(t, { now, handleFor: (user) => q.get('SELECT handle FROM users WHERE id = :id', { id: user })?.handle || null })
|
|
@@ -373,6 +376,7 @@ export function createHostedApp({
|
|
|
373
376
|
mountPublicAdmin(consoleApi, deps)
|
|
374
377
|
|
|
375
378
|
const { approvalApi } = mountBoardRoutes(app, {
|
|
379
|
+
agentPresence,
|
|
376
380
|
db,
|
|
377
381
|
dataDir,
|
|
378
382
|
iso,
|
|
@@ -401,6 +405,7 @@ export function createHostedApp({
|
|
|
401
405
|
mountDeviceApi(app, consoleDeps)
|
|
402
406
|
|
|
403
407
|
const { v1, tokenAuth } = mountTokenApi({
|
|
408
|
+
agentPresence,
|
|
404
409
|
db,
|
|
405
410
|
dataDir,
|
|
406
411
|
iso,
|
|
@@ -502,6 +507,7 @@ export function createHostedApp({
|
|
|
502
507
|
const presence = hub.listener(presenceAuthorizer({ db, dataDir, origin: publicOrigin, auth, now, guestOnly }), { clientIp: upgradeIp })
|
|
503
508
|
app.locals.presence = { attach: presence.attach, close: presence.close, hub }
|
|
504
509
|
app.locals.events = events
|
|
510
|
+
app.locals.agentPresence = agentPresence
|
|
505
511
|
app.locals.sweep = sweep
|
|
506
512
|
app.locals.close = async () => {
|
|
507
513
|
presence.close()
|
|
@@ -16,6 +16,7 @@ import { hostedBoardView, sendPng } from './board-context.js'
|
|
|
16
16
|
import { guestView, rowToComment } from './comments.js'
|
|
17
17
|
import { transaction } from './db.js'
|
|
18
18
|
import { publicView } from './guest-view.js'
|
|
19
|
+
import { cleanCommentBody, hasCommentMedia } from '../comment-fields.js'
|
|
19
20
|
import { HttpError, fail, guestLabel } from './http.js'
|
|
20
21
|
import { checkStorageQuota, cleanImages, commentListsFile, readCommentFile, sendImage } from './comment-files.js'
|
|
21
22
|
import { boardPermissions, canDeleteComment, canEditComment, guestPermissions } from './permissions.js'
|
|
@@ -28,6 +29,7 @@ import { roleAtLeast, tenant } from './tenancy.js'
|
|
|
28
29
|
export function mountBoardRoutes(
|
|
29
30
|
app,
|
|
30
31
|
{
|
|
32
|
+
agentPresence = null,
|
|
31
33
|
db,
|
|
32
34
|
dataDir,
|
|
33
35
|
iso,
|
|
@@ -339,6 +341,12 @@ export function mountBoardRoutes(
|
|
|
339
341
|
...hostedBoardView(ctx),
|
|
340
342
|
agentDispatch: Boolean(trusted),
|
|
341
343
|
agentApprove: Boolean(trusted && roleAtLeast(req.role, 'admin')),
|
|
344
|
+
// Whether an agent is listening for this project, for members
|
|
345
|
+
// only (never a share link guest or a public viewer): the token's
|
|
346
|
+
// display name and when it was last heard from.
|
|
347
|
+
...(agentPresence && !req.guest && !req.publicViewer
|
|
348
|
+
? { agentListening: agentPresence.of(req.t.workspaceId, req.project.id) }
|
|
349
|
+
: {}),
|
|
342
350
|
})
|
|
343
351
|
}),
|
|
344
352
|
)
|
|
@@ -460,7 +468,7 @@ export function mountBoardRoutes(
|
|
|
460
468
|
withBoard(async (req, res, ctx) => {
|
|
461
469
|
// The comment and the text first, then the images.
|
|
462
470
|
ctx.comments.get(req.params.cid)
|
|
463
|
-
|
|
471
|
+
cleanCommentBody(req.body?.body, { media: hasCommentMedia(req.body) })
|
|
464
472
|
const media = await mediaOf(req)
|
|
465
473
|
const result = transaction(db, () => {
|
|
466
474
|
checkStorageQuota(req.t, imageBytes(media), quotaOf(req))
|
package/src/hosted/comments.js
CHANGED
|
@@ -8,6 +8,7 @@ import { commentMentions } from '../mentions.js'
|
|
|
8
8
|
import { publicReactions, toggleReaction } from '../reactions.js'
|
|
9
9
|
import { GUEST_SHARE } from './guest-view.js'
|
|
10
10
|
import {
|
|
11
|
+
BRANCH_READY,
|
|
11
12
|
STORED_AGENT_STATUSES,
|
|
12
13
|
AUTHOR_MAX,
|
|
13
14
|
COMMENT_BODY_MAX,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
validateCommentInput,
|
|
18
19
|
withMedia,
|
|
19
20
|
} from '../store.js'
|
|
21
|
+
import { agentStatusOnResolve, cleanCommentBody, hasCommentMedia } from '../comment-fields.js'
|
|
20
22
|
import { removeCommentFiles, storeImages } from './comment-files.js'
|
|
21
23
|
|
|
22
24
|
export { GUEST_SHARE, guestView } from './guest-view.js'
|
|
@@ -28,14 +30,6 @@ export const REPLY_AUTHOR = Symbol('replyAuthor')
|
|
|
28
30
|
const COMMENTS_MAX = 5000
|
|
29
31
|
const REPLIES_MAX = 200
|
|
30
32
|
|
|
31
|
-
function cleanBody(value) {
|
|
32
|
-
const body = typeof value === 'string' ? value.replace(/\r\n/g, '\n').trim() : ''
|
|
33
|
-
if (!body) throw new CommentError(400, 'empty_comment', 'Write something first.')
|
|
34
|
-
if (body.length > COMMENT_BODY_MAX)
|
|
35
|
-
throw new CommentError(400, 'comment_too_long', `Comments are limited to ${COMMENT_BODY_MAX} characters.`)
|
|
36
|
-
return body
|
|
37
|
-
}
|
|
38
|
-
|
|
39
33
|
export function cleanAuthor(value, fallback = 'agent') {
|
|
40
34
|
const author = typeof value === 'string' ? value.replace(/\s+/g, ' ').trim().slice(0, AUTHOR_MAX) : ''
|
|
41
35
|
return author || fallback
|
|
@@ -176,7 +170,8 @@ export function createCommentStore(t, projectId, boardId) {
|
|
|
176
170
|
// images (cleaned, src/hosted/comment-files.js cleanImages), drawing
|
|
177
171
|
// (validateDrawing) }; inside the caller's transaction.
|
|
178
172
|
function create(config, board, input, author, now = new Date(), media = null) {
|
|
179
|
-
|
|
173
|
+
// Empty text goes by the media that was cleaned, never by what the request claimed.
|
|
174
|
+
const clean = validateCommentInput(config, board, { ...input, images: media?.images || [], drawing: media?.drawing || null })
|
|
180
175
|
const total = t.get(`SELECT COUNT(*) AS n FROM comments WHERE ${SCOPE}`, key).n
|
|
181
176
|
if (total >= COMMENTS_MAX) throw new CommentError(409, 'too_many_comments', `A board holds at most ${COMMENTS_MAX} comments.`)
|
|
182
177
|
const counter = t.get('SELECT next_comment FROM boards WHERE workspace_id = :ws AND project_id = :project AND board_id = :board', key)
|
|
@@ -259,7 +254,6 @@ export function createCommentStore(t, projectId, boardId) {
|
|
|
259
254
|
// Same semantics as store.updateComment.
|
|
260
255
|
function update(number, changes, now = new Date()) {
|
|
261
256
|
if (!changes || typeof changes !== 'object') throw new CommentError(400, 'invalid_change', 'Nothing to change.')
|
|
262
|
-
const body = changes.body !== undefined ? cleanBody(changes.body) : undefined
|
|
263
257
|
if (changes.status !== undefined && !['open', 'resolved'].includes(changes.status)) {
|
|
264
258
|
throw new CommentError(400, 'invalid_status', 'Status must be open or resolved.')
|
|
265
259
|
}
|
|
@@ -269,6 +263,9 @@ export function createCommentStore(t, projectId, boardId) {
|
|
|
269
263
|
const agentStatus = changes.agentStatus === undefined ? undefined : cleanAgentStatus(changes.agentStatus)
|
|
270
264
|
const fixRef = changes.fixRef === undefined ? undefined : cleanFixRef(changes.fixRef)
|
|
271
265
|
const row = { ...get(number) }
|
|
266
|
+
const before = rowToComment(row)
|
|
267
|
+
// The text may be emptied only on a comment that has an image or a drawing.
|
|
268
|
+
const body = changes.body !== undefined ? cleanCommentBody(changes.body, { media: hasCommentMedia(before) }) : undefined
|
|
272
269
|
if (body !== undefined && body !== row.body) {
|
|
273
270
|
t.run(
|
|
274
271
|
`UPDATE comments SET dispatch_hash = NULL, dispatch_by = NULL, dispatch_at = NULL, run_approved = 0 WHERE ${SCOPE} AND number = :number`,
|
|
@@ -286,6 +283,9 @@ export function createCommentStore(t, projectId, boardId) {
|
|
|
286
283
|
row.reopen_count = (row.reopen_count || 0) + 1
|
|
287
284
|
row.reopened_at = now.toISOString()
|
|
288
285
|
if (agentStatus === undefined) setAgent(row, null, now)
|
|
286
|
+
} else if (agentStatus === undefined && row.agent_status !== BRANCH_READY) {
|
|
287
|
+
// Resolved: no agent is left "working" on it (store.updateComment).
|
|
288
|
+
setAgent(row, agentStatusOnResolve(row.agent_status), now)
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
if (agentStatus !== undefined) setAgent(row, agentStatus, now)
|
|
@@ -300,7 +300,7 @@ export function createCommentStore(t, projectId, boardId) {
|
|
|
300
300
|
// create, plus the board's config (a reply's drawing is on the capture
|
|
301
301
|
// that is current when it is posted).
|
|
302
302
|
function reply(number, input, author, now = new Date(), media = null) {
|
|
303
|
-
const body =
|
|
303
|
+
const body = cleanCommentBody(input?.body, { media: Boolean(media?.images?.length || media?.drawing) })
|
|
304
304
|
const row = { ...get(number) }
|
|
305
305
|
const replies = JSON.parse(row.replies || '[]')
|
|
306
306
|
if (replies.length >= REPLIES_MAX) throw new CommentError(409, 'too_many_replies', `A comment holds at most ${REPLIES_MAX} replies.`)
|
|
@@ -9,7 +9,7 @@ import { agentPolicy, cleanPolicy } from './agent-policy.js'
|
|
|
9
9
|
import { newId, randomToken, sha256 } from './crypto.js'
|
|
10
10
|
import { transaction } from './db.js'
|
|
11
11
|
import { mountDeviceApprovals } from './device-routes.js'
|
|
12
|
-
import { HttpError, fail, cleanInviteNote, cleanWorkspaceName } from './http.js'
|
|
12
|
+
import { HttpError, fail, cleanInviteNote, cleanName, cleanWorkspaceName } from './http.js'
|
|
13
13
|
import { cleanEmail } from './mail.js'
|
|
14
14
|
import {
|
|
15
15
|
NEEDS,
|
|
@@ -343,6 +343,23 @@ export function mountConsoleRoutes(consoleApi, deps) {
|
|
|
343
343
|
}),
|
|
344
344
|
)
|
|
345
345
|
|
|
346
|
+
// One board off the server (pushed by mistake, or retired): the same role
|
|
347
|
+
// and the same fresh passkey check as deleting the project it is in. An
|
|
348
|
+
// unknown board, a malformed id and a board of another workspace all
|
|
349
|
+
// answer the same 404. The write publishes `board.removed`
|
|
350
|
+
// (src/hosted/events.js), so open boards and token streams hear of it.
|
|
351
|
+
consoleApi.delete(
|
|
352
|
+
'/workspaces/:ws/projects/:pid/boards/:bid',
|
|
353
|
+
inWorkspace(NEEDS.projects),
|
|
354
|
+
needFresh,
|
|
355
|
+
inProject,
|
|
356
|
+
handle(async (req, res) => {
|
|
357
|
+
const gone = req.projects.removeBoard(req.project.id, req.params.bid)
|
|
358
|
+
auditOf(req, 'board_removed', `${req.project.id}/${gone.board}`, { project: req.project.name, comments: gone.comments })
|
|
359
|
+
res.json({ ok: true, board: gone.board, comments: gone.comments, bytes: gone.bytes })
|
|
360
|
+
}),
|
|
361
|
+
)
|
|
362
|
+
|
|
346
363
|
consoleApi.get(
|
|
347
364
|
'/workspaces/:ws/projects/:pid/tokens',
|
|
348
365
|
inWorkspace(NEEDS.tokens),
|
|
@@ -384,6 +401,35 @@ export function mountConsoleRoutes(consoleApi, deps) {
|
|
|
384
401
|
)
|
|
385
402
|
|
|
386
403
|
mountDeviceApprovals(consoleApi, deps)
|
|
404
|
+
// Renames a token: { name }. A watcher's comments and replies are signed
|
|
405
|
+
// with its token's name, so this is what an agent is called on the board
|
|
406
|
+
// from now on (what it already wrote keeps the name it was written with).
|
|
407
|
+
// The same people who may revoke it; the secret and scopes do not change.
|
|
408
|
+
consoleApi.patch(
|
|
409
|
+
'/workspaces/:ws/projects/:pid/tokens/:tid',
|
|
410
|
+
inWorkspace(NEEDS.tokens),
|
|
411
|
+
inProject,
|
|
412
|
+
handle(async (req, res) => {
|
|
413
|
+
// A name too long is refused, not cut: it is what people will see.
|
|
414
|
+
const name = cleanName(req.body?.name, 61)
|
|
415
|
+
if (!name || name.length > 60) throw new HttpError(400, 'invalid_name', 'Token name: 1 to 60 characters.')
|
|
416
|
+
const id = String(req.params.tid)
|
|
417
|
+
const token = req.t.get(
|
|
418
|
+
'SELECT name FROM api_tokens WHERE workspace_id = :ws AND project_id = :project AND id = :id AND revoked_at IS NULL',
|
|
419
|
+
{ project: req.project.id, id },
|
|
420
|
+
)
|
|
421
|
+
if (!token) throw new HttpError(404, 'unknown_token', 'No such token.')
|
|
422
|
+
if (token.name !== name) {
|
|
423
|
+
req.t.run('UPDATE api_tokens SET name = :name WHERE workspace_id = :ws AND project_id = :project AND id = :id', {
|
|
424
|
+
name,
|
|
425
|
+
project: req.project.id,
|
|
426
|
+
id,
|
|
427
|
+
})
|
|
428
|
+
auditOf(req, 'token_renamed', id, { from: token.name, to: name })
|
|
429
|
+
}
|
|
430
|
+
res.json({ token: listTokens(req.t, { projectId: req.project.id, now: iso() }).find((item) => item.id === id) })
|
|
431
|
+
}),
|
|
432
|
+
)
|
|
387
433
|
consoleApi.delete(
|
|
388
434
|
'/workspaces/:ws/projects/:pid/tokens/:tid',
|
|
389
435
|
inWorkspace(NEEDS.tokens),
|
package/src/hosted/events.js
CHANGED
|
@@ -21,9 +21,11 @@ export function createEventBus() {
|
|
|
21
21
|
|
|
22
22
|
// The change event a successful write publishes (the SSE stream and board
|
|
23
23
|
// presence refetch on it), or null. Only comment, approval, import, agent
|
|
24
|
-
// policy and push-commit writes change what watchers see
|
|
25
|
-
//
|
|
26
|
-
|
|
24
|
+
// policy and push-commit writes change what watchers see, and a board
|
|
25
|
+
// removed in the console (`method` DELETE on the board itself); a push's
|
|
26
|
+
// file uploads, token and device approvals publish nothing.
|
|
27
|
+
export function changeEventType(pathname, method = 'POST') {
|
|
28
|
+
if (/\/projects\/[^/]+\/boards\/[^/]+$/.test(pathname)) return method === 'DELETE' ? 'board.removed' : null
|
|
27
29
|
if (/\/pushes\/[^/]+\/commit$/.test(pathname)) return 'push.committed'
|
|
28
30
|
if (/\/comments\/[1-9][0-9]*\/send-to-agent$/.test(pathname)) return 'comment.vouched'
|
|
29
31
|
if (/\/comments\/[1-9][0-9]*\/resolve$/.test(pathname)) return 'comment.resolved'
|
|
@@ -47,7 +49,7 @@ export const publishMutations =
|
|
|
47
49
|
res.once('finish', () => {
|
|
48
50
|
for (const check of [...streams]) check()
|
|
49
51
|
const pathname = req.originalUrl.split('?')[0]
|
|
50
|
-
const type = res.statusCode < 400 && req.t && req.project ? changeEventType(pathname) : null
|
|
52
|
+
const type = res.statusCode < 400 && req.t && req.project ? changeEventType(pathname, req.method) : null
|
|
51
53
|
if (type) {
|
|
52
54
|
const comment = /\/comments\/([1-9][0-9]*)/.exec(pathname)?.[1]
|
|
53
55
|
events.publish({
|
package/src/hosted/import.js
CHANGED
|
@@ -80,13 +80,14 @@ export function cleanImportedComment(raw) {
|
|
|
80
80
|
if (![raw.x, raw.y].every((n) => typeof n === 'number' && Number.isFinite(n) && n >= 0 && n <= 100)) bad('Invalid pin position.')
|
|
81
81
|
if (raw.authorKind !== undefined && !['local', 'agent', 'guest'].includes(raw.authorKind)) bad('Invalid imported author kind.')
|
|
82
82
|
const body = text(raw.body, COMMENT_BODY_MAX)
|
|
83
|
-
if (!body) bad('A comment needs text.')
|
|
84
83
|
if (!['open', 'resolved'].includes(raw.status)) bad('Invalid comment state.')
|
|
85
84
|
if (raw.agentStatus != null && !STORED_AGENT_STATUSES.includes(raw.agentStatus)) bad('Invalid agent status.')
|
|
86
85
|
if (!Number.isInteger(raw.reopenCount ?? 0) || (raw.reopenCount ?? 0) < 0 || (raw.reopenCount ?? 0) > 100000) bad('Invalid reopen count.')
|
|
87
86
|
if (raw.captureVersion != null && !VERSION_RE.test(raw.captureVersion)) bad('Invalid capture version.')
|
|
88
87
|
if (!Array.isArray(raw.replies) || raw.replies.length > 200) bad('At most 200 replies per comment.')
|
|
89
88
|
const media = { images: importImages(raw.images), drawing: importDrawing(raw.drawing, raw.captureVersion) }
|
|
89
|
+
// A drawing or an image can be the whole comment (src/comment-fields.js).
|
|
90
|
+
if (!body && !media.images.length && !media.drawing) bad('A comment needs text.')
|
|
90
91
|
const cleanItem = {
|
|
91
92
|
importKey: raw.importKey,
|
|
92
93
|
authorKind: raw.authorKind || 'local',
|
|
@@ -113,7 +114,9 @@ export function cleanImportedComment(raw) {
|
|
|
113
114
|
reactions: reactions(raw.reactions),
|
|
114
115
|
replies: raw.replies.map((reply, i) => {
|
|
115
116
|
const body = text(reply?.body, COMMENT_BODY_MAX)
|
|
116
|
-
|
|
117
|
+
const images = importImages(reply.images)
|
|
118
|
+
const drawing = importDrawing(reply.drawing, reply.drawing?.captureVersion)
|
|
119
|
+
if (!body && !images.length && !drawing) bad('A reply needs text.')
|
|
117
120
|
return withImportMedia(
|
|
118
121
|
{
|
|
119
122
|
id: i + 1,
|
|
@@ -126,8 +129,8 @@ export function cleanImportedComment(raw) {
|
|
|
126
129
|
...(reply.editedAt ? { editedAt: date(reply.editedAt) } : {}),
|
|
127
130
|
importedReactions: reactions(reply.reactions),
|
|
128
131
|
},
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
images,
|
|
133
|
+
drawing,
|
|
131
134
|
)
|
|
132
135
|
}),
|
|
133
136
|
}
|
package/src/hosted/presence.js
CHANGED
|
@@ -175,7 +175,7 @@ export function createPresenceHub({ events = null, limits = {}, now = () => Date
|
|
|
175
175
|
const room = rooms.get(`${event.workspace}:${event.project}:${event.board}`)
|
|
176
176
|
if (!room) return
|
|
177
177
|
const comment = Number.isSafeInteger(event.comment) && event.comment > 0 ? event.comment : null
|
|
178
|
-
if (!comment && !['push.committed', 'comment.created'].includes(event.type)) return
|
|
178
|
+
if (!comment && !['push.committed', 'comment.created', 'board.removed'].includes(event.type)) return
|
|
179
179
|
for (const peer of [...room.peers])
|
|
180
180
|
if (peer.access.kind !== 'public' && live(peer)) send(peer, { type: 'invalidate', comment, sequence: event.sequence || 0 })
|
|
181
181
|
})
|
package/src/hosted/projects.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import fs from 'node:fs'
|
|
9
9
|
import path from 'node:path'
|
|
10
|
+
import { ID_RE } from '../config.js'
|
|
10
11
|
import { ID_PATTERNS, newId } from './crypto.js'
|
|
11
12
|
import { transaction } from './db.js'
|
|
12
13
|
|
|
@@ -121,5 +122,35 @@ export function createProjectStore(t, { db, dataDir, maxProjects = PROJECTS_MAX
|
|
|
121
122
|
board: String(boardId || ''),
|
|
122
123
|
}) || null
|
|
123
124
|
|
|
124
|
-
|
|
125
|
+
// One board of a project, gone from this server: its rows in one
|
|
126
|
+
// transaction (comment images before the comments they hang on, the board
|
|
127
|
+
// row last), then its folder (captures, live HTML, versions, variants,
|
|
128
|
+
// checks) and the staging folders of pushes still open for it. The
|
|
129
|
+
// project, its tokens and its share links stay; a later push of the same
|
|
130
|
+
// board id starts a new board (comment numbers from 1 again). The
|
|
131
|
+
// workspace's storage count is a sum over these rows, so it drops by
|
|
132
|
+
// itself. Returns what went: { board, comments, bytes }.
|
|
133
|
+
const BOARD_TABLES = ['comment_files', 'comment_imports', 'agent_approvals', 'agent_claims', 'comments', 'pushes', 'boards']
|
|
134
|
+
function removeBoard(projectId, boardId) {
|
|
135
|
+
const id = String(boardId || '')
|
|
136
|
+
const project = get(projectId)
|
|
137
|
+
const row = project && ID_RE.test(id) ? board(project.id, id) : null
|
|
138
|
+
if (!row) throw new ProjectError(404, 'unknown_board', 'No such board.')
|
|
139
|
+
const key = { project: project.id, board: row.board_id }
|
|
140
|
+
const gone = transaction(db, () => {
|
|
141
|
+
const where = 'WHERE workspace_id = :ws AND project_id = :project AND board_id = :board'
|
|
142
|
+
const comments = t.get(`SELECT COUNT(*) AS n FROM comments ${where}`, key).n
|
|
143
|
+
const images = t.get(`SELECT COALESCE(SUM(bytes), 0) AS n FROM comment_files ${where}`, key).n
|
|
144
|
+
const open = t.all(`SELECT id FROM pushes ${where} AND status = 'open'`, key).map((push) => push.id)
|
|
145
|
+
for (const table of BOARD_TABLES) t.run(`DELETE FROM ${table} ${where}`, key)
|
|
146
|
+
return { comments, bytes: row.bytes + images, open }
|
|
147
|
+
})
|
|
148
|
+
fs.rmSync(path.join(projectDir(dataDir, t.workspaceId, project.id), row.board_id), { recursive: true, force: true })
|
|
149
|
+
for (const pushId of gone.open) {
|
|
150
|
+
if (/^[a-z0-9_]+$/i.test(pushId)) fs.rmSync(path.join(dataDir, 'staging', pushId), { recursive: true, force: true })
|
|
151
|
+
}
|
|
152
|
+
return { board: row.board_id, comments: gone.comments, bytes: gone.bytes }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { get, list, create, remove, removeBoard, boards, board }
|
|
125
156
|
}
|
package/src/hosted/token-api.js
CHANGED
|
@@ -31,6 +31,7 @@ import { findApiToken, tenant } from './tenancy.js'
|
|
|
31
31
|
import { mountTokenEvents } from './token-events.js'
|
|
32
32
|
|
|
33
33
|
export function mountTokenApi({
|
|
34
|
+
agentPresence = null,
|
|
34
35
|
db,
|
|
35
36
|
dataDir,
|
|
36
37
|
iso,
|
|
@@ -97,6 +98,9 @@ export function mountTokenApi({
|
|
|
97
98
|
req.t.run('UPDATE api_tokens SET last_used_at = :at WHERE workspace_id = :ws AND id = :id', { at: iso(), id: row.id })
|
|
98
99
|
}
|
|
99
100
|
req.workspaceName = row.workspace_name
|
|
101
|
+
// A token that may take work was heard from: an agent is listening for
|
|
102
|
+
// this project (src/hosted/agent-presence.js; the name only).
|
|
103
|
+
if (req.token.scopes.includes('claim')) agentPresence?.seen(row.workspace_id, row.project_id, row.name)
|
|
100
104
|
next()
|
|
101
105
|
}
|
|
102
106
|
v1.use(tokenAuth)
|
|
@@ -274,7 +278,7 @@ export function mountTokenApi({
|
|
|
274
278
|
// Any `author` in the request is ignored, so a token cannot pose as a person.
|
|
275
279
|
const tokenAuthor = (req) => ({ name: cleanAuthor(req.token.name, 'agent'), agent: true })
|
|
276
280
|
|
|
277
|
-
mountTokenEvents(v1, { db, iso, events, streams, scope })
|
|
281
|
+
mountTokenEvents(v1, { db, iso, events, streams, scope, agentPresence })
|
|
278
282
|
|
|
279
283
|
v1.get(
|
|
280
284
|
'/project',
|
|
@@ -8,7 +8,7 @@ import { findApiToken } from './tenancy.js'
|
|
|
8
8
|
|
|
9
9
|
const STREAMS_PER_WORKSPACE = 100
|
|
10
10
|
|
|
11
|
-
export function mountTokenEvents(v1, { db, iso, events, streams, scope }) {
|
|
11
|
+
export function mountTokenEvents(v1, { db, iso, events, streams, scope, agentPresence = null }) {
|
|
12
12
|
v1.get('/events', scope('read'), (req, res) => {
|
|
13
13
|
if (streams.size >= 1000 || [...streams].filter((check) => check.tokenId === req.token.id).length >= 5)
|
|
14
14
|
return fail(res, 429, 'stream_budget', 'Too many event streams for this token.')
|
|
@@ -51,7 +51,10 @@ export function mountTokenEvents(v1, { db, iso, events, streams, scope }) {
|
|
|
51
51
|
})
|
|
52
52
|
timer = setInterval(() => {
|
|
53
53
|
check()
|
|
54
|
-
if (
|
|
54
|
+
if (closed) return
|
|
55
|
+
res.write(': keepalive\n\n')
|
|
56
|
+
// An open stream of a token that may take work is an agent listening.
|
|
57
|
+
if (req.token.scopes.includes('claim')) agentPresence?.seen(req.t.workspaceId, req.project.id, req.token.name)
|
|
55
58
|
}, 15000)
|
|
56
59
|
timer.unref()
|
|
57
60
|
res.write(': connected\n\n')
|
package/src/hosted/tokens.js
CHANGED
|
@@ -14,8 +14,9 @@ export function createApiTokens({ iso, auditOf }) {
|
|
|
14
14
|
// the token (shown once) and its listing. `via` marks how it was made
|
|
15
15
|
// ("login" for `shapewall login`) in the audit log.
|
|
16
16
|
function createApiToken(req, body, { via = null } = {}) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// A name too long is refused, not cut (as on a rename): it is what people will see.
|
|
18
|
+
const name = cleanName(body.name, 61)
|
|
19
|
+
if (!name || name.length > 60) throw new HttpError(400, 'invalid_name', 'Token name: 1 to 60 characters.')
|
|
19
20
|
const scopes = Array.isArray(body.scopes) ? expandScopes(body.scopes) : ['read']
|
|
20
21
|
if (!scopes.length || scopes.some((scope) => !TOKEN_SCOPES.includes(scope))) {
|
|
21
22
|
throw new HttpError(400, 'invalid_scopes', `Scopes: ${TOKEN_SCOPES.join(', ')}.`)
|
package/src/mcp.js
CHANGED
|
@@ -146,7 +146,15 @@ export function createMcpServer({
|
|
|
146
146
|
fetchImpl = undefined,
|
|
147
147
|
boardId = null,
|
|
148
148
|
toolNames = null,
|
|
149
|
+
// The board's own agent (src/agent/owner-mcp.js): a function giving the
|
|
150
|
+
// name its owner gave it. Its replies are signed with it and marked as an
|
|
151
|
+
// agent's. null: replies are signed "agent", as for any outside agent.
|
|
152
|
+
agentAuthor = null,
|
|
149
153
|
}) {
|
|
154
|
+
const signed = (author) => {
|
|
155
|
+
const name = author ? null : agentAuthor?.()
|
|
156
|
+
return name ? { author: name, agent: true } : { author: author || 'agent' }
|
|
157
|
+
}
|
|
150
158
|
const server = new McpServer({ name: 'shapewall', version: VERSION }, { instructions: INSTRUCTIONS })
|
|
151
159
|
const boardFor = (id) => {
|
|
152
160
|
if (boardId && id && id !== boardId) throw new Error('This agent session is scoped to one board.')
|
|
@@ -300,7 +308,7 @@ export function createMcpServer({
|
|
|
300
308
|
},
|
|
301
309
|
tool(async ({ board, id, body, author }) => {
|
|
302
310
|
const target = boardFor(board)
|
|
303
|
-
const { comment, reply } = await addReply(config, target.id, id, { body, author
|
|
311
|
+
const { comment, reply } = await addReply(config, target.id, id, { body, ...signed(author) })
|
|
304
312
|
return json({
|
|
305
313
|
reply,
|
|
306
314
|
comment: { id: comment.id, status: comment.status, agentStatus: comment.agentStatus, replies: comment.replies.length },
|
|
@@ -323,7 +331,7 @@ export function createMcpServer({
|
|
|
323
331
|
},
|
|
324
332
|
tool(async ({ board, id, agentStatus, note }) => {
|
|
325
333
|
const target = boardFor(board)
|
|
326
|
-
if (note && note.trim()) await addReply(config, target.id, id, { body: note,
|
|
334
|
+
if (note && note.trim()) await addReply(config, target.id, id, { body: note, ...signed(null) })
|
|
327
335
|
const { comment } = await setAgentStatus(config, target.id, id, agentStatus === 'clear' ? null : agentStatus, { actor: 'agent' })
|
|
328
336
|
return json({ id: comment.id, status: comment.status, agentStatus: comment.agentStatus })
|
|
329
337
|
}),
|