@fish-under-sea/dsh-client-ui-task-board-fish 0.0.0-stage → 0.5.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/LICENSE +202 -0
- package/README.i18n.yaml +6 -0
- package/README.md +202 -2
- package/README.zh.md +203 -0
- package/cordis.patch.yml +12 -0
- package/icon.svg +3 -0
- package/lib/client.js +12941 -0
- package/lib/client.js.map +1 -0
- package/lib/index.js +10471 -0
- package/lib/types/client/PluginSettingsCard.d.ts +144 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +92 -0
- package/lib/types/client/apply-guard.d.ts +25 -0
- package/lib/types/client/board/ClampedMarkdown.d.ts +3 -0
- package/lib/types/client/board/ConfirmDialog.d.ts +15 -0
- package/lib/types/client/board/EditTaskModal.d.ts +17 -0
- package/lib/types/client/board/LinkSubtaskModal.d.ts +14 -0
- package/lib/types/client/board/NewTaskModal.d.ts +26 -0
- package/lib/types/client/board/TagManagerModal.d.ts +26 -0
- package/lib/types/client/board/TaskBoard.d.ts +26 -0
- package/lib/types/client/board/TaskCard.d.ts +36 -0
- package/lib/types/client/board/TaskDetail.d.ts +9 -0
- package/lib/types/client/board/TaskForm.d.ts +72 -0
- package/lib/types/client/board/VerificationReport.d.ts +23 -0
- package/lib/types/client/board/card-view.d.ts +113 -0
- package/lib/types/client/board/icons.d.ts +32 -0
- package/lib/types/client/board/overlay.d.ts +69 -0
- package/lib/types/client/board/parse-model-pref.d.ts +4 -0
- package/lib/types/client/board/preset-label.d.ts +22 -0
- package/lib/types/client/board/status-key.d.ts +19 -0
- package/lib/types/client/board/task-markdown.d.ts +19 -0
- package/lib/types/client/host-api.d.ts +63 -0
- package/lib/types/client/index.d.ts +128 -0
- package/lib/types/client/locales.d.ts +443 -0
- package/lib/types/client/main-session.d.ts +32 -0
- package/lib/types/client/native-panel.d.ts +48 -0
- package/lib/types/client/plugin-card-seat.d.ts +108 -0
- package/lib/types/client/schedule-presets.d.ts +10 -0
- package/lib/types/client/schedule-zone.d.ts +97 -0
- package/lib/types/client/seats.d.ts +18 -0
- package/lib/types/client/service.d.ts +32 -0
- package/lib/types/client/settings-entry-form.d.ts +49 -0
- package/lib/types/client/settings-form.d.ts +213 -0
- package/lib/types/core/controller.d.ts +373 -0
- package/lib/types/core/degraded-reason.d.ts +46 -0
- package/lib/types/core/extension.d.ts +283 -0
- package/lib/types/core/freeze-snapshot.d.ts +71 -0
- package/lib/types/core/handover.d.ts +70 -0
- package/lib/types/core/issue-form.d.ts +16 -0
- package/lib/types/core/package-name.d.ts +9 -0
- package/lib/types/core/poll-cadence.d.ts +31 -0
- package/lib/types/core/schedule.d.ts +124 -0
- package/lib/types/core/session-reuse.d.ts +24 -0
- package/lib/types/core/store.d.ts +64 -0
- package/lib/types/core/subtask.d.ts +141 -0
- package/lib/types/core/tasks.d.ts +601 -0
- package/lib/types/core/use-cases/task-archive.d.ts +20 -0
- package/lib/types/core/use-cases/task-create.d.ts +27 -0
- package/lib/types/core/use-cases/task-delete.d.ts +27 -0
- package/lib/types/core/use-cases/task-parent.d.ts +21 -0
- package/lib/types/core/use-cases/task-schedule.d.ts +96 -0
- package/lib/types/core/use-cases/task-tag.d.ts +48 -0
- package/lib/types/core/use-cases/task-update.d.ts +56 -0
- package/lib/types/core/verification-budget.d.ts +52 -0
- package/lib/types/core/verification.d.ts +753 -0
- package/lib/types/core/workspace-target.d.ts +41 -0
- package/lib/types/dsh-home.d.ts +16 -0
- package/lib/types/host/agent-tools.d.ts +27 -0
- package/lib/types/host/extension-registry.d.ts +111 -0
- package/lib/types/host/llm-dispatch.d.ts +63 -0
- package/lib/types/host/verification-gate.d.ts +95 -0
- package/lib/types/host/verification-runner.d.ts +139 -0
- package/lib/types/host/workspace-evidence.d.ts +53 -0
- package/lib/types/host-ai.d.ts +51 -0
- package/lib/types/host-ledger.d.ts +385 -0
- package/lib/types/host-routes.d.ts +36 -0
- package/lib/types/host-runner.d.ts +252 -0
- package/lib/types/host-service.d.ts +379 -0
- package/lib/types/http.d.ts +59 -0
- package/lib/types/index.d.ts +322 -0
- package/lib/types/loopback.d.ts +24 -0
- package/lib/types/mount-once.d.ts +55 -0
- package/lib/types/power-inhibitor.d.ts +73 -0
- package/lib/types/protocol.d.ts +212 -0
- package/lib/types/tool-surface.d.ts +71 -0
- package/package.json +107 -4
- package/src/client/PluginSettingsCard.tsx +564 -0
- package/src/client/TaskBoardSettingsCard.tsx +539 -0
- package/src/client/apply-guard.ts +35 -0
- package/src/client/board/ClampedMarkdown.tsx +69 -0
- package/src/client/board/ConfirmDialog.tsx +44 -0
- package/src/client/board/EditTaskModal.tsx +110 -0
- package/src/client/board/LinkSubtaskModal.tsx +97 -0
- package/src/client/board/NewTaskModal.tsx +718 -0
- package/src/client/board/TagManagerModal.tsx +235 -0
- package/src/client/board/TaskBoard.tsx +558 -0
- package/src/client/board/TaskCard.tsx +315 -0
- package/src/client/board/TaskDetail.tsx +985 -0
- package/src/client/board/TaskForm.tsx +264 -0
- package/src/client/board/VerificationReport.tsx +322 -0
- package/src/client/board/card-view.ts +220 -0
- package/src/client/board/icons.tsx +89 -0
- package/src/client/board/overlay.tsx +189 -0
- package/src/client/board/parse-model-pref.ts +35 -0
- package/src/client/board/preset-label.ts +44 -0
- package/src/client/board/status-key.ts +41 -0
- package/src/client/board/task-markdown.module.css +137 -0
- package/src/client/board/task-markdown.tsx +106 -0
- package/src/client/board-settings.module.css +66 -0
- package/src/client/board.module.css +1837 -0
- package/src/client/css-modules.d.ts +5 -0
- package/src/client/host-api.ts +336 -0
- package/src/client/index.ts +501 -0
- package/src/client/locales.ts +905 -0
- package/src/client/main-session.ts +43 -0
- package/src/client/native-panel.tsx +140 -0
- package/src/client/plugin-card-seat.ts +199 -0
- package/src/client/schedule-presets.ts +13 -0
- package/src/client/schedule-zone.ts +233 -0
- package/src/client/seats.tsx +58 -0
- package/src/client/service.ts +94 -0
- package/src/client/settings-card.module.css +444 -0
- package/src/client/settings-entry-form.ts +142 -0
- package/src/client/settings-form.ts +468 -0
- package/src/core/controller.ts +871 -0
- package/src/core/degraded-reason.ts +81 -0
- package/src/core/extension.ts +376 -0
- package/src/core/freeze-snapshot.ts +213 -0
- package/src/core/handover.ts +132 -0
- package/src/core/issue-form.ts +19 -0
- package/src/core/package-name.ts +9 -0
- package/src/core/poll-cadence.ts +41 -0
- package/src/core/schedule.ts +363 -0
- package/src/core/session-reuse.ts +40 -0
- package/src/core/store.ts +371 -0
- package/src/core/subtask.ts +341 -0
- package/src/core/tasks.ts +843 -0
- package/src/core/use-cases/task-archive.ts +91 -0
- package/src/core/use-cases/task-create.ts +110 -0
- package/src/core/use-cases/task-delete.ts +43 -0
- package/src/core/use-cases/task-parent.ts +65 -0
- package/src/core/use-cases/task-schedule.ts +251 -0
- package/src/core/use-cases/task-tag.ts +110 -0
- package/src/core/use-cases/task-update.ts +126 -0
- package/src/core/verification-budget.ts +115 -0
- package/src/core/verification.ts +1594 -0
- package/src/core/workspace-target.ts +59 -0
- package/src/dsh-home.ts +42 -0
- package/src/host/agent-tools.ts +762 -0
- package/src/host/extension-registry.ts +509 -0
- package/src/host/llm-dispatch.ts +87 -0
- package/src/host/verification-gate.ts +487 -0
- package/src/host/verification-runner.ts +702 -0
- package/src/host/workspace-evidence.ts +176 -0
- package/src/host-ai.ts +158 -0
- package/src/host-ledger.ts +1826 -0
- package/src/host-routes.ts +306 -0
- package/src/host-runner.ts +755 -0
- package/src/host-service.ts +1112 -0
- package/src/http.ts +127 -0
- package/src/index.ts +722 -0
- package/src/loopback.ts +63 -0
- package/src/mount-once.ts +142 -0
- package/src/power-inhibitor.ts +321 -0
- package/src/protocol.ts +591 -0
- package/src/tool-surface.ts +95 -0
|
@@ -0,0 +1,871 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Board controller: the single owner of task-ledger state and view state.
|
|
3
|
+
*
|
|
4
|
+
* In production it projects the Host ledger and submits confirmed actions;
|
|
5
|
+
* the legacy store seam remains for v1 migration tests. The board closes
|
|
6
|
+
* only on explicit user navigation, never implicitly on session-list churn.
|
|
7
|
+
* Framework-free (structural runtime faces) so the whole orchestration is
|
|
8
|
+
* unit-testable with fakes.
|
|
9
|
+
*
|
|
10
|
+
* The per use-case domain transitions (create/update/delete/schedule) live in
|
|
11
|
+
* dedicated modules under core/use-cases and are applied here; the controller
|
|
12
|
+
* owns only the orchestration seam (state, persistence, notify, navigation).
|
|
13
|
+
*/
|
|
14
|
+
import type { TaskStore } from './store.ts'
|
|
15
|
+
import { hasOpenExecution, withStatus, type NewTaskInput, type TaskRecord, type TaskStatus } from './tasks.ts'
|
|
16
|
+
import { applyArchiveTask, applyRestoreTask } from './use-cases/task-archive.ts'
|
|
17
|
+
import { applyCreateTask } from './use-cases/task-create.ts'
|
|
18
|
+
import { applyDeleteTask } from './use-cases/task-delete.ts'
|
|
19
|
+
import { applyScheduleNextRun as applyScheduleRollForward, applySetSchedule, type SetSchedulePatch } from './use-cases/task-schedule.ts'
|
|
20
|
+
import { resolveHostTimeZone } from './schedule.ts'
|
|
21
|
+
import { applySetParent } from './use-cases/task-parent.ts'
|
|
22
|
+
import { applyDeleteTag, applyRenameTag } from './use-cases/task-tag.ts'
|
|
23
|
+
import { applyUpdateTask, type TaskUpdatePatch } from './use-cases/task-update.ts'
|
|
24
|
+
import { DEFAULT_SUBTASK_DEPTH } from './subtask.ts'
|
|
25
|
+
import type {
|
|
26
|
+
TaskBoardAction,
|
|
27
|
+
TaskBoardEventPayload,
|
|
28
|
+
TaskBoardParseDraft,
|
|
29
|
+
TaskBoardParseRequest,
|
|
30
|
+
TaskBoardSnapshot,
|
|
31
|
+
} from '../protocol.ts'
|
|
32
|
+
import type {
|
|
33
|
+
TaskBoardExtensionActionRequest,
|
|
34
|
+
TaskBoardVisibilityPredicate,
|
|
35
|
+
} from './extension.ts'
|
|
36
|
+
|
|
37
|
+
export interface TaskBoardTransport {
|
|
38
|
+
bootstrap(legacy: readonly TaskRecord[]): Promise<TaskBoardSnapshot>
|
|
39
|
+
state(): Promise<TaskBoardSnapshot>
|
|
40
|
+
/**
|
|
41
|
+
* Submit one action; the optional initiator is the current DSH session id
|
|
42
|
+
* (issue #6 audit origin), asserted by the client and recorded by the Host.
|
|
43
|
+
*/
|
|
44
|
+
action(action: TaskBoardAction, initiator?: string): Promise<TaskBoardSnapshot>
|
|
45
|
+
subscribe(listener: (event?: TaskBoardEventPayload) => void): () => void
|
|
46
|
+
/**
|
|
47
|
+
* One-shot model parse of pasted text (issue #1540). Optional: a deployment
|
|
48
|
+
* that cannot parse simply omits it, and the form hides the section.
|
|
49
|
+
*/
|
|
50
|
+
parseDraft?(request: TaskBoardParseRequest, signal?: AbortSignal): Promise<TaskBoardParseDraft>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The sessions face the controller needs for navigation awareness. The Client
|
|
55
|
+
* Session Controller carries no global selection since 0.1.6-alpha.2, so the
|
|
56
|
+
* wiring resolves the main-view Session once and exposes it as current().
|
|
57
|
+
*/
|
|
58
|
+
export interface SessionsControllerFace {
|
|
59
|
+
/** The Session the main view currently shows, when any. */
|
|
60
|
+
current(): string | undefined
|
|
61
|
+
/** Navigate the main view to a Session. */
|
|
62
|
+
open(id: string): void
|
|
63
|
+
/** Subscribe to catalog changes; selection ownership rides the same snapshot. */
|
|
64
|
+
subscribe(fn: () => void): () => void
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function currentOf(sessions: SessionsControllerFace | undefined): string | undefined {
|
|
68
|
+
return sessions?.current()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Stable id shared by the board's sidebar panel row and its main-slot page. */
|
|
72
|
+
export const TASK_BOARD_PANEL_ID = 'task-board'
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The layout's panel-navigation face. The board no longer owns the center
|
|
76
|
+
* column at the DOM level: selecting the panel is the layout's business, and
|
|
77
|
+
* this is the one call that asks for it (null returns to the conversation).
|
|
78
|
+
* Optional, so a composition without the layout service keeps the board's
|
|
79
|
+
* pure state transitions testable.
|
|
80
|
+
*/
|
|
81
|
+
export interface PanelNavigationFace {
|
|
82
|
+
/** Select the board panel, or null to hand the column back to the conversation. */
|
|
83
|
+
select(panelId: string | null): void
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Controller dependencies (all swappable in tests). */
|
|
87
|
+
export interface ControllerDeps {
|
|
88
|
+
store: TaskStore
|
|
89
|
+
sessions: SessionsControllerFace
|
|
90
|
+
/** Clock; defaults to Date.now. */
|
|
91
|
+
now?: () => number
|
|
92
|
+
/** Id minting; defaults to a random-uuid. */
|
|
93
|
+
uuid?: () => string
|
|
94
|
+
/** Host-authoritative transport; absent keeps the legacy in-memory test path. */
|
|
95
|
+
transport?: TaskBoardTransport
|
|
96
|
+
/** Layout panel selection; absent keeps the board state-only (tests, shell-less hosts). */
|
|
97
|
+
panel?: PanelNavigationFace
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Register one host directory as a DSH project (workspace). Wired by the
|
|
102
|
+
* browser apply() to the runtime's workspace controller; without it the board
|
|
103
|
+
* hides its "new project" action instead of offering a dead control (#1536).
|
|
104
|
+
*/
|
|
105
|
+
export type WorkspaceCreator = (path: string) => Promise<{ workspaceId: string }>
|
|
106
|
+
|
|
107
|
+
/** One workspace option the execution-target pickers offer. */
|
|
108
|
+
export interface ExecutionWorkspaceOption {
|
|
109
|
+
workspaceId: string
|
|
110
|
+
/** Display label (workspace title; the wiring falls back to the path). */
|
|
111
|
+
title: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** One agent-preset option the execution-target pickers offer. */
|
|
115
|
+
export interface ExecutionPresetOption {
|
|
116
|
+
id: string
|
|
117
|
+
name?: string
|
|
118
|
+
description?: string
|
|
119
|
+
/** Why this preset cannot compose a session; the pickers disable it. */
|
|
120
|
+
broken?: string
|
|
121
|
+
isDefault: boolean
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** One model option the execution-target pickers offer. */
|
|
125
|
+
export interface ExecutionModelOption {
|
|
126
|
+
id: string
|
|
127
|
+
name?: string
|
|
128
|
+
label?: string
|
|
129
|
+
provider?: string
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The execution-target option sets the UI feeds into the controller. */
|
|
133
|
+
export interface ExecutionOptionsSnapshot {
|
|
134
|
+
workspaces: readonly ExecutionWorkspaceOption[]
|
|
135
|
+
presets: readonly ExecutionPresetOption[]
|
|
136
|
+
models?: readonly ExecutionModelOption[]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Host-owned state the browser mirrors. SSE frames carry the volatile subset
|
|
141
|
+
* (revision/scheduler/power); a full snapshot also carries the deployment
|
|
142
|
+
* constants the UI reads (session default permission, subtask depth).
|
|
143
|
+
*/
|
|
144
|
+
export type HostMirror = Pick<TaskBoardSnapshot, 'revision' | 'scheduler' | 'power' | 'sessionDefaultPermission' | 'maxSubtaskDepth' | 'teamRunAvailable' | 'goalRunEnabled' | 'extensions'>
|
|
145
|
+
|
|
146
|
+
/** Immutable controller snapshot for UI subscriptions. */
|
|
147
|
+
export interface ControllerSnapshot {
|
|
148
|
+
tasks: readonly TaskRecord[]
|
|
149
|
+
boardOpen: boolean
|
|
150
|
+
/** True when the board shows the archive view instead of the columns. */
|
|
151
|
+
archiveView: boolean
|
|
152
|
+
selectedTaskId: string | undefined
|
|
153
|
+
/** Picker option sets (workspace list + agent-preset roster). */
|
|
154
|
+
executionOptions: ExecutionOptionsSnapshot
|
|
155
|
+
pendingTaskIds: readonly string[]
|
|
156
|
+
/** Whether the board may offer "register a new project" (issue #1536). */
|
|
157
|
+
canCreateWorkspace?: boolean
|
|
158
|
+
/** Whether this deployment can parse pasted text into task fields (issue #1540). */
|
|
159
|
+
canParseTask?: boolean
|
|
160
|
+
transportError?: string
|
|
161
|
+
host?: HostMirror
|
|
162
|
+
/**
|
|
163
|
+
* Provider card-visibility predicates, in registration order. A task shows
|
|
164
|
+
* only while every predicate accepts it; providers hide their own off-board
|
|
165
|
+
* cards here instead of the board hard-coding a provider rule. Optional so a
|
|
166
|
+
* hand-built snapshot (tests, a shell-less composition) defaults to visible.
|
|
167
|
+
*/
|
|
168
|
+
visibility?: readonly TaskBoardVisibilityPredicate[]
|
|
169
|
+
/** Read-only summaries published by running extensions, keyed by extension id. */
|
|
170
|
+
extensions?: Readonly<Record<string, unknown>>
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The selected task (resolved from the ledger), or undefined. */
|
|
174
|
+
export function selectedTaskOf(snapshot: ControllerSnapshot): TaskRecord | undefined {
|
|
175
|
+
if (snapshot.selectedTaskId === undefined) return undefined
|
|
176
|
+
return snapshot.tasks.find(task => task.id === snapshot.selectedTaskId)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function randomUuid(): string {
|
|
180
|
+
const randomUUID = globalThis.crypto?.randomUUID
|
|
181
|
+
if (randomUUID !== undefined) {
|
|
182
|
+
return randomUUID.call(globalThis.crypto!)
|
|
183
|
+
}
|
|
184
|
+
const bytes = globalThis.crypto?.getRandomValues(new Uint8Array(16))
|
|
185
|
+
if (bytes === undefined) {
|
|
186
|
+
// Non-secure fallback (tests, odd environments).
|
|
187
|
+
return `t-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`
|
|
188
|
+
}
|
|
189
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40
|
|
190
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
|
191
|
+
const hex = Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('')
|
|
192
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function messageOf(error: unknown): string {
|
|
196
|
+
return error instanceof Error ? error.message : String(error)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Board controller (see module doc). All mutations bump the snapshot and
|
|
201
|
+
* persist through the store; UI and DOM mounts subscribe and re-render.
|
|
202
|
+
*/
|
|
203
|
+
export class BoardController {
|
|
204
|
+
private tasks: TaskRecord[] = []
|
|
205
|
+
private boardOpen = false
|
|
206
|
+
private archiveView = false
|
|
207
|
+
private selectedTaskId: string | undefined
|
|
208
|
+
private executionOptions: ExecutionOptionsSnapshot = { workspaces: [], presets: [], models: [] }
|
|
209
|
+
private workspaceCreator: WorkspaceCreator | undefined
|
|
210
|
+
private listeners = new Set<() => void>()
|
|
211
|
+
private disposers: Array<() => void> = []
|
|
212
|
+
private readonly now: () => number
|
|
213
|
+
private readonly uuid: () => string
|
|
214
|
+
private readonly pendingTaskIds = new Set<string>()
|
|
215
|
+
private readonly taskQueues = new Map<string, Promise<void>>()
|
|
216
|
+
private transportError: string | undefined
|
|
217
|
+
private hostState: HostMirror | undefined
|
|
218
|
+
/** Provider visibility predicates (immutable array; replaced on change). */
|
|
219
|
+
private visibility: readonly TaskBoardVisibilityPredicate[] = []
|
|
220
|
+
private remoteSubscribed = false
|
|
221
|
+
private remoteInitialization: Promise<boolean> | undefined
|
|
222
|
+
|
|
223
|
+
/** @param deps - store and the sessions navigation face. */
|
|
224
|
+
constructor(private readonly deps: ControllerDeps) {
|
|
225
|
+
this.now = deps.now ?? (() => Date.now())
|
|
226
|
+
this.uuid = deps.uuid ?? randomUuid
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// --- lifecycle -------------------------------------------------------------
|
|
230
|
+
|
|
231
|
+
/** Load the persisted ledger and start the navigation/status subscriptions. */
|
|
232
|
+
start(): void {
|
|
233
|
+
this.tasks = this.deps.store.load()
|
|
234
|
+
if (this.deps.transport !== undefined) void this.initializeRemote()
|
|
235
|
+
// A sibling tab may have edited or deleted the ledger (same origin,
|
|
236
|
+
// storage events). Reload on external change so a task deleted in
|
|
237
|
+
// another tab stops firing here — and is never written back by this
|
|
238
|
+
// tab's stale copy (scheduler roll-forward, execution settlement).
|
|
239
|
+
const unsubscribeExternal = this.deps.transport === undefined ? this.deps.store.subscribeExternal?.(() => {
|
|
240
|
+
this.tasks = this.deps.store.load()
|
|
241
|
+
this.notify()
|
|
242
|
+
}) : undefined
|
|
243
|
+
if (unsubscribeExternal !== undefined) this.disposers.push(unsubscribeExternal)
|
|
244
|
+
this.disposers.push(this.deps.sessions.subscribe(() => {
|
|
245
|
+
this.onSessionsChanged()
|
|
246
|
+
}))
|
|
247
|
+
this.notify()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Stop all subscriptions and drop retained state (idempotent). */
|
|
251
|
+
dispose(): void {
|
|
252
|
+
for (const dispose of this.disposers.splice(0)) dispose()
|
|
253
|
+
this.listeners.clear()
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// --- snapshot / subscription ------------------------------------------------
|
|
257
|
+
|
|
258
|
+
getSnapshot(): ControllerSnapshot {
|
|
259
|
+
return {
|
|
260
|
+
tasks: this.tasks,
|
|
261
|
+
boardOpen: this.boardOpen,
|
|
262
|
+
archiveView: this.archiveView,
|
|
263
|
+
selectedTaskId: this.selectedTaskId,
|
|
264
|
+
executionOptions: this.executionOptions,
|
|
265
|
+
pendingTaskIds: [...this.pendingTaskIds],
|
|
266
|
+
...(this.workspaceCreator === undefined ? {} : { canCreateWorkspace: true }),
|
|
267
|
+
...(typeof this.deps.transport?.parseDraft === 'function' ? { canParseTask: true } : {}),
|
|
268
|
+
...(this.transportError === undefined ? {} : { transportError: this.transportError }),
|
|
269
|
+
...(this.hostState === undefined ? {} : { host: this.hostState }),
|
|
270
|
+
visibility: this.visibility,
|
|
271
|
+
...(this.hostState?.extensions === undefined ? {} : { extensions: this.hostState.extensions }),
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Register one card-visibility predicate. The returned disposer removes it;
|
|
277
|
+
* both changes notify subscribers so the board re-renders.
|
|
278
|
+
*/
|
|
279
|
+
registerVisibility(predicate: TaskBoardVisibilityPredicate): () => void {
|
|
280
|
+
this.visibility = [...this.visibility, predicate]
|
|
281
|
+
this.notify()
|
|
282
|
+
return () => {
|
|
283
|
+
const next = this.visibility.filter(candidate => candidate !== predicate)
|
|
284
|
+
if (next.length === this.visibility.length) return
|
|
285
|
+
this.visibility = next
|
|
286
|
+
this.notify()
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Deliver one provider action through the board's same-origin channel. A
|
|
292
|
+
* board without a Host transport (the legacy in-memory path) refuses it.
|
|
293
|
+
*/
|
|
294
|
+
async dispatchExtension(request: TaskBoardExtensionActionRequest): Promise<boolean> {
|
|
295
|
+
if (this.deps.transport === undefined) return false
|
|
296
|
+
const action: TaskBoardAction = {
|
|
297
|
+
kind: 'extension-action',
|
|
298
|
+
extensionId: request.extensionId,
|
|
299
|
+
action: request.action,
|
|
300
|
+
...(request.taskId === undefined ? {} : { taskId: request.taskId }),
|
|
301
|
+
...(request.payload === undefined ? {} : { payload: request.payload }),
|
|
302
|
+
}
|
|
303
|
+
return await this.commitRemote(action, request.taskId)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
subscribe(fn: () => void): () => void {
|
|
307
|
+
this.listeners.add(fn)
|
|
308
|
+
return () => { this.listeners.delete(fn) }
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Whether production mutations are confirmed by the Host transport. */
|
|
312
|
+
isHostBacked(): boolean {
|
|
313
|
+
return this.deps.transport !== undefined
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Retry initial migration/state synchronization after an explicit Host error. */
|
|
317
|
+
async retryHostSync(): Promise<boolean> {
|
|
318
|
+
return await this.initializeRemote()
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// --- view state -------------------------------------------------------------
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Show the board. The layout owns which panel the center column renders, so
|
|
325
|
+
* the state flip and the panel selection travel together here; a composition
|
|
326
|
+
* with no layout face (tests, a shell-less host) still flips the state.
|
|
327
|
+
*
|
|
328
|
+
* The selection is requested AFTER the snapshot flips so a subscriber
|
|
329
|
+
* rendering against `boardOpen` never observes "open" while the shell still
|
|
330
|
+
* shows the conversation.
|
|
331
|
+
*/
|
|
332
|
+
openBoard(): void {
|
|
333
|
+
if (this.boardOpen) return
|
|
334
|
+
this.boardOpen = true
|
|
335
|
+
this.notify()
|
|
336
|
+
this.selectPanel(TASK_BOARD_PANEL_ID)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Return the center column to the conversation. The layout's own selection is
|
|
341
|
+
* the source of truth for what the column renders, so this asks for the
|
|
342
|
+
* conversation explicitly rather than only clearing local state.
|
|
343
|
+
*/
|
|
344
|
+
closeBoard(): void {
|
|
345
|
+
this.boardOpen = false
|
|
346
|
+
this.notify()
|
|
347
|
+
this.selectPanel(null)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
toggleBoard(): void {
|
|
351
|
+
if (this.boardOpen) this.closeBoard()
|
|
352
|
+
else this.openBoard()
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Reflect a panel selection that came from OUTSIDE this controller (the user
|
|
357
|
+
* clicked another sidebar row, or the layout dropped the panel id). Keeps
|
|
358
|
+
* `boardOpen` aligned with what the column actually shows without asking the
|
|
359
|
+
* layout to select anything back.
|
|
360
|
+
* @param panelId - the layout's current panel id, or null for the conversation.
|
|
361
|
+
*/
|
|
362
|
+
syncPanelSelection(panelId: string | null): void {
|
|
363
|
+
const open = panelId === TASK_BOARD_PANEL_ID
|
|
364
|
+
if (open === this.boardOpen) return
|
|
365
|
+
this.boardOpen = open
|
|
366
|
+
this.notify()
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Ask the layout to select a panel; a shell that serves no layout face is a no-op. */
|
|
370
|
+
private selectPanel(panelId: string | null): void {
|
|
371
|
+
try {
|
|
372
|
+
this.deps.panel?.select(panelId)
|
|
373
|
+
} catch {
|
|
374
|
+
// The layout service throws by contract before its root entry mounts;
|
|
375
|
+
// the state flip above already stands, and the next selection retries.
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Switch between the kanban columns and the archive view. Leaving the
|
|
381
|
+
* archive view with an archived task still selected closes the selection —
|
|
382
|
+
* the detail overlay must not linger over a task that is off-board.
|
|
383
|
+
*/
|
|
384
|
+
toggleArchiveView(): void {
|
|
385
|
+
this.archiveView = !this.archiveView
|
|
386
|
+
if (!this.archiveView && this.selectedTaskId !== undefined) {
|
|
387
|
+
const selected = this.tasks.find(task => task.id === this.selectedTaskId)
|
|
388
|
+
if (selected?.archivedAt !== undefined) this.selectedTaskId = undefined
|
|
389
|
+
}
|
|
390
|
+
this.notify()
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
openTask(id: string): void {
|
|
394
|
+
if (this.tasks.some(task => task.id === id)) {
|
|
395
|
+
this.selectedTaskId = id
|
|
396
|
+
this.notify()
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
closeTask(): void {
|
|
401
|
+
if (this.selectedTaskId === undefined) return
|
|
402
|
+
this.selectedTaskId = undefined
|
|
403
|
+
this.notify()
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// --- task mutations (use-case transitions in core/use-cases) -----------------
|
|
407
|
+
|
|
408
|
+
createTask(input: NewTaskInput): TaskRecord | undefined {
|
|
409
|
+
const id = this.uuid()
|
|
410
|
+
const { task, tasks } = applyCreateTask(this.tasks, input, this.now(), id, this.mirrorDepth())
|
|
411
|
+
if (task === undefined) return undefined
|
|
412
|
+
this.tasks = [...tasks]
|
|
413
|
+
this.persistAndNotify()
|
|
414
|
+
return task
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** Create through the Host and expose the task only after confirmation. */
|
|
418
|
+
async createTaskConfirmed(input: NewTaskInput): Promise<TaskRecord | undefined> {
|
|
419
|
+
if (this.deps.transport === undefined) return this.createTask(input)
|
|
420
|
+
const id = this.uuid()
|
|
421
|
+
// The preview must obey the SAME lineage gate the Host will: a browser-side
|
|
422
|
+
// default of one level would reject a legal subtask-of-subtask before the
|
|
423
|
+
// request is ever sent.
|
|
424
|
+
const preview = applyCreateTask(this.tasks, input, this.now(), id, this.mirrorDepth()).task
|
|
425
|
+
if (preview === undefined) return undefined
|
|
426
|
+
return await this.commitRemote({ kind: 'create', id, input }, id)
|
|
427
|
+
? this.tasks.find(task => task.id === id)
|
|
428
|
+
: undefined
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Apply an editable-field patch (task content + execution targets).
|
|
433
|
+
* Host-backed: the Host ledger owns the fail-closed checks (the content of
|
|
434
|
+
* an executed task is read-only) and confirms the mutation, so the resolved
|
|
435
|
+
* value reflects whether the Host accepted it; the legacy in-memory path
|
|
436
|
+
* applies and persists synchronously.
|
|
437
|
+
* @returns true when the patch was accepted by the authority.
|
|
438
|
+
*/
|
|
439
|
+
async updateTask(id: string, patch: TaskUpdatePatch): Promise<boolean> {
|
|
440
|
+
if (this.deps.transport !== undefined) {
|
|
441
|
+
return await this.commitRemote({ kind: 'update', taskId: id, patch }, id)
|
|
442
|
+
}
|
|
443
|
+
this.tasks = [...applyUpdateTask(this.tasks, id, patch, this.now())]
|
|
444
|
+
this.persistAndNotify()
|
|
445
|
+
return true
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Replace (a part of) the picker option sets the UI feeds (workspace list
|
|
450
|
+
* and agent-preset roster come from the runtime, not the ledger).
|
|
451
|
+
*/
|
|
452
|
+
setExecutionOptions(patch: Partial<ExecutionOptionsSnapshot>): void {
|
|
453
|
+
this.executionOptions = { ...this.executionOptions, ...patch }
|
|
454
|
+
this.notify()
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** Wire (or clear) the runtime's project registration face (issue #1536). */
|
|
458
|
+
setWorkspaceCreator(creator: WorkspaceCreator | undefined): void {
|
|
459
|
+
this.workspaceCreator = creator
|
|
460
|
+
this.notify()
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Register an existing host directory as a DSH project, exactly as the GUI's
|
|
465
|
+
* own "add project" does; the runtime's failure message surfaces unchanged.
|
|
466
|
+
*/
|
|
467
|
+
async createWorkspace(path: string): Promise<{ workspaceId: string }> {
|
|
468
|
+
if (this.workspaceCreator === undefined) throw new Error('workspace creation is unavailable')
|
|
469
|
+
return await this.workspaceCreator(path)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** Whether this deployment can parse pasted text into task fields (issue #1540). */
|
|
473
|
+
canParseTask(): boolean {
|
|
474
|
+
return typeof this.deps.transport?.parseDraft === 'function'
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Parse pasted text into task fields through the Host. The transport already
|
|
479
|
+
* phrases every failure for the user, so its message surfaces unchanged.
|
|
480
|
+
*/
|
|
481
|
+
async parseTaskDraft(request: TaskBoardParseRequest, signal?: AbortSignal): Promise<TaskBoardParseDraft> {
|
|
482
|
+
const transport = this.deps.transport
|
|
483
|
+
const parse = transport?.parseDraft
|
|
484
|
+
if (transport === undefined || parse === undefined) throw new Error('task parsing is unavailable')
|
|
485
|
+
return await parse.call(transport, request, signal)
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
moveTask(id: string, status: TaskStatus): void {
|
|
489
|
+
if (this.deps.transport !== undefined) {
|
|
490
|
+
void this.commitRemote({ kind: 'move', taskId: id, status }, id)
|
|
491
|
+
return
|
|
492
|
+
}
|
|
493
|
+
this.tasks = this.tasks.map(task => task.id === id ? withStatus(task, status, this.now()) : task)
|
|
494
|
+
this.persistAndNotify()
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
deleteTask(id: string): void {
|
|
498
|
+
if (this.deps.transport !== undefined) {
|
|
499
|
+
void this.commitRemote({ kind: 'delete', taskId: id }, id)
|
|
500
|
+
return
|
|
501
|
+
}
|
|
502
|
+
const { tasks, selectionCleared } = applyDeleteTask(this.tasks, this.selectedTaskId, id)
|
|
503
|
+
this.tasks = [...tasks]
|
|
504
|
+
if (selectionCleared) this.selectedTaskId = undefined
|
|
505
|
+
this.persistAndNotify()
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Archive a task from any status but `running`, whose lifecycle the runner
|
|
510
|
+
* keeps exclusive ownership of until it settles.
|
|
511
|
+
* @returns true when applied.
|
|
512
|
+
*/
|
|
513
|
+
archiveTask(id: string): boolean {
|
|
514
|
+
const { tasks, archived } = applyArchiveTask(this.tasks, id, this.now(), this.mirrorDepth())
|
|
515
|
+
if (!archived) return false
|
|
516
|
+
if (this.deps.transport !== undefined) {
|
|
517
|
+
void this.commitRemote({ kind: 'archive', taskId: id }, id)
|
|
518
|
+
return true
|
|
519
|
+
}
|
|
520
|
+
this.tasks = [...tasks]
|
|
521
|
+
this.persistAndNotify()
|
|
522
|
+
return true
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Attach an existing task under a parent (or detach it with a null parent)
|
|
527
|
+
* through the Host. The lineage gate — parent exists and is on-board, no
|
|
528
|
+
* cycle, depth within the deployment limit — belongs to the Host; a refusal
|
|
529
|
+
* surfaces through the transport error like every other rejected action.
|
|
530
|
+
* @returns true when the link was accepted by the authority.
|
|
531
|
+
*/
|
|
532
|
+
async setParent(id: string, parentId: string | null): Promise<boolean> {
|
|
533
|
+
if (this.deps.transport === undefined) {
|
|
534
|
+
const result = applySetParent(this.tasks, id, parentId, this.now(), this.mirrorDepth())
|
|
535
|
+
if (!result.applied) return false
|
|
536
|
+
this.tasks = [...result.tasks]
|
|
537
|
+
this.persistAndNotify()
|
|
538
|
+
return true
|
|
539
|
+
}
|
|
540
|
+
return await this.commitRemote({ kind: 'set-parent', taskId: id, parentId }, id)
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** Restore an archived task back onto the board (same status column). */
|
|
544
|
+
restoreTask(id: string): boolean {
|
|
545
|
+
const { tasks, archived } = applyRestoreTask(this.tasks, id, this.now(), this.mirrorDepth())
|
|
546
|
+
if (!archived) return false
|
|
547
|
+
if (this.deps.transport !== undefined) {
|
|
548
|
+
void this.commitRemote({ kind: 'restore', taskId: id }, id).then(restored => {
|
|
549
|
+
if (restored && this.selectedTaskId === id) this.closeTask()
|
|
550
|
+
})
|
|
551
|
+
return true
|
|
552
|
+
}
|
|
553
|
+
this.tasks = [...tasks]
|
|
554
|
+
if (this.selectedTaskId === id) this.selectedTaskId = undefined
|
|
555
|
+
this.persistAndNotify()
|
|
556
|
+
return true
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Rename one label across the whole ledger; a name already in use merges the
|
|
561
|
+
* two labels. Host-backed: the ledger owns the transition and confirms it, so
|
|
562
|
+
* the board's label row reflects whether the Host accepted the edit.
|
|
563
|
+
* @returns true when the edit was accepted by the authority.
|
|
564
|
+
*/
|
|
565
|
+
async renameTag(from: string, to: string): Promise<boolean> {
|
|
566
|
+
if (this.deps.transport !== undefined) {
|
|
567
|
+
return await this.commitRemote({ kind: 'rename-tag', from, to })
|
|
568
|
+
}
|
|
569
|
+
const result = applyRenameTag(this.tasks, from, to, this.now())
|
|
570
|
+
if (result.error !== undefined) return false
|
|
571
|
+
if (result.changed) {
|
|
572
|
+
this.tasks = [...result.tasks]
|
|
573
|
+
this.persistAndNotify()
|
|
574
|
+
}
|
|
575
|
+
return true
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Remove one label from every task that carries it, board and archive alike —
|
|
580
|
+
* the board's label row is drawn from the whole ledger, so a label left on an
|
|
581
|
+
* archived card would come straight back.
|
|
582
|
+
* @returns true when the edit was accepted by the authority.
|
|
583
|
+
*/
|
|
584
|
+
async deleteTag(name: string): Promise<boolean> {
|
|
585
|
+
if (this.deps.transport !== undefined) {
|
|
586
|
+
return await this.commitRemote({ kind: 'delete-tag', name })
|
|
587
|
+
}
|
|
588
|
+
const result = applyDeleteTag(this.tasks, name, this.now())
|
|
589
|
+
if (result.error !== undefined) return false
|
|
590
|
+
if (result.changed) {
|
|
591
|
+
this.tasks = [...result.tasks]
|
|
592
|
+
this.persistAndNotify()
|
|
593
|
+
}
|
|
594
|
+
return true
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// --- scheduling ---------------------------------------------------------------
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Update a task's schedule rule. An unusable plan (blank or invalid cron, a
|
|
601
|
+
* one-shot with no future instant, a non-positive run cap) is rejected
|
|
602
|
+
* (returns false, state untouched). When the rule ends up enabled the next
|
|
603
|
+
* run instant is computed immediately — a one-shot's next instant IS its
|
|
604
|
+
* planned instant — and a disabled rule carries none. Delegates the domain
|
|
605
|
+
* transition to the schedule use case.
|
|
606
|
+
* @param id - the task to schedule.
|
|
607
|
+
* @param patch - fields to change (absent fields keep their current value).
|
|
608
|
+
* @returns true when applied, false when rejected (unknown task / unusable plan).
|
|
609
|
+
*/
|
|
610
|
+
setSchedule(id: string, patch: SetSchedulePatch): boolean {
|
|
611
|
+
// The Host zone is the fallback a rule with no stored zone follows: the
|
|
612
|
+
// mirrored snapshot carries it, and a controller without a Host mirror
|
|
613
|
+
// (pure client tests) falls back to the process zone.
|
|
614
|
+
const hostTimeZone = this.hostState?.scheduler.timeZone ?? resolveHostTimeZone()
|
|
615
|
+
const { tasks, applied } = applySetSchedule(this.tasks, id, patch, this.now(), hostTimeZone)
|
|
616
|
+
if (!applied) return false
|
|
617
|
+
if (this.deps.transport !== undefined) {
|
|
618
|
+
void this.commitRemote({ kind: 'set-schedule', taskId: id, patch }, id)
|
|
619
|
+
return true
|
|
620
|
+
}
|
|
621
|
+
this.tasks = [...tasks]
|
|
622
|
+
this.persistAndNotify()
|
|
623
|
+
return true
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* Legacy pure-controller seam retained for migration-focused tests. The
|
|
628
|
+
* production browser never rolls schedules; the Host ledger owns them.
|
|
629
|
+
*/
|
|
630
|
+
applyScheduleNextRun(id: string, nextRunAt: number | undefined, lastTriggeredAt: number | undefined): void {
|
|
631
|
+
const next = applyScheduleRollForward(this.tasks, id, nextRunAt, lastTriggeredAt, this.now())
|
|
632
|
+
this.tasks = [...next]
|
|
633
|
+
this.persistAndNotify()
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Reload the legacy v1 store without notifying subscribers. Production v2
|
|
638
|
+
* reads Host snapshots instead; this remains only for isolated legacy tests.
|
|
639
|
+
*/
|
|
640
|
+
reloadFromStore(): void {
|
|
641
|
+
this.tasks = this.deps.store.load()
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Jump to an execution's session transcript. Selecting the session changes
|
|
646
|
+
* `current`, which closes the board (the conversation view takes over).
|
|
647
|
+
* @param sessionId - the execution session to open.
|
|
648
|
+
*/
|
|
649
|
+
openSession(sessionId: string): void {
|
|
650
|
+
this.closeBoard()
|
|
651
|
+
this.deps.sessions.open(sessionId)
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// --- execution ---------------------------------------------------------------
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Request a Host execution for a task: the Host ledger owns the running
|
|
658
|
+
* transition, the execution record, and the settlement. A second call
|
|
659
|
+
* while the task is already running is ignored; without a Host transport
|
|
660
|
+
* the run is refused (returns false).
|
|
661
|
+
*/
|
|
662
|
+
async runTask(id: string): Promise<boolean> {
|
|
663
|
+
const task = this.tasks.find(candidate => candidate.id === id)
|
|
664
|
+
// Only an open execution blocks a second launch; the 'running' column is a
|
|
665
|
+
// board statement and a card parked there by hand still runs on request.
|
|
666
|
+
if (task === undefined || task.archivedAt !== undefined || hasOpenExecution(task)) return false
|
|
667
|
+
if (this.deps.transport === undefined) return false
|
|
668
|
+
return await this.commitRemote({ kind: 'run', taskId: id }, id, currentOf(this.deps.sessions))
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Confirm a card's above-default permission binding through the Host
|
|
673
|
+
* (resolves the pending-confirmation transaction; no-op otherwise).
|
|
674
|
+
*/
|
|
675
|
+
async confirmPermission(id: string): Promise<boolean> {
|
|
676
|
+
const task = this.tasks.find(candidate => candidate.id === id)
|
|
677
|
+
if (task === undefined) return false
|
|
678
|
+
if (this.deps.transport === undefined) {
|
|
679
|
+
this.tasks = this.tasks.map(candidate => candidate.id === id
|
|
680
|
+
? { ...candidate, permissionConfirmedAt: this.now(), updatedAt: this.now() }
|
|
681
|
+
: candidate)
|
|
682
|
+
this.persistAndNotify()
|
|
683
|
+
return true
|
|
684
|
+
}
|
|
685
|
+
return await this.commitRemote({ kind: 'confirm-permission', taskId: id }, id)
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/** Re-run a settled task through the Host (the Host replans and executes). */
|
|
689
|
+
async rerunTask(id: string): Promise<void> {
|
|
690
|
+
const task = this.tasks.find(candidate => candidate.id === id)
|
|
691
|
+
if (task === undefined || task.archivedAt !== undefined) return
|
|
692
|
+
if (this.deps.transport === undefined) return
|
|
693
|
+
await this.commitRemote({ kind: 'rerun', taskId: id }, id, currentOf(this.deps.sessions))
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// --- internals ---------------------------------------------------------------
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Session-list notifications fire for all kinds of incidental churn
|
|
700
|
+
* (background navigation, the Host runner creating and selecting a fresh
|
|
701
|
+
* execution session, settlement, other plugins), so closing on `current`
|
|
702
|
+
* changes would evict the board without the user asking. The board closes
|
|
703
|
+
* only on explicit user navigation: selecting another panel (the layout owns
|
|
704
|
+
* selection, and `syncPanelSelection` follows it) or the board's own actions
|
|
705
|
+
* (openSession / close). Keeping the hook preserves the subscription
|
|
706
|
+
* contract for future listeners.
|
|
707
|
+
*/
|
|
708
|
+
private onSessionsChanged(): void {
|
|
709
|
+
// Intentionally empty: never close the board implicitly.
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
private persistAndNotify(): void {
|
|
713
|
+
if (this.deps.transport === undefined) this.deps.store.save(this.tasks)
|
|
714
|
+
this.notify()
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
private async commitRemote(action: TaskBoardAction, taskId?: string, initiator?: string): Promise<boolean> {
|
|
718
|
+
const transport = this.deps.transport
|
|
719
|
+
if (transport === undefined) return true
|
|
720
|
+
if (taskId === undefined) return await this.performRemote(action, initiator)
|
|
721
|
+
const previous = this.taskQueues.get(taskId) ?? Promise.resolve()
|
|
722
|
+
const operation = previous.catch(() => {}).then(async () => await this.performRemote(action, initiator))
|
|
723
|
+
const tail = operation.then(() => {}, () => {})
|
|
724
|
+
this.taskQueues.set(taskId, tail)
|
|
725
|
+
this.pendingTaskIds.add(taskId)
|
|
726
|
+
this.notify()
|
|
727
|
+
try {
|
|
728
|
+
return await operation
|
|
729
|
+
} finally {
|
|
730
|
+
if (this.taskQueues.get(taskId) === tail) {
|
|
731
|
+
this.taskQueues.delete(taskId)
|
|
732
|
+
this.pendingTaskIds.delete(taskId)
|
|
733
|
+
this.notify()
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
private async performRemote(action: TaskBoardAction, initiator?: string): Promise<boolean> {
|
|
739
|
+
const transport = this.deps.transport
|
|
740
|
+
if (transport === undefined) return true
|
|
741
|
+
this.transportError = undefined
|
|
742
|
+
this.notify()
|
|
743
|
+
try {
|
|
744
|
+
const accepted = this.acceptRemote(await transport.action(action, initiator))
|
|
745
|
+
return accepted || await this.refreshRemote()
|
|
746
|
+
} catch (error) {
|
|
747
|
+
await this.refreshRemote(messageOf(error))
|
|
748
|
+
return false
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
private async initializeRemote(): Promise<boolean> {
|
|
753
|
+
if (this.remoteInitialization !== undefined) return await this.remoteInitialization
|
|
754
|
+
const initialization = this.doInitializeRemote()
|
|
755
|
+
this.remoteInitialization = initialization
|
|
756
|
+
try {
|
|
757
|
+
return await initialization
|
|
758
|
+
} finally {
|
|
759
|
+
if (this.remoteInitialization === initialization) this.remoteInitialization = undefined
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
private async doInitializeRemote(): Promise<boolean> {
|
|
764
|
+
const transport = this.deps.transport
|
|
765
|
+
if (transport === undefined) return true
|
|
766
|
+
try {
|
|
767
|
+
this.acceptRemote(await transport.bootstrap(this.tasks))
|
|
768
|
+
if (!this.remoteSubscribed) {
|
|
769
|
+
this.remoteSubscribed = true
|
|
770
|
+
this.disposers.push(transport.subscribe((event) => { this.onRemoteEvent(event) }))
|
|
771
|
+
}
|
|
772
|
+
return true
|
|
773
|
+
} catch (error) {
|
|
774
|
+
this.transportError = messageOf(error)
|
|
775
|
+
this.notify()
|
|
776
|
+
return false
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* SSE frames carry revision/scheduler/power. When the revision matches the
|
|
782
|
+
* one already applied, apply the frame's scheduler/power in place and skip
|
|
783
|
+
* the full /state fetch; otherwise the 5 s heartbeat would re-clone and
|
|
784
|
+
* re-serialize the whole ledger per tab even while nothing changes.
|
|
785
|
+
*/
|
|
786
|
+
private onRemoteEvent(event: TaskBoardEventPayload | undefined): void {
|
|
787
|
+
if (event !== undefined && this.hostState !== undefined && event.revision === this.hostState.revision
|
|
788
|
+
&& typeof event.scheduler === 'object' && event.scheduler !== null
|
|
789
|
+
&& typeof event.power === 'object' && event.power !== null) {
|
|
790
|
+
this.hostState = { ...this.hostState, revision: event.revision, scheduler: event.scheduler, power: event.power }
|
|
791
|
+
this.notify()
|
|
792
|
+
return
|
|
793
|
+
}
|
|
794
|
+
void this.refreshRemote()
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Deployment subtask depth limit the browser mirrors from the last Host
|
|
799
|
+
* snapshot; the fallback is the deployment default for the legacy path (no
|
|
800
|
+
* transport) and for the window before the first snapshot arrives.
|
|
801
|
+
*/
|
|
802
|
+
private mirrorDepth(): number {
|
|
803
|
+
return this.hostState?.maxSubtaskDepth ?? DEFAULT_SUBTASK_DEPTH
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Project a Host snapshot onto the browser's mirror. SSE frames and partial
|
|
808
|
+
* snapshots carry only the volatile subset (revision/scheduler/power), so the
|
|
809
|
+
* deployment constants the UI reads — the session-default permission the
|
|
810
|
+
* confirmation banner compares against and the subtask depth limit — are
|
|
811
|
+
* carried over from the last full snapshot instead of being dropped by a
|
|
812
|
+
* heartbeat frame.
|
|
813
|
+
*/
|
|
814
|
+
private mirrorOf(snapshot: TaskBoardSnapshot): HostMirror {
|
|
815
|
+
const sessionDefaultPermission = snapshot.sessionDefaultPermission ?? this.hostState?.sessionDefaultPermission
|
|
816
|
+
const maxSubtaskDepth = snapshot.maxSubtaskDepth ?? this.hostState?.maxSubtaskDepth
|
|
817
|
+
const teamRunAvailable = snapshot.teamRunAvailable ?? this.hostState?.teamRunAvailable
|
|
818
|
+
const goalRunEnabled = snapshot.goalRunEnabled ?? this.hostState?.goalRunEnabled
|
|
819
|
+
const extensions = snapshot.extensions ?? this.hostState?.extensions
|
|
820
|
+
return {
|
|
821
|
+
revision: snapshot.revision,
|
|
822
|
+
scheduler: snapshot.scheduler,
|
|
823
|
+
power: snapshot.power,
|
|
824
|
+
...(sessionDefaultPermission === undefined ? {} : { sessionDefaultPermission }),
|
|
825
|
+
...(maxSubtaskDepth === undefined ? {} : { maxSubtaskDepth }),
|
|
826
|
+
...(teamRunAvailable === undefined ? {} : { teamRunAvailable }),
|
|
827
|
+
...(goalRunEnabled === undefined ? {} : { goalRunEnabled }),
|
|
828
|
+
...(extensions === undefined ? {} : { extensions }),
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
private async refreshRemote(preserveError?: string): Promise<boolean> {
|
|
833
|
+
const transport = this.deps.transport
|
|
834
|
+
if (transport === undefined) return true
|
|
835
|
+
try {
|
|
836
|
+
this.acceptRemote(await transport.state())
|
|
837
|
+
if (preserveError !== undefined) {
|
|
838
|
+
this.transportError = preserveError
|
|
839
|
+
this.notify()
|
|
840
|
+
}
|
|
841
|
+
return true
|
|
842
|
+
} catch (error) {
|
|
843
|
+
this.transportError = preserveError ?? messageOf(error)
|
|
844
|
+
this.notify()
|
|
845
|
+
return false
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
private acceptRemote(snapshot: TaskBoardSnapshot): boolean {
|
|
850
|
+
const currentLedgerId = this.hostState?.scheduler.ledgerId
|
|
851
|
+
const nextLedgerId = snapshot.scheduler.ledgerId
|
|
852
|
+
const sameGeneration = currentLedgerId === nextLedgerId
|
|
853
|
+
if (sameGeneration && this.hostState !== undefined && snapshot.revision < this.hostState.revision) return false
|
|
854
|
+
this.tasks = [...snapshot.tasks]
|
|
855
|
+
this.hostState = this.mirrorOf(snapshot)
|
|
856
|
+
this.transportError = undefined
|
|
857
|
+
if (this.selectedTaskId !== undefined && !this.tasks.some(task => task.id === this.selectedTaskId)) {
|
|
858
|
+
this.selectedTaskId = undefined
|
|
859
|
+
}
|
|
860
|
+
if (!this.archiveView && this.selectedTaskId !== undefined
|
|
861
|
+
&& this.tasks.find(task => task.id === this.selectedTaskId)?.archivedAt !== undefined) {
|
|
862
|
+
this.selectedTaskId = undefined
|
|
863
|
+
}
|
|
864
|
+
this.notify()
|
|
865
|
+
return true
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
private notify(): void {
|
|
869
|
+
for (const fn of [...this.listeners]) fn()
|
|
870
|
+
}
|
|
871
|
+
}
|