@linxin666/dsh-client-ui-task-board 0.4.6 → 0.4.8
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 +15 -6
- package/README.zh.md +15 -6
- package/lib/client.js +1634 -822
- package/lib/client.js.map +1 -1
- package/lib/index.js +1072 -125
- package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
- package/lib/types/client/PluginSettingsCard.d.ts +39 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +56 -0
- package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
- package/lib/types/client/board/model-options.d.ts +67 -0
- package/lib/types/client/board/preset-label.d.ts +21 -0
- package/lib/types/client/board/preset-roster.d.ts +45 -0
- package/lib/types/client/board/team-run-promotion.d.ts +26 -0
- package/lib/types/client/locales.d.ts +18 -0
- package/lib/types/client/telemetry.d.ts +14 -2
- package/lib/types/core/card-defaults.d.ts +78 -0
- package/lib/types/core/controller.d.ts +32 -7
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +34 -0
- package/lib/types/core/launch-width.d.ts +31 -0
- package/lib/types/core/reasoning-effort.d.ts +57 -0
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/subtask.d.ts +30 -8
- package/lib/types/core/tasks.d.ts +51 -1
- package/lib/types/core/use-cases/task-create.d.ts +10 -5
- package/lib/types/core/use-cases/task-update.d.ts +1 -1
- package/lib/types/host/launch-admission.d.ts +72 -0
- package/lib/types/host-ledger.d.ts +33 -6
- package/lib/types/host-runner.d.ts +83 -5
- package/lib/types/host-service.d.ts +116 -2
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +98 -0
- package/lib/types/loopback.d.ts +20 -1
- package/lib/types/protocol.d.ts +13 -0
- package/package.json +28 -28
- package/src/client/CardDefaultPresetField.tsx +101 -0
- package/src/client/PluginSettingsCard.tsx +63 -3
- package/src/client/TaskBoardSettingsCard.tsx +251 -16
- package/src/client/board/LinkSubtaskModal.tsx +8 -0
- package/src/client/board/NewTaskModal.tsx +86 -40
- package/src/client/board/ReasoningEffortField.tsx +50 -0
- package/src/client/board/TaskDetail.tsx +42 -6
- package/src/client/board/model-options.ts +178 -0
- package/src/client/board/preset-label.ts +32 -0
- package/src/client/board/preset-roster.ts +58 -0
- package/src/client/board/team-run-promotion.ts +39 -0
- package/src/client/index.ts +98 -94
- package/src/client/locales.ts +38 -2
- package/src/client/settings-card.module.css +70 -1
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/telemetry.ts +47 -2
- package/src/core/card-defaults.ts +132 -0
- package/src/core/controller.ts +44 -9
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +34 -0
- package/src/core/launch-width.ts +38 -0
- package/src/core/reasoning-effort.ts +92 -0
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +9 -0
- package/src/core/subtask.ts +48 -13
- package/src/core/tasks.ts +63 -1
- package/src/core/use-cases/task-create.ts +27 -16
- package/src/core/use-cases/task-update.ts +6 -1
- package/src/host/agent-tools.ts +21 -8
- package/src/host/launch-admission.ts +140 -0
- package/src/host-ledger.ts +80 -10
- package/src/host-runner.ts +199 -25
- package/src/host-service.ts +340 -27
- package/src/host-spend.ts +105 -0
- package/src/index.ts +182 -2
- package/src/loopback.ts +25 -1
- package/src/protocol.ts +28 -4
package/src/host-service.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import type { TypertGateway } from '@deepseek-ai/dsh-api-gateway'
|
|
2
|
+
import { DEFAULT_RUN_LAUNCH_WIDTH, normalizeRunLaunchWidth } from './core/launch-width.ts'
|
|
3
|
+
import { DEFAULT_SPEND_BUDGET_TOKENS, spendCapMessage, spendCapReached } from './core/spend-budget.ts'
|
|
4
|
+
import { usedTokensToday } from './host-spend.ts'
|
|
2
5
|
import { DEFAULT_SESSION_POLL_SECONDS, normalizeSessionPollSeconds, sessionPollMs } from './core/poll-cadence.ts'
|
|
3
6
|
import { reusableSessionId } from './core/session-reuse.ts'
|
|
7
|
+
import { LaunchAdmissionQueue, type QueuedLaunch } from './host/launch-admission.ts'
|
|
4
8
|
import { HostTaskLedger, type OpenedRun, type OpenExecutionReference } from './host-ledger.ts'
|
|
5
|
-
import { HostExecutionRunner, SessionLaunchError, promptText, type SessionCommandDispatcher, type SessionSummary, type TaskBoardWorkspaceRegistry } from './host-runner.ts'
|
|
9
|
+
import { HostExecutionRunner, SessionLaunchError, promptText, type GatewayPeer, type SessionCommandDispatcher, type SessionSummary, type TaskBoardWorkspaceRegistry } from './host-runner.ts'
|
|
6
10
|
import { teammateName } from './core/subtask.ts'
|
|
7
11
|
import { workspaceOwningSession } from './core/workspace-target.ts'
|
|
8
12
|
import { PowerInhibitor } from './power-inhibitor.ts'
|
|
9
13
|
import { TASK_BOARD_SCHEMA_VERSION, type TaskBoardAction, type TaskBoardEventPayload, type TaskBoardSnapshot } from './protocol.ts'
|
|
14
|
+
import type { CardDefaults } from './core/card-defaults.ts'
|
|
10
15
|
import { TaskBoardExtensionRegistry } from './host/extension-registry.ts'
|
|
11
16
|
import type { TaskBoardExtension } from './core/extension.ts'
|
|
12
|
-
import type
|
|
17
|
+
import { isTaskPermission, normalizeTargetId, type ExecutionOutcome, type ExecutionSummary, type ScheduleMode, type TaskRecord, type TaskStatus } from './core/tasks.ts'
|
|
13
18
|
import { passedAttempt, resolveContract, verificationNeverInvoked, verificationOnlyInvalid, verificationRequired, withAcceptanceDetailCleared, type ExecutionVerification, type ModelCatalogView, type VerificationContract, type VerificationSettings } from './core/verification.ts'
|
|
14
19
|
import type { TaskPermission } from './core/handover.ts'
|
|
15
20
|
|
|
@@ -65,6 +70,35 @@ const MAX_TIMER_DELAY_MS = 2_147_483_647
|
|
|
65
70
|
*/
|
|
66
71
|
const UNREADABLE_SETTLE_POLLS = 24
|
|
67
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Why a member of a run never started: the Host stopped while its launch was
|
|
75
|
+
* still waiting for an admission slot. Recorded rather than left open, so the
|
|
76
|
+
* card leaves the running column instead of waiting for the next Host start's
|
|
77
|
+
* interrupted-start recovery.
|
|
78
|
+
*/
|
|
79
|
+
const ABANDONED_LAUNCH_REASON = 'host stopped before this execution started'
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The acceptance contract one run group freezes, read once for the whole group.
|
|
83
|
+
*
|
|
84
|
+
* The board freezes an execution's acceptance contract BEFORE its session is
|
|
85
|
+
* prompted. Admission delays the launch, so reading these per execution would
|
|
86
|
+
* let a settings edit made while later members wait reach some members of one
|
|
87
|
+
* run and not others. Reading them once per run group — at the group's first
|
|
88
|
+
* admission, which is its root's — keeps the whole group on one contract and
|
|
89
|
+
* still freezes it before any member's session is prompted.
|
|
90
|
+
*/
|
|
91
|
+
interface FrozenRunContract {
|
|
92
|
+
settings: VerificationSettings
|
|
93
|
+
/** The GLOBAL native-/goal switch, resolved exactly once for the run group. */
|
|
94
|
+
globalGoalEnabled: boolean
|
|
95
|
+
/** The host model catalog the group's contracts resolve their route from. */
|
|
96
|
+
catalog: ModelCatalogView | undefined
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Reads (or returns the already-read) contract of one run group. */
|
|
100
|
+
type RunContractFreezer = () => Promise<FrozenRunContract>
|
|
101
|
+
|
|
68
102
|
/**
|
|
69
103
|
* Why an enforced goal execution settled failed while its acceptance DID run:
|
|
70
104
|
* attempts were recorded and none of them passed. The judge answered about the
|
|
@@ -105,10 +139,18 @@ export interface ScheduledRunContext {
|
|
|
105
139
|
}
|
|
106
140
|
|
|
107
141
|
/**
|
|
108
|
-
* Actions that can
|
|
109
|
-
* an unrelated card edit leaves the pending fire
|
|
142
|
+
* Actions that can change the instant the schedule timer is armed at. Only
|
|
143
|
+
* these re-arm the native timer; an unrelated card edit leaves the pending fire
|
|
144
|
+
* untouched.
|
|
145
|
+
*
|
|
146
|
+
* The set is the write surface of a rule itself rather than a guess at the UI
|
|
147
|
+
* flows that reach it: `create` and `import` land a card that already carries
|
|
148
|
+
* an enabled rule (the new-task dialog and the one-time browser import),
|
|
149
|
+
* `set-schedule` edits one, and `delete`/`archive` drop one. `update` is
|
|
150
|
+
* deliberately absent — the update patch cannot carry a schedule — and neither
|
|
151
|
+
* can the run, move, lineage, permission, verification or label actions.
|
|
110
152
|
*/
|
|
111
|
-
const SCHEDULE_WRITE_ACTIONS: ReadonlySet<TaskBoardAction['kind']> = new Set(['set-schedule', 'delete', 'archive'])
|
|
153
|
+
const SCHEDULE_WRITE_ACTIONS: ReadonlySet<TaskBoardAction['kind']> = new Set(['create', 'import', 'set-schedule', 'delete', 'archive'])
|
|
112
154
|
|
|
113
155
|
/**
|
|
114
156
|
* The native timer face the Host arms through. The cordis `timer` service
|
|
@@ -134,6 +176,61 @@ const PROCESS_TIMERS: HostTimerFace = {
|
|
|
134
176
|
},
|
|
135
177
|
}
|
|
136
178
|
|
|
179
|
+
/**
|
|
180
|
+
* The new-card defaults a snapshot publishes, or undefined when this
|
|
181
|
+
* deployment configures none. A target the board configures nothing for is
|
|
182
|
+
* omitted instead of published blank, so the browser can tell "no default
|
|
183
|
+
* model" from "a blank one" (only a hand-edited settings document can express
|
|
184
|
+
* the latter).
|
|
185
|
+
*/
|
|
186
|
+
function cardDefaultsOf(defaults: CardDefaults): TaskBoardSnapshot['cardDefaults'] {
|
|
187
|
+
const mode = normalizeTargetId(defaults.mode)
|
|
188
|
+
const permission = normalizeTargetId(defaults.permission)
|
|
189
|
+
const model = normalizeTargetId(defaults.model)
|
|
190
|
+
const reasoningEffort = normalizeTargetId(defaults.reasoningEffort)
|
|
191
|
+
const published: NonNullable<TaskBoardSnapshot['cardDefaults']> = {
|
|
192
|
+
...(mode === undefined ? {} : { mode }),
|
|
193
|
+
// The snapshot publishes a permission the board's own vocabulary knows; an
|
|
194
|
+
// out-of-domain value is ignored here exactly as the create path ignores it.
|
|
195
|
+
...(isTaskPermission(permission) ? { permission } : {}),
|
|
196
|
+
...(model === undefined ? {} : { model }),
|
|
197
|
+
...(reasoningEffort === undefined ? {} : { reasoningEffort }),
|
|
198
|
+
}
|
|
199
|
+
return Object.keys(published).length === 0 ? undefined : published
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Every action kind this board accepts, keyed by the kind itself.
|
|
204
|
+
*
|
|
205
|
+
* Written as a total record of `TaskBoardAction['kind']` on purpose: a new member
|
|
206
|
+
* of that union does not compile until it is listed here, so the table cannot
|
|
207
|
+
* drift behind the protocol. `apply()` validates against it because a caller
|
|
208
|
+
* reaching the board through the in-process capability face forwards its action
|
|
209
|
+
* object verbatim, with no envelope parser in front of it — the HTTP route was the
|
|
210
|
+
* only entrance before that face existed, and its parser is what used to turn an
|
|
211
|
+
* unknown kind into a refusal.
|
|
212
|
+
*/
|
|
213
|
+
const ACTION_KINDS: Readonly<Record<TaskBoardAction['kind'], true>> = {
|
|
214
|
+
import: true,
|
|
215
|
+
create: true,
|
|
216
|
+
update: true,
|
|
217
|
+
delete: true,
|
|
218
|
+
move: true,
|
|
219
|
+
archive: true,
|
|
220
|
+
restore: true,
|
|
221
|
+
settle: true,
|
|
222
|
+
'reset-verification': true,
|
|
223
|
+
'record-external-outcome': true,
|
|
224
|
+
'set-schedule': true,
|
|
225
|
+
run: true,
|
|
226
|
+
rerun: true,
|
|
227
|
+
'confirm-permission': true,
|
|
228
|
+
'set-parent': true,
|
|
229
|
+
'rename-tag': true,
|
|
230
|
+
'delete-tag': true,
|
|
231
|
+
'extension-action': true,
|
|
232
|
+
}
|
|
233
|
+
|
|
137
234
|
export class TaskBoardHostService {
|
|
138
235
|
readonly ledger: HostTaskLedger
|
|
139
236
|
readonly runner: HostExecutionRunner
|
|
@@ -154,6 +251,12 @@ export class TaskBoardHostService {
|
|
|
154
251
|
private disposed = false
|
|
155
252
|
private pollInFlight = false
|
|
156
253
|
private active = true
|
|
254
|
+
/**
|
|
255
|
+
* Admission control for the session-creating half of a run: one board action
|
|
256
|
+
* opens a whole subtree, and this is what keeps the Host from asking DSH for
|
|
257
|
+
* every member's session at once (see {@link LaunchAdmissionQueue}).
|
|
258
|
+
*/
|
|
259
|
+
private readonly launches: LaunchAdmissionQueue
|
|
157
260
|
/**
|
|
158
261
|
* Consecutive unreadable-history polls per open execution (see
|
|
159
262
|
* {@link noteUnreadableInspection}). Cleared as soon as an inspection
|
|
@@ -167,6 +270,21 @@ export class TaskBoardHostService {
|
|
|
167
270
|
private readonly timers: HostTimerFace
|
|
168
271
|
/** Live reader of the global native-/goal switch; frozen per execution. */
|
|
169
272
|
private readonly goalRunEnabled: () => boolean
|
|
273
|
+
/** Live reader of the deployment's new-card defaults (published and applied per create). */
|
|
274
|
+
private readonly cardDefaults: () => CardDefaults
|
|
275
|
+
/**
|
|
276
|
+
* Live reader of the run-launch admission width: how many launches may be in
|
|
277
|
+
* flight at once. Read at every admission, so a settings edit bounds the next
|
|
278
|
+
* launch without remounting the row. Absent means the default.
|
|
279
|
+
*/
|
|
280
|
+
private readonly runLaunchWidth: () => number
|
|
281
|
+
/**
|
|
282
|
+
* Live reader of the daily token cap; 0 means no gate. Read at each run
|
|
283
|
+
* action, so closing or raising the cap binds the next action.
|
|
284
|
+
*/
|
|
285
|
+
private readonly spendBudgetTokens: () => number
|
|
286
|
+
/** Today's measured spend: absent measurement reads as "cannot see", never as zero. */
|
|
287
|
+
private readonly spendUsedToday: (now: number) => number | undefined
|
|
170
288
|
private lastPowerJson = ''
|
|
171
289
|
private readonly now: () => number
|
|
172
290
|
/** The deployment's workspaces, consulted to resolve a card that pins none. */
|
|
@@ -184,12 +302,26 @@ export class TaskBoardHostService {
|
|
|
184
302
|
now?: () => number
|
|
185
303
|
commandDispatcher?: SessionCommandDispatcher
|
|
186
304
|
workspaceRegistry?: TaskBoardWorkspaceRegistry
|
|
305
|
+
/**
|
|
306
|
+
* The owner peer every gateway request the runner makes speaks for.
|
|
307
|
+
* Production passes the peer bound to the plugin fiber (see
|
|
308
|
+
* {@link createOwnerPeer}); absent is fine for tests and bare mounts,
|
|
309
|
+
* where the runner binds one to a fresh root context.
|
|
310
|
+
*/
|
|
311
|
+
ownerPeer?: GatewayPeer
|
|
187
312
|
/**
|
|
188
313
|
* Permission baseline of the confirmation gate: a fixed value, or a live
|
|
189
314
|
* resolver the board re-reads so a Host Settings change needs no remount.
|
|
190
315
|
*/
|
|
191
316
|
sessionDefaultPermission?: TaskPermission | (() => TaskPermission)
|
|
192
317
|
maxSubtaskDepth?: number
|
|
318
|
+
/**
|
|
319
|
+
* Live reader of the deployment's new-card defaults (volatile config reads).
|
|
320
|
+
* The board publishes them for the create dialog and re-reads them for every
|
|
321
|
+
* create that opts in, so a settings edit reaches the next created card
|
|
322
|
+
* without remounting the row. Absent means the deployment configures none.
|
|
323
|
+
*/
|
|
324
|
+
cardDefaults?: () => CardDefaults
|
|
193
325
|
team?: TaskBoardTeamDispatcher
|
|
194
326
|
timers?: HostTimerFace
|
|
195
327
|
/**
|
|
@@ -208,18 +340,45 @@ export class TaskBoardHostService {
|
|
|
208
340
|
verificationSettings?: () => VerificationSettings
|
|
209
341
|
/** The host model catalog the acceptance contract resolves its route from. */
|
|
210
342
|
verificationCatalog?: () => Promise<ModelCatalogView | undefined>
|
|
343
|
+
/**
|
|
344
|
+
* Live admission width for run launches: the number of launches (one
|
|
345
|
+
* session creation and its prompt each) that may be in flight at once. Read
|
|
346
|
+
* per admission, so editing the setting bounds the next launch of a run that
|
|
347
|
+
* is still queueing. Absent means the default width.
|
|
348
|
+
*/
|
|
349
|
+
runLaunchWidth?: () => number
|
|
350
|
+
/**
|
|
351
|
+
* Live daily token cap (a volatile config read). 0 — the default, and what
|
|
352
|
+
* every deployment that never configured one keeps — ends the gate before
|
|
353
|
+
* anything is measured. A positive cap refuses a run whose day already spent
|
|
354
|
+
* it, on both the action path and the cron path.
|
|
355
|
+
*/
|
|
356
|
+
spendBudgetTokens?: () => number
|
|
357
|
+
/**
|
|
358
|
+
* Today's measured spend in tokens, or undefined when this deployment keeps
|
|
359
|
+
* no readable usage ledger. Defaults to the family usage ledger reader.
|
|
360
|
+
*/
|
|
361
|
+
spendUsedToday?: (now: number) => number | undefined
|
|
211
362
|
} = {}) {
|
|
212
363
|
this.ledger = options.ledger ?? new HostTaskLedger(undefined, undefined, {
|
|
213
364
|
sessionDefaultPermission: options.sessionDefaultPermission,
|
|
214
365
|
maxSubtaskDepth: options.maxSubtaskDepth,
|
|
366
|
+
cardDefaults: options.cardDefaults,
|
|
367
|
+
spendBudgetTokens: options.spendBudgetTokens,
|
|
368
|
+
spendUsedToday: options.spendUsedToday,
|
|
215
369
|
})
|
|
216
|
-
this.runner = new HostExecutionRunner(gateway, options.commandDispatcher, options.workspaceRegistry)
|
|
370
|
+
this.runner = new HostExecutionRunner(gateway, options.commandDispatcher, options.workspaceRegistry, undefined, options.ownerPeer)
|
|
217
371
|
this.workspaceRegistry = options.workspaceRegistry
|
|
218
372
|
this.team = options.team
|
|
219
373
|
this.timers = options.timers ?? PROCESS_TIMERS
|
|
220
374
|
this.power = options.power ?? new PowerInhibitor()
|
|
221
375
|
this.now = options.now ?? Date.now
|
|
222
376
|
this.goalRunEnabled = options.goalRunEnabled ?? (() => false)
|
|
377
|
+
this.cardDefaults = options.cardDefaults ?? (() => ({}))
|
|
378
|
+
this.runLaunchWidth = options.runLaunchWidth ?? (() => DEFAULT_RUN_LAUNCH_WIDTH)
|
|
379
|
+
this.spendBudgetTokens = options.spendBudgetTokens ?? (() => DEFAULT_SPEND_BUDGET_TOKENS)
|
|
380
|
+
this.spendUsedToday = options.spendUsedToday ?? (now => usedTokensToday(now))
|
|
381
|
+
this.launches = new LaunchAdmissionQueue(() => normalizeRunLaunchWidth(this.runLaunchWidth()))
|
|
223
382
|
this.verificationSettings = options.verificationSettings ?? (() => ({ enabled: false, model: '', reasoningEffort: '' }))
|
|
224
383
|
this.verificationCatalog = options.verificationCatalog ?? (async () => undefined)
|
|
225
384
|
this.extensions = new TaskBoardExtensionRegistry({
|
|
@@ -310,6 +469,7 @@ export class TaskBoardHostService {
|
|
|
310
469
|
snapshot(): TaskBoardSnapshot {
|
|
311
470
|
const state = this.ledger.state()
|
|
312
471
|
const published = this.extensions.published()
|
|
472
|
+
const cardDefaults = cardDefaultsOf(this.cardDefaults())
|
|
313
473
|
return {
|
|
314
474
|
schemaVersion: TASK_BOARD_SCHEMA_VERSION,
|
|
315
475
|
revision: state.revision,
|
|
@@ -323,6 +483,10 @@ export class TaskBoardHostService {
|
|
|
323
483
|
// service freezes its own read at launch: this mirror is for the FORM
|
|
324
484
|
// (enable/disable + explanation), never for a run already in flight.
|
|
325
485
|
goalRunEnabled: this.goalRunEnabled(),
|
|
486
|
+
// The new-card defaults are published live for the same reason the switch
|
|
487
|
+
// is: the create dialog prefills from them, and each creating session
|
|
488
|
+
// re-reads them for the create it submits.
|
|
489
|
+
...(cardDefaults === undefined ? {} : { cardDefaults }),
|
|
326
490
|
...(Object.keys(published).length === 0 ? {} : { extensions: published }),
|
|
327
491
|
}
|
|
328
492
|
}
|
|
@@ -402,6 +566,15 @@ export class TaskBoardHostService {
|
|
|
402
566
|
apply(requestId: string, action: TaskBoardAction, initiator?: string): TaskBoardSnapshot | Promise<TaskBoardSnapshot>
|
|
403
567
|
apply(requestId: string, action: TaskBoardAction, initiator?: string): TaskBoardSnapshot | Promise<TaskBoardSnapshot> {
|
|
404
568
|
if (!this.active) throw new Error('task board is disabled')
|
|
569
|
+
// A caller that never met the HTTP envelope parser can name a kind this build
|
|
570
|
+
// does not implement. It is refused here, in the board's own vocabulary: the
|
|
571
|
+
// ledger has no case for it, and letting it through committed an unchanged
|
|
572
|
+
// document under a fresh revision — which every connected client then reloads
|
|
573
|
+
// a whole snapshot for.
|
|
574
|
+
const kind = (action as { kind?: unknown } | null | undefined)?.kind
|
|
575
|
+
if (typeof kind !== 'string' || !Object.hasOwn(ACTION_KINDS, kind)) {
|
|
576
|
+
throw new Error(`unknown task board action kind: ${String(kind)}`)
|
|
577
|
+
}
|
|
405
578
|
// Provider actions never touch the ledger directly: the registry routes the
|
|
406
579
|
// action to the owning extension, whose own capability calls come back
|
|
407
580
|
// through applyBoardAction and every board gate below.
|
|
@@ -425,11 +598,14 @@ export class TaskBoardHostService {
|
|
|
425
598
|
const task = this.ledger.state().tasks.find(item => item.id === action.taskId)
|
|
426
599
|
if (task?.teamRun === true) throw new Error('Agent Teams is unavailable in this deployment')
|
|
427
600
|
}
|
|
601
|
+
if (action.kind === 'run' || action.kind === 'rerun') this.assertSpendCap()
|
|
428
602
|
const result = this.ledger.applyRequest(requestId, this.withInheritedWorkspace(action, initiator), initiator)
|
|
429
603
|
if (result.runs !== undefined) this.dispatchRuns(result.runs)
|
|
430
|
-
// A committed
|
|
431
|
-
//
|
|
432
|
-
//
|
|
604
|
+
// A committed write that can move a rule moves the nearest trigger;
|
|
605
|
+
// re-arm from the ledger so a created or edited schedule fires at its own
|
|
606
|
+
// instant instead of waiting out whatever target was armed before it. The
|
|
607
|
+
// re-arm is derived from the ledger, so a write that moved nothing leaves
|
|
608
|
+
// the pending fire exactly as it was.
|
|
433
609
|
if (SCHEDULE_WRITE_ACTIONS.has(action.kind)) this.refreshSchedule()
|
|
434
610
|
this.emitStatusChanges(before, initiator)
|
|
435
611
|
if (action.kind === 'delete') this.extensions.emitTaskDeleted({ taskId: action.taskId })
|
|
@@ -442,6 +618,25 @@ export class TaskBoardHostService {
|
|
|
442
618
|
}
|
|
443
619
|
}
|
|
444
620
|
|
|
621
|
+
/**
|
|
622
|
+
* Refuse a run whose day already spent the cap.
|
|
623
|
+
*
|
|
624
|
+
* A cap of 0 — the shipped default — answers before the measurement is read:
|
|
625
|
+
* no ledger file is opened and nothing is summed, which is what keeps a board
|
|
626
|
+
* that never configured a cap identical to the one before it existed.
|
|
627
|
+
*
|
|
628
|
+
* The refusal is a thrown message rather than a code: the wire hands its text
|
|
629
|
+
* to the caller as board-refused, exactly like every other refusal this board
|
|
630
|
+
* makes.
|
|
631
|
+
*/
|
|
632
|
+
private assertSpendCap(): void {
|
|
633
|
+
const cap = this.spendBudgetTokens()
|
|
634
|
+
if (!(cap > 0)) return
|
|
635
|
+
const used = this.spendUsedToday(this.now())
|
|
636
|
+
if (used === undefined || !spendCapReached(used, cap)) return
|
|
637
|
+
throw new Error(spendCapMessage(used, cap))
|
|
638
|
+
}
|
|
639
|
+
|
|
445
640
|
/** Route one provider action and answer the resulting board snapshot. */
|
|
446
641
|
private async handleExtensionAction(action: Extract<TaskBoardAction, { kind: 'extension-action' }>): Promise<TaskBoardSnapshot> {
|
|
447
642
|
await this.extensions.handleAction({
|
|
@@ -474,6 +669,14 @@ export class TaskBoardHostService {
|
|
|
474
669
|
|
|
475
670
|
dispose(): void {
|
|
476
671
|
this.disposed = true
|
|
672
|
+
// Launches still waiting for a slot can never start now: settle them so
|
|
673
|
+
// their cards leave the running column here, instead of waiting for the
|
|
674
|
+
// next Host start's interrupted-start recovery. Launches already in flight
|
|
675
|
+
// are left to finish — their session may already exist.
|
|
676
|
+
const abandoned = this.launches.drain()
|
|
677
|
+
if (abandoned.length > 0) {
|
|
678
|
+
safeConsoleError(`[dsh-task-board] ${abandoned.length} run member(s) were still waiting for a launch slot when the Host stopped; each is settled as cancelled`)
|
|
679
|
+
}
|
|
477
680
|
this.extensions.dispose()
|
|
478
681
|
this.clearScheduleTimer()
|
|
479
682
|
this.clearPollBackoff()
|
|
@@ -484,7 +687,7 @@ export class TaskBoardHostService {
|
|
|
484
687
|
this.listeners.clear()
|
|
485
688
|
}
|
|
486
689
|
|
|
487
|
-
private async launch(opened: OpenedRun, others: readonly OpenedRun[] = [], schedule?: ScheduledRunContext): Promise<void> {
|
|
690
|
+
private async launch(opened: OpenedRun, others: readonly OpenedRun[] = [], schedule?: ScheduledRunContext, freezeContract?: RunContractFreezer): Promise<void> {
|
|
488
691
|
/** The session this launch attached to the execution, once it exists. */
|
|
489
692
|
let attached: string | undefined
|
|
490
693
|
try {
|
|
@@ -512,11 +715,16 @@ export class TaskBoardHostService {
|
|
|
512
715
|
// retrofit the rule that will judge it. A card that opted out resolves the
|
|
513
716
|
// same contract from an OFF switch: the board-wide switch decides the
|
|
514
717
|
// default, the card decides this execution, and both are read here.
|
|
515
|
-
|
|
516
|
-
// The
|
|
517
|
-
//
|
|
718
|
+
//
|
|
719
|
+
// The read is the run GROUP's when the queue handed one down: admission
|
|
720
|
+
// delays a member's launch, so a per-execution read would let a settings
|
|
721
|
+
// edit made while later members wait reach some members of one run and not
|
|
722
|
+
// others. One group, one contract — and still frozen before the group's
|
|
723
|
+
// first session is prompted.
|
|
724
|
+
const { settings, globalGoalEnabled, catalog } = await (freezeContract ?? (() => this.freezeRunContract()))()
|
|
725
|
+
// The GLOBAL native-/goal switch is read ONCE per run group and carried by
|
|
726
|
+
// value for the whole execution: a settings edit after this point can only
|
|
518
727
|
// affect executions that start later.
|
|
519
|
-
const globalGoalEnabled = this.goalRunEnabled() === true
|
|
520
728
|
// The card must ASK for the goal run: the option is off by default, so an
|
|
521
729
|
// absent value is a plain turn exactly like an explicit false.
|
|
522
730
|
const goalEnabled = globalGoalEnabled && opened.task.goalRun === true
|
|
@@ -525,7 +733,7 @@ export class TaskBoardHostService {
|
|
|
525
733
|
const skippedBy: ExecutionVerification['applicability'] = opened.task.skipVerification === true ? 'skipped' : 'disabled'
|
|
526
734
|
const contract = resolveContract(
|
|
527
735
|
{ ...settings, enabled: settings.enabled && opened.task.skipVerification !== true },
|
|
528
|
-
|
|
736
|
+
catalog,
|
|
529
737
|
)
|
|
530
738
|
// An execution that will not become a goal run can never fire the
|
|
531
739
|
// completion gate, so it is marked with the reason that actually applied:
|
|
@@ -549,6 +757,8 @@ export class TaskBoardHostService {
|
|
|
549
757
|
// The frozen global switch travels with the launch, so the runner's
|
|
550
758
|
// arming decision is exactly the one made above.
|
|
551
759
|
goalEnabled,
|
|
760
|
+
// The same catalog snapshot the acceptance contract was frozen from.
|
|
761
|
+
catalog,
|
|
552
762
|
// Bind the session to the execution before the prompt is queued, so the
|
|
553
763
|
// completion gate can never observe the agent without its binding.
|
|
554
764
|
onSession: (id) => {
|
|
@@ -573,16 +783,60 @@ export class TaskBoardHostService {
|
|
|
573
783
|
// failed launch can never silently spend the user's run budget. A manual
|
|
574
784
|
// run, and a launch that DID reach a session, are never refunded.
|
|
575
785
|
if (schedule !== undefined && attached === undefined && launchedSession === undefined) {
|
|
576
|
-
this.
|
|
786
|
+
this.refundUnstartedSchedule(opened.task.id)
|
|
577
787
|
}
|
|
578
788
|
this.settleAndNotify(opened.task.id, opened.execution.id, 'failed', error instanceof Error ? error.message : String(error))
|
|
579
789
|
}
|
|
580
790
|
}
|
|
581
791
|
|
|
792
|
+
/**
|
|
793
|
+
* Read the acceptance contract one run group freezes, in the order the board
|
|
794
|
+
* has always read it: the acceptance settings, then the global native-/goal
|
|
795
|
+
* switch, then the model catalog that both resolves the contract's route and
|
|
796
|
+
* decides the reasoning effort the session may be given.
|
|
797
|
+
*/
|
|
798
|
+
private async freezeRunContract(): Promise<FrozenRunContract> {
|
|
799
|
+
const settings = this.verificationSettings()
|
|
800
|
+
const globalGoalEnabled = this.goalRunEnabled() === true
|
|
801
|
+
const catalog = await this.verificationCatalog()
|
|
802
|
+
return { settings, globalGoalEnabled, catalog }
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* A {@link RunContractFreezer} that reads once and hands the SAME value to
|
|
807
|
+
* every later caller of one run group. A read that fails is not cached: the
|
|
808
|
+
* next member reads again, exactly as a per-execution read would have.
|
|
809
|
+
*/
|
|
810
|
+
private contractFreezerForRunGroup(): RunContractFreezer {
|
|
811
|
+
let pending: Promise<FrozenRunContract> | undefined
|
|
812
|
+
return () => {
|
|
813
|
+
pending ??= this.freezeRunContract().catch((error: unknown) => {
|
|
814
|
+
pending = undefined
|
|
815
|
+
throw error
|
|
816
|
+
})
|
|
817
|
+
return pending
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Give back the occurrence a launch consumed, for a launch that never reached
|
|
823
|
+
* a session: a failed launch, or one the Host abandoned while it was still
|
|
824
|
+
* waiting for an admission slot. A manual run, and a launch that DID reach a
|
|
825
|
+
* session, are never refunded.
|
|
826
|
+
*/
|
|
827
|
+
private refundUnstartedSchedule(taskId: string): void {
|
|
828
|
+
this.ledger.refundScheduledOccurrence(taskId, this.now())
|
|
829
|
+
// The refund runs after the fire already armed the next target, and a
|
|
830
|
+
// refunded occurrence can restore one the fire had just cleared (a rule
|
|
831
|
+
// that spent its last run). Re-arm so the restored occurrence is served
|
|
832
|
+
// at its own instant rather than lost until some unrelated write.
|
|
833
|
+
this.refreshSchedule()
|
|
834
|
+
}
|
|
835
|
+
|
|
582
836
|
private scheduleTeammate(opened: OpenedRun, leadSessionId: string): void {
|
|
583
|
-
|
|
837
|
+
this.enqueueLaunch(opened, () => this.spawnTeammate(opened, leadSessionId).catch(error => {
|
|
584
838
|
safeConsoleError('[dsh-task-board] teammate spawn settlement failed', error)
|
|
585
|
-
})
|
|
839
|
+
}))
|
|
586
840
|
}
|
|
587
841
|
|
|
588
842
|
/**
|
|
@@ -747,10 +1001,13 @@ export class TaskBoardHostService {
|
|
|
747
1001
|
: verificationOnlyInvalid(verification)
|
|
748
1002
|
? INVALID_ONLY_VERIFICATION_REASON
|
|
749
1003
|
: NO_MATCHING_PASS_VERIFICATION_REASON,
|
|
1004
|
+
result.summary,
|
|
750
1005
|
)
|
|
751
1006
|
continue
|
|
752
1007
|
}
|
|
753
|
-
|
|
1008
|
+
// The run's closing text rides whichever verdict it earned: a failed
|
|
1009
|
+
// execution still leaves what it managed to say.
|
|
1010
|
+
this.settleAndNotify(execution.taskId, execution.executionId, result.outcome, 'error' in result ? result.error : undefined, result.summary)
|
|
754
1011
|
} catch {
|
|
755
1012
|
// A transient inspection failure never settles a running execution.
|
|
756
1013
|
}
|
|
@@ -770,16 +1027,16 @@ export class TaskBoardHostService {
|
|
|
770
1027
|
* ancestor of it — in the running column with no way out. The first poll of
|
|
771
1028
|
* each streak is logged, so the Host log names the session.
|
|
772
1029
|
*/
|
|
773
|
-
private settleAndNotify(taskId: string, executionId: string, outcome: ExecutionOutcome, error?: string): void {
|
|
1030
|
+
private settleAndNotify(taskId: string, executionId: string, outcome: ExecutionOutcome, error?: string, summary?: ExecutionSummary): void {
|
|
774
1031
|
const before = this.ledger.getTask(taskId)
|
|
775
1032
|
if (before?.executions.find(entry => entry.id === executionId)?.endedAt !== undefined) {
|
|
776
1033
|
// Already settled: the ledger would no-op, and re-emitting would report
|
|
777
1034
|
// the same settlement twice.
|
|
778
|
-
this.ledger.settle(taskId, executionId, outcome, error)
|
|
1035
|
+
this.ledger.settle(taskId, executionId, outcome, error, summary)
|
|
779
1036
|
return
|
|
780
1037
|
}
|
|
781
1038
|
const previousStatus = before?.status
|
|
782
|
-
this.ledger.settle(taskId, executionId, outcome, error)
|
|
1039
|
+
this.ledger.settle(taskId, executionId, outcome, error, summary)
|
|
783
1040
|
const task = this.ledger.getTask(taskId)
|
|
784
1041
|
if (task !== undefined && previousStatus !== undefined && previousStatus !== task.status) {
|
|
785
1042
|
this.extensions.emitStatusChanged({ taskId, status: task.status, previous: previousStatus })
|
|
@@ -966,14 +1223,22 @@ export class TaskBoardHostService {
|
|
|
966
1223
|
* member then launches on its own so one refused participant cannot hold the
|
|
967
1224
|
* others back. A team run's members are spawned inside the root's Lead
|
|
968
1225
|
* session instead, once that session exists.
|
|
1226
|
+
*
|
|
1227
|
+
* Every launch of one run set goes through the admission queue, which admits
|
|
1228
|
+
* at most `runLaunchWidth` of them at a time — the whole subtree still opens,
|
|
1229
|
+
* members just enter the running column in batches. Order inside the group is
|
|
1230
|
+
* the order they are enqueued here, so the root's session always exists before
|
|
1231
|
+
* any member's, and one member's launch settling (or failing) is what admits
|
|
1232
|
+
* the next. All members share the one contract this group freezes.
|
|
969
1233
|
*/
|
|
970
1234
|
private dispatchRuns(runs: readonly OpenedRun[], schedule?: ScheduledRunContext): void {
|
|
971
1235
|
if (runs.length === 0) return
|
|
972
1236
|
const root = runs.find(run => run.dispatch !== 'teammate') ?? runs[0]
|
|
973
1237
|
const others = runs.filter(run => run !== root)
|
|
974
|
-
this.
|
|
1238
|
+
const freezeContract = this.contractFreezerForRunGroup()
|
|
1239
|
+
this.scheduleLaunch(root, others, schedule, freezeContract)
|
|
975
1240
|
for (const run of others) {
|
|
976
|
-
if (run.dispatch !== 'teammate') this.scheduleLaunch(run, [], schedule)
|
|
1241
|
+
if (run.dispatch !== 'teammate') this.scheduleLaunch(run, [], schedule, freezeContract)
|
|
977
1242
|
}
|
|
978
1243
|
}
|
|
979
1244
|
|
|
@@ -987,10 +1252,58 @@ export class TaskBoardHostService {
|
|
|
987
1252
|
this.ledger.setVerification(taskId, executionId, { ...verification, applicability })
|
|
988
1253
|
}
|
|
989
1254
|
|
|
990
|
-
private scheduleLaunch(opened: OpenedRun, others: readonly OpenedRun[] = [], schedule?: ScheduledRunContext): void {
|
|
991
|
-
|
|
1255
|
+
private scheduleLaunch(opened: OpenedRun, others: readonly OpenedRun[] = [], schedule?: ScheduledRunContext, freezeContract?: RunContractFreezer): void {
|
|
1256
|
+
this.enqueueLaunch(opened, () => this.launch(opened, others, schedule, freezeContract).catch(error => {
|
|
992
1257
|
safeConsoleError('[dsh-task-board] execution launch settlement failed', error)
|
|
993
|
-
})
|
|
1258
|
+
}), schedule)
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* Hand one launch to the admission queue, or abandon it on the spot when the
|
|
1263
|
+
* Host is already stopping: a queue entry created after {@link dispose} would
|
|
1264
|
+
* otherwise never be drained, and its card would sit in the running column
|
|
1265
|
+
* until the next Host start recovered it.
|
|
1266
|
+
*/
|
|
1267
|
+
private enqueueLaunch(opened: OpenedRun, start: () => Promise<void>, schedule?: ScheduledRunContext): void {
|
|
1268
|
+
const launch: QueuedLaunch = {
|
|
1269
|
+
groupId: opened.execution.runGroupId ?? opened.task.id,
|
|
1270
|
+
start: async () => {
|
|
1271
|
+
// Waiting for a slot is time the execution can be settled in: a manual
|
|
1272
|
+
// settle, or a team run folded onto its Lead's verdict, can close a
|
|
1273
|
+
// member's execution before it ever started. Starting it then would
|
|
1274
|
+
// create a session no execution is watching, so a launch whose
|
|
1275
|
+
// execution is already closed is dropped instead.
|
|
1276
|
+
if (!this.isExecutionOpen(opened)) return
|
|
1277
|
+
await start()
|
|
1278
|
+
},
|
|
1279
|
+
abandon: () => this.abandonQueuedRun(opened, schedule),
|
|
1280
|
+
}
|
|
1281
|
+
if (this.disposed) {
|
|
1282
|
+
launch.abandon()
|
|
1283
|
+
return
|
|
1284
|
+
}
|
|
1285
|
+
this.launches.enqueue(launch)
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/** Whether one opened execution is still open in the ledger. */
|
|
1289
|
+
private isExecutionOpen(opened: OpenedRun): boolean {
|
|
1290
|
+
const execution = this.ledger.getTask(opened.task.id)?.executions.find(entry => entry.id === opened.execution.id)
|
|
1291
|
+
return execution !== undefined && execution.endedAt === undefined
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Take one launch that never started out of the running column.
|
|
1296
|
+
*
|
|
1297
|
+
* Settled as CANCELLED, not failed: nothing about the run's work went wrong —
|
|
1298
|
+
* the Host stopped before the launch got a slot, which is exactly what the
|
|
1299
|
+
* next start's interrupted-start recovery records for an execution that never
|
|
1300
|
+
* reached a session. A scheduled occurrence that never reached a session is
|
|
1301
|
+
* refunded on the same terms as any other pre-session failure, so a run the
|
|
1302
|
+
* Host never started cannot silently spend the user's run budget.
|
|
1303
|
+
*/
|
|
1304
|
+
private abandonQueuedRun(opened: OpenedRun, schedule?: ScheduledRunContext): void {
|
|
1305
|
+
if (schedule !== undefined) this.refundUnstartedSchedule(opened.task.id)
|
|
1306
|
+
this.settleAndNotify(opened.task.id, opened.execution.id, 'cancelled', ABANDONED_LAUNCH_REASON)
|
|
994
1307
|
}
|
|
995
1308
|
|
|
996
1309
|
private schedulePoll(): void {
|