@linxin666/dsh-client-ui-task-board 0.4.19 → 0.4.21
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 +1 -1
- package/README.zh.md +1 -1
- package/lib/client.js +190 -63
- package/lib/client.js.map +1 -1
- package/lib/index.js +599 -95
- package/lib/types/client/board/TaskForm.d.ts +3 -1
- package/lib/types/client/index.d.ts +7 -1
- package/lib/types/client/native-panel.d.ts +1 -1
- package/lib/types/client/seats.d.ts +36 -2
- package/lib/types/client/settings-form.d.ts +2 -0
- package/lib/types/core/controller.d.ts +1 -1
- package/lib/types/core/extension.d.ts +160 -1
- package/lib/types/core/session-reuse.d.ts +46 -13
- package/lib/types/core/tasks.d.ts +16 -5
- package/lib/types/host/agent-tools.d.ts +12 -2
- package/lib/types/host/extension-registry.d.ts +38 -1
- package/lib/types/host-ledger.d.ts +86 -1
- package/lib/types/host-runner.d.ts +20 -1
- package/lib/types/host-service.d.ts +64 -15
- package/lib/types/protocol.d.ts +18 -1
- package/package.json +1 -1
- package/src/client/board/ExecutionLog.tsx +15 -2
- package/src/client/board/NewTaskModal.tsx +88 -3
- package/src/client/board/TaskDetail.tsx +18 -11
- package/src/client/board/TaskForm.tsx +13 -2
- package/src/client/board.module.css +67 -1
- package/src/client/index.ts +3 -0
- package/src/client/locales.ts +7 -6
- package/src/client/native-panel.tsx +2 -1
- package/src/client/seats.tsx +32 -4
- package/src/client/service.ts +3 -0
- package/src/client/settings-form.ts +21 -2
- package/src/core/controller.ts +9 -3
- package/src/core/execution-summary.ts +3 -2
- package/src/core/extension.ts +159 -1
- package/src/core/session-reuse.ts +58 -21
- package/src/core/store.ts +2 -0
- package/src/core/tasks.ts +16 -5
- package/src/host/agent-tools.ts +70 -17
- package/src/host/extension-registry.ts +157 -2
- package/src/host-ledger.ts +274 -23
- package/src/host-runner.ts +44 -5
- package/src/host-service.ts +190 -37
- package/src/protocol.ts +37 -3
|
@@ -5,42 +5,79 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ExecutionRecord, TaskRecord } from './tasks.ts'
|
|
7
7
|
|
|
8
|
+
/** Everything the reuse rule reads beyond the card's own execution history. */
|
|
9
|
+
export interface ReuseOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Continue the settled session regardless of the card's own `reuseSession`
|
|
12
|
+
* opt-in. A rework is exactly that case: the reviewer read the previous run's
|
|
13
|
+
* session and sent it back. The force waives the opt-in, never the evidence.
|
|
14
|
+
*/
|
|
15
|
+
force?: boolean
|
|
16
|
+
/**
|
|
17
|
+
* The Workspace registry's global archive set (issue #2068).
|
|
18
|
+
*
|
|
19
|
+
* A Session in that set can never run a turn: the Host's archived-session
|
|
20
|
+
* gate rejects its first step before any model request is issued, so a
|
|
21
|
+
* launch that prompts into one settles as the opaque failure `agent turn
|
|
22
|
+
* ended without completing: blocked`. A card that keeps one conversation may
|
|
23
|
+
* still lose it to a bulk archive of the sidebar, and every later scheduled
|
|
24
|
+
* run would fail there, so reuse has to step aside instead of dying.
|
|
25
|
+
*
|
|
26
|
+
* Absent means this deployment's registry face cannot report an archive set.
|
|
27
|
+
* That is unknown evidence, never proof that nothing is archived: the rule
|
|
28
|
+
* then keeps its pre-archive-set behavior instead of inventing a refusal,
|
|
29
|
+
* because a registry face without the getter serves no archive action for the
|
|
30
|
+
* board to defend against.
|
|
31
|
+
*/
|
|
32
|
+
archivedSessionIds?: ReadonlySet<string>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The session the newest settled execution ran in, or undefined when no
|
|
37
|
+
* execution carries one.
|
|
38
|
+
*
|
|
39
|
+
* The launch path calls the reuse rule after `startExecution` appended this
|
|
40
|
+
* run's own open record, so the array tail is always an unsettled row at that
|
|
41
|
+
* point and the scan has to skip it (issue #1587).
|
|
42
|
+
* @param task - the task whose history is read.
|
|
43
|
+
* @returns the newest settled session id, if any.
|
|
44
|
+
*/
|
|
45
|
+
export function newestSettledSessionId(task: TaskRecord): string | undefined {
|
|
46
|
+
for (let index = task.executions.length - 1; index >= 0; index -= 1) {
|
|
47
|
+
const candidate: ExecutionRecord | undefined = task.executions[index]
|
|
48
|
+
if (candidate !== undefined && candidate.sessionId !== undefined && candidate.endedAt !== undefined) return candidate.sessionId
|
|
49
|
+
}
|
|
50
|
+
return undefined
|
|
51
|
+
}
|
|
52
|
+
|
|
8
53
|
/**
|
|
9
54
|
* Pick the session a new execution of this task may continue in, or undefined
|
|
10
55
|
* to mint a fresh conversation. Reuse requires ALL of:
|
|
11
|
-
* - the task opted in (`reuseSession === true`);
|
|
12
|
-
* - the task's newest
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - the roster is known and that session is present and idle.
|
|
56
|
+
* - the task opted in (`reuseSession === true`) unless the caller forces it;
|
|
57
|
+
* - the task's newest settled execution carries a session id (issue #1587);
|
|
58
|
+
* - the roster is known and that session is present and idle;
|
|
59
|
+
* - that session is not archived, when the deployment reports an archive set
|
|
60
|
+
* (issue #2068).
|
|
17
61
|
*
|
|
18
62
|
* An unknown roster (session/list unavailable) never reuses: minting a fresh
|
|
19
63
|
* conversation is always safe, prompting into a session we cannot see is not.
|
|
64
|
+
* An archived session is refused for the same reason — the Host will not run a
|
|
65
|
+
* turn in it, so continuing there can only fail the run that tried.
|
|
20
66
|
* @param task - the task about to run.
|
|
21
67
|
* @param idleSessionIds - ids the last roster saw as present and not running;
|
|
22
68
|
* undefined when that roster is unknown.
|
|
23
|
-
* @param options
|
|
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.
|
|
69
|
+
* @param options - force and the archive set; see {@link ReuseOptions}.
|
|
27
70
|
* @returns the session id to continue in, or undefined for a fresh session.
|
|
28
71
|
*/
|
|
29
72
|
export function reusableSessionId(
|
|
30
73
|
task: TaskRecord,
|
|
31
74
|
idleSessionIds: ReadonlySet<string> | undefined,
|
|
32
|
-
options:
|
|
75
|
+
options: ReuseOptions = {},
|
|
33
76
|
): string | undefined {
|
|
34
77
|
if (options.force !== true && task.reuseSession !== true) return undefined
|
|
35
78
|
if (idleSessionIds === undefined) return undefined
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
last = candidate
|
|
41
|
-
break
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (last === undefined || last.sessionId === undefined) return undefined
|
|
45
|
-
return idleSessionIds.has(last.sessionId) ? last.sessionId : undefined
|
|
79
|
+
const newest = newestSettledSessionId(task)
|
|
80
|
+
if (newest === undefined) return undefined
|
|
81
|
+
if (options.archivedSessionIds?.has(newest) === true) return undefined
|
|
82
|
+
return idleSessionIds.has(newest) ? newest : undefined
|
|
46
83
|
}
|
package/src/core/store.ts
CHANGED
|
@@ -280,6 +280,8 @@ export function parseLedger(raw: string | null): TaskRecord[] {
|
|
|
280
280
|
// is what the history is for, and only its instructions are unrecoverable.
|
|
281
281
|
rework: normalizeExecutionRework(execution.rework),
|
|
282
282
|
external: execution.external === true ? true : undefined,
|
|
283
|
+
errorCode: typeof execution.errorCode === 'string' && execution.errorCode !== '' ? execution.errorCode : undefined,
|
|
284
|
+
retryHint: typeof execution.retryHint === 'string' && execution.retryHint !== '' ? execution.retryHint : undefined,
|
|
283
285
|
}))
|
|
284
286
|
// Execution targets are normalized like the schedule: blank strings
|
|
285
287
|
// clear the pin and unknown permission strings from a future version
|
package/src/core/tasks.ts
CHANGED
|
@@ -27,8 +27,11 @@ export type ExecutionOutcome = 'succeeded' | 'failed' | 'cancelled'
|
|
|
27
27
|
export interface ExecutionSummary {
|
|
28
28
|
/** Last assistant message text of the run, bounded by {@link EXECUTION_SUMMARY_LIMIT}. */
|
|
29
29
|
text: string
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Seq of the session event that text came from. Absent on an external run's
|
|
32
|
+
* conclusion, which was never read out of a Host session.
|
|
33
|
+
*/
|
|
34
|
+
seq?: number
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/**
|
|
@@ -75,8 +78,16 @@ export interface ExecutionRecord {
|
|
|
75
78
|
endedAt: number | undefined
|
|
76
79
|
/** Outcome once settled. */
|
|
77
80
|
result: ExecutionOutcome | undefined
|
|
78
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Human failure text when the run failed (prompt rejection or agent error).
|
|
83
|
+
* Only a failure writes it: an external run's success conclusion rides
|
|
84
|
+
* {@link ExecutionRecord.summary}.
|
|
85
|
+
*/
|
|
79
86
|
error: string | undefined
|
|
87
|
+
/** Stable machine-readable failure code a provider reported with the verdict. */
|
|
88
|
+
errorCode?: string
|
|
89
|
+
/** One line telling the caller whether and how to retry a failed external run. */
|
|
90
|
+
retryHint?: string
|
|
80
91
|
/**
|
|
81
92
|
* Session id of the DSH session that issued the run/rerun action (issue #6
|
|
82
93
|
* audit origin). Client-asserted, not a trust boundary; absent when the run
|
|
@@ -472,8 +483,8 @@ export interface TaskRecord {
|
|
|
472
483
|
* Whether later executions continue in the previous execution's session
|
|
473
484
|
* (issue #1419) instead of minting a fresh conversation per run. Absent or
|
|
474
485
|
* false keeps the historical one-session-per-execution behavior; the reuse
|
|
475
|
-
* itself only happens when that session is idle
|
|
476
|
-
* {@link reusableSessionId}).
|
|
486
|
+
* itself only happens when that session is idle, still present, and not
|
|
487
|
+
* archived (issue #2068; see {@link reusableSessionId}).
|
|
477
488
|
*/
|
|
478
489
|
reuseSession?: boolean
|
|
479
490
|
/**
|
package/src/host/agent-tools.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
import type { SetSchedulePatch } from '../core/use-cases/task-schedule.ts'
|
|
33
33
|
import type { TaskUpdatePatch } from '../core/use-cases/task-update.ts'
|
|
34
34
|
import type { TaskBoardAction, TaskBoardSnapshot } from '../protocol.ts'
|
|
35
|
+
import type { TaskBoardLaunchTrigger } from '../core/extension.ts'
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* The narrow Host face the tools need. TaskBoardHostService satisfies it
|
|
@@ -40,8 +41,29 @@ import type { TaskBoardAction, TaskBoardSnapshot } from '../protocol.ts'
|
|
|
40
41
|
export interface TaskBoardToolHost {
|
|
41
42
|
/** Current board snapshot (tasks + scheduler + power + deployment constants). */
|
|
42
43
|
snapshot(): TaskBoardSnapshot
|
|
43
|
-
/**
|
|
44
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Submit one confirmed Host action; returns the resulting snapshot. `trigger`
|
|
46
|
+
* names the entry that asked for a run when the tool knows it is the tool, so
|
|
47
|
+
* a provider's launch handler can tell an agent's run from a person's.
|
|
48
|
+
*/
|
|
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 }
|
|
45
67
|
}
|
|
46
68
|
|
|
47
69
|
/** Registered tool names, in registration order. */
|
|
@@ -125,7 +147,12 @@ function executionView(execution: ExecutionRecord): Record<string, unknown> {
|
|
|
125
147
|
startedAt: execution.startedAt,
|
|
126
148
|
...(execution.endedAt === undefined ? {} : { endedAt: execution.endedAt }),
|
|
127
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 }),
|
|
128
153
|
...(execution.error === undefined ? {} : { error: execution.error }),
|
|
154
|
+
...(execution.errorCode === undefined ? {} : { errorCode: execution.errorCode }),
|
|
155
|
+
...(execution.retryHint === undefined ? {} : { retryHint: execution.retryHint }),
|
|
129
156
|
// The session that asked for the run (audit only; client-asserted by the
|
|
130
157
|
// browser, the calling session here). On an external record it names the
|
|
131
158
|
// outside agent instead, which is what distinguishes it in the history.
|
|
@@ -153,8 +180,10 @@ function taskSummary(
|
|
|
153
180
|
task: TaskRecord,
|
|
154
181
|
tasks: readonly TaskRecord[],
|
|
155
182
|
sessionDefault: TaskPermission | undefined,
|
|
183
|
+
host?: TaskBoardToolHost,
|
|
156
184
|
): Record<string, unknown> {
|
|
157
185
|
const latest = task.executions.at(-1)
|
|
186
|
+
const remote = remoteView(host?.describeTask?.(task))
|
|
158
187
|
const subtaskCount = directSubtasks(tasks, task.id).length
|
|
159
188
|
return {
|
|
160
189
|
id: task.id,
|
|
@@ -177,9 +206,12 @@ function taskSummary(
|
|
|
177
206
|
...(task.permissionConfirmedAt === undefined ? {} : { permissionConfirmedAt: task.permissionConfirmedAt }),
|
|
178
207
|
// Whether this card may run at all: an elevated binding still needs a
|
|
179
208
|
// human confirmation, and only a human can give it.
|
|
180
|
-
|
|
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)
|
|
181
212
|
? { permissionPending: true }
|
|
182
213
|
: {}),
|
|
214
|
+
...(remote === undefined ? {} : { remote: remote.view }),
|
|
183
215
|
executionCount: task.executions.length,
|
|
184
216
|
...(latest === undefined ? {} : { latestExecution: executionView(latest) }),
|
|
185
217
|
createdAt: task.createdAt,
|
|
@@ -192,10 +224,11 @@ function taskDetail(
|
|
|
192
224
|
task: TaskRecord,
|
|
193
225
|
tasks: readonly TaskRecord[],
|
|
194
226
|
sessionDefault: TaskPermission | undefined,
|
|
227
|
+
host?: TaskBoardToolHost,
|
|
195
228
|
): Record<string, unknown> {
|
|
196
229
|
const parent = task.parentId === undefined ? undefined : tasks.find(item => item.id === task.parentId)
|
|
197
230
|
return {
|
|
198
|
-
...taskSummary(task, tasks, sessionDefault),
|
|
231
|
+
...taskSummary(task, tasks, sessionDefault, host),
|
|
199
232
|
prompt: task.prompt,
|
|
200
233
|
depth: taskDepth(tasks, task.id),
|
|
201
234
|
...(parent === undefined ? {} : { parent: { id: parent.id, title: parent.title, status: parent.status } }),
|
|
@@ -222,7 +255,7 @@ function taskDetail(
|
|
|
222
255
|
bundledAt: task.handover.bundledAt,
|
|
223
256
|
},
|
|
224
257
|
}),
|
|
225
|
-
subtasks: directSubtasks(tasks, task.id).map(child => taskSummary(child, tasks, sessionDefault)),
|
|
258
|
+
subtasks: directSubtasks(tasks, task.id).map(child => taskSummary(child, tasks, sessionDefault, host)),
|
|
226
259
|
executions: task.executions.slice(-10).map(executionView),
|
|
227
260
|
}
|
|
228
261
|
}
|
|
@@ -233,6 +266,15 @@ function openedExecutions(before: readonly ExecutionRecord[], after: readonly Ex
|
|
|
233
266
|
return after.filter(execution => !known.has(execution.id))
|
|
234
267
|
}
|
|
235
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
|
+
|
|
236
278
|
/** Board summary attached to task_board_list. */
|
|
237
279
|
function boardView(snapshot: TaskBoardSnapshot, maxSubtaskDepth: number): Record<string, unknown> {
|
|
238
280
|
const counts = { backlog: 0, todo: 0, running: 0, done: 0, failed: 0, archived: 0 }
|
|
@@ -293,7 +335,7 @@ function buildSetParentTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
293
335
|
)
|
|
294
336
|
const task = snapshot.tasks.find(item => item.id === args.taskId)
|
|
295
337
|
if (task === undefined) return refused('task-not-found', 'no task with id ' + args.taskId)
|
|
296
|
-
return json({ ok: true, task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
338
|
+
return json({ ok: true, task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
297
339
|
} catch (error) {
|
|
298
340
|
return refused('refused', messageOf(error))
|
|
299
341
|
}
|
|
@@ -309,6 +351,7 @@ function buildRunTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
309
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.',
|
|
310
352
|
'Clicking a subtask runs that subtask as its own root, again without opening anything for its descendants.',
|
|
311
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.',
|
|
312
355
|
'Executions consume real API quota. Sessions are created asynchronously, so read their ids and outcomes back with task_board_get.',
|
|
313
356
|
].join(' '),
|
|
314
357
|
parameters: {
|
|
@@ -323,6 +366,7 @@ function buildRunTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
323
366
|
crypto.randomUUID(),
|
|
324
367
|
{ kind: args.rerun === true ? 'rerun' : 'run', taskId: args.taskId },
|
|
325
368
|
callingSessionId(exec),
|
|
369
|
+
'tool',
|
|
326
370
|
)
|
|
327
371
|
const beforeById = new Map(before.tasks.map(task => [task.id, task]))
|
|
328
372
|
const started = snapshot.tasks.flatMap(task => {
|
|
@@ -335,15 +379,24 @@ function buildRunTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
335
379
|
}))
|
|
336
380
|
})
|
|
337
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
|
|
338
387
|
return json({
|
|
339
388
|
ok: true,
|
|
340
389
|
started,
|
|
341
|
-
...(
|
|
342
|
-
|
|
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.',
|
|
343
393
|
})
|
|
344
394
|
} catch (error) {
|
|
345
395
|
const message = messageOf(error)
|
|
346
|
-
|
|
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)
|
|
347
400
|
}
|
|
348
401
|
},
|
|
349
402
|
})
|
|
@@ -412,7 +465,7 @@ function buildManageTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
412
465
|
return json({
|
|
413
466
|
ok: true,
|
|
414
467
|
action: args.action,
|
|
415
|
-
...(task === undefined ? {} : { task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission) }),
|
|
468
|
+
...(task === undefined ? {} : { task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) }),
|
|
416
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.',
|
|
417
470
|
})
|
|
418
471
|
} catch (error) {
|
|
@@ -440,7 +493,7 @@ function buildManageTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
440
493
|
if (args.action === 'delete') return json({ ok: true, action: args.action, taskId: args.taskId })
|
|
441
494
|
const task = snapshot.tasks.find(item => item.id === args.taskId)
|
|
442
495
|
if (task === undefined) return refused('task-not-found', 'no task with id ' + args.taskId)
|
|
443
|
-
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) })
|
|
444
497
|
} catch (error) {
|
|
445
498
|
return refused('refused', messageOf(error))
|
|
446
499
|
}
|
|
@@ -500,7 +553,7 @@ function buildScheduleTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
500
553
|
return json({
|
|
501
554
|
ok: true,
|
|
502
555
|
schedule: task.schedule === undefined ? null : scheduleView(task.schedule),
|
|
503
|
-
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission),
|
|
556
|
+
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host),
|
|
504
557
|
})
|
|
505
558
|
} catch (error) {
|
|
506
559
|
return refused('refused', messageOf(error))
|
|
@@ -516,7 +569,7 @@ function buildListTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
516
569
|
description: [
|
|
517
570
|
'List tasks on the DSH task board (the Host-authoritative ledger behind the Web GUI task board).',
|
|
518
571
|
'Filters: status column, parentId (direct subtasks), rootsOnly, tag, free-text query, and archived inclusion.',
|
|
519
|
-
'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).',
|
|
520
573
|
'Use task_board_get for one task in full, task_board_create to add work, and task_board_run to execute it.',
|
|
521
574
|
].join(' '),
|
|
522
575
|
parameters: {
|
|
@@ -551,7 +604,7 @@ function buildListTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
551
604
|
board: boardView(snapshot, snapshot.maxSubtaskDepth ?? DEFAULT_SUBTASK_DEPTH),
|
|
552
605
|
total: matched.length,
|
|
553
606
|
count: Math.min(matched.length, limit),
|
|
554
|
-
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)),
|
|
555
608
|
})
|
|
556
609
|
},
|
|
557
610
|
})
|
|
@@ -574,7 +627,7 @@ function buildGetTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
574
627
|
const snapshot = host.snapshot()
|
|
575
628
|
const task = snapshot.tasks.find(item => item.id === args.taskId)
|
|
576
629
|
if (task === undefined) return refused('task-not-found', 'no task with id ' + args.taskId)
|
|
577
|
-
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
630
|
+
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
578
631
|
},
|
|
579
632
|
})
|
|
580
633
|
}
|
|
@@ -663,7 +716,7 @@ function buildCreateTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
663
716
|
const snapshot = await host.apply(crypto.randomUUID(), { kind: 'create', id, input }, callingSessionId(exec))
|
|
664
717
|
const task = snapshot.tasks.find(item => item.id === id)
|
|
665
718
|
if (task === undefined) return refused('create-failed', 'the Host did not confirm the new task')
|
|
666
|
-
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
719
|
+
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
667
720
|
} catch (error) {
|
|
668
721
|
return refused('refused', messageOf(error))
|
|
669
722
|
}
|
|
@@ -750,7 +803,7 @@ function buildUpdateTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
750
803
|
const snapshot = await host.apply(crypto.randomUUID(), { kind: 'update', taskId: args.taskId, patch }, callingSessionId(exec))
|
|
751
804
|
const task = snapshot.tasks.find(item => item.id === args.taskId)
|
|
752
805
|
if (task === undefined) return refused('task-not-found', 'no task with id ' + args.taskId)
|
|
753
|
-
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission) })
|
|
806
|
+
return json({ ok: true, task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) })
|
|
754
807
|
} catch (error) {
|
|
755
808
|
return refused('refused', messageOf(error))
|
|
756
809
|
}
|
|
@@ -26,6 +26,10 @@ import {
|
|
|
26
26
|
type TaskBoardExtensionHost,
|
|
27
27
|
type TaskBoardExtensionPayload,
|
|
28
28
|
type TaskBoardIntegrationFace,
|
|
29
|
+
type TaskBoardLaunchContext,
|
|
30
|
+
type TaskBoardLaunchDecision,
|
|
31
|
+
type TaskBoardLaunchFace,
|
|
32
|
+
type TaskBoardLaunchHandler,
|
|
29
33
|
type TaskBoardLinkedTask,
|
|
30
34
|
type TaskBoardSessionsFace,
|
|
31
35
|
type TaskBoardStatusChangedEvent,
|
|
@@ -82,6 +86,8 @@ export interface TaskBoardExtensionRegistryOptions {
|
|
|
82
86
|
rework?: TaskBoardReworkApplier
|
|
83
87
|
/** Resolve the deployment's tool registry; absent loses the tool surface only. */
|
|
84
88
|
toolRegistry?: () => TaskBoardExtensionToolRegistry | undefined
|
|
89
|
+
/** Notified whenever a provider publishes, changes, or withdraws its summary. */
|
|
90
|
+
onPublished?: () => void
|
|
85
91
|
now?: () => number
|
|
86
92
|
uuid?: () => string
|
|
87
93
|
logger?: TaskBoardExtensionLogger
|
|
@@ -99,6 +105,8 @@ interface RegistryEntry {
|
|
|
99
105
|
readonly subscriptions: Record<keyof TaskBoardEventFace, Set<RegistryEventCallback>>
|
|
100
106
|
/** Tool definitions the provider registered, with their live disposers. */
|
|
101
107
|
tools: Array<{ definition: ToolDefinition; dispose?: () => void }>
|
|
108
|
+
/** Launch handlers this provider holds, in registration order. */
|
|
109
|
+
readonly launchHandlers: Set<TaskBoardLaunchHandler>
|
|
102
110
|
published?: TaskBoardExtensionPayload
|
|
103
111
|
}
|
|
104
112
|
|
|
@@ -176,6 +184,51 @@ function extensionText(value: string, what: string): string {
|
|
|
176
184
|
return text
|
|
177
185
|
}
|
|
178
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Read one handler answer as a launch decision.
|
|
189
|
+
*
|
|
190
|
+
* A handler is provider code reached synchronously from the launch path, so its
|
|
191
|
+
* return value is judged here instead of trusted: anything the board cannot act
|
|
192
|
+
* on is reported and treated as "not mine", exactly like a throw. A local
|
|
193
|
+
* decision with a blank preamble is normalized to no preamble, so a provider
|
|
194
|
+
* that answers local to take no visible part changes nothing at all.
|
|
195
|
+
* @param answer - what the handler returned.
|
|
196
|
+
* @param warn - sink for a refusal the provider can read.
|
|
197
|
+
* @returns the decision to act on, or undefined.
|
|
198
|
+
*/
|
|
199
|
+
function launchDecision(
|
|
200
|
+
answer: unknown,
|
|
201
|
+
warn: (message: string) => void,
|
|
202
|
+
): TaskBoardLaunchDecision | undefined {
|
|
203
|
+
if (answer === undefined) return undefined
|
|
204
|
+
if (typeof answer !== 'object' || answer === null) {
|
|
205
|
+
warn('returned a non-object decision')
|
|
206
|
+
return undefined
|
|
207
|
+
}
|
|
208
|
+
const kind = (answer as { kind?: unknown }).kind
|
|
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
|
+
}
|
|
218
|
+
if (kind !== 'local') {
|
|
219
|
+
warn('returned an unknown decision kind')
|
|
220
|
+
return undefined
|
|
221
|
+
}
|
|
222
|
+
const preamble = (answer as { promptPreamble?: unknown }).promptPreamble
|
|
223
|
+
if (preamble === undefined) return { kind: 'local' }
|
|
224
|
+
if (typeof preamble !== 'string') {
|
|
225
|
+
warn('returned a non-string promptPreamble')
|
|
226
|
+
return undefined
|
|
227
|
+
}
|
|
228
|
+
const trimmed = preamble.trim()
|
|
229
|
+
return trimmed === '' ? { kind: 'local' } : { kind: 'local', promptPreamble: trimmed }
|
|
230
|
+
}
|
|
231
|
+
|
|
179
232
|
/**
|
|
180
233
|
* The session a follow-up message goes to, or the refusal that says why there
|
|
181
234
|
* is none. The open execution owns the answer while one is running: delivering
|
|
@@ -208,6 +261,8 @@ export class TaskBoardExtensionRegistry {
|
|
|
208
261
|
private readonly uuid: () => string
|
|
209
262
|
private readonly logger: TaskBoardExtensionLogger
|
|
210
263
|
private toolResolver: (() => TaskBoardExtensionToolRegistry | undefined) | undefined
|
|
264
|
+
private readonly onPublished: (() => void) | undefined
|
|
265
|
+
private publishedVersionCounter = 0
|
|
211
266
|
/** Board master switch (enabled config); providers start only while it is on. */
|
|
212
267
|
private boardEnabled = true
|
|
213
268
|
private disposed = false
|
|
@@ -221,6 +276,12 @@ export class TaskBoardExtensionRegistry {
|
|
|
221
276
|
this.uuid = options.uuid ?? (() => crypto.randomUUID())
|
|
222
277
|
this.logger = options.logger ?? DEFAULT_LOGGER
|
|
223
278
|
this.toolResolver = options.toolRegistry
|
|
279
|
+
this.onPublished = options.onPublished
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Monotonic revision of the published extension summaries map. */
|
|
283
|
+
get publishedRevision(): number {
|
|
284
|
+
return this.publishedVersionCounter
|
|
224
285
|
}
|
|
225
286
|
|
|
226
287
|
/**
|
|
@@ -272,7 +333,7 @@ export class TaskBoardExtensionRegistry {
|
|
|
272
333
|
this.logger.error('[dsh-task-board] ' + message)
|
|
273
334
|
throw new TaskBoardExtensionError('api-version-mismatch', message)
|
|
274
335
|
}
|
|
275
|
-
const entry: RegistryEntry = { extension, active: false, subscriptions: emptySubscriptions(), tools: [] }
|
|
336
|
+
const entry: RegistryEntry = { extension, active: false, subscriptions: emptySubscriptions(), tools: [], launchHandlers: new Set() }
|
|
276
337
|
this.entries.set(extension.id, entry)
|
|
277
338
|
this.reconcile(entry)
|
|
278
339
|
return () => { this.unregister(extension.id) }
|
|
@@ -305,6 +366,70 @@ export class TaskBoardExtensionRegistry {
|
|
|
305
366
|
return await handler.call(entry.extension, request)
|
|
306
367
|
}
|
|
307
368
|
|
|
369
|
+
/**
|
|
370
|
+
* The board's single launch gate: ask every running provider whether this run
|
|
371
|
+
* is theirs.
|
|
372
|
+
*
|
|
373
|
+
* Consulted by the ledger at the one point every trigger passes — before a
|
|
374
|
+
* session exists and before an execution record is written — so the order
|
|
375
|
+
* here is the only ordering a provider can observe: registration order, first
|
|
376
|
+
* decision wins. A handler that throws is isolated and treated as "not mine",
|
|
377
|
+
* exactly as if it had answered undefined, because a provider's bug must cost
|
|
378
|
+
* its own interception and never the launch. Without a registered handler
|
|
379
|
+
* this answers nothing at all and the launch path is untouched.
|
|
380
|
+
* @param task - the card about to run.
|
|
381
|
+
* @param context - which entry asked for this run.
|
|
382
|
+
* @returns the first decision a running provider made, or undefined.
|
|
383
|
+
*/
|
|
384
|
+
interceptLaunch(task: TaskRecord, context: TaskBoardLaunchContext): TaskBoardLaunchDecision | undefined {
|
|
385
|
+
if (this.disposed) return undefined
|
|
386
|
+
for (const entry of this.entries.values()) {
|
|
387
|
+
if (!entry.active) continue
|
|
388
|
+
for (const handler of [...entry.launchHandlers]) {
|
|
389
|
+
let answer: unknown
|
|
390
|
+
try {
|
|
391
|
+
answer = handler(task, context)
|
|
392
|
+
} catch (error) {
|
|
393
|
+
this.logger.error(`[dsh-task-board] extension "${entry.extension.id}" launch handler failed; the launch proceeds unhandled`, error)
|
|
394
|
+
continue
|
|
395
|
+
}
|
|
396
|
+
const decision = launchDecision(answer, (message) => {
|
|
397
|
+
this.logger.warn(`[dsh-task-board] extension "${entry.extension.id}" launch handler ${message}; the launch proceeds unhandled`)
|
|
398
|
+
})
|
|
399
|
+
if (decision !== undefined) return decision
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return undefined
|
|
403
|
+
}
|
|
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
|
+
|
|
308
433
|
/** Published summaries of currently running providers, keyed by extension id. */
|
|
309
434
|
published(): Record<string, TaskBoardExtensionPayload> {
|
|
310
435
|
const result: Record<string, TaskBoardExtensionPayload> = {}
|
|
@@ -376,6 +501,7 @@ export class TaskBoardExtensionRegistry {
|
|
|
376
501
|
}
|
|
377
502
|
|
|
378
503
|
private stopEntry(entry: RegistryEntry): void {
|
|
504
|
+
const hadPublished = entry.published !== undefined
|
|
379
505
|
if (entry.active) {
|
|
380
506
|
entry.active = false
|
|
381
507
|
for (const kind of Object.keys(entry.subscriptions) as Array<keyof TaskBoardEventFace>) {
|
|
@@ -387,10 +513,17 @@ export class TaskBoardExtensionRegistry {
|
|
|
387
513
|
this.logger.error(`[dsh-task-board] extension "${entry.extension.id}" stop() failed`, error)
|
|
388
514
|
}
|
|
389
515
|
}
|
|
516
|
+
entry.published = undefined
|
|
390
517
|
this.disposeTools(entry)
|
|
391
518
|
// A stopped provider re-registers its tools from start(); keeping the old
|
|
392
|
-
// definitions would double-register them on the next enable.
|
|
519
|
+
// definitions would double-register them on the next enable. Launch
|
|
520
|
+
// handlers go with them: a switched-off provider is never consulted.
|
|
393
521
|
entry.tools.length = 0
|
|
522
|
+
entry.launchHandlers.clear()
|
|
523
|
+
if (hadPublished) {
|
|
524
|
+
this.publishedVersionCounter += 1
|
|
525
|
+
if (!this.disposed) this.onPublished?.()
|
|
526
|
+
}
|
|
394
527
|
}
|
|
395
528
|
|
|
396
529
|
/** (Re)register every buffered tool against the current tool registry. */
|
|
@@ -463,9 +596,16 @@ export class TaskBoardExtensionRegistry {
|
|
|
463
596
|
onExecutionSettled: (callback) => subscribe('onExecutionSettled', callback as RegistryEventCallback),
|
|
464
597
|
onTaskDeleted: (callback) => subscribe('onTaskDeleted', callback as RegistryEventCallback),
|
|
465
598
|
}
|
|
599
|
+
const launch: TaskBoardLaunchFace = {
|
|
600
|
+
intercept: (handler) => {
|
|
601
|
+
assertActive('intercept a launch')
|
|
602
|
+
return this.addLaunchHandler(entry, handler)
|
|
603
|
+
},
|
|
604
|
+
}
|
|
466
605
|
return {
|
|
467
606
|
tasks,
|
|
468
607
|
sessions,
|
|
608
|
+
launch,
|
|
469
609
|
integration,
|
|
470
610
|
events,
|
|
471
611
|
publish: (summary) => { this.publish(entry, summary) },
|
|
@@ -634,6 +774,21 @@ export class TaskBoardExtensionRegistry {
|
|
|
634
774
|
throw new TaskBoardExtensionError('invalid-payload', 'published summary must be a pure JSON object within the size limit')
|
|
635
775
|
}
|
|
636
776
|
entry.published = summary
|
|
777
|
+
this.publishedVersionCounter += 1
|
|
778
|
+
this.onPublished?.()
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Hold one launch handler for a running provider. The handler is dropped when
|
|
783
|
+
* the provider stops or is unregistered, so the disposer only has to cover the
|
|
784
|
+
* provider's own early withdrawal.
|
|
785
|
+
*/
|
|
786
|
+
private addLaunchHandler(entry: RegistryEntry, handler: TaskBoardLaunchHandler): () => void {
|
|
787
|
+
if (typeof handler !== 'function') {
|
|
788
|
+
throw new TaskBoardExtensionError('invalid-handler', 'a launch handler must be a function')
|
|
789
|
+
}
|
|
790
|
+
entry.launchHandlers.add(handler)
|
|
791
|
+
return () => { entry.launchHandlers.delete(handler) }
|
|
637
792
|
}
|
|
638
793
|
|
|
639
794
|
private registerTool(entry: RegistryEntry, definition: ToolDefinition): () => void {
|