@linxin666/dsh-client-ui-task-board 0.4.20 → 0.4.22
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/README.i18n.yaml +2 -2
- package/README.md +2 -1
- package/README.zh.md +2 -1
- package/lib/client.js +55 -63
- package/lib/client.js.map +1 -1
- package/lib/index.js +181 -45
- package/lib/types/client/board/AttachmentField.d.ts +3 -1
- package/lib/types/client/locales.d.ts +1 -0
- package/lib/types/core/extension.d.ts +25 -0
- package/lib/types/core/tasks.d.ts +23 -3
- package/lib/types/core/use-cases/task-update.d.ts +25 -17
- package/lib/types/host/agent-tools.d.ts +5 -0
- package/lib/types/host/extension-registry.d.ts +8 -0
- package/lib/types/host-service.d.ts +5 -1
- package/lib/types/protocol.d.ts +9 -0
- package/package.json +28 -28
- package/src/client/board/AttachmentField.tsx +6 -1
- package/src/client/board/EditTaskModal.tsx +4 -1
- package/src/client/board/ExecutionLog.tsx +6 -0
- package/src/client/board/TaskDetail.tsx +16 -11
- package/src/client/locales.ts +2 -0
- package/src/core/execution-summary.ts +3 -2
- package/src/core/extension.ts +21 -0
- package/src/core/store.ts +4 -0
- package/src/core/tasks.ts +27 -3
- package/src/core/use-cases/task-update.ts +29 -19
- package/src/host/agent-tools.ts +62 -15
- package/src/host/extension-registry.ts +36 -0
- package/src/host-ledger.ts +33 -10
- package/src/host-service.ts +10 -0
- package/src/protocol.ts +32 -2
package/src/host/agent-tools.ts
CHANGED
|
@@ -47,6 +47,23 @@ export interface TaskBoardToolHost {
|
|
|
47
47
|
* a provider's launch handler can tell an agent's run from a person's.
|
|
48
48
|
*/
|
|
49
49
|
apply(requestId: string, action: TaskBoardAction, initiator?: string, trigger?: TaskBoardLaunchTrigger): TaskBoardSnapshot | Promise<TaskBoardSnapshot>
|
|
50
|
+
/** What running providers say about one card, keyed by extension id (optional). */
|
|
51
|
+
describeTask?(task: TaskRecord): Record<string, Record<string, unknown>> | undefined
|
|
52
|
+
/** The run handle a provider holds for one card, keyed by extension id (optional). */
|
|
53
|
+
describeRun?(taskId: string): Record<string, Record<string, unknown>> | undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The one provider view a card carries, with its extension id as `provider`.
|
|
58
|
+
* A provider that says `localPermission: false` marks a card the board's
|
|
59
|
+
* session permission gate does not govern (it runs outside this Host).
|
|
60
|
+
*/
|
|
61
|
+
function remoteView(views: Record<string, Record<string, unknown>> | undefined): { view: Record<string, unknown>; localPermission: boolean } | undefined {
|
|
62
|
+
if (views === undefined) return undefined
|
|
63
|
+
const [id, view] = Object.entries(views)[0] ?? []
|
|
64
|
+
if (id === undefined || view === undefined) return undefined
|
|
65
|
+
const { localPermission, ...rest } = view
|
|
66
|
+
return { view: { provider: id, ...rest }, localPermission: localPermission !== false }
|
|
50
67
|
}
|
|
51
68
|
|
|
52
69
|
/** Registered tool names, in registration order. */
|
|
@@ -130,7 +147,12 @@ function executionView(execution: ExecutionRecord): Record<string, unknown> {
|
|
|
130
147
|
startedAt: execution.startedAt,
|
|
131
148
|
...(execution.endedAt === undefined ? {} : { endedAt: execution.endedAt }),
|
|
132
149
|
...(execution.result === undefined ? {} : { result: execution.result }),
|
|
150
|
+
// The conclusion of a succeeded run and the reason of a failed one never
|
|
151
|
+
// share a field: summary says what was done, error says why it failed.
|
|
152
|
+
...(execution.summary === undefined ? {} : { summary: execution.summary.text }),
|
|
133
153
|
...(execution.error === undefined ? {} : { error: execution.error }),
|
|
154
|
+
...(execution.errorCode === undefined ? {} : { errorCode: execution.errorCode }),
|
|
155
|
+
...(execution.retryHint === undefined ? {} : { retryHint: execution.retryHint }),
|
|
134
156
|
// The session that asked for the run (audit only; client-asserted by the
|
|
135
157
|
// browser, the calling session here). On an external record it names the
|
|
136
158
|
// outside agent instead, which is what distinguishes it in the history.
|
|
@@ -158,8 +180,10 @@ function taskSummary(
|
|
|
158
180
|
task: TaskRecord,
|
|
159
181
|
tasks: readonly TaskRecord[],
|
|
160
182
|
sessionDefault: TaskPermission | undefined,
|
|
183
|
+
host?: TaskBoardToolHost,
|
|
161
184
|
): Record<string, unknown> {
|
|
162
185
|
const latest = task.executions.at(-1)
|
|
186
|
+
const remote = remoteView(host?.describeTask?.(task))
|
|
163
187
|
const subtaskCount = directSubtasks(tasks, task.id).length
|
|
164
188
|
return {
|
|
165
189
|
id: task.id,
|
|
@@ -182,9 +206,12 @@ function taskSummary(
|
|
|
182
206
|
...(task.permissionConfirmedAt === undefined ? {} : { permissionConfirmedAt: task.permissionConfirmedAt }),
|
|
183
207
|
// Whether this card may run at all: an elevated binding still needs a
|
|
184
208
|
// human confirmation, and only a human can give it.
|
|
185
|
-
|
|
209
|
+
// A card that runs outside this Host is not governed by the session
|
|
210
|
+
// permission gate, so it never reports a pending confirmation it cannot use.
|
|
211
|
+
...(remote?.localPermission !== false && requiresPermissionConfirmation(task, sessionDefault ?? DEFAULT_SESSION_PERMISSION)
|
|
186
212
|
? { permissionPending: true }
|
|
187
213
|
: {}),
|
|
214
|
+
...(remote === undefined ? {} : { remote: remote.view }),
|
|
188
215
|
executionCount: task.executions.length,
|
|
189
216
|
...(latest === undefined ? {} : { latestExecution: executionView(latest) }),
|
|
190
217
|
createdAt: task.createdAt,
|
|
@@ -197,10 +224,11 @@ function taskDetail(
|
|
|
197
224
|
task: TaskRecord,
|
|
198
225
|
tasks: readonly TaskRecord[],
|
|
199
226
|
sessionDefault: TaskPermission | undefined,
|
|
227
|
+
host?: TaskBoardToolHost,
|
|
200
228
|
): Record<string, unknown> {
|
|
201
229
|
const parent = task.parentId === undefined ? undefined : tasks.find(item => item.id === task.parentId)
|
|
202
230
|
return {
|
|
203
|
-
...taskSummary(task, tasks, sessionDefault),
|
|
231
|
+
...taskSummary(task, tasks, sessionDefault, host),
|
|
204
232
|
prompt: task.prompt,
|
|
205
233
|
depth: taskDepth(tasks, task.id),
|
|
206
234
|
...(parent === undefined ? {} : { parent: { id: parent.id, title: parent.title, status: parent.status } }),
|
|
@@ -227,7 +255,7 @@ function taskDetail(
|
|
|
227
255
|
bundledAt: task.handover.bundledAt,
|
|
228
256
|
},
|
|
229
257
|
}),
|
|
230
|
-
subtasks: directSubtasks(tasks, task.id).map(child => taskSummary(child, tasks, sessionDefault)),
|
|
258
|
+
subtasks: directSubtasks(tasks, task.id).map(child => taskSummary(child, tasks, sessionDefault, host)),
|
|
231
259
|
executions: task.executions.slice(-10).map(executionView),
|
|
232
260
|
}
|
|
233
261
|
}
|
|
@@ -238,6 +266,15 @@ function openedExecutions(before: readonly ExecutionRecord[], after: readonly Ex
|
|
|
238
266
|
return after.filter(execution => !known.has(execution.id))
|
|
239
267
|
}
|
|
240
268
|
|
|
269
|
+
/** The identifiers of a run handle, lifted to the top level of the run output. */
|
|
270
|
+
function liftHandle(handle: Record<string, unknown>): Record<string, unknown> {
|
|
271
|
+
const lifted: Record<string, unknown> = {}
|
|
272
|
+
for (const key of ['executionId', 'runId', 'logPath', 'target', 'estimatedDurationMs']) {
|
|
273
|
+
if (handle[key] !== undefined) lifted[key] = handle[key]
|
|
274
|
+
}
|
|
275
|
+
return lifted
|
|
276
|
+
}
|
|
277
|
+
|
|
241
278
|
/** Board summary attached to task_board_list. */
|
|
242
279
|
function boardView(snapshot: TaskBoardSnapshot, maxSubtaskDepth: number): Record<string, unknown> {
|
|
243
280
|
const counts = { backlog: 0, todo: 0, running: 0, done: 0, failed: 0, archived: 0 }
|
|
@@ -298,7 +335,7 @@ function buildSetParentTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
298
335
|
)
|
|
299
336
|
const task = snapshot.tasks.find(item => item.id === args.taskId)
|
|
300
337
|
if (task === undefined) return refused('task-not-found', 'no task with id ' + args.taskId)
|
|
301
|
-
return json({ ok: true, task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
338
|
+
return json({ ok: true, task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
302
339
|
} catch (error) {
|
|
303
340
|
return refused('refused', messageOf(error))
|
|
304
341
|
}
|
|
@@ -314,6 +351,7 @@ function buildRunTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
314
351
|
'Running a card opens ONE session for that card: no session is opened for its subtasks, and the card agent dispatches them itself with subagent. A card whose subtasks are still unfinished runs under the liangshen agent preset and is told which cards to pick up.',
|
|
315
352
|
'Clicking a subtask runs that subtask as its own root, again without opening anything for its descendants.',
|
|
316
353
|
'A card whose effective permission is above the deployment session default is refused with confirmation-required until a HUMAN confirms the binding in the board UI; this tool cannot confirm it.',
|
|
354
|
+
'A card whose run a provider takes over (for example a card pinned to a remote host) answers with that run handle at the top level - executionId, runId, logPath, target, estimatedDurationMs - and a note naming the call that blocks until it settles; a second run request against a card that already has a run in flight is refused with a stable code instead of overwriting it.',
|
|
317
355
|
'Executions consume real API quota. Sessions are created asynchronously, so read their ids and outcomes back with task_board_get.',
|
|
318
356
|
].join(' '),
|
|
319
357
|
parameters: {
|
|
@@ -341,15 +379,24 @@ function buildRunTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
341
379
|
}))
|
|
342
380
|
})
|
|
343
381
|
const root = snapshot.tasks.find(task => task.id === args.taskId)
|
|
382
|
+
// A provider that took the run over opens no board execution, so its
|
|
383
|
+
// own handle (run id, log location, target, estimate) is what the
|
|
384
|
+
// caller needs to follow it.
|
|
385
|
+
const handle = remoteView(host.describeRun?.(String(args.taskId)))?.view
|
|
386
|
+
const waitHint = typeof handle?.next === 'string' ? handle.next : undefined
|
|
344
387
|
return json({
|
|
345
388
|
ok: true,
|
|
346
389
|
started,
|
|
347
|
-
...(
|
|
348
|
-
|
|
390
|
+
...(handle === undefined ? {} : { run: handle, ...liftHandle(handle) }),
|
|
391
|
+
...(root === undefined ? {} : { task: taskSummary(root, snapshot.tasks, snapshot.sessionDefaultPermission, host) }),
|
|
392
|
+
note: waitHint ?? 'Executions run asynchronously; call task_board_get to read session ids and the settled outcome.',
|
|
349
393
|
})
|
|
350
394
|
} catch (error) {
|
|
351
395
|
const message = messageOf(error)
|
|
352
|
-
|
|
396
|
+
if (message.startsWith('confirmation-required')) return refused('confirmation-required', message)
|
|
397
|
+
// A provider refusal reads `code: reason`; the code is the stable part.
|
|
398
|
+
const coded = /^([a-z][a-z0-9-]*): ([\s\S]+)$/.exec(message)
|
|
399
|
+
return coded === null ? refused('refused', message) : refused(coded[1] as string, coded[2] as string)
|
|
353
400
|
}
|
|
354
401
|
},
|
|
355
402
|
})
|
|
@@ -418,7 +465,7 @@ function buildManageTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
418
465
|
return json({
|
|
419
466
|
ok: true,
|
|
420
467
|
action: args.action,
|
|
421
|
-
...(task === undefined ? {} : { task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission) }),
|
|
468
|
+
...(task === undefined ? {} : { task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) }),
|
|
422
469
|
note: 'The outcome is recorded as its own execution, so the terminal column and the run history agree. Read it back with task_board_get.',
|
|
423
470
|
})
|
|
424
471
|
} catch (error) {
|
|
@@ -446,7 +493,7 @@ function buildManageTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
446
493
|
if (args.action === 'delete') return json({ ok: true, action: args.action, taskId: args.taskId })
|
|
447
494
|
const task = snapshot.tasks.find(item => item.id === args.taskId)
|
|
448
495
|
if (task === undefined) return refused('task-not-found', 'no task with id ' + args.taskId)
|
|
449
|
-
return json({ ok: true, action: args.action, task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
496
|
+
return json({ ok: true, action: args.action, task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
450
497
|
} catch (error) {
|
|
451
498
|
return refused('refused', messageOf(error))
|
|
452
499
|
}
|
|
@@ -506,7 +553,7 @@ function buildScheduleTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
506
553
|
return json({
|
|
507
554
|
ok: true,
|
|
508
555
|
schedule: task.schedule === undefined ? null : scheduleView(task.schedule),
|
|
509
|
-
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission),
|
|
556
|
+
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host),
|
|
510
557
|
})
|
|
511
558
|
} catch (error) {
|
|
512
559
|
return refused('refused', messageOf(error))
|
|
@@ -522,7 +569,7 @@ function buildListTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
522
569
|
description: [
|
|
523
570
|
'List tasks on the DSH task board (the Host-authoritative ledger behind the Web GUI task board).',
|
|
524
571
|
'Filters: status column, parentId (direct subtasks), rootsOnly, tag, free-text query, and archived inclusion.',
|
|
525
|
-
'Returns each task id, title, column, parent/subtask link, execution targets, schedule and latest run outcome, plus the board summary (revision, time zone, subtask depth limit, session-default permission).',
|
|
572
|
+
'Returns each task id, title, column, parent/subtask link, execution targets, schedule and latest run outcome (a card a provider runs remotely also carries a `remote` summary: host, agent, mode, whether a follow-up is possible), plus the board summary (revision, time zone, subtask depth limit, session-default permission).',
|
|
526
573
|
'Use task_board_get for one task in full, task_board_create to add work, and task_board_run to execute it.',
|
|
527
574
|
].join(' '),
|
|
528
575
|
parameters: {
|
|
@@ -557,7 +604,7 @@ function buildListTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
557
604
|
board: boardView(snapshot, snapshot.maxSubtaskDepth ?? DEFAULT_SUBTASK_DEPTH),
|
|
558
605
|
total: matched.length,
|
|
559
606
|
count: Math.min(matched.length, limit),
|
|
560
|
-
tasks: matched.slice(0, limit).map(task => taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission)),
|
|
607
|
+
tasks: matched.slice(0, limit).map(task => taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host)),
|
|
561
608
|
})
|
|
562
609
|
},
|
|
563
610
|
})
|
|
@@ -580,7 +627,7 @@ function buildGetTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
580
627
|
const snapshot = host.snapshot()
|
|
581
628
|
const task = snapshot.tasks.find(item => item.id === args.taskId)
|
|
582
629
|
if (task === undefined) return refused('task-not-found', 'no task with id ' + args.taskId)
|
|
583
|
-
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
630
|
+
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
584
631
|
},
|
|
585
632
|
})
|
|
586
633
|
}
|
|
@@ -669,7 +716,7 @@ function buildCreateTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
669
716
|
const snapshot = await host.apply(crypto.randomUUID(), { kind: 'create', id, input }, callingSessionId(exec))
|
|
670
717
|
const task = snapshot.tasks.find(item => item.id === id)
|
|
671
718
|
if (task === undefined) return refused('create-failed', 'the Host did not confirm the new task')
|
|
672
|
-
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
719
|
+
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
673
720
|
} catch (error) {
|
|
674
721
|
return refused('refused', messageOf(error))
|
|
675
722
|
}
|
|
@@ -756,7 +803,7 @@ function buildUpdateTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
756
803
|
const snapshot = await host.apply(crypto.randomUUID(), { kind: 'update', taskId: args.taskId, patch }, callingSessionId(exec))
|
|
757
804
|
const task = snapshot.tasks.find(item => item.id === args.taskId)
|
|
758
805
|
if (task === undefined) return refused('task-not-found', 'no task with id ' + args.taskId)
|
|
759
|
-
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
806
|
+
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
760
807
|
} catch (error) {
|
|
761
808
|
return refused('refused', messageOf(error))
|
|
762
809
|
}
|
|
@@ -207,6 +207,14 @@ function launchDecision(
|
|
|
207
207
|
}
|
|
208
208
|
const kind = (answer as { kind?: unknown }).kind
|
|
209
209
|
if (kind === 'external') return { kind: 'external' }
|
|
210
|
+
if (kind === 'refuse') {
|
|
211
|
+
const { code, reason } = answer as { code?: unknown; reason?: unknown }
|
|
212
|
+
if (typeof code !== 'string' || !/^[a-z][a-z0-9-]*$/.test(code) || typeof reason !== 'string' || reason.trim() === '') {
|
|
213
|
+
warn('returned a malformed refusal')
|
|
214
|
+
return undefined
|
|
215
|
+
}
|
|
216
|
+
return { kind: 'refuse', code, reason: reason.trim() }
|
|
217
|
+
}
|
|
210
218
|
if (kind !== 'local') {
|
|
211
219
|
warn('returned an unknown decision kind')
|
|
212
220
|
return undefined
|
|
@@ -394,6 +402,34 @@ export class TaskBoardExtensionRegistry {
|
|
|
394
402
|
return undefined
|
|
395
403
|
}
|
|
396
404
|
|
|
405
|
+
/**
|
|
406
|
+
* What the running providers say about one card, keyed by extension id.
|
|
407
|
+
* Isolated per provider: a throw drops that provider's entry only.
|
|
408
|
+
*/
|
|
409
|
+
describeTask(task: TaskRecord): Record<string, Record<string, unknown>> | undefined {
|
|
410
|
+
return this.describe(entry => entry.extension.describeTask?.(task))
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/** The run handle a running provider holds for one card, keyed by extension id. */
|
|
414
|
+
describeRun(taskId: string): Record<string, Record<string, unknown>> | undefined {
|
|
415
|
+
return this.describe(entry => entry.extension.describeRun?.(taskId))
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private describe(read: (entry: { extension: TaskBoardExtension }) => Record<string, unknown> | undefined): Record<string, Record<string, unknown>> | undefined {
|
|
419
|
+
if (this.disposed) return undefined
|
|
420
|
+
const result: Record<string, Record<string, unknown>> = {}
|
|
421
|
+
for (const entry of this.entries.values()) {
|
|
422
|
+
if (!entry.active) continue
|
|
423
|
+
try {
|
|
424
|
+
const view = read(entry)
|
|
425
|
+
if (typeof view === 'object' && view !== null && !Array.isArray(view)) result[entry.extension.id] = view
|
|
426
|
+
} catch (error) {
|
|
427
|
+
this.logger.error(`[dsh-task-board] extension "${entry.extension.id}" description failed`, error)
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return Object.keys(result).length === 0 ? undefined : result
|
|
431
|
+
}
|
|
432
|
+
|
|
397
433
|
/** Published summaries of currently running providers, keyed by extension id. */
|
|
398
434
|
published(): Record<string, TaskBoardExtensionPayload> {
|
|
399
435
|
const result: Record<string, TaskBoardExtensionPayload> = {}
|
package/src/host-ledger.ts
CHANGED
|
@@ -28,7 +28,7 @@ import { applyDeleteTask } from './core/use-cases/task-delete.ts'
|
|
|
28
28
|
import { applySetSchedule, applyScheduleProgress, applyScheduleRefund, type ScheduleProgress } from './core/use-cases/task-schedule.ts'
|
|
29
29
|
import { applySetParent } from './core/use-cases/task-parent.ts'
|
|
30
30
|
import { applyDeleteTag, applyRenameTag } from './core/use-cases/task-tag.ts'
|
|
31
|
-
import { applyUpdateTask, canEditTaskContent, hasContentPatch } from './core/use-cases/task-update.ts'
|
|
31
|
+
import { applyUpdateTask, canEditTaskAttachments, canEditTaskContent, hasContentPatch } from './core/use-cases/task-update.ts'
|
|
32
32
|
import { TASK_BOARD_MIGRATABLE_SCHEMA_VERSIONS, TASK_BOARD_SCHEMA_VERSION, TASK_BOARD_ZONE_STAMP_SCHEMA_VERSION, type TaskBoardAction, type TaskBoardSchedulerSnapshot } from './protocol.ts'
|
|
33
33
|
import { DEFAULT_SESSION_PERMISSION, requiresPermissionConfirmation, type TaskPermission } from './core/handover.ts'
|
|
34
34
|
import type { TaskBoardLaunchDecision, TaskBoardLaunchHandler, TaskBoardLaunchTrigger } from './core/extension.ts'
|
|
@@ -1244,10 +1244,16 @@ export class HostTaskLedger {
|
|
|
1244
1244
|
const task = this.document.tasks.find(task => task.id === action.taskId)
|
|
1245
1245
|
if (task === undefined) throw new Error('task not found')
|
|
1246
1246
|
if (task.archivedAt !== undefined) throw new Error('archived task is read-only')
|
|
1247
|
-
//
|
|
1248
|
-
//
|
|
1249
|
-
//
|
|
1250
|
-
|
|
1247
|
+
// Attachments keep the historical boundary: they are not captured on
|
|
1248
|
+
// the execution record, so they freeze at the first run and stay
|
|
1249
|
+
// frozen for every executed or archived card afterwards.
|
|
1250
|
+
if ('attachments' in action.patch && !canEditTaskAttachments(task)) {
|
|
1251
|
+
throw new Error('task has already been executed')
|
|
1252
|
+
}
|
|
1253
|
+
// The content fields (title/description/prompt) may change between
|
|
1254
|
+
// runs — each execution record carries the snapshot it was opened
|
|
1255
|
+
// with — but never under an open execution. Execution targets stay
|
|
1256
|
+
// editable throughout (they only affect future runs).
|
|
1251
1257
|
if (hasContentPatch(action.patch) && !canEditTaskContent(task)) {
|
|
1252
1258
|
throw new Error('task has already been executed')
|
|
1253
1259
|
}
|
|
@@ -1306,15 +1312,26 @@ export class HostTaskLedger {
|
|
|
1306
1312
|
// terminal verdict over it. This is also what keeps a stale report from
|
|
1307
1313
|
// racing the session it claims to have replaced.
|
|
1308
1314
|
if (hasOpenExecution(task)) throw new Error('running task cannot receive an external outcome')
|
|
1315
|
+
// A caller-chosen id must stay unique in the history: a duplicate would
|
|
1316
|
+
// make one handle name two attempts.
|
|
1317
|
+
if (action.executionId !== undefined && task.executions.some(entry => entry.id === action.executionId)) {
|
|
1318
|
+
throw new Error('execution id already recorded')
|
|
1319
|
+
}
|
|
1320
|
+
const succeeded = action.result === 'succeeded'
|
|
1309
1321
|
const execution: ExecutionRecord = {
|
|
1310
|
-
// A fresh id
|
|
1311
|
-
// new attempt in the history, never an overwrite
|
|
1312
|
-
id: crypto.randomUUID(),
|
|
1322
|
+
// A fresh id unless the provider handed one out at launch: the external
|
|
1323
|
+
// work is a new attempt in the history, never an overwrite.
|
|
1324
|
+
id: action.executionId ?? crypto.randomUUID(),
|
|
1313
1325
|
sessionId: undefined,
|
|
1314
|
-
startedAt: now,
|
|
1326
|
+
startedAt: action.startedAt === undefined ? now : Math.min(action.startedAt, now),
|
|
1315
1327
|
endedAt: now,
|
|
1316
1328
|
result: action.result,
|
|
1317
|
-
|
|
1329
|
+
// The two texts never share a field: a conclusion is a summary and only
|
|
1330
|
+
// a failure is an error.
|
|
1331
|
+
error: succeeded ? undefined : action.summary,
|
|
1332
|
+
...(succeeded || action.errorCode === undefined ? {} : { errorCode: action.errorCode }),
|
|
1333
|
+
...(succeeded || action.retryHint === undefined ? {} : { retryHint: action.retryHint }),
|
|
1334
|
+
...(succeeded && action.summary !== undefined ? { summary: { text: action.summary } } : {}),
|
|
1318
1335
|
initiatedBy: action.initiatedBy,
|
|
1319
1336
|
external: true,
|
|
1320
1337
|
}
|
|
@@ -1560,6 +1577,12 @@ export class HostTaskLedger {
|
|
|
1560
1577
|
// document is touched: a decision to hand the run over is not a mutation
|
|
1561
1578
|
// the ledger has to roll back.
|
|
1562
1579
|
const decision: TaskBoardLaunchDecision | undefined = this.launchGate?.(participant, { trigger })
|
|
1580
|
+
if (decision?.kind === 'refuse') {
|
|
1581
|
+
// A scheduled occurrence has no caller to answer, so it is skipped like an
|
|
1582
|
+
// open execution; every other entry hears the provider's own code.
|
|
1583
|
+
if (progress !== undefined) return { runs: [], committed: false }
|
|
1584
|
+
throw new Error(`${decision.code}: ${decision.reason}`)
|
|
1585
|
+
}
|
|
1563
1586
|
if (decision?.kind === 'external') {
|
|
1564
1587
|
// The provider runs this card outside the board. The Host writes no
|
|
1565
1588
|
// execution record, so nothing here can be inspected, settled or
|
package/src/host-service.ts
CHANGED
|
@@ -529,6 +529,16 @@ export class TaskBoardHostService {
|
|
|
529
529
|
return this.extensions.registerExtension(extension)
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
+
/** What running providers say about one card, for the model-facing tools. */
|
|
533
|
+
describeTask(task: TaskRecord): Record<string, Record<string, unknown>> | undefined {
|
|
534
|
+
return this.extensions.describeTask(task)
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** The run handle a running provider holds for one card, for `task_board_run`. */
|
|
538
|
+
describeRun(taskId: string): Record<string, Record<string, unknown>> | undefined {
|
|
539
|
+
return this.extensions.describeRun(taskId)
|
|
540
|
+
}
|
|
541
|
+
|
|
532
542
|
/**
|
|
533
543
|
* The host model catalog the settings card's model and reasoning-level
|
|
534
544
|
* choices come from.
|
package/src/protocol.ts
CHANGED
|
@@ -196,7 +196,22 @@ export type TaskBoardAction =
|
|
|
196
196
|
* `cancelled` is deliberately absent: nothing outside a DSH session may
|
|
197
197
|
* claim the Host closed a run, and `running` must stay Host-only.
|
|
198
198
|
*/
|
|
199
|
-
| {
|
|
199
|
+
| {
|
|
200
|
+
kind: 'record-external-outcome'
|
|
201
|
+
taskId: string
|
|
202
|
+
result: 'succeeded' | 'failed'
|
|
203
|
+
initiatedBy: string
|
|
204
|
+
/** Success: stored as the execution summary. Failure: stored as the error text. */
|
|
205
|
+
summary?: string
|
|
206
|
+
/** Id the execution record takes, so a handle returned at launch stays valid. */
|
|
207
|
+
executionId?: string
|
|
208
|
+
/** Instant the outside run started (ms epoch); the record starts there instead of at settlement. */
|
|
209
|
+
startedAt?: number
|
|
210
|
+
/** Failure only: stable machine-readable code. */
|
|
211
|
+
errorCode?: string
|
|
212
|
+
/** Failure only: one line on whether and how to retry. */
|
|
213
|
+
retryHint?: string
|
|
214
|
+
}
|
|
200
215
|
| { kind: 'set-schedule'; taskId: string; patch: SetSchedulePatch }
|
|
201
216
|
| { kind: 'run'; taskId: string }
|
|
202
217
|
| { kind: 'rerun'; taskId: string }
|
|
@@ -314,6 +329,8 @@ function validImportedKnownFields(value: Record<string, unknown>): boolean {
|
|
|
314
329
|
if (execution.external !== undefined && typeof execution.external !== 'boolean') return false
|
|
315
330
|
if (execution.frozenBy !== undefined && typeof execution.frozenBy !== 'string') return false
|
|
316
331
|
if (execution.frozenAt !== undefined && typeof execution.frozenAt !== 'number') return false
|
|
332
|
+
if (execution.promptSnapshot !== undefined && typeof execution.promptSnapshot !== 'string') return false
|
|
333
|
+
if (execution.titleSnapshot !== undefined && typeof execution.titleSnapshot !== 'string') return false
|
|
317
334
|
}
|
|
318
335
|
}
|
|
319
336
|
return true
|
|
@@ -343,6 +360,8 @@ function importedTask(value: unknown): TaskRecord | undefined {
|
|
|
343
360
|
...(execution.external === true ? { external: true } : {}),
|
|
344
361
|
...(execution.frozenAt === undefined ? {} : { frozenAt: execution.frozenAt }),
|
|
345
362
|
...(execution.frozenBy === undefined ? {} : { frozenBy: execution.frozenBy }),
|
|
363
|
+
...(execution.promptSnapshot === undefined ? {} : { promptSnapshot: execution.promptSnapshot }),
|
|
364
|
+
...(execution.titleSnapshot === undefined ? {} : { titleSnapshot: execution.titleSnapshot }),
|
|
346
365
|
})),
|
|
347
366
|
// The rule was already reconstructed field by field by parseLedger (which
|
|
348
367
|
// is what drops an unknown or malformed field), so the import keeps that
|
|
@@ -584,7 +603,7 @@ function parseEnvelopeAction(value: unknown): TaskBoardActionEnvelope | undefine
|
|
|
584
603
|
}
|
|
585
604
|
}
|
|
586
605
|
case 'record-external-outcome': {
|
|
587
|
-
if (!exactKeys(action, ['kind', 'taskId', 'result', 'initiatedBy', 'summary'])) return undefined
|
|
606
|
+
if (!exactKeys(action, ['kind', 'taskId', 'result', 'initiatedBy', 'summary', 'executionId', 'startedAt', 'errorCode', 'retryHint'])) return undefined
|
|
588
607
|
if (taskId === undefined) return undefined
|
|
589
608
|
// Only a real outside verdict is accepted: `running` is Host-only and
|
|
590
609
|
// `cancelled` is the Host's own bookkeeping for a run it closed.
|
|
@@ -596,6 +615,13 @@ function parseEnvelopeAction(value: unknown): TaskBoardActionEnvelope | undefine
|
|
|
596
615
|
if (initiatedBy === '' || initiatedBy.length > EXTERNAL_INITIATOR_MAX_LENGTH) return undefined
|
|
597
616
|
if (action.summary !== undefined && typeof action.summary !== 'string') return undefined
|
|
598
617
|
const summary = typeof action.summary === 'string' ? action.summary.trim().slice(0, EXTERNAL_SUMMARY_MAX_LENGTH) : ''
|
|
618
|
+
if (action.executionId !== undefined && (typeof action.executionId !== 'string' || action.executionId === '' || action.executionId.length > 128)) return undefined
|
|
619
|
+
if (action.startedAt !== undefined && (typeof action.startedAt !== 'number' || !Number.isFinite(action.startedAt) || action.startedAt < 0)) return undefined
|
|
620
|
+
for (const key of ['errorCode', 'retryHint'] as const) {
|
|
621
|
+
if (action[key] !== undefined && typeof action[key] !== 'string') return undefined
|
|
622
|
+
}
|
|
623
|
+
const errorCode = typeof action.errorCode === 'string' ? action.errorCode.trim().slice(0, 64) : ''
|
|
624
|
+
const retryHint = typeof action.retryHint === 'string' ? action.retryHint.trim().slice(0, EXTERNAL_SUMMARY_MAX_LENGTH) : ''
|
|
599
625
|
return {
|
|
600
626
|
requestId: envelope.requestId,
|
|
601
627
|
action: {
|
|
@@ -604,6 +630,10 @@ function parseEnvelopeAction(value: unknown): TaskBoardActionEnvelope | undefine
|
|
|
604
630
|
result: action.result,
|
|
605
631
|
initiatedBy,
|
|
606
632
|
...(summary === '' ? {} : { summary }),
|
|
633
|
+
...(action.executionId === undefined ? {} : { executionId: action.executionId as string }),
|
|
634
|
+
...(action.startedAt === undefined ? {} : { startedAt: action.startedAt as number }),
|
|
635
|
+
...(errorCode === '' ? {} : { errorCode }),
|
|
636
|
+
...(retryHint === '' ? {} : { retryHint }),
|
|
607
637
|
},
|
|
608
638
|
}
|
|
609
639
|
}
|