@linxin666/dsh-client-ui-task-board 0.4.7 → 0.4.9

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 (75) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +29 -22
  3. package/README.zh.md +29 -22
  4. package/lib/client.js +1553 -670
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +757 -419
  7. package/lib/types/client/PluginSettingsCard.d.ts +60 -0
  8. package/lib/types/client/TaskBoardSettingsCard.d.ts +14 -0
  9. package/lib/types/client/board/ExecutionLog.d.ts +16 -0
  10. package/lib/types/client/board/TaskForm.d.ts +4 -0
  11. package/lib/types/client/board/VerificationReport.d.ts +2 -15
  12. package/lib/types/client/body-mutations.d.ts +45 -0
  13. package/lib/types/client/locales.d.ts +44 -6
  14. package/lib/types/client/suppress-schedule-row.d.ts +86 -0
  15. package/lib/types/client/telemetry.d.ts +14 -2
  16. package/lib/types/core/controller.d.ts +1 -1
  17. package/lib/types/core/execution-summary.d.ts +52 -0
  18. package/lib/types/core/extension.d.ts +34 -0
  19. package/lib/types/core/spend-budget.d.ts +28 -0
  20. package/lib/types/core/subtask.d.ts +59 -49
  21. package/lib/types/core/tasks.d.ts +37 -9
  22. package/lib/types/core/use-cases/task-update.d.ts +1 -1
  23. package/lib/types/core/workspace-target.d.ts +23 -3
  24. package/lib/types/host/launch-admission.d.ts +8 -9
  25. package/lib/types/host-ledger.d.ts +96 -50
  26. package/lib/types/host-routes.d.ts +49 -0
  27. package/lib/types/host-runner.d.ts +24 -11
  28. package/lib/types/host-service.d.ts +38 -50
  29. package/lib/types/host-spend.d.ts +52 -0
  30. package/lib/types/index.d.ts +70 -61
  31. package/lib/types/loopback.d.ts +41 -1
  32. package/lib/types/protocol.d.ts +0 -5
  33. package/lib/types/tool-surface.d.ts +1 -0
  34. package/package.json +25 -25
  35. package/src/client/CardDefaultPresetField.tsx +1 -1
  36. package/src/client/PluginSettingsCard.tsx +140 -20
  37. package/src/client/TaskBoardSettingsCard.tsx +104 -24
  38. package/src/client/board/ExecutionLog.tsx +140 -0
  39. package/src/client/board/LinkSubtaskModal.tsx +1 -9
  40. package/src/client/board/NewTaskModal.tsx +2 -11
  41. package/src/client/board/TaskCard.tsx +45 -23
  42. package/src/client/board/TaskDetail.tsx +407 -261
  43. package/src/client/board/TaskForm.tsx +19 -4
  44. package/src/client/board/VerificationReport.tsx +143 -104
  45. package/src/client/board/task-markdown.module.css +11 -8
  46. package/src/client/board-settings.module.css +35 -7
  47. package/src/client/board.module.css +855 -115
  48. package/src/client/body-mutations.ts +133 -0
  49. package/src/client/index.ts +10 -0
  50. package/src/client/locales.ts +101 -24
  51. package/src/client/settings-card.module.css +141 -11
  52. package/src/client/suppress-schedule-row.ts +198 -0
  53. package/src/client/telemetry.ts +47 -2
  54. package/src/core/controller.ts +1 -3
  55. package/src/core/execution-summary.ts +96 -0
  56. package/src/core/extension.ts +34 -0
  57. package/src/core/spend-budget.ts +35 -0
  58. package/src/core/store.ts +4 -0
  59. package/src/core/subtask.ts +81 -76
  60. package/src/core/tasks.ts +48 -10
  61. package/src/core/use-cases/task-update.ts +1 -3
  62. package/src/core/workspace-target.ts +27 -3
  63. package/src/host/agent-tools.ts +14 -15
  64. package/src/host/launch-admission.ts +8 -9
  65. package/src/host-ledger.ts +218 -127
  66. package/src/host-routes.ts +65 -2
  67. package/src/host-runner.ts +68 -35
  68. package/src/host-service.ts +136 -132
  69. package/src/host-spend.ts +105 -0
  70. package/src/index.ts +115 -104
  71. package/src/loopback.ts +57 -1
  72. package/src/protocol.ts +2 -9
  73. package/src/tool-surface.ts +1 -0
  74. package/lib/types/client/board/team-run-promotion.d.ts +0 -26
  75. package/src/client/board/team-run-promotion.ts +0 -39
@@ -3,7 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'node:http'
3
3
  import type { WebRoute } from '@deepseek-ai/dsh-host-webserver'
4
4
  import type { TaskBoardHostService } from './host-service.ts'
5
5
  import { writeJson } from './http.ts'
6
- import { isLoopbackAddress, isLoopbackRequest } from './loopback.ts'
6
+ import { isForwardedLoopbackRequest, isLoopbackAddress, isLoopbackRequest } from './loopback.ts'
7
7
  import { TaskParseError, TASK_PARSE_MAX_INPUT } from './host-ai.ts'
8
8
  import {
9
9
  parseActionEnvelope,
@@ -20,10 +20,40 @@ const HEARTBEAT_MS = 15_000
20
20
  /** Header replaced by an authenticated same-host reverse proxy. */
21
21
  export const TASK_BOARD_PROXY_TOKEN_HEADER = 'x-dsh-task-board-proxy-token'
22
22
 
23
+ /**
24
+ * The composition's Host connection service, narrowed to the one check the
25
+ * board bridges: `requestRejection` runs the Host/Origin fence and verifies
26
+ * the authority-bound `dsh-auth-*` browser session minted by the Host. It
27
+ * answers `undefined` only for a request it admits and 401/403 otherwise.
28
+ * Declared structurally, like the official open-in-app routes do, because the
29
+ * service's package is a browser-side dependency this Host half does not
30
+ * import.
31
+ */
32
+ export interface TaskBoardConnectionTrust {
33
+ requestRejection(request: { readonly headers: IncomingMessage['headers'] }): 401 | 403 | undefined
34
+ }
35
+
23
36
  /** Optional authenticated reverse-proxy access layered over the loopback default. */
24
37
  export interface TaskBoardRouteAccess {
25
38
  trustedProxyHosts?: readonly string[]
26
39
  proxyToken?: string
40
+ /**
41
+ /**
42
+ * Whether the operator's own reverse proxy or tunnel may speak for the
43
+ * browser: a forwarded request that landed on this machine's loopback
44
+ * upstream then counts as trustable, still behind the browser same-origin
45
+ * marker. Read at each request (hence the function), so the settings switch
46
+ * binds the next request without re-registering the routes. Absent or false
47
+ * keeps the pre-existing fence exactly as it was (issue #1906).
48
+ */
49
+ trustForwardedProxy?: () => boolean
50
+ /**
51
+ * Resolves the Host's `connection` service when a request arrives, so a
52
+ * deployment that mounts it after these routes still gains the bridge and a
53
+ * composition that never mounts it keeps the pre-existing fence. Absent means
54
+ * no bridge (issue #1930).
55
+ */
56
+ connection?: () => TaskBoardConnectionTrust | undefined
27
57
  }
28
58
 
29
59
  /**
@@ -39,6 +69,8 @@ export interface TaskBoardRouteOptions {
39
69
  interface ResolvedRouteAccess {
40
70
  trustedProxyHosts: ReadonlySet<string>
41
71
  proxyToken?: string
72
+ trustForwardedProxy: () => boolean
73
+ connection?: () => TaskBoardConnectionTrust | undefined
42
74
  }
43
75
 
44
76
  function parseAuthority(authority: string): { canonical: string; url: URL } | undefined {
@@ -70,7 +102,12 @@ function resolveAccess(access: TaskBoardRouteAccess): ResolvedRouteAccess {
70
102
  if (trustedProxyHosts.size > 0 && (access.proxyToken === undefined || access.proxyToken === '')) {
71
103
  throw new Error('task-board: authenticated proxy hosts require a non-empty proxy token')
72
104
  }
73
- return { trustedProxyHosts, ...(access.proxyToken === undefined ? {} : { proxyToken: access.proxyToken }) }
105
+ return {
106
+ trustedProxyHosts,
107
+ trustForwardedProxy: access.trustForwardedProxy ?? ((): boolean => false),
108
+ ...(access.proxyToken === undefined ? {} : { proxyToken: access.proxyToken }),
109
+ ...(access.connection === undefined ? {} : { connection: access.connection }),
110
+ }
74
111
  }
75
112
 
76
113
  /**
@@ -146,10 +183,36 @@ function matchesToken(candidate: string | string[] | undefined, expected: string
146
183
  * tripwire, the socket/Host/origin-equality checks carry the authority).
147
184
  * Authenticated proxies must be explicitly allowlisted and replace the
148
185
  * internal token header after their own authentication step.
186
+ *
187
+ * A third party's proxy cannot inject that token, so a deployment whose own
188
+ * tunnel dials the loopback upstream (issue #1918) can instead turn on
189
+ * trustForwardedProxy: a forwarded request that landed on this machine
190
+ * (loopback socket AND loopback Host) is then admitted on the same browser
191
+ * marker alone. The switch defaults off, so an unconfigured board keeps
192
+ * refusing every forwarded request (issue #1906).
193
+ *
194
+ * A deployment behind a reverse proxy or ingress that DSH itself serves
195
+ * (`--trusted-host`, TLS terminated at the edge) is admitted by the Host's
196
+ * `connection` service instead: a request whose Host/Origin fence and signed
197
+ * browser session it accepts needs no board-specific allowlist, which is why
198
+ * the check runs first when the service is mounted (issue #1930). The fence
199
+ * below stays untouched as the fallback, so a deployment without the service,
200
+ * and every direct client the service does not admit, keeps exactly the
201
+ * pre-existing decision.
149
202
  */
150
203
  export function isTrustedTaskBoardRequest(req: IncomingMessage, access: ResolvedRouteAccess): boolean {
204
+ const connection = access.connection?.()
205
+ if (connection !== undefined && connection.requestRejection(req) === undefined) return true
151
206
  if (!browserSameOriginMarker(req)) return false
152
207
  if (isLoopbackRequest(req)) return true
208
+ // The tunnel makes the socket and the Host describe the proxy, so the
209
+ // origin-equality check of the direct fence has nothing to compare on this
210
+ // path; the explicit cross-site marker is then the one signal that separates
211
+ // the operator's own page from a third-party page posting through the tunnel,
212
+ // and it is refused instead of being read as a mere tripwire.
213
+ if (access.trustForwardedProxy()
214
+ && req.headers['sec-fetch-site'] !== 'cross-site'
215
+ && isForwardedLoopbackRequest(req)) return true
153
216
  if (!isLoopbackAddress(req.socket.remoteAddress)) return false
154
217
  const host = req.headers.host
155
218
  if (typeof host !== 'string') return false
@@ -3,11 +3,12 @@ import type { InvokeRemoteRequest, TypertGateway } from '@deepseek-ai/dsh-api-ga
3
3
  import type { SessionAddress, SessionHistoryRecord, SessionListValue, SessionPage, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/types'
4
4
  import type { CommandResult } from '@deepseek-ai/dsh-commands/types'
5
5
  import type { Workspace } from '@deepseek-ai/dsh-workspace/types'
6
- import { teammateName } from './core/subtask.ts'
7
- import { mostRecentWorkspaceId } from './core/workspace-target.ts'
6
+ import { LIANGSHEN_PRESET_ID } from './core/subtask.ts'
7
+ import { MISSING_WORKSPACE_REASON, mostRecentWorkspaceId } from './core/workspace-target.ts'
8
8
  import { declaredRoute, normalizeReasoningEffort, resolveReasoningEffort, type ReasoningRoute } from './core/reasoning-effort.ts'
9
9
  import type { ModelCatalogView } from './core/verification.ts'
10
- import type { TaskPermission, TaskRecord } from './core/tasks.ts'
10
+ import type { ExecutionSummary, TaskPermission, TaskRecord } from './core/tasks.ts'
11
+ import { executionSummaryOf } from './core/execution-summary.ts'
11
12
 
12
13
  /**
13
14
  * Host services needed to validate a task's workspace before creating a
@@ -169,9 +170,9 @@ export type ExecutionInspection =
169
170
  * forever.
170
171
  */
171
172
  | { outcome: 'pending'; unreadable?: true; reason?: string }
172
- | { outcome: 'succeeded' }
173
- | { outcome: 'failed'; error: string }
174
- | { outcome: 'cancelled'; error: string }
173
+ | { outcome: 'succeeded'; summary?: ExecutionSummary }
174
+ | { outcome: 'failed'; error: string; summary?: ExecutionSummary }
175
+ | { outcome: 'cancelled'; error: string; summary?: ExecutionSummary }
175
176
 
176
177
  /** A post-create launch failure that still identifies the session to the ledger. */
177
178
  export class SessionLaunchError extends Error {
@@ -201,22 +202,24 @@ function escapeProvenanceDelimiter(value: string): string {
201
202
  * first, the provenance wrap then encloses the instruction. Plain tasks (no
202
203
  * freeze) keep the bare handover preamble + prompt.
203
204
  */
204
- /** One other execution member of a run, as named in the launched task's prompt. */
205
- export interface PromptPeer {
206
- /** Task id of the member. */
205
+ /** One unfinished subtask the launched card's own agent has to dispatch. */
206
+ export interface PromptDescendant {
207
+ /** Task id of the subtask card. */
207
208
  id: string
208
- /** Member title. */
209
+ /** Subtask title. */
209
210
  title: string
210
- /** Teammate name when this member runs as a teammate. */
211
- name?: string
211
+ /** Its column, so the run can tell a fresh card from one already failed before. */
212
+ status: string
212
213
  }
213
214
 
214
215
  /** Execution-shape context appended to the launched task's prompt. */
215
216
  export interface PromptContext {
216
- /** The other members this run opens, excluding the launched task itself. */
217
- peers?: readonly PromptPeer[]
218
- /** True when those members run as teammates inside this session (Team Lead). */
219
- team?: boolean
217
+ /**
218
+ * The card's outstanding descendants. Present exactly when this run is an
219
+ * autonomous dispatch: the Host opens no session for them, so this session
220
+ * reads them and dispatches subagents itself.
221
+ */
222
+ descendants?: readonly PromptDescendant[]
220
223
  /**
221
224
  * Scheduled-run provenance: the instant the rule actually fired, its kind,
222
225
  * and the IANA zone its wall clock was read in. Present only for a
@@ -227,19 +230,18 @@ export interface PromptContext {
227
230
  }
228
231
 
229
232
  /**
230
- * The execution-shape section: what else this run opens. A plain cascade opens
231
- * one independent session per member; a team run starts every other member as a
232
- * teammate inside THIS session, so the prompt names the Team tools instead.
233
+ * The dispatch section: this run is the card's own session, and the card still
234
+ * has unfinished subtasks. The Host opens no session for them, so the prompt
235
+ * states what the session must do itself — read each card, dispatch subagents
236
+ * in dependency order, and write the conclusions back before finishing. A card
237
+ * with no outstanding descendant gets no section at all.
233
238
  */
234
- function peerPromptPreamble(context: PromptContext): string | undefined {
235
- const peers = context.peers ?? []
236
- if (peers.length === 0) return undefined
237
- if (context.team === true) {
238
- const lines = peers.map(peer => `- ${escapeProvenanceDelimiter(peer.title)}(teammate: ${peer.name ?? teammateName(peer.title, peer.id, peer.id)})`)
239
- return `本任务是 Agent Team 的 Lead:本次运行不额外开启独立会话,以下 ${peers.length} 个子任务成员已在本会话中作为 teammate 启动。用 list_agents / send_message / wait_agent 协调它们,用任务看板工具读写它们在看板上的卡片:\n${lines.join('\n')}`
240
- }
241
- const lines = peers.map(peer => `- ${escapeProvenanceDelimiter(peer.title)}(任务 ${peer.id})`)
242
- return `本次运行同时并发开启 ${peers.length} 个独立 DSH 会话执行下列子任务成员(可用 task_board_* 工具查看它们的进度):\n${lines.join('\n')}`
239
+ function dispatchPromptPreamble(context: PromptContext): string | undefined {
240
+ const descendants = context.descendants ?? []
241
+ if (descendants.length === 0) return undefined
242
+ const lines = descendants.map(descendant =>
243
+ `- ${escapeProvenanceDelimiter(descendant.title)}(任务 ${descendant.id},状态 ${descendant.status})`)
244
+ return `本卡还有 ${descendants.length} 个未完成的子任务,本次执行不会为它们额外开启会话,由你在本会话内自行派发:\n${lines.join('\n')}\n先用 task_board_get 读取每张子卡的内容与执行目标,再用 subagent 按依赖顺序派发(互不依赖的可以并发),完工前用 task_board_manage({action:'record-external-outcome', result, initiatedBy, summary}) 一次性回填各子卡的结论。`
243
245
  }
244
246
 
245
247
  /**
@@ -278,7 +280,7 @@ export function promptText(task: TaskRecord, context: PromptContext = {}): strin
278
280
  const tagPreamble = tagPromptPreamble(task)
279
281
  const handoverSection = handoverPreamble
280
282
  const schedulePreamble = schedulePromptPreamble(context)
281
- const runPreamble = peerPromptPreamble(context)
283
+ const runPreamble = dispatchPromptPreamble(context)
282
284
  const preambles = [tagPreamble, handoverSection, schedulePreamble, runPreamble]
283
285
  .filter((part): part is string => part !== undefined)
284
286
  const preamble = preambles.length === 0 ? undefined : preambles.join('\n\n')
@@ -434,6 +436,14 @@ export class HostExecutionRunner {
434
436
  async launch(task: TaskRecord, options: {
435
437
  reuseSessionId?: string
436
438
  promptContext?: PromptContext
439
+ /**
440
+ * Agent preset this execution is FORCED under, overriding the card's own
441
+ * `mode` pin (and a handover bundle's): the caller decides it from the run's
442
+ * shape (a card with unfinished subtasks runs as the autonomous dispatcher),
443
+ * and the override is never written into the card. A preset the deployment
444
+ * does not register fails the launch before any session exists.
445
+ */
446
+ agentPreset?: string
437
447
  onSession?: (sessionId: string) => void
438
448
  onGoalArmed?: (armed: boolean) => void
439
449
  /**
@@ -462,9 +472,10 @@ export class HostExecutionRunner {
462
472
  // card that pins nothing is resolved to the deployment's most recently used
463
473
  // workspace instead of being left to `session.create`, whose own fallback is
464
474
  // the Host process working directory (the desktop app's profile directory) —
465
- // never the project the user was in when the card was written.
475
+ // never the project the user was in when the card was written. A deployment
476
+ // with no workspace to offer gets a refusal below, not that fallback.
466
477
  const workspaceId = task.handover?.workspaceId ?? task.workspaceId ?? this.recentWorkspaceId()
467
- const mode = task.handover?.mode ?? task.mode
478
+ const mode = options.agentPreset ?? task.handover?.mode ?? task.mode
468
479
  const permission = task.handover?.permission ?? task.permission
469
480
 
470
481
  if (workspaceId !== undefined && this.workspaceRegistry !== undefined) {
@@ -475,6 +486,14 @@ export class HostExecutionRunner {
475
486
  if (mode !== undefined) {
476
487
  const presets = await this.invoke('agentPresets', 'list', {}) as { presets?: readonly { id: string; broken?: string }[] }
477
488
  const preset = presets.presets?.find(item => item.id === mode)
489
+ // A forced preset is the run's shape, not a stored preference: a
490
+ // deployment that does not serve it (the `liangshen` dispatcher preset is
491
+ // shipped by packages/dsh-liangshen) cannot run this card the way its tree
492
+ // requires, so the run fails closed with the reason readable on the card.
493
+ if (preset === undefined && options.agentPreset !== undefined) {
494
+ throw new Error('agent preset not found: ' + mode + ' (a card with unfinished subtasks runs under the '
495
+ + LIANGSHEN_PRESET_ID + ' preset, which this deployment does not serve)')
496
+ }
478
497
  if (preset === undefined) throw new Error('agent preset not found: ' + mode)
479
498
  if (preset.broken !== undefined) throw new Error('agent preset is unavailable: ' + preset.broken)
480
499
  }
@@ -502,8 +521,15 @@ export class HostExecutionRunner {
502
521
  }
503
522
  return reused
504
523
  }
524
+ // Nothing names a workspace and the deployment has none to resolve to, so
525
+ // there is no place this run may legitimately start: `session.create` would
526
+ // quietly land it in the Host process working directory (the desktop app's
527
+ // profile directory). Refuse before the session exists, with the reason the
528
+ // board settles the card with and the browser renders in the user's
529
+ // language, so the fix (pick a workspace on the card) is what the user reads.
530
+ if (workspaceId === undefined) throw new Error(MISSING_WORKSPACE_REASON)
505
531
  const created = await this.invoke('session', 'create', {
506
- ...(workspaceId === undefined ? {} : { workspaceId }),
532
+ workspaceId,
507
533
  ...(mode === undefined ? {} : { agentPreset: mode }),
508
534
  }) as { sessionId: ExecutionSessionId }
509
535
  const sessionId = created.sessionId
@@ -909,13 +935,20 @@ export class HostExecutionRunner {
909
935
  return { outcome: 'pending' }
910
936
  }
911
937
  this.scanMemos.delete(sessionId)
938
+ // What the run left behind rides the verdict the caller settles with, for a
939
+ // success and a failure alike: the events are in hand here, and no later
940
+ // reader can recover them once the session is gone. A run with no assistant
941
+ // prose carries no field at all, so settling stays a decision about the
942
+ // verdict alone.
943
+ const closing = executionSummaryOf(events.map(entry => entry.event), startedAt)
944
+ const carried = closing === undefined ? {} : { summary: closing }
912
945
  const reason = nonCompletedTurnEnd(turnEnd.event.data)
913
- if (reason === undefined) return await this.goalVerdict(sessionId) ?? { outcome: 'succeeded' }
946
+ if (reason === undefined) return { ...(await this.goalVerdict(sessionId) ?? { outcome: 'succeeded' as const }), ...carried }
914
947
  // `error` keeps its historical wording; every other non-completed reason
915
948
  // (aborted / blocked / max-tokens / interrupted) now reports instead of
916
949
  // silently counting as success.
917
950
  return reason === 'error'
918
- ? { outcome: 'failed', error: 'agent turn ended with an error' }
919
- : { outcome: 'failed', error: 'agent turn ended without completing: ' + reason }
951
+ ? { outcome: 'failed', error: 'agent turn ended with an error', ...carried }
952
+ : { outcome: 'failed', error: 'agent turn ended without completing: ' + reason, ...carried }
920
953
  }
921
954
  }