@linxin666/dsh-client-ui-task-board 0.4.19 → 0.4.20
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 +179 -60
- package/lib/client.js.map +1 -1
- package/lib/index.js +457 -70
- 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 +135 -1
- package/lib/types/core/session-reuse.d.ts +46 -13
- package/lib/types/core/tasks.d.ts +2 -2
- package/lib/types/host/agent-tools.d.ts +7 -2
- package/lib/types/host/extension-registry.d.ts +30 -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 +59 -14
- package/lib/types/protocol.d.ts +9 -1
- package/package.json +1 -1
- package/src/client/board/ExecutionLog.tsx +9 -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/extension.ts +138 -1
- package/src/core/session-reuse.ts +58 -21
- package/src/core/tasks.ts +2 -2
- package/src/host/agent-tools.ts +8 -2
- package/src/host/extension-registry.ts +121 -2
- package/src/host-ledger.ts +252 -18
- package/src/host-runner.ts +44 -5
- package/src/host-service.ts +180 -37
- package/src/protocol.ts +9 -1
package/src/client/seats.tsx
CHANGED
|
@@ -4,27 +4,30 @@
|
|
|
4
4
|
*
|
|
5
5
|
* The framework hands the declaring component a `renderSlot` binding; the board
|
|
6
6
|
* wraps that binding in a React context so a provider's contribution can render
|
|
7
|
-
* deep inside TaskDetail, the card,
|
|
8
|
-
* components knowing which providers exist.
|
|
7
|
+
* deep inside TaskDetail, the card, the settings card, or the create dialog
|
|
8
|
+
* without those components knowing which providers exist.
|
|
9
9
|
*
|
|
10
10
|
* @module dsh-task-board/client/seats
|
|
11
11
|
*/
|
|
12
|
-
import { createContext, useContext } from 'react'
|
|
12
|
+
import { Component, createContext, useContext } from 'react'
|
|
13
13
|
import type { ReactNode } from 'react'
|
|
14
14
|
import {
|
|
15
15
|
TASK_BOARD_CARD_DECORATION,
|
|
16
|
+
TASK_BOARD_COMPOSE_SECTION,
|
|
16
17
|
TASK_BOARD_DETAIL_SECTION,
|
|
17
18
|
TASK_BOARD_SETTINGS_SECTION,
|
|
18
19
|
type TaskBoardCardDecorationProps,
|
|
20
|
+
type TaskBoardComposeSectionProps,
|
|
19
21
|
type TaskBoardDetailSectionProps,
|
|
20
22
|
type TaskBoardSettingsSectionProps,
|
|
21
23
|
} from '../core/extension.ts'
|
|
22
24
|
|
|
23
|
-
/** The
|
|
25
|
+
/** The four provider seats, adapted to plain render functions. */
|
|
24
26
|
export interface TaskBoardSeats {
|
|
25
27
|
detailSection: (props: TaskBoardDetailSectionProps) => ReactNode
|
|
26
28
|
settingsSection: (props: TaskBoardSettingsSectionProps) => ReactNode
|
|
27
29
|
cardDecoration: (props: TaskBoardCardDecorationProps) => ReactNode
|
|
30
|
+
composeSection: (props: TaskBoardComposeSectionProps) => ReactNode
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
/** Nothing registered: every seat renders empty. */
|
|
@@ -32,6 +35,7 @@ export const EMPTY_TASK_BOARD_SEATS: TaskBoardSeats = {
|
|
|
32
35
|
detailSection: () => null,
|
|
33
36
|
settingsSection: () => null,
|
|
34
37
|
cardDecoration: () => null,
|
|
38
|
+
composeSection: () => null,
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/** The framework `renderSlot` binding shape (key + owner props share). */
|
|
@@ -44,6 +48,30 @@ export function seatsFromRenderSlot(renderSlot: SlotRenderBinding | undefined):
|
|
|
44
48
|
detailSection: props => renderSlot(TASK_BOARD_DETAIL_SECTION, props as unknown as Record<string, unknown>),
|
|
45
49
|
settingsSection: props => renderSlot(TASK_BOARD_SETTINGS_SECTION, props as unknown as Record<string, unknown>),
|
|
46
50
|
cardDecoration: props => renderSlot(TASK_BOARD_CARD_DECORATION, props as unknown as Record<string, unknown>),
|
|
51
|
+
composeSection: props => renderSlot(TASK_BOARD_COMPOSE_SECTION, props as unknown as Record<string, unknown>),
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Isolation for one seat whose providers render outside the framework's own
|
|
57
|
+
* per-entry boundary: a provider that throws while rendering contributes
|
|
58
|
+
* nothing here instead of taking the surface around the seat down with it.
|
|
59
|
+
* Nothing is rendered in that case — the seat is optional, so its absence is
|
|
60
|
+
* the honest state — and the failure is logged once for the provider's author.
|
|
61
|
+
*/
|
|
62
|
+
export class TaskBoardSeatBoundary extends Component<{ children: ReactNode }, { failed: boolean }> {
|
|
63
|
+
state = { failed: false }
|
|
64
|
+
|
|
65
|
+
static getDerivedStateFromError(): { failed: boolean } {
|
|
66
|
+
return { failed: true }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
componentDidCatch(error: unknown): void {
|
|
70
|
+
console.error('[dsh-task-board] a provider seat failed to render', error)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
render(): ReactNode {
|
|
74
|
+
return this.state.failed ? null : this.props.children
|
|
47
75
|
}
|
|
48
76
|
}
|
|
49
77
|
|
package/src/client/service.ts
CHANGED
|
@@ -101,6 +101,9 @@ export class TaskBoardClientService implements TaskBoardClientFace {
|
|
|
101
101
|
enabled: this.enabled,
|
|
102
102
|
tasks: (state?.tasks ?? []) as readonly TaskRecord[],
|
|
103
103
|
extensions: state?.extensions ?? {},
|
|
104
|
+
hydrated: state?.host !== undefined,
|
|
105
|
+
...(state?.executionOptions.workspaces === undefined ? {} : { workspaces: state.executionOptions.workspaces }),
|
|
106
|
+
...(state?.transportError === undefined ? {} : { lastError: state.transportError }),
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
|
|
@@ -141,11 +141,13 @@ export interface NumberConstraints {
|
|
|
141
141
|
integer?: boolean
|
|
142
142
|
/** The accepted value must be at least this. */
|
|
143
143
|
min?: number
|
|
144
|
+
/** The accepted value must be at most this. */
|
|
145
|
+
max?: number
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
/** A whole- or decimal-number field. An empty draft clears the field; any other draft that is not a finite number within the constraints stays unwritten. */
|
|
147
149
|
export function numberField(field: string, constraints: NumberConstraints = {}): FieldSpec {
|
|
148
|
-
const { integer = false, min } = constraints
|
|
150
|
+
const { integer = false, min, max } = constraints
|
|
149
151
|
return {
|
|
150
152
|
field,
|
|
151
153
|
entry: 'type',
|
|
@@ -157,6 +159,7 @@ export function numberField(field: string, constraints: NumberConstraints = {}):
|
|
|
157
159
|
if (!Number.isFinite(parsed)) return undefined
|
|
158
160
|
if (integer && !Number.isInteger(parsed)) return undefined
|
|
159
161
|
if (min !== undefined && parsed < min) return undefined
|
|
162
|
+
if (max !== undefined && parsed > max) return undefined
|
|
160
163
|
return { kind: 'set', value: parsed }
|
|
161
164
|
},
|
|
162
165
|
}
|
|
@@ -439,7 +442,7 @@ export class CardForm<T> {
|
|
|
439
442
|
// against. Settling is the only signal the form has; the rest of the
|
|
440
443
|
// batch, when one exists, still carries the atomic verdict by read-back.
|
|
441
444
|
if (this.specOf(field).secret) return true
|
|
442
|
-
return this.userLayer()?.[field]
|
|
445
|
+
return jsonValuesEqual(this.userLayer()?.[field], value)
|
|
443
446
|
}
|
|
444
447
|
|
|
445
448
|
/**
|
|
@@ -508,3 +511,19 @@ export class CardForm<T> {
|
|
|
508
511
|
for (const listener of this.listeners) listener()
|
|
509
512
|
}
|
|
510
513
|
}
|
|
514
|
+
|
|
515
|
+
/** Structural equality for JSON settings values (primitives, arrays, plain objects). */
|
|
516
|
+
function jsonValuesEqual(left: unknown, right: unknown): boolean {
|
|
517
|
+
if (Object.is(left, right)) return true
|
|
518
|
+
if (typeof left !== 'object' || left === null || typeof right !== 'object' || right === null) return false
|
|
519
|
+
if (Array.isArray(left) || Array.isArray(right)) {
|
|
520
|
+
if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false
|
|
521
|
+
return left.every((item, index) => jsonValuesEqual(item, right[index]))
|
|
522
|
+
}
|
|
523
|
+
const a = left as Record<string, unknown>
|
|
524
|
+
const b = right as Record<string, unknown>
|
|
525
|
+
const keysA = Object.keys(a).filter(key => a[key] !== undefined)
|
|
526
|
+
const keysB = Object.keys(b).filter(key => b[key] !== undefined)
|
|
527
|
+
if (keysA.length !== keysB.length) return false
|
|
528
|
+
return keysA.every(key => Object.hasOwn(b, key) && jsonValuesEqual(a[key], b[key]))
|
|
529
|
+
}
|
package/src/core/controller.ts
CHANGED
|
@@ -160,7 +160,7 @@ export interface ExecutionOptionsSnapshot {
|
|
|
160
160
|
* (revision/scheduler/power); a full snapshot also carries the deployment
|
|
161
161
|
* constants the UI reads (session default permission, subtask depth).
|
|
162
162
|
*/
|
|
163
|
-
export type HostMirror = Pick<TaskBoardSnapshot, 'revision' | 'scheduler' | 'power' | 'sessionDefaultPermission' | 'maxSubtaskDepth' | 'cardDefaults' | 'extensions' | 'attachmentLimits'>
|
|
163
|
+
export type HostMirror = Pick<TaskBoardSnapshot, 'revision' | 'extensionsRevision' | 'scheduler' | 'power' | 'sessionDefaultPermission' | 'maxSubtaskDepth' | 'cardDefaults' | 'extensions' | 'attachmentLimits'>
|
|
164
164
|
|
|
165
165
|
/** Immutable controller snapshot for UI subscriptions. */
|
|
166
166
|
export interface ControllerSnapshot {
|
|
@@ -853,7 +853,8 @@ export class BoardController {
|
|
|
853
853
|
* re-serialize the whole ledger per tab even while nothing changes.
|
|
854
854
|
*/
|
|
855
855
|
private onRemoteEvent(event: TaskBoardEventPayload | undefined): void {
|
|
856
|
-
|
|
856
|
+
const sameExtensions = event?.extensionsRevision === this.hostState?.extensionsRevision
|
|
857
|
+
if (event !== undefined && this.hostState !== undefined && event.revision === this.hostState.revision && sameExtensions
|
|
857
858
|
&& typeof event.scheduler === 'object' && event.scheduler !== null
|
|
858
859
|
&& typeof event.power === 'object' && event.power !== null) {
|
|
859
860
|
this.hostState = { ...this.hostState, revision: event.revision, scheduler: event.scheduler, power: event.power }
|
|
@@ -890,7 +891,11 @@ export class BoardController {
|
|
|
890
891
|
// value over would keep a CLEARED default alive in the create dialog, which
|
|
891
892
|
// is the mirror image of the staleness this key is re-read for.
|
|
892
893
|
const cardDefaults = snapshot.cardDefaults
|
|
893
|
-
|
|
894
|
+
// Published extension summaries are NOT carried over across snapshots: the
|
|
895
|
+
// Host omits `extensions` when the last running extension unmounts, so
|
|
896
|
+
// carrying over an earlier value would keep a stale summary alive forever.
|
|
897
|
+
const extensions = snapshot.extensions
|
|
898
|
+
const extensionsRevision = snapshot.extensionsRevision
|
|
894
899
|
// The attachment limits are carried over: a deployment that lowers them
|
|
895
900
|
// must keep the browser's refusal in step until the next snapshot.
|
|
896
901
|
const attachmentLimits = snapshot.attachmentLimits ?? this.hostState?.attachmentLimits
|
|
@@ -898,6 +903,7 @@ export class BoardController {
|
|
|
898
903
|
revision: snapshot.revision,
|
|
899
904
|
scheduler: snapshot.scheduler,
|
|
900
905
|
power: snapshot.power,
|
|
906
|
+
...(extensionsRevision === undefined ? {} : { extensionsRevision }),
|
|
901
907
|
...(sessionDefaultPermission === undefined ? {} : { sessionDefaultPermission }),
|
|
902
908
|
...(maxSubtaskDepth === undefined ? {} : { maxSubtaskDepth }),
|
|
903
909
|
...(cardDefaults === undefined ? {} : { cardDefaults }),
|
package/src/core/extension.ts
CHANGED
|
@@ -31,12 +31,19 @@ export const TASK_BOARD_DETAIL_SECTION = 'task-board.detail.section'
|
|
|
31
31
|
export const TASK_BOARD_SETTINGS_SECTION = 'task-board.settings.section'
|
|
32
32
|
/** Child seat a provider registers its card decoration into. */
|
|
33
33
|
export const TASK_BOARD_CARD_DECORATION = 'task-board.card.decoration'
|
|
34
|
+
/**
|
|
35
|
+
* Child seat a provider registers its new-card section into: its own
|
|
36
|
+
* create-time configuration, rendered inside the create dialog's execution
|
|
37
|
+
* settings, whose draft the board stores on the card it creates.
|
|
38
|
+
*/
|
|
39
|
+
export const TASK_BOARD_COMPOSE_SECTION = 'task-board.compose.section'
|
|
34
40
|
|
|
35
41
|
/** Every child seat the board declares for extensions, in render order. */
|
|
36
42
|
export const TASK_BOARD_EXTENSION_SEATS: readonly string[] = [
|
|
37
43
|
TASK_BOARD_DETAIL_SECTION,
|
|
38
44
|
TASK_BOARD_SETTINGS_SECTION,
|
|
39
45
|
TASK_BOARD_CARD_DECORATION,
|
|
46
|
+
TASK_BOARD_COMPOSE_SECTION,
|
|
40
47
|
]
|
|
41
48
|
|
|
42
49
|
/**
|
|
@@ -267,6 +274,79 @@ export interface TaskBoardSessionsFace {
|
|
|
267
274
|
followUp(taskId: string, text: string): Promise<void>
|
|
268
275
|
}
|
|
269
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Why the board is opening a run. The four entries reach the launch path from
|
|
279
|
+
* different places and a provider may want to answer only some of them: the
|
|
280
|
+
* board's own run action ({@link 'manual'}), a settled card sent back to run
|
|
281
|
+
* again ({@link 'rerun'}), an armed schedule ({@link 'schedule'}), and the
|
|
282
|
+
* `task_board_run` model-visible tool ({@link 'tool'}).
|
|
283
|
+
*
|
|
284
|
+
* A rework arrives as `manual`: it is the same human entry point, opening a
|
|
285
|
+
* run in the card's own conversation rather than a fresh one.
|
|
286
|
+
*/
|
|
287
|
+
export type TaskBoardLaunchTrigger = 'manual' | 'rerun' | 'schedule' | 'tool'
|
|
288
|
+
|
|
289
|
+
/** Context of one launch the board is about to open. */
|
|
290
|
+
export interface TaskBoardLaunchContext {
|
|
291
|
+
/** Which entry asked for this run. */
|
|
292
|
+
trigger: TaskBoardLaunchTrigger
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* What a launch handler decided for one run.
|
|
297
|
+
*
|
|
298
|
+
* `local` keeps the board's own execution and only adds context, so a provider
|
|
299
|
+
* that runs a card through an ordinary session (a session told to drive
|
|
300
|
+
* something else, for instance) reads exactly the launch the board would have
|
|
301
|
+
* made. `external` hands the whole run to the provider: the board opens no
|
|
302
|
+
* session and writes no execution record.
|
|
303
|
+
*/
|
|
304
|
+
export type TaskBoardLaunchDecision =
|
|
305
|
+
/**
|
|
306
|
+
* Run the card locally through the board's own session, with `promptPreamble`
|
|
307
|
+
* injected ahead of the card's prompt on the same path the board's tag
|
|
308
|
+
* prompts take. A blank preamble injects nothing.
|
|
309
|
+
*/
|
|
310
|
+
| { kind: 'local'; promptPreamble?: string }
|
|
311
|
+
/**
|
|
312
|
+
* The provider takes this run over. The board creates no session and records
|
|
313
|
+
* no execution; it only moves the card into the running column, which is
|
|
314
|
+
* already the board's own way of saying work is under way outside a Host-run
|
|
315
|
+
* session. The provider closes the card through the existing
|
|
316
|
+
* `record-external-outcome` action once its own run settles.
|
|
317
|
+
*/
|
|
318
|
+
| { kind: 'external' }
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Decide whether one launch belongs to the provider, and how it runs.
|
|
322
|
+
* @param task - the card about to run.
|
|
323
|
+
* @param context - which entry asked for this run.
|
|
324
|
+
* @returns a decision, or undefined to leave the run to the board unchanged.
|
|
325
|
+
*/
|
|
326
|
+
export type TaskBoardLaunchHandler = (
|
|
327
|
+
task: TaskRecord,
|
|
328
|
+
context: TaskBoardLaunchContext,
|
|
329
|
+
) => TaskBoardLaunchDecision | undefined
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Launch interception: the seam through which a provider takes a run over.
|
|
333
|
+
*
|
|
334
|
+
* The board consults the registered handlers at its single launch gate — before
|
|
335
|
+
* any session exists and before any execution record is written — for every
|
|
336
|
+
* trigger. Handlers run in registration order and the first one that answers
|
|
337
|
+
* anything other than undefined decides that launch. A handler that throws is
|
|
338
|
+
* isolated and treated as undefined, so a broken provider costs one run's
|
|
339
|
+
* interception and never the launch itself.
|
|
340
|
+
*/
|
|
341
|
+
export interface TaskBoardLaunchFace {
|
|
342
|
+
/**
|
|
343
|
+
* Register one launch handler. The returned disposer unregisters it, and the
|
|
344
|
+
* handler is released with the extension's own stop, so a switched-off
|
|
345
|
+
* provider is never consulted.
|
|
346
|
+
*/
|
|
347
|
+
intercept(handler: TaskBoardLaunchHandler): () => void
|
|
348
|
+
}
|
|
349
|
+
|
|
270
350
|
/** Storage face for one extension's own payload on a task. */
|
|
271
351
|
export interface TaskBoardIntegrationFace {
|
|
272
352
|
/** Read this extension's payload, or undefined when the task carries none. */
|
|
@@ -324,6 +404,14 @@ export interface TaskBoardExtensionHost {
|
|
|
324
404
|
* probes the face and keeps working against a board that serves none.
|
|
325
405
|
*/
|
|
326
406
|
sessions?: TaskBoardSessionsFace
|
|
407
|
+
/**
|
|
408
|
+
* Launch interception: the provider decides, per run, whether the board's own
|
|
409
|
+
* session launches it or whether this provider takes the run over. Optional
|
|
410
|
+
* on the same terms as {@link TaskBoardExtensionHost.sessions} — the API
|
|
411
|
+
* version stays 1, so a provider probes the face before using it, and a board
|
|
412
|
+
* that serves no launch gate keeps launching every card itself.
|
|
413
|
+
*/
|
|
414
|
+
launch?: TaskBoardLaunchFace
|
|
327
415
|
integration: TaskBoardIntegrationFace
|
|
328
416
|
events: TaskBoardEventFace
|
|
329
417
|
/**
|
|
@@ -359,6 +447,16 @@ export interface TaskBoardClientMirror {
|
|
|
359
447
|
tasks: readonly TaskRecord[]
|
|
360
448
|
/** Published extension summaries, keyed by extension id (opaque to the board). */
|
|
361
449
|
extensions: Readonly<Record<string, unknown>>
|
|
450
|
+
/**
|
|
451
|
+
* Whether at least one authoritative Host snapshot has arrived in this page.
|
|
452
|
+
* Absent on older boards or test mirrors; false while `/bootstrap` is still
|
|
453
|
+
* in flight, so providers do not misread an initial empty `{}` as unmounted.
|
|
454
|
+
*/
|
|
455
|
+
hydrated?: boolean
|
|
456
|
+
/** Local workspaces registered in the runtime, for provider workspace pickers. */
|
|
457
|
+
workspaces?: readonly { workspaceId: string; title: string }[]
|
|
458
|
+
/** Last Host transport refusal message (e.g. a refused extension action), when any. */
|
|
459
|
+
lastError?: string
|
|
362
460
|
}
|
|
363
461
|
|
|
364
462
|
/** Whether a task should be shown on the board; false hides it. */
|
|
@@ -412,6 +510,40 @@ export interface TaskBoardCardDecorationProps {
|
|
|
412
510
|
task: TaskRecord
|
|
413
511
|
}
|
|
414
512
|
|
|
513
|
+
/** Optional metadata a provider reports alongside its new-card draft. */
|
|
514
|
+
export interface TaskBoardComposeDraftOptions {
|
|
515
|
+
/** One-line label included in the collapsed Run Mode summary. */
|
|
516
|
+
summary?: string
|
|
517
|
+
/**
|
|
518
|
+
* Validation blocker message: while non-empty, the create dialog refuses to
|
|
519
|
+
* submit or run locally and forces the Run Mode section open.
|
|
520
|
+
*/
|
|
521
|
+
error?: string
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** Owner props of the new-card compose seat. */
|
|
525
|
+
export interface TaskBoardComposeSectionProps {
|
|
526
|
+
/**
|
|
527
|
+
* Report the draft this provider wants written into the new card's
|
|
528
|
+
* `integrations` under `extensionId` — that is, what the board stores when
|
|
529
|
+
* the create dialog is submitted. The id is the provider's own extension id,
|
|
530
|
+
* the same key its payload lives under on every other card; a later call for
|
|
531
|
+
* the same id replaces the earlier draft instead of merging with it, and
|
|
532
|
+
* `undefined` withdraws it, so a provider that clears its picker leaves no
|
|
533
|
+
* entry behind. The draft stands until the dialog submits or its provider
|
|
534
|
+
* replaces or withdraws it, because collapsing the region that holds the seat
|
|
535
|
+
* must never discard a choice already made. The board never interprets the
|
|
536
|
+
* payload: a draft that is not a plain JSON object or that exceeds
|
|
537
|
+
* {@link TASK_BOARD_PAYLOAD_LIMIT_BYTES} is dropped from the card being
|
|
538
|
+
* created and named in one warning, and the create itself still happens.
|
|
539
|
+
*/
|
|
540
|
+
contribute(extensionId: string, payload: TaskBoardExtensionPayload | undefined, options?: TaskBoardComposeDraftOptions): void
|
|
541
|
+
/** Initial integrations of the source card when duplicating an existing card. */
|
|
542
|
+
initialIntegrations?: Readonly<Record<string, unknown>>
|
|
543
|
+
/** Incremented each time the user submits the dialog, so providers can reveal untouched field errors. */
|
|
544
|
+
submitAttempt?: number
|
|
545
|
+
}
|
|
546
|
+
|
|
415
547
|
/**
|
|
416
548
|
* Host-half service face published under {@link TASK_BOARD_SERVICE_NAME}. A
|
|
417
549
|
* provider package's host half resolves this from the shared cordis service
|
|
@@ -444,8 +576,13 @@ export interface TaskBoardHostFace {
|
|
|
444
576
|
* retries one envelope does not apply it twice. Refusals are the ledger's:
|
|
445
577
|
* they throw with the Host's own text, which is why this face adds no code
|
|
446
578
|
* table of its own.
|
|
579
|
+
*
|
|
580
|
+
* `trigger` says which entry asked for a run, when the caller knows better
|
|
581
|
+
* than the board's default: the `task_board_run` tool passes `tool` so a
|
|
582
|
+
* launch handler can tell an agent's run from a person's. Only a `run` action
|
|
583
|
+
* reads it — `rerun`, `rework` and the human run path are their own triggers.
|
|
447
584
|
*/
|
|
448
|
-
apply(requestId: string, action: TaskBoardAction, initiator?: string): TaskBoardSnapshot | Promise<TaskBoardSnapshot>
|
|
585
|
+
apply(requestId: string, action: TaskBoardAction, initiator?: string, trigger?: TaskBoardLaunchTrigger): TaskBoardSnapshot | Promise<TaskBoardSnapshot>
|
|
449
586
|
/**
|
|
450
587
|
* Follow the board's change notifications. The listener receives no payload —
|
|
451
588
|
* a consumer that needs the state reads {@link snapshot} — and the returned
|
|
@@ -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/tasks.ts
CHANGED
|
@@ -472,8 +472,8 @@ export interface TaskRecord {
|
|
|
472
472
|
* Whether later executions continue in the previous execution's session
|
|
473
473
|
* (issue #1419) instead of minting a fresh conversation per run. Absent or
|
|
474
474
|
* false keeps the historical one-session-per-execution behavior; the reuse
|
|
475
|
-
* itself only happens when that session is idle
|
|
476
|
-
* {@link reusableSessionId}).
|
|
475
|
+
* itself only happens when that session is idle, still present, and not
|
|
476
|
+
* archived (issue #2068; see {@link reusableSessionId}).
|
|
477
477
|
*/
|
|
478
478
|
reuseSession?: boolean
|
|
479
479
|
/**
|
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,12 @@ 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>
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
/** Registered tool names, in registration order. */
|
|
@@ -323,6 +328,7 @@ function buildRunTool(host: TaskBoardToolHost): ToolDefinition {
|
|
|
323
328
|
crypto.randomUUID(),
|
|
324
329
|
{ kind: args.rerun === true ? 'rerun' : 'run', taskId: args.taskId },
|
|
325
330
|
callingSessionId(exec),
|
|
331
|
+
'tool',
|
|
326
332
|
)
|
|
327
333
|
const beforeById = new Map(before.tasks.map(task => [task.id, task]))
|
|
328
334
|
const started = snapshot.tasks.flatMap(task => {
|