@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
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Subtask lineage: the depth gate, the ancestry/descendant queries, the
3
- * cascade participant set one run request opens, the deferred settlement of a
4
- * cascade parent, and the execution-target inheritance a subtask resolves at
5
- * run time.
3
+ * outstanding-descendant decision one run request makes, the deferred
4
+ * settlement of a historical run group, and the execution-target inheritance a
5
+ * subtask resolves at run time.
6
6
  *
7
7
  * Framework-free (no cordis, no runtime imports) so every rule is
8
8
  * unit-testable in isolation. The Host ledger is the only authority; the
@@ -75,34 +75,61 @@ export interface ParentLinkCheck {
75
75
  */
76
76
  export declare function checkParentLink(tasks: readonly TaskRecord[], childId: string, parentId: string | null, maxSubtaskDepth: number, lineage?: LineageIndex): ParentLinkCheck;
77
77
  /**
78
- * The tasks one run request opens executions for: the requested task first,
79
- * then its on-board descendants within the configured depth. This is the
80
- * SHAPE of a cascade — every walk that must see the whole tree (settlement,
81
- * archive/restore, the running lock) reads it. The run path filters it with
82
- * {@link joinsCascadeRun}: archived tasks never run, a participant that already
83
- * has an open execution is skipped by the caller, which cannot start it twice,
84
- * and a finished descendant is left alone.
78
+ * The tasks one run request opens executions for: the requested card ALONE.
79
+ *
80
+ * Running a card never expands into its subtask tree. The card's own session
81
+ * reads its subtasks through the board tools and dispatches subagents itself,
82
+ * so a parent run opens exactly one session. Clicking a subtask runs that
83
+ * subtask as its own root, again without expanding its own descendants. The
84
+ * lineage queries around this one answer questions about the tree the card's
85
+ * agent works with (who is still outstanding, what a historical run group
86
+ * still holds open) — never who gets a session from the Host.
87
+ * @param tasks - the ledger.
88
+ * @param rootId - the task the run request named.
89
+ * @returns the one card this run opens an execution for, or [] when unknown.
85
90
  */
86
- export declare function cascadeTargets(tasks: readonly TaskRecord[], rootId: string, maxSubtaskDepth: number): TaskRecord[];
91
+ export declare function cascadeTargets(tasks: readonly TaskRecord[], rootId: string): TaskRecord[];
87
92
  /**
88
- * Whether a cascade member takes part in a new run.
89
- *
90
- * The task the user ran is always a member: the request names that card, and
91
- * the operator asked for it to run whatever its column says. A descendant does
92
- * not join once it sits in the `done` column — its work is finished, so running
93
- * the parent again is a run of the parent, never a second execution of work
94
- * that is already done. The rule keys on the column alone, so it covers both a
95
- * subtask that ran and one an operator moved to done by hand, and it holds for
96
- * every trigger: a manual run, a re-run, and a due occurrence of a schedule.
97
- * A card whose own schedule is enabled settles back into `todo`, so a scheduled
98
- * subtask stays a participant; to make a finished one run again, move it back
99
- * to `todo` or run it on its own.
100
- * @param task - the candidate member.
93
+ * A task together with every descendant within the configured depth: the
94
+ * subtree a lineage gate (archive, restore, force-close) has to walk.
95
+ */
96
+ export declare function subtreeTasks(tasks: readonly TaskRecord[], id: string, maxSubtaskDepth: number): TaskRecord[];
97
+ /**
98
+ * Whether a card still has work outstanding: anything outside the `done`
99
+ * column. It keys on the column alone, so it covers both a subtask that ran
100
+ * and one an operator moved to done by hand.
101
+ */
102
+ export declare function isOutstanding(task: TaskRecord): boolean;
103
+ /**
104
+ * The descendants of a card that still have work outstanding, in breadth-first
105
+ * order: the cards its own session is expected to dispatch. An archived
106
+ * descendant is off the board and cannot be dispatched, so it is not listed.
107
+ */
108
+ export declare function outstandingDescendants(tasks: readonly TaskRecord[], rootId: string, maxSubtaskDepth: number): TaskRecord[];
109
+ /**
110
+ * Whether any descendant of this card still sits outside the `done` column.
111
+ * This is the ONE decision behind both the forced agent preset and the dispatch
112
+ * section of the execution prompt: a card whose tree still holds work runs as
113
+ * the autonomous dispatcher.
114
+ */
115
+ export declare function hasOutstandingDescendants(tasks: readonly TaskRecord[], rootId: string, maxSubtaskDepth: number): boolean;
116
+ /**
117
+ * Agent preset a run with unfinished subtasks is forced under. The id comes
118
+ * from packages/dsh-liangshen (its own `LIANGSHEN_PRESET_ID`); the force is
119
+ * applied at launch and never written into a card's `mode` field.
120
+ */
121
+ export declare const LIANGSHEN_PRESET_ID = "liangshen";
122
+ /**
123
+ * Whether a card belongs to a run's dispatch set: the card the request named,
124
+ * or a card whose work is still outstanding. Kept for the browser's subtask
125
+ * preview; the Host run itself opens the clicked card alone
126
+ * ({@link cascadeTargets}).
127
+ * @param task - the candidate card.
101
128
  * @param rootId - the task the run request named.
102
- * @returns false when this member is left alone by the run.
129
+ * @returns false when this card is finished and left alone.
103
130
  */
104
131
  export declare function joinsCascadeRun(task: TaskRecord, rootId: string): boolean;
105
- /** One still-open execution belonging to a cascade run group. */
132
+ /** One still-open execution belonging to a stored run group. */
106
133
  export interface OpenCascadeChild {
107
134
  taskId: string;
108
135
  execution: ExecutionRecord;
@@ -111,14 +138,15 @@ export interface OpenCascadeChild {
111
138
  export declare function openGroupExecution(task: TaskRecord, runGroupId: string): ExecutionRecord | undefined;
112
139
  /**
113
140
  * The direct subtasks of parentTaskId whose execution in this run group is
114
- * still open: the parent remaining waiters. The parent may settle once this
115
- * list is empty and its own outcome is known.
141
+ * still open: the parent's remaining waiters. A stored multi-member group (a
142
+ * run the Host opened before it stopped spreading one run across a subtree)
143
+ * folds once this list is empty and the parent's own outcome is known.
116
144
  */
117
145
  export declare function pendingCascadeChildren(tasks: readonly TaskRecord[], parentTaskId: string, runGroupId: string): OpenCascadeChild[];
118
146
  /**
119
- * Fold a cascade parent own outcome and its children outcomes into one
120
- * verdict: failure dominates, then cancellation, then success. The error text
121
- * is the first failure, falling back to the first cancellation.
147
+ * Fold a stored run-group parent's own outcome and its children's outcomes into
148
+ * one verdict: failure dominates, then cancellation, then success. The error
149
+ * text is the first failure, falling back to the first cancellation.
122
150
  */
123
151
  export declare function combineCascadeOutcome(entries: readonly {
124
152
  result: ExecutionOutcome;
@@ -142,22 +170,4 @@ export declare function effectiveTaskPermission(task: TaskRecord): TaskRecord['p
142
170
  * elevated card is runnable while a subtask's own unconfirmed binding stays
143
171
  * gated.
144
172
  */
145
- /**
146
- * The immutable teammate name for one team-mode member. Teammate names are
147
- * lower-kebab-case and must stay unique for the lifetime of the Team: the
148
- * run-group token separates two runs of the same tree, and the member
149
- * discriminator separates two members of one run that reduce to the same slug.
150
- *
151
- * The discriminator is not cosmetic. A title with no ASCII word characters (a
152
- * CJK title, for example) carries no slug at all, so every such title of one
153
- * run group collides on the generic prefix; Agent Teams answers every member
154
- * after the first with `teammate name "..." was already used in this Team`,
155
- * and those subtasks never start. Two ASCII titles that share a slug
156
- * (`AI 强度预测` next to `AI 配比优化`) collide the same way.
157
- * @param title - the member task's title.
158
- * @param token - the run group id (the task id when no group is recorded).
159
- * @param memberId - the member task's id, which makes the name unique in the run.
160
- * @returns the teammate name handed to the Agent Teams service.
161
- */
162
- export declare function teammateName(title: string, token: string, memberId?: string): string;
163
173
  export declare function resolveExecutionTargets(task: TaskRecord, tasks: readonly TaskRecord[], maxSubtaskDepth?: number): TaskRecord;
@@ -12,6 +12,27 @@ import { type TaskBoardExtensionPayload } from './extension.ts';
12
12
  export type TaskStatus = 'backlog' | 'todo' | 'running' | 'done' | 'failed';
13
13
  /** Settled outcome of one execution attempt. */
14
14
  export type ExecutionOutcome = 'succeeded' | 'failed' | 'cancelled';
15
+ /**
16
+ * What one execution left behind: the text of the run's last assistant message
17
+ * and the session event it was read from.
18
+ *
19
+ * The board records a verdict per execution but no output, so a parent card
20
+ * could see that a subtask succeeded without seeing what it produced. Card
21
+ * content cannot answer that (it is the plan and freezes at the first
22
+ * execution), so the closing text rides the execution record instead.
23
+ */
24
+ export interface ExecutionSummary {
25
+ /** Last assistant message text of the run, bounded by {@link EXECUTION_SUMMARY_LIMIT}. */
26
+ text: string;
27
+ /** Seq of the session event that text came from; absent text has no seq either. */
28
+ seq: number;
29
+ }
30
+ /**
31
+ * Upper bound of one recorded summary, in characters. The ledger stores a
32
+ * conclusion, not a transcript: a reader that needs the whole message follows
33
+ * {@link ExecutionSummary.seq} into the session history.
34
+ */
35
+ export declare const EXECUTION_SUMMARY_LIMIT = 4000;
15
36
  /**
16
37
  * One real execution attempt: the run's own id, the dsh session that ran it
17
38
  * (filled once the session is created), and the settled outcome once the
@@ -69,6 +90,16 @@ export interface ExecutionRecord {
69
90
  ownResult?: ExecutionOutcome;
70
91
  /** Human failure text that arrived with {@link ownResult}. */
71
92
  ownError?: string;
93
+ /**
94
+ * What this run left behind: the text of its last assistant message, taken
95
+ * when the settlement read the session and recorded with the verdict.
96
+ *
97
+ * Absent — never an empty string — when the session could not be read or
98
+ * carried no assistant prose, so "recorded nothing" stays distinguishable
99
+ * from "produced nothing". Settling never fails over it: a summary is
100
+ * informational, and every field above is what the board decides with.
101
+ */
102
+ summary?: ExecutionSummary;
72
103
  /**
73
104
  * Goal acceptance state of this execution (task-board goal verification).
74
105
  * Fixed when the execution starts and never rewritten from later settings:
@@ -343,12 +374,11 @@ export interface TaskRecord {
343
374
  */
344
375
  reuseSession?: boolean;
345
376
  /**
346
- * Run this task's subtree as an Agent Team instead of one Host-launched
347
- * session per participant: the root becomes the Team Lead session and the
348
- * Host spawns one teammate for each direct subtask inside it. Absent or false
349
- * keeps the plain concurrent cascade. A deployment that does not serve the
350
- * Agent Teams service refuses a team run instead of silently falling back,
351
- * and a subtask's own permission pin cannot be honored in this mode.
377
+ * Historical Agent Team opt-in. New runs never write it and the Host never
378
+ * reads it to decide how to run: a run with unfinished subtasks opens one
379
+ * session whose own agent dispatches subagents. The field is kept so cards
380
+ * already on disk keep their record, and so the ledger can still fold a team
381
+ * run group it opened before this behavior changed.
352
382
  */
353
383
  teamRun?: boolean;
354
384
  /**
@@ -467,8 +497,6 @@ export interface NewTaskInput {
467
497
  applyCardDefaults?: boolean;
468
498
  /** Reuse the previous execution's session for later runs (issue #1419). */
469
499
  reuseSession?: boolean;
470
- /** Run the subtree as an Agent Team (Team Lead session plus one teammate per direct subtask). */
471
- teamRun?: boolean;
472
500
  /**
473
501
  * Start the execution with dsh's built-in `/goal`. Absent means the default
474
502
  * (one plain turn); only an explicit true joins the goal run.
@@ -615,6 +643,6 @@ export declare function settledStatus(task: TaskRecord, outcome: ExecutionOutcom
615
643
  * matching column. No-op (returns the input task) when the execution is not
616
644
  * the task's latest or is already settled.
617
645
  */
618
- export declare function settleExecution(task: TaskRecord, executionId: string, outcome: ExecutionOutcome, now: number, error: string | undefined): TaskRecord;
646
+ export declare function settleExecution(task: TaskRecord, executionId: string, outcome: ExecutionOutcome, now: number, error: string | undefined, summary?: ExecutionSummary): TaskRecord;
619
647
  /** A settled-execution summary string for the detail view. */
620
648
  export declare function executionLabel(execution: ExecutionRecord): string;
@@ -15,7 +15,7 @@ import type { TaskHandoverInput } from '../handover.ts';
15
15
  * Editable fields on a task (the update patch surface). `freeze` replaces the
16
16
  * continuation-card snapshot (restamping frozenAt); an explicit null clears it.
17
17
  */
18
- export type TaskUpdatePatch = Partial<Pick<TaskRecord, 'title' | 'description' | 'prompt' | 'workspaceId' | 'mode' | 'permission' | 'model' | 'reasoningEffort' | 'reuseSession' | 'teamRun' | 'goalRun' | 'skipVerification'>> & {
18
+ export type TaskUpdatePatch = Partial<Pick<TaskRecord, 'title' | 'description' | 'prompt' | 'workspaceId' | 'mode' | 'permission' | 'model' | 'reasoningEffort' | 'reuseSession' | 'goalRun' | 'skipVerification'>> & {
19
19
  freeze?: FreezeSnapshot & {
20
20
  redacted?: boolean;
21
21
  } | null;
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Workspace targeting for cards that pin none.
3
3
  *
4
- * The Host answers two questions here instead of leaving them to
4
+ * The Host answers three questions here instead of leaving them to
5
5
  * `session.create`, whose own fallback is the Host process working directory
6
6
  * (the desktop app's profile directory): which workspace a root card inherits
7
- * from the session that created it, and which workspace an unpinned run lands
8
- * in when nothing could be inherited.
7
+ * from the session that created it, which workspace an unpinned run lands in
8
+ * when nothing could be inherited, and — when neither names one — the refusal
9
+ * that stops the run instead of landing it there.
9
10
  *
10
11
  * Structural types only — the Host's `Workspace` entity satisfies them — so the
11
12
  * browser program compiles this module without importing an SDK value.
@@ -39,3 +40,22 @@ export declare function workspaceOwningSession(items: readonly WorkspaceCandidat
39
40
  * @returns the most recently used workspace id, or undefined when there is none.
40
41
  */
41
42
  export declare function mostRecentWorkspaceId(items: readonly WorkspaceCandidate[]): string | undefined;
43
+ /**
44
+ * The failure text the Host records when a card names no workspace and the
45
+ * deployment has none to resolve it to: the run is refused before any session
46
+ * exists instead of letting `session.create` fall back to the Host process
47
+ * working directory (the desktop app's profile directory), which is never the
48
+ * project the user meant.
49
+ *
50
+ * A finished sentence rather than a code: the ledger stores it as the
51
+ * execution's failure text, which the agent tools serve to a model and which
52
+ * any client prints verbatim. It names the fix, not the mechanism.
53
+ */
54
+ export declare const MISSING_WORKSPACE_REASON = "this card pins no workspace; choose a workspace on the card before running";
55
+ /**
56
+ * Whether a recorded failure text is the missing-workspace refusal, which the
57
+ * browser half renders in the reader's own language.
58
+ * @param reason - the execution's recorded failure text.
59
+ * @returns true when that run was refused for naming no workspace.
60
+ */
61
+ export declare function isMissingWorkspaceReason(reason: string): boolean;
@@ -1,19 +1,18 @@
1
1
  /**
2
2
  * Admission control for the session-creating half of a run.
3
3
  *
4
- * One board action can open a whole subtree, and a team run hands every member
5
- * of it to the Lead at once. Both paths used to fire every launch in the same
6
- * tick, so the Host asked DSH for N sessions at once — the burst the repository's
7
- * measured guidance caps at three heavy implementation subagents
8
- * (docs/multi-agent-resources.md), with no mechanism enforcing it.
4
+ * A run opens one session, so the burst this bounds is several runs starting at
5
+ * once — several cards run from different tabs, or a due schedule firing while
6
+ * a manual run is still launching. Unbounded, the Host asks DSH for N sessions
7
+ * in the same tick: the burst the repository's measured guidance caps at three
8
+ * heavy implementation subagents (docs/multi-agent-resources.md), with no
9
+ * mechanism enforcing it.
9
10
  *
10
11
  * The queue is SERVICE-wide, not per run group: the pressure it bounds is the
11
12
  * machine's (the Host process's memory and the swap it drives), and two run
12
13
  * groups opened from two tabs share one Host. Admission is round-robin across
13
- * run groups — FIFO inside a group, so a group's first run (the Lead, which
14
- * carries the run shape and the teammate namespace) always starts before its
15
- * members — so a large subtree cannot starve a run opened after it, and no
16
- * entry can be starved.
14
+ * run groups — FIFO inside a group — so one run cannot starve another opened
15
+ * after it, and no entry can be starved.
17
16
  *
18
17
  * The width is read through a live callback, so a settings edit takes effect on
19
18
  * the next admission without remounting anything.
@@ -1,4 +1,4 @@
1
- import { type ExecutionOutcome, type ExecutionRecord, type ScheduleMode, type TaskRecord } from './core/tasks.ts';
1
+ import { type ExecutionOutcome, type ExecutionRecord, type ExecutionSummary, type ScheduleMode, type TaskRecord } from './core/tasks.ts';
2
2
  import type { CardDefaults } from './core/card-defaults.ts';
3
3
  import { type TaskBoardAction, type TaskBoardSchedulerSnapshot } from './protocol.ts';
4
4
  import { type ExecutionVerification } from './core/verification.ts';
@@ -11,14 +11,13 @@ export interface LedgerState {
11
11
  export interface OpenedRun {
12
12
  task: TaskRecord;
13
13
  execution: ExecutionRecord;
14
- /**
15
- * How the Host obtains this run's session. Absent or `session` launches a
16
- * fresh (or reused) execution session; `teammate` means the run belongs to a
17
- * team-mode cascade, where the Host asks the root's Lead session to spawn a
18
- * teammate instead of launching a session of its own.
19
- */
20
- dispatch?: 'session' | 'teammate';
21
14
  }
15
+ /**
16
+ * Prefix of the `initiatedBy` an inherited descendant verdict carries. The Host
17
+ * recorded it on the run card's behalf (see `inheritVerdictForDescendants`), not
18
+ * an outside agent that reported its own work.
19
+ */
20
+ export declare const PARENT_RUN_INITIATOR_PREFIX = "parent-run:";
22
21
  /** Minimal value copy used by the Host session monitor. */
23
22
  export interface OpenExecutionReference {
24
23
  readonly taskId: string;
@@ -52,7 +51,7 @@ export interface LedgerRuntimeView {
52
51
  * Session ids of every open execution, including the ones
53
52
  * {@link openExecutions} skips because their own outcome is already
54
53
  * recorded. A caller that asks whether the board still observes any session
55
- * must use this list: a deferred cascade parent is settled by its members,
54
+ * must use this list: a stored run-group parent is settled by its members,
56
55
  * but it is still an open execution.
57
56
  */
58
57
  readonly openSessionIds: readonly string[];
@@ -96,7 +95,7 @@ export declare function win32StartTimeMs(pid: number, probe?: PowerShellProbe):
96
95
  * missing, cyclic, or names an archived parent while the child is on board is
97
96
  * dropped (the task becomes a root) instead of dropping the task. A chain
98
97
  * deeper than the current `maxSubtaskDepth` is deliberately KEPT: the limit
99
- * gates new links, it never deletes a stored one, and every cascade walk is
98
+ * gates new links, it never deletes a stored one, and every lineage walk is
100
99
  * bounded by the limit anyway. The Host is the only writer of these links, so
101
100
  * this is a last-resort guard against a hand-edited or imported document.
102
101
  */
@@ -128,10 +127,20 @@ export declare class HostTaskLedger {
128
127
  private depthLimit;
129
128
  /** Live reader of the deployment's new-card defaults (a volatile config read). */
130
129
  private readonly cardDefaults;
130
+ /**
131
+ * Live reader of the daily token cap (0 = no gate). The scheduled path asks it
132
+ * per due occurrence, so a cap raised after a skipped occurrence admits the
133
+ * next one without a restart.
134
+ */
135
+ private readonly spendBudget;
136
+ /** Today's measured spend in tokens, or undefined when nothing can be measured. */
137
+ private readonly spendUsed;
131
138
  constructor(dir?: string, now?: () => number, options?: {
132
139
  sessionDefaultPermission?: TaskPermission | (() => TaskPermission);
133
140
  maxSubtaskDepth?: number;
134
141
  cardDefaults?: () => CardDefaults;
142
+ spendBudgetTokens?: () => number;
143
+ spendUsedToday?: (now: number) => number | undefined;
135
144
  });
136
145
  /** Current subtask depth limit (1..3). */
137
146
  get maxSubtaskDepth(): number;
@@ -175,10 +184,10 @@ export declare class HostTaskLedger {
175
184
  runs?: OpenedRun[];
176
185
  };
177
186
  /**
178
- * Open the cascade one due schedule triggers: an empty array means nothing
179
- * ran (already running, or a participant whose elevated permission is still
180
- * unconfirmed, a one-shot whose instant was missed, or an exhausted budget),
181
- * and the rule's own state says which.
187
+ * Open the one run a due schedule triggers: an empty array means nothing ran
188
+ * (already running, a card whose elevated permission is still unconfirmed, a
189
+ * one-shot whose instant was missed, or an exhausted budget), and the rule's
190
+ * own state says which.
182
191
  *
183
192
  * The run budget is enforced HERE, inside the single ledger writer: a rule
184
193
  * whose counter already reached its cap is stopped instead of opened, so no
@@ -188,6 +197,14 @@ export declare class HostTaskLedger {
188
197
  * @returns the executions this occurrence opened.
189
198
  */
190
199
  openScheduled(taskId: string, triggeredAt: number): OpenedRun[];
200
+ /**
201
+ * Why a due occurrence may not open a run because the day already spent the
202
+ * cap, or undefined when it may. A cap of 0 — the default — answers before the
203
+ * measurement is read, so a board with no gate reads no ledger file.
204
+ * @param now - clock instant (ms epoch).
205
+ * @returns the refusal message, when the cap is reached.
206
+ */
207
+ private spendRefusal;
191
208
  /**
192
209
  * Record a due occurrence that opened no execution: roll a recurring rule to
193
210
  * its next occurrence (budget untouched), or stop it when there is none. A
@@ -201,8 +218,8 @@ export declare class HostTaskLedger {
201
218
  * failed without creating a session (see
202
219
  * {@link applyScheduleRefund}). Called by the service on the failed-launch
203
220
  * path only; a manual run and a launch that did reach a session are never
204
- * refunded. A no-op for a task with no rule, so a failed cascade member does
205
- * not touch anything.
221
+ * refunded. A no-op for a task with no rule, so a failed run does not touch
222
+ * anything.
206
223
  * @param taskId - the task whose occurrence is being refunded.
207
224
  * @param now - clock instant (ms epoch).
208
225
  */
@@ -219,12 +236,46 @@ export declare class HostTaskLedger {
219
236
  skipMissed(now: number): void;
220
237
  setScheduler(patch: Partial<TaskBoardSchedulerSnapshot>): void;
221
238
  /**
222
- * Settle one execution. A cascade participant first records its OWN outcome
223
- * and only finalizes once every child execution in its run group has
224
- * settled, so a parent card leaves 'running' with the whole tree's verdict
225
- * rather than its own turn alone.
239
+ * Settle one execution. A NEW run is a single-member group, so it settles on
240
+ * its own turn. A run group the Host opened before it stopped spreading one
241
+ * run across a subtree is folded here instead: a stored participant records
242
+ * its OWN outcome and only finalizes once every child execution in its group
243
+ * has settled, so a parent card leaves 'running' with the whole group's
244
+ * verdict rather than its own turn alone.
245
+ *
246
+ * `summary` is what the run left behind (see `ExecutionSummary`), passed in
247
+ * by whichever reader observed the session. It is informational: a caller
248
+ * without one settles exactly as before, and a settlement never waits on it.
226
249
  */
227
- settle(taskId: string, executionId: string, outcome: ExecutionOutcome, error?: string): void;
250
+ settle(taskId: string, executionId: string, outcome: ExecutionOutcome, error?: string, summary?: ExecutionSummary): void;
251
+ /**
252
+ * Record the run's verdict on the outstanding descendants its root was asked
253
+ * to dispatch.
254
+ *
255
+ * A card with unfinished subtasks runs as an autonomous dispatcher: its
256
+ * session reads the subtasks, dispatches them with subagents, and is asked to
257
+ * write their conclusions back with
258
+ * `task_board_manage({action:'record-external-outcome'})` before it finishes.
259
+ * A run that never wrote one back would leave those cards parked with no
260
+ * record of what the parent decided about them, so once the RUN CARD's
261
+ * execution reached a decisive terminal record, every outstanding descendant
262
+ * this run opened no execution for inherits that verdict as an external
263
+ * record.
264
+ *
265
+ * Idempotent by construction: a card that already carries an execution in
266
+ * this run group (the fold owns it), an open execution (it is running on its
267
+ * own), or a terminal record stamped after this run started (the dispatching
268
+ * agent's own backfill, or an earlier pass of this one) is left alone. Only a
269
+ * decisive verdict is inherited: a cancelled run judged nothing about the
270
+ * subtasks, and a subtask already in the done column has nothing left to
271
+ * inherit.
272
+ * @param taskId - the card whose execution just settled.
273
+ * @param executionId - that execution.
274
+ * @param groupId - its run group.
275
+ * @param now - clock instant (ms epoch).
276
+ * @returns whether the document changed.
277
+ */
278
+ private inheritVerdictForDescendants;
228
279
  attachSession(taskId: string, executionId: string, sessionId: string): void;
229
280
  allTasks(): readonly TaskRecord[];
230
281
  getTask(id: string): TaskRecord | undefined;
@@ -241,47 +292,41 @@ export declare class HostTaskLedger {
241
292
  /**
242
293
  * The binding that makes a run illegal, if any.
243
294
  *
244
- * A plain cascade launches one session per participant, so every participant
245
- * carries its own resolved binding and each one gates the run. A team run
246
- * launches only the Lead session: the Lead's binding gates it, and a
247
- * teammate inherits that session's permission, so a subtask's OWN pin is
248
- * refused exactly when the Lead session does not already carry it — the
249
- * teammate could never be given that authority, and dropping the pin
250
- * silently would misreport the work (an inherited binding is the Lead's own
251
- * and stays allowed once the Lead is confirmed).
295
+ * Only the card being run gets a session, so only ITS resolved binding gates
296
+ * the run: a subtask's own elevated permission is that subtask's gate when the
297
+ * subtask is run, and no longer blocks its parent from running.
252
298
  * @param root - the task being run.
253
299
  * @returns the first refusal, or undefined when the run may start.
254
300
  */
255
301
  private bindingRefusal;
256
- /**
257
- * The tasks a cascade from `rootId` would actually open executions for, with
258
- * their effective execution targets resolved. Archived members never run, and
259
- * a member that already has an open execution is skipped (a task cannot run
260
- * twice), so the result is the participant set the launch will use.
261
- */
262
- private cascadeParticipants;
263
302
  /** Whether a task or any of its subtasks still has an open execution. */
264
303
  private subtreeHasOpenExecution;
304
+ /** The descendants of a card that still hold work, as the launch prompt names them. */
305
+ outstandingDescendants(taskId: string): TaskRecord[];
306
+ /** Whether a card still has a subtask outside the done column. */
307
+ hasOutstandingDescendants(taskId: string): boolean;
265
308
  /**
266
- * Open one execution per cascade participant that still has work (the
267
- * requested task and its on-board descendants, within the depth limit) under
268
- * a single run group, and commit the ledger once. A descendant in 'done' is
269
- * not a participant ({@link joinsCascadeRun}). The returned runs are ordered
270
- * root-first, so the Host launches the parent before its subtasks.
309
+ * Open ONE execution for the requested card, under a fresh run group, and
310
+ * commit the ledger once. The group stays single-member on purpose: a run
311
+ * never opens a session for a subtask (that card's own agent dispatches
312
+ * subagents inside this session), and the group id is what later lets the
313
+ * settlement fold a HISTORICAL multi-member group it opened before this
314
+ * behavior changed.
271
315
  * @param root - the task the user ran.
272
316
  * @param now - clock instant (ms epoch).
273
317
  * @param initiator - the DSH session that asked for the run (audit only).
274
318
  * @param rerun - true to reset the root to 'todo' before starting it.
275
319
  * @param progress - when set, this run was a due occurrence and the root's
276
320
  * rule is advanced (counter, next target, stop/skip record) in the same
277
- * atomic commit that opened the executions.
321
+ * atomic commit that opened the execution.
278
322
  */
279
- private startCascade;
323
+ private startRun;
280
324
  /**
281
- * Finalize every cascade parent that is ready, walking from `taskId` up the
282
- * lineage: a member settles once its own outcome is recorded and none of its
283
- * group children is still open, and its verdict folds those children in
284
- * (failure dominates, then cancellation).
325
+ * Finalize every stored run-group parent that is ready, walking from `taskId`
326
+ * up the lineage: a member settles once its own outcome is recorded and none
327
+ * of its group children is still open, and its verdict folds those children in
328
+ * (failure dominates, then cancellation). A single-member group — every run
329
+ * this Host opens now — settles on its own turn exactly as any plain run does.
285
330
  */
286
331
  private settleCascade;
287
332
  /**
@@ -289,11 +334,12 @@ export declare class HostTaskLedger {
289
334
  * members are all settled. The Host poll calls this on every tick, so a run
290
335
  * can no longer be left in the running column by a settle nobody observed:
291
336
  *
292
- * - A team run is governed by its Lead. Once the Lead's own outcome is
337
+ * - A stored team run is governed by its Lead. Once the Lead's own outcome is
293
338
  * recorded, its still-open members are settled with that verdict. A
294
339
  * teammate is a durable member of the Team and may never report a turn of
295
- * its own, and without this the whole lineage waits on it forever.
296
- * - A cascade parent whose members are all settled is finalized here even
340
+ * its own, and without this the whole lineage waits on it forever. New runs
341
+ * never start a team, so this only closes a group the ledger already holds.
342
+ * - A stored group parent whose members are all settled is finalized here even
297
343
  * when the settle that completed the tree happened in another process, or
298
344
  * was interrupted between its child write and its parent write.
299
345
  *
@@ -4,10 +4,41 @@ import type { TaskBoardHostService } from './host-service.ts';
4
4
  import { type TaskBoardParseDraft, type TaskBoardParseRequest } from './protocol.ts';
5
5
  /** Header replaced by an authenticated same-host reverse proxy. */
6
6
  export declare const TASK_BOARD_PROXY_TOKEN_HEADER = "x-dsh-task-board-proxy-token";
7
+ /**
8
+ * The composition's Host connection service, narrowed to the one check the
9
+ * board bridges: `requestRejection` runs the Host/Origin fence and verifies
10
+ * the authority-bound `dsh-auth-*` browser session minted by the Host. It
11
+ * answers `undefined` only for a request it admits and 401/403 otherwise.
12
+ * Declared structurally, like the official open-in-app routes do, because the
13
+ * service's package is a browser-side dependency this Host half does not
14
+ * import.
15
+ */
16
+ export interface TaskBoardConnectionTrust {
17
+ requestRejection(request: {
18
+ readonly headers: IncomingMessage['headers'];
19
+ }): 401 | 403 | undefined;
20
+ }
7
21
  /** Optional authenticated reverse-proxy access layered over the loopback default. */
8
22
  export interface TaskBoardRouteAccess {
9
23
  trustedProxyHosts?: readonly string[];
10
24
  proxyToken?: string;
25
+ /**
26
+ /**
27
+ * Whether the operator's own reverse proxy or tunnel may speak for the
28
+ * browser: a forwarded request that landed on this machine's loopback
29
+ * upstream then counts as trustable, still behind the browser same-origin
30
+ * marker. Read at each request (hence the function), so the settings switch
31
+ * binds the next request without re-registering the routes. Absent or false
32
+ * keeps the pre-existing fence exactly as it was (issue #1906).
33
+ */
34
+ trustForwardedProxy?: () => boolean;
35
+ /**
36
+ * Resolves the Host's `connection` service when a request arrives, so a
37
+ * deployment that mounts it after these routes still gains the bridge and a
38
+ * composition that never mounts it keeps the pre-existing fence. Absent means
39
+ * no bridge (issue #1930).
40
+ */
41
+ connection?: () => TaskBoardConnectionTrust | undefined;
11
42
  }
12
43
  /**
13
44
  * Host faces the routes need beyond the ledger service. The parse face is
@@ -21,6 +52,8 @@ export interface TaskBoardRouteOptions {
21
52
  interface ResolvedRouteAccess {
22
53
  trustedProxyHosts: ReadonlySet<string>;
23
54
  proxyToken?: string;
55
+ trustForwardedProxy: () => boolean;
56
+ connection?: () => TaskBoardConnectionTrust | undefined;
24
57
  }
25
58
  /**
26
59
  * Task-board route fence. Direct desktop access uses the repository-wide
@@ -30,6 +63,22 @@ interface ResolvedRouteAccess {
30
63
  * tripwire, the socket/Host/origin-equality checks carry the authority).
31
64
  * Authenticated proxies must be explicitly allowlisted and replace the
32
65
  * internal token header after their own authentication step.
66
+ *
67
+ * A third party's proxy cannot inject that token, so a deployment whose own
68
+ * tunnel dials the loopback upstream (issue #1918) can instead turn on
69
+ * trustForwardedProxy: a forwarded request that landed on this machine
70
+ * (loopback socket AND loopback Host) is then admitted on the same browser
71
+ * marker alone. The switch defaults off, so an unconfigured board keeps
72
+ * refusing every forwarded request (issue #1906).
73
+ *
74
+ * A deployment behind a reverse proxy or ingress that DSH itself serves
75
+ * (`--trusted-host`, TLS terminated at the edge) is admitted by the Host's
76
+ * `connection` service instead: a request whose Host/Origin fence and signed
77
+ * browser session it accepts needs no board-specific allowlist, which is why
78
+ * the check runs first when the service is mounted (issue #1930). The fence
79
+ * below stays untouched as the fallback, so a deployment without the service,
80
+ * and every direct client the service does not admit, keeps exactly the
81
+ * pre-existing decision.
33
82
  */
34
83
  export declare function isTrustedTaskBoardRequest(req: IncomingMessage, access: ResolvedRouteAccess): boolean;
35
84
  export declare function makeTaskBoardRoutes(service: TaskBoardHostService, access?: TaskBoardRouteAccess, options?: TaskBoardRouteOptions): WebRoute[];