@fish-under-sea/dsh-client-ui-task-board-fish 1.0.2 → 1.1.0
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/NOTICE +1 -1
- package/README.en.md +4 -4
- package/README.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +4428 -1508
- package/lib/client.js.map +1 -1
- package/lib/index.js +2670 -496
- package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
- package/lib/types/client/PluginSettingsCard.d.ts +130 -19
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +63 -0
- package/lib/types/client/board/AttachmentField.d.ts +70 -0
- package/lib/types/client/board/ExecutionLog.d.ts +24 -0
- package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
- package/lib/types/client/board/TaskForm.d.ts +4 -0
- package/lib/types/client/board/VerificationReport.d.ts +2 -15
- package/lib/types/client/board/model-options.d.ts +87 -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/source-group.d.ts +27 -0
- package/lib/types/client/body-mutations.d.ts +45 -0
- package/lib/types/client/host-api.d.ts +25 -0
- package/lib/types/client/locales.d.ts +87 -9
- package/lib/types/client/pending-verify.d.ts +47 -0
- package/lib/types/client/plugin-card-seat.d.ts +3 -1
- package/lib/types/client/service.d.ts +4 -1
- package/lib/types/client/settings-form.d.ts +73 -51
- package/lib/types/core/attachment.d.ts +132 -0
- package/lib/types/core/card-defaults.d.ts +78 -0
- package/lib/types/core/controller.d.ts +57 -8
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +116 -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/session-reuse.d.ts +7 -1
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/subtask.d.ts +100 -37
- package/lib/types/core/tasks.d.ts +94 -10
- package/lib/types/core/use-cases/task-create.d.ts +10 -5
- package/lib/types/core/use-cases/task-tag.d.ts +36 -0
- package/lib/types/core/use-cases/task-update.d.ts +22 -1
- package/lib/types/core/wire-projection.d.ts +35 -0
- package/lib/types/core/workspace-target.d.ts +23 -3
- package/lib/types/host/attachments.d.ts +250 -0
- package/lib/types/host/extension-registry.d.ts +40 -0
- package/lib/types/host/launch-admission.d.ts +71 -0
- package/lib/types/host-ledger.d.ts +114 -47
- package/lib/types/host-routes.d.ts +63 -0
- package/lib/types/host-runner.d.ts +164 -18
- package/lib/types/host-service.d.ts +182 -46
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +173 -54
- package/lib/types/loopback.d.ts +41 -1
- package/lib/types/protocol.d.ts +52 -11
- package/lib/types/tool-surface.d.ts +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +35 -28
- package/src/client/CardDefaultPresetField.tsx +101 -0
- package/src/client/PluginSettingsCard.tsx +385 -111
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/TaskBoardSettingsCard.tsx +332 -37
- package/src/client/board/AttachmentField.tsx +383 -0
- package/src/client/board/EditTaskModal.tsx +63 -0
- package/src/client/board/ExecutionLog.tsx +154 -0
- package/src/client/board/LinkSubtaskModal.tsx +1 -1
- package/src/client/board/NewTaskModal.tsx +154 -45
- package/src/client/board/ReasoningEffortField.tsx +50 -0
- package/src/client/board/TagManagerModal.tsx +151 -2
- package/src/client/board/TaskBoard.tsx +47 -10
- package/src/client/board/TaskCard.tsx +45 -23
- package/src/client/board/TaskDetail.tsx +468 -258
- package/src/client/board/TaskForm.tsx +19 -4
- package/src/client/board/VerificationReport.tsx +143 -104
- package/src/client/board/model-options.ts +208 -0
- package/src/client/board/preset-label.ts +32 -0
- package/src/client/board/preset-roster.ts +58 -0
- package/src/client/board/source-group.ts +94 -0
- package/src/client/board/task-markdown.module.css +11 -8
- package/src/client/board-settings.module.css +35 -7
- package/src/client/board.module.css +1044 -105
- package/src/client/body-mutations.ts +133 -0
- package/src/client/host-api.ts +70 -0
- package/src/client/index.ts +109 -95
- package/src/client/locales.ts +205 -48
- package/src/client/pending-verify.ts +90 -0
- package/src/client/plugin-card-seat.ts +8 -2
- package/src/client/service.ts +24 -0
- package/src/client/settings-card.module.css +466 -89
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/settings-form.ts +102 -60
- package/src/core/attachment.ts +287 -0
- package/src/core/card-defaults.ts +132 -0
- package/src/core/controller.ts +90 -11
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +120 -0
- package/src/core/launch-width.ts +38 -0
- package/src/core/reasoning-effort.ts +92 -0
- package/src/core/session-reuse.ts +7 -1
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +19 -1
- package/src/core/subtask.ts +144 -68
- package/src/core/tasks.ts +117 -10
- package/src/core/use-cases/task-create.ts +27 -16
- package/src/core/use-cases/task-tag.ts +56 -0
- package/src/core/use-cases/task-update.ts +33 -5
- package/src/core/wire-projection.ts +81 -0
- package/src/core/workspace-target.ts +27 -3
- package/src/host/agent-tools.ts +33 -21
- package/src/host/attachments.ts +650 -0
- package/src/host/extension-registry.ts +150 -5
- package/src/host/launch-admission.ts +139 -0
- package/src/host-ledger.ts +248 -117
- package/src/host-routes.ts +233 -15
- package/src/host-runner.ts +395 -61
- package/src/host-service.ts +512 -139
- package/src/host-spend.ts +105 -0
- package/src/index.ts +312 -92
- package/src/loopback.ts +57 -1
- package/src/protocol.ts +83 -18
- package/src/tool-surface.ts +1 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which reasoning effort one execution may actually send.
|
|
3
|
+
*
|
|
4
|
+
* The rule lives here, in one pure place, so the launch path cannot drift from
|
|
5
|
+
* what the picker promises: an effort is sent ONLY for the exact model route
|
|
6
|
+
* whose adapter declares that id. An unsupported value is dropped rather than
|
|
7
|
+
* passed through — the Host validates the selection against the same
|
|
8
|
+
* capability (`resolveCallConfig` rejects an unsupported effort) and the whole
|
|
9
|
+
* model selection would fail with it. An absent effort stays absent: the SDK
|
|
10
|
+
* then materializes the model's own default, which is exactly what "inherit
|
|
11
|
+
* the model" means.
|
|
12
|
+
*
|
|
13
|
+
* A card that pins a bare model id also gets its provider resolved here: the
|
|
14
|
+
* session wire contract requires `provider` (ModelSelection), so the catalog is
|
|
15
|
+
* the only place that can complete the documented `provider/model` or model-id
|
|
16
|
+
* pin.
|
|
17
|
+
*/
|
|
18
|
+
import type { CatalogModel, ModelCatalogView } from './verification.ts'
|
|
19
|
+
|
|
20
|
+
/** One execution route an effort resolves against: `provider/model`, or a bare model id. */
|
|
21
|
+
export interface ReasoningRoute {
|
|
22
|
+
provider?: string
|
|
23
|
+
model: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The catalog entry a route names, once the catalog can complete it. */
|
|
27
|
+
export interface DeclaredReasoningRoute {
|
|
28
|
+
provider: string
|
|
29
|
+
model: string
|
|
30
|
+
/** The adapter's reasoning metadata; absent when it exposes none. */
|
|
31
|
+
reasoning?: CatalogModel['reasoning']
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** What one card's effort resolves to for one route. */
|
|
35
|
+
export interface ReasoningEffortDecision {
|
|
36
|
+
/** The effort to send; absent means "send none". */
|
|
37
|
+
effort?: string
|
|
38
|
+
/** The card's own value when it will NOT be sent. */
|
|
39
|
+
dropped?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Trim one optional effort: blank text means "not set", like every other pinned target. */
|
|
43
|
+
export function normalizeReasoningEffort(value: string | undefined): string | undefined {
|
|
44
|
+
const trimmed = value?.trim()
|
|
45
|
+
return trimmed === undefined || trimmed === '' ? undefined : trimmed
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Complete one route through the host catalog: a qualified route must match its
|
|
50
|
+
* provider group, and a bare model id matches the first group carrying it —
|
|
51
|
+
* which is the provider the request then names.
|
|
52
|
+
* @param catalog - the host model catalog, when this deployment serves one.
|
|
53
|
+
* @param route - the route as the card pins it.
|
|
54
|
+
* @returns the completed route with its reasoning metadata, or undefined when
|
|
55
|
+
* the catalog declares no such model.
|
|
56
|
+
*/
|
|
57
|
+
export function declaredRoute(
|
|
58
|
+
catalog: ModelCatalogView | undefined,
|
|
59
|
+
route: ReasoningRoute,
|
|
60
|
+
): DeclaredReasoningRoute | undefined {
|
|
61
|
+
const groups = catalog?.groups ?? []
|
|
62
|
+
const matched = route.provider === undefined || route.provider === ''
|
|
63
|
+
? groups.find(group => group.models.some(model => model.id === route.model))
|
|
64
|
+
: groups.find(group => group.id === route.provider)
|
|
65
|
+
const model = matched?.models.find(candidate => candidate.id === route.model)
|
|
66
|
+
if (matched === undefined || model === undefined) return undefined
|
|
67
|
+
return {
|
|
68
|
+
provider: matched.id,
|
|
69
|
+
model: model.id,
|
|
70
|
+
...(model.reasoning === undefined ? {} : { reasoning: model.reasoning }),
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Resolve the effort one execution sends.
|
|
76
|
+
* @param requested - the card's stored effort (absent or blank = inherit).
|
|
77
|
+
* @param catalog - the host model catalog, when this deployment serves one.
|
|
78
|
+
* @param route - the route the execution will actually run at.
|
|
79
|
+
* @returns the effort to send, or the dropped value that will not be sent.
|
|
80
|
+
*/
|
|
81
|
+
export function resolveReasoningEffort(
|
|
82
|
+
requested: string | undefined,
|
|
83
|
+
catalog: ModelCatalogView | undefined,
|
|
84
|
+
route: ReasoningRoute | undefined,
|
|
85
|
+
): ReasoningEffortDecision {
|
|
86
|
+
const effort = normalizeReasoningEffort(requested)
|
|
87
|
+
if (effort === undefined) return {}
|
|
88
|
+
if (route === undefined) return { dropped: effort }
|
|
89
|
+
const declared = declaredRoute(catalog, route)
|
|
90
|
+
const supported = declared?.reasoning?.efforts.some(option => option.id === effort) === true
|
|
91
|
+
return supported ? { effort } : { dropped: effort }
|
|
92
|
+
}
|
|
@@ -20,13 +20,19 @@ import type { ExecutionRecord, TaskRecord } from './tasks.ts'
|
|
|
20
20
|
* @param task - the task about to run.
|
|
21
21
|
* @param idleSessionIds - ids the last roster saw as present and not running;
|
|
22
22
|
* undefined when that roster is unknown.
|
|
23
|
+
* @param options.force - continue the settled session regardless of the card's
|
|
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.
|
|
23
27
|
* @returns the session id to continue in, or undefined for a fresh session.
|
|
24
28
|
*/
|
|
25
29
|
export function reusableSessionId(
|
|
26
30
|
task: TaskRecord,
|
|
27
31
|
idleSessionIds: ReadonlySet<string> | undefined,
|
|
32
|
+
options: { force?: boolean } = {},
|
|
28
33
|
): string | undefined {
|
|
29
|
-
if (
|
|
34
|
+
if (options.force !== true && task.reuseSession !== true) return undefined
|
|
35
|
+
if (idleSessionIds === undefined) return undefined
|
|
30
36
|
let last: ExecutionRecord | undefined
|
|
31
37
|
for (let index = task.executions.length - 1; index >= 0; index -= 1) {
|
|
32
38
|
const candidate = task.executions[index]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The daily token ceiling both spend gates share, as pure rules: the cap
|
|
3
|
+
* comparison and the one refusal wording.
|
|
4
|
+
*
|
|
5
|
+
* The unit is tokens, not money. The usage ledger the board reads prices only
|
|
6
|
+
* DeepSeek's own routes, so a cost cap would read 0 on every other route and
|
|
7
|
+
* refuse nothing on exactly the deployments that need it. A cap of 0 is the
|
|
8
|
+
* shipped default and means "no gate": both gates answer before they read a
|
|
9
|
+
* file, subscribe to an event, or compute anything.
|
|
10
|
+
* @module @fish-under-sea/dsh-client-ui-task-board-fish/core/spend-budget
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** Token cap one board day may spend; 0 disables the gate. */
|
|
14
|
+
export const DEFAULT_SPEND_BUDGET_TOKENS = 0
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether a day's measured spend already reached the cap.
|
|
18
|
+
* @param usedTokens - tokens the day's spend measurement reported.
|
|
19
|
+
* @param cap - the configured cap, 0 for "no gate".
|
|
20
|
+
* @returns true when a run must be refused.
|
|
21
|
+
*/
|
|
22
|
+
export function spendCapReached(usedTokens: number, cap: number): boolean {
|
|
23
|
+
return cap > 0 && usedTokens >= cap
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The refusal text both gates report: the thrown message a client sees as
|
|
28
|
+
* board-refused, and the scheduler error a due occurrence records.
|
|
29
|
+
* @param usedTokens - tokens the day's spend measurement reported.
|
|
30
|
+
* @param cap - the configured cap.
|
|
31
|
+
* @returns the refusal message.
|
|
32
|
+
*/
|
|
33
|
+
export function spendCapMessage(usedTokens: number, cap: number): string {
|
|
34
|
+
return `spend cap reached: ${usedTokens} tokens of ${cap} today; raise the cap in the task board settings`
|
|
35
|
+
}
|
package/src/core/store.ts
CHANGED
|
@@ -10,12 +10,14 @@
|
|
|
10
10
|
* localStorage backend.
|
|
11
11
|
*/
|
|
12
12
|
import { isValidCron, isValidTimeZone } from './schedule.ts'
|
|
13
|
-
import { SCHEDULE_STOP_REASONS, isTaskPermission, isTaskStatus, normalizeTags, normalizeTargetId, type ScheduleRule, type ScheduleStopReason, type TaskFreeze, type TaskRecord, type TaskPermission, type TaskStatus } from './tasks.ts'
|
|
13
|
+
import { SCHEDULE_STOP_REASONS, isTaskPermission, isTaskStatus, normalizeExecutionRework, normalizeTags, normalizeTargetId, type ScheduleRule, type ScheduleStopReason, type TaskFreeze, type TaskRecord, type TaskPermission, type TaskStatus } from './tasks.ts'
|
|
14
14
|
import { isExecutionOutcome } from './subtask.ts'
|
|
15
|
+
import { normalizeExecutionSummary } from './execution-summary.ts'
|
|
15
16
|
import type { TaskHandover } from './handover.ts'
|
|
16
17
|
import { sanitizeFreezeSnapshot } from './freeze-snapshot.ts'
|
|
17
18
|
import { sanitizeHandover } from './handover.ts'
|
|
18
19
|
import { normalizeTaskIntegrations } from './extension.ts'
|
|
20
|
+
import { normalizeAttachments } from './attachment.ts'
|
|
19
21
|
import { normalizeVerification } from './verification.ts'
|
|
20
22
|
|
|
21
23
|
/** Persistence seam for the task ledger. */
|
|
@@ -68,9 +70,11 @@ function isTaskRecordShape(value: unknown): value is Omit<TaskRecord, 'status'>
|
|
|
68
70
|
if (record.parentId !== undefined && typeof record.parentId !== 'string') return false
|
|
69
71
|
if (record.workspaceId !== undefined && typeof record.workspaceId !== 'string') return false
|
|
70
72
|
if (record.mode !== undefined && typeof record.mode !== 'string') return false
|
|
73
|
+
if (record.reasoningEffort !== undefined && typeof record.reasoningEffort !== 'string') return false
|
|
71
74
|
if (record.permission !== undefined && typeof record.permission !== 'string') return false
|
|
72
75
|
if (record.integrations !== undefined && (typeof record.integrations !== 'object' || record.integrations === null || Array.isArray(record.integrations))) return false
|
|
73
76
|
if (record.hidden !== undefined && typeof record.hidden !== 'boolean') return false
|
|
77
|
+
if (record.attachments !== undefined && !Array.isArray(record.attachments)) return false
|
|
74
78
|
if (record.reuseSession !== undefined && typeof record.reuseSession !== 'boolean') return false
|
|
75
79
|
if (record.goalRun !== undefined && typeof record.goalRun !== 'boolean') return false
|
|
76
80
|
if (record.skipVerification !== undefined && typeof record.skipVerification !== 'boolean') return false
|
|
@@ -255,9 +259,15 @@ export function parseLedger(raw: string | null): TaskRecord[] {
|
|
|
255
259
|
runGroupId: normalizeTargetId(execution.runGroupId),
|
|
256
260
|
ownResult: isExecutionOutcome(execution.ownResult) ? execution.ownResult : undefined,
|
|
257
261
|
ownError: typeof execution.ownError === 'string' ? execution.ownError : undefined,
|
|
262
|
+
// A summary a reader does not recognize (an older document has none) is
|
|
263
|
+
// simply absent; a malformed one is dropped without costing the run.
|
|
264
|
+
summary: normalizeExecutionSummary(execution.summary),
|
|
258
265
|
// A malformed acceptance block is dropped rather than dropping the
|
|
259
266
|
// execution record: the board then treats that run as unverified.
|
|
260
267
|
verification: normalizeVerification(execution.verification),
|
|
268
|
+
// A malformed rework block is dropped on the same terms: the run itself
|
|
269
|
+
// is what the history is for, and only its instructions are unrecoverable.
|
|
270
|
+
rework: normalizeExecutionRework(execution.rework),
|
|
261
271
|
external: execution.external === true ? true : undefined,
|
|
262
272
|
}))
|
|
263
273
|
// Execution targets are normalized like the schedule: blank strings
|
|
@@ -265,6 +275,10 @@ export function parseLedger(raw: string | null): TaskRecord[] {
|
|
|
265
275
|
// fall back to the session default instead of dropping the row.
|
|
266
276
|
task.workspaceId = normalizeTargetId(row.workspaceId)
|
|
267
277
|
task.mode = normalizeTargetId(row.mode)
|
|
278
|
+
// The effort is repaired like the other execution-target strings: blank text
|
|
279
|
+
// from a hand-edited document clears the pin instead of dropping the row,
|
|
280
|
+
// and the card then runs at its model's own default level.
|
|
281
|
+
task.reasoningEffort = normalizeTargetId(row.reasoningEffort)
|
|
268
282
|
task.archivedAt = typeof row.archivedAt === 'number' && Number.isFinite(row.archivedAt) ? row.archivedAt : undefined
|
|
269
283
|
task.permission = isTaskPermission(row.permission) ? row.permission as TaskPermission : undefined
|
|
270
284
|
task.reuseSession = row.reuseSession === true ? true : undefined
|
|
@@ -282,6 +296,10 @@ export function parseLedger(raw: string | null): TaskRecord[] {
|
|
|
282
296
|
task.tags = normalizeTags(row.tags)
|
|
283
297
|
task.permissionConfirmedAt = typeof row.permissionConfirmedAt === 'number' && Number.isFinite(row.permissionConfirmedAt) ? row.permissionConfirmedAt : undefined
|
|
284
298
|
task.integrations = normalizeTaskIntegrations(row.integrations)
|
|
299
|
+
// Attachments are repaired field by field like the tags: a malformed entry
|
|
300
|
+
// is dropped, and a list that repairs to nothing clears the field instead
|
|
301
|
+
// of dropping the task row.
|
|
302
|
+
task.attachments = normalizeAttachments(row.attachments)
|
|
285
303
|
task.hidden = row.hidden === true ? true : undefined
|
|
286
304
|
tasks.push(task)
|
|
287
305
|
}
|
package/src/core/subtask.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Subtask lineage: the depth gate, the ancestry/descendant queries, the
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* run time.
|
|
3
|
+
* outstanding-descendant decision one run request makes, the deferred
|
|
4
|
+
* settlement of a historical run group, and the execution-target inheritance a
|
|
5
|
+
* subtask resolves at run time.
|
|
6
6
|
*
|
|
7
7
|
* Framework-free (no cordis, no runtime imports) so every rule is
|
|
8
8
|
* unit-testable in isolation. The Host ledger is the only authority; the
|
|
@@ -182,22 +182,127 @@ export function checkParentLink(
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
/**
|
|
185
|
-
* The tasks one run request opens executions for: the requested
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* the
|
|
185
|
+
* The tasks one run request opens executions for: the requested card ALONE.
|
|
186
|
+
*
|
|
187
|
+
* Running a card never expands into its subtask tree. The card's own session
|
|
188
|
+
* reads its subtasks through the board tools and dispatches subagents itself,
|
|
189
|
+
* so a parent run opens exactly one session. Clicking a subtask runs that
|
|
190
|
+
* subtask as its own root, again without expanding its own descendants. The
|
|
191
|
+
* lineage queries around this one answer questions about the tree the card's
|
|
192
|
+
* agent works with (who is still outstanding, what a historical run group
|
|
193
|
+
* still holds open) — never who gets a session from the Host.
|
|
194
|
+
* @param tasks - the ledger.
|
|
195
|
+
* @param rootId - the task the run request named.
|
|
196
|
+
* @returns the one card this run opens an execution for, or [] when unknown.
|
|
189
197
|
*/
|
|
190
|
-
export function cascadeTargets(
|
|
198
|
+
export function cascadeTargets(tasks: readonly TaskRecord[], rootId: string): TaskRecord[] {
|
|
199
|
+
const root = tasks.find(task => task.id === rootId)
|
|
200
|
+
return root === undefined ? [] : [root]
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A task together with every descendant within the configured depth: the
|
|
205
|
+
* subtree a lineage gate (archive, restore, force-close) has to walk.
|
|
206
|
+
*/
|
|
207
|
+
export function subtreeTasks(tasks: readonly TaskRecord[], id: string, maxSubtaskDepth: number): TaskRecord[] {
|
|
208
|
+
const root = tasks.find(task => task.id === id)
|
|
209
|
+
return root === undefined ? [] : [root, ...descendantTasks(tasks, id, maxSubtaskDepth)]
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Whether a card still has work outstanding: anything outside the `done`
|
|
214
|
+
* column. It keys on the column alone, so it covers both a subtask that ran
|
|
215
|
+
* and one an operator moved to done by hand.
|
|
216
|
+
*/
|
|
217
|
+
export function isOutstanding(task: TaskRecord): boolean {
|
|
218
|
+
return task.status !== 'done'
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The descendants of a card that still have work outstanding, in breadth-first
|
|
223
|
+
* order: the cards its own session is expected to dispatch. An archived
|
|
224
|
+
* descendant is off the board and cannot be dispatched, so it is not listed.
|
|
225
|
+
*/
|
|
226
|
+
export function outstandingDescendants(
|
|
191
227
|
tasks: readonly TaskRecord[],
|
|
192
228
|
rootId: string,
|
|
193
229
|
maxSubtaskDepth: number,
|
|
194
230
|
): TaskRecord[] {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
231
|
+
return descendantTasks(tasks, rootId, maxSubtaskDepth)
|
|
232
|
+
.filter(task => task.archivedAt === undefined && isOutstanding(task))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Whether any descendant of this card still sits outside the `done` column.
|
|
237
|
+
* This is the ONE decision behind both the forced agent preset and the dispatch
|
|
238
|
+
* section of the execution prompt: a card whose tree still holds work runs as
|
|
239
|
+
* the autonomous dispatcher.
|
|
240
|
+
*/
|
|
241
|
+
export function hasOutstandingDescendants(
|
|
242
|
+
tasks: readonly TaskRecord[],
|
|
243
|
+
rootId: string,
|
|
244
|
+
maxSubtaskDepth: number,
|
|
245
|
+
): boolean {
|
|
246
|
+
return outstandingDescendants(tasks, rootId, maxSubtaskDepth).length > 0
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Agent preset a run with unfinished subtasks is forced under. The id comes
|
|
251
|
+
* from packages/dsh-liangshen (its own `LIANGSHEN_PRESET_ID`); the force is
|
|
252
|
+
* applied at launch and never written into a card's `mode` field.
|
|
253
|
+
*/
|
|
254
|
+
export const LIANGSHEN_PRESET_ID = 'liangshen'
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The tool a legacy Agent Teams runtime registers, and the one fingerprint
|
|
258
|
+
* this board reads off a deployment: the pre-#7519 generation registers
|
|
259
|
+
* `spawn_teammate` and replaces `send_message` / `list_agents` /
|
|
260
|
+
* `interrupt_agent` with team-scoped variants, so children exist but are
|
|
261
|
+
* unreachable. The current runtime adds a shared task board instead and reuses
|
|
262
|
+
* the coordination tools, so those three names prove nothing and are never
|
|
263
|
+
* gated on (the criterion is the same one
|
|
264
|
+
* `packages/dsh-liangshen/presets/liangshen/dispatcher-rules.mjs` states).
|
|
265
|
+
*/
|
|
266
|
+
export const LEGACY_AGENT_TEAMS_TOOL = 'spawn_teammate'
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The failure text the Host records when a run would have been forced under
|
|
270
|
+
* the dispatcher preset on a deployment that cannot orchestrate.
|
|
271
|
+
*
|
|
272
|
+
* A finished sentence rather than a code (the shape `core/workspace-target.ts`
|
|
273
|
+
* gives its missing-workspace refusal): the ledger stores it as the
|
|
274
|
+
* execution's failure text, the agent tools serve it to a model, and any
|
|
275
|
+
* client prints it verbatim. It names the fix, not the mechanism. The launch
|
|
276
|
+
* is refused before any session exists, because the dispatcher preset would
|
|
277
|
+
* otherwise stop and wait for a human reply that an unattended run never
|
|
278
|
+
* brings.
|
|
279
|
+
*/
|
|
280
|
+
export const LEGACY_AGENT_TEAMS_REASON = 'this deployment runs the legacy Agent Teams runtime, which cannot dispatch a card that has unfinished subtasks under the ' + LIANGSHEN_PRESET_ID + ' preset; disable that runtime and restart the Host, or finish the subtasks before running'
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Whether a recorded failure text is the legacy-runtime refusal, which the
|
|
284
|
+
* browser half renders in the reader's own language.
|
|
285
|
+
* @param reason - the execution's recorded failure text.
|
|
286
|
+
* @returns true when that run was refused for a deployment that cannot orchestrate.
|
|
287
|
+
*/
|
|
288
|
+
export function isLegacyAgentTeamsReason(reason: string): boolean {
|
|
289
|
+
return reason === LEGACY_AGENT_TEAMS_REASON
|
|
198
290
|
}
|
|
199
291
|
|
|
200
|
-
/**
|
|
292
|
+
/**
|
|
293
|
+
* Whether a card belongs to a run's dispatch set: the card the request named,
|
|
294
|
+
* or a card whose work is still outstanding. Kept for the browser's subtask
|
|
295
|
+
* preview; the Host run itself opens the clicked card alone
|
|
296
|
+
* ({@link cascadeTargets}).
|
|
297
|
+
* @param task - the candidate card.
|
|
298
|
+
* @param rootId - the task the run request named.
|
|
299
|
+
* @returns false when this card is finished and left alone.
|
|
300
|
+
*/
|
|
301
|
+
export function joinsCascadeRun(task: TaskRecord, rootId: string): boolean {
|
|
302
|
+
return task.id === rootId || isOutstanding(task)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** One still-open execution belonging to a stored run group. */
|
|
201
306
|
export interface OpenCascadeChild {
|
|
202
307
|
taskId: string
|
|
203
308
|
execution: ExecutionRecord
|
|
@@ -210,8 +315,9 @@ export function openGroupExecution(task: TaskRecord, runGroupId: string): Execut
|
|
|
210
315
|
|
|
211
316
|
/**
|
|
212
317
|
* The direct subtasks of parentTaskId whose execution in this run group is
|
|
213
|
-
* still open: the parent remaining waiters.
|
|
214
|
-
*
|
|
318
|
+
* still open: the parent's remaining waiters. A stored multi-member group (a
|
|
319
|
+
* run the Host opened before it stopped spreading one run across a subtree)
|
|
320
|
+
* folds once this list is empty and the parent's own outcome is known.
|
|
215
321
|
*/
|
|
216
322
|
export function pendingCascadeChildren(
|
|
217
323
|
tasks: readonly TaskRecord[],
|
|
@@ -228,9 +334,9 @@ export function pendingCascadeChildren(
|
|
|
228
334
|
}
|
|
229
335
|
|
|
230
336
|
/**
|
|
231
|
-
* Fold a
|
|
232
|
-
* verdict: failure dominates, then cancellation, then success. The error
|
|
233
|
-
* is the first failure, falling back to the first cancellation.
|
|
337
|
+
* Fold a stored run-group parent's own outcome and its children's outcomes into
|
|
338
|
+
* one verdict: failure dominates, then cancellation, then success. The error
|
|
339
|
+
* text is the first failure, falling back to the first cancellation.
|
|
234
340
|
*/
|
|
235
341
|
export function combineCascadeOutcome(
|
|
236
342
|
entries: readonly { result: ExecutionOutcome; error?: string }[],
|
|
@@ -263,53 +369,13 @@ export function effectiveTaskPermission(task: TaskRecord): TaskRecord['permissio
|
|
|
263
369
|
/**
|
|
264
370
|
* Resolve the execution targets a (sub)task actually runs with: its own value
|
|
265
371
|
* wins, and an unset target inherits the nearest ancestor up to the root.
|
|
266
|
-
* Workspace, agent preset and
|
|
267
|
-
* handover bundle is a per-card continuation artefact and is never
|
|
268
|
-
* The permission inherits the ancestor's EFFECTIVE binding, and its
|
|
269
|
-
* confirmation travels with it, so a subtask of an already-confirmed
|
|
270
|
-
* card is runnable while a subtask's own unconfirmed binding stays
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* The immutable teammate name for one team-mode member. Teammate names are
|
|
274
|
-
* lower-kebab-case and must stay unique for the lifetime of the Team: the
|
|
275
|
-
* run-group token separates two runs of the same tree, and the member
|
|
276
|
-
* discriminator separates two members of one run that reduce to the same slug.
|
|
277
|
-
*
|
|
278
|
-
* The discriminator is not cosmetic. A title with no ASCII word characters (a
|
|
279
|
-
* CJK title, for example) carries no slug at all, so every such title of one
|
|
280
|
-
* run group collides on the generic prefix; Agent Teams answers every member
|
|
281
|
-
* after the first with `teammate name "..." was already used in this Team`,
|
|
282
|
-
* and those subtasks never start. Two ASCII titles that share a slug
|
|
283
|
-
* (`AI 强度预测` next to `AI 配比优化`) collide the same way.
|
|
284
|
-
* @param title - the member task's title.
|
|
285
|
-
* @param token - the run group id (the task id when no group is recorded).
|
|
286
|
-
* @param memberId - the member task's id, which makes the name unique in the run.
|
|
287
|
-
* @returns the teammate name handed to the Agent Teams service.
|
|
288
|
-
*/
|
|
289
|
-
export function teammateName(title: string, token: string, memberId?: string): string {
|
|
290
|
-
const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 32).replace(/-+$/g, '')
|
|
291
|
-
const suffix = token.replace(/[^a-z0-9]/gi, '').slice(0, 8).toLowerCase()
|
|
292
|
-
const member = memberId === undefined || memberId === '' ? undefined : stableTag(memberId)
|
|
293
|
-
return [slug === '' ? 'subtask' : slug, member, suffix === '' ? 'run' : suffix]
|
|
294
|
-
.filter((part): part is string => part !== undefined)
|
|
295
|
-
.join('-')
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* A stable 4-hex tag for one member id. The name is derived twice for the same
|
|
300
|
-
* member — once for the Lead's prompt and once for the spawn request — so the
|
|
301
|
-
* tag must be a pure function of the id, never of a clock or a counter. FNV-1a
|
|
302
|
-
* keeps it dependency-free in `core/`, which both halves compile.
|
|
372
|
+
* Workspace, agent preset, model and reasoning effort inherit the ancestor's
|
|
373
|
+
* PIN only — a handover bundle is a per-card continuation artefact and is never
|
|
374
|
+
* inherited. The permission inherits the ancestor's EFFECTIVE binding, and its
|
|
375
|
+
* human confirmation travels with it, so a subtask of an already-confirmed
|
|
376
|
+
* elevated card is runnable while a subtask's own unconfirmed binding stays
|
|
377
|
+
* gated.
|
|
303
378
|
*/
|
|
304
|
-
function stableTag(value: string): string {
|
|
305
|
-
let hash = 0x811c9dc5
|
|
306
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
307
|
-
hash ^= value.charCodeAt(index)
|
|
308
|
-
hash = Math.imul(hash, 0x01000193) >>> 0
|
|
309
|
-
}
|
|
310
|
-
return hash.toString(16).padStart(8, '0').slice(0, 4)
|
|
311
|
-
}
|
|
312
|
-
|
|
313
379
|
export function resolveExecutionTargets(
|
|
314
380
|
task: TaskRecord,
|
|
315
381
|
tasks: readonly TaskRecord[],
|
|
@@ -317,13 +383,22 @@ export function resolveExecutionTargets(
|
|
|
317
383
|
): TaskRecord {
|
|
318
384
|
if (task.parentId === undefined) return task
|
|
319
385
|
const chain = [task, ...ancestorChain(tasks, task).slice(0, maxSubtaskDepth)]
|
|
320
|
-
const first = (key: 'workspaceId' | 'mode' | 'model'): string | undefined => {
|
|
321
|
-
for (const candidate of
|
|
386
|
+
const first = (key: 'workspaceId' | 'mode' | 'model' | 'reasoningEffort', candidates: readonly TaskRecord[]): string | undefined => {
|
|
387
|
+
for (const candidate of candidates) {
|
|
322
388
|
const value = candidate[key]
|
|
323
389
|
if (value !== undefined) return value
|
|
324
390
|
}
|
|
325
391
|
return undefined
|
|
326
392
|
}
|
|
393
|
+
// The model pin is the boundary of the effort: an effort is only ever taken
|
|
394
|
+
// from the card the model came from, or from the card that pinned it below
|
|
395
|
+
// that one. A card with a model of its own thus sends NO effort when it stores
|
|
396
|
+
// none — the model's own default — instead of quietly running at an ancestor
|
|
397
|
+
// level chosen for a different model, even when both models declare that
|
|
398
|
+
// level. A card with no model of its own still inherits the nearest model
|
|
399
|
+
// together with the nearest level pinned at or below it.
|
|
400
|
+
const boundary = chain.findIndex(candidate => candidate.model !== undefined)
|
|
401
|
+
const effortChain = boundary === -1 ? chain : chain.slice(0, boundary + 1)
|
|
327
402
|
const own = effectiveTaskPermission(task)
|
|
328
403
|
// An own binding (pin or handover) keeps its own confirmation stamp; only an
|
|
329
404
|
// absent one borrows the ancestor's binding AND that ancestor's stamp.
|
|
@@ -332,9 +407,10 @@ export function resolveExecutionTargets(
|
|
|
332
407
|
: undefined
|
|
333
408
|
return {
|
|
334
409
|
...task,
|
|
335
|
-
workspaceId: first('workspaceId'),
|
|
336
|
-
mode: first('mode'),
|
|
337
|
-
model: first('model'),
|
|
410
|
+
workspaceId: first('workspaceId', chain),
|
|
411
|
+
mode: first('mode', chain),
|
|
412
|
+
model: first('model', chain),
|
|
413
|
+
reasoningEffort: first('reasoningEffort', effortChain),
|
|
338
414
|
permission: own ?? (owner === undefined ? undefined : effectiveTaskPermission(owner)),
|
|
339
415
|
permissionConfirmedAt: own === undefined ? owner?.permissionConfirmedAt : task.permissionConfirmedAt,
|
|
340
416
|
}
|