@fish-under-sea/dsh-client-ui-task-board-fish 1.0.2 → 2.0.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/NOTICE +1 -1
- package/README.en.md +6 -4
- package/README.md +6 -4
- package/README.zh.md +6 -4
- package/icon.png +0 -0
- package/lib/client.js +4428 -1508
- package/lib/client.js.map +1 -1
- package/lib/index.js +2670 -496
- package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
- package/lib/types/client/PluginSettingsCard.d.ts +130 -19
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +63 -0
- package/lib/types/client/board/AttachmentField.d.ts +70 -0
- package/lib/types/client/board/ExecutionLog.d.ts +24 -0
- package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
- package/lib/types/client/board/TaskForm.d.ts +4 -0
- package/lib/types/client/board/VerificationReport.d.ts +2 -15
- package/lib/types/client/board/model-options.d.ts +87 -0
- package/lib/types/client/board/preset-label.d.ts +21 -0
- package/lib/types/client/board/preset-roster.d.ts +45 -0
- package/lib/types/client/board/source-group.d.ts +27 -0
- package/lib/types/client/body-mutations.d.ts +45 -0
- package/lib/types/client/host-api.d.ts +25 -0
- package/lib/types/client/locales.d.ts +87 -9
- package/lib/types/client/pending-verify.d.ts +47 -0
- package/lib/types/client/plugin-card-seat.d.ts +3 -1
- package/lib/types/client/service.d.ts +4 -1
- package/lib/types/client/settings-form.d.ts +73 -51
- package/lib/types/core/attachment.d.ts +132 -0
- package/lib/types/core/card-defaults.d.ts +78 -0
- package/lib/types/core/controller.d.ts +57 -8
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +116 -0
- package/lib/types/core/launch-width.d.ts +31 -0
- package/lib/types/core/reasoning-effort.d.ts +57 -0
- package/lib/types/core/session-reuse.d.ts +7 -1
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/subtask.d.ts +100 -37
- package/lib/types/core/tasks.d.ts +94 -10
- package/lib/types/core/use-cases/task-create.d.ts +10 -5
- package/lib/types/core/use-cases/task-tag.d.ts +36 -0
- package/lib/types/core/use-cases/task-update.d.ts +22 -1
- package/lib/types/core/wire-projection.d.ts +35 -0
- package/lib/types/core/workspace-target.d.ts +23 -3
- package/lib/types/host/attachments.d.ts +250 -0
- package/lib/types/host/extension-registry.d.ts +40 -0
- package/lib/types/host/launch-admission.d.ts +71 -0
- package/lib/types/host-ledger.d.ts +114 -47
- package/lib/types/host-routes.d.ts +63 -0
- package/lib/types/host-runner.d.ts +164 -18
- package/lib/types/host-service.d.ts +182 -46
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +173 -54
- package/lib/types/loopback.d.ts +41 -1
- package/lib/types/protocol.d.ts +52 -11
- package/lib/types/tool-surface.d.ts +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +36 -29
- package/src/client/CardDefaultPresetField.tsx +101 -0
- package/src/client/PluginSettingsCard.tsx +385 -111
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/TaskBoardSettingsCard.tsx +332 -37
- package/src/client/board/AttachmentField.tsx +383 -0
- package/src/client/board/EditTaskModal.tsx +63 -0
- package/src/client/board/ExecutionLog.tsx +154 -0
- package/src/client/board/LinkSubtaskModal.tsx +1 -1
- package/src/client/board/NewTaskModal.tsx +154 -45
- package/src/client/board/ReasoningEffortField.tsx +50 -0
- package/src/client/board/TagManagerModal.tsx +151 -2
- package/src/client/board/TaskBoard.tsx +47 -10
- package/src/client/board/TaskCard.tsx +45 -23
- package/src/client/board/TaskDetail.tsx +468 -258
- package/src/client/board/TaskForm.tsx +19 -4
- package/src/client/board/VerificationReport.tsx +143 -104
- package/src/client/board/model-options.ts +208 -0
- package/src/client/board/preset-label.ts +32 -0
- package/src/client/board/preset-roster.ts +58 -0
- package/src/client/board/source-group.ts +94 -0
- package/src/client/board/task-markdown.module.css +11 -8
- package/src/client/board-settings.module.css +35 -7
- package/src/client/board.module.css +1044 -105
- package/src/client/body-mutations.ts +133 -0
- package/src/client/host-api.ts +70 -0
- package/src/client/index.ts +109 -95
- package/src/client/locales.ts +205 -48
- package/src/client/pending-verify.ts +90 -0
- package/src/client/plugin-card-seat.ts +8 -2
- package/src/client/service.ts +24 -0
- package/src/client/settings-card.module.css +466 -89
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/settings-form.ts +102 -60
- package/src/core/attachment.ts +287 -0
- package/src/core/card-defaults.ts +132 -0
- package/src/core/controller.ts +90 -11
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +120 -0
- package/src/core/launch-width.ts +38 -0
- package/src/core/reasoning-effort.ts +92 -0
- package/src/core/session-reuse.ts +7 -1
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +19 -1
- package/src/core/subtask.ts +144 -68
- package/src/core/tasks.ts +117 -10
- package/src/core/use-cases/task-create.ts +27 -16
- package/src/core/use-cases/task-tag.ts +56 -0
- package/src/core/use-cases/task-update.ts +33 -5
- package/src/core/wire-projection.ts +81 -0
- package/src/core/workspace-target.ts +27 -3
- package/src/host/agent-tools.ts +33 -21
- package/src/host/attachments.ts +650 -0
- package/src/host/extension-registry.ts +150 -5
- package/src/host/launch-admission.ts +139 -0
- package/src/host-ledger.ts +248 -117
- package/src/host-routes.ts +233 -15
- package/src/host-runner.ts +395 -61
- package/src/host-service.ts +512 -139
- package/src/host-spend.ts +105 -0
- package/src/index.ts +312 -92
- package/src/loopback.ts +57 -1
- package/src/protocol.ts +83 -18
- package/src/tool-surface.ts +1 -0
- package/icon.svg +0 -3
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The attachment field of the create and edit forms.
|
|
3
|
+
*
|
|
4
|
+
* A file the user picks is STAGED locally first: the form shows a preview,
|
|
5
|
+
* the name and the size, and nothing leaves the browser until the card is
|
|
6
|
+
* saved. The upload therefore happens on save, not on selection — a card the
|
|
7
|
+
* user abandons never leaves a stored object behind.
|
|
8
|
+
*
|
|
9
|
+
* Three input modes are supported: drag and drop, paste, and the file picker.
|
|
10
|
+
* All three end in the same staged list.
|
|
11
|
+
*/
|
|
12
|
+
import { useEffect, useRef, useState } from 'react'
|
|
13
|
+
import {
|
|
14
|
+
TASK_ATTACHMENT_IMAGE_MEDIA_TYPES,
|
|
15
|
+
TASK_ATTACHMENT_LIMIT,
|
|
16
|
+
TASK_ATTACHMENT_MAX_BYTES,
|
|
17
|
+
TASK_ATTACHMENT_TOTAL_MAX_BYTES,
|
|
18
|
+
type TaskAttachment,
|
|
19
|
+
type TaskAttachmentKind,
|
|
20
|
+
} from '../../core/attachment.ts'
|
|
21
|
+
import { attachmentImageUrl } from '../host-api.ts'
|
|
22
|
+
import { t } from '../locales.ts'
|
|
23
|
+
import css from '../board.module.css'
|
|
24
|
+
import { IconClose } from './icons.tsx'
|
|
25
|
+
|
|
26
|
+
/** One file the user staged locally; it is uploaded when the card is saved. */
|
|
27
|
+
export interface StagedAttachment {
|
|
28
|
+
/** Stable id of the staged row (a monotonic counter, never a clock reading). */
|
|
29
|
+
id: string
|
|
30
|
+
/** The picked file. */
|
|
31
|
+
file: File
|
|
32
|
+
/** Whether the file is uploaded as an image or as a verbatim file. */
|
|
33
|
+
kind: TaskAttachmentKind
|
|
34
|
+
/** Display name of the file. */
|
|
35
|
+
name: string
|
|
36
|
+
/** Byte length of the file. */
|
|
37
|
+
bytes: number
|
|
38
|
+
/** Declared media type of the file. */
|
|
39
|
+
mediaType: string
|
|
40
|
+
/** Local object URL of the preview; images only. */
|
|
41
|
+
previewUrl?: string
|
|
42
|
+
/** True while the file is being uploaded. */
|
|
43
|
+
pending?: boolean
|
|
44
|
+
/** Why the upload failed, when it did. */
|
|
45
|
+
error?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What the card will carry once the form is saved. */
|
|
49
|
+
export interface AttachmentSelection {
|
|
50
|
+
/** The attachments already stored on the card and kept by the user. */
|
|
51
|
+
persisted: TaskAttachment[]
|
|
52
|
+
/** The files staged locally and uploaded on save. */
|
|
53
|
+
staged: StagedAttachment[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The limits the deployment publishes for attachments. */
|
|
57
|
+
export interface AttachmentLimits {
|
|
58
|
+
maxAttachments: number
|
|
59
|
+
maxBytes: number
|
|
60
|
+
maxTotalBytes: number
|
|
61
|
+
/** Maximum number of IMAGES one card may carry (the official per-message budget). */
|
|
62
|
+
maxImages: number
|
|
63
|
+
/** Maximum byte length of one image. */
|
|
64
|
+
maxImageBytes: number
|
|
65
|
+
/** Maximum byte length of all images of one card together. */
|
|
66
|
+
maxMessageImageBytes: number
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The board's own limits, used when the deployment publishes none. */
|
|
70
|
+
export const DEFAULT_ATTACHMENT_LIMITS: AttachmentLimits = {
|
|
71
|
+
maxAttachments: TASK_ATTACHMENT_LIMIT,
|
|
72
|
+
maxBytes: TASK_ATTACHMENT_MAX_BYTES,
|
|
73
|
+
maxTotalBytes: TASK_ATTACHMENT_TOTAL_MAX_BYTES,
|
|
74
|
+
maxImages: TASK_ATTACHMENT_LIMIT,
|
|
75
|
+
maxImageBytes: TASK_ATTACHMENT_MAX_BYTES,
|
|
76
|
+
maxMessageImageBytes: TASK_ATTACHMENT_TOTAL_MAX_BYTES,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A human-readable byte size. */
|
|
80
|
+
export function formatAttachmentBytes(bytes: number): string {
|
|
81
|
+
if (bytes < 1024) return `${bytes} B`
|
|
82
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KiB`
|
|
83
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Whether a picked file is uploaded as an image.
|
|
88
|
+
*
|
|
89
|
+
* Only the raster types the official image path accepts are images; every
|
|
90
|
+
* other file is stored verbatim.
|
|
91
|
+
*/
|
|
92
|
+
export function attachmentKindOf(file: File): TaskAttachmentKind {
|
|
93
|
+
const type = file.type.toLowerCase()
|
|
94
|
+
return TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(type as typeof TASK_ATTACHMENT_IMAGE_MEDIA_TYPES[number])
|
|
95
|
+
? 'image'
|
|
96
|
+
: 'file'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** One row of the attachment list: a stored attachment or a staged file. */
|
|
100
|
+
interface AttachmentRow {
|
|
101
|
+
/** Stable key of the row. */
|
|
102
|
+
key: string
|
|
103
|
+
/** The stored attachment, when the row shows one. */
|
|
104
|
+
attachment?: TaskAttachment
|
|
105
|
+
/** The staged file, when the row shows one. */
|
|
106
|
+
staged?: StagedAttachment
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The byte total of a selection: the stored attachments plus the staged files. */
|
|
110
|
+
function totalBytesOf(selection: AttachmentSelection): number {
|
|
111
|
+
return selection.persisted.reduce((sum, attachment) => sum + attachment.bytes, 0)
|
|
112
|
+
+ selection.staged.reduce((sum, staged) => sum + staged.bytes, 0)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The byte total of the IMAGES of a selection. */
|
|
116
|
+
function imageBytesOf(selection: AttachmentSelection): number {
|
|
117
|
+
return selection.persisted
|
|
118
|
+
.filter(attachment => attachment.kind === 'image')
|
|
119
|
+
.reduce((sum, attachment) => sum + attachment.bytes, 0)
|
|
120
|
+
+ selection.staged
|
|
121
|
+
.filter(staged => staged.kind === 'image')
|
|
122
|
+
.reduce((sum, staged) => sum + staged.bytes, 0)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The number of IMAGES of a selection. */
|
|
126
|
+
function imageCountOf(selection: AttachmentSelection): number {
|
|
127
|
+
return selection.persisted.filter(attachment => attachment.kind === 'image').length
|
|
128
|
+
+ selection.staged.filter(staged => staged.kind === 'image').length
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The staged files the form already holds.
|
|
133
|
+
*
|
|
134
|
+
* The identity is the File OBJECT, never its metadata: two different files can
|
|
135
|
+
* share a name, a size, a type and a modification time, and inferring byte
|
|
136
|
+
* identity from those four would silently discard one of them. The form
|
|
137
|
+
* therefore stages every distinct File it is handed.
|
|
138
|
+
*
|
|
139
|
+
* The content identity that actually matters — the storage identifier the Host
|
|
140
|
+
* answers with — is applied AFTER the upload, where it is authoritative
|
|
141
|
+
* (see the core dedupe). The only case the form skips is the very same File
|
|
142
|
+
* object handed over twice, which is the same row twice.
|
|
143
|
+
*/
|
|
144
|
+
function stagedFileSet(staged: readonly StagedAttachment[]): Set<File> {
|
|
145
|
+
return new Set(staged.map(entry => entry.file))
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* The attachment field of a card form.
|
|
150
|
+
*
|
|
151
|
+
* The component owns the local staging only: the selection it reports is what
|
|
152
|
+
* the card will carry, and the parent uploads the staged files on save.
|
|
153
|
+
*/
|
|
154
|
+
export function AttachmentField({
|
|
155
|
+
selection,
|
|
156
|
+
onChange,
|
|
157
|
+
limits,
|
|
158
|
+
disabled = false,
|
|
159
|
+
onError,
|
|
160
|
+
}: {
|
|
161
|
+
/** What the card currently carries and what is staged on top of it. */
|
|
162
|
+
selection: AttachmentSelection
|
|
163
|
+
/** Receives the new selection after every change. */
|
|
164
|
+
onChange: (selection: AttachmentSelection) => void
|
|
165
|
+
/** The deployment limits; the board's own limits are used when absent. */
|
|
166
|
+
limits?: AttachmentLimits
|
|
167
|
+
/** Whether the field refuses new input. */
|
|
168
|
+
disabled?: boolean
|
|
169
|
+
/** Receives the reason a selection was refused. */
|
|
170
|
+
onError?: (message: string) => void
|
|
171
|
+
}) {
|
|
172
|
+
const effective = limits ?? DEFAULT_ATTACHMENT_LIMITS
|
|
173
|
+
const inputRef = useRef<HTMLInputElement | null>(null)
|
|
174
|
+
const objectUrls = useRef<string[]>([])
|
|
175
|
+
const counter = useRef(0)
|
|
176
|
+
const [dragging, setDragging] = useState(false)
|
|
177
|
+
|
|
178
|
+
// The object URLs belong to this component: they are released when the form
|
|
179
|
+
// closes, so a discarded card leaves no preview behind.
|
|
180
|
+
useEffect(() => () => {
|
|
181
|
+
for (const url of objectUrls.current) URL.revokeObjectURL(url)
|
|
182
|
+
objectUrls.current = []
|
|
183
|
+
}, [])
|
|
184
|
+
|
|
185
|
+
const addFiles = (files: readonly File[]): void => {
|
|
186
|
+
if (disabled || files.length === 0) return
|
|
187
|
+
const staged = [...selection.staged]
|
|
188
|
+
// Only the very same File object is skipped: the browser hands the same
|
|
189
|
+
// object again when a picker reports one selection twice, and that is the
|
|
190
|
+
// one case where a second row would duplicate the first. Two DIFFERENT
|
|
191
|
+
// files that merely share their metadata are two files, and both stage.
|
|
192
|
+
const seen = stagedFileSet(staged)
|
|
193
|
+
let total = totalBytesOf(selection)
|
|
194
|
+
let imageBytes = imageBytesOf(selection)
|
|
195
|
+
let imageCount = imageCountOf(selection)
|
|
196
|
+
let added = 0
|
|
197
|
+
for (const file of files) {
|
|
198
|
+
if (seen.has(file)) continue
|
|
199
|
+
if (selection.persisted.length + staged.length >= effective.maxAttachments) {
|
|
200
|
+
onError?.(t('new.attachments.limitCount', { count: String(effective.maxAttachments) }))
|
|
201
|
+
break
|
|
202
|
+
}
|
|
203
|
+
const kind = attachmentKindOf(file)
|
|
204
|
+
const limit = kind === 'image'
|
|
205
|
+
? Math.min(effective.maxBytes, effective.maxImageBytes ?? effective.maxBytes)
|
|
206
|
+
: effective.maxBytes
|
|
207
|
+
if (file.size > limit) {
|
|
208
|
+
onError?.(t('new.attachments.limitSize', { name: file.name, size: formatAttachmentBytes(limit) }))
|
|
209
|
+
continue
|
|
210
|
+
}
|
|
211
|
+
if (total + file.size > effective.maxTotalBytes) {
|
|
212
|
+
onError?.(t('new.attachments.limitTotal', { size: formatAttachmentBytes(effective.maxTotalBytes) }))
|
|
213
|
+
break
|
|
214
|
+
}
|
|
215
|
+
// The official per-message image budget: the count of images and their
|
|
216
|
+
// total bytes are what one prompt carries.
|
|
217
|
+
if (kind === 'image') {
|
|
218
|
+
if (imageCount + 1 > effective.maxImages) {
|
|
219
|
+
onError?.(t('new.attachments.limitImages', { count: String(effective.maxImages) }))
|
|
220
|
+
break
|
|
221
|
+
}
|
|
222
|
+
if (imageBytes + file.size > effective.maxMessageImageBytes) {
|
|
223
|
+
onError?.(t('new.attachments.limitImageBytes', { size: formatAttachmentBytes(effective.maxMessageImageBytes) }))
|
|
224
|
+
break
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
const previewUrl = kind === 'image' && typeof URL.createObjectURL === 'function'
|
|
228
|
+
? URL.createObjectURL(file)
|
|
229
|
+
: undefined
|
|
230
|
+
if (previewUrl !== undefined) objectUrls.current.push(previewUrl)
|
|
231
|
+
counter.current += 1
|
|
232
|
+
seen.add(file)
|
|
233
|
+
staged.push({
|
|
234
|
+
id: `staged-${counter.current}`,
|
|
235
|
+
file,
|
|
236
|
+
kind,
|
|
237
|
+
name: file.name,
|
|
238
|
+
bytes: file.size,
|
|
239
|
+
mediaType: file.type,
|
|
240
|
+
...(previewUrl === undefined ? {} : { previewUrl }),
|
|
241
|
+
})
|
|
242
|
+
total += file.size
|
|
243
|
+
if (kind === 'image') {
|
|
244
|
+
imageBytes += file.size
|
|
245
|
+
imageCount += 1
|
|
246
|
+
}
|
|
247
|
+
added += 1
|
|
248
|
+
}
|
|
249
|
+
if (added > 0) onChange({ ...selection, staged })
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const removeStaged = (id: string): void => {
|
|
253
|
+
const target = selection.staged.find(staged => staged.id === id)
|
|
254
|
+
if (target?.previewUrl !== undefined) {
|
|
255
|
+
URL.revokeObjectURL(target.previewUrl)
|
|
256
|
+
objectUrls.current = objectUrls.current.filter(url => url !== target.previewUrl)
|
|
257
|
+
}
|
|
258
|
+
onChange({ ...selection, staged: selection.staged.filter(staged => staged.id !== id) })
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const removePersisted = (attachmentId: string): void => {
|
|
262
|
+
onChange({
|
|
263
|
+
...selection,
|
|
264
|
+
persisted: selection.persisted.filter(attachment => attachment.attachmentId !== attachmentId),
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// One row per attachment: the stored ones and the staged files, in the
|
|
269
|
+
// order the user sees them.
|
|
270
|
+
const rows: AttachmentRow[] = [
|
|
271
|
+
...selection.persisted.map(attachment => ({ key: attachment.attachmentId, attachment })),
|
|
272
|
+
...selection.staged.map(staged => ({ key: staged.id, staged })),
|
|
273
|
+
]
|
|
274
|
+
|
|
275
|
+
return (
|
|
276
|
+
<div className={css.field} data-dsh-part="form-section">
|
|
277
|
+
<span className={css.fieldLabel}>{t('new.attachments')}</span>
|
|
278
|
+
<span className={css.fieldHint}>{t('new.attachmentsHint')}</span>
|
|
279
|
+
<div
|
|
280
|
+
className={css.attachmentDrop}
|
|
281
|
+
// A disabled field is not styled as a drop target: the drag state is
|
|
282
|
+
// the field's own, and a field that refuses input must not invite it.
|
|
283
|
+
data-state={dragging && !disabled ? 'active' : undefined}
|
|
284
|
+
data-disabled={disabled ? 'true' : undefined}
|
|
285
|
+
// The region is focusable and keyboard-operable: Enter or Space opens
|
|
286
|
+
// the picker. The button inside it owns its own activation, so a key
|
|
287
|
+
// press there is not handled twice. A DISABLED field leaves the tab
|
|
288
|
+
// order and says so, instead of staying focusable and inert.
|
|
289
|
+
tabIndex={disabled ? -1 : 0}
|
|
290
|
+
aria-disabled={disabled ? true : undefined}
|
|
291
|
+
aria-label={t('new.attachments.drop')}
|
|
292
|
+
onKeyDown={event => {
|
|
293
|
+
if (disabled) return
|
|
294
|
+
if (event.target !== event.currentTarget) return
|
|
295
|
+
if (event.key !== 'Enter' && event.key !== ' ') return
|
|
296
|
+
event.preventDefault()
|
|
297
|
+
inputRef.current?.click()
|
|
298
|
+
}}
|
|
299
|
+
onDragOver={event => {
|
|
300
|
+
event.preventDefault()
|
|
301
|
+
if (disabled) return
|
|
302
|
+
setDragging(true)
|
|
303
|
+
}}
|
|
304
|
+
onDragLeave={() => { if (!disabled) setDragging(false) }}
|
|
305
|
+
onDrop={event => {
|
|
306
|
+
event.preventDefault()
|
|
307
|
+
setDragging(false)
|
|
308
|
+
addFiles(Array.from(event.dataTransfer?.files ?? []))
|
|
309
|
+
}}
|
|
310
|
+
onPaste={event => {
|
|
311
|
+
const files = Array.from(event.clipboardData?.files ?? [])
|
|
312
|
+
if (files.length === 0) return
|
|
313
|
+
event.preventDefault()
|
|
314
|
+
addFiles(files)
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
<span className={css.attachmentDropHint}>{t('new.attachments.drop')}</span>
|
|
318
|
+
<input
|
|
319
|
+
ref={inputRef}
|
|
320
|
+
type="file"
|
|
321
|
+
multiple
|
|
322
|
+
hidden
|
|
323
|
+
// A disabled field cannot be opened, so the picker itself is
|
|
324
|
+
// disabled: the region never opens a picker it must not open.
|
|
325
|
+
disabled={disabled}
|
|
326
|
+
onChange={event => {
|
|
327
|
+
addFiles(Array.from(event.target.files ?? []))
|
|
328
|
+
event.target.value = ''
|
|
329
|
+
}}
|
|
330
|
+
/>
|
|
331
|
+
<button
|
|
332
|
+
type="button"
|
|
333
|
+
className={css.ghostButton}
|
|
334
|
+
disabled={disabled}
|
|
335
|
+
onClick={() => {
|
|
336
|
+
if (disabled) return
|
|
337
|
+
inputRef.current?.click()
|
|
338
|
+
}}
|
|
339
|
+
>
|
|
340
|
+
{t('new.attachments.pick')}
|
|
341
|
+
</button>
|
|
342
|
+
</div>
|
|
343
|
+
{rows.length > 0 && (
|
|
344
|
+
<ul className={css.attachmentList}>
|
|
345
|
+
{rows.map(row => (
|
|
346
|
+
<li className={css.attachmentRow} key={row.key}>
|
|
347
|
+
{row.attachment !== undefined && row.attachment.kind === 'image'
|
|
348
|
+
? <img className={css.attachmentThumb} src={attachmentImageUrl(row.attachment.attachmentId)} alt={row.attachment.name} />
|
|
349
|
+
: null}
|
|
350
|
+
{row.staged !== undefined && row.staged.kind === 'image' && row.staged.previewUrl !== undefined
|
|
351
|
+
? <img className={css.attachmentThumb} src={row.staged.previewUrl} alt={row.staged.name} />
|
|
352
|
+
: null}
|
|
353
|
+
<span className={css.attachmentName}>
|
|
354
|
+
{row.attachment?.name ?? row.staged?.name}
|
|
355
|
+
<span className={css.attachmentMeta}>
|
|
356
|
+
{' '}
|
|
357
|
+
{formatAttachmentBytes(row.attachment?.bytes ?? row.staged?.bytes ?? 0)}
|
|
358
|
+
{row.staged?.pending === true ? ` · ${t('new.attachments.uploading')}` : ''}
|
|
359
|
+
{row.staged?.error !== undefined ? ` · ${row.staged.error}` : ''}
|
|
360
|
+
</span>
|
|
361
|
+
</span>
|
|
362
|
+
<button
|
|
363
|
+
type="button"
|
|
364
|
+
className={css.iconButton}
|
|
365
|
+
// A pending submission owns the set it is about to send: the
|
|
366
|
+
// removal controls are disabled while it is in flight, so the
|
|
367
|
+
// submitted set cannot race a user edit.
|
|
368
|
+
disabled={disabled}
|
|
369
|
+
aria-label={t('new.attachments.remove', { name: row.attachment?.name ?? row.staged?.name ?? '' })}
|
|
370
|
+
onClick={() => {
|
|
371
|
+
if (row.attachment !== undefined) removePersisted(row.attachment.attachmentId)
|
|
372
|
+
else if (row.staged !== undefined) removeStaged(row.staged.id)
|
|
373
|
+
}}
|
|
374
|
+
>
|
|
375
|
+
<IconClose size={14} />
|
|
376
|
+
</button>
|
|
377
|
+
</li>
|
|
378
|
+
))}
|
|
379
|
+
</ul>
|
|
380
|
+
)}
|
|
381
|
+
</div>
|
|
382
|
+
)
|
|
383
|
+
}
|
|
@@ -10,7 +10,10 @@ import type { BoardController } from '../../core/controller.ts'
|
|
|
10
10
|
import { collectKnownTags, type TaskRecord, type TaskTag } from '../../core/tasks.ts'
|
|
11
11
|
import { t } from '../locales.ts'
|
|
12
12
|
import { ModalShell, TaskContentFields, TaskTagFields, cleanTags } from './TaskForm.tsx'
|
|
13
|
+
import { AttachmentField, type AttachmentSelection } from './AttachmentField.tsx'
|
|
14
|
+
import { dedupeAttachments, type TaskAttachment } from '../../core/attachment.ts'
|
|
13
15
|
import type { OverlayPhase } from './overlay.tsx'
|
|
16
|
+
import css from '../board.module.css'
|
|
14
17
|
|
|
15
18
|
/** Edit-task form overlay. */
|
|
16
19
|
export function EditTaskModal({ controller, task, onClose, phase }: { controller: BoardController; task: TaskRecord; onClose: () => void; phase?: OverlayPhase }) {
|
|
@@ -18,6 +21,13 @@ export function EditTaskModal({ controller, task, onClose, phase }: { controller
|
|
|
18
21
|
const [description, setDescription] = useState(task.description)
|
|
19
22
|
const [prompt, setPrompt] = useState(task.prompt)
|
|
20
23
|
const [tags, setTags] = useState<TaskTag[]>(task.tags ?? [])
|
|
24
|
+
// The card's attachments: the stored ones the user kept, plus the files
|
|
25
|
+
// staged locally. A staged file is uploaded when the card is SAVED.
|
|
26
|
+
const [attachments, setAttachments] = useState<AttachmentSelection>({
|
|
27
|
+
persisted: task.attachments ?? [],
|
|
28
|
+
staged: [],
|
|
29
|
+
})
|
|
30
|
+
const [attachmentError, setAttachmentError] = useState<string | undefined>(undefined)
|
|
21
31
|
const [error, setError] = useState<string | undefined>(undefined)
|
|
22
32
|
const [pending, setPending] = useState(false)
|
|
23
33
|
|
|
@@ -33,11 +43,41 @@ export function EditTaskModal({ controller, task, onClose, phase }: { controller
|
|
|
33
43
|
// carried one is not sent a clearing null: the wire stays minimal, and the
|
|
34
44
|
// no-tags path keeps producing exactly the patch it produced before.
|
|
35
45
|
const tagList = cleanTags(tags)
|
|
46
|
+
// The staged files are uploaded when the card is saved, never when they
|
|
47
|
+
// are picked: an abandoned edit leaves no stored object behind.
|
|
48
|
+
const uploaded: TaskAttachment[] = []
|
|
49
|
+
for (const staged of attachments.staged) {
|
|
50
|
+
setAttachments(current => markStaged(current, staged.id, { pending: true, error: undefined }))
|
|
51
|
+
try {
|
|
52
|
+
const attachment = await controller.uploadAttachment(staged.file, staged.kind)
|
|
53
|
+
if (attachment === undefined) throw new Error(t('new.attachments.unavailable'))
|
|
54
|
+
uploaded.push(attachment)
|
|
55
|
+
} catch (uploadError) {
|
|
56
|
+
const message = uploadError instanceof Error ? uploadError.message : String(uploadError)
|
|
57
|
+
setAttachments(current => markStaged(current, staged.id, { pending: false, error: message }))
|
|
58
|
+
setPending(false)
|
|
59
|
+
setError(message)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const carried = dedupeAttachments([...attachments.persisted, ...uploaded])
|
|
64
|
+
// The attachments ride the patch ONLY when the resulting ordered set
|
|
65
|
+
// differs from the card's current one: a title-only edit must not make
|
|
66
|
+
// the Host re-read and re-verify the stored objects, and it must still
|
|
67
|
+
// work in a deployment whose attachment storage is unavailable.
|
|
68
|
+
const current = task.attachments ?? []
|
|
69
|
+
const unchanged = current.length === carried.length
|
|
70
|
+
&& current.every((attachment, index) => attachment.attachmentId === carried[index]?.attachmentId)
|
|
36
71
|
const patch = {
|
|
37
72
|
title,
|
|
38
73
|
description,
|
|
39
74
|
prompt,
|
|
40
75
|
...(tagList.length > 0 ? { tags: tagList } : (task.tags === undefined ? {} : { tags: null })),
|
|
76
|
+
// An array REPLACES the stored set; an explicit null clears it. A card
|
|
77
|
+
// whose set did not change sends nothing at all.
|
|
78
|
+
...(unchanged
|
|
79
|
+
? {}
|
|
80
|
+
: (carried.length > 0 ? { attachments: carried } : { attachments: null })),
|
|
41
81
|
}
|
|
42
82
|
if (await controller.updateTask(task.id, patch)) {
|
|
43
83
|
onClose()
|
|
@@ -68,10 +108,33 @@ export function EditTaskModal({ controller, task, onClose, phase }: { controller
|
|
|
68
108
|
/>
|
|
69
109
|
|
|
70
110
|
<TaskTagFields tags={tags} knownTags={collectKnownTags(controller.getSnapshot().tasks)} onChange={setTags} />
|
|
111
|
+
|
|
112
|
+
<AttachmentField
|
|
113
|
+
selection={attachments}
|
|
114
|
+
onChange={setAttachments}
|
|
115
|
+
limits={controller.getSnapshot().host?.attachmentLimits}
|
|
116
|
+
disabled={pending}
|
|
117
|
+
onError={message => { setAttachmentError(message) }}
|
|
118
|
+
/>
|
|
119
|
+
{attachmentError !== undefined && <p className={css.formError}>{attachmentError}</p>}
|
|
71
120
|
</ModalShell>
|
|
72
121
|
)
|
|
73
122
|
}
|
|
74
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Mark one staged attachment row: the upload state and the failure reason.
|
|
126
|
+
*/
|
|
127
|
+
function markStaged(
|
|
128
|
+
selection: AttachmentSelection,
|
|
129
|
+
id: string,
|
|
130
|
+
patch: { pending?: boolean; error?: string },
|
|
131
|
+
): AttachmentSelection {
|
|
132
|
+
return {
|
|
133
|
+
...selection,
|
|
134
|
+
staged: selection.staged.map(staged => staged.id === id ? { ...staged, ...patch } : staged),
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
75
138
|
/** Edit-tags modal: edit labels only, shown for tasks after first execution. */
|
|
76
139
|
export function EditTagsModal({ controller, task, onClose, phase }: { controller: BoardController; task: TaskRecord; onClose: () => void; phase?: OverlayPhase }) {
|
|
77
140
|
const [tags, setTags] = useState<TaskTag[]>(task.tags ?? [])
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The execution history of one card.
|
|
3
|
+
*
|
|
4
|
+
* A card accumulates dozens of runs, and each run carried the full acceptance
|
|
5
|
+
* report inline: the same machine explanation repeated once per row buried the
|
|
6
|
+
* one row a reader needed. The history therefore renders newest first, keeps
|
|
7
|
+
* the five latest rows visible and puts the rest behind one disclosure that
|
|
8
|
+
* opens and closes as one motion pair (the presence hook keeps the extra rows
|
|
9
|
+
* mounted through the exit leg instead of pulling them out on the click's
|
|
10
|
+
* tick). Each row is two lines: identity on top (status, start/end in one
|
|
11
|
+
* format, the session jump) and the evidence the run produced underneath.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately adds no new `data-dsh-part` value: the part enum belongs to the
|
|
14
|
+
* cross-repository semantic-attribute contract.
|
|
15
|
+
*/
|
|
16
|
+
import { useId, useState } from 'react'
|
|
17
|
+
import type { ExecutionRecord } from '../../core/tasks.ts'
|
|
18
|
+
import { isLegacyAgentTeamsReason } from '../../core/subtask.ts'
|
|
19
|
+
import { isMissingWorkspaceReason } from '../../core/workspace-target.ts'
|
|
20
|
+
import { t, type TaskBoardKey } from '../locales.ts'
|
|
21
|
+
import css from '../board.module.css'
|
|
22
|
+
import { IconSession } from './icons.tsx'
|
|
23
|
+
import { usePresence } from './overlay.tsx'
|
|
24
|
+
import { formatTime } from './TaskCard.tsx'
|
|
25
|
+
import { VerificationReport } from './VerificationReport.tsx'
|
|
26
|
+
|
|
27
|
+
/** Rows shown before the history asks to be expanded. */
|
|
28
|
+
export const VISIBLE_EXECUTIONS = 5
|
|
29
|
+
|
|
30
|
+
/** Execution outcome → locale key, shared with the history's folded summary. */
|
|
31
|
+
/**
|
|
32
|
+
* A recorded failure text in the reader's own language, for the refusals the
|
|
33
|
+
* board itself produces and can therefore translate. Any other text is the
|
|
34
|
+
* Host's own sentence and is printed verbatim.
|
|
35
|
+
* @param error - the execution's recorded failure text.
|
|
36
|
+
* @returns the localized refusal, or the original text.
|
|
37
|
+
*/
|
|
38
|
+
export function failureText(error: string): string {
|
|
39
|
+
if (isMissingWorkspaceReason(error)) return t('exec.error.noWorkspace')
|
|
40
|
+
if (isLegacyAgentTeamsReason(error)) return t('exec.error.legacyAgentTeams')
|
|
41
|
+
return error
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const EXECUTION_RESULT_KEY: Record<NonNullable<ExecutionRecord['result']>, TaskBoardKey> = {
|
|
45
|
+
succeeded: 'detail.result.succeeded',
|
|
46
|
+
failed: 'detail.result.failed',
|
|
47
|
+
cancelled: 'detail.result.cancelled',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One execution-history row: identity on the head line, evidence below it. */
|
|
51
|
+
function ExecutionRow({ execution, timeZone, onOpen }: {
|
|
52
|
+
execution: ExecutionRecord
|
|
53
|
+
timeZone?: string
|
|
54
|
+
onOpen: (sessionId: string) => void
|
|
55
|
+
}) {
|
|
56
|
+
const result = execution.result
|
|
57
|
+
// An external record is one the Host never observed running: no session, no
|
|
58
|
+
// spinner, and a named outside agent instead of the initiating session. The
|
|
59
|
+
// data attribute keeps the distinction machine-readable too.
|
|
60
|
+
const external = execution.external === true
|
|
61
|
+
return (
|
|
62
|
+
<li
|
|
63
|
+
className={css.executionRow}
|
|
64
|
+
data-result={result}
|
|
65
|
+
data-execution-id={execution.id}
|
|
66
|
+
data-external={external ? 'true' : undefined}
|
|
67
|
+
>
|
|
68
|
+
<div className={css.executionRowHead}>
|
|
69
|
+
<span className={css.executionBadge} data-result={result}>
|
|
70
|
+
{result === undefined ? t('detail.result.running') : t(EXECUTION_RESULT_KEY[result])}
|
|
71
|
+
</span>
|
|
72
|
+
<span className={css.executionTimes}>
|
|
73
|
+
{t('detail.executionStarted')} {formatTime(execution.startedAt, timeZone)}
|
|
74
|
+
{execution.endedAt !== undefined && ` · ${t('detail.executionEnded')} ${formatTime(execution.endedAt, timeZone)}`}
|
|
75
|
+
</span>
|
|
76
|
+
{execution.sessionId !== undefined && (
|
|
77
|
+
<button
|
|
78
|
+
type="button"
|
|
79
|
+
className={css.executionSession}
|
|
80
|
+
onClick={() => { onOpen(execution.sessionId as string) }}
|
|
81
|
+
title={execution.sessionId}
|
|
82
|
+
>
|
|
83
|
+
{t('detail.viewSession')}
|
|
84
|
+
<IconSession size={13} />
|
|
85
|
+
</button>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
<div className={css.executionRowEvidence}>
|
|
89
|
+
{external && execution.initiatedBy !== undefined && (
|
|
90
|
+
<span className={css.executionTimes} title={execution.initiatedBy}>
|
|
91
|
+
{t('detail.execution.external', { agent: execution.initiatedBy })}
|
|
92
|
+
</span>
|
|
93
|
+
)}
|
|
94
|
+
{!external && execution.initiatedBy !== undefined && (
|
|
95
|
+
<span className={css.executionTimes} title={execution.initiatedBy}>
|
|
96
|
+
{t('detail.execution.initiator', { session: execution.initiatedBy })}
|
|
97
|
+
</span>
|
|
98
|
+
)}
|
|
99
|
+
{execution.verification !== undefined && <VerificationReport verification={execution.verification} />}
|
|
100
|
+
{execution.error !== undefined && execution.error !== '' && (
|
|
101
|
+
<span className={css.executionError}>
|
|
102
|
+
{failureText(execution.error)}
|
|
103
|
+
</span>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
</li>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Render one card's execution history.
|
|
112
|
+
* @param props - the card's executions, its time zone and the session jump.
|
|
113
|
+
* @returns the newest rows, the disclosure for the rest, and nothing else.
|
|
114
|
+
*/
|
|
115
|
+
export function ExecutionLog({ executions, timeZone, onOpenSession }: {
|
|
116
|
+
executions: readonly ExecutionRecord[]
|
|
117
|
+
timeZone?: string
|
|
118
|
+
onOpenSession: (sessionId: string) => void
|
|
119
|
+
}) {
|
|
120
|
+
const [expanded, setExpanded] = useState(false)
|
|
121
|
+
const presence = usePresence(expanded)
|
|
122
|
+
const logId = useId()
|
|
123
|
+
// Newest first: the row a reader wants is the run that just settled.
|
|
124
|
+
const recent = [...executions].reverse()
|
|
125
|
+
const visible = recent.slice(0, VISIBLE_EXECUTIONS)
|
|
126
|
+
const older = recent.slice(VISIBLE_EXECUTIONS)
|
|
127
|
+
const row = (execution: ExecutionRecord) => (
|
|
128
|
+
<ExecutionRow key={execution.id} execution={execution} timeZone={timeZone} onOpen={onOpenSession} />
|
|
129
|
+
)
|
|
130
|
+
return (
|
|
131
|
+
<div className={css.executionLog} id={logId}>
|
|
132
|
+
<ul className={css.executionList}>{visible.map(row)}</ul>
|
|
133
|
+
{older.length > 0 && presence.mounted && (
|
|
134
|
+
<div className={css.executionExtra} data-execution-fold={presence.phase}>
|
|
135
|
+
<ul className={css.executionList}>{older.map(row)}</ul>
|
|
136
|
+
</div>
|
|
137
|
+
)}
|
|
138
|
+
{older.length > 0 && (
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
className={`${css.linkButton} ${css.executionDisclosure}`}
|
|
142
|
+
aria-expanded={expanded}
|
|
143
|
+
aria-controls={logId}
|
|
144
|
+
onClick={() => { setExpanded(!expanded) }}
|
|
145
|
+
>
|
|
146
|
+
{expanded
|
|
147
|
+
? t('detail.collapse')
|
|
148
|
+
: t('detail.execution.showAll', { count: String(recent.length) })}
|
|
149
|
+
<span className={css.disclosureChevron} data-open={expanded} aria-hidden="true" />
|
|
150
|
+
</button>
|
|
151
|
+
)}
|
|
152
|
+
</div>
|
|
153
|
+
)
|
|
154
|
+
}
|
|
@@ -77,7 +77,7 @@ export function LinkSubtaskModal({ controller, parent, onClose, phase = 'open' }
|
|
|
77
77
|
<span className={css.statusBadge} data-status={task.status}>{t(STATUS_KEY[task.status])}</span>
|
|
78
78
|
<button
|
|
79
79
|
type="button"
|
|
80
|
-
className={css.
|
|
80
|
+
className={css.ghostButton}
|
|
81
81
|
disabled={pending}
|
|
82
82
|
onClick={() => { void link(task.id) }}
|
|
83
83
|
>
|