@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.
Files changed (165) hide show
  1. package/LICENSE +202 -0
  2. package/README.i18n.yaml +6 -0
  3. package/README.md +202 -2
  4. package/README.zh.md +203 -0
  5. package/cordis.patch.yml +12 -0
  6. package/icon.svg +3 -0
  7. package/lib/client.js +12941 -0
  8. package/lib/client.js.map +1 -0
  9. package/lib/index.js +10471 -0
  10. package/lib/types/client/PluginSettingsCard.d.ts +144 -0
  11. package/lib/types/client/TaskBoardSettingsCard.d.ts +92 -0
  12. package/lib/types/client/apply-guard.d.ts +25 -0
  13. package/lib/types/client/board/ClampedMarkdown.d.ts +3 -0
  14. package/lib/types/client/board/ConfirmDialog.d.ts +15 -0
  15. package/lib/types/client/board/EditTaskModal.d.ts +17 -0
  16. package/lib/types/client/board/LinkSubtaskModal.d.ts +14 -0
  17. package/lib/types/client/board/NewTaskModal.d.ts +26 -0
  18. package/lib/types/client/board/TagManagerModal.d.ts +26 -0
  19. package/lib/types/client/board/TaskBoard.d.ts +26 -0
  20. package/lib/types/client/board/TaskCard.d.ts +36 -0
  21. package/lib/types/client/board/TaskDetail.d.ts +9 -0
  22. package/lib/types/client/board/TaskForm.d.ts +72 -0
  23. package/lib/types/client/board/VerificationReport.d.ts +23 -0
  24. package/lib/types/client/board/card-view.d.ts +113 -0
  25. package/lib/types/client/board/icons.d.ts +32 -0
  26. package/lib/types/client/board/overlay.d.ts +69 -0
  27. package/lib/types/client/board/parse-model-pref.d.ts +4 -0
  28. package/lib/types/client/board/preset-label.d.ts +22 -0
  29. package/lib/types/client/board/status-key.d.ts +19 -0
  30. package/lib/types/client/board/task-markdown.d.ts +19 -0
  31. package/lib/types/client/host-api.d.ts +63 -0
  32. package/lib/types/client/index.d.ts +128 -0
  33. package/lib/types/client/locales.d.ts +443 -0
  34. package/lib/types/client/main-session.d.ts +32 -0
  35. package/lib/types/client/native-panel.d.ts +48 -0
  36. package/lib/types/client/plugin-card-seat.d.ts +108 -0
  37. package/lib/types/client/schedule-presets.d.ts +10 -0
  38. package/lib/types/client/schedule-zone.d.ts +97 -0
  39. package/lib/types/client/seats.d.ts +18 -0
  40. package/lib/types/client/service.d.ts +32 -0
  41. package/lib/types/client/settings-entry-form.d.ts +49 -0
  42. package/lib/types/client/settings-form.d.ts +213 -0
  43. package/lib/types/core/controller.d.ts +373 -0
  44. package/lib/types/core/degraded-reason.d.ts +46 -0
  45. package/lib/types/core/extension.d.ts +283 -0
  46. package/lib/types/core/freeze-snapshot.d.ts +71 -0
  47. package/lib/types/core/handover.d.ts +70 -0
  48. package/lib/types/core/issue-form.d.ts +16 -0
  49. package/lib/types/core/package-name.d.ts +9 -0
  50. package/lib/types/core/poll-cadence.d.ts +31 -0
  51. package/lib/types/core/schedule.d.ts +124 -0
  52. package/lib/types/core/session-reuse.d.ts +24 -0
  53. package/lib/types/core/store.d.ts +64 -0
  54. package/lib/types/core/subtask.d.ts +141 -0
  55. package/lib/types/core/tasks.d.ts +601 -0
  56. package/lib/types/core/use-cases/task-archive.d.ts +20 -0
  57. package/lib/types/core/use-cases/task-create.d.ts +27 -0
  58. package/lib/types/core/use-cases/task-delete.d.ts +27 -0
  59. package/lib/types/core/use-cases/task-parent.d.ts +21 -0
  60. package/lib/types/core/use-cases/task-schedule.d.ts +96 -0
  61. package/lib/types/core/use-cases/task-tag.d.ts +48 -0
  62. package/lib/types/core/use-cases/task-update.d.ts +56 -0
  63. package/lib/types/core/verification-budget.d.ts +52 -0
  64. package/lib/types/core/verification.d.ts +753 -0
  65. package/lib/types/core/workspace-target.d.ts +41 -0
  66. package/lib/types/dsh-home.d.ts +16 -0
  67. package/lib/types/host/agent-tools.d.ts +27 -0
  68. package/lib/types/host/extension-registry.d.ts +111 -0
  69. package/lib/types/host/llm-dispatch.d.ts +63 -0
  70. package/lib/types/host/verification-gate.d.ts +95 -0
  71. package/lib/types/host/verification-runner.d.ts +139 -0
  72. package/lib/types/host/workspace-evidence.d.ts +53 -0
  73. package/lib/types/host-ai.d.ts +51 -0
  74. package/lib/types/host-ledger.d.ts +385 -0
  75. package/lib/types/host-routes.d.ts +36 -0
  76. package/lib/types/host-runner.d.ts +252 -0
  77. package/lib/types/host-service.d.ts +379 -0
  78. package/lib/types/http.d.ts +59 -0
  79. package/lib/types/index.d.ts +322 -0
  80. package/lib/types/loopback.d.ts +24 -0
  81. package/lib/types/mount-once.d.ts +55 -0
  82. package/lib/types/power-inhibitor.d.ts +73 -0
  83. package/lib/types/protocol.d.ts +212 -0
  84. package/lib/types/tool-surface.d.ts +71 -0
  85. package/package.json +107 -4
  86. package/src/client/PluginSettingsCard.tsx +564 -0
  87. package/src/client/TaskBoardSettingsCard.tsx +539 -0
  88. package/src/client/apply-guard.ts +35 -0
  89. package/src/client/board/ClampedMarkdown.tsx +69 -0
  90. package/src/client/board/ConfirmDialog.tsx +44 -0
  91. package/src/client/board/EditTaskModal.tsx +110 -0
  92. package/src/client/board/LinkSubtaskModal.tsx +97 -0
  93. package/src/client/board/NewTaskModal.tsx +718 -0
  94. package/src/client/board/TagManagerModal.tsx +235 -0
  95. package/src/client/board/TaskBoard.tsx +558 -0
  96. package/src/client/board/TaskCard.tsx +315 -0
  97. package/src/client/board/TaskDetail.tsx +985 -0
  98. package/src/client/board/TaskForm.tsx +264 -0
  99. package/src/client/board/VerificationReport.tsx +322 -0
  100. package/src/client/board/card-view.ts +220 -0
  101. package/src/client/board/icons.tsx +89 -0
  102. package/src/client/board/overlay.tsx +189 -0
  103. package/src/client/board/parse-model-pref.ts +35 -0
  104. package/src/client/board/preset-label.ts +44 -0
  105. package/src/client/board/status-key.ts +41 -0
  106. package/src/client/board/task-markdown.module.css +137 -0
  107. package/src/client/board/task-markdown.tsx +106 -0
  108. package/src/client/board-settings.module.css +66 -0
  109. package/src/client/board.module.css +1837 -0
  110. package/src/client/css-modules.d.ts +5 -0
  111. package/src/client/host-api.ts +336 -0
  112. package/src/client/index.ts +501 -0
  113. package/src/client/locales.ts +905 -0
  114. package/src/client/main-session.ts +43 -0
  115. package/src/client/native-panel.tsx +140 -0
  116. package/src/client/plugin-card-seat.ts +199 -0
  117. package/src/client/schedule-presets.ts +13 -0
  118. package/src/client/schedule-zone.ts +233 -0
  119. package/src/client/seats.tsx +58 -0
  120. package/src/client/service.ts +94 -0
  121. package/src/client/settings-card.module.css +444 -0
  122. package/src/client/settings-entry-form.ts +142 -0
  123. package/src/client/settings-form.ts +468 -0
  124. package/src/core/controller.ts +871 -0
  125. package/src/core/degraded-reason.ts +81 -0
  126. package/src/core/extension.ts +376 -0
  127. package/src/core/freeze-snapshot.ts +213 -0
  128. package/src/core/handover.ts +132 -0
  129. package/src/core/issue-form.ts +19 -0
  130. package/src/core/package-name.ts +9 -0
  131. package/src/core/poll-cadence.ts +41 -0
  132. package/src/core/schedule.ts +363 -0
  133. package/src/core/session-reuse.ts +40 -0
  134. package/src/core/store.ts +371 -0
  135. package/src/core/subtask.ts +341 -0
  136. package/src/core/tasks.ts +843 -0
  137. package/src/core/use-cases/task-archive.ts +91 -0
  138. package/src/core/use-cases/task-create.ts +110 -0
  139. package/src/core/use-cases/task-delete.ts +43 -0
  140. package/src/core/use-cases/task-parent.ts +65 -0
  141. package/src/core/use-cases/task-schedule.ts +251 -0
  142. package/src/core/use-cases/task-tag.ts +110 -0
  143. package/src/core/use-cases/task-update.ts +126 -0
  144. package/src/core/verification-budget.ts +115 -0
  145. package/src/core/verification.ts +1594 -0
  146. package/src/core/workspace-target.ts +59 -0
  147. package/src/dsh-home.ts +42 -0
  148. package/src/host/agent-tools.ts +762 -0
  149. package/src/host/extension-registry.ts +509 -0
  150. package/src/host/llm-dispatch.ts +87 -0
  151. package/src/host/verification-gate.ts +487 -0
  152. package/src/host/verification-runner.ts +702 -0
  153. package/src/host/workspace-evidence.ts +176 -0
  154. package/src/host-ai.ts +158 -0
  155. package/src/host-ledger.ts +1826 -0
  156. package/src/host-routes.ts +306 -0
  157. package/src/host-runner.ts +755 -0
  158. package/src/host-service.ts +1112 -0
  159. package/src/http.ts +127 -0
  160. package/src/index.ts +722 -0
  161. package/src/loopback.ts +63 -0
  162. package/src/mount-once.ts +142 -0
  163. package/src/power-inhibitor.ts +321 -0
  164. package/src/protocol.ts +591 -0
  165. package/src/tool-surface.ts +95 -0
@@ -0,0 +1,843 @@
1
+ /**
2
+ * Task board domain model: task lifecycle statuses, the task record shape,
3
+ * and the pure transition functions the controller and tests share.
4
+ * Framework-free (no cordis, no runtime imports) so the state machine is
5
+ * unit-testable in isolation.
6
+ */
7
+ import type { FreezeSnapshot } from './freeze-snapshot.ts'
8
+ import type { ExecutionVerification } from './verification.ts'
9
+ import type { TaskHandover, TaskHandoverInput } from './handover.ts'
10
+ import { normalizeTaskIntegrations, type TaskBoardExtensionPayload } from './extension.ts'
11
+
12
+ /** Task lifecycle status, one per kanban column. */
13
+ export type TaskStatus = 'backlog' | 'todo' | 'running' | 'done' | 'failed'
14
+
15
+ /** Settled outcome of one execution attempt. */
16
+ export type ExecutionOutcome = 'succeeded' | 'failed' | 'cancelled'
17
+
18
+ /**
19
+ * One real execution attempt: the run's own id, the dsh session that ran it
20
+ * (filled once the session is created), and the settled outcome once the
21
+ * session's turn ended.
22
+ */
23
+ export interface ExecutionRecord {
24
+ /** Execution attempt id (uuid). */
25
+ id: string
26
+ /** The dsh session that ran this attempt; absent until creation resolves. */
27
+ sessionId: string | undefined
28
+ /** When the run started (ms epoch). */
29
+ startedAt: number
30
+ /** When the run settled; absent while still running. */
31
+ endedAt: number | undefined
32
+ /** Outcome once settled. */
33
+ result: ExecutionOutcome | undefined
34
+ /** Human failure text when the run failed (prompt rejection or agent error). */
35
+ error: string | undefined
36
+ /**
37
+ * Session id of the DSH session that issued the run/rerun action (issue #6
38
+ * audit origin). Client-asserted, not a trust boundary; absent when the run
39
+ * was triggered by cron (source unknown).
40
+ *
41
+ * On an EXTERNAL record (issue #1826) this names the agent that completed the
42
+ * work outside the Host instead, which is what makes the history readable.
43
+ */
44
+ initiatedBy?: string
45
+ /**
46
+ * True when this outcome was recorded from outside the Host by
47
+ * `record-external-outcome` rather than observed from a DSH session
48
+ * (issue #1826).
49
+ *
50
+ * The board never manufactures one of these itself: every Host-side path
51
+ * (`run`, `settle`, cascade folding, restart recovery) writes an execution
52
+ * without it, so `external` is the single field separating work this Host ran
53
+ * from work an outside agent reported. Such a record never carries a
54
+ * `sessionId` and never claims a verdict the Host observed.
55
+ */
56
+ external?: boolean
57
+ /** Freeze instant captured from the card snapshot when the run opened. */
58
+ frozenAt?: number
59
+ /** Freeze source session captured from the card snapshot when the run opened. */
60
+ frozenBy?: string
61
+ /**
62
+ * Cascade run group shared by the parent execution and every descendant
63
+ * execution one run request opened. Absent on a plain single-task run.
64
+ */
65
+ runGroupId?: string
66
+ /**
67
+ * A cascade parent's own session outcome, recorded as soon as its own turn
68
+ * settles and held while its subtask executions finish. The execution stays
69
+ * open (no `endedAt`) until the last child settles; the Host monitor skips
70
+ * an execution whose own outcome is already recorded.
71
+ */
72
+ ownResult?: ExecutionOutcome
73
+ /** Human failure text that arrived with {@link ownResult}. */
74
+ ownError?: string
75
+ /**
76
+ * Goal acceptance state of this execution (task-board goal verification).
77
+ * Fixed when the execution starts and never rewritten from later settings:
78
+ * the contract is frozen here, the attempts accrue here, and the settlement
79
+ * rule reads the pass record here. Absent on an execution that started
80
+ * before the feature existed, which keeps it on the historical verdict.
81
+ */
82
+ verification?: ExecutionVerification
83
+ }
84
+
85
+ /**
86
+ * Maximum number of execution records retained per task. Older settled runs
87
+ * are trimmed when a new execution starts so per-action ledger cost stays
88
+ * bounded regardless of how often a task ran before.
89
+ */
90
+ export const EXECUTION_HISTORY_LIMIT = 20
91
+
92
+ /**
93
+ * Trim an execution list to at most {@link EXECUTION_HISTORY_LIMIT} records,
94
+ * most recent last. A running (unsettled) execution is never trimmed: the
95
+ * Host monitor and restart recovery depend on the active record, and a task
96
+ * cannot start a new run while one is still open.
97
+ */
98
+ export function retainRecentExecutions(executions: readonly ExecutionRecord[]): ExecutionRecord[] {
99
+ if (executions.length <= EXECUTION_HISTORY_LIMIT) return [...executions]
100
+ const open = executions.filter(execution => execution.endedAt === undefined)
101
+ const settled = executions.filter(execution => execution.endedAt !== undefined)
102
+ const keepSettled = Math.max(EXECUTION_HISTORY_LIMIT - open.length, 0)
103
+ return [...settled.slice(Math.max(settled.length - keepSettled, 0)), ...open]
104
+ }
105
+
106
+ /**
107
+ * How a rule produces its triggers: a recurring cron rule, or one single
108
+ * planned instant. The distinction is stored rather than inferred so a
109
+ * one-shot is never represented as a date-restricted cron expression.
110
+ */
111
+ export type ScheduleMode = 'cron' | 'once'
112
+
113
+ /**
114
+ * Why a due occurrence produced no run, or why a rule stopped on its own.
115
+ *
116
+ * These are stable codes, not display text: the board renders them through its
117
+ * locale dictionary, so the ledger never carries a translated string.
118
+ */
119
+ export type ScheduleStopReason =
120
+ /** The single planned instant produced its run. */
121
+ | 'fired'
122
+ /** The recurring rule reached its run budget. */
123
+ | 'limit'
124
+ /** The plan has no reachable instant any more (an impossible cron). */
125
+ | 'no-target'
126
+ /** The instant passed while the board was not running through it. */
127
+ | 'missed'
128
+ /** The task already had an open execution, so this occurrence was skipped. */
129
+ | 'busy'
130
+ /** An above-default permission was still unconfirmed, so this occurrence was skipped. */
131
+ | 'permission'
132
+ /**
133
+ * A scheduled launch failed before any session existed, so the occurrence
134
+ * created no execution and its run was refunded rather than spent.
135
+ */
136
+ | 'launch-failed'
137
+
138
+ /** Every stop reason this build understands; the repair and wire gates share it. */
139
+ export const SCHEDULE_STOP_REASONS: readonly ScheduleStopReason[] = [
140
+ 'fired', 'limit', 'no-target', 'missed', 'busy', 'permission', 'launch-failed',
141
+ ]
142
+
143
+ /**
144
+ * A scheduled-run rule attached to a task. The Host scheduler triggers the
145
+ * task when `nextRunAt` is due and persists the rule in the Host ledger.
146
+ *
147
+ * A rule is either `cron` (the historical shape: a 5-field expression with an
148
+ * explicit IANA zone, optionally capped by `maxRuns`) or `once` (one planned
149
+ * instant, `at`, with an implicit budget of one run). Both modes count the
150
+ * executions the scheduler actually started in `runCount`; a rule that reaches
151
+ * its budget stops itself in the ledger (`enabled: false` + `endedReason`)
152
+ * instead of relying on the execution agent to disable it.
153
+ */
154
+ export interface ScheduleRule {
155
+ /** Whether the schedule is armed. */
156
+ enabled: boolean
157
+ /**
158
+ * Which kind of plan this rule carries. A rule loaded from a ledger written
159
+ * before the field existed normalizes to `cron` (its `cron` is the plan).
160
+ */
161
+ mode: ScheduleMode
162
+ /**
163
+ * 5-field cron expression: `分 时 日 月 周`. Present on a `cron` rule and
164
+ * absent on a `once` rule.
165
+ */
166
+ cron?: string
167
+ /**
168
+ * The instant a `once` rule executes (ms epoch). Kept after the run so the
169
+ * detail view can still show the planned time once the rule has ended.
170
+ */
171
+ at?: number
172
+ /**
173
+ * IANA zone the wall clock is read in (issue #1722). Absent means the
174
+ * Host process zone, which is what a rule written before zones were
175
+ * persisted keeps using; the Host stamps its own zone at ledger migration so
176
+ * a later `TZ` change cannot silently move an existing rule.
177
+ */
178
+ timeZone?: string
179
+ /** Next due instant (ms epoch); maintained by the scheduler/controller. */
180
+ nextRunAt: number | undefined
181
+ /** Instant of the latest scheduled trigger (ms epoch). */
182
+ lastTriggeredAt: number | undefined
183
+ /**
184
+ * Scheduled executions the Host has created under this rule. This is the
185
+ * run budget's counter: it counts executions that were successfully opened
186
+ * (whatever their later outcome), never completions, and a manual run never
187
+ * touches it. A skipped occurrence (busy / permission / missed / no target)
188
+ * creates no execution and therefore consumes nothing.
189
+ */
190
+ runCount: number
191
+ /**
192
+ * Maximum scheduled executions for a `cron` rule; absent means unlimited
193
+ * (the historical behavior). A `once` rule has an implicit budget of one and
194
+ * stores no `maxRuns`.
195
+ */
196
+ maxRuns?: number
197
+ /** Instant the rule stopped itself (ms epoch); absent while it may still fire. */
198
+ endedAt?: number
199
+ /** Why the rule stopped itself; present with `endedAt`. */
200
+ endedReason?: ScheduleStopReason
201
+ /** Instant of the latest occurrence that produced no run. */
202
+ skippedAt?: number
203
+ /** Why that occurrence produced no run; present with `skippedAt`. */
204
+ skippedReason?: ScheduleStopReason
205
+ }
206
+
207
+ /**
208
+ * The rule's total run budget: one for a one-shot, the stored cap for a
209
+ * recurring rule, and undefined when the rule is unlimited.
210
+ * @param rule - the schedule rule.
211
+ * @returns the budget, or undefined for an uncapped rule.
212
+ */
213
+ export function scheduleRunBudget(rule: ScheduleRule): number | undefined {
214
+ if (rule.mode === 'once') return 1
215
+ return rule.maxRuns
216
+ }
217
+
218
+ /**
219
+ * Whether a rule has no runs left. The scheduler refuses to open another
220
+ * execution for an exhausted rule, which is what makes the budget terminal
221
+ * regardless of restarts or repeated timer fires.
222
+ * @param rule - the schedule rule.
223
+ * @returns true when the run budget is spent.
224
+ */
225
+ export function scheduleExhausted(rule: ScheduleRule): boolean {
226
+ const budget = scheduleRunBudget(rule)
227
+ return budget !== undefined && rule.runCount >= budget
228
+ }
229
+
230
+ /**
231
+ * The instant a rule plans to fire next, for display, whatever its mode: the
232
+ * planned `at` of a one-shot, or the stored `nextRunAt` of a recurring rule.
233
+ * @param rule - the schedule rule.
234
+ * @returns the planned instant, or undefined when the rule carries none.
235
+ */
236
+ export function schedulePlannedAt(rule: ScheduleRule): number | undefined {
237
+ if (rule.mode === 'once') return rule.at
238
+ return rule.nextRunAt
239
+ }
240
+
241
+ /**
242
+ * Frozen context snapshot carried by a continuation card (issue #4): the
243
+ * goal/progress/next text (already sanitized by the freeze gates) plus the
244
+ * freeze instant and the redaction warning flag.
245
+ */
246
+ export interface TaskFreeze extends FreezeSnapshot {
247
+ /** When the snapshot was frozen (ms epoch, stamped by the create/update use case). */
248
+ frozenAt: number
249
+ /** True when the freeze gates redacted sensitive patterns out of the text. */
250
+ redacted?: boolean
251
+ /**
252
+ * Session id of the DSH session that authored the frozen snapshot (issue #6
253
+ * provenance): stamped by the Host ledger from the create/update action's
254
+ * initiator, or kept from the wire payload when no initiator was asserted.
255
+ */
256
+ frozenBy?: string
257
+ }
258
+
259
+ /**
260
+ * One task label (issue #1521). The name is the badge and the tag-filter key;
261
+ * the optional prompt line rides the execution prompt, so a label may be
262
+ * display-only (no prefix) or carry an instruction (business-line routing,
263
+ * output directory, house style) that every run of the task inherits.
264
+ */
265
+ export interface TaskTag {
266
+ /** Display name; trimmed, non-empty, unique within the task. */
267
+ name: string
268
+ /**
269
+ * Prompt line injected ahead of the execution prompt. Absent (or blank
270
+ * after trimming) keeps the tag display-only: it never touches the prompt,
271
+ * so a label with no prefix has zero execution side effects.
272
+ */
273
+ promptPrefix?: string
274
+ }
275
+
276
+ /** Maximum number of tags carried by one task. */
277
+ export const TASK_TAG_LIMIT = 8
278
+ /** Maximum length of a tag name. */
279
+ export const TAG_NAME_MAX_LENGTH = 32
280
+ /** Maximum length of a tag's injected prompt line. */
281
+ export const TAG_PROMPT_MAX_LENGTH = 200
282
+
283
+ /** Whether an unknown value is a well-formed tag (strict: the wire gate). */
284
+ export function isTaskTag(value: unknown): value is TaskTag {
285
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
286
+ const tag = value as Record<string, unknown>
287
+ if (Object.keys(tag).some(key => key !== 'name' && key !== 'promptPrefix')) return false
288
+ if (typeof tag.name !== 'string') return false
289
+ const name = tag.name.trim()
290
+ if (name === '' || name.length > TAG_NAME_MAX_LENGTH) return false
291
+ if (tag.promptPrefix !== undefined && typeof tag.promptPrefix !== 'string') return false
292
+ return tag.promptPrefix === undefined || (tag.promptPrefix as string).trim().length <= TAG_PROMPT_MAX_LENGTH
293
+ }
294
+
295
+ /**
296
+ * Whether an unknown value is a well-formed tag list (strict: the wire gate).
297
+ * An empty list is rejected — clearing tags is expressed by omitting the field
298
+ * (create) or by an explicit null (update), never by an empty array.
299
+ */
300
+ export function isTaskTagList(value: unknown): value is TaskTag[] {
301
+ return Array.isArray(value) && value.length > 0 && value.length <= TASK_TAG_LIMIT && value.every(isTaskTag)
302
+ }
303
+
304
+ /**
305
+ * Repair a persisted tag list: keep the well-formed entries, trim, drop
306
+ * blanks and repeats, cap the count, and collapse a blank prompt line to
307
+ * "display-only". Returns undefined when nothing usable remains, so the caller
308
+ * clears the field instead of storing an empty array.
309
+ */
310
+ export function normalizeTags(value: unknown): TaskTag[] | undefined {
311
+ if (!Array.isArray(value)) return undefined
312
+ const tags: TaskTag[] = []
313
+ const seen = new Set<string>()
314
+ for (const entry of value) {
315
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) continue
316
+ const row = entry as Record<string, unknown>
317
+ if (typeof row.name !== 'string') continue
318
+ const name = row.name.trim()
319
+ if (name === '' || name.length > TAG_NAME_MAX_LENGTH || seen.has(name)) continue
320
+ const raw = typeof row.promptPrefix === 'string' ? row.promptPrefix.trim() : ''
321
+ const promptPrefix = raw === '' ? undefined : raw.slice(0, TAG_PROMPT_MAX_LENGTH)
322
+ seen.add(name)
323
+ tags.push(promptPrefix === undefined ? { name } : { name, promptPrefix })
324
+ if (tags.length >= TASK_TAG_LIMIT) break
325
+ }
326
+ return tags.length === 0 ? undefined : tags
327
+ }
328
+
329
+ /**
330
+ * Stable palette slot (0..5) for a tag name. The same label always lands on the
331
+ * same tone, so a badge needs no stored colour and two tasks sharing a label
332
+ * cannot disagree about it.
333
+ */
334
+ export function tagTone(name: string): number {
335
+ let hash = 0
336
+ for (const char of name) hash = (hash * 31 + (char.codePointAt(0) ?? 0)) >>> 0
337
+ return hash % 6
338
+ }
339
+
340
+ /**
341
+ * Union of the labels already carried by `tasks`, first occurrence wins (the
342
+ * oldest task's hint is the one offered). Feeds the editor's name datalist and
343
+ * the board's tag filter, so a label defined once can be reused everywhere.
344
+ */
345
+ export function collectKnownTags(tasks: readonly TaskRecord[]): TaskTag[] {
346
+ const known: TaskTag[] = []
347
+ const seen = new Set<string>()
348
+ for (const task of tasks) {
349
+ for (const tag of task.tags ?? []) {
350
+ if (seen.has(tag.name)) continue
351
+ seen.add(tag.name)
352
+ known.push(tag)
353
+ }
354
+ }
355
+ return known
356
+ }
357
+
358
+ /** One task on the board. */
359
+ export interface TaskRecord {
360
+ /** Stable task id (uuid). */
361
+ id: string
362
+ /** Short display title. */
363
+ title: string
364
+ /** Longer human description shown in the detail view. */
365
+ description: string
366
+ /** The prompt sent to dsh when this task is executed. */
367
+ prompt: string
368
+ /**
369
+ * Parent task id: present only on a subtask. The Host owns the lineage gate
370
+ * (see `core/subtask.ts`), which refuses a cycle, an archived parent, and
371
+ * any link that would exceed `maxSubtaskDepth` — so every chain the Host
372
+ * wrote under the current setting is at most that many links long. Lowering
373
+ * the limit later neither rewrites nor deletes an already stored link.
374
+ */
375
+ parentId?: string
376
+ /** Current column. */
377
+ status: TaskStatus
378
+ /** Creation instant (ms epoch). */
379
+ createdAt: number
380
+ /** Last mutation instant (ms epoch). */
381
+ updatedAt: number
382
+ /**
383
+ * Execution history retained on the task, most recent last: the latest
384
+ * {@link EXECUTION_HISTORY_LIMIT} attempts, oldest trimmed on append.
385
+ */
386
+ executions: ExecutionRecord[]
387
+ /** Optional scheduled-run rule (absent on tasks without a schedule). */
388
+ schedule?: ScheduleRule
389
+ /**
390
+ * Workspace the execution must run in (a workspace-list id); absent means
391
+ * the recent-workspace fallback at execution time.
392
+ */
393
+ workspaceId?: string
394
+ /**
395
+ * Agent preset the execution session must be composed from (an
396
+ * `agentPreset.list` id); absent means the deployment default.
397
+ */
398
+ mode?: string
399
+ /**
400
+ * Permission preset applied to the execution session through the
401
+ * `/permission <id>` slash command; absent leaves the session default.
402
+ */
403
+ permission?: TaskPermission
404
+ /**
405
+ * Pinned model selection for the execution session (format: "provider/model" or model id);
406
+ * absent falls back to the host default (agent-default-model).
407
+ */
408
+ model?: string
409
+ /**
410
+ * Whether later executions continue in the previous execution's session
411
+ * (issue #1419) instead of minting a fresh conversation per run. Absent or
412
+ * false keeps the historical one-session-per-execution behavior; the reuse
413
+ * itself only happens when that session is idle and still present (see
414
+ * {@link reusableSessionId}).
415
+ */
416
+ reuseSession?: boolean
417
+ /**
418
+ * Run this task's subtree as an Agent Team instead of one Host-launched
419
+ * session per participant: the root becomes the Team Lead session and the
420
+ * Host spawns one teammate for each direct subtask inside it. Absent or false
421
+ * keeps the plain concurrent cascade. A deployment that does not serve the
422
+ * Agent Teams service refuses a team run instead of silently falling back,
423
+ * and a subtask's own permission pin cannot be honored in this mode.
424
+ */
425
+ teamRun?: boolean
426
+ /**
427
+ * Start every execution of this task with dsh's built-in `/goal` command,
428
+ * armed with the composed execution prompt as its objective. The session then
429
+ * keeps working automatic continuation rounds until the agent marks the goal
430
+ * complete, and this board settles the execution on the goal's own end
431
+ * instead of at the first turn end. Absent means OFF — the option is
432
+ * unchecked by default, so only an explicit `true` joins the goal run and
433
+ * every card that never touched it (including every card written before the
434
+ * field existed) runs one plain turn. A session whose `/goal` command is
435
+ * refused still runs the prompt.
436
+ */
437
+ goalRun?: boolean
438
+ /**
439
+ * Run this task's goal executions WITHOUT the board's acceptance gate.
440
+ *
441
+ * Absent means INHERIT: the execution's applicability is decided by the
442
+ * board-wide `goalVerification` switch frozen at start, exactly as a card
443
+ * that never touched this option behaves. Only an explicit `true` opts the
444
+ * card out, and the execution records `applicability: 'disabled'` so the
445
+ * report says plainly that nothing certified this run.
446
+ *
447
+ * The opt-out is per execution, not per run: flipping it never rewrites the
448
+ * verdict rule of an execution already open, and a rerun or a scheduled
449
+ * occurrence reads the card's current value when it freezes its contract.
450
+ */
451
+ skipVerification?: boolean
452
+ /**
453
+ * Frozen context snapshot for a continuation card; absent on plain tasks.
454
+ * Sanitized before it enters the ledger (redaction, slash-command taint,
455
+ * 8 KiB per-field cap) by the protocol gate and re-normalized on load.
456
+ */
457
+ freeze?: TaskFreeze
458
+ /**
459
+ * Handover bundle carried by a continuation card (issue #5): the pinned
460
+ * execution triplet plus doc/script references. Sanitized before it
461
+ * enters the ledger by the protocol gate and re-normalized on load; the
462
+ * bundle's triplet overrides the legacy pin fields at execution time.
463
+ */
464
+ handover?: TaskHandover
465
+ /**
466
+ * Task labels (issue #1521): optional, additive, and absent on every task
467
+ * created before the field existed. A tag whose `promptPrefix` is set is
468
+ * prepended to the execution prompt; a bare name is display and filter only.
469
+ */
470
+ tags?: TaskTag[]
471
+ /**
472
+ * Human confirmation stamp for an above-default effective permission
473
+ * (ms epoch). Absent while the binding awaits confirmation; any permission
474
+ * or handover change re-arms the gate by clearing it.
475
+ */
476
+ permissionConfirmedAt?: number
477
+ /**
478
+ * When the task was archived (ms epoch). Archived tasks keep their status
479
+ * and execution history, leave the main board, and cannot run until restored;
480
+ * absent means on-board.
481
+ */
482
+ archivedAt?: number
483
+ /**
484
+ * Opaque external-provider metadata, keyed by extension id; optional and
485
+ * additive so existing tasks require no ledger migration. The board stores
486
+ * and forwards it without interpreting the keys — each provider owns the
487
+ * shape and validation of its own entry.
488
+ */
489
+ integrations?: Record<string, TaskBoardExtensionPayload>
490
+ /**
491
+ * Whether the card is held off the board: it exists in the ledger (and its
492
+ * execution history is intact) but no column ever renders it. Providers
493
+ * create hidden cards for work they materialize but do not want displayed;
494
+ * absent means on-board.
495
+ */
496
+ hidden?: boolean
497
+ }
498
+
499
+ /**
500
+ * Statuses a task may be archived from: every status but `running`, whose
501
+ * execution the runner still owns until it settles. A settled-only gate made
502
+ * the duplicate-and-archive flow a silent no-op for scheduled tasks, which
503
+ * return to `todo` after every successful run (issue #1447).
504
+ */
505
+ export const ARCHIVABLE_STATUSES: readonly TaskStatus[] = ['backlog', 'todo', 'done', 'failed']
506
+
507
+
508
+ /** Permission presets a task may pin on its execution session (the `/permission <id>` ids). */
509
+ export const TASK_PERMISSIONS = ['read-only', 'workspace-write', 'danger-full-access'] as const
510
+
511
+ /** One permission preset id. */
512
+ export type TaskPermission = typeof TASK_PERMISSIONS[number]
513
+
514
+ /** Whether an unknown value is a known permission preset id. */
515
+ export function isTaskPermission(value: unknown): value is TaskPermission {
516
+ return typeof value === 'string' && (TASK_PERMISSIONS as readonly string[]).includes(value)
517
+ }
518
+
519
+ /** Input for creating a task. */
520
+ export interface NewTaskInput {
521
+ title: string
522
+ description: string
523
+ prompt: string
524
+ /**
525
+ * Parent task id, turning this creation into a subtask. Absent keeps a root
526
+ * task; the create use case validates the link (existence, depth) and
527
+ * inherits the parent's unset execution targets.
528
+ */
529
+ parentId?: string
530
+ /** Workspace the execution must run in; empty/absent = the creating session's workspace for a root task, else the recent workspace at execution time. */
531
+ workspaceId?: string
532
+ /** Agent preset the execution session must be composed from; empty/absent = deployment default. */
533
+ mode?: string
534
+ /** Permission preset applied to the execution session; absent = session default. */
535
+ permission?: TaskPermission
536
+ /** Optional pinned model for the execution session; absent = host default. */
537
+ model?: string
538
+ /** Reuse the previous execution's session for later runs (issue #1419). */
539
+ reuseSession?: boolean
540
+ /** Run the subtree as an Agent Team (Team Lead session plus one teammate per direct subtask). */
541
+ teamRun?: boolean
542
+ /**
543
+ * Start the execution with dsh's built-in `/goal`. Absent means the default
544
+ * (one plain turn); only an explicit true joins the goal run.
545
+ */
546
+ goalRun?: boolean
547
+ /**
548
+ * Run this task's goal executions without the acceptance gate; absent
549
+ * inherits the board-wide `goalVerification` switch.
550
+ */
551
+ skipVerification?: boolean
552
+ /**
553
+ * Optional scheduling rule requested at creation time (the new-task
554
+ * dialog): an enable flag, the kind of plan (a recurring 5-field cron
555
+ * expression, or one planned instant for a one-shot), an optional run cap,
556
+ * and the IANA zone its wall clock is read in (absent means the Host zone).
557
+ * The create use case arms it only when enabled and the plan is valid.
558
+ */
559
+ schedule?: {
560
+ enabled: boolean
561
+ mode?: ScheduleMode
562
+ cron?: string
563
+ /** Planned instant of a one-shot rule (ms epoch). */
564
+ at?: number
565
+ timeZone?: string
566
+ /** Run cap of a recurring rule; absent means unlimited. */
567
+ maxRuns?: number
568
+ }
569
+ /**
570
+ * Optional frozen context snapshot (goal/progress/next, sanitized by the
571
+ * protocol gate) turning the new task into a continuation card.
572
+ */
573
+ freeze?: FreezeSnapshot & { redacted?: boolean; frozenBy?: string }
574
+ /**
575
+ * Optional handover bundle (pinned triplet + doc/script references,
576
+ * sanitized by the protocol gate) attached at creation.
577
+ */
578
+ handover?: TaskHandoverInput
579
+ /**
580
+ * Optional task labels. A tag with a non-blank `promptPrefix` is injected
581
+ * ahead of the execution prompt; a bare name changes nothing at run time.
582
+ */
583
+ tags?: TaskTag[]
584
+ /** Opaque external-provider metadata keyed by extension id. */
585
+ integrations?: Record<string, TaskBoardExtensionPayload>
586
+ /** Column the created card opens in; absent means the board default (todo). */
587
+ status?: TaskStatus
588
+ /** Create the card off-board (held in the ledger, never rendered). */
589
+ hidden?: boolean
590
+ }
591
+
592
+ /** The five kanban columns, in display order. */
593
+ export const COLUMNS: readonly { status: TaskStatus; label: string }[] = [
594
+ { status: 'backlog', label: '待规划' },
595
+ { status: 'todo', label: '待办' },
596
+ { status: 'running', label: '进行中' },
597
+ { status: 'done', label: '已完成' },
598
+ { status: 'failed', label: '已失败' },
599
+ ]
600
+
601
+ /**
602
+ * Statuses a card may be moved to by hand: every column. The board UI and the
603
+ * agent tool surface share this one list, so no column can be manual on one
604
+ * surface and locked on the other.
605
+ *
606
+ * The column is a board statement, not a claim about a run. A hand-written
607
+ * `done`/`failed` declares that the work finished (or failed) outside a
608
+ * Host-run execution — human hands, an external system — and a hand-written
609
+ * `running` says the work is under way without a tracked session. None of them
610
+ * creates an {@link ExecutionRecord}, which is what keeps a declaration
611
+ * distinguishable from a recorded outcome in the card's execution history; the
612
+ * next settled run overwrites the column with the real one.
613
+ */
614
+ export const MANUAL_STATUSES: readonly TaskStatus[] = ['backlog', 'todo', 'running', 'done', 'failed']
615
+
616
+ /** Statuses the runner may move a card to from 'running'. */
617
+ export const RUNNER_SETTLE_STATUSES: readonly TaskStatus[] = ['done', 'failed']
618
+
619
+ /** All valid statuses (closed union guard). */
620
+ export const ALL_STATUSES: readonly TaskStatus[] = [
621
+ 'backlog', 'todo', 'running', 'done', 'failed',
622
+ ]
623
+
624
+ /** Brand an unknown string as a status; undefined when it is not one. */
625
+ export function isTaskStatus(value: unknown): value is TaskStatus {
626
+ return typeof value === 'string' && (ALL_STATUSES as readonly string[]).includes(value)
627
+ }
628
+
629
+ /**
630
+ * Whether the manual move `from` -> `to` is a legal *column* change: any
631
+ * column, and never the one the card already shows.
632
+ *
633
+ * Whether the card may be moved at all is a separate question. The lock an
634
+ * executing card carries belongs to its open execution, never to the column
635
+ * text, so it is {@link canMoveTask} — not this predicate — that expresses it.
636
+ */
637
+ export function canMoveManually(from: TaskStatus, to: TaskStatus): boolean {
638
+ return from !== to && (MANUAL_STATUSES as readonly TaskStatus[]).includes(to)
639
+ }
640
+
641
+ /**
642
+ * Whether the board may move `task` to `to` by hand: the card is on-board,
643
+ * holds no open execution, and the target is a legal column change. The ledger,
644
+ * the detail view's status buttons and the board's drop handler all decide
645
+ * through this one predicate, so no two surfaces can disagree about a card.
646
+ */
647
+ export function canMoveTask(task: TaskRecord, to: TaskStatus): boolean {
648
+ return task.archivedAt === undefined && !hasOpenExecution(task) && canMoveManually(task.status, to)
649
+ }
650
+
651
+ /**
652
+ * Whether the task still has an execution the runner has not settled. This —
653
+ * not the `running` column — is what "the runner owns this card" means: a card
654
+ * parked in `running` by hand has no session and stays fully movable.
655
+ */
656
+ export function hasOpenExecution(task: TaskRecord): boolean {
657
+ return task.executions.some(execution => execution.endedAt === undefined)
658
+ }
659
+
660
+ /** Normalize one optional execution-target string: trim; blank collapses to undefined. */
661
+ export function normalizeTargetId(value: string | undefined): string | undefined {
662
+ const trimmed = value?.trim()
663
+ return trimmed === undefined || trimmed === '' ? undefined : trimmed
664
+ }
665
+
666
+ /**
667
+ * Build the persisted freeze snapshot from a sanitized input, stamping the
668
+ * freeze instant (shared by the create and update use cases).
669
+ */
670
+ export function freezeOf(
671
+ input: FreezeSnapshot & { redacted?: boolean; frozenBy?: string },
672
+ now: number,
673
+ ): TaskFreeze {
674
+ return {
675
+ goal: input.goal,
676
+ progress: input.progress,
677
+ next: input.next,
678
+ frozenAt: now,
679
+ ...(input.redacted === true ? { redacted: true } : {}),
680
+ ...(input.frozenBy === undefined || input.frozenBy === '' ? {} : { frozenBy: input.frozenBy }),
681
+ }
682
+ }
683
+
684
+ /** Create a task from user input. */
685
+ export function createTask(input: NewTaskInput, now: number, id: string): TaskRecord {
686
+ const tags = normalizeTags(input.tags)
687
+ const integrations = normalizeTaskIntegrations(input.integrations)
688
+ return {
689
+ id,
690
+ title: input.title.trim(),
691
+ description: input.description.trim(),
692
+ prompt: input.prompt.trim(),
693
+ parentId: normalizeTargetId(input.parentId),
694
+ status: input.status ?? 'todo',
695
+ createdAt: now,
696
+ updatedAt: now,
697
+ executions: [],
698
+ workspaceId: normalizeTargetId(input.workspaceId),
699
+ mode: normalizeTargetId(input.mode),
700
+ permission: isTaskPermission(input.permission) ? input.permission : undefined,
701
+ model: normalizeTargetId(input.model),
702
+ reuseSession: input.reuseSession === true ? true : undefined,
703
+ teamRun: input.teamRun === true ? true : undefined,
704
+ // Default OFF: only an explicit true is stored, so a card that never
705
+ // touched the option (and every card written before the field existed)
706
+ // keeps running one plain turn.
707
+ goalRun: input.goalRun === true ? true : undefined,
708
+ // Default OFF: only an explicit true is stored, so a card that never
709
+ // touched the option inherits the board-wide acceptance switch exactly as
710
+ // every card written before the field existed does.
711
+ skipVerification: input.skipVerification === true ? true : undefined,
712
+ ...(input.freeze === undefined ? {} : { freeze: freezeOf(input.freeze, now) }),
713
+ ...(input.handover === undefined ? {} : { handover: { ...input.handover, bundledAt: now } }),
714
+ ...(tags === undefined ? {} : { tags }),
715
+ ...(integrations === undefined ? {} : { integrations }),
716
+ ...(input.hidden === true ? { hidden: true } : {}),
717
+ }
718
+ }
719
+
720
+ /** Clone a task with an updated status and a fresh updatedAt. */
721
+ export function withStatus(task: TaskRecord, status: TaskStatus, now: number): TaskRecord {
722
+ return { ...task, status, updatedAt: now }
723
+ }
724
+
725
+ /** Every field a schedule patch may carry; the rest of the rule is carried over. */
726
+ const SCHEDULE_PATCH_KEYS = [
727
+ 'enabled', 'mode', 'cron', 'at', 'timeZone', 'nextRunAt', 'lastTriggeredAt',
728
+ 'runCount', 'maxRuns', 'endedAt', 'endedReason', 'skippedAt', 'skippedReason',
729
+ ] as const satisfies ReadonlyArray<keyof ScheduleRule>
730
+
731
+ /**
732
+ * Merge a schedule patch into a task's schedule rule (creating it when
733
+ * absent), with a fresh updatedAt. Keys present in the patch overwrite the
734
+ * current value — including explicit `undefined`, which clears a field (used
735
+ * to disarm `nextRunAt` or to drop an ended/skip record); absent keys keep
736
+ * their current value.
737
+ */
738
+ export function withSchedule(
739
+ task: TaskRecord,
740
+ patch: Partial<ScheduleRule>,
741
+ now: number,
742
+ ): TaskRecord {
743
+ const schedule: ScheduleRule = task.schedule === undefined
744
+ ? { enabled: false, mode: 'cron', nextRunAt: undefined, lastTriggeredAt: undefined, runCount: 0 }
745
+ : { ...task.schedule }
746
+ const fields = schedule as unknown as Record<string, unknown>
747
+ const next = patch as unknown as Record<string, unknown>
748
+ for (const key of SCHEDULE_PATCH_KEYS) {
749
+ if (!(key in patch)) continue
750
+ if (next[key] === undefined) delete fields[key]
751
+ else fields[key] = next[key]
752
+ }
753
+ // The three non-optional fields can never be cleared into an unusable rule.
754
+ if (schedule.enabled !== true) schedule.enabled = false
755
+ if (schedule.mode !== 'once') schedule.mode = 'cron'
756
+ if (!Number.isFinite(schedule.runCount) || schedule.runCount < 0) schedule.runCount = 0
757
+ return { ...task, updatedAt: now, schedule }
758
+ }
759
+
760
+ /**
761
+ * Open a fresh execution on a task: move it to 'running' and append a
762
+ * running execution record. Returns the new task and the new execution.
763
+ * @param runGroupId - cascade run group, when this run also opened executions
764
+ * for the task's subtasks (see `core/subtask.ts`).
765
+ */
766
+ export function startExecution(
767
+ task: TaskRecord,
768
+ now: number,
769
+ executionId: string,
770
+ initiatedBy?: string,
771
+ runGroupId?: string,
772
+ ): { task: TaskRecord; execution: ExecutionRecord } {
773
+ const execution: ExecutionRecord = {
774
+ id: executionId,
775
+ sessionId: undefined,
776
+ startedAt: now,
777
+ endedAt: undefined,
778
+ result: undefined,
779
+ error: undefined,
780
+ ...(runGroupId === undefined || runGroupId === '' ? {} : { runGroupId }),
781
+ ...(initiatedBy === undefined || initiatedBy === '' ? {} : { initiatedBy }),
782
+ // Capture the card's freeze provenance on the execution record so the
783
+ // audit trail stays queryable even if the snapshot is replaced later.
784
+ ...(task.freeze === undefined ? {} : {
785
+ frozenAt: task.freeze.frozenAt,
786
+ ...(task.freeze.frozenBy === undefined ? {} : { frozenBy: task.freeze.frozenBy }),
787
+ }),
788
+ }
789
+ return {
790
+ task: {
791
+ ...task,
792
+ status: 'running',
793
+ updatedAt: now,
794
+ executions: retainRecentExecutions([...task.executions, execution]),
795
+ },
796
+ execution,
797
+ }
798
+ }
799
+
800
+ /**
801
+ * The column a settled outcome puts a card in. The ONE derivation shared by
802
+ * every settlement path (issue #1826): a Host-run execution and an outcome an
803
+ * outside agent reported both land in the same column from the same rule, so
804
+ * the column never becomes a second, independent piece of state.
805
+ @param task - the card being settled.
806
+ @param outcome - the settled outcome.
807
+ @returns the status the card shows afterwards.
808
+ */
809
+ export function settledStatus(task: TaskRecord, outcome: ExecutionOutcome): TaskStatus {
810
+ if (outcome === 'succeeded') return task.schedule?.enabled === true ? 'todo' : 'done'
811
+ if (outcome === 'failed') return 'failed'
812
+ return task.status === 'running' ? 'todo' : task.status
813
+ }
814
+
815
+ /**
816
+ * Settle a running execution: record the outcome and move the task into the
817
+ * matching column. No-op (returns the input task) when the execution is not
818
+ * the task's latest or is already settled.
819
+ */
820
+ export function settleExecution(
821
+ task: TaskRecord,
822
+ executionId: string,
823
+ outcome: ExecutionOutcome,
824
+ now: number,
825
+ error: string | undefined,
826
+ ): TaskRecord {
827
+ const index = task.executions.findIndex(execution => execution.id === executionId)
828
+ if (index === -1) return task
829
+ const execution = task.executions[index]
830
+ if (execution.endedAt !== undefined) return task
831
+ const settled: ExecutionRecord = { ...execution, endedAt: now, result: outcome, error }
832
+ const executions = [...task.executions]
833
+ executions[index] = settled
834
+ return { ...task, status: settledStatus(task, outcome), updatedAt: now, executions }
835
+ }
836
+
837
+ /** A settled-execution summary string for the detail view. */
838
+ export function executionLabel(execution: ExecutionRecord): string {
839
+ if (execution.result === 'succeeded') return 'succeeded'
840
+ if (execution.result === 'failed') return 'failed'
841
+ if (execution.result === 'cancelled') return 'cancelled'
842
+ return 'running'
843
+ }