shapewall 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +35 -1
  3. package/dist/agent/package-lock.json +2 -2
  4. package/dist/client/assets/BoardChat-CupOxioV.js +27 -0
  5. package/dist/client/assets/{BuzzDialog-CZdwIQLF.js → BuzzDialog-Ds7Thpfe.js} +1 -1
  6. package/dist/client/assets/ChecksPanel-BqrS02Ih.js +1 -0
  7. package/dist/client/assets/History-CQG3NQOC.js +1 -0
  8. package/dist/client/assets/{LocalSettings-CvlVtNY_.js → LocalSettings-CSNMhNyV.js} +1 -1
  9. package/dist/client/assets/{Management-DOJkFY_o.js → Management-CJVNAqAW.js} +1 -1
  10. package/dist/client/assets/QuickConnect-B-4pUgXH.js +1 -0
  11. package/dist/client/assets/{ShareDialog-CdVAreaw.js → ShareDialog-BouvNraR.js} +2 -2
  12. package/dist/client/assets/{app-update-dialog-Dox9-LWv.js → app-update-dialog-rhaw0MRk.js} +1 -1
  13. package/dist/client/assets/{circle-x-BmT6vHKl.js → circle-x-PRxj7kPi.js} +1 -1
  14. package/dist/client/assets/index-CXtuJi1K.css +2 -0
  15. package/dist/client/assets/index-DKOCIQiq.js +37 -0
  16. package/dist/client/assets/{refresh-cw-ugt3cWKH.js → refresh-cw-aeOBDuGQ.js} +1 -1
  17. package/dist/client/assets/{square-_KG6tM5A.js → shield-check-DuPBJ6H_.js} +1 -1
  18. package/dist/client/assets/ui-Cg4TTrec.js +41 -0
  19. package/dist/client/build-info.json +1 -1
  20. package/dist/client/index.html +3 -3
  21. package/dist/client/sw.js +2 -2
  22. package/dist/console/assets/LocalAccountsApp-DOKZI6Lt.js +1 -0
  23. package/dist/console/assets/LocalConsole-DXzldLW9.js +1 -0
  24. package/dist/console/assets/app-update-dialog-CrqIMEwN.js +1 -0
  25. package/dist/console/assets/console-76WovHlh.js +55 -0
  26. package/dist/console/assets/console-Fp4k9iyx.css +2 -0
  27. package/dist/console/build-info.json +1 -1
  28. package/dist/console/console.html +2 -2
  29. package/docs/agent-hardening.md +19 -0
  30. package/docs/agent-workflow.md +33 -0
  31. package/docs/agents.md +112 -0
  32. package/docs/config.md +41 -0
  33. package/docs/deployment.md +3 -0
  34. package/docs/design-system.md +13 -5
  35. package/docs/hosted.md +10 -0
  36. package/docs/journeys.md +13 -1
  37. package/docs/pull-requests.md +192 -0
  38. package/package.json +2 -1
  39. package/src/agent/backends/acp.js +35 -6
  40. package/src/agent/batch-fixes.js +45 -0
  41. package/src/agent/batch-queue.js +204 -0
  42. package/src/agent/branch-mode.js +753 -0
  43. package/src/agent/config.js +6 -0
  44. package/src/agent/fix-prompt.js +5 -0
  45. package/src/agent/manage.js +1 -1
  46. package/src/agent/routes.js +901 -186
  47. package/src/agent/run.js +8 -1
  48. package/src/agent/settings-events.js +103 -0
  49. package/src/agent/settings-routes.js +92 -2
  50. package/src/agent/starter/worktree.js +254 -25
  51. package/src/agent/threads.js +2 -7
  52. package/src/agent/tools.js +51 -0
  53. package/src/agent/user-settings.js +33 -2
  54. package/src/ci/capture.js +103 -0
  55. package/src/ci/compare.js +267 -0
  56. package/src/ci/github.js +307 -0
  57. package/src/ci/images.js +76 -0
  58. package/src/ci/settings.js +211 -0
  59. package/src/ci/start.js +148 -0
  60. package/src/ci/summary.js +262 -0
  61. package/src/ci/workflow.js +238 -0
  62. package/src/cli/args.js +24 -1
  63. package/src/cli/ci.js +229 -0
  64. package/src/cli/help.js +23 -1
  65. package/src/cli/init.js +33 -1
  66. package/src/cli.js +6 -2
  67. package/src/comment-drawing.js +161 -0
  68. package/src/comment-fields.js +51 -0
  69. package/src/comment-media.js +528 -0
  70. package/src/config.js +7 -0
  71. package/src/doctor.js +23 -0
  72. package/src/export.js +8 -0
  73. package/src/feedback.js +89 -12
  74. package/src/github.js +3 -3
  75. package/src/hosted/admin.js +36 -4
  76. package/src/hosted/app.js +5 -0
  77. package/src/hosted/board-routes.js +63 -7
  78. package/src/hosted/clean-worker.js +22 -4
  79. package/src/hosted/cleaner.js +4 -1
  80. package/src/hosted/comment-files.js +200 -0
  81. package/src/hosted/comments.js +68 -15
  82. package/src/hosted/db.js +32 -0
  83. package/src/hosted/guest-view.js +9 -0
  84. package/src/hosted/import.js +213 -18
  85. package/src/hosted/operator.js +3 -1
  86. package/src/hosted/projects.js +3 -2
  87. package/src/hosted/push.js +6 -3
  88. package/src/hosted/retention.js +18 -0
  89. package/src/hosted/tenancy.js +1 -0
  90. package/src/hosted/token-api.js +110 -9
  91. package/src/image-sniff.js +11 -0
  92. package/src/mcp.js +48 -3
  93. package/src/remote/remote-mcp.js +2 -2
  94. package/src/remote/remote.js +6 -2
  95. package/src/remote/share.js +77 -7
  96. package/src/server/app.js +18 -1
  97. package/src/store.js +119 -33
  98. package/src/watch.js +4 -0
  99. package/dist/client/assets/BoardChat-C88k4s-W.js +0 -28
  100. package/dist/client/assets/ChecksPanel-B54chcLA.js +0 -1
  101. package/dist/client/assets/History-CVVuuxUK.js +0 -1
  102. package/dist/client/assets/QuickConnect-D40mj4Ry.js +0 -1
  103. package/dist/client/assets/index-CwvFfwU0.js +0 -29
  104. package/dist/client/assets/index-UIYSPHoh.css +0 -2
  105. package/dist/client/assets/ui-BAGBTB_P.js +0 -41
  106. package/dist/console/assets/LocalAccountsApp-4MtW1QlZ.js +0 -1
  107. package/dist/console/assets/LocalConsole-CgKqYa8i.js +0 -1
  108. package/dist/console/assets/app-update-dialog-S2Yyc7Pw.js +0 -1
  109. package/dist/console/assets/console-BPmBRIoz.js +0 -51
  110. package/dist/console/assets/console-DgVrGRMD.css +0 -2
@@ -0,0 +1,200 @@
1
+ // Images on comments of hosted boards: cleaned like pushed files (in the
2
+ // cleaner's worker pool, src/hosted/clean-worker.js), stored as BLOBs in
3
+ // comment_files (src/hosted/db.js migration 11) and served from there.
4
+ //
5
+ // Why the database and not a folder: a push commit replaces the whole board
6
+ // folder (src/hosted/push.js commit), so images there would vanish with the
7
+ // next push. In SQLite they are written in the same transaction as the
8
+ // comment that owns them, go with it when it is deleted (a foreign key with
9
+ // ON DELETE CASCADE, and an explicit delete), are scoped by workspace like
10
+ // every tenant row, and are in every backup (VACUUM INTO) without a second
11
+ // copy step. They are small and capped (4 per comment or reply, 5 MB each,
12
+ // the workspace storage quota over all of them).
13
+
14
+ import { COMMENT_FILE_RE, CommentError, readImages } from '../comment-fields.js'
15
+ import { cleanCommentImage, newImageFile, renderMarkup } from '../comment-media.js'
16
+ import { allWorkspaces, tenant } from './tenancy.js'
17
+
18
+ const SCOPE = 'workspace_id = :ws AND project_id = :project AND board_id = :board'
19
+
20
+ // Staged import images that no batch attached go after this long.
21
+ export const STAGED_IMAGE_MS = 2 * 3_600_000
22
+
23
+ // Cleans parsed image inputs ([{ name, mediaType, buffer }],
24
+ // parseImageInputs) off the event loop. Returns [{ name, mediaType, buffer,
25
+ // width, height }]. Throws CommentError or PushError (statusCode, code).
26
+ export async function cleanImages(cleaner, inputs) {
27
+ return Promise.all(
28
+ inputs.map(async (input) => {
29
+ const clean = cleaner
30
+ ? await cleaner.clean('comment-image', input.buffer, input.mediaType)
31
+ : cleanCommentImage(input.buffer, input.mediaType)
32
+ if (clean.mediaType !== input.mediaType || !Buffer.isBuffer(clean.buffer))
33
+ throw new CommentError(400, 'bad_image', 'That image could not be read.')
34
+ return { name: input.name, mediaType: clean.mediaType, buffer: clean.buffer, width: clean.width, height: clean.height }
35
+ }),
36
+ )
37
+ }
38
+
39
+ // Bytes of every comment image the workspace holds (attached or staged).
40
+ export function commentFileBytes(t) {
41
+ return t.get('SELECT COALESCE(SUM(bytes), 0) AS n FROM comment_files WHERE workspace_id = :ws').n
42
+ }
43
+
44
+ // Everything the storage quota counts: pushed boards, open pushes and
45
+ // comment images. Run inside the transaction that writes `adding` bytes.
46
+ export function checkStorageQuota(t, adding, quotaBytes) {
47
+ if (!adding) return
48
+ const boards = t.get('SELECT COALESCE(SUM(bytes), 0) AS n FROM boards WHERE workspace_id = :ws').n
49
+ const open = t.get("SELECT COALESCE(SUM(bytes), 0) AS n FROM pushes WHERE workspace_id = :ws AND status = 'open'").n
50
+ if (boards + open + commentFileBytes(t) + adding > quotaBytes)
51
+ throw new CommentError(413, 'quota_exceeded', 'This workspace is over its storage quota. Remove images or old boards to make room.')
52
+ }
53
+
54
+ // Writes cleaned images for a comment (replyId null) or a reply; returns
55
+ // their records ({ id, file, name, mediaType, bytes, width, height }). Inside
56
+ // the caller's transaction, after the comment row exists.
57
+ // An import stages an image first (commentNumber null, importSession and
58
+ // importRef set) and attaches it in its batch (src/hosted/import.js).
59
+ export function storeImages(t, { projectId, boardId, commentNumber, replyId = null, images, at, importSession = null, importRef = null }) {
60
+ return images.map((image) => {
61
+ const file = newImageFile(image.mediaType)
62
+ t.run(
63
+ `INSERT INTO comment_files (workspace_id, project_id, board_id, file, comment_number, reply_id, name, media_type, bytes, width,
64
+ height, data, import_session, import_ref, created_at)
65
+ VALUES (:ws, :project, :board, :file, :number, :reply, :name, :type, :bytes, :width, :height, :data, :session, :ref, :at)`,
66
+ {
67
+ project: projectId,
68
+ board: boardId,
69
+ file,
70
+ number: commentNumber,
71
+ reply: replyId,
72
+ session: importSession,
73
+ ref: importRef,
74
+ name: image.name,
75
+ type: image.mediaType,
76
+ bytes: image.buffer.length,
77
+ width: image.width,
78
+ height: image.height,
79
+ data: image.buffer,
80
+ at,
81
+ },
82
+ )
83
+ return {
84
+ id: file.split('.')[0],
85
+ file,
86
+ name: image.name,
87
+ mediaType: image.mediaType,
88
+ bytes: image.buffer.length,
89
+ width: image.width,
90
+ height: image.height,
91
+ }
92
+ })
93
+ }
94
+
95
+ // The stored file `name` of a comment on this board, or null. Only names
96
+ // Shapewall writes, only files attached to a comment (never a staged import).
97
+ export function readCommentFile(t, projectId, boardId, name) {
98
+ if (!COMMENT_FILE_RE.test(String(name || ''))) return null
99
+ return (
100
+ t.get(
101
+ `SELECT file, comment_number, reply_id, media_type, bytes, data FROM comment_files
102
+ WHERE ${SCOPE} AND file = :file AND comment_number IS NOT NULL`,
103
+ { project: projectId, board: boardId, file: name },
104
+ ) || null
105
+ )
106
+ }
107
+
108
+ // Does the comment (as the asker sees it) list this file, on itself or on
109
+ // the reply the row says it belongs to?
110
+ export function commentListsFile(comment, row) {
111
+ if (!comment || Number(comment.id) !== Number(row.comment_number)) return false
112
+ const owner = row.reply_id ? (comment.replies || []).find((reply) => Number(reply.id) === Number(row.reply_id)) : comment
113
+ return readImages(owner?.images).some((image) => image.file === row.file)
114
+ }
115
+
116
+ // Sends an image the way src/comment-media.js sendCommentFile does: its
117
+ // stored type (set when it was cleaned), never sniffed, never a document.
118
+ // Revalidated each time (ETag), so a deleted comment or an ended share link
119
+ // stops showing it.
120
+ export function sendImage(res, data, mediaType) {
121
+ res.setHeader('Cache-Control', 'private, no-cache')
122
+ res.setHeader('Cross-Origin-Resource-Policy', 'same-origin')
123
+ res.setHeader('Content-Security-Policy', "default-src 'none'; sandbox")
124
+ res.setHeader('X-Content-Type-Options', 'nosniff')
125
+ res.setHeader('Content-Disposition', 'inline')
126
+ res.type(mediaType).send(Buffer.from(data.buffer, data.byteOffset, data.byteLength))
127
+ }
128
+
129
+ // Removes the files of a comment (all of them, replyId undefined) inside
130
+ // the caller's transaction. The foreign key would too; explicit, so it never
131
+ // depends on the connection's PRAGMA.
132
+ export function removeCommentFiles(t, projectId, boardId, commentNumber) {
133
+ t.run(`DELETE FROM comment_files WHERE ${SCOPE} AND comment_number = :number`, {
134
+ project: projectId,
135
+ board: boardId,
136
+ number: commentNumber,
137
+ })
138
+ }
139
+
140
+ // Staged import images that no batch attached, older than STAGED_IMAGE_MS,
141
+ // in every workspace (the server's staging sweep).
142
+ export function sweepStagedImages(db, now = new Date()) {
143
+ const cutoff = new Date(now.getTime() - STAGED_IMAGE_MS).toISOString()
144
+ let removed = 0
145
+ for (const workspace of allWorkspaces(db)) {
146
+ const result = tenant(db, workspace.id).run(
147
+ 'DELETE FROM comment_files WHERE workspace_id = :ws AND comment_number IS NULL AND created_at < :cutoff',
148
+ { cutoff },
149
+ )
150
+ removed += Number(result.changes || 0)
151
+ }
152
+ return removed
153
+ }
154
+
155
+ // Rendered markup PNGs, in memory: a drawing never changes once posted and
156
+ // the capture it was drawn on is named by its path, so the same key always
157
+ // renders the same bytes. Bounded by count and bytes.
158
+ export function createMarkupCache({ entries = 64, bytes = 48 * 1024 * 1024 } = {}) {
159
+ const map = new Map()
160
+ let total = 0
161
+ return {
162
+ get(key) {
163
+ const value = map.get(key)
164
+ if (!value) return null
165
+ map.delete(key)
166
+ map.set(key, value)
167
+ return value
168
+ },
169
+ set(key, png) {
170
+ if (png.length > bytes) return
171
+ if (map.has(key)) {
172
+ total -= map.get(key).length
173
+ map.delete(key)
174
+ }
175
+ map.set(key, png)
176
+ total += png.length
177
+ while (map.size > entries || total > bytes) {
178
+ const [oldest, value] = map.entries().next().value
179
+ map.delete(oldest)
180
+ total -= value.length
181
+ }
182
+ },
183
+ clear() {
184
+ map.clear()
185
+ total = 0
186
+ },
187
+ }
188
+ }
189
+
190
+ // Renders a drawing on its screenshot, in the cleaner's pool when there is
191
+ // one. Resolves with the PNG or null.
192
+ export async function renderMarkupPng(cleaner, screenshot, drawing) {
193
+ if (!cleaner) return renderMarkup(screenshot, drawing)?.png || null
194
+ try {
195
+ return await cleaner.clean('markup', screenshot, JSON.stringify({ shapes: drawing.shapes }))
196
+ } catch (error) {
197
+ if (error.code === 'no_markup') return null
198
+ throw error
199
+ }
200
+ }
@@ -7,7 +7,17 @@
7
7
  import { commentMentions } from '../mentions.js'
8
8
  import { publicReactions, toggleReaction } from '../reactions.js'
9
9
  import { GUEST_SHARE } from './guest-view.js'
10
- import { AGENT_STATUSES, AUTHOR_MAX, COMMENT_BODY_MAX, CommentError, cleanFixRef, currentVersion, validateCommentInput } from '../store.js'
10
+ import {
11
+ STORED_AGENT_STATUSES,
12
+ AUTHOR_MAX,
13
+ COMMENT_BODY_MAX,
14
+ CommentError,
15
+ cleanFixRef,
16
+ currentVersion,
17
+ validateCommentInput,
18
+ withMedia,
19
+ } from '../store.js'
20
+ import { removeCommentFiles, storeImages } from './comment-files.js'
11
21
 
12
22
  export { GUEST_SHARE, guestView } from './guest-view.js'
13
23
 
@@ -32,8 +42,8 @@ export function cleanAuthor(value, fallback = 'agent') {
32
42
  }
33
43
 
34
44
  function cleanAgentStatus(value) {
35
- if (value === null || AGENT_STATUSES.includes(value)) return value
36
- throw new CommentError(400, 'invalid_agent_status', `Agent status must be one of ${AGENT_STATUSES.join(', ')} (or null to clear).`)
45
+ if (value === null || STORED_AGENT_STATUSES.includes(value)) return value
46
+ throw new CommentError(400, 'invalid_agent_status', `Agent status must be one of ${STORED_AGENT_STATUSES.join(', ')} (or null to clear).`)
37
47
  }
38
48
 
39
49
  function parseNumber(value) {
@@ -56,12 +66,14 @@ function combinedReactions(current, imported) {
56
66
  // A row in the shape the board and agents know.
57
67
  export function rowToComment(row) {
58
68
  const stored = JSON.parse(row.replies || '[]')
69
+ // Images and a drawing, through their validators, only when present
70
+ // (withMedia, the same as the local store).
59
71
  const replies = stored.map(({ share: _share, user, token, reactions, ...reply }) => ({
60
- ...reply,
72
+ ...withMedia(reply),
61
73
  reactions: combinedReactions(reactions, JSON.stringify(reply.importedReactions || [])),
62
74
  [REPLY_AUTHOR]: { user: user || null, token: token || null },
63
75
  }))
64
- const comment = {
76
+ const comment = withMedia({
65
77
  id: row.number,
66
78
  ...(row.imported_by
67
79
  ? {
@@ -92,14 +104,16 @@ export function rowToComment(row) {
92
104
  resolvedAt: row.resolved_at || null,
93
105
  resolution: row.resolution || null,
94
106
  replies,
95
- agentStatus: AGENT_STATUSES.includes(row.agent_status) ? row.agent_status : null,
107
+ agentStatus: STORED_AGENT_STATUSES.includes(row.agent_status) ? row.agent_status : null,
96
108
  agentStatusAt: row.agent_status_at || null,
97
109
  reopenCount: row.reopen_count || 0,
98
110
  reopenedAt: row.reopened_at || null,
99
111
  ...(row.fix_ref ? { fixRef: row.fix_ref } : {}),
100
112
  editedAt: row.edited_at || null,
101
113
  reactions: combinedReactions(parseList(row.reactions), row.imported_reactions),
102
- }
114
+ images: parseList(row.images),
115
+ drawing: parseJson(row.drawing),
116
+ })
103
117
  // Guests never @mention anyone: their text must not wake a watcher
104
118
  // ("watch --mention agent") or page a person.
105
119
  comment.mentions = commentMentions({
@@ -110,6 +124,14 @@ export function rowToComment(row) {
110
124
  return comment
111
125
  }
112
126
 
127
+ function parseJson(text) {
128
+ try {
129
+ return text ? JSON.parse(text) : null
130
+ } catch {
131
+ return null
132
+ }
133
+ }
134
+
113
135
  function parseList(text) {
114
136
  try {
115
137
  const value = JSON.parse(text || '[]')
@@ -150,8 +172,10 @@ export function createCommentStore(t, projectId, boardId) {
150
172
  }
151
173
 
152
174
  // `author` is { name, userId, handle } for a person, { name, tokenId } for
153
- // a token, or { name, shareId } for a share link's guest.
154
- function create(config, board, input, author, now = new Date()) {
175
+ // a token, or { name, shareId } for a share link's guest. `media`: {
176
+ // images (cleaned, src/hosted/comment-files.js cleanImages), drawing
177
+ // (validateDrawing) }; inside the caller's transaction.
178
+ function create(config, board, input, author, now = new Date(), media = null) {
155
179
  const clean = validateCommentInput(config, board, input)
156
180
  const total = t.get(`SELECT COUNT(*) AS n FROM comments WHERE ${SCOPE}`, key).n
157
181
  if (total >= COMMENTS_MAX) throw new CommentError(409, 'too_many_comments', `A board holds at most ${COMMENTS_MAX} comments.`)
@@ -186,6 +210,17 @@ export function createCommentStore(t, projectId, boardId) {
186
210
  at,
187
211
  },
188
212
  )
213
+ if (media?.images?.length || media?.drawing) {
214
+ const images = storeImages(t, { projectId, boardId, commentNumber: number, images: media.images || [], at })
215
+ const version = rowOf(number).capture_version || null
216
+ t.run(`UPDATE comments SET images = :images, drawing = :drawing WHERE ${SCOPE} AND number = :number`, {
217
+ ...key,
218
+ number,
219
+ images: images.length ? JSON.stringify(images) : null,
220
+ // The drawing belongs to the capture it was drawn on.
221
+ drawing: media.drawing ? JSON.stringify({ ...media.drawing, captureVersion: version }) : null,
222
+ })
223
+ }
189
224
  return rowToComment(rowOf(number))
190
225
  }
191
226
 
@@ -261,14 +296,28 @@ export function createCommentStore(t, projectId, boardId) {
261
296
  }
262
297
 
263
298
  // `author`: { name, handle } for a person, { name, agent: true } for a
264
- // token, { name, guest: true } for a share link's guest.
265
- function reply(number, input, author, now = new Date()) {
299
+ // token, { name, guest: true } for a share link's guest. `media` as on
300
+ // create, plus the board's config (a reply's drawing is on the capture
301
+ // that is current when it is posted).
302
+ function reply(number, input, author, now = new Date(), media = null) {
266
303
  const body = cleanBody(input?.body)
267
304
  const row = { ...get(number) }
268
305
  const replies = JSON.parse(row.replies || '[]')
269
306
  if (replies.length >= REPLIES_MAX) throw new CommentError(409, 'too_many_replies', `A comment holds at most ${REPLIES_MAX} replies.`)
307
+ const id = Math.max(0, ...replies.map((item) => Number(item.id) || 0)) + 1
308
+ const images = media?.images?.length
309
+ ? storeImages(t, { projectId, boardId, commentNumber: row.number, replyId: id, images: media.images, at: now.toISOString() })
310
+ : []
311
+ const drawing = media?.drawing
312
+ ? {
313
+ ...media.drawing,
314
+ captureVersion: String(row.page_id).startsWith('variant:')
315
+ ? null
316
+ : currentVersion(media.config, boardId, row.page_id, row.viewport) || null,
317
+ }
318
+ : null
270
319
  const entry = {
271
- id: Math.max(0, ...replies.map((item) => Number(item.id) || 0)) + 1,
320
+ id,
272
321
  author: author.name,
273
322
  ...(author.handle ? { handle: author.handle } : {}),
274
323
  ...(author.agent ? { agent: true } : {}),
@@ -278,11 +327,13 @@ export function createCommentStore(t, projectId, boardId) {
278
327
  ...(author.agent && author.tokenId ? { token: author.tokenId } : {}),
279
328
  body,
280
329
  createdAt: now.toISOString(),
330
+ ...(images.length ? { images } : {}),
331
+ ...(drawing ? { drawing } : {}),
281
332
  }
282
333
  row.replies = JSON.stringify([...replies, entry])
283
334
  // The reply as everyone sees it: which link, account or token wrote it
284
335
  // stays stored only.
285
- const shown = { ...entry }
336
+ const shown = withMedia(entry)
286
337
  delete shown.share
287
338
  delete shown.user
288
339
  delete shown.token
@@ -293,11 +344,11 @@ export function createCommentStore(t, projectId, boardId) {
293
344
  // open comment whose status is one of them.
294
345
  function setAgentStatus(number, value, { onlyFrom = null } = {}, now = new Date()) {
295
346
  const next = cleanAgentStatus(value)
296
- if (onlyFrom && (!Array.isArray(onlyFrom) || onlyFrom.some((item) => item !== null && !AGENT_STATUSES.includes(item)))) {
347
+ if (onlyFrom && (!Array.isArray(onlyFrom) || onlyFrom.some((item) => item !== null && !STORED_AGENT_STATUSES.includes(item)))) {
297
348
  throw new CommentError(400, 'invalid_agent_status', 'onlyFrom: a list of agent statuses (null for none).')
298
349
  }
299
350
  const row = { ...get(number) }
300
- const current = AGENT_STATUSES.includes(row.agent_status) ? row.agent_status : null
351
+ const current = STORED_AGENT_STATUSES.includes(row.agent_status) ? row.agent_status : null
301
352
  if ((onlyFrom && (row.status !== 'open' || !onlyFrom.includes(current))) || current === next) {
302
353
  return { comment: rowToComment(row), changed: false }
303
354
  }
@@ -346,8 +397,10 @@ export function createCommentStore(t, projectId, boardId) {
346
397
  return { comment: rowToComment(rowOf(row.number)), added }
347
398
  }
348
399
 
400
+ // The comment, its images and its replies' images.
349
401
  function remove(number) {
350
402
  const row = get(number)
403
+ removeCommentFiles(t, projectId, boardId, row.number)
351
404
  t.run(`DELETE FROM comments WHERE ${SCOPE} AND number = :number`, { ...key, number: row.number })
352
405
  }
353
406
 
package/src/hosted/db.js CHANGED
@@ -430,6 +430,38 @@ const MIGRATIONS = [
430
430
  `,
431
431
  // 10: reports are private unless the creator explicitly includes them in a link.
432
432
  `ALTER TABLE shares ADD COLUMN include_checks INTEGER NOT NULL DEFAULT 0 CHECK(include_checks IN (0, 1));`,
433
+ // 11: images and drawings on comments and replies. The image records and
434
+ // the drawing are JSON on the comment row (replies keep theirs in the
435
+ // replies JSON); the image bytes are BLOBs here, not in the board folder,
436
+ // which every push replaces. A row belongs to one comment (and reply) and
437
+ // goes with it; rows without a comment are images a `shapewall share`
438
+ // import uploaded first (import_session, import_ref) and attaches in a
439
+ // later batch, swept when never attached.
440
+ `
441
+ ALTER TABLE comments ADD COLUMN images TEXT;
442
+ ALTER TABLE comments ADD COLUMN drawing TEXT;
443
+ CREATE TABLE comment_files (
444
+ workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,
445
+ project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
446
+ board_id TEXT NOT NULL,
447
+ file TEXT NOT NULL,
448
+ comment_number INTEGER,
449
+ reply_id INTEGER,
450
+ name TEXT NOT NULL,
451
+ media_type TEXT NOT NULL CHECK (media_type IN ('image/png', 'image/jpeg', 'image/webp', 'image/gif')),
452
+ bytes INTEGER NOT NULL,
453
+ width INTEGER NOT NULL,
454
+ height INTEGER NOT NULL,
455
+ data BLOB NOT NULL CHECK (length(data) <= 10485760),
456
+ import_session TEXT,
457
+ import_ref TEXT,
458
+ created_at TEXT NOT NULL,
459
+ PRIMARY KEY (project_id, board_id, file),
460
+ FOREIGN KEY (project_id, board_id, comment_number) REFERENCES comments(project_id, board_id, number) ON DELETE CASCADE
461
+ );
462
+ CREATE INDEX comment_files_comment ON comment_files(workspace_id, project_id, board_id, comment_number);
463
+ CREATE INDEX comment_files_import ON comment_files(workspace_id, project_id, import_session, import_ref);
464
+ `,
433
465
  ]
434
466
 
435
467
  export async function openDatabase(file) {
@@ -8,6 +8,11 @@ import { countedReactions } from '../reactions.js'
8
8
  // symbol key) so members and tokens never see it; guestView uses it.
9
9
  export const GUEST_SHARE = Symbol('guestShare')
10
10
 
11
+ const media = (item) => ({
12
+ ...(Array.isArray(item.images) && item.images.length ? { images: item.images } : {}),
13
+ ...(item.drawing ? { drawing: item.drawing } : {}),
14
+ })
15
+
11
16
  // What a share link guest sees of a comment: the text, place and state, and
12
17
  // no workspace detail. Members by display name only (no handles), agents as
13
18
  // "Agent", guests of other links as "Another guest"; no agent status,
@@ -27,6 +32,9 @@ export function guestView(comment, shareId) {
27
32
  ...(comment.authorGuest ? { authorGuest: true } : {}),
28
33
  ...(comment.authorAgent ? { authorAgent: true } : {}),
29
34
  ...(comment.anchor ? { anchor: comment.anchor } : {}),
35
+ // Images and a drawing, when the comment has them (members attach
36
+ // images; guests may draw).
37
+ ...media(comment),
30
38
  captureVersion: comment.captureVersion,
31
39
  status: comment.status,
32
40
  createdAt: comment.createdAt,
@@ -40,6 +48,7 @@ export function guestView(comment, shareId) {
40
48
  ...(reply.agent ? { agent: true } : {}),
41
49
  body: reply.body,
42
50
  createdAt: reply.createdAt,
51
+ ...media(reply),
43
52
  reactions: countedReactions(reply.reactions),
44
53
  })),
45
54
  reactions: countedReactions(comment.reactions),