@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-ledger.ts
CHANGED
|
@@ -5,11 +5,14 @@ import { dirname, join } from 'node:path'
|
|
|
5
5
|
import { dshHome } from './dsh-home.ts'
|
|
6
6
|
import { isValidCron, isValidTimeZone, nextRunAtMs, resolveHostTimeZone } from './core/schedule.ts'
|
|
7
7
|
import { isTaskRecord, parseLedger } from './core/store.ts'
|
|
8
|
-
import {
|
|
8
|
+
import { DEFAULT_SPEND_BUDGET_TOKENS, spendCapMessage, spendCapReached } from './core/spend-budget.ts'
|
|
9
|
+
import { usedTokensToday } from './host-spend.ts'
|
|
10
|
+
import { canMoveManually, hasOpenExecution, retainRecentExecutions, scheduleExhausted, scheduleRunBudget, settleExecution, settledStatus, startExecution, withSchedule, withStatus, type ExecutionOutcome, type ExecutionRecord, type ExecutionSummary, type ScheduleMode, type ScheduleStopReason, type TaskRecord } from './core/tasks.ts'
|
|
9
11
|
import {
|
|
10
12
|
DEFAULT_SUBTASK_DEPTH,
|
|
11
13
|
cascadeTargets,
|
|
12
14
|
combineCascadeOutcome,
|
|
15
|
+
joinsCascadeRun,
|
|
13
16
|
normalizeSubtaskDepth,
|
|
14
17
|
openGroupExecution,
|
|
15
18
|
pendingCascadeChildren,
|
|
@@ -17,6 +20,7 @@ import {
|
|
|
17
20
|
} from './core/subtask.ts'
|
|
18
21
|
import { applyArchiveTask, applyRestoreTask } from './core/use-cases/task-archive.ts'
|
|
19
22
|
import { applyCreateTask } from './core/use-cases/task-create.ts'
|
|
23
|
+
import type { CardDefaults } from './core/card-defaults.ts'
|
|
20
24
|
import { applyDeleteTask } from './core/use-cases/task-delete.ts'
|
|
21
25
|
import { applySetSchedule, applyScheduleProgress, applyScheduleRefund, type ScheduleProgress } from './core/use-cases/task-schedule.ts'
|
|
22
26
|
import { applySetParent } from './core/use-cases/task-parent.ts'
|
|
@@ -488,11 +492,27 @@ export class HostTaskLedger {
|
|
|
488
492
|
*/
|
|
489
493
|
private depthLimit: number
|
|
490
494
|
|
|
491
|
-
|
|
495
|
+
/** Live reader of the deployment's new-card defaults (a volatile config read). */
|
|
496
|
+
private readonly cardDefaults: () => CardDefaults
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Live reader of the daily token cap (0 = no gate). The scheduled path asks it
|
|
500
|
+
* per due occurrence, so a cap raised after a skipped occurrence admits the
|
|
501
|
+
* next one without a restart.
|
|
502
|
+
*/
|
|
503
|
+
private readonly spendBudget: () => number
|
|
504
|
+
|
|
505
|
+
/** Today's measured spend in tokens, or undefined when nothing can be measured. */
|
|
506
|
+
private readonly spendUsed: (now: number) => number | undefined
|
|
507
|
+
|
|
508
|
+
constructor(dir: string = join(dshHome(), 'task-board'), private readonly now: () => number = Date.now, options: { sessionDefaultPermission?: TaskPermission | (() => TaskPermission); maxSubtaskDepth?: number; cardDefaults?: () => CardDefaults; spendBudgetTokens?: () => number; spendUsedToday?: (now: number) => number | undefined } = {}) {
|
|
492
509
|
// Resolved before the load/repair passes below: they can evaluate the gate.
|
|
493
510
|
const baseline = options.sessionDefaultPermission
|
|
494
511
|
this.sessionDefault = typeof baseline === 'function' ? baseline : () => baseline ?? DEFAULT_SESSION_PERMISSION
|
|
495
512
|
this.depthLimit = normalizeSubtaskDepth(options.maxSubtaskDepth ?? DEFAULT_SUBTASK_DEPTH)
|
|
513
|
+
this.cardDefaults = options.cardDefaults ?? (() => ({}))
|
|
514
|
+
this.spendBudget = options.spendBudgetTokens ?? (() => DEFAULT_SPEND_BUDGET_TOKENS)
|
|
515
|
+
this.spendUsed = options.spendUsedToday ?? (now => usedTokensToday(now))
|
|
496
516
|
mkdirSync(dir, { recursive: true })
|
|
497
517
|
this.file = join(dir, 'ledger-v2.json')
|
|
498
518
|
this.lockFile = join(dir, 'ledger-v2.lock')
|
|
@@ -747,6 +767,17 @@ export class HostTaskLedger {
|
|
|
747
767
|
return []
|
|
748
768
|
}
|
|
749
769
|
|
|
770
|
+
const spendRefusal = this.spendRefusal(triggeredAt)
|
|
771
|
+
if (spendRefusal !== undefined) {
|
|
772
|
+
// A scheduled occurrence has no client to throw at, so the refusal lands
|
|
773
|
+
// on the board's own scheduler error and the occurrence is skipped without
|
|
774
|
+
// consuming the rule's run budget: raising the cap, or the day rolling
|
|
775
|
+
// over, admits the next trigger instead of leaving a spent rule behind.
|
|
776
|
+
this.document.scheduler.error = `scheduled run refused for task ${taskId}: ${spendRefusal}`
|
|
777
|
+
this.skipOccurrence(taskId, 'limit', triggeredAt)
|
|
778
|
+
return []
|
|
779
|
+
}
|
|
780
|
+
|
|
750
781
|
if (schedule.mode === 'once') {
|
|
751
782
|
// The single planned instant is due: open its one run and stop the rule
|
|
752
783
|
// in the same commit, so the budget can never produce a second one.
|
|
@@ -773,6 +804,21 @@ export class HostTaskLedger {
|
|
|
773
804
|
})
|
|
774
805
|
}
|
|
775
806
|
|
|
807
|
+
/**
|
|
808
|
+
* Why a due occurrence may not open a run because the day already spent the
|
|
809
|
+
* cap, or undefined when it may. A cap of 0 — the default — answers before the
|
|
810
|
+
* measurement is read, so a board with no gate reads no ledger file.
|
|
811
|
+
* @param now - clock instant (ms epoch).
|
|
812
|
+
* @returns the refusal message, when the cap is reached.
|
|
813
|
+
*/
|
|
814
|
+
private spendRefusal(now: number): string | undefined {
|
|
815
|
+
const cap = this.spendBudget()
|
|
816
|
+
if (!(cap > 0)) return undefined
|
|
817
|
+
const used = this.spendUsed(now)
|
|
818
|
+
if (used === undefined || !spendCapReached(used, cap)) return undefined
|
|
819
|
+
return spendCapMessage(used, cap)
|
|
820
|
+
}
|
|
821
|
+
|
|
776
822
|
/**
|
|
777
823
|
* Record a due occurrence that opened no execution: roll a recurring rule to
|
|
778
824
|
* its next occurrence (budget untouched), or stop it when there is none. A
|
|
@@ -871,8 +917,12 @@ export class HostTaskLedger {
|
|
|
871
917
|
* and only finalizes once every child execution in its run group has
|
|
872
918
|
* settled, so a parent card leaves 'running' with the whole tree's verdict
|
|
873
919
|
* rather than its own turn alone.
|
|
920
|
+
*
|
|
921
|
+
* `summary` is what the run left behind (see `ExecutionSummary`), passed in
|
|
922
|
+
* by whichever reader observed the session. It is informational: a caller
|
|
923
|
+
* without one settles exactly as before, and a settlement never waits on it.
|
|
874
924
|
*/
|
|
875
|
-
settle(taskId: string, executionId: string, outcome: ExecutionOutcome, error?: string): void {
|
|
925
|
+
settle(taskId: string, executionId: string, outcome: ExecutionOutcome, error?: string, summary?: ExecutionSummary): void {
|
|
876
926
|
const now = this.now()
|
|
877
927
|
const task = this.document.tasks.find(item => item.id === taskId)
|
|
878
928
|
const execution = task?.executions.find(entry => entry.id === executionId)
|
|
@@ -880,17 +930,22 @@ export class HostTaskLedger {
|
|
|
880
930
|
const groupId = execution.runGroupId
|
|
881
931
|
if (groupId === undefined) {
|
|
882
932
|
this.document.tasks = this.document.tasks.map(item => item.id === taskId
|
|
883
|
-
? settleExecution(item, executionId, outcome, now, error)
|
|
933
|
+
? settleExecution(item, executionId, outcome, now, error, summary)
|
|
884
934
|
: item)
|
|
885
935
|
this.commit()
|
|
886
936
|
return
|
|
887
937
|
}
|
|
888
938
|
let changed = false
|
|
889
939
|
if (execution.ownResult === undefined) {
|
|
940
|
+
// A cascade parent records its own turn's closing text with its own
|
|
941
|
+
// outcome; the fold that finalizes the card carries no session of its own
|
|
942
|
+
// and leaves what is already here in place.
|
|
890
943
|
this.document.tasks = this.document.tasks.map(item => item.id !== taskId ? item : {
|
|
891
944
|
...item,
|
|
892
945
|
updatedAt: now,
|
|
893
|
-
executions: item.executions.map(entry => entry.id === executionId
|
|
946
|
+
executions: item.executions.map(entry => entry.id === executionId
|
|
947
|
+
? { ...entry, ownResult: outcome, ownError: error, ...(summary === undefined ? {} : { summary }) }
|
|
948
|
+
: entry),
|
|
894
949
|
})
|
|
895
950
|
changed = true
|
|
896
951
|
}
|
|
@@ -974,7 +1029,7 @@ export class HostTaskLedger {
|
|
|
974
1029
|
const input = action.input.freeze === undefined || initiator === undefined || initiator === ''
|
|
975
1030
|
? action.input
|
|
976
1031
|
: { ...action.input, freeze: { ...action.input.freeze, frozenBy: initiator } }
|
|
977
|
-
const result = applyCreateTask(this.document.tasks, input, now, action.id, this.maxSubtaskDepth, timeZone())
|
|
1032
|
+
const result = applyCreateTask(this.document.tasks, input, now, action.id, this.maxSubtaskDepth, timeZone(), this.cardDefaults())
|
|
978
1033
|
if (result.task === undefined) throw new Error(result.error ?? 'invalid task')
|
|
979
1034
|
this.document.tasks = [...result.tasks]
|
|
980
1035
|
break
|
|
@@ -1170,6 +1225,15 @@ export class HostTaskLedger {
|
|
|
1170
1225
|
runs = this.startCascade(task, now, initiator, action.kind === 'rerun')
|
|
1171
1226
|
break
|
|
1172
1227
|
}
|
|
1228
|
+
default: {
|
|
1229
|
+
// Defence in depth. Every kind above is reachable only through
|
|
1230
|
+
// TaskBoardHostService.apply(), which validates the kind first; this
|
|
1231
|
+
// default exists so a future call path that reaches the ledger directly
|
|
1232
|
+
// fails loudly instead of falling through to the commit below — which is
|
|
1233
|
+
// exactly what an unknown kind did while the switch had no default:
|
|
1234
|
+
// unchanged document, new revision.
|
|
1235
|
+
throw new Error(`unknown task board action kind: ${String((action as { kind?: unknown }).kind)}`)
|
|
1236
|
+
}
|
|
1173
1237
|
}
|
|
1174
1238
|
// startCascade committed the opened participants itself; committing again
|
|
1175
1239
|
// here would bump the revision twice for one action.
|
|
@@ -1262,10 +1326,11 @@ export class HostTaskLedger {
|
|
|
1262
1326
|
}
|
|
1263
1327
|
|
|
1264
1328
|
/**
|
|
1265
|
-
* Open one execution per cascade participant
|
|
1266
|
-
* on-board descendants, within the depth limit) under
|
|
1267
|
-
* commit the ledger once.
|
|
1268
|
-
*
|
|
1329
|
+
* Open one execution per cascade participant that still has work (the
|
|
1330
|
+
* requested task and its on-board descendants, within the depth limit) under
|
|
1331
|
+
* a single run group, and commit the ledger once. A descendant in 'done' is
|
|
1332
|
+
* not a participant ({@link joinsCascadeRun}). The returned runs are ordered
|
|
1333
|
+
* root-first, so the Host launches the parent before its subtasks.
|
|
1269
1334
|
* @param root - the task the user ran.
|
|
1270
1335
|
* @param now - clock instant (ms epoch).
|
|
1271
1336
|
* @param initiator - the DSH session that asked for the run (audit only).
|
|
@@ -1285,6 +1350,11 @@ export class HostTaskLedger {
|
|
|
1285
1350
|
const runs: OpenedRun[] = []
|
|
1286
1351
|
for (const task of cascadeTargets(before, root.id, this.maxSubtaskDepth)) {
|
|
1287
1352
|
if (task.archivedAt !== undefined) continue
|
|
1353
|
+
// A subtask that already sits in 'done' is left alone: running the parent
|
|
1354
|
+
// repeats the parent, never the work a subtask has already finished. The
|
|
1355
|
+
// rule is the card's column, so it holds for a manual run, a re-run and a
|
|
1356
|
+
// due occurrence alike.
|
|
1357
|
+
if (!joinsCascadeRun(task, root.id)) continue
|
|
1288
1358
|
if (hasOpenExecution(task)) continue
|
|
1289
1359
|
const base = rerun && task.id === root.id ? withStatus(task, 'todo', now) : task
|
|
1290
1360
|
const opened = startExecution(base, now, crypto.randomUUID(), initiator, groupId)
|
package/src/host-runner.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
2
|
+
import type { InvokeRemoteRequest, TypertGateway } from '@deepseek-ai/dsh-api-gateway'
|
|
2
3
|
import type { SessionAddress, SessionHistoryRecord, SessionListValue, SessionPage, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/types'
|
|
3
4
|
import type { CommandResult } from '@deepseek-ai/dsh-commands/types'
|
|
4
5
|
import type { Workspace } from '@deepseek-ai/dsh-workspace/types'
|
|
5
6
|
import { teammateName } from './core/subtask.ts'
|
|
6
7
|
import { mostRecentWorkspaceId } from './core/workspace-target.ts'
|
|
7
|
-
import
|
|
8
|
+
import { declaredRoute, normalizeReasoningEffort, resolveReasoningEffort, type ReasoningRoute } from './core/reasoning-effort.ts'
|
|
9
|
+
import type { ModelCatalogView } from './core/verification.ts'
|
|
10
|
+
import type { ExecutionSummary, TaskPermission, TaskRecord } from './core/tasks.ts'
|
|
11
|
+
import { executionSummaryOf } from './core/execution-summary.ts'
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* Host services needed to validate a task's workspace before creating a
|
|
@@ -14,13 +18,69 @@ export interface TaskBoardWorkspaceRegistry {
|
|
|
14
18
|
list(): readonly Workspace[]
|
|
15
19
|
}
|
|
16
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The peer every gateway request names: derived from the public
|
|
23
|
+
* `InvokeRemoteRequest` type so this package needs no direct dependency on
|
|
24
|
+
* `@deepseek-ai/dsh-typert-protocol` for the shape.
|
|
25
|
+
*/
|
|
26
|
+
export type GatewayPeer = InvokeRemoteRequest['peer']
|
|
27
|
+
|
|
17
28
|
interface GatewayRequest {
|
|
18
29
|
namespace: string
|
|
19
30
|
method: string
|
|
20
31
|
args: Record<string, unknown>
|
|
32
|
+
peer: GatewayPeer
|
|
21
33
|
signal?: AbortSignal
|
|
22
34
|
}
|
|
23
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Mint the in-process owner peer this plugin's Host calls speak for.
|
|
38
|
+
*
|
|
39
|
+
* The 0.2.1 gateway made `peer` mandatory on every request, and the
|
|
40
|
+
* authorization layer reads only `peer.principal`: a principal of
|
|
41
|
+
* `{ kind: 'owner' }` is how host-local code states that the call IS the local
|
|
42
|
+
* user driving their own Host, so the gateway answers it directly instead of
|
|
43
|
+
* running a remote-access decision (only non-owner principals are judged).
|
|
44
|
+
* That is exactly the task board's position — it creates, renames, prompts,
|
|
45
|
+
* and reads sessions as the Host itself, which before 0.2.1 was the implicit
|
|
46
|
+
* privilege of every in-process caller. The board claims owner explicitly, and
|
|
47
|
+
* only ever inside its own Host process: no wire field can set a principal,
|
|
48
|
+
* and this plugin never forwards a browser-supplied one.
|
|
49
|
+
*
|
|
50
|
+
* `interactions` stays `'none'`: the board only invokes methods and opens the
|
|
51
|
+
* short `session/follow` stream. The gateway's interactions check gates
|
|
52
|
+
* exactly the forwarded-event endpoints (opening an event stream, answering a
|
|
53
|
+
* waterfall), which this caller never touches; an `'answer'` peer would
|
|
54
|
+
* additionally receive forwarded Host events, a capability the board neither
|
|
55
|
+
* needs nor wants.
|
|
56
|
+
*
|
|
57
|
+
* The peer's signal aborts once `ctx` disposes, so streams opened for it end
|
|
58
|
+
* with the plugin fiber, and `dispose()` is idempotent with racing calls
|
|
59
|
+
* sharing one completion. The id carries no credential — the protocol fixes
|
|
60
|
+
* `principal` as the only identity persisted in a session log — so a fresh
|
|
61
|
+
* unique id per mount is sufficient.
|
|
62
|
+
*/
|
|
63
|
+
export function createOwnerPeer(ctx: Context): GatewayPeer {
|
|
64
|
+
const controller = new AbortController()
|
|
65
|
+
let completion: Promise<void> | undefined
|
|
66
|
+
const peer: GatewayPeer = {
|
|
67
|
+
id: `task-board-owner:${crypto.randomUUID()}` as GatewayPeer['id'],
|
|
68
|
+
ctx,
|
|
69
|
+
principal: { kind: 'owner' },
|
|
70
|
+
signal: controller.signal,
|
|
71
|
+
interactions: 'none',
|
|
72
|
+
dispose() {
|
|
73
|
+
if (completion === undefined) {
|
|
74
|
+
controller.abort()
|
|
75
|
+
completion = Promise.resolve()
|
|
76
|
+
}
|
|
77
|
+
return completion
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
ctx.effect(() => () => { void peer.dispose() }, 'task-board owner peer')
|
|
81
|
+
return peer
|
|
82
|
+
}
|
|
83
|
+
|
|
24
84
|
interface SessionGateway {
|
|
25
85
|
invoke(request: GatewayRequest): Promise<unknown>
|
|
26
86
|
stream?(request: GatewayRequest): Promise<AsyncIterable<unknown>>
|
|
@@ -110,9 +170,9 @@ export type ExecutionInspection =
|
|
|
110
170
|
* forever.
|
|
111
171
|
*/
|
|
112
172
|
| { outcome: 'pending'; unreadable?: true; reason?: string }
|
|
113
|
-
| { outcome: 'succeeded' }
|
|
114
|
-
| { outcome: 'failed'; error: string }
|
|
115
|
-
| { outcome: 'cancelled'; error: string }
|
|
173
|
+
| { outcome: 'succeeded'; summary?: ExecutionSummary }
|
|
174
|
+
| { outcome: 'failed'; error: string; summary?: ExecutionSummary }
|
|
175
|
+
| { outcome: 'cancelled'; error: string; summary?: ExecutionSummary }
|
|
116
176
|
|
|
117
177
|
/** A post-create launch failure that still identifies the session to the ledger. */
|
|
118
178
|
export class SessionLaunchError extends Error {
|
|
@@ -313,10 +373,20 @@ function invokeWireArgs(namespace: string, method: string, request: Record<strin
|
|
|
313
373
|
}
|
|
314
374
|
|
|
315
375
|
export class HostExecutionRunner {
|
|
316
|
-
/**
|
|
376
|
+
/**
|
|
377
|
+
* Newest event sequence per session whose COMPLETE history walk (reaching
|
|
378
|
+
* the execution boundary) found no matching execution end. A later walk may
|
|
379
|
+
* trust everything at or below it and examine only newer records.
|
|
380
|
+
*/
|
|
317
381
|
private readonly scanMemos = new Map<string, number>()
|
|
318
382
|
private readonly unavailableAttempts: number
|
|
319
383
|
private readonly unavailableBackoffMs: number
|
|
384
|
+
/**
|
|
385
|
+
* The peer every request speaks for. Production passes the peer bound to the
|
|
386
|
+
* plugin fiber; a bare runner (unit tests around fake gateways) gets one
|
|
387
|
+
* bound to a fresh root context instead.
|
|
388
|
+
*/
|
|
389
|
+
private readonly ownerPeer: GatewayPeer
|
|
320
390
|
private unsupportedSessionListWarned = false
|
|
321
391
|
|
|
322
392
|
constructor(
|
|
@@ -324,18 +394,20 @@ export class HostExecutionRunner {
|
|
|
324
394
|
private readonly commands?: SessionCommandDispatcher,
|
|
325
395
|
private readonly workspaceRegistry?: TaskBoardWorkspaceRegistry,
|
|
326
396
|
unavailableRetry?: { attempts?: number; backoffMs?: number },
|
|
397
|
+
ownerPeer?: GatewayPeer,
|
|
327
398
|
) {
|
|
328
399
|
this.unavailableAttempts = unavailableRetry?.attempts ?? SERVICE_UNAVAILABLE_ATTEMPTS
|
|
329
400
|
this.unavailableBackoffMs = unavailableRetry?.backoffMs ?? SERVICE_UNAVAILABLE_BACKOFF_MS
|
|
401
|
+
this.ownerPeer = ownerPeer ?? createOwnerPeer(new Context())
|
|
330
402
|
}
|
|
331
403
|
|
|
332
404
|
private invoke(namespace: string, method: string, request: Record<string, unknown>, signal?: AbortSignal): Promise<unknown> {
|
|
333
|
-
return this.gateway.invoke({ namespace, method, args: invokeWireArgs(namespace, method, request), ...(signal === undefined ? {} : { signal }) })
|
|
405
|
+
return this.gateway.invoke({ namespace, method, args: invokeWireArgs(namespace, method, request), peer: this.ownerPeer, ...(signal === undefined ? {} : { signal }) })
|
|
334
406
|
}
|
|
335
407
|
|
|
336
408
|
private stream(namespace: string, method: string, request: Record<string, unknown>, signal?: AbortSignal): Promise<AsyncIterable<unknown>> {
|
|
337
409
|
if (!('stream' in this.gateway) || this.gateway.stream === undefined) throw new Error('gateway stream is unavailable')
|
|
338
|
-
return this.gateway.stream({ namespace, method, args: { request }, ...(signal === undefined ? {} : { signal }) })
|
|
410
|
+
return this.gateway.stream({ namespace, method, args: { request }, peer: this.ownerPeer, ...(signal === undefined ? {} : { signal }) })
|
|
339
411
|
}
|
|
340
412
|
|
|
341
413
|
/**
|
|
@@ -377,6 +449,14 @@ export class HostExecutionRunner {
|
|
|
377
449
|
* `goalRun` still applies on top of it (both must ASK for a goal).
|
|
378
450
|
*/
|
|
379
451
|
goalEnabled?: boolean
|
|
452
|
+
/**
|
|
453
|
+
* The host model catalog, read ONCE per execution by the caller. The card's
|
|
454
|
+
* pinned reasoning effort is sent only when this catalog declares it for the
|
|
455
|
+
* route the execution runs at, so one snapshot decides both the acceptance
|
|
456
|
+
* contract and the effort this run freezes. Absent means "no capability
|
|
457
|
+
* evidence": an effort is then not sent at all.
|
|
458
|
+
*/
|
|
459
|
+
catalog?: ModelCatalogView
|
|
380
460
|
} = {}): Promise<string> {
|
|
381
461
|
// A handover bundle overrides the legacy pin fields: the bundle is the
|
|
382
462
|
// authoritative execution triplet for a continuation card (issue #5). A
|
|
@@ -417,7 +497,7 @@ export class HostExecutionRunner {
|
|
|
417
497
|
// at the gate without its binding.
|
|
418
498
|
options.onSession?.(reused)
|
|
419
499
|
await this.assertReusedPreset(reused, mode)
|
|
420
|
-
await this.pinAndPrompt(reused, task, permission, options.promptContext, options.onGoalArmed, options.goalEnabled === true)
|
|
500
|
+
await this.pinAndPrompt(reused, task, permission, options.promptContext, options.onGoalArmed, options.goalEnabled === true, options.catalog)
|
|
421
501
|
} catch (error) {
|
|
422
502
|
throw new SessionLaunchError(reused, error)
|
|
423
503
|
}
|
|
@@ -431,7 +511,7 @@ export class HostExecutionRunner {
|
|
|
431
511
|
options.onSession?.(sessionId)
|
|
432
512
|
try {
|
|
433
513
|
await this.invoke('session', 'rename', { sessionId, title: task.title })
|
|
434
|
-
await this.pinAndPrompt(sessionId, task, permission, options.promptContext, options.onGoalArmed, options.goalEnabled === true)
|
|
514
|
+
await this.pinAndPrompt(sessionId, task, permission, options.promptContext, options.onGoalArmed, options.goalEnabled === true, options.catalog)
|
|
435
515
|
} catch (error) {
|
|
436
516
|
throw new SessionLaunchError(sessionId, error)
|
|
437
517
|
}
|
|
@@ -466,10 +546,59 @@ export class HostExecutionRunner {
|
|
|
466
546
|
)
|
|
467
547
|
}
|
|
468
548
|
|
|
549
|
+
/**
|
|
550
|
+
* Split a `provider/model` pin. A pin without a provider keeps only the model
|
|
551
|
+
* id: the provider is the one the host catalog declares for it, resolved at
|
|
552
|
+
* launch because the session wire contract requires a provider.
|
|
553
|
+
*/
|
|
554
|
+
private static pinnedRoute(model: string | undefined): ReasoningRoute | undefined {
|
|
555
|
+
const raw = model?.trim()
|
|
556
|
+
if (raw === undefined || raw === '') return undefined
|
|
557
|
+
const slash = raw.indexOf('/')
|
|
558
|
+
if (slash < 0) return { model: raw }
|
|
559
|
+
const provider = raw.slice(0, slash).trim()
|
|
560
|
+
const modelId = raw.slice(slash + 1).trim()
|
|
561
|
+
if (provider === '' || modelId === '') return undefined
|
|
562
|
+
return { provider, model: modelId }
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* The route a card that pins no model actually runs at: the session's own
|
|
567
|
+
* recorded selection (the durable fold the GUI reads; `next` is the pending
|
|
568
|
+
* user choice, `lastUsed` what the last request consumed), or — for a session
|
|
569
|
+
* that has selected none yet, which is exactly a session that would start at
|
|
570
|
+
* the deployment default — the host default from the catalog.
|
|
571
|
+
*
|
|
572
|
+
* A route that cannot be READ is undefined and the effort is not sent:
|
|
573
|
+
* falling back to the host default there would silently switch the model of a
|
|
574
|
+
* session this run only meant to continue.
|
|
575
|
+
*/
|
|
576
|
+
private async sessionRoute(sessionId: ExecutionSessionId, catalog?: ModelCatalogView): Promise<ReasoningRoute | undefined> {
|
|
577
|
+
let selection: { provider?: unknown; model?: unknown } | null | undefined
|
|
578
|
+
try {
|
|
579
|
+
const projections = await this.invoke('session', 'projections', { sessionId }) as
|
|
580
|
+
| { values?: { modelSelection?: { lastUsed?: { provider?: unknown; model?: unknown } | null; next?: { provider?: unknown; model?: unknown } | null } } }
|
|
581
|
+
| null
|
|
582
|
+
selection = projections?.values?.modelSelection?.next ?? projections?.values?.modelSelection?.lastUsed
|
|
583
|
+
} catch (error) {
|
|
584
|
+
console.warn('[dsh-task-board] session/projections failed while resolving the execution model route', error)
|
|
585
|
+
return undefined
|
|
586
|
+
}
|
|
587
|
+
if (typeof selection?.provider === 'string' && selection.provider !== ''
|
|
588
|
+
&& typeof selection.model === 'string' && selection.model !== '') {
|
|
589
|
+
return { provider: selection.provider, model: selection.model }
|
|
590
|
+
}
|
|
591
|
+
return catalog?.default === undefined
|
|
592
|
+
? undefined
|
|
593
|
+
: { provider: catalog.default.provider, model: catalog.default.model }
|
|
594
|
+
}
|
|
595
|
+
|
|
469
596
|
/**
|
|
470
597
|
* Re-assert the pinned execution contract on a session and queue the task
|
|
471
598
|
* prompt. Shared by the fresh-session and reuse paths so both apply exactly
|
|
472
|
-
* the same permission/model pins before the prompt.
|
|
599
|
+
* the same permission/model/effort pins before the prompt. A session that
|
|
600
|
+
* refuses a selection carrying a catalog-confirmed effort throws here, so the
|
|
601
|
+
* prompt is never queued behind a run at the wrong level.
|
|
473
602
|
*/
|
|
474
603
|
private async pinAndPrompt(
|
|
475
604
|
sessionId: ExecutionSessionId,
|
|
@@ -478,6 +607,7 @@ export class HostExecutionRunner {
|
|
|
478
607
|
context: PromptContext = {},
|
|
479
608
|
onGoalArmed?: (armed: boolean) => void,
|
|
480
609
|
goalEnabled = false,
|
|
610
|
+
catalog?: ModelCatalogView,
|
|
481
611
|
): Promise<void> {
|
|
482
612
|
if (permission !== undefined) {
|
|
483
613
|
if (this.commands === undefined) throw new Error('permission command dispatcher is unavailable')
|
|
@@ -485,19 +615,43 @@ export class HostExecutionRunner {
|
|
|
485
615
|
if (command === undefined) throw new Error('permission command was not acknowledged')
|
|
486
616
|
if (command.kind !== 'success') throw new Error(command.text ?? 'permission command failed')
|
|
487
617
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
618
|
+
// The effort is bound to the model route the execution runs at. A card that
|
|
619
|
+
// pins no model of its own runs at the session's route, so that route is
|
|
620
|
+
// resolved first — and only when there is an effort to place: a card that
|
|
621
|
+
// never chose one must not gain a model-selection call it did not have.
|
|
622
|
+
const requestedEffort = normalizeReasoningEffort(task.reasoningEffort)
|
|
623
|
+
const pinned = HostExecutionRunner.pinnedRoute(task.model)
|
|
624
|
+
const route = pinned ?? (requestedEffort === undefined ? undefined : await this.sessionRoute(sessionId, catalog))
|
|
625
|
+
if (route !== undefined) {
|
|
626
|
+
const routeLabel = `${route.provider === undefined ? '' : route.provider + '/'}${route.model}`
|
|
627
|
+
const decision = resolveReasoningEffort(requestedEffort, catalog, route)
|
|
628
|
+
if (decision.dropped !== undefined) {
|
|
629
|
+
console.warn(`[dsh-task-board] model route ${routeLabel} does not declare reasoning effort "${decision.dropped}"; session ${sessionId} runs at the model default`)
|
|
630
|
+
}
|
|
631
|
+
// The catalog completes a bare model pin into the provider the session
|
|
632
|
+
// request must name; an undeclared pin keeps its own spelling exactly as
|
|
633
|
+
// before, minus an effort that could not be verified.
|
|
634
|
+
const declared = declaredRoute(catalog, route)
|
|
635
|
+
const provider = declared?.provider ?? route.provider
|
|
636
|
+
const modelId = declared?.model ?? route.model
|
|
493
637
|
try {
|
|
494
638
|
await this.invoke('session', 'selectModel', {
|
|
495
639
|
sessionId,
|
|
496
|
-
...(provider ? {
|
|
640
|
+
...(provider === undefined ? {} : { provider }),
|
|
497
641
|
model: modelId,
|
|
642
|
+
...(decision.effort === undefined ? {} : { reasoningEffort: decision.effort }),
|
|
498
643
|
})
|
|
499
644
|
} catch (modelError) {
|
|
500
|
-
|
|
645
|
+
// An effort the catalog CONFIRMED for this route is a contract, not a
|
|
646
|
+
// preference: if the session refuses the selection, the run fails here,
|
|
647
|
+
// before the prompt, rather than silently executing at the model default
|
|
648
|
+
// the user did not pick. A selection that carries no confirmed effort
|
|
649
|
+
// keeps the best-effort behavior: the card was asked to run, and losing
|
|
650
|
+
// the work over a model switch this run never promised is worse.
|
|
651
|
+
if (decision.effort !== undefined) {
|
|
652
|
+
throw new Error(`session ${sessionId} refused the model selection "${provider === undefined ? modelId : provider + '/' + modelId}" with reasoning effort "${decision.effort}": ` + (modelError instanceof Error ? modelError.message : String(modelError)))
|
|
653
|
+
}
|
|
654
|
+
console.warn(`[dsh-task-board] failed to select model "${provider === undefined ? modelId : provider + '/' + modelId}" for session ${sessionId}, falling back to default:`, modelError)
|
|
501
655
|
}
|
|
502
656
|
}
|
|
503
657
|
await this.invoke('session', 'prompt', {
|
|
@@ -704,10 +858,21 @@ export class HostExecutionRunner {
|
|
|
704
858
|
}
|
|
705
859
|
const openingEvents = opening.records.map(record => ({ event: recordEvent(record) }))
|
|
706
860
|
const newestSeq = openingEvents.reduce<number | undefined>((newest, entry) => newest === undefined ? entry.event.seq : Math.max(newest, entry.event.seq), undefined)
|
|
707
|
-
|
|
861
|
+
const scannedThrough = this.scanMemos.get(sessionId)
|
|
862
|
+
if (newestSeq !== undefined && scannedThrough === newestSeq) return { outcome: 'pending' }
|
|
863
|
+
// The memo is not only "nothing changed": it is the seq up to which a
|
|
864
|
+
// COMPLETE walk already proved this execution has no completed turn. A
|
|
865
|
+
// session log is append-only, so records at or below it can never acquire
|
|
866
|
+
// one — this pass only has to examine what arrived after it. Without that,
|
|
867
|
+
// a working teammate (whose roster entry never stops reporting `running`,
|
|
868
|
+
// so every poll re-inspects it) re-read its whole history since the run
|
|
869
|
+
// started once per poll: a 1200-record history cost 12 page RPCs and 1223
|
|
870
|
+
// materialized records per session per poll, against 0 and 21 here.
|
|
871
|
+
const oldestOpeningSeq = openingEvents.reduce<number | undefined>((oldest, entry) => oldest === undefined ? entry.event.seq : Math.min(oldest, entry.event.seq), undefined)
|
|
872
|
+
const coveredThrough = scannedThrough !== undefined && oldestOpeningSeq !== undefined && oldestOpeningSeq <= scannedThrough
|
|
708
873
|
const events: Array<{ event: { type: string; seq: number; time: number; data: unknown } }> = [...openingEvents]
|
|
709
874
|
let beforeSeq: number | undefined
|
|
710
|
-
let reachedExecutionBoundary = !opening.hasMore
|
|
875
|
+
let reachedExecutionBoundary = !opening.hasMore || coveredThrough
|
|
711
876
|
for (let page = 0; page < HISTORY_PAGE_LIMIT && !reachedExecutionBoundary; page += 1) {
|
|
712
877
|
let history: SessionPage
|
|
713
878
|
try {
|
|
@@ -724,11 +889,13 @@ export class HostExecutionRunner {
|
|
|
724
889
|
const pageEntries = pageEvents(history)
|
|
725
890
|
events.push(...pageEntries)
|
|
726
891
|
const oldestTime = pageEntries.reduce<number | undefined>((oldest, entry) => oldest === undefined ? entry.event.time : Math.min(oldest, entry.event.time), undefined)
|
|
727
|
-
|
|
892
|
+
const oldestSeq = pageEntries.reduce<number | undefined>((oldest, entry) => oldest === undefined ? entry.event.seq : Math.min(oldest, entry.event.seq), undefined)
|
|
893
|
+
if (!history.hasMore
|
|
894
|
+
|| (oldestTime !== undefined && oldestTime <= startedAt)
|
|
895
|
+
|| (scannedThrough !== undefined && oldestSeq !== undefined && oldestSeq <= scannedThrough)) {
|
|
728
896
|
reachedExecutionBoundary = true
|
|
729
897
|
break
|
|
730
898
|
}
|
|
731
|
-
const oldestSeq = pageEntries.reduce<number | undefined>((oldest, entry) => oldest === undefined ? entry.event.seq : Math.min(oldest, entry.event.seq), undefined)
|
|
732
899
|
if (oldestSeq === undefined || oldestSeq === beforeSeq) return { outcome: 'pending' }
|
|
733
900
|
beforeSeq = oldestSeq
|
|
734
901
|
}
|
|
@@ -743,13 +910,20 @@ export class HostExecutionRunner {
|
|
|
743
910
|
return { outcome: 'pending' }
|
|
744
911
|
}
|
|
745
912
|
this.scanMemos.delete(sessionId)
|
|
913
|
+
// What the run left behind rides the verdict the caller settles with, for a
|
|
914
|
+
// success and a failure alike: the events are in hand here, and no later
|
|
915
|
+
// reader can recover them once the session is gone. A run with no assistant
|
|
916
|
+
// prose carries no field at all, so settling stays a decision about the
|
|
917
|
+
// verdict alone.
|
|
918
|
+
const closing = executionSummaryOf(events.map(entry => entry.event), startedAt)
|
|
919
|
+
const carried = closing === undefined ? {} : { summary: closing }
|
|
746
920
|
const reason = nonCompletedTurnEnd(turnEnd.event.data)
|
|
747
|
-
if (reason === undefined) return await this.goalVerdict(sessionId) ?? { outcome: 'succeeded' }
|
|
921
|
+
if (reason === undefined) return { ...(await this.goalVerdict(sessionId) ?? { outcome: 'succeeded' as const }), ...carried }
|
|
748
922
|
// `error` keeps its historical wording; every other non-completed reason
|
|
749
923
|
// (aborted / blocked / max-tokens / interrupted) now reports instead of
|
|
750
924
|
// silently counting as success.
|
|
751
925
|
return reason === 'error'
|
|
752
|
-
? { outcome: 'failed', error: 'agent turn ended with an error' }
|
|
753
|
-
: { outcome: 'failed', error: 'agent turn ended without completing: ' + reason }
|
|
926
|
+
? { outcome: 'failed', error: 'agent turn ended with an error', ...carried }
|
|
927
|
+
: { outcome: 'failed', error: 'agent turn ended without completing: ' + reason, ...carried }
|
|
754
928
|
}
|
|
755
929
|
}
|