@alpacachen/dsh-kanban 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { matchCardSearch } from './search.js'
2
+
1
3
  /**
2
4
  * dsh-kanban: DSH bundle host plugin (standard Cordis function plugin).
3
5
  *
@@ -7,11 +9,11 @@
7
9
  * Responsibilities:
8
10
  * - Workspace isolation: boards are keyed by workspaceId, one board per workspace.
9
11
  * - Persistence: ctx.fs writes <workspace.path>/.dsh-kanban.json.
10
- * - Agent tools: ctx.tools.register exposes 16 kanban_* tools.
12
+ * - Agent tools: ctx.tools.register exposes 19 kanban_* tools.
11
13
  * - Browser API: ctx.get('connection') registers the authenticated /api/kanban route.
12
14
  *
13
15
  * Per-workspace data model (disk files include schemaVersion):
14
- * schemaVersion: 5
16
+ * schemaVersion: 6
15
17
  * completedColumnId: string | null
16
18
  * columns: [{ id, title }]
17
19
  * labels: [{ name, color }] // name is the unique key and binds the color
@@ -46,7 +48,7 @@ export const inject = ['tools']
46
48
  // Back up old files before following the migration chain on first access.
47
49
  // ---------------------------------------------------------------------------
48
50
 
49
- export const SCHEMA_VERSION = 5
51
+ export const SCHEMA_VERSION = 6
50
52
  export const LEGACY_VERSION = 0
51
53
 
52
54
  // Append-only activity log persisted with the board; drop oldest events above the limit.
@@ -60,6 +62,20 @@ export const NOTE_LIMIT = 2000
60
62
  export const LABEL_LIMIT = 20
61
63
  export const COLUMN_TITLE_LIMIT = 40
62
64
  export const COMMENT_LIMIT = 2000
65
+ export const MAX_IMAGE_BYTES = 10 * 1024 * 1024
66
+ export const MAX_CARD_IMAGES = 10
67
+ const IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/webp']
68
+ const imageRef = ({ attachmentId, mediaType, bytes, width, height }) => ({ attachmentId, mediaType, bytes, width, height })
69
+ const validImageRef = (image) => isObj(image)
70
+ && /^sha256:[a-f0-9]{64}$/.test(image.attachmentId)
71
+ && IMAGE_TYPES.includes(image.mediaType)
72
+ && ['bytes', 'width', 'height'].every((field) => Number.isSafeInteger(image[field]) && image[field] > 0)
73
+ const imageType = (bytes) => {
74
+ if (bytes.length >= 8 && Buffer.from(bytes.subarray(0, 8)).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) return 'image/png'
75
+ if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return 'image/jpeg'
76
+ if (bytes.length >= 12 && Buffer.from(bytes.subarray(0, 4)).toString() === 'RIFF' && Buffer.from(bytes.subarray(8, 12)).toString() === 'WEBP') return 'image/webp'
77
+ throw new Error('Only PNG, JPEG and WebP images are supported')
78
+ }
63
79
 
64
80
  const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v)
65
81
  const strField = (v, fb) => (typeof v === 'string' && v ? v : fb)
@@ -145,6 +161,11 @@ export const MIGRATIONS = {
145
161
  completedColumnId: null,
146
162
  cards: Array.isArray(data.cards) ? data.cards.map((card) => isObj(card) ? { ...card, dueDate: null } : card) : data.cards,
147
163
  }),
164
+ 5: (data) => ({
165
+ ...data,
166
+ schemaVersion: 6,
167
+ cards: Array.isArray(data.cards) ? data.cards.map((card) => isObj(card) ? { ...card, images: [] } : card) : data.cards,
168
+ }),
148
169
  4: (data) => ({
149
170
  ...data,
150
171
  schemaVersion: 5,
@@ -238,6 +259,7 @@ export function validateBoard(data) {
238
259
  errors.push('duplicate card id: ' + c.id)
239
260
  break
240
261
  }
262
+ if (!Array.isArray(c.images) || c.images.length > MAX_CARD_IMAGES || c.images.some((image) => !validImageRef(image)) || new Set(c.images.map((image) => image.attachmentId)).size !== c.images.length) errors.push('card images contain invalid or duplicate references: ' + c.id)
241
263
  if (!columnIds.has(c.columnId)) errors.push('card references missing column: ' + c.id)
242
264
  if (c.label != null && !labelNames.has(c.label)) errors.push('card references missing label: ' + c.id)
243
265
  if (c.dueDate !== null && !isDueDate(c.dueDate)) errors.push('card has invalid due date: ' + c.id)
@@ -362,6 +384,15 @@ export function apply(ctx) {
362
384
  const getFs = () => ctx.get('fs')
363
385
  const getPolicy = () => ctx.get('sandboxPolicy')
364
386
  const getWorkspaceRegistry = () => ctx.get('workspaceRegistry')
387
+ const getAttachments = () => ctx.get('attachments')
388
+ const imageLimits = () => {
389
+ const store = getAttachments()
390
+ const limits = store?.imageLimits
391
+ if (!limits || typeof store.saveImage !== 'function' || typeof store.readImage !== 'function') return null
392
+ const mediaTypes = IMAGE_TYPES.filter((type) => limits.mediaTypes.includes(type))
393
+ const maxImageBytes = Math.min(MAX_IMAGE_BYTES, limits.maxImageBytes)
394
+ return mediaTypes.length && maxImageBytes > 0 ? { maxImageBytes, maxImagesPerCard: MAX_CARD_IMAGES, mediaTypes } : null
395
+ }
365
396
 
366
397
  const boards = new Map() // workspaceId -> { columns, labels, cards }
367
398
  const boardLoads = new Map() // workspaceId -> Promise<board>; publish only fully initialized boards
@@ -550,7 +581,7 @@ export function apply(ctx) {
550
581
  const target = await targetOf(workspace)
551
582
  const key = workspaceKey(workspace)
552
583
  const board = boards.get(key)
553
- if (!fs || !target || !board) return
584
+ if (!fs || !target || !board) return false
554
585
  try {
555
586
  await fs.writeText(
556
587
  target,
@@ -566,6 +597,7 @@ export function apply(ctx) {
566
597
  undefined,
567
598
  writePolicyFor(workspace, session),
568
599
  )
600
+ return true
569
601
  } catch (err) {
570
602
  console.log('dsh-kanban: Save failed ' + key + ': ' + ((err && err.message) || err))
571
603
  throw err
@@ -606,6 +638,7 @@ export function apply(ctx) {
606
638
  completedAt: c.completedAt,
607
639
  createdAt: typeof c.createdAt === 'string' ? c.createdAt : null,
608
640
  createdBy: typeof c.createdBy === 'string' ? c.createdBy : null,
641
+ images: c.images.map(imageRef),
609
642
  comments: Array.isArray(c.comments)
610
643
  ? c.comments.map((comment) => ({
611
644
  id: comment.id,
@@ -634,6 +667,7 @@ export function apply(ctx) {
634
667
  dueDate: c.dueDate,
635
668
  completedAt: c.completedAt,
636
669
  commentCount: c.comments.length,
670
+ imageCount: c.images.length,
637
671
  })),
638
672
  })
639
673
 
@@ -651,20 +685,56 @@ export function apply(ctx) {
651
685
  }
652
686
 
653
687
  // ---- Core operations shared by agent tools and browser HTTP ----
654
- const READ_METHODS = new Set(['get', 'getCard'])
688
+ const READ_METHODS = new Set(['get', 'getCard', '_getImage'])
655
689
  const dispatchUnlocked = async (workspace, method, args, source, session) => {
656
690
  const board = await boardOf(workspace, session)
657
691
  const a = args || {}
658
692
  const actor = source === 'agent' ? 'agent' : 'human'
659
693
  const persisted = () => persistedFlag(workspace)
660
- const result = (extra) => ({ board: cloneBoard(board), persisted: persisted(), warnings: takeWarnings(board), ...extra })
694
+ const result = (extra) => ({ board: cloneBoard(board), persisted: persisted(), imageLimits: imageLimits(), warnings: takeWarnings(board), ...extra })
661
695
  if (!READ_METHODS.has(method) && board.readOnlyReason) {
662
696
  return result({ error: board.readOnlyReason })
663
697
  }
664
698
 
665
699
  switch (method) {
666
- case 'get':
667
- return { board: cloneBoard(board), persisted: persisted(), warnings: takeWarnings(board), message: 'Board loaded' }
700
+ case 'get': {
701
+ if (a.query !== undefined && (typeof a.query !== 'string' || a.query.length > 200)) return result({ error: 'Search query must be at most 200 characters' })
702
+ const copy = cloneBoard(board)
703
+ copy.cards = copy.cards.filter((card) => matchCardSearch(card, a.query))
704
+ return result({ board: copy, message: 'Board loaded' })
705
+ }
706
+
707
+ case '_getImage': {
708
+ const card = findCard(board, a.id)
709
+ const image = card?.images.find((item) => item.attachmentId === a.attachmentId)
710
+ return image ? { image: imageRef(image) } : { error: 'Image not found on this card' }
711
+ }
712
+
713
+ case '_addImage': {
714
+ const card = findCard(board, a.id)
715
+ if (!card) return result({ error: 'Card not found: ' + str(a.id, '') })
716
+ if (!persisted()) return result({ error: 'Images require persistent workspace storage' })
717
+ if (!validImageRef(a.image)) return result({ error: 'Invalid image reference' })
718
+ if (card.images.some((image) => image.attachmentId === a.image.attachmentId)) return result({ message: 'Image already added' })
719
+ if (card.images.length >= MAX_CARD_IMAGES) return result({ error: 'A card can contain at most ' + MAX_CARD_IMAGES + ' images' })
720
+ card.images.push(imageRef(a.image))
721
+ record(board, { cardId: card.id, type: 'card_image_added', source: actor })
722
+ if (!await save(workspace, session)) throw new Error('Image association could not be persisted')
723
+ return result({ message: 'Image added' })
724
+ }
725
+
726
+ case 'removeImage': {
727
+ const card = findCard(board, a.id)
728
+ if (!card) return result({ error: 'Card not found: ' + str(a.id, '') })
729
+ if (!persisted()) return result({ error: 'Images require persistent workspace storage' })
730
+ const index = card.images.findIndex((image) => image.attachmentId === a.attachmentId)
731
+ if (index < 0) return result({ error: 'Image not found on this card' })
732
+ card.images.splice(index, 1)
733
+ // DSH objects may be shared by other cards and conversations.
734
+ record(board, { cardId: card.id, type: 'card_image_removed', source: actor })
735
+ if (!await save(workspace, session)) throw new Error('Image removal could not be persisted')
736
+ return result({ message: 'Image removed' })
737
+ }
668
738
 
669
739
  case 'getCard': {
670
740
  const card = cloneBoard(board).cards.find((c) => c.id === str(a.id, ''))
@@ -689,6 +759,7 @@ export function apply(ctx) {
689
759
  createdAt: new Date().toISOString(),
690
760
  createdBy: actor,
691
761
  comments: [],
762
+ images: [],
692
763
  }
693
764
  card.completedAt = col.id === board.completedColumnId ? card.createdAt : null
694
765
  board.cards.push(card)
@@ -705,7 +776,7 @@ export function apply(ctx) {
705
776
  },
706
777
  })
707
778
  await save(workspace, session)
708
- return result({ message: 'Card added to "' + col.title + '"' })
779
+ return result({ cardId: card.id, message: 'Card added to "' + col.title + '"' })
709
780
  }
710
781
 
711
782
  case 'updateCard': {
@@ -957,6 +1028,62 @@ export function apply(ctx) {
957
1028
  return run
958
1029
  }
959
1030
 
1031
+ const requireImages = () => {
1032
+ const limits = imageLimits()
1033
+ if (!limits) throw new Error('Image attachments require a DSH image storage service')
1034
+ return limits
1035
+ }
1036
+ const checkImageTarget = async (workspace, id, session) => {
1037
+ const board = await boardOf(workspace, session)
1038
+ if (board.readOnlyReason) throw new Error(board.readOnlyReason)
1039
+ if (!await targetOf(workspace)) throw new Error('Images require persistent workspace storage')
1040
+ if (writePolicyFor(workspace, session).mode === 'read-only') throw new Error('Workspace is read-only')
1041
+ const card = findCard(board, id)
1042
+ if (!card) throw new Error('Card not found: ' + str(id, ''))
1043
+ return card
1044
+ }
1045
+ const storeImage = async (workspace, id, data, mediaType, source, session) => {
1046
+ const limits = requireImages()
1047
+ await checkImageTarget(workspace, id, session)
1048
+ if (!limits.mediaTypes.includes(mediaType)) throw new Error('Only PNG, JPEG and WebP images are supported')
1049
+ if (!data.byteLength || data.byteLength > limits.maxImageBytes) throw new Error('Image exceeds the allowed byte limit or is empty')
1050
+ // The DSH store fully decodes and validates bytes before publishing an image reference.
1051
+ const image = await getAttachments().saveImage({ data, mediaType })
1052
+ return dispatch(workspace, '_addImage', { id, image }, source, session)
1053
+ }
1054
+ const importImage = async (workspace, args, exec) => {
1055
+ const session = exec?.agent?.session
1056
+ const limits = requireImages()
1057
+ await checkImageTarget(workspace, args.id, session)
1058
+ const source = args.source
1059
+ if (source?.kind === 'workspace_file') {
1060
+ if (typeof source.path !== 'string' || !source.path || source.path.includes('\0') || /^(?:[\\/]|[a-zA-Z]:)/.test(source.path)) throw new Error('Image path must be relative to the current workspace')
1061
+ const fs = getFs()
1062
+ if (typeof fs?.readBytes !== 'function' || typeof fs.contains !== 'function') throw new Error('This DSH filesystem cannot import images')
1063
+ const root = await fs.resolve(workspace.path)
1064
+ const target = await fs.resolve(source.path, { cwd: workspace.path })
1065
+ if (!fs.contains(root, target)) throw new Error('Image must be inside the current workspace')
1066
+ const data = await fs.readBytes(target, exec?.signal, limits.maxImageBytes)
1067
+ return storeImage(workspace, args.id, data, imageType(data), 'agent', session)
1068
+ }
1069
+ if (source?.kind === 'session_attachment') {
1070
+ const controller = ctx.get('sessionController')
1071
+ if (!session?.id || typeof controller?.attachment !== 'function') throw new Error('Current session image access is unavailable')
1072
+ // Only the current execution session can authorize an existing image reference.
1073
+ const stored = await controller.attachment({ sessionId: session.id, attachmentId: source.attachmentId })
1074
+ const image = stored.attachment
1075
+ if (!validImageRef(image) || image.bytes > limits.maxImageBytes || !limits.mediaTypes.includes(image.mediaType)) throw new Error('Session image exceeds the supported type or size limits')
1076
+ return dispatch(workspace, '_addImage', { id: args.id, image }, 'agent', session)
1077
+ }
1078
+ throw new Error('Expected a workspace_file or session_attachment image source')
1079
+ }
1080
+ const readCardImage = async (workspace, args, session, signal) => {
1081
+ requireImages()
1082
+ const result = await dispatch(workspace, '_getImage', args, 'agent', session)
1083
+ if (result.error) throw new Error(result.error)
1084
+ return getAttachments().readImage(result.image, signal)
1085
+ }
1086
+
960
1087
  // ---- Tool execution context and browser workspaceId resolution ----
961
1088
  const workspaceOfExec = async (exec) => {
962
1089
  const agent = exec && exec.agent
@@ -996,6 +1123,7 @@ export function apply(ctx) {
996
1123
  const r = await dispatch(workspace, method, args, 'agent', session)
997
1124
  return {
998
1125
  ok: !r.error,
1126
+ ...(r.cardId ? { cardId: r.cardId } : {}),
999
1127
  message: r.error || r.message || 'Done',
1000
1128
  board: summaryOfClone(r.board),
1001
1129
  warnings: Array.isArray(r.warnings) ? r.warnings : [],
@@ -1038,6 +1166,7 @@ export function apply(ctx) {
1038
1166
  const body = raw ? JSON.parse(raw) : {}
1039
1167
  if (!isObj(body)) return sendJson(400, { error: 'Expected a JSON object' })
1040
1168
  const method = typeof body.method === 'string' ? body.method : 'get'
1169
+ if (method.startsWith('_')) return sendJson(400, { error: 'Unknown kanban method' })
1041
1170
  const args = isObj(body.args) ? body.args : {}
1042
1171
  const workspaceId = typeof args.workspaceId === 'string' ? args.workspaceId : ''
1043
1172
  const workspace = workspaceId ? workspaceOfId(workspaceId) : undefined
@@ -1058,6 +1187,89 @@ export function apply(ctx) {
1058
1187
  fetch: httpHandler,
1059
1188
  }))
1060
1189
 
1190
+ const imageHttpHandler = async (req) => {
1191
+ try {
1192
+ if (!['GET', 'POST'].includes(req.method)) return sendJson(405, { error: 'Method not allowed' })
1193
+ const chunks = []
1194
+ let oversized = false
1195
+ if (req.method === 'POST' && req.body) {
1196
+ const maxBytes = imageLimits()?.maxImageBytes ?? MAX_IMAGE_BYTES
1197
+ const reader = req.body.getReader()
1198
+ let size = 0
1199
+ let timedOut = false
1200
+ const timeout = setTimeout(() => {
1201
+ timedOut = true
1202
+ void reader.cancel().catch(() => {})
1203
+ }, 30_000)
1204
+ try {
1205
+ // Connection destroys unread requests before its error response can flush; drain without buffering excess bytes.
1206
+ while (true) {
1207
+ const { done, value } = await reader.read()
1208
+ if (done) break
1209
+ if (!oversized) {
1210
+ size += value.byteLength
1211
+ oversized = size > maxBytes
1212
+ if (oversized) chunks.length = 0
1213
+ else chunks.push(value)
1214
+ }
1215
+ }
1216
+ } finally {
1217
+ clearTimeout(timeout)
1218
+ reader.releaseLock()
1219
+ }
1220
+ // shortcut: Connection may close timed-out uploads without a JSON response; revisit when its streaming bridge flushes before destroying requests.
1221
+ if (timedOut) return sendJson(408, { error: 'Image upload timed out' })
1222
+ }
1223
+ const url = new URL(req.url)
1224
+ const origin = req.headers.get('origin')
1225
+ const host = req.headers.get('host') || url.host
1226
+ if (origin) {
1227
+ let originHost = ''
1228
+ try { originHost = new URL(origin).host } catch {}
1229
+ if (originHost !== host) return sendJson(403, { error: 'Cross-origin request denied' })
1230
+ }
1231
+ const workspace = workspaceOfId(url.searchParams.get('workspaceId') || '')
1232
+ if (!workspace) return sendJson(400, { error: 'Unknown workspace' })
1233
+ const id = url.searchParams.get('cardId') || ''
1234
+ if (req.method === 'GET') {
1235
+ const attachmentId = url.searchParams.get('attachmentId') || ''
1236
+ const ref = await dispatch(workspace, '_getImage', { id, attachmentId }, 'human')
1237
+ if (ref.error) return sendJson(404, { error: ref.error })
1238
+ requireImages()
1239
+ const stored = await getAttachments().readImage(ref.image, req.signal)
1240
+ return new Response(stored.data.slice(), { headers: {
1241
+ 'Content-Type': stored.ref.mediaType,
1242
+ 'Content-Length': String(stored.data.byteLength),
1243
+ 'Cache-Control': 'private, no-store',
1244
+ 'X-Content-Type-Options': 'nosniff',
1245
+ 'Content-Security-Policy': "sandbox; default-src 'none'",
1246
+ } })
1247
+ }
1248
+ const limits = requireImages()
1249
+ const mediaType = (req.headers.get('content-type') || '').split(';', 1)[0].trim().toLowerCase()
1250
+ if (!limits.mediaTypes.includes(mediaType)) return sendJson(415, { error: 'Only PNG, JPEG and WebP images are supported' })
1251
+ if (oversized) return sendJson(413, { error: 'Image exceeds the allowed byte limit' })
1252
+ await checkImageTarget(workspace, id)
1253
+ const result = await storeImage(workspace, id, Buffer.concat(chunks), mediaType, 'human')
1254
+ return sendJson(result.error ? 400 : 200, result)
1255
+ } catch (err) {
1256
+ return sendJson(400, { error: String(err?.message || err) })
1257
+ }
1258
+ }
1259
+ // Connection's streaming bridge always supplies a body, which Fetch forbids on GET.
1260
+ ctx.inject(['connection'], (routeCtx) => routeCtx.connection.fetch.register({
1261
+ path: '/api/kanban/image',
1262
+ methods: ['GET'],
1263
+ requestBody: 'buffered',
1264
+ fetch: imageHttpHandler,
1265
+ }))
1266
+ ctx.inject(['connection'], (routeCtx) => routeCtx.connection.fetch.register({
1267
+ path: '/api/kanban/image/upload',
1268
+ methods: ['POST'],
1269
+ requestBody: 'streaming',
1270
+ fetch: imageHttpHandler,
1271
+ }))
1272
+
1061
1273
  // ---- Startup checks: read each workspace board and back up corrupt files ----
1062
1274
  const runStartupCheck = async () => {
1063
1275
  const fs = getFs()
@@ -1129,6 +1341,7 @@ export function apply(ctx) {
1129
1341
  ok: { type: 'boolean' },
1130
1342
  message: { type: 'string' },
1131
1343
  board: { type: 'object' },
1344
+ cardId: { type: 'string' },
1132
1345
  warnings: { type: 'array', items: { type: 'string' } },
1133
1346
  },
1134
1347
  required: ['ok', 'message'],
@@ -1159,7 +1372,8 @@ export function apply(ctx) {
1159
1372
  card.title +
1160
1373
  (card.dueDate ? ' (due ' + card.dueDate + ')' : '') +
1161
1374
  (card.columnId === b.completedColumnId ? ' [completed; completedAt: ' + (card.completedAt || 'unknown') + ']' : '') +
1162
- (card.commentCount ? ' (' + card.commentCount + ' comments)' : ''),
1375
+ (card.commentCount ? ' (' + card.commentCount + ' comments)' : '') +
1376
+ (card.imageCount ? ' (' + card.imageCount + ' images)' : ''),
1163
1377
  )
1164
1378
  }
1165
1379
  }
@@ -1169,10 +1383,67 @@ export function apply(ctx) {
1169
1383
  const output = (render) => ({ schema: resultSchema, render: (args, value) => render(value) })
1170
1384
 
1171
1385
  const tools = [
1386
+ {
1387
+ name: 'kanban_add_image',
1388
+ description: 'Add a PNG, JPEG or WebP image to an existing card. Supply a workspace-relative file path or an attachmentId actually present in the current session. Never send base64 or a URL. Use the cardId returned by kanban_add_card. Retries of the same image do not add duplicates.',
1389
+ parameters: {
1390
+ type: 'object',
1391
+ properties: {
1392
+ id: { type: 'string', description: 'Card id' },
1393
+ source: {
1394
+ oneOf: [
1395
+ { type: 'object', properties: { kind: { type: 'string', const: 'workspace_file' }, path: { type: 'string' } }, required: ['kind', 'path'], additionalProperties: false },
1396
+ { type: 'object', properties: { kind: { type: 'string', const: 'session_attachment' }, attachmentId: { type: 'string' } }, required: ['kind', 'attachmentId'], additionalProperties: false },
1397
+ ],
1398
+ },
1399
+ },
1400
+ required: ['id', 'source'],
1401
+ },
1402
+ output: output(renderBoard),
1403
+ async execute(args, exec) {
1404
+ try {
1405
+ const workspace = await workspaceOfExec(exec)
1406
+ if (!workspace) throw new Error('Cannot determine current workspace')
1407
+ const result = await importImage(workspace, args, exec)
1408
+ return { ok: !result.error, message: result.error || result.message, board: summaryOfClone(result.board), warnings: result.warnings || [] }
1409
+ } catch (err) {
1410
+ return { ok: false, message: String(err?.message || err), warnings: [] }
1411
+ }
1412
+ },
1413
+ },
1414
+ {
1415
+ name: 'kanban_read_image',
1416
+ description: 'Read the actual image attached to a card for visual inspection. Use an attachmentId from kanban_get_card. Only images associated with the card in the current workspace can be read.',
1417
+ parameters: { type: 'object', properties: { id: { type: 'string' }, attachmentId: { type: 'string' } }, required: ['id', 'attachmentId'] },
1418
+ output: {
1419
+ schema: { type: 'object', properties: { ok: { type: 'boolean' }, message: { type: 'string' }, image: { type: 'object' } }, required: ['ok', 'message'], additionalProperties: false },
1420
+ render: (_args, value) => value.ok && value.image
1421
+ ? [{ type: 'text', text: value.message }, { type: 'image', attachment: value.image }]
1422
+ : [{ type: 'text', text: value.message }],
1423
+ },
1424
+ async execute(args, exec) {
1425
+ try {
1426
+ const workspace = await workspaceOfExec(exec)
1427
+ if (!workspace) throw new Error('Cannot determine current workspace')
1428
+ const stored = await readCardImage(workspace, args, exec?.agent?.session, exec?.signal)
1429
+ return { ok: true, message: 'Card image', image: imageRef(stored.ref) }
1430
+ } catch (err) {
1431
+ return { ok: false, message: String(err?.message || err) }
1432
+ }
1433
+ },
1434
+ },
1435
+ {
1436
+ name: 'kanban_remove_image',
1437
+ description: 'Remove an image association from a card. The DSH object may still be used by other cards or conversations and is not physically deleted.',
1438
+ parameters: { type: 'object', properties: { id: { type: 'string' }, attachmentId: { type: 'string' } }, required: ['id', 'attachmentId'] },
1439
+ output: output(renderBoard),
1440
+ execute(args, exec) { return runTool('removeImage', args, exec) },
1441
+ },
1442
+
1172
1443
  {
1173
1444
  name: 'kanban_get',
1174
- description: 'Read the current state of the current project (workspace) kanban board (all lists, labels, cards with dueDate and completedAt, and completedColumnId). Due dates are local calendar dates, not UTC timestamps; a date becomes overdue the following day. Cards in completedColumnId are finished and excluded from due-today/overdue checks. completedAt is the latest completion UTC timestamp; null on a completed card means unknown. Resolve relative dates using the user local date and confirm the concrete YYYY-MM-DD date. Call it before planning to understand existing content and avoid duplicate cards.',
1175
- parameters: { type: 'object', properties: {} },
1445
+ description: 'Read the current state of the current project (workspace) kanban board (all lists, labels, cards optionally filtered by query, with dueDate and completedAt, and completedColumnId). Due dates are local calendar dates, not UTC timestamps; a date becomes overdue the following day. Cards in completedColumnId are finished and excluded from due-today/overdue checks. completedAt is the latest completion UTC timestamp; null on a completed card means unknown. Resolve relative dates using the user local date and confirm the concrete YYYY-MM-DD date. Call it before planning to understand existing content and avoid duplicate cards.',
1446
+ parameters: { type: 'object', properties: { query: { type: 'string', description: 'Optional text, at most 200 characters. Literal text search across card ids, titles, descriptions and comments; ignores case and surrounding whitespace.' } } },
1176
1447
  output: output(renderBoard),
1177
1448
  async execute(args, exec) {
1178
1449
  return runTool('get', args, exec)
@@ -1216,6 +1487,7 @@ export function apply(ctx) {
1216
1487
  lines.push('Completed: ' + (c.columnId === value.completedColumnId ? 'yes' : 'no'))
1217
1488
  if (c.columnId === value.completedColumnId) lines.push('Completed at: ' + (c.completedAt || 'unknown'))
1218
1489
  if (c.note) lines.push('Note: ' + c.note)
1490
+ for (const image of c.images || []) lines.push('Image: ' + image.attachmentId + ' (' + image.width + '×' + image.height + '); use kanban_read_image to view it')
1219
1491
  if (Array.isArray(c.comments) && c.comments.length > 0) {
1220
1492
  lines.push('Comments:')
1221
1493
  for (const comment of c.comments) {