@linxin666/dsh-client-ui-task-board 0.4.12 → 0.4.14

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 (61) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +9 -3
  3. package/README.zh.md +9 -3
  4. package/lib/client.js +1476 -478
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +1280 -65
  7. package/lib/types/client/board/AttachmentField.d.ts +70 -0
  8. package/lib/types/client/board/model-options.d.ts +21 -1
  9. package/lib/types/client/board/source-group.d.ts +27 -0
  10. package/lib/types/client/host-api.d.ts +25 -0
  11. package/lib/types/client/locales.d.ts +17 -0
  12. package/lib/types/client/pending-verify.d.ts +47 -0
  13. package/lib/types/client/service.d.ts +4 -1
  14. package/lib/types/core/attachment.d.ts +132 -0
  15. package/lib/types/core/controller.d.ts +26 -2
  16. package/lib/types/core/extension.d.ts +82 -0
  17. package/lib/types/core/session-reuse.d.ts +7 -1
  18. package/lib/types/core/tasks.d.ts +38 -1
  19. package/lib/types/core/use-cases/task-update.d.ts +21 -0
  20. package/lib/types/core/wire-projection.d.ts +35 -0
  21. package/lib/types/host/attachments.d.ts +250 -0
  22. package/lib/types/host/extension-registry.d.ts +40 -0
  23. package/lib/types/host-ledger.d.ts +16 -0
  24. package/lib/types/host-routes.d.ts +14 -0
  25. package/lib/types/host-runner.d.ts +53 -1
  26. package/lib/types/host-service.d.ts +59 -0
  27. package/lib/types/index.d.ts +23 -0
  28. package/lib/types/protocol.d.ts +39 -6
  29. package/locale/en.json +6 -0
  30. package/locale/zh.json +6 -0
  31. package/package.json +6 -2
  32. package/src/client/TaskBoardSettingsCard.tsx +11 -1
  33. package/src/client/board/AttachmentField.tsx +383 -0
  34. package/src/client/board/EditTaskModal.tsx +63 -0
  35. package/src/client/board/NewTaskModal.tsx +76 -4
  36. package/src/client/board/TaskBoard.tsx +47 -10
  37. package/src/client/board/TaskDetail.tsx +30 -2
  38. package/src/client/board/model-options.ts +32 -2
  39. package/src/client/board/source-group.ts +94 -0
  40. package/src/client/board.module.css +83 -0
  41. package/src/client/host-api.ts +70 -0
  42. package/src/client/index.ts +11 -0
  43. package/src/client/locales.ts +34 -0
  44. package/src/client/pending-verify.ts +90 -0
  45. package/src/client/service.ts +24 -0
  46. package/src/core/attachment.ts +287 -0
  47. package/src/core/controller.ts +47 -1
  48. package/src/core/extension.ts +86 -0
  49. package/src/core/session-reuse.ts +7 -1
  50. package/src/core/store.ts +10 -1
  51. package/src/core/tasks.ts +49 -0
  52. package/src/core/use-cases/task-update.ts +27 -2
  53. package/src/core/wire-projection.ts +81 -0
  54. package/src/host/attachments.ts +650 -0
  55. package/src/host/extension-registry.ts +150 -5
  56. package/src/host-ledger.ts +32 -4
  57. package/src/host-routes.ts +168 -13
  58. package/src/host-runner.ts +124 -4
  59. package/src/host-service.ts +165 -12
  60. package/src/index.ts +47 -0
  61. package/src/protocol.ts +57 -9
@@ -0,0 +1,287 @@
1
+ /**
2
+ * Card attachments: the durable metadata a card keeps about the files and
3
+ * images it carries.
4
+ *
5
+ * The ledger stores METADATA only — never bytes, never base64, never a data
6
+ * URL, never an upload timestamp. The bytes live in the official attachment
7
+ * storage; this record says WHICH object, how large it is, and what it is, so
8
+ * an execution can resolve the object and the Host can prove the recorded
9
+ * claim against the storage before the claim reaches the ledger.
10
+ *
11
+ * The module is pure (no cordis, no runtime imports) so both halves — the Host
12
+ * ledger and the browser form — share one vocabulary and one set of limits.
13
+ */
14
+
15
+ /** What one attachment holds: a raster image or an arbitrary file. */
16
+ export type TaskAttachmentKind = 'image' | 'file'
17
+
18
+ /**
19
+ * One attachment of a card: identity, size and type, plus the digest of the
20
+ * exact bytes the Host stored.
21
+ *
22
+ * An image carries its intrinsic pixel size; a file carries neither. The
23
+ * display name is always the CANONICAL form (see
24
+ * {@link canonicalAttachmentName}): single-line, without any path part, so a
25
+ * name can never break the prompt an execution reads.
26
+ */
27
+ export interface TaskAttachment {
28
+ /** Whether the object is a raster image or an arbitrary file. */
29
+ kind: TaskAttachmentKind
30
+ /** Opaque storage identifier of the stored object; never a path or a URL. */
31
+ attachmentId: string
32
+ /** Canonical display name; never a local path, never multi-line. */
33
+ name: string
34
+ /** Exact stored byte length. */
35
+ bytes: number
36
+ /** Media type of the stored bytes. */
37
+ mediaType: string
38
+ /** Lowercase hex sha256 digest of the exact stored bytes. */
39
+ sha256: string
40
+ /** Intrinsic pixel width; images only, always positive. */
41
+ width?: number
42
+ /** Intrinsic pixel height; images only, always positive. */
43
+ height?: number
44
+ }
45
+
46
+ /** Maximum number of attachments one card may carry. */
47
+ export const TASK_ATTACHMENT_LIMIT = 8
48
+ /** Maximum byte length of one attachment (10 MiB). */
49
+ export const TASK_ATTACHMENT_MAX_BYTES = 10 * 1024 * 1024
50
+ /** Maximum byte length of all attachments of one card together (32 MiB). */
51
+ export const TASK_ATTACHMENT_TOTAL_MAX_BYTES = 32 * 1024 * 1024
52
+ /** Raster media types the official image path accepts. */
53
+ export const TASK_ATTACHMENT_IMAGE_MEDIA_TYPES = ['image/png', 'image/jpeg', 'image/webp', 'image/gif'] as const
54
+
55
+ /** Longest accepted display name of an attachment. */
56
+ const ATTACHMENT_NAME_MAX_LENGTH = 255
57
+ /** Longest accepted media type of an attachment. */
58
+ const ATTACHMENT_MEDIA_TYPE_MAX_LENGTH = 255
59
+ /** Longest accepted storage identifier of an attachment. */
60
+ const ATTACHMENT_ID_MAX_LENGTH = 512
61
+
62
+ const SHA256_PATTERN = /^[0-9a-f]{64}$/
63
+ const MEDIA_TYPE_PATTERN = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/
64
+
65
+ /** Every key one attachment may carry. */
66
+ const ATTACHMENT_KEYS = ['kind', 'attachmentId', 'name', 'bytes', 'mediaType', 'sha256', 'width', 'height'] as const
67
+
68
+ function isPlainObject(value: unknown): value is Record<string, unknown> {
69
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
70
+ }
71
+
72
+ /** Whether a value is a well-formed positive pixel count. */
73
+ function isPixelCount(value: unknown): value is number {
74
+ return typeof value === 'number' && Number.isInteger(value) && value > 0
75
+ }
76
+
77
+ /**
78
+ * The canonical display name of an attachment.
79
+ *
80
+ * A name reaches the ledger from two directions: the browser picks it, and an
81
+ * execution prompt reads it. Both make one form mandatory — the name must be
82
+ * a single line without any path part, so it can neither break out of the
83
+ * prompt line nor point at a directory.
84
+ *
85
+ * The canonical form is therefore: the LEAF of whatever path-like text was
86
+ * offered, every control character (a newline included) turned into a space,
87
+ * whitespace runs collapsed into one space, the result trimmed and bounded.
88
+ * An empty result becomes a fixed placeholder.
89
+ *
90
+ * The Host upload path canonicalizes the name BEFORE publishing it, and the
91
+ * wire gate accepts only a name that already IS canonical — so the name the
92
+ * ledger holds and the name the storage holds are the same string.
93
+ * @param value - the offered name.
94
+ * @returns the canonical name.
95
+ */
96
+ export function canonicalAttachmentName(value: unknown): string {
97
+ const raw = typeof value === 'string' ? value : ''
98
+ const leaf = raw.split(/[\\/]/).pop() ?? ''
99
+ const cleaned = leaf
100
+ .replace(/[\u0000-\u001f\u007f]/g, ' ')
101
+ .replace(/\s+/g, ' ')
102
+ .trim()
103
+ if (cleaned === '') return 'attachment'
104
+ return cleaned.slice(0, ATTACHMENT_NAME_MAX_LENGTH)
105
+ }
106
+
107
+ /**
108
+ * Whether an unknown value is a well-formed attachment (the STRICT gate: the
109
+ * wire path uses it, so a hand-written payload cannot smuggle an extra field
110
+ * onto the ledger, a path-like name, or an image without its pixel size).
111
+ * @param value - the candidate attachment.
112
+ * @returns whether the value is a usable attachment.
113
+ */
114
+ export function isTaskAttachment(value: unknown): value is TaskAttachment {
115
+ if (!isPlainObject(value)) return false
116
+ if (Object.keys(value).some(key => !(ATTACHMENT_KEYS as readonly string[]).includes(key))) return false
117
+ if (value.kind !== 'image' && value.kind !== 'file') return false
118
+ if (typeof value.attachmentId !== 'string') return false
119
+ const id = value.attachmentId
120
+ if (id === '' || id.length > ATTACHMENT_ID_MAX_LENGTH) return false
121
+ // A storage identifier is opaque: a value that looks like a path or a URL is
122
+ // refused rather than stored, so no consumer can mistake it for one.
123
+ if (id.includes('/') || id.includes('\\') || id.includes('..')) return false
124
+ if (typeof value.name !== 'string') return false
125
+ // The name must ALREADY be canonical: a payload that carries a path, a
126
+ // newline or a control character is refused rather than repaired, because
127
+ // the client and the Host must agree on one name.
128
+ if (value.name !== canonicalAttachmentName(value.name)) return false
129
+ if (typeof value.bytes !== 'number' || !Number.isInteger(value.bytes) || value.bytes < 0) return false
130
+ if (typeof value.mediaType !== 'string' || value.mediaType.length > ATTACHMENT_MEDIA_TYPE_MAX_LENGTH) return false
131
+ if (!MEDIA_TYPE_PATTERN.test(value.mediaType)) return false
132
+ // The media type is stored lowercased by the Host upload path, so the gate
133
+ // requires the same form the Host produces.
134
+ if (value.mediaType !== value.mediaType.toLowerCase()) return false
135
+ if (typeof value.sha256 !== 'string' || !SHA256_PATTERN.test(value.sha256)) return false
136
+ if (value.kind === 'image') {
137
+ if (!TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(value.mediaType.toLowerCase() as typeof TASK_ATTACHMENT_IMAGE_MEDIA_TYPES[number])) return false
138
+ // An image always carries its intrinsic pixel size: a record without one
139
+ // cannot address the stored object, so it is refused rather than
140
+ // completed with a manufactured 0x0.
141
+ if (!isPixelCount(value.width) || !isPixelCount(value.height)) return false
142
+ } else {
143
+ // A file carries no pixel size: the fields exist for images only.
144
+ if (value.width !== undefined || value.height !== undefined) return false
145
+ }
146
+ return true
147
+ }
148
+
149
+ /**
150
+ * Repair one persisted attachment entry: canonicalize its name and keep the
151
+ * fields that are usable. An entry that cannot be repaired — an unknown kind,
152
+ * a malformed identifier, an image without its pixel size — is dropped.
153
+ * @param value - the persisted entry.
154
+ * @returns the repaired attachment, or undefined when it cannot be repaired.
155
+ */
156
+ export function repairAttachment(value: unknown): TaskAttachment | undefined {
157
+ if (!isPlainObject(value)) return undefined
158
+ if (value.kind !== 'image' && value.kind !== 'file') return undefined
159
+ if (typeof value.attachmentId !== 'string') return undefined
160
+ const id = value.attachmentId
161
+ if (id === '' || id.length > ATTACHMENT_ID_MAX_LENGTH) return undefined
162
+ if (id.includes('/') || id.includes('\\') || id.includes('..')) return undefined
163
+ if (typeof value.bytes !== 'number' || !Number.isInteger(value.bytes) || value.bytes < 0) return undefined
164
+ if (typeof value.mediaType !== 'string' || !MEDIA_TYPE_PATTERN.test(value.mediaType)) return undefined
165
+ if (typeof value.sha256 !== 'string' || !SHA256_PATTERN.test(value.sha256)) return undefined
166
+ const name = canonicalAttachmentName(value.name)
167
+ if (value.kind === 'image') {
168
+ if (!TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(value.mediaType.toLowerCase() as typeof TASK_ATTACHMENT_IMAGE_MEDIA_TYPES[number])) return undefined
169
+ if (!isPixelCount(value.width) || !isPixelCount(value.height)) return undefined
170
+ return {
171
+ kind: 'image',
172
+ attachmentId: id,
173
+ name,
174
+ bytes: value.bytes,
175
+ mediaType: value.mediaType.toLowerCase(),
176
+ sha256: value.sha256,
177
+ width: value.width,
178
+ height: value.height,
179
+ }
180
+ }
181
+ if (value.width !== undefined || value.height !== undefined) return undefined
182
+ return {
183
+ kind: 'file',
184
+ attachmentId: id,
185
+ name,
186
+ bytes: value.bytes,
187
+ mediaType: value.mediaType.toLowerCase(),
188
+ sha256: value.sha256,
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Whether a list satisfies the card-wide attachment limits: the count, the
194
+ * per-item byte cap, and the total byte cap.
195
+ * @param attachments - the candidate list.
196
+ * @returns whether the list fits every limit.
197
+ */
198
+ export function attachmentsWithinLimits(attachments: readonly TaskAttachment[]): boolean {
199
+ if (attachments.length > TASK_ATTACHMENT_LIMIT) return false
200
+ let total = 0
201
+ for (const attachment of attachments) {
202
+ if (attachment.bytes > TASK_ATTACHMENT_MAX_BYTES) return false
203
+ total += attachment.bytes
204
+ }
205
+ return total <= TASK_ATTACHMENT_TOTAL_MAX_BYTES
206
+ }
207
+
208
+ /**
209
+ * Drop the repeated storage identifiers of a list, keeping the FIRST entry of
210
+ * each identifier.
211
+ *
212
+ * The storage is content-addressed, so the same bytes uploaded twice produce
213
+ * the same identifier. A list that carried the identifier twice would render
214
+ * two rows for one object and claim it twice against the card's limits, so the
215
+ * list is deduplicated at the boundary that can produce it.
216
+ * @param attachments - the candidate list.
217
+ * @returns the deduplicated list, in the original order.
218
+ */
219
+ export function dedupeAttachments(attachments: readonly TaskAttachment[]): TaskAttachment[] {
220
+ const seen = new Set<string>()
221
+ const unique: TaskAttachment[] = []
222
+ for (const attachment of attachments) {
223
+ if (seen.has(attachment.attachmentId)) continue
224
+ seen.add(attachment.attachmentId)
225
+ unique.push(attachment)
226
+ }
227
+ return unique
228
+ }
229
+
230
+ /**
231
+ * Whether an unknown value is a well-formed attachment LIST (the strict wire
232
+ * gate). The list must be non-empty: clearing attachments is expressed by
233
+ * omitting the field (create) or by an explicit null (update), never by an
234
+ * empty array. A list that repeats one storage identifier is refused: one
235
+ * object cannot be claimed twice.
236
+ * @param value - the candidate list.
237
+ * @returns whether the list may reach the ledger.
238
+ */
239
+ export function isTaskAttachmentList(value: unknown): value is TaskAttachment[] {
240
+ if (!Array.isArray(value)) return false
241
+ if (value.length === 0 || value.length > TASK_ATTACHMENT_LIMIT) return false
242
+ if (!value.every(isTaskAttachment)) return false
243
+ const list = value as TaskAttachment[]
244
+ if (new Set(list.map(attachment => attachment.attachmentId)).size !== list.length) return false
245
+ return attachmentsWithinLimits(list)
246
+ }
247
+
248
+ /**
249
+ * Repair a persisted attachment list: canonicalize the names, drop the
250
+ * entries that cannot be repaired, deduplicate the storage identifiers, and
251
+ * cap the count and the byte totals. Returns undefined when nothing usable
252
+ * remains, so the caller clears the field instead of storing an empty list —
253
+ * the same policy the tag and schedule repairs follow.
254
+ * @param value - the persisted value.
255
+ * @returns the repaired list, or undefined when nothing survives.
256
+ */
257
+ export function normalizeAttachments(value: unknown): TaskAttachment[] | undefined {
258
+ if (!Array.isArray(value)) return undefined
259
+ const repaired: TaskAttachment[] = []
260
+ const seen = new Set<string>()
261
+ let total = 0
262
+ for (const entry of value) {
263
+ const attachment = repairAttachment(entry)
264
+ if (attachment === undefined) continue
265
+ if (attachment.bytes > TASK_ATTACHMENT_MAX_BYTES) continue
266
+ if (total + attachment.bytes > TASK_ATTACHMENT_TOTAL_MAX_BYTES) continue
267
+ if (seen.has(attachment.attachmentId)) continue
268
+ seen.add(attachment.attachmentId)
269
+ total += attachment.bytes
270
+ repaired.push(attachment)
271
+ if (repaired.length >= TASK_ATTACHMENT_LIMIT) break
272
+ }
273
+ return repaired.length === 0 ? undefined : repaired
274
+ }
275
+
276
+ /**
277
+ * The attachment of a list whose storage identifier matches, or undefined.
278
+ * @param attachments - the list to search.
279
+ * @param attachmentId - the storage identifier to find.
280
+ * @returns the matching attachment, or undefined.
281
+ */
282
+ export function findAttachment(
283
+ attachments: readonly TaskAttachment[] | undefined,
284
+ attachmentId: string,
285
+ ): TaskAttachment | undefined {
286
+ return attachments?.find(attachment => attachment.attachmentId === attachmentId)
287
+ }
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import type { TaskStore } from './store.ts'
15
15
  import { hasOpenExecution, withStatus, type NewTaskInput, type TaskRecord, type TaskStatus } from './tasks.ts'
16
+ import type { TaskAttachment, TaskAttachmentKind } from './attachment.ts'
16
17
  import { applyArchiveTask, applyRestoreTask } from './use-cases/task-archive.ts'
17
18
  import { applyCreateTask } from './use-cases/task-create.ts'
18
19
  import { applyDeleteTask } from './use-cases/task-delete.ts'
@@ -31,6 +32,7 @@ import type {
31
32
  } from '../protocol.ts'
32
33
  import type {
33
34
  TaskBoardExtensionActionRequest,
35
+ TaskBoardGroupingSelector,
34
36
  TaskBoardVisibilityPredicate,
35
37
  } from './extension.ts'
36
38
 
@@ -48,6 +50,12 @@ export interface TaskBoardTransport {
48
50
  * that cannot parse simply omits it, and the form hides the section.
49
51
  */
50
52
  parseDraft?(request: TaskBoardParseRequest, signal?: AbortSignal): Promise<TaskBoardParseDraft>
53
+ /**
54
+ * Upload one file or image into the Host's attachment storage. Optional: a
55
+ * deployment that serves no attachment storage omits it, and the form then
56
+ * refuses to stage an attachment.
57
+ */
58
+ uploadAttachment?(file: File, kind: TaskAttachmentKind): Promise<TaskAttachment>
51
59
  }
52
60
 
53
61
  /**
@@ -152,7 +160,7 @@ export interface ExecutionOptionsSnapshot {
152
160
  * (revision/scheduler/power); a full snapshot also carries the deployment
153
161
  * constants the UI reads (session default permission, subtask depth).
154
162
  */
155
- export type HostMirror = Pick<TaskBoardSnapshot, 'revision' | 'scheduler' | 'power' | 'sessionDefaultPermission' | 'maxSubtaskDepth' | 'goalRunEnabled' | 'cardDefaults' | 'extensions'>
163
+ export type HostMirror = Pick<TaskBoardSnapshot, 'revision' | 'scheduler' | 'power' | 'sessionDefaultPermission' | 'maxSubtaskDepth' | 'goalRunEnabled' | 'cardDefaults' | 'extensions' | 'attachmentLimits'>
156
164
 
157
165
  /** Immutable controller snapshot for UI subscriptions. */
158
166
  export interface ControllerSnapshot {
@@ -177,6 +185,8 @@ export interface ControllerSnapshot {
177
185
  * hand-built snapshot (tests, a shell-less composition) defaults to visible.
178
186
  */
179
187
  visibility?: readonly TaskBoardVisibilityPredicate[]
188
+ /** Provider source-group selectors, in registration order; browser-only functions. */
189
+ grouping?: readonly TaskBoardGroupingSelector[]
180
190
  /** Read-only summaries published by running extensions, keyed by extension id. */
181
191
  extensions?: Readonly<Record<string, unknown>>
182
192
  }
@@ -228,6 +238,8 @@ export class BoardController {
228
238
  private hostState: HostMirror | undefined
229
239
  /** Provider visibility predicates (immutable array; replaced on change). */
230
240
  private visibility: readonly TaskBoardVisibilityPredicate[] = []
241
+ /** Provider source-group selectors (immutable array; replaced on change). */
242
+ private grouping: readonly TaskBoardGroupingSelector[] = []
231
243
  private remoteSubscribed = false
232
244
  private remoteInitialization: Promise<boolean> | undefined
233
245
 
@@ -279,6 +291,7 @@ export class BoardController {
279
291
  ...(this.transportError === undefined ? {} : { transportError: this.transportError }),
280
292
  ...(this.hostState === undefined ? {} : { host: this.hostState }),
281
293
  visibility: this.visibility,
294
+ grouping: this.grouping,
282
295
  ...(this.hostState?.extensions === undefined ? {} : { extensions: this.hostState.extensions }),
283
296
  }
284
297
  }
@@ -298,6 +311,18 @@ export class BoardController {
298
311
  }
299
312
  }
300
313
 
314
+ /** Register one source-group selector; registration order breaks ownership ties. */
315
+ registerGrouping(selector: TaskBoardGroupingSelector): () => void {
316
+ this.grouping = [...this.grouping, selector]
317
+ this.notify()
318
+ return () => {
319
+ const next = this.grouping.filter(candidate => candidate !== selector)
320
+ if (next.length === this.grouping.length) return
321
+ this.grouping = next
322
+ this.notify()
323
+ }
324
+ }
325
+
301
326
  /**
302
327
  * Deliver one provider action through the board's same-origin channel. A
303
328
  * board without a Host transport (the legacy in-memory path) refuses it.
@@ -512,6 +537,23 @@ export class BoardController {
512
537
  return await parse.call(transport, request, signal)
513
538
  }
514
539
 
540
+ /**
541
+ * Upload one attachment into the Host's attachment storage.
542
+ *
543
+ * The form calls this when the card is SAVED, never when a file is picked:
544
+ * a staged file is a local preview until the card is really saved.
545
+ * @param file - the picked file.
546
+ * @param kind - whether the file is stored as an image or verbatim.
547
+ * @returns the metadata the Host computed, or undefined when this
548
+ * deployment serves no attachment storage.
549
+ */
550
+ async uploadAttachment(file: File, kind: TaskAttachmentKind): Promise<TaskAttachment | undefined> {
551
+ const transport = this.deps.transport
552
+ const upload = transport?.uploadAttachment
553
+ if (transport === undefined || upload === undefined) return undefined
554
+ return await upload.call(transport, file, kind)
555
+ }
556
+
515
557
  moveTask(id: string, status: TaskStatus): void {
516
558
  if (this.deps.transport !== undefined) {
517
559
  void this.commitRemote({ kind: 'move', taskId: id, status }, id)
@@ -850,6 +892,9 @@ export class BoardController {
850
892
  // is the mirror image of the staleness this key is re-read for.
851
893
  const cardDefaults = snapshot.cardDefaults
852
894
  const extensions = snapshot.extensions ?? this.hostState?.extensions
895
+ // The attachment limits are carried over: a deployment that lowers them
896
+ // must keep the browser's refusal in step until the next snapshot.
897
+ const attachmentLimits = snapshot.attachmentLimits ?? this.hostState?.attachmentLimits
853
898
  return {
854
899
  revision: snapshot.revision,
855
900
  scheduler: snapshot.scheduler,
@@ -859,6 +904,7 @@ export class BoardController {
859
904
  ...(goalRunEnabled === undefined ? {} : { goalRunEnabled }),
860
905
  ...(cardDefaults === undefined ? {} : { cardDefaults }),
861
906
  ...(extensions === undefined ? {} : { extensions }),
907
+ ...(attachmentLimits === undefined ? {} : { attachmentLimits }),
862
908
  }
863
909
  }
864
910
 
@@ -47,6 +47,14 @@ export const TASK_BOARD_EXTENSION_SEATS: readonly string[] = [
47
47
  */
48
48
  export const TASK_BOARD_PAYLOAD_LIMIT_BYTES = 64 * 1024
49
49
 
50
+ /**
51
+ * Largest accepted free text a provider pushes into an execution, in
52
+ * characters: one follow-up message, or one set of rework instructions. Both
53
+ * reach a model as user input, so the bound keeps a single provider call from
54
+ * becoming an unbounded context injection.
55
+ */
56
+ export const TASK_BOARD_MESSAGE_MAX_LENGTH = 4_000
57
+
50
58
  /** Depth beyond which a payload is refused instead of walked. */
51
59
  const PAYLOAD_DEPTH_LIMIT = 64
52
60
 
@@ -161,6 +169,26 @@ export interface TaskBoardTaskDraft {
161
169
  * no reason to know better pins nothing.
162
170
  */
163
171
  workspaceId?: string
172
+ /**
173
+ * Agent preset the created card pins as its execution composition. Absent
174
+ * pins nothing and leaves the board's own resolution in charge. The value is
175
+ * forwarded to the board's creation path unchanged, so a preset this
176
+ * deployment does not register fails the RUN closed, exactly as it does for a
177
+ * card created anywhere else.
178
+ */
179
+ mode?: string
180
+ /**
181
+ * Model the created card pins, in `provider/model` form — the same field
182
+ * `task_board_create` takes. Resolved against the host catalog at launch, so
183
+ * an unknown route is a run-time answer, not a creation-time one.
184
+ */
185
+ model?: string
186
+ /**
187
+ * Reasoning level for the pinned {@link model}. It travels with the model it
188
+ * was chosen for: the board never applies a level to a route that does not
189
+ * declare it.
190
+ */
191
+ reasoningEffort?: string
164
192
  }
165
193
 
166
194
  /** Options of {@link TaskBoardTasksFace.create}. */
@@ -201,6 +229,42 @@ export interface TaskBoardTasksFace {
201
229
  setStatus(taskId: string, status: TaskStatus, initiator?: string): void
202
230
  /** Every task carrying this extension's payload. */
203
231
  linked(): readonly TaskBoardLinkedTask[]
232
+ /**
233
+ * Run a card that already executed again — in its ORIGINAL session — with
234
+ * `instructions` carried as this run's additional input, which is how a
235
+ * reviewer sends work back rather than asking for a fresh attempt. The
236
+ * instructions are recorded on the execution the request opens, so the run
237
+ * history says why that run exists.
238
+ *
239
+ * The request passes through every run gate the board already has — the
240
+ * running lock, the permission confirmation, the acceptance contract and the
241
+ * spend cap — and it never rewrites the card: an executed card's frozen
242
+ * title, description and prompt stay exactly what ran (see
243
+ * {@link TaskBoardTasksFace.patchContent}). A card that never executed, or
244
+ * whose session cannot be continued, is refused instead of quietly starting a
245
+ * conversation the caller never saw.
246
+ *
247
+ * Optional, like {@link TaskBoardExtensionHost.sessions}: the contract
248
+ * version stays 1, so a provider checks the face before using it.
249
+ */
250
+ rework?(taskId: string, instructions: string, initiator?: string): void
251
+ }
252
+
253
+ /**
254
+ * Execution-session face: what a provider delivers INTO a run the board
255
+ * already executed or is executing now.
256
+ */
257
+ export interface TaskBoardSessionsFace {
258
+ /**
259
+ * Queue one follow-up user message into the session of the card's current
260
+ * execution, or of its most recent one when no execution is open.
261
+ *
262
+ * The message is an ordinary user turn queued behind whatever that session is
263
+ * doing; it re-asserts nothing, so the execution's permission, model and
264
+ * preset stay the ones the run froze. A card that never executed, an archived
265
+ * card, and a session the host no longer reaches are refused.
266
+ */
267
+ followUp(taskId: string, text: string): Promise<void>
204
268
  }
205
269
 
206
270
  /** Storage face for one extension's own payload on a task. */
@@ -254,6 +318,12 @@ export interface TaskBoardEventFace {
254
318
  */
255
319
  export interface TaskBoardExtensionHost {
256
320
  tasks: TaskBoardTasksFace
321
+ /**
322
+ * Delivery into a card's execution session. Optional in the contract on
323
+ * purpose: the API version stays 1, so a provider built against this revision
324
+ * probes the face and keeps working against a board that serves none.
325
+ */
326
+ sessions?: TaskBoardSessionsFace
257
327
  integration: TaskBoardIntegrationFace
258
328
  events: TaskBoardEventFace
259
329
  /**
@@ -294,6 +364,17 @@ export interface TaskBoardClientMirror {
294
364
  /** Whether a task should be shown on the board; false hides it. */
295
365
  export type TaskBoardVisibilityPredicate = (task: TaskRecord) => boolean
296
366
 
367
+ /** Generic source bucket a provider assigns to one card. */
368
+ export interface TaskBoardSourceGroup {
369
+ /** Stable, provider-namespaced identity used for ordering and fold persistence. */
370
+ id: string
371
+ /** Full human-readable source label, such as an owner/repository pair. */
372
+ label: string
373
+ }
374
+
375
+ /** Return a card's source group, or undefined when this provider does not own it. */
376
+ export type TaskBoardGroupingSelector = (task: TaskRecord) => TaskBoardSourceGroup | undefined
377
+
297
378
  /**
298
379
  * Client capability face the board's browser half provides. A provider's
299
380
  * browser half resolves it from the shared cordis service name; it never
@@ -304,6 +385,11 @@ export interface TaskBoardClientFace {
304
385
  dispatch(request: TaskBoardExtensionActionRequest): Promise<boolean>
305
386
  /** Register one card visibility predicate; the returned disposer removes it. */
306
387
  registerVisibility(predicate: TaskBoardVisibilityPredicate): () => void
388
+ /**
389
+ * Register one source-group selector; the first selector returning a group
390
+ * wins. Optional so an older board can serve the same API version.
391
+ */
392
+ registerGrouping?(selector: TaskBoardGroupingSelector): () => void
307
393
  /** Subscribe to the board mirror. */
308
394
  subscribe(callback: (mirror: TaskBoardClientMirror) => void): () => void
309
395
  /** Read the current board mirror. */
@@ -20,13 +20,19 @@ import type { ExecutionRecord, TaskRecord } from './tasks.ts'
20
20
  * @param task - the task about to run.
21
21
  * @param idleSessionIds - ids the last roster saw as present and not running;
22
22
  * undefined when that roster is unknown.
23
+ * @param options.force - continue the settled session regardless of the card's
24
+ * own `reuseSession` opt-in. A rework is exactly that case: the reviewer read
25
+ * the previous run's session and sent it back. Every condition above still
26
+ * applies — the force waives the opt-in, never the evidence.
23
27
  * @returns the session id to continue in, or undefined for a fresh session.
24
28
  */
25
29
  export function reusableSessionId(
26
30
  task: TaskRecord,
27
31
  idleSessionIds: ReadonlySet<string> | undefined,
32
+ options: { force?: boolean } = {},
28
33
  ): string | undefined {
29
- if (task.reuseSession !== true || idleSessionIds === undefined) return undefined
34
+ if (options.force !== true && task.reuseSession !== true) return undefined
35
+ if (idleSessionIds === undefined) return undefined
30
36
  let last: ExecutionRecord | undefined
31
37
  for (let index = task.executions.length - 1; index >= 0; index -= 1) {
32
38
  const candidate = task.executions[index]
package/src/core/store.ts CHANGED
@@ -10,13 +10,14 @@
10
10
  * localStorage backend.
11
11
  */
12
12
  import { isValidCron, isValidTimeZone } from './schedule.ts'
13
- import { SCHEDULE_STOP_REASONS, isTaskPermission, isTaskStatus, normalizeTags, normalizeTargetId, type ScheduleRule, type ScheduleStopReason, type TaskFreeze, type TaskRecord, type TaskPermission, type TaskStatus } from './tasks.ts'
13
+ import { SCHEDULE_STOP_REASONS, isTaskPermission, isTaskStatus, normalizeExecutionRework, normalizeTags, normalizeTargetId, type ScheduleRule, type ScheduleStopReason, type TaskFreeze, type TaskRecord, type TaskPermission, type TaskStatus } from './tasks.ts'
14
14
  import { isExecutionOutcome } from './subtask.ts'
15
15
  import { normalizeExecutionSummary } from './execution-summary.ts'
16
16
  import type { TaskHandover } from './handover.ts'
17
17
  import { sanitizeFreezeSnapshot } from './freeze-snapshot.ts'
18
18
  import { sanitizeHandover } from './handover.ts'
19
19
  import { normalizeTaskIntegrations } from './extension.ts'
20
+ import { normalizeAttachments } from './attachment.ts'
20
21
  import { normalizeVerification } from './verification.ts'
21
22
 
22
23
  /** Persistence seam for the task ledger. */
@@ -73,6 +74,7 @@ function isTaskRecordShape(value: unknown): value is Omit<TaskRecord, 'status'>
73
74
  if (record.permission !== undefined && typeof record.permission !== 'string') return false
74
75
  if (record.integrations !== undefined && (typeof record.integrations !== 'object' || record.integrations === null || Array.isArray(record.integrations))) return false
75
76
  if (record.hidden !== undefined && typeof record.hidden !== 'boolean') return false
77
+ if (record.attachments !== undefined && !Array.isArray(record.attachments)) return false
76
78
  if (record.reuseSession !== undefined && typeof record.reuseSession !== 'boolean') return false
77
79
  if (record.goalRun !== undefined && typeof record.goalRun !== 'boolean') return false
78
80
  if (record.skipVerification !== undefined && typeof record.skipVerification !== 'boolean') return false
@@ -263,6 +265,9 @@ export function parseLedger(raw: string | null): TaskRecord[] {
263
265
  // A malformed acceptance block is dropped rather than dropping the
264
266
  // execution record: the board then treats that run as unverified.
265
267
  verification: normalizeVerification(execution.verification),
268
+ // A malformed rework block is dropped on the same terms: the run itself
269
+ // is what the history is for, and only its instructions are unrecoverable.
270
+ rework: normalizeExecutionRework(execution.rework),
266
271
  external: execution.external === true ? true : undefined,
267
272
  }))
268
273
  // Execution targets are normalized like the schedule: blank strings
@@ -291,6 +296,10 @@ export function parseLedger(raw: string | null): TaskRecord[] {
291
296
  task.tags = normalizeTags(row.tags)
292
297
  task.permissionConfirmedAt = typeof row.permissionConfirmedAt === 'number' && Number.isFinite(row.permissionConfirmedAt) ? row.permissionConfirmedAt : undefined
293
298
  task.integrations = normalizeTaskIntegrations(row.integrations)
299
+ // Attachments are repaired field by field like the tags: a malformed entry
300
+ // is dropped, and a list that repairs to nothing clears the field instead
301
+ // of dropping the task row.
302
+ task.attachments = normalizeAttachments(row.attachments)
294
303
  task.hidden = row.hidden === true ? true : undefined
295
304
  tasks.push(task)
296
305
  }