@fish-under-sea/dsh-client-ui-task-board-fish 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.en.md +4 -4
- package/README.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +4428 -1508
- package/lib/client.js.map +1 -1
- package/lib/index.js +2670 -496
- package/lib/types/client/CardDefaultPresetField.d.ts +35 -0
- package/lib/types/client/PluginSettingsCard.d.ts +130 -19
- package/lib/types/client/RangeBubble.d.ts +46 -0
- package/lib/types/client/SegmentGroup.d.ts +28 -0
- package/lib/types/client/TaskBoardSettingsCard.d.ts +63 -0
- package/lib/types/client/board/AttachmentField.d.ts +70 -0
- package/lib/types/client/board/ExecutionLog.d.ts +24 -0
- package/lib/types/client/board/ReasoningEffortField.d.ts +25 -0
- package/lib/types/client/board/TaskForm.d.ts +4 -0
- package/lib/types/client/board/VerificationReport.d.ts +2 -15
- package/lib/types/client/board/model-options.d.ts +87 -0
- package/lib/types/client/board/preset-label.d.ts +21 -0
- package/lib/types/client/board/preset-roster.d.ts +45 -0
- package/lib/types/client/board/source-group.d.ts +27 -0
- package/lib/types/client/body-mutations.d.ts +45 -0
- package/lib/types/client/host-api.d.ts +25 -0
- package/lib/types/client/locales.d.ts +87 -9
- package/lib/types/client/pending-verify.d.ts +47 -0
- package/lib/types/client/plugin-card-seat.d.ts +3 -1
- package/lib/types/client/service.d.ts +4 -1
- package/lib/types/client/settings-form.d.ts +73 -51
- package/lib/types/core/attachment.d.ts +132 -0
- package/lib/types/core/card-defaults.d.ts +78 -0
- package/lib/types/core/controller.d.ts +57 -8
- package/lib/types/core/execution-summary.d.ts +52 -0
- package/lib/types/core/extension.d.ts +116 -0
- package/lib/types/core/launch-width.d.ts +31 -0
- package/lib/types/core/reasoning-effort.d.ts +57 -0
- package/lib/types/core/session-reuse.d.ts +7 -1
- package/lib/types/core/spend-budget.d.ts +28 -0
- package/lib/types/core/subtask.d.ts +100 -37
- package/lib/types/core/tasks.d.ts +94 -10
- package/lib/types/core/use-cases/task-create.d.ts +10 -5
- package/lib/types/core/use-cases/task-tag.d.ts +36 -0
- package/lib/types/core/use-cases/task-update.d.ts +22 -1
- package/lib/types/core/wire-projection.d.ts +35 -0
- package/lib/types/core/workspace-target.d.ts +23 -3
- package/lib/types/host/attachments.d.ts +250 -0
- package/lib/types/host/extension-registry.d.ts +40 -0
- package/lib/types/host/launch-admission.d.ts +71 -0
- package/lib/types/host-ledger.d.ts +114 -47
- package/lib/types/host-routes.d.ts +63 -0
- package/lib/types/host-runner.d.ts +164 -18
- package/lib/types/host-service.d.ts +182 -46
- package/lib/types/host-spend.d.ts +52 -0
- package/lib/types/index.d.ts +173 -54
- package/lib/types/loopback.d.ts +41 -1
- package/lib/types/protocol.d.ts +52 -11
- package/lib/types/tool-surface.d.ts +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +35 -28
- package/src/client/CardDefaultPresetField.tsx +101 -0
- package/src/client/PluginSettingsCard.tsx +385 -111
- package/src/client/RangeBubble.tsx +164 -0
- package/src/client/SegmentGroup.tsx +93 -0
- package/src/client/TaskBoardSettingsCard.tsx +332 -37
- package/src/client/board/AttachmentField.tsx +383 -0
- package/src/client/board/EditTaskModal.tsx +63 -0
- package/src/client/board/ExecutionLog.tsx +154 -0
- package/src/client/board/LinkSubtaskModal.tsx +1 -1
- package/src/client/board/NewTaskModal.tsx +154 -45
- package/src/client/board/ReasoningEffortField.tsx +50 -0
- package/src/client/board/TagManagerModal.tsx +151 -2
- package/src/client/board/TaskBoard.tsx +47 -10
- package/src/client/board/TaskCard.tsx +45 -23
- package/src/client/board/TaskDetail.tsx +468 -258
- package/src/client/board/TaskForm.tsx +19 -4
- package/src/client/board/VerificationReport.tsx +143 -104
- package/src/client/board/model-options.ts +208 -0
- package/src/client/board/preset-label.ts +32 -0
- package/src/client/board/preset-roster.ts +58 -0
- package/src/client/board/source-group.ts +94 -0
- package/src/client/board/task-markdown.module.css +11 -8
- package/src/client/board-settings.module.css +35 -7
- package/src/client/board.module.css +1044 -105
- package/src/client/body-mutations.ts +133 -0
- package/src/client/host-api.ts +70 -0
- package/src/client/index.ts +109 -95
- package/src/client/locales.ts +205 -48
- package/src/client/pending-verify.ts +90 -0
- package/src/client/plugin-card-seat.ts +8 -2
- package/src/client/service.ts +24 -0
- package/src/client/settings-card.module.css +466 -89
- package/src/client/settings-entry-form.ts +0 -1
- package/src/client/settings-form.ts +102 -60
- package/src/core/attachment.ts +287 -0
- package/src/core/card-defaults.ts +132 -0
- package/src/core/controller.ts +90 -11
- package/src/core/execution-summary.ts +96 -0
- package/src/core/extension.ts +120 -0
- package/src/core/launch-width.ts +38 -0
- package/src/core/reasoning-effort.ts +92 -0
- package/src/core/session-reuse.ts +7 -1
- package/src/core/spend-budget.ts +35 -0
- package/src/core/store.ts +19 -1
- package/src/core/subtask.ts +144 -68
- package/src/core/tasks.ts +117 -10
- package/src/core/use-cases/task-create.ts +27 -16
- package/src/core/use-cases/task-tag.ts +56 -0
- package/src/core/use-cases/task-update.ts +33 -5
- package/src/core/wire-projection.ts +81 -0
- package/src/core/workspace-target.ts +27 -3
- package/src/host/agent-tools.ts +33 -21
- package/src/host/attachments.ts +650 -0
- package/src/host/extension-registry.ts +150 -5
- package/src/host/launch-admission.ts +139 -0
- package/src/host-ledger.ts +248 -117
- package/src/host-routes.ts +233 -15
- package/src/host-runner.ts +395 -61
- package/src/host-service.ts +512 -139
- package/src/host-spend.ts +105 -0
- package/src/index.ts +312 -92
- package/src/loopback.ts +57 -1
- package/src/protocol.ts +83 -18
- package/src/tool-surface.ts +1 -0
package/lib/index.js
CHANGED
|
@@ -1,13 +1,183 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
|
-
import {
|
|
3
|
-
import { createHash, timingSafeEqual } from "node:crypto";
|
|
4
|
-
import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { accessSync, chmodSync, closeSync, constants, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
3
|
import { dirname, isAbsolute, join, win32 } from "node:path";
|
|
6
4
|
import { homedir } from "node:os";
|
|
7
5
|
import { isAbsolute as isAbsolute$1, join as join$1 } from "node:path/posix";
|
|
6
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
7
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
8
|
+
import { Context } from "@deepseek-ai/cordis";
|
|
8
9
|
import { ReasoningEffortId, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
9
10
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
10
11
|
/**
|
|
12
|
+
* Clamp a configured width into the supported range. A value the schema would
|
|
13
|
+
* refuse (non-finite, below the floor, above the ceiling) still leaves the
|
|
14
|
+
* board launching: an out-of-range setting never stalls a run.
|
|
15
|
+
* @param width - configured width, or undefined for the default.
|
|
16
|
+
* @returns the effective width.
|
|
17
|
+
*/
|
|
18
|
+
function normalizeRunLaunchWidth(width) {
|
|
19
|
+
if (width === void 0 || !Number.isFinite(width)) return 3;
|
|
20
|
+
return Math.min(Math.max(Math.trunc(width), 1), 16);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/core/spend-budget.ts
|
|
24
|
+
/**
|
|
25
|
+
* Whether a day's measured spend already reached the cap.
|
|
26
|
+
* @param usedTokens - tokens the day's spend measurement reported.
|
|
27
|
+
* @param cap - the configured cap, 0 for "no gate".
|
|
28
|
+
* @returns true when a run must be refused.
|
|
29
|
+
*/
|
|
30
|
+
function spendCapReached(usedTokens, cap) {
|
|
31
|
+
return cap > 0 && usedTokens >= cap;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The refusal text both gates report: the thrown message a client sees as
|
|
35
|
+
* board-refused, and the scheduler error a due occurrence records.
|
|
36
|
+
* @param usedTokens - tokens the day's spend measurement reported.
|
|
37
|
+
* @param cap - the configured cap.
|
|
38
|
+
* @returns the refusal message.
|
|
39
|
+
*/
|
|
40
|
+
function spendCapMessage(usedTokens, cap) {
|
|
41
|
+
return `spend cap reached: ${usedTokens} tokens of ${cap} today; raise the cap in the task board settings`;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/dsh-home.ts
|
|
45
|
+
/**
|
|
46
|
+
* DSH_HOME resolution shared by the plugin family's Host halves: the
|
|
47
|
+
* environment override wins, the platform home fallback follows. Mirrors
|
|
48
|
+
* what dsh-pet and dsh-liangshen each used to implement locally.
|
|
49
|
+
*/
|
|
50
|
+
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
51
|
+
function expandHome(path, home = homedir()) {
|
|
52
|
+
const j = home.startsWith("/") ? join$1 : join;
|
|
53
|
+
if (path === "~") return home;
|
|
54
|
+
if (path.startsWith("~/") || path.startsWith("~\\")) return j(home, path.slice(2));
|
|
55
|
+
return path;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolve the DSH home directory.
|
|
59
|
+
* @param env - process environment to read DSH_HOME from.
|
|
60
|
+
* @param home - platform home directory fallback (test seam).
|
|
61
|
+
* @returns the absolute DSH home path.
|
|
62
|
+
*/
|
|
63
|
+
function resolveDshHome(env = process.env, home = homedir()) {
|
|
64
|
+
const isPosix = home.startsWith("/");
|
|
65
|
+
const j = isPosix ? join$1 : join;
|
|
66
|
+
const isAbs = isPosix ? isAbsolute$1 : isAbsolute;
|
|
67
|
+
const raw = env.DSH_HOME;
|
|
68
|
+
if (raw !== void 0 && raw.trim() !== "") {
|
|
69
|
+
const expanded = expandHome(raw.trim(), home);
|
|
70
|
+
return isAbs(expanded) ? expanded : j(process.cwd(), expanded);
|
|
71
|
+
}
|
|
72
|
+
return j(home, ".dsh");
|
|
73
|
+
}
|
|
74
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
75
|
+
function dshHome() {
|
|
76
|
+
return resolveDshHome();
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/host-spend.ts
|
|
80
|
+
/**
|
|
81
|
+
* Today's measured spend, read from the usage ledger this deployment keeps at
|
|
82
|
+
* `$DSH_HOME/dsh-usage/usage-ledger.json`.
|
|
83
|
+
*
|
|
84
|
+
* The measure is the family usage ledger rather than a counter this plugin
|
|
85
|
+
* accumulates from `session/event`, for two reasons. The ledger is durable, so
|
|
86
|
+
* a cap cannot be reset by restarting the Host (the Loader remounts a row on
|
|
87
|
+
* any config change, and a spend counter that lived only in memory would forget
|
|
88
|
+
* the day). And a second fold of the same events inside the board would have to
|
|
89
|
+
* persist its own totals to be worth anything, which means a second writer of
|
|
90
|
+
* spend state in one process.
|
|
91
|
+
*
|
|
92
|
+
* What that costs: the file belongs to the dsh-usage plugin, so a deployment
|
|
93
|
+
* that does not mount it keeps no ledger and the cap cannot measure anything.
|
|
94
|
+
* That case is reported once per process and the gate then refuses nothing —
|
|
95
|
+
* wedging the board because a sibling plugin is absent would be worse than a
|
|
96
|
+
* cap that says it cannot see. The 3 s flush debounce of that plugin is the
|
|
97
|
+
* other cost: the reading trails the busiest moments by at most one debounce.
|
|
98
|
+
* @module @fish-under-sea/dsh-client-ui-task-board-fish/host-spend
|
|
99
|
+
*/
|
|
100
|
+
/**
|
|
101
|
+
* The token fields one ledger bucket totals. Billed input is uncached input
|
|
102
|
+
* plus both cache buckets; output already includes reasoning, so reasoning is
|
|
103
|
+
* deliberately not added again — the sum is the one the usage panel shows.
|
|
104
|
+
*/
|
|
105
|
+
const TOKEN_FIELDS = [
|
|
106
|
+
"inputTokens",
|
|
107
|
+
"outputTokens",
|
|
108
|
+
"cacheReadTokens",
|
|
109
|
+
"cacheWriteTokens"
|
|
110
|
+
];
|
|
111
|
+
/** Reported at most once per process: an unmeasurable cap is a startup fact, not a per-run one. */
|
|
112
|
+
let reportedUnmeasurable = false;
|
|
113
|
+
/**
|
|
114
|
+
* Local-date key (`YYYY-MM-DD`) of an instant, the bucketing the usage ledger
|
|
115
|
+
* itself uses: the cap and the usage panel therefore roll over at the same
|
|
116
|
+
* local midnight.
|
|
117
|
+
* @param ms - clock instant (ms epoch).
|
|
118
|
+
* @returns the day key.
|
|
119
|
+
*/
|
|
120
|
+
function spendDateKey(ms) {
|
|
121
|
+
const date = new Date(ms);
|
|
122
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
123
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
124
|
+
return `${date.getFullYear()}-${month}-${day}`;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Total tokens one ledger day recorded, across every provider and model of that
|
|
128
|
+
* day. Anything that is not a finite token count contributes 0, so a ledger
|
|
129
|
+
* written by another version degrades to a smaller reading instead of NaN.
|
|
130
|
+
* @param day - one day bucket as the ledger stores it, when it is one.
|
|
131
|
+
* @returns the day's token total.
|
|
132
|
+
*/
|
|
133
|
+
function ledgerDayTokens(day) {
|
|
134
|
+
if (typeof day !== "object" || day === null) return 0;
|
|
135
|
+
let total = 0;
|
|
136
|
+
for (const models of Object.values(day)) {
|
|
137
|
+
if (typeof models !== "object" || models === null) continue;
|
|
138
|
+
for (const bucket of Object.values(models)) {
|
|
139
|
+
if (typeof bucket !== "object" || bucket === null) continue;
|
|
140
|
+
for (const field of TOKEN_FIELDS) {
|
|
141
|
+
const value = bucket[field];
|
|
142
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) total += value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return total;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Path of the usage ledger for this DSH home.
|
|
150
|
+
* @returns the absolute ledger path.
|
|
151
|
+
*/
|
|
152
|
+
function spendLedgerPath() {
|
|
153
|
+
return join(dshHome(), "dsh-usage", "usage-ledger.json");
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Tokens already spent today, or undefined when no measurement is available.
|
|
157
|
+
*
|
|
158
|
+
* Undefined is "cannot see", not "spent nothing": the caller fails open and
|
|
159
|
+
* reports it, because a spend cap that cannot read its own source must never
|
|
160
|
+
* decide that no work may run.
|
|
161
|
+
* @param now - clock instant (ms epoch).
|
|
162
|
+
* @param path - ledger path (test seam).
|
|
163
|
+
* @returns today's token total, or undefined when the ledger is unreadable.
|
|
164
|
+
*/
|
|
165
|
+
function usedTokensToday(now = Date.now(), path = spendLedgerPath()) {
|
|
166
|
+
try {
|
|
167
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
168
|
+
const days = typeof parsed === "object" && parsed !== null ? parsed.days : void 0;
|
|
169
|
+
if (typeof days !== "object" || days === null) return void 0;
|
|
170
|
+
return ledgerDayTokens(days[spendDateKey(now)]);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
if (!reportedUnmeasurable) {
|
|
173
|
+
reportedUnmeasurable = true;
|
|
174
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
175
|
+
console.warn(`[dsh-task-board] spend cap cannot be measured from ${path}: ${detail}; runs are not gated until that ledger is readable`);
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
11
181
|
* Clamp a configured cadence into the supported range. A value the schema
|
|
12
182
|
* would refuse (non-finite, below the floor, above the ceiling) still leaves
|
|
13
183
|
* the board polling: an out-of-range setting never disables the timer.
|
|
@@ -43,10 +213,15 @@ function sessionPollMs(seconds) {
|
|
|
43
213
|
* @param task - the task about to run.
|
|
44
214
|
* @param idleSessionIds - ids the last roster saw as present and not running;
|
|
45
215
|
* undefined when that roster is unknown.
|
|
216
|
+
* @param options.force - continue the settled session regardless of the card's
|
|
217
|
+
* own `reuseSession` opt-in. A rework is exactly that case: the reviewer read
|
|
218
|
+
* the previous run's session and sent it back. Every condition above still
|
|
219
|
+
* applies — the force waives the opt-in, never the evidence.
|
|
46
220
|
* @returns the session id to continue in, or undefined for a fresh session.
|
|
47
221
|
*/
|
|
48
|
-
function reusableSessionId(task, idleSessionIds) {
|
|
49
|
-
if (
|
|
222
|
+
function reusableSessionId(task, idleSessionIds, options = {}) {
|
|
223
|
+
if (options.force !== true && task.reuseSession !== true) return void 0;
|
|
224
|
+
if (idleSessionIds === void 0) return void 0;
|
|
50
225
|
let last;
|
|
51
226
|
for (let index = task.executions.length - 1; index >= 0; index -= 1) {
|
|
52
227
|
const candidate = task.executions[index];
|
|
@@ -59,40 +234,91 @@ function reusableSessionId(task, idleSessionIds) {
|
|
|
59
234
|
return idleSessionIds.has(last.sessionId) ? last.sessionId : void 0;
|
|
60
235
|
}
|
|
61
236
|
//#endregion
|
|
62
|
-
//#region src/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
237
|
+
//#region src/host/launch-admission.ts
|
|
238
|
+
var LaunchAdmissionQueue = class {
|
|
239
|
+
width;
|
|
240
|
+
/** Waiting launches per run group, in arrival order. */
|
|
241
|
+
waiting = /* @__PURE__ */ new Map();
|
|
242
|
+
/** Run groups in round-robin order. */
|
|
243
|
+
rotation = [];
|
|
244
|
+
/** Slot holders of the launches in flight, one per admitted launch. */
|
|
245
|
+
inFlight = /* @__PURE__ */ new Set();
|
|
246
|
+
/** Highest number of launches in flight at once; observability and tests. */
|
|
247
|
+
peakInFlight = 0;
|
|
248
|
+
/**
|
|
249
|
+
* @param width - live admission width (already normalized by the caller).
|
|
250
|
+
*/
|
|
251
|
+
constructor(width) {
|
|
252
|
+
this.width = width;
|
|
253
|
+
}
|
|
254
|
+
/** Launches the queue has not admitted yet. */
|
|
255
|
+
get pendingCount() {
|
|
256
|
+
let total = 0;
|
|
257
|
+
for (const queue of this.waiting.values()) total += queue.length;
|
|
258
|
+
return total;
|
|
259
|
+
}
|
|
260
|
+
/** Launches currently holding a slot. */
|
|
261
|
+
get inFlightCount() {
|
|
262
|
+
return this.inFlight.size;
|
|
263
|
+
}
|
|
264
|
+
/** Admit one launch, immediately if a slot is free. */
|
|
265
|
+
enqueue(launch) {
|
|
266
|
+
const queue = this.waiting.get(launch.groupId);
|
|
267
|
+
if (queue === void 0) {
|
|
268
|
+
this.waiting.set(launch.groupId, [launch]);
|
|
269
|
+
this.rotation.push(launch.groupId);
|
|
270
|
+
} else queue.push(launch);
|
|
271
|
+
this.pump();
|
|
89
272
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
273
|
+
/**
|
|
274
|
+
* Abandon every waiting launch: the queue is being torn down, so an entry
|
|
275
|
+
* that never started can never start. Launches already in flight are left
|
|
276
|
+
* alone — their session may already exist, and the callers that own them
|
|
277
|
+
* settle them through the normal path.
|
|
278
|
+
* @returns the abandoned launches, in abandonment order.
|
|
279
|
+
*/
|
|
280
|
+
drain() {
|
|
281
|
+
const abandoned = [];
|
|
282
|
+
for (const groupId of this.rotation) for (const launch of this.waiting.get(groupId) ?? []) abandoned.push(launch);
|
|
283
|
+
this.rotation = [];
|
|
284
|
+
this.waiting.clear();
|
|
285
|
+
for (const launch of abandoned) launch.abandon();
|
|
286
|
+
return abandoned;
|
|
287
|
+
}
|
|
288
|
+
pump() {
|
|
289
|
+
while (this.inFlight.size < this.width()) {
|
|
290
|
+
const launch = this.takeNext();
|
|
291
|
+
if (launch === void 0) return;
|
|
292
|
+
this.admit(launch);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/** The next launch by round-robin across groups and FIFO inside one. */
|
|
296
|
+
takeNext() {
|
|
297
|
+
while (this.rotation.length > 0) {
|
|
298
|
+
const groupId = this.rotation.shift();
|
|
299
|
+
if (groupId === void 0) return void 0;
|
|
300
|
+
const queue = this.waiting.get(groupId);
|
|
301
|
+
if (queue === void 0 || queue.length === 0) {
|
|
302
|
+
this.waiting.delete(groupId);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const launch = queue.shift();
|
|
306
|
+
if (launch === void 0) continue;
|
|
307
|
+
if (queue.length === 0) this.waiting.delete(groupId);
|
|
308
|
+
else this.rotation.push(groupId);
|
|
309
|
+
return launch;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
admit(launch) {
|
|
313
|
+
const release = () => {
|
|
314
|
+
this.inFlight.delete(release);
|
|
315
|
+
this.pump();
|
|
316
|
+
};
|
|
317
|
+
this.inFlight.add(release);
|
|
318
|
+
if (this.inFlight.size > this.peakInFlight) this.peakInFlight = this.inFlight.size;
|
|
319
|
+
Promise.resolve().then(() => launch.start()).catch(() => {}).then(release);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
96
322
|
//#endregion
|
|
97
323
|
//#region src/core/schedule.ts
|
|
98
324
|
/** Inclusive ranges per field, in cron order. */
|
|
@@ -380,6 +606,13 @@ const TASK_BOARD_SERVICE_NAME = "taskBoard";
|
|
|
380
606
|
* channel.
|
|
381
607
|
*/
|
|
382
608
|
const TASK_BOARD_PAYLOAD_LIMIT_BYTES = 64 * 1024;
|
|
609
|
+
/**
|
|
610
|
+
* Largest accepted free text a provider pushes into an execution, in
|
|
611
|
+
* characters: one follow-up message, or one set of rework instructions. Both
|
|
612
|
+
* reach a model as user input, so the bound keeps a single provider call from
|
|
613
|
+
* becoming an unbounded context injection.
|
|
614
|
+
*/
|
|
615
|
+
const TASK_BOARD_MESSAGE_MAX_LENGTH = 4e3;
|
|
383
616
|
/** Depth beyond which a payload is refused instead of walked. */
|
|
384
617
|
const PAYLOAD_DEPTH_LIMIT = 64;
|
|
385
618
|
/** Whether a value is a plain JSON value (no undefined, function, symbol, bigint or cycle). */
|
|
@@ -444,6 +677,215 @@ function normalizeTaskIntegrations(value) {
|
|
|
444
677
|
}
|
|
445
678
|
return Object.keys(result).length === 0 ? void 0 : result;
|
|
446
679
|
}
|
|
680
|
+
/** Maximum byte length of one attachment (10 MiB). */
|
|
681
|
+
const TASK_ATTACHMENT_MAX_BYTES = 10 * 1024 * 1024;
|
|
682
|
+
/** Maximum byte length of all attachments of one card together (32 MiB). */
|
|
683
|
+
const TASK_ATTACHMENT_TOTAL_MAX_BYTES = 32 * 1024 * 1024;
|
|
684
|
+
/** Raster media types the official image path accepts. */
|
|
685
|
+
const TASK_ATTACHMENT_IMAGE_MEDIA_TYPES = [
|
|
686
|
+
"image/png",
|
|
687
|
+
"image/jpeg",
|
|
688
|
+
"image/webp",
|
|
689
|
+
"image/gif"
|
|
690
|
+
];
|
|
691
|
+
/** Longest accepted display name of an attachment. */
|
|
692
|
+
const ATTACHMENT_NAME_MAX_LENGTH = 255;
|
|
693
|
+
/** Longest accepted media type of an attachment. */
|
|
694
|
+
const ATTACHMENT_MEDIA_TYPE_MAX_LENGTH = 255;
|
|
695
|
+
/** Longest accepted storage identifier of an attachment. */
|
|
696
|
+
const ATTACHMENT_ID_MAX_LENGTH = 512;
|
|
697
|
+
const SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
698
|
+
const MEDIA_TYPE_PATTERN = /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/;
|
|
699
|
+
/** Every key one attachment may carry. */
|
|
700
|
+
const ATTACHMENT_KEYS = [
|
|
701
|
+
"kind",
|
|
702
|
+
"attachmentId",
|
|
703
|
+
"name",
|
|
704
|
+
"bytes",
|
|
705
|
+
"mediaType",
|
|
706
|
+
"sha256",
|
|
707
|
+
"width",
|
|
708
|
+
"height"
|
|
709
|
+
];
|
|
710
|
+
function isPlainObject(value) {
|
|
711
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
712
|
+
}
|
|
713
|
+
/** Whether a value is a well-formed positive pixel count. */
|
|
714
|
+
function isPixelCount(value) {
|
|
715
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* The canonical display name of an attachment.
|
|
719
|
+
*
|
|
720
|
+
* A name reaches the ledger from two directions: the browser picks it, and an
|
|
721
|
+
* execution prompt reads it. Both make one form mandatory — the name must be
|
|
722
|
+
* a single line without any path part, so it can neither break out of the
|
|
723
|
+
* prompt line nor point at a directory.
|
|
724
|
+
*
|
|
725
|
+
* The canonical form is therefore: the LEAF of whatever path-like text was
|
|
726
|
+
* offered, every control character (a newline included) turned into a space,
|
|
727
|
+
* whitespace runs collapsed into one space, the result trimmed and bounded.
|
|
728
|
+
* An empty result becomes a fixed placeholder.
|
|
729
|
+
*
|
|
730
|
+
* The Host upload path canonicalizes the name BEFORE publishing it, and the
|
|
731
|
+
* wire gate accepts only a name that already IS canonical — so the name the
|
|
732
|
+
* ledger holds and the name the storage holds are the same string.
|
|
733
|
+
* @param value - the offered name.
|
|
734
|
+
* @returns the canonical name.
|
|
735
|
+
*/
|
|
736
|
+
function canonicalAttachmentName(value) {
|
|
737
|
+
const cleaned = ((typeof value === "string" ? value : "").split(/[\\/]/).pop() ?? "").replace(/[\u0000-\u001f\u007f]/g, " ").replace(/\s+/g, " ").trim();
|
|
738
|
+
if (cleaned === "") return "attachment";
|
|
739
|
+
return cleaned.slice(0, ATTACHMENT_NAME_MAX_LENGTH);
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* Whether an unknown value is a well-formed attachment (the STRICT gate: the
|
|
743
|
+
* wire path uses it, so a hand-written payload cannot smuggle an extra field
|
|
744
|
+
* onto the ledger, a path-like name, or an image without its pixel size).
|
|
745
|
+
* @param value - the candidate attachment.
|
|
746
|
+
* @returns whether the value is a usable attachment.
|
|
747
|
+
*/
|
|
748
|
+
function isTaskAttachment(value) {
|
|
749
|
+
if (!isPlainObject(value)) return false;
|
|
750
|
+
if (Object.keys(value).some((key) => !ATTACHMENT_KEYS.includes(key))) return false;
|
|
751
|
+
if (value.kind !== "image" && value.kind !== "file") return false;
|
|
752
|
+
if (typeof value.attachmentId !== "string") return false;
|
|
753
|
+
const id = value.attachmentId;
|
|
754
|
+
if (id === "" || id.length > ATTACHMENT_ID_MAX_LENGTH) return false;
|
|
755
|
+
if (id.includes("/") || id.includes("\\") || id.includes("..")) return false;
|
|
756
|
+
if (typeof value.name !== "string") return false;
|
|
757
|
+
if (value.name !== canonicalAttachmentName(value.name)) return false;
|
|
758
|
+
if (typeof value.bytes !== "number" || !Number.isInteger(value.bytes) || value.bytes < 0) return false;
|
|
759
|
+
if (typeof value.mediaType !== "string" || value.mediaType.length > ATTACHMENT_MEDIA_TYPE_MAX_LENGTH) return false;
|
|
760
|
+
if (!MEDIA_TYPE_PATTERN.test(value.mediaType)) return false;
|
|
761
|
+
if (value.mediaType !== value.mediaType.toLowerCase()) return false;
|
|
762
|
+
if (typeof value.sha256 !== "string" || !SHA256_PATTERN.test(value.sha256)) return false;
|
|
763
|
+
if (value.kind === "image") {
|
|
764
|
+
if (!TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(value.mediaType.toLowerCase())) return false;
|
|
765
|
+
if (!isPixelCount(value.width) || !isPixelCount(value.height)) return false;
|
|
766
|
+
} else if (value.width !== void 0 || value.height !== void 0) return false;
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Repair one persisted attachment entry: canonicalize its name and keep the
|
|
771
|
+
* fields that are usable. An entry that cannot be repaired — an unknown kind,
|
|
772
|
+
* a malformed identifier, an image without its pixel size — is dropped.
|
|
773
|
+
* @param value - the persisted entry.
|
|
774
|
+
* @returns the repaired attachment, or undefined when it cannot be repaired.
|
|
775
|
+
*/
|
|
776
|
+
function repairAttachment(value) {
|
|
777
|
+
if (!isPlainObject(value)) return void 0;
|
|
778
|
+
if (value.kind !== "image" && value.kind !== "file") return void 0;
|
|
779
|
+
if (typeof value.attachmentId !== "string") return void 0;
|
|
780
|
+
const id = value.attachmentId;
|
|
781
|
+
if (id === "" || id.length > ATTACHMENT_ID_MAX_LENGTH) return void 0;
|
|
782
|
+
if (id.includes("/") || id.includes("\\") || id.includes("..")) return void 0;
|
|
783
|
+
if (typeof value.bytes !== "number" || !Number.isInteger(value.bytes) || value.bytes < 0) return void 0;
|
|
784
|
+
if (typeof value.mediaType !== "string" || !MEDIA_TYPE_PATTERN.test(value.mediaType)) return void 0;
|
|
785
|
+
if (typeof value.sha256 !== "string" || !SHA256_PATTERN.test(value.sha256)) return void 0;
|
|
786
|
+
const name = canonicalAttachmentName(value.name);
|
|
787
|
+
if (value.kind === "image") {
|
|
788
|
+
if (!TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(value.mediaType.toLowerCase())) return void 0;
|
|
789
|
+
if (!isPixelCount(value.width) || !isPixelCount(value.height)) return void 0;
|
|
790
|
+
return {
|
|
791
|
+
kind: "image",
|
|
792
|
+
attachmentId: id,
|
|
793
|
+
name,
|
|
794
|
+
bytes: value.bytes,
|
|
795
|
+
mediaType: value.mediaType.toLowerCase(),
|
|
796
|
+
sha256: value.sha256,
|
|
797
|
+
width: value.width,
|
|
798
|
+
height: value.height
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
if (value.width !== void 0 || value.height !== void 0) return void 0;
|
|
802
|
+
return {
|
|
803
|
+
kind: "file",
|
|
804
|
+
attachmentId: id,
|
|
805
|
+
name,
|
|
806
|
+
bytes: value.bytes,
|
|
807
|
+
mediaType: value.mediaType.toLowerCase(),
|
|
808
|
+
sha256: value.sha256
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Whether a list satisfies the card-wide attachment limits: the count, the
|
|
813
|
+
* per-item byte cap, and the total byte cap.
|
|
814
|
+
* @param attachments - the candidate list.
|
|
815
|
+
* @returns whether the list fits every limit.
|
|
816
|
+
*/
|
|
817
|
+
function attachmentsWithinLimits(attachments) {
|
|
818
|
+
if (attachments.length > 8) return false;
|
|
819
|
+
let total = 0;
|
|
820
|
+
for (const attachment of attachments) {
|
|
821
|
+
if (attachment.bytes > 10485760) return false;
|
|
822
|
+
total += attachment.bytes;
|
|
823
|
+
}
|
|
824
|
+
return total <= TASK_ATTACHMENT_TOTAL_MAX_BYTES;
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Whether an unknown value is a well-formed attachment LIST (the strict wire
|
|
828
|
+
* gate). The list must be non-empty: clearing attachments is expressed by
|
|
829
|
+
* omitting the field (create) or by an explicit null (update), never by an
|
|
830
|
+
* empty array. A list that repeats one storage identifier is refused: one
|
|
831
|
+
* object cannot be claimed twice.
|
|
832
|
+
* @param value - the candidate list.
|
|
833
|
+
* @returns whether the list may reach the ledger.
|
|
834
|
+
*/
|
|
835
|
+
function isTaskAttachmentList(value) {
|
|
836
|
+
if (!Array.isArray(value)) return false;
|
|
837
|
+
if (value.length === 0 || value.length > 8) return false;
|
|
838
|
+
if (!value.every(isTaskAttachment)) return false;
|
|
839
|
+
const list = value;
|
|
840
|
+
if (new Set(list.map((attachment) => attachment.attachmentId)).size !== list.length) return false;
|
|
841
|
+
return attachmentsWithinLimits(list);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Repair a persisted attachment list: canonicalize the names, drop the
|
|
845
|
+
* entries that cannot be repaired, deduplicate the storage identifiers, and
|
|
846
|
+
* cap the count and the byte totals. Returns undefined when nothing usable
|
|
847
|
+
* remains, so the caller clears the field instead of storing an empty list —
|
|
848
|
+
* the same policy the tag and schedule repairs follow.
|
|
849
|
+
* @param value - the persisted value.
|
|
850
|
+
* @returns the repaired list, or undefined when nothing survives.
|
|
851
|
+
*/
|
|
852
|
+
function normalizeAttachments(value) {
|
|
853
|
+
if (!Array.isArray(value)) return void 0;
|
|
854
|
+
const repaired = [];
|
|
855
|
+
const seen = /* @__PURE__ */ new Set();
|
|
856
|
+
let total = 0;
|
|
857
|
+
for (const entry of value) {
|
|
858
|
+
const attachment = repairAttachment(entry);
|
|
859
|
+
if (attachment === void 0) continue;
|
|
860
|
+
if (attachment.bytes > 10485760) continue;
|
|
861
|
+
if (total + attachment.bytes > 33554432) continue;
|
|
862
|
+
if (seen.has(attachment.attachmentId)) continue;
|
|
863
|
+
seen.add(attachment.attachmentId);
|
|
864
|
+
total += attachment.bytes;
|
|
865
|
+
repaired.push(attachment);
|
|
866
|
+
if (repaired.length >= 8) break;
|
|
867
|
+
}
|
|
868
|
+
return repaired.length === 0 ? void 0 : repaired;
|
|
869
|
+
}
|
|
870
|
+
//#endregion
|
|
871
|
+
//#region src/core/tasks.ts
|
|
872
|
+
/**
|
|
873
|
+
* Upper bound of one recorded summary, in characters. The ledger stores a
|
|
874
|
+
* conclusion, not a transcript: a reader that needs the whole message follows
|
|
875
|
+
* {@link ExecutionSummary.seq} into the session history.
|
|
876
|
+
*/
|
|
877
|
+
const EXECUTION_SUMMARY_LIMIT = 4e3;
|
|
878
|
+
/**
|
|
879
|
+
* Repair a persisted rework block: only a non-blank instruction string
|
|
880
|
+
* survives, so a hand-edited ledger loses the block instead of the execution.
|
|
881
|
+
*/
|
|
882
|
+
function normalizeExecutionRework(value) {
|
|
883
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
884
|
+
const instructions = value.instructions;
|
|
885
|
+
if (typeof instructions !== "string") return void 0;
|
|
886
|
+
const trimmed = instructions.trim();
|
|
887
|
+
return trimmed === "" ? void 0 : { instructions: trimmed };
|
|
888
|
+
}
|
|
447
889
|
/**
|
|
448
890
|
* Trim an execution list to at most {@link EXECUTION_HISTORY_LIMIT} records,
|
|
449
891
|
* most recent last. A running (unsettled) execution is never trimmed: the
|
|
@@ -645,6 +1087,7 @@ function freezeOf(input, now) {
|
|
|
645
1087
|
function createTask(input, now, id) {
|
|
646
1088
|
const tags = normalizeTags(input.tags);
|
|
647
1089
|
const integrations = normalizeTaskIntegrations(input.integrations);
|
|
1090
|
+
const attachments = normalizeAttachments(input.attachments);
|
|
648
1091
|
return {
|
|
649
1092
|
id,
|
|
650
1093
|
title: input.title.trim(),
|
|
@@ -659,8 +1102,8 @@ function createTask(input, now, id) {
|
|
|
659
1102
|
mode: normalizeTargetId(input.mode),
|
|
660
1103
|
permission: isTaskPermission(input.permission) ? input.permission : void 0,
|
|
661
1104
|
model: normalizeTargetId(input.model),
|
|
1105
|
+
reasoningEffort: normalizeTargetId(input.reasoningEffort),
|
|
662
1106
|
reuseSession: input.reuseSession === true ? true : void 0,
|
|
663
|
-
teamRun: input.teamRun === true ? true : void 0,
|
|
664
1107
|
goalRun: input.goalRun === true ? true : void 0,
|
|
665
1108
|
skipVerification: input.skipVerification === true ? true : void 0,
|
|
666
1109
|
...input.freeze === void 0 ? {} : { freeze: freezeOf(input.freeze, now) },
|
|
@@ -670,6 +1113,7 @@ function createTask(input, now, id) {
|
|
|
670
1113
|
} },
|
|
671
1114
|
...tags === void 0 ? {} : { tags },
|
|
672
1115
|
...integrations === void 0 ? {} : { integrations },
|
|
1116
|
+
...attachments === void 0 ? {} : { attachments },
|
|
673
1117
|
...input.hidden === true ? { hidden: true } : {}
|
|
674
1118
|
};
|
|
675
1119
|
}
|
|
@@ -733,8 +1177,10 @@ function withSchedule(task, patch, now) {
|
|
|
733
1177
|
* running execution record. Returns the new task and the new execution.
|
|
734
1178
|
* @param runGroupId - cascade run group, when this run also opened executions
|
|
735
1179
|
* for the task's subtasks (see `core/subtask.ts`).
|
|
1180
|
+
* @param rework - the reviewer's instructions, when this run is a rework of the
|
|
1181
|
+
* card's previous work; recorded on the execution it opens.
|
|
736
1182
|
*/
|
|
737
|
-
function startExecution(task, now, executionId, initiatedBy, runGroupId) {
|
|
1183
|
+
function startExecution(task, now, executionId, initiatedBy, runGroupId, rework) {
|
|
738
1184
|
const execution = {
|
|
739
1185
|
id: executionId,
|
|
740
1186
|
sessionId: void 0,
|
|
@@ -742,6 +1188,7 @@ function startExecution(task, now, executionId, initiatedBy, runGroupId) {
|
|
|
742
1188
|
endedAt: void 0,
|
|
743
1189
|
result: void 0,
|
|
744
1190
|
error: void 0,
|
|
1191
|
+
...rework === void 0 ? {} : { rework },
|
|
745
1192
|
...runGroupId === void 0 || runGroupId === "" ? {} : { runGroupId },
|
|
746
1193
|
...initiatedBy === void 0 || initiatedBy === "" ? {} : { initiatedBy },
|
|
747
1194
|
...task.freeze === void 0 ? {} : {
|
|
@@ -778,7 +1225,7 @@ function settledStatus(task, outcome) {
|
|
|
778
1225
|
* matching column. No-op (returns the input task) when the execution is not
|
|
779
1226
|
* the task's latest or is already settled.
|
|
780
1227
|
*/
|
|
781
|
-
function settleExecution(task, executionId, outcome, now, error) {
|
|
1228
|
+
function settleExecution(task, executionId, outcome, now, error, summary) {
|
|
782
1229
|
const index = task.executions.findIndex((execution) => execution.id === executionId);
|
|
783
1230
|
if (index === -1) return task;
|
|
784
1231
|
const execution = task.executions[index];
|
|
@@ -787,7 +1234,8 @@ function settleExecution(task, executionId, outcome, now, error) {
|
|
|
787
1234
|
...execution,
|
|
788
1235
|
endedAt: now,
|
|
789
1236
|
result: outcome,
|
|
790
|
-
error
|
|
1237
|
+
error,
|
|
1238
|
+
...summary === void 0 ? {} : { summary }
|
|
791
1239
|
};
|
|
792
1240
|
const executions = [...task.executions];
|
|
793
1241
|
executions[index] = settled;
|
|
@@ -920,24 +1368,95 @@ function checkParentLink(tasks, childId, parentId, maxSubtaskDepth, lineage) {
|
|
|
920
1368
|
return { ok: true };
|
|
921
1369
|
}
|
|
922
1370
|
/**
|
|
923
|
-
* The tasks one run request opens executions for: the requested
|
|
924
|
-
*
|
|
925
|
-
*
|
|
926
|
-
* the
|
|
927
|
-
|
|
928
|
-
|
|
1371
|
+
* The tasks one run request opens executions for: the requested card ALONE.
|
|
1372
|
+
*
|
|
1373
|
+
* Running a card never expands into its subtask tree. The card's own session
|
|
1374
|
+
* reads its subtasks through the board tools and dispatches subagents itself,
|
|
1375
|
+
* so a parent run opens exactly one session. Clicking a subtask runs that
|
|
1376
|
+
* subtask as its own root, again without expanding its own descendants. The
|
|
1377
|
+
* lineage queries around this one answer questions about the tree the card's
|
|
1378
|
+
* agent works with (who is still outstanding, what a historical run group
|
|
1379
|
+
* still holds open) — never who gets a session from the Host.
|
|
1380
|
+
* @param tasks - the ledger.
|
|
1381
|
+
* @param rootId - the task the run request named.
|
|
1382
|
+
* @returns the one card this run opens an execution for, or [] when unknown.
|
|
1383
|
+
*/
|
|
1384
|
+
function cascadeTargets(tasks, rootId) {
|
|
929
1385
|
const root = tasks.find((task) => task.id === rootId);
|
|
930
|
-
|
|
931
|
-
|
|
1386
|
+
return root === void 0 ? [] : [root];
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* A task together with every descendant within the configured depth: the
|
|
1390
|
+
* subtree a lineage gate (archive, restore, force-close) has to walk.
|
|
1391
|
+
*/
|
|
1392
|
+
function subtreeTasks(tasks, id, maxSubtaskDepth) {
|
|
1393
|
+
const root = tasks.find((task) => task.id === id);
|
|
1394
|
+
return root === void 0 ? [] : [root, ...descendantTasks(tasks, id, maxSubtaskDepth)];
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* Whether a card still has work outstanding: anything outside the `done`
|
|
1398
|
+
* column. It keys on the column alone, so it covers both a subtask that ran
|
|
1399
|
+
* and one an operator moved to done by hand.
|
|
1400
|
+
*/
|
|
1401
|
+
function isOutstanding(task) {
|
|
1402
|
+
return task.status !== "done";
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* The descendants of a card that still have work outstanding, in breadth-first
|
|
1406
|
+
* order: the cards its own session is expected to dispatch. An archived
|
|
1407
|
+
* descendant is off the board and cannot be dispatched, so it is not listed.
|
|
1408
|
+
*/
|
|
1409
|
+
function outstandingDescendants(tasks, rootId, maxSubtaskDepth) {
|
|
1410
|
+
return descendantTasks(tasks, rootId, maxSubtaskDepth).filter((task) => task.archivedAt === void 0 && isOutstanding(task));
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* Whether any descendant of this card still sits outside the `done` column.
|
|
1414
|
+
* This is the ONE decision behind both the forced agent preset and the dispatch
|
|
1415
|
+
* section of the execution prompt: a card whose tree still holds work runs as
|
|
1416
|
+
* the autonomous dispatcher.
|
|
1417
|
+
*/
|
|
1418
|
+
function hasOutstandingDescendants(tasks, rootId, maxSubtaskDepth) {
|
|
1419
|
+
return outstandingDescendants(tasks, rootId, maxSubtaskDepth).length > 0;
|
|
932
1420
|
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Agent preset a run with unfinished subtasks is forced under. The id comes
|
|
1423
|
+
* from packages/dsh-liangshen (its own `LIANGSHEN_PRESET_ID`); the force is
|
|
1424
|
+
* applied at launch and never written into a card's `mode` field.
|
|
1425
|
+
*/
|
|
1426
|
+
const LIANGSHEN_PRESET_ID = "liangshen";
|
|
1427
|
+
/**
|
|
1428
|
+
* The tool a legacy Agent Teams runtime registers, and the one fingerprint
|
|
1429
|
+
* this board reads off a deployment: the pre-#7519 generation registers
|
|
1430
|
+
* `spawn_teammate` and replaces `send_message` / `list_agents` /
|
|
1431
|
+
* `interrupt_agent` with team-scoped variants, so children exist but are
|
|
1432
|
+
* unreachable. The current runtime adds a shared task board instead and reuses
|
|
1433
|
+
* the coordination tools, so those three names prove nothing and are never
|
|
1434
|
+
* gated on (the criterion is the same one
|
|
1435
|
+
* `packages/dsh-liangshen/presets/liangshen/dispatcher-rules.mjs` states).
|
|
1436
|
+
*/
|
|
1437
|
+
const LEGACY_AGENT_TEAMS_TOOL = "spawn_teammate";
|
|
1438
|
+
/**
|
|
1439
|
+
* The failure text the Host records when a run would have been forced under
|
|
1440
|
+
* the dispatcher preset on a deployment that cannot orchestrate.
|
|
1441
|
+
*
|
|
1442
|
+
* A finished sentence rather than a code (the shape `core/workspace-target.ts`
|
|
1443
|
+
* gives its missing-workspace refusal): the ledger stores it as the
|
|
1444
|
+
* execution's failure text, the agent tools serve it to a model, and any
|
|
1445
|
+
* client prints it verbatim. It names the fix, not the mechanism. The launch
|
|
1446
|
+
* is refused before any session exists, because the dispatcher preset would
|
|
1447
|
+
* otherwise stop and wait for a human reply that an unattended run never
|
|
1448
|
+
* brings.
|
|
1449
|
+
*/
|
|
1450
|
+
const LEGACY_AGENT_TEAMS_REASON = "this deployment runs the legacy Agent Teams runtime, which cannot dispatch a card that has unfinished subtasks under the liangshen preset; disable that runtime and restart the Host, or finish the subtasks before running";
|
|
933
1451
|
/** The open execution of a task inside a run group, if it still exists. */
|
|
934
1452
|
function openGroupExecution(task, runGroupId) {
|
|
935
1453
|
return task.executions.find((execution) => execution.runGroupId === runGroupId && execution.endedAt === void 0);
|
|
936
1454
|
}
|
|
937
1455
|
/**
|
|
938
1456
|
* The direct subtasks of parentTaskId whose execution in this run group is
|
|
939
|
-
* still open: the parent remaining waiters.
|
|
940
|
-
*
|
|
1457
|
+
* still open: the parent's remaining waiters. A stored multi-member group (a
|
|
1458
|
+
* run the Host opened before it stopped spreading one run across a subtree)
|
|
1459
|
+
* folds once this list is empty and the parent's own outcome is known.
|
|
941
1460
|
*/
|
|
942
1461
|
function pendingCascadeChildren(tasks, parentTaskId, runGroupId) {
|
|
943
1462
|
const pending = [];
|
|
@@ -952,9 +1471,9 @@ function pendingCascadeChildren(tasks, parentTaskId, runGroupId) {
|
|
|
952
1471
|
return pending;
|
|
953
1472
|
}
|
|
954
1473
|
/**
|
|
955
|
-
* Fold a
|
|
956
|
-
* verdict: failure dominates, then cancellation, then success. The error
|
|
957
|
-
* is the first failure, falling back to the first cancellation.
|
|
1474
|
+
* Fold a stored run-group parent's own outcome and its children's outcomes into
|
|
1475
|
+
* one verdict: failure dominates, then cancellation, then success. The error
|
|
1476
|
+
* text is the first failure, falling back to the first cancellation.
|
|
958
1477
|
*/
|
|
959
1478
|
function combineCascadeOutcome(entries) {
|
|
960
1479
|
let result = "succeeded";
|
|
@@ -989,73 +1508,119 @@ function effectiveTaskPermission(task) {
|
|
|
989
1508
|
/**
|
|
990
1509
|
* Resolve the execution targets a (sub)task actually runs with: its own value
|
|
991
1510
|
* wins, and an unset target inherits the nearest ancestor up to the root.
|
|
992
|
-
* Workspace, agent preset and
|
|
993
|
-
* handover bundle is a per-card continuation artefact and is never
|
|
994
|
-
* The permission inherits the ancestor's EFFECTIVE binding, and its
|
|
995
|
-
* confirmation travels with it, so a subtask of an already-confirmed
|
|
996
|
-
* card is runnable while a subtask's own unconfirmed binding stays
|
|
997
|
-
|
|
998
|
-
/**
|
|
999
|
-
* The immutable teammate name for one team-mode member. Teammate names are
|
|
1000
|
-
* lower-kebab-case and must stay unique for the lifetime of the Team: the
|
|
1001
|
-
* run-group token separates two runs of the same tree, and the member
|
|
1002
|
-
* discriminator separates two members of one run that reduce to the same slug.
|
|
1003
|
-
*
|
|
1004
|
-
* The discriminator is not cosmetic. A title with no ASCII word characters (a
|
|
1005
|
-
* CJK title, for example) carries no slug at all, so every such title of one
|
|
1006
|
-
* run group collides on the generic prefix; Agent Teams answers every member
|
|
1007
|
-
* after the first with `teammate name "..." was already used in this Team`,
|
|
1008
|
-
* and those subtasks never start. Two ASCII titles that share a slug
|
|
1009
|
-
* (`AI 强度预测` next to `AI 配比优化`) collide the same way.
|
|
1010
|
-
* @param title - the member task's title.
|
|
1011
|
-
* @param token - the run group id (the task id when no group is recorded).
|
|
1012
|
-
* @param memberId - the member task's id, which makes the name unique in the run.
|
|
1013
|
-
* @returns the teammate name handed to the Agent Teams service.
|
|
1014
|
-
*/
|
|
1015
|
-
function teammateName(title, token, memberId) {
|
|
1016
|
-
const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 32).replace(/-+$/g, "");
|
|
1017
|
-
const suffix = token.replace(/[^a-z0-9]/gi, "").slice(0, 8).toLowerCase();
|
|
1018
|
-
const member = memberId === void 0 || memberId === "" ? void 0 : stableTag(memberId);
|
|
1019
|
-
return [
|
|
1020
|
-
slug === "" ? "subtask" : slug,
|
|
1021
|
-
member,
|
|
1022
|
-
suffix === "" ? "run" : suffix
|
|
1023
|
-
].filter((part) => part !== void 0).join("-");
|
|
1024
|
-
}
|
|
1025
|
-
/**
|
|
1026
|
-
* A stable 4-hex tag for one member id. The name is derived twice for the same
|
|
1027
|
-
* member — once for the Lead's prompt and once for the spawn request — so the
|
|
1028
|
-
* tag must be a pure function of the id, never of a clock or a counter. FNV-1a
|
|
1029
|
-
* keeps it dependency-free in `core/`, which both halves compile.
|
|
1511
|
+
* Workspace, agent preset, model and reasoning effort inherit the ancestor's
|
|
1512
|
+
* PIN only — a handover bundle is a per-card continuation artefact and is never
|
|
1513
|
+
* inherited. The permission inherits the ancestor's EFFECTIVE binding, and its
|
|
1514
|
+
* human confirmation travels with it, so a subtask of an already-confirmed
|
|
1515
|
+
* elevated card is runnable while a subtask's own unconfirmed binding stays
|
|
1516
|
+
* gated.
|
|
1030
1517
|
*/
|
|
1031
|
-
function stableTag(value) {
|
|
1032
|
-
let hash = 2166136261;
|
|
1033
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
1034
|
-
hash ^= value.charCodeAt(index);
|
|
1035
|
-
hash = Math.imul(hash, 16777619) >>> 0;
|
|
1036
|
-
}
|
|
1037
|
-
return hash.toString(16).padStart(8, "0").slice(0, 4);
|
|
1038
|
-
}
|
|
1039
1518
|
function resolveExecutionTargets(task, tasks, maxSubtaskDepth = 3) {
|
|
1040
1519
|
if (task.parentId === void 0) return task;
|
|
1041
1520
|
const chain = [task, ...ancestorChain(tasks, task).slice(0, maxSubtaskDepth)];
|
|
1042
|
-
const first = (key) => {
|
|
1043
|
-
for (const candidate of
|
|
1521
|
+
const first = (key, candidates) => {
|
|
1522
|
+
for (const candidate of candidates) {
|
|
1044
1523
|
const value = candidate[key];
|
|
1045
1524
|
if (value !== void 0) return value;
|
|
1046
1525
|
}
|
|
1047
1526
|
};
|
|
1527
|
+
const boundary = chain.findIndex((candidate) => candidate.model !== void 0);
|
|
1528
|
+
const effortChain = boundary === -1 ? chain : chain.slice(0, boundary + 1);
|
|
1048
1529
|
const own = effectiveTaskPermission(task);
|
|
1049
1530
|
const owner = own === void 0 ? chain.slice(1).find((candidate) => effectiveTaskPermission(candidate) !== void 0) : void 0;
|
|
1050
1531
|
return {
|
|
1051
1532
|
...task,
|
|
1052
|
-
workspaceId: first("workspaceId"),
|
|
1053
|
-
mode: first("mode"),
|
|
1054
|
-
model: first("model"),
|
|
1533
|
+
workspaceId: first("workspaceId", chain),
|
|
1534
|
+
mode: first("mode", chain),
|
|
1535
|
+
model: first("model", chain),
|
|
1536
|
+
reasoningEffort: first("reasoningEffort", effortChain),
|
|
1055
1537
|
permission: own ?? (owner === void 0 ? void 0 : effectiveTaskPermission(owner)),
|
|
1056
1538
|
permissionConfirmedAt: own === void 0 ? owner?.permissionConfirmedAt : task.permissionConfirmedAt
|
|
1057
1539
|
};
|
|
1058
1540
|
}
|
|
1541
|
+
//#endregion
|
|
1542
|
+
//#region src/core/execution-summary.ts
|
|
1543
|
+
/**
|
|
1544
|
+
* What one execution left behind: the text of its last assistant message,
|
|
1545
|
+
* recorded on the execution record next to the verdict it belongs to.
|
|
1546
|
+
*
|
|
1547
|
+
* A settled execution used to carry only a verdict, so a parent card could see
|
|
1548
|
+
* that a subtask succeeded without ever seeing what it produced, and had to
|
|
1549
|
+
* guess or redo the work. The card's own content cannot answer that: card
|
|
1550
|
+
* content is the plan and freezes at the first execution
|
|
1551
|
+
* (`canEditTaskContent`), so the closing words of a run are recorded on the
|
|
1552
|
+
* execution record instead.
|
|
1553
|
+
*
|
|
1554
|
+
* Pure (no cordis, no runtime imports) so the settlement path is unit-testable
|
|
1555
|
+
* without a session, and so a text-less run degrades to "no field" rather than
|
|
1556
|
+
* to an empty string.
|
|
1557
|
+
*/
|
|
1558
|
+
/** One rendered content block of an assistant message, or '' when it has no prose. */
|
|
1559
|
+
function blockProse(block) {
|
|
1560
|
+
if (typeof block !== "object" || block === null) return "";
|
|
1561
|
+
const row = block;
|
|
1562
|
+
return row.type === "text" && typeof row.text === "string" ? row.text : "";
|
|
1563
|
+
}
|
|
1564
|
+
/** The assistant's own prose of one message: its text blocks joined and trimmed. */
|
|
1565
|
+
function messageProse(content) {
|
|
1566
|
+
if (!Array.isArray(content)) return "";
|
|
1567
|
+
return content.map(blockProse).filter((part) => part !== "").join("\n").trim();
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Bound one summary, keeping its tail: the closing paragraphs carry the
|
|
1571
|
+
* conclusion a reader is after, and the omitted opening is announced instead of
|
|
1572
|
+
* silently dropped. Mirrors the evidence reader's tail bound.
|
|
1573
|
+
*/
|
|
1574
|
+
function truncateExecutionSummary(text, limit = EXECUTION_SUMMARY_LIMIT) {
|
|
1575
|
+
if (text.length <= limit) return text;
|
|
1576
|
+
const notice = "[truncated " + String(text.length - limit) + " chars] ";
|
|
1577
|
+
return notice.length >= limit ? text.slice(-limit) : notice + text.slice(-(limit - notice.length));
|
|
1578
|
+
}
|
|
1579
|
+
/**
|
|
1580
|
+
* The summary one execution's own events support.
|
|
1581
|
+
*
|
|
1582
|
+
* Only events at or after `startedAt` belong to this run: a reused session
|
|
1583
|
+
* carries the history of earlier executions, which must not be reported as this
|
|
1584
|
+
* one's output. The last assistant message WITH prose wins — a trailing
|
|
1585
|
+
* tool-call or reasoning-only message has nothing to leave behind, so the reader
|
|
1586
|
+
* walks back to the last one that speaks.
|
|
1587
|
+
* @param events - the session events the inspection already read.
|
|
1588
|
+
* @param startedAt - the execution's start instant (ms epoch); 0 means "all".
|
|
1589
|
+
* @returns the bounded summary with the seq it came from, or undefined when the
|
|
1590
|
+
* run left no usable text.
|
|
1591
|
+
*/
|
|
1592
|
+
function executionSummaryOf(events, startedAt) {
|
|
1593
|
+
const own = events.filter((event) => typeof event.time !== "number" || startedAt <= 0 || event.time >= startedAt).filter((event) => event.type === "assistant/message" && typeof event.seq === "number").sort((a, b) => a.seq - b.seq);
|
|
1594
|
+
for (let index = own.length - 1; index >= 0; index -= 1) {
|
|
1595
|
+
const event = own[index];
|
|
1596
|
+
const data = typeof event.data === "object" && event.data !== null ? event.data : {};
|
|
1597
|
+
const text = messageProse((typeof data.message === "object" && data.message !== null ? data.message : {}).content);
|
|
1598
|
+
if (text === "") continue;
|
|
1599
|
+
return {
|
|
1600
|
+
text: truncateExecutionSummary(text),
|
|
1601
|
+
seq: event.seq
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Repair one persisted or reported summary.
|
|
1607
|
+
*
|
|
1608
|
+
* A summary is informational, so an unreadable one is dropped on its own rather
|
|
1609
|
+
* than costing the execution (or the task row) it hangs on. A hand-edited
|
|
1610
|
+
* overlong text is bounded on the way in, so no reader ever holds more than the
|
|
1611
|
+
* limit.
|
|
1612
|
+
*/
|
|
1613
|
+
function normalizeExecutionSummary(value) {
|
|
1614
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
1615
|
+
const row = value;
|
|
1616
|
+
if (typeof row.text !== "string" || typeof row.seq !== "number" || !Number.isFinite(row.seq)) return void 0;
|
|
1617
|
+
const text = row.text.trim();
|
|
1618
|
+
if (text === "") return void 0;
|
|
1619
|
+
return {
|
|
1620
|
+
text: truncateExecutionSummary(text),
|
|
1621
|
+
seq: row.seq
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1059
1624
|
/** Marker replacing every sensitive match. */
|
|
1060
1625
|
const REDACTED_MARKER = "[REDACTED]";
|
|
1061
1626
|
const SECTION_ORDER$1 = [
|
|
@@ -1227,16 +1792,6 @@ function exceedsSessionDefault(permission, sessionDefault) {
|
|
|
1227
1792
|
return (PERMISSION_RANK.get(permission) ?? -1) > (PERMISSION_RANK.get(sessionDefault) ?? -1);
|
|
1228
1793
|
}
|
|
1229
1794
|
/**
|
|
1230
|
-
* Whether a session running at `holder` already carries `permission`: the
|
|
1231
|
-
* permission is absent, or its rank does not exceed the holder's. A teammate
|
|
1232
|
-
* inherits the Lead session's permission and cannot be narrowed below it, so a
|
|
1233
|
-
* subtask's own pin is carried by a team run exactly when this holds, and a pin
|
|
1234
|
-
* it does not carry would be silently dropped instead.
|
|
1235
|
-
*/
|
|
1236
|
-
function permissionCarriedBy(holder, permission) {
|
|
1237
|
-
return !exceedsSessionDefault(permission, holder);
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
1795
|
* The confirmation-gate predicate: an elevated permission without a human
|
|
1241
1796
|
* confirmation stamp. Manual run/rerun and cron must refuse such a card.
|
|
1242
1797
|
*/
|
|
@@ -2277,9 +2832,11 @@ function isTaskRecordShape(value) {
|
|
|
2277
2832
|
if (record.parentId !== void 0 && typeof record.parentId !== "string") return false;
|
|
2278
2833
|
if (record.workspaceId !== void 0 && typeof record.workspaceId !== "string") return false;
|
|
2279
2834
|
if (record.mode !== void 0 && typeof record.mode !== "string") return false;
|
|
2835
|
+
if (record.reasoningEffort !== void 0 && typeof record.reasoningEffort !== "string") return false;
|
|
2280
2836
|
if (record.permission !== void 0 && typeof record.permission !== "string") return false;
|
|
2281
2837
|
if (record.integrations !== void 0 && (typeof record.integrations !== "object" || record.integrations === null || Array.isArray(record.integrations))) return false;
|
|
2282
2838
|
if (record.hidden !== void 0 && typeof record.hidden !== "boolean") return false;
|
|
2839
|
+
if (record.attachments !== void 0 && !Array.isArray(record.attachments)) return false;
|
|
2283
2840
|
if (record.reuseSession !== void 0 && typeof record.reuseSession !== "boolean") return false;
|
|
2284
2841
|
if (record.goalRun !== void 0 && typeof record.goalRun !== "boolean") return false;
|
|
2285
2842
|
if (record.skipVerification !== void 0 && typeof record.skipVerification !== "boolean") return false;
|
|
@@ -2441,11 +2998,14 @@ function parseLedger(raw) {
|
|
|
2441
2998
|
runGroupId: normalizeTargetId(execution.runGroupId),
|
|
2442
2999
|
ownResult: isExecutionOutcome(execution.ownResult) ? execution.ownResult : void 0,
|
|
2443
3000
|
ownError: typeof execution.ownError === "string" ? execution.ownError : void 0,
|
|
3001
|
+
summary: normalizeExecutionSummary(execution.summary),
|
|
2444
3002
|
verification: normalizeVerification(execution.verification),
|
|
3003
|
+
rework: normalizeExecutionRework(execution.rework),
|
|
2445
3004
|
external: execution.external === true ? true : void 0
|
|
2446
3005
|
}));
|
|
2447
3006
|
task.workspaceId = normalizeTargetId(row.workspaceId);
|
|
2448
3007
|
task.mode = normalizeTargetId(row.mode);
|
|
3008
|
+
task.reasoningEffort = normalizeTargetId(row.reasoningEffort);
|
|
2449
3009
|
task.archivedAt = typeof row.archivedAt === "number" && Number.isFinite(row.archivedAt) ? row.archivedAt : void 0;
|
|
2450
3010
|
task.permission = isTaskPermission(row.permission) ? row.permission : void 0;
|
|
2451
3011
|
task.reuseSession = row.reuseSession === true ? true : void 0;
|
|
@@ -2456,6 +3016,7 @@ function parseLedger(raw) {
|
|
|
2456
3016
|
task.tags = normalizeTags(row.tags);
|
|
2457
3017
|
task.permissionConfirmedAt = typeof row.permissionConfirmedAt === "number" && Number.isFinite(row.permissionConfirmedAt) ? row.permissionConfirmedAt : void 0;
|
|
2458
3018
|
task.integrations = normalizeTaskIntegrations(row.integrations);
|
|
3019
|
+
task.attachments = normalizeAttachments(row.attachments);
|
|
2459
3020
|
task.hidden = row.hidden === true ? true : void 0;
|
|
2460
3021
|
tasks.push(task);
|
|
2461
3022
|
}
|
|
@@ -2546,6 +3107,57 @@ function applyRestoreTask(tasks, id, now, maxSubtaskDepth = 1) {
|
|
|
2546
3107
|
};
|
|
2547
3108
|
}
|
|
2548
3109
|
//#endregion
|
|
3110
|
+
//#region src/core/card-defaults.ts
|
|
3111
|
+
/** Trim one optional target: blank text means "not set", like every stored pin. */
|
|
3112
|
+
function textOf(value) {
|
|
3113
|
+
return value?.trim() ?? "";
|
|
3114
|
+
}
|
|
3115
|
+
/**
|
|
3116
|
+
* Resolve the execution targets a new card starts from.
|
|
3117
|
+
* @param defaults - the board's configured new-card defaults, if any.
|
|
3118
|
+
* @param source - the card this one is created from (a duplicate or a parent), if any.
|
|
3119
|
+
* @param picked - what the caller chose explicitly; a non-blank value wins.
|
|
3120
|
+
* @returns the four targets, blank where nothing supplies a value.
|
|
3121
|
+
*/
|
|
3122
|
+
function resolveCardTargets(defaults, source, picked) {
|
|
3123
|
+
const defaultMode = textOf(defaults?.mode);
|
|
3124
|
+
const defaultPermission = textOf(defaults?.permission);
|
|
3125
|
+
const defaultModel = textOf(defaults?.model);
|
|
3126
|
+
const defaultEffort = defaultModel === "" ? "" : textOf(defaults?.reasoningEffort);
|
|
3127
|
+
const chosen = {
|
|
3128
|
+
mode: textOf(picked?.mode),
|
|
3129
|
+
permission: textOf(picked?.permission),
|
|
3130
|
+
model: textOf(picked?.model),
|
|
3131
|
+
reasoningEffort: textOf(picked?.reasoningEffort)
|
|
3132
|
+
};
|
|
3133
|
+
const copied = source === void 0 ? void 0 : {
|
|
3134
|
+
mode: textOf(source.task.mode),
|
|
3135
|
+
permission: textOf(source.task.permission),
|
|
3136
|
+
model: textOf(source.task.model),
|
|
3137
|
+
reasoningEffort: textOf(source.task.reasoningEffort)
|
|
3138
|
+
};
|
|
3139
|
+
/** The value carried over from the source card, or the board default. */
|
|
3140
|
+
const inherited = (key) => {
|
|
3141
|
+
const fallback = key === "mode" ? defaultMode : key === "model" ? defaultModel : defaultPermission;
|
|
3142
|
+
if (copied === void 0 || key === "permission" && source?.kind === "parent") return fallback;
|
|
3143
|
+
return copied[key] === "" ? fallback : copied[key];
|
|
3144
|
+
};
|
|
3145
|
+
const mode = chosen.mode === "" ? inherited("mode") : chosen.mode;
|
|
3146
|
+
const permission = chosen.permission === "" ? inherited("permission") : chosen.permission;
|
|
3147
|
+
const model = chosen.model === "" ? inherited("model") : chosen.model;
|
|
3148
|
+
let reasoningEffort = chosen.reasoningEffort;
|
|
3149
|
+
if (reasoningEffort === "" && chosen.model === "") {
|
|
3150
|
+
const sourced = copied === void 0 ? "" : copied.reasoningEffort;
|
|
3151
|
+
reasoningEffort = sourced !== "" ? sourced : model !== "" && model === defaultModel ? defaultEffort : "";
|
|
3152
|
+
}
|
|
3153
|
+
return {
|
|
3154
|
+
mode,
|
|
3155
|
+
permission,
|
|
3156
|
+
model,
|
|
3157
|
+
reasoningEffort
|
|
3158
|
+
};
|
|
3159
|
+
}
|
|
3160
|
+
//#endregion
|
|
2549
3161
|
//#region src/core/use-cases/task-create.ts
|
|
2550
3162
|
/**
|
|
2551
3163
|
* Create-task use case: mint a new task from user input, rejecting a blank
|
|
@@ -2558,18 +3170,22 @@ function applyRestoreTask(tasks, id, now, maxSubtaskDepth = 1) {
|
|
|
2558
3170
|
* appended ledger, or the unchanged ledger when the title is blank or the
|
|
2559
3171
|
* requested parent link is refused.
|
|
2560
3172
|
*
|
|
2561
|
-
*
|
|
2562
|
-
*
|
|
2563
|
-
*
|
|
2564
|
-
*
|
|
3173
|
+
* The execution targets resolve through {@link resolveCardTargets}: what the
|
|
3174
|
+
* caller sent wins, then the parent's own pins, then - only when the caller
|
|
3175
|
+
* opted in with `applyCardDefaults` - the deployment's configured new-card
|
|
3176
|
+
* defaults. Without the flag the resolution sees no defaults at all, which is
|
|
3177
|
+
* exactly the inline parent inheritance this path has always applied. The
|
|
3178
|
+
* workspace is not part of that resolution: a subtask still takes the parent's
|
|
3179
|
+
* workspace, and the defaults never name one.
|
|
2565
3180
|
* @param tasks - current ledger.
|
|
2566
3181
|
* @param input - raw user input (title/description/prompt + optional schedule/parent).
|
|
2567
3182
|
* @param now - clock instant (ms epoch).
|
|
2568
3183
|
* @param id - minted task id.
|
|
2569
3184
|
* @param maxSubtaskDepth - deployment subtask depth limit.
|
|
2570
3185
|
* @param hostTimeZone - zone a rule that stores no zone of its own follows.
|
|
3186
|
+
* @param cardDefaults - the deployment's new-card defaults, read live at creation.
|
|
2571
3187
|
*/
|
|
2572
|
-
function applyCreateTask(tasks, input, now, id, maxSubtaskDepth = 1, hostTimeZone = resolveHostTimeZone()) {
|
|
3188
|
+
function applyCreateTask(tasks, input, now, id, maxSubtaskDepth = 1, hostTimeZone = resolveHostTimeZone(), cardDefaults) {
|
|
2573
3189
|
if (input.title.trim() === "") return {
|
|
2574
3190
|
task: void 0,
|
|
2575
3191
|
tasks,
|
|
@@ -2595,11 +3211,22 @@ function applyCreateTask(tasks, input, now, id, maxSubtaskDepth = 1, hostTimeZon
|
|
|
2595
3211
|
error: `subtask depth limit (${limit}) exceeded`
|
|
2596
3212
|
};
|
|
2597
3213
|
}
|
|
2598
|
-
|
|
3214
|
+
const seed = resolveCardTargets(input.applyCardDefaults === true ? cardDefaults : void 0, parent === void 0 ? void 0 : {
|
|
3215
|
+
kind: "parent",
|
|
3216
|
+
task: parent
|
|
3217
|
+
}, {
|
|
3218
|
+
mode: input.mode,
|
|
3219
|
+
permission: input.permission,
|
|
3220
|
+
model: input.model,
|
|
3221
|
+
reasoningEffort: input.reasoningEffort
|
|
3222
|
+
});
|
|
3223
|
+
let task = createTask({
|
|
2599
3224
|
...input,
|
|
2600
|
-
workspaceId: input.workspaceId ?? parent
|
|
2601
|
-
mode:
|
|
2602
|
-
|
|
3225
|
+
workspaceId: input.workspaceId ?? parent?.workspaceId,
|
|
3226
|
+
mode: seed.mode,
|
|
3227
|
+
permission: isTaskPermission(seed.permission) ? seed.permission : void 0,
|
|
3228
|
+
model: seed.model,
|
|
3229
|
+
reasoningEffort: seed.reasoningEffort
|
|
2603
3230
|
}, now, id);
|
|
2604
3231
|
const requested = input.schedule;
|
|
2605
3232
|
if (requested?.enabled === true) {
|
|
@@ -2958,6 +3585,13 @@ function applySetParent(tasks, id, parentId, now, maxSubtaskDepth = 1) {
|
|
|
2958
3585
|
* Renaming onto a name that is already in use MERGES the two: a task carrying
|
|
2959
3586
|
* both keeps the row it already had (with its execution hint) and loses the
|
|
2960
3587
|
* duplicate, which is the only reading that cannot lose a hint the user typed.
|
|
3588
|
+
*
|
|
3589
|
+
* Clearing up is the third ledger-wide transition, and it is a SELECTION rather
|
|
3590
|
+
* than a fourth rewrite: {@link cleanupCandidates} names the labels that are
|
|
3591
|
+
* both rarely used and attached only to finished tasks, and each of them then
|
|
3592
|
+
* leaves through {@link applyDeleteTag} like any other delete. One delete path,
|
|
3593
|
+
* one meaning — a label never disappears by a second rule written beside the
|
|
3594
|
+
* first.
|
|
2961
3595
|
*/
|
|
2962
3596
|
/** Trim a label name the way creation does. */
|
|
2963
3597
|
function normalizeName(value) {
|
|
@@ -3084,9 +3718,20 @@ const TASK_CONTENT_FIELDS = [
|
|
|
3084
3718
|
"description",
|
|
3085
3719
|
"prompt"
|
|
3086
3720
|
];
|
|
3721
|
+
/**
|
|
3722
|
+
* The fields that freeze with the card content: the text the card says AND
|
|
3723
|
+
* the attachments it carries.
|
|
3724
|
+
*
|
|
3725
|
+
* The attachments freeze with the content because they ARE part of what the
|
|
3726
|
+
* card hands to its execution: a card whose first run already consumed an
|
|
3727
|
+
* image keeps that image, and the record of what ran stays what it was. An
|
|
3728
|
+
* executed or archived card therefore refuses an attachment change exactly
|
|
3729
|
+
* as it refuses a prompt change.
|
|
3730
|
+
*/
|
|
3731
|
+
const TASK_FROZEN_FIELDS = [...TASK_CONTENT_FIELDS, "attachments"];
|
|
3087
3732
|
/** Whether an update patch touches any task-content field. */
|
|
3088
3733
|
function hasContentPatch(patch) {
|
|
3089
|
-
return
|
|
3734
|
+
return TASK_FROZEN_FIELDS.some((field) => field in patch);
|
|
3090
3735
|
}
|
|
3091
3736
|
/**
|
|
3092
3737
|
* Whether a task's content may still be edited: the task must be on-board
|
|
@@ -3114,11 +3759,12 @@ function normalizePermission(current, value) {
|
|
|
3114
3759
|
function applyUpdateTask(tasks, id, patch, now) {
|
|
3115
3760
|
return tasks.map((task) => {
|
|
3116
3761
|
if (task.id !== id) return task;
|
|
3117
|
-
const { freeze: freezePatch, handover: handoverPatch, tags: tagsPatch, ...rest } = patch;
|
|
3762
|
+
const { freeze: freezePatch, handover: handoverPatch, tags: tagsPatch, attachments: attachmentsPatch, ...rest } = patch;
|
|
3118
3763
|
const workspaceId = "workspaceId" in patch ? normalizeTargetId(patch.workspaceId) : void 0;
|
|
3119
3764
|
const mode = "mode" in patch ? normalizeTargetId(patch.mode) : void 0;
|
|
3120
3765
|
const permission = "permission" in patch ? normalizePermission(task.permission, patch.permission) : void 0;
|
|
3121
3766
|
const model = "model" in patch ? normalizeTargetId(patch.model) : void 0;
|
|
3767
|
+
const reasoningEffort = "reasoningEffort" in patch ? normalizeTargetId(patch.reasoningEffort) : void 0;
|
|
3122
3768
|
const next = {
|
|
3123
3769
|
...task,
|
|
3124
3770
|
...rest,
|
|
@@ -3135,25 +3781,28 @@ function applyUpdateTask(tasks, id, patch, now) {
|
|
|
3135
3781
|
bundledAt: now
|
|
3136
3782
|
};
|
|
3137
3783
|
if ("tags" in patch) next.tags = tagsPatch == null ? void 0 : normalizeTags(tagsPatch);
|
|
3784
|
+
if ("attachments" in patch) next.attachments = attachmentsPatch == null ? void 0 : normalizeAttachments(attachmentsPatch);
|
|
3138
3785
|
if ("permission" in patch && patch.permission !== void 0 && patch.permission !== task.permission || "handover" in patch) next.permissionConfirmedAt = void 0;
|
|
3139
3786
|
if ("reuseSession" in patch) next.reuseSession = patch.reuseSession === true ? true : void 0;
|
|
3140
|
-
if ("teamRun" in patch) next.teamRun = patch.teamRun === true ? true : void 0;
|
|
3141
3787
|
if ("goalRun" in patch) next.goalRun = patch.goalRun === true ? true : void 0;
|
|
3142
3788
|
if ("skipVerification" in patch) next.skipVerification = patch.skipVerification === true ? true : void 0;
|
|
3143
3789
|
if (workspaceId !== void 0 || "workspaceId" in patch) next.workspaceId = workspaceId;
|
|
3144
3790
|
if (mode !== void 0 || "mode" in patch) next.mode = mode;
|
|
3145
3791
|
if (permission !== void 0 || "permission" in patch) next.permission = permission;
|
|
3146
3792
|
if (model !== void 0 || "model" in patch) next.model = model;
|
|
3793
|
+
if (reasoningEffort !== void 0 || "reasoningEffort" in patch) next.reasoningEffort = reasoningEffort;
|
|
3147
3794
|
return next;
|
|
3148
3795
|
});
|
|
3149
3796
|
}
|
|
3150
3797
|
/**
|
|
3151
3798
|
* Every older generation the loader migrates in place. v5 only added the
|
|
3152
|
-
* per-execution acceptance block
|
|
3153
|
-
* budget,
|
|
3154
|
-
* row; a document from any
|
|
3799
|
+
* per-execution acceptance block, v6 only added the scheduling mode and run
|
|
3800
|
+
* budget, and v7 only added the card attachment metadata, so the migration is
|
|
3801
|
+
* the normalization pass that re-validates each row; a document from any
|
|
3802
|
+
* listed generation upgrades losslessly.
|
|
3155
3803
|
*/
|
|
3156
3804
|
const TASK_BOARD_MIGRATABLE_SCHEMA_VERSIONS = [
|
|
3805
|
+
6,
|
|
3157
3806
|
5,
|
|
3158
3807
|
4,
|
|
3159
3808
|
3,
|
|
@@ -3229,7 +3878,9 @@ function validImportedSchedule(value) {
|
|
|
3229
3878
|
}
|
|
3230
3879
|
function validImportedKnownFields(value) {
|
|
3231
3880
|
if (value.tags !== void 0 && !isTaskTagList(value.tags)) return false;
|
|
3881
|
+
if (value.model !== void 0 && typeof value.model !== "string") return false;
|
|
3232
3882
|
if (value.integrations !== void 0 && normalizeTaskIntegrations(value.integrations) === void 0) return false;
|
|
3883
|
+
if (value.attachments !== void 0) return false;
|
|
3233
3884
|
if (value.schedule !== void 0 && !validImportedSchedule(value.schedule)) return false;
|
|
3234
3885
|
if (value.executions !== void 0) {
|
|
3235
3886
|
if (!Array.isArray(value.executions)) return false;
|
|
@@ -3281,7 +3932,9 @@ function importedTask(value) {
|
|
|
3281
3932
|
...task.parentId === void 0 ? {} : { parentId: task.parentId },
|
|
3282
3933
|
...task.workspaceId === void 0 ? {} : { workspaceId: task.workspaceId },
|
|
3283
3934
|
...task.mode === void 0 ? {} : { mode: task.mode },
|
|
3935
|
+
...typeof task.model !== "string" || task.model.trim() === "" ? {} : { model: task.model },
|
|
3284
3936
|
...task.permission === void 0 ? {} : { permission: task.permission },
|
|
3937
|
+
...task.reasoningEffort === void 0 ? {} : { reasoningEffort: task.reasoningEffort },
|
|
3285
3938
|
...task.reuseSession === void 0 ? {} : { reuseSession: task.reuseSession },
|
|
3286
3939
|
...task.goalRun === void 0 ? {} : { goalRun: task.goalRun },
|
|
3287
3940
|
...task.skipVerification === void 0 ? {} : { skipVerification: task.skipVerification },
|
|
@@ -3330,23 +3983,26 @@ function createInput(value) {
|
|
|
3330
3983
|
"freeze",
|
|
3331
3984
|
"handover",
|
|
3332
3985
|
"model",
|
|
3986
|
+
"reasoningEffort",
|
|
3987
|
+
"applyCardDefaults",
|
|
3333
3988
|
"reuseSession",
|
|
3334
|
-
"teamRun",
|
|
3335
3989
|
"goalRun",
|
|
3336
3990
|
"skipVerification",
|
|
3337
3991
|
"tags",
|
|
3338
|
-
"integrations"
|
|
3992
|
+
"integrations",
|
|
3993
|
+
"attachments"
|
|
3339
3994
|
])) return false;
|
|
3340
3995
|
if (input.parentId !== void 0 && (typeof input.parentId !== "string" || input.parentId.trim() === "")) return false;
|
|
3341
3996
|
if (typeof input.title !== "string" || typeof input.description !== "string" || typeof input.prompt !== "string") return false;
|
|
3342
|
-
if (!optionalString(input.workspaceId) || !optionalString(input.mode) || !optionalString(input.model)) return false;
|
|
3997
|
+
if (!optionalString(input.workspaceId) || !optionalString(input.mode) || !optionalString(input.model) || !optionalString(input.reasoningEffort)) return false;
|
|
3998
|
+
if (input.applyCardDefaults !== void 0 && typeof input.applyCardDefaults !== "boolean") return false;
|
|
3343
3999
|
if (input.reuseSession !== void 0 && typeof input.reuseSession !== "boolean") return false;
|
|
3344
|
-
if (input.teamRun !== void 0 && typeof input.teamRun !== "boolean") return false;
|
|
3345
4000
|
if (input.goalRun !== void 0 && typeof input.goalRun !== "boolean") return false;
|
|
3346
4001
|
if (input.skipVerification !== void 0 && typeof input.skipVerification !== "boolean") return false;
|
|
3347
4002
|
if (input.permission !== void 0 && !isTaskPermission(input.permission)) return false;
|
|
3348
4003
|
if (input.tags !== void 0 && !isTaskTagList(input.tags)) return false;
|
|
3349
4004
|
if (input.integrations !== void 0 && normalizeTaskIntegrations(input.integrations) === void 0) return false;
|
|
4005
|
+
if (input.attachments !== void 0 && !isTaskAttachmentList(input.attachments)) return false;
|
|
3350
4006
|
if (input.freeze !== void 0 && freezePayload(input.freeze) === void 0) return false;
|
|
3351
4007
|
if (input.handover !== void 0 && handoverPayload(input.handover) === void 0) return false;
|
|
3352
4008
|
if (input.schedule !== void 0) {
|
|
@@ -3380,14 +4036,14 @@ function updatePatch(value) {
|
|
|
3380
4036
|
"freeze",
|
|
3381
4037
|
"handover",
|
|
3382
4038
|
"model",
|
|
4039
|
+
"reasoningEffort",
|
|
3383
4040
|
"reuseSession",
|
|
3384
|
-
"teamRun",
|
|
3385
4041
|
"goalRun",
|
|
3386
4042
|
"skipVerification",
|
|
3387
|
-
"tags"
|
|
4043
|
+
"tags",
|
|
4044
|
+
"attachments"
|
|
3388
4045
|
])) return false;
|
|
3389
4046
|
if (patch.reuseSession !== void 0 && patch.reuseSession !== null && typeof patch.reuseSession !== "boolean") return false;
|
|
3390
|
-
if (patch.teamRun !== void 0 && patch.teamRun !== null && typeof patch.teamRun !== "boolean") return false;
|
|
3391
4047
|
if (patch.goalRun !== void 0 && patch.goalRun !== null && typeof patch.goalRun !== "boolean") return false;
|
|
3392
4048
|
if (patch.skipVerification !== void 0 && patch.skipVerification !== null && typeof patch.skipVerification !== "boolean") return false;
|
|
3393
4049
|
for (const key of [
|
|
@@ -3396,10 +4052,12 @@ function updatePatch(value) {
|
|
|
3396
4052
|
"prompt",
|
|
3397
4053
|
"workspaceId",
|
|
3398
4054
|
"mode",
|
|
3399
|
-
"model"
|
|
4055
|
+
"model",
|
|
4056
|
+
"reasoningEffort"
|
|
3400
4057
|
]) if (!optionalString(patch[key])) return false;
|
|
3401
4058
|
if (patch.permission !== void 0 && !isTaskPermission(patch.permission)) return false;
|
|
3402
4059
|
if (patch.tags !== void 0 && patch.tags !== null && !isTaskTagList(patch.tags)) return false;
|
|
4060
|
+
if (patch.attachments !== void 0 && patch.attachments !== null && !isTaskAttachmentList(patch.attachments)) return false;
|
|
3403
4061
|
if (patch.freeze !== void 0 && patch.freeze !== null && freezePayload(patch.freeze) === void 0) return false;
|
|
3404
4062
|
return patch.handover === void 0 || patch.handover === null || handoverPayload(patch.handover) !== void 0;
|
|
3405
4063
|
}
|
|
@@ -3625,6 +4283,24 @@ function parseEnvelopeAction(value) {
|
|
|
3625
4283
|
}
|
|
3626
4284
|
};
|
|
3627
4285
|
}
|
|
4286
|
+
case "rework": {
|
|
4287
|
+
if (!exactKeys(action, [
|
|
4288
|
+
"kind",
|
|
4289
|
+
"taskId",
|
|
4290
|
+
"instructions"
|
|
4291
|
+
])) return void 0;
|
|
4292
|
+
if (taskId === void 0 || typeof action.instructions !== "string") return void 0;
|
|
4293
|
+
const instructions = action.instructions.trim();
|
|
4294
|
+
if (instructions === "" || instructions.length > 4e3) return void 0;
|
|
4295
|
+
return {
|
|
4296
|
+
requestId: envelope.requestId,
|
|
4297
|
+
action: {
|
|
4298
|
+
kind: "rework",
|
|
4299
|
+
taskId,
|
|
4300
|
+
instructions
|
|
4301
|
+
}
|
|
4302
|
+
};
|
|
4303
|
+
}
|
|
3628
4304
|
case "confirm-permission":
|
|
3629
4305
|
case "delete":
|
|
3630
4306
|
case "archive":
|
|
@@ -3645,11 +4321,16 @@ function parseEnvelopeAction(value) {
|
|
|
3645
4321
|
//#region src/host-ledger.ts
|
|
3646
4322
|
/** Human-facing text for a refused binding, per surface. */
|
|
3647
4323
|
function bindingRefusalMessage(refusal, sessionDefault, surface) {
|
|
3648
|
-
if (refusal.kind === "subtask-pin") return `team run cannot honor the permission binding of subtask "${refusal.title}": a teammate runs inside the Lead session and inherits its permission, which that pin exceeds; clear the card's permission or run the tree without Agent Team`;
|
|
3649
4324
|
if (surface === "schedule") return `task "${refusal.title}" has an unconfirmed above-default permission`;
|
|
3650
4325
|
if (refusal.kind === "root") return `confirmation-required: the effective permission is above the session default (${sessionDefault}); confirm the card's permission binding first`;
|
|
3651
4326
|
return `confirmation-required: subtask "${refusal.title}" inherits an above-default permission; confirm that card's permission binding first`;
|
|
3652
4327
|
}
|
|
4328
|
+
/**
|
|
4329
|
+
* Prefix of the `initiatedBy` an inherited descendant verdict carries. The Host
|
|
4330
|
+
* recorded it on the run card's behalf (see `inheritVerdictForDescendants`), not
|
|
4331
|
+
* an outside agent that reported its own work.
|
|
4332
|
+
*/
|
|
4333
|
+
const PARENT_RUN_INITIATOR_PREFIX = "parent-run:";
|
|
3653
4334
|
const MAX_REQUEST_CACHE = 256;
|
|
3654
4335
|
function timeZone() {
|
|
3655
4336
|
return resolveHostTimeZone();
|
|
@@ -3905,7 +4586,7 @@ function mergeTask(a, b) {
|
|
|
3905
4586
|
* missing, cyclic, or names an archived parent while the child is on board is
|
|
3906
4587
|
* dropped (the task becomes a root) instead of dropping the task. A chain
|
|
3907
4588
|
* deeper than the current `maxSubtaskDepth` is deliberately KEPT: the limit
|
|
3908
|
-
* gates new links, it never deletes a stored one, and every
|
|
4589
|
+
* gates new links, it never deletes a stored one, and every lineage walk is
|
|
3909
4590
|
* bounded by the limit anyway. The Host is the only writer of these links, so
|
|
3910
4591
|
* this is a last-resort guard against a hand-edited or imported document.
|
|
3911
4592
|
*/
|
|
@@ -3985,11 +4666,24 @@ var HostTaskLedger = class {
|
|
|
3985
4666
|
* instead of remounting the row.
|
|
3986
4667
|
*/
|
|
3987
4668
|
depthLimit;
|
|
4669
|
+
/** Live reader of the deployment's new-card defaults (a volatile config read). */
|
|
4670
|
+
cardDefaults;
|
|
4671
|
+
/**
|
|
4672
|
+
* Live reader of the daily token cap (0 = no gate). The scheduled path asks it
|
|
4673
|
+
* per due occurrence, so a cap raised after a skipped occurrence admits the
|
|
4674
|
+
* next one without a restart.
|
|
4675
|
+
*/
|
|
4676
|
+
spendBudget;
|
|
4677
|
+
/** Today's measured spend in tokens, or undefined when nothing can be measured. */
|
|
4678
|
+
spendUsed;
|
|
3988
4679
|
constructor(dir = join(dshHome(), "task-board"), now = Date.now, options = {}) {
|
|
3989
4680
|
this.now = now;
|
|
3990
4681
|
const baseline = options.sessionDefaultPermission;
|
|
3991
4682
|
this.sessionDefault = typeof baseline === "function" ? baseline : () => baseline ?? "read-only";
|
|
3992
4683
|
this.depthLimit = normalizeSubtaskDepth(options.maxSubtaskDepth ?? 1);
|
|
4684
|
+
this.cardDefaults = options.cardDefaults ?? (() => ({}));
|
|
4685
|
+
this.spendBudget = options.spendBudgetTokens ?? (() => 0);
|
|
4686
|
+
this.spendUsed = options.spendUsedToday ?? ((now) => usedTokensToday(now));
|
|
3993
4687
|
mkdirSync(dir, { recursive: true });
|
|
3994
4688
|
this.file = join(dir, "ledger-v2.json");
|
|
3995
4689
|
this.lockFile = join(dir, "ledger-v2.lock");
|
|
@@ -4162,10 +4856,10 @@ var HostTaskLedger = class {
|
|
|
4162
4856
|
}
|
|
4163
4857
|
}
|
|
4164
4858
|
/**
|
|
4165
|
-
* Open the
|
|
4166
|
-
*
|
|
4167
|
-
*
|
|
4168
|
-
*
|
|
4859
|
+
* Open the one run a due schedule triggers: an empty array means nothing ran
|
|
4860
|
+
* (already running, a card whose elevated permission is still unconfirmed, a
|
|
4861
|
+
* one-shot whose instant was missed, or an exhausted budget), and the rule's
|
|
4862
|
+
* own state says which.
|
|
4169
4863
|
*
|
|
4170
4864
|
* The run budget is enforced HERE, inside the single ledger writer: a rule
|
|
4171
4865
|
* whose counter already reached its cap is stopped instead of opened, so no
|
|
@@ -4196,7 +4890,13 @@ var HostTaskLedger = class {
|
|
|
4196
4890
|
this.skipOccurrence(taskId, "busy", triggeredAt);
|
|
4197
4891
|
return [];
|
|
4198
4892
|
}
|
|
4199
|
-
|
|
4893
|
+
const spendRefusal = this.spendRefusal(triggeredAt);
|
|
4894
|
+
if (spendRefusal !== void 0) {
|
|
4895
|
+
this.document.scheduler.error = `scheduled run refused for task ${taskId}: ${spendRefusal}`;
|
|
4896
|
+
this.skipOccurrence(taskId, "limit", triggeredAt);
|
|
4897
|
+
return [];
|
|
4898
|
+
}
|
|
4899
|
+
if (schedule.mode === "once") return this.startRun(task, triggeredAt, void 0, false, {
|
|
4200
4900
|
consumed: 1,
|
|
4201
4901
|
lastTriggeredAt: triggeredAt,
|
|
4202
4902
|
endedReason: "fired"
|
|
@@ -4212,7 +4912,7 @@ var HostTaskLedger = class {
|
|
|
4212
4912
|
const consumed = schedule.runCount + 1;
|
|
4213
4913
|
const budget = scheduleRunBudget(schedule);
|
|
4214
4914
|
const spent = budget !== void 0 && consumed >= budget;
|
|
4215
|
-
return this.
|
|
4915
|
+
return this.startRun(task, triggeredAt, void 0, false, {
|
|
4216
4916
|
consumed: 1,
|
|
4217
4917
|
nextRunAt: spent ? void 0 : next,
|
|
4218
4918
|
lastTriggeredAt: triggeredAt,
|
|
@@ -4220,6 +4920,20 @@ var HostTaskLedger = class {
|
|
|
4220
4920
|
});
|
|
4221
4921
|
}
|
|
4222
4922
|
/**
|
|
4923
|
+
* Why a due occurrence may not open a run because the day already spent the
|
|
4924
|
+
* cap, or undefined when it may. A cap of 0 — the default — answers before the
|
|
4925
|
+
* measurement is read, so a board with no gate reads no ledger file.
|
|
4926
|
+
* @param now - clock instant (ms epoch).
|
|
4927
|
+
* @returns the refusal message, when the cap is reached.
|
|
4928
|
+
*/
|
|
4929
|
+
spendRefusal(now) {
|
|
4930
|
+
const cap = this.spendBudget();
|
|
4931
|
+
if (!(cap > 0)) return void 0;
|
|
4932
|
+
const used = this.spendUsed(now);
|
|
4933
|
+
if (used === void 0 || !spendCapReached(used, cap)) return void 0;
|
|
4934
|
+
return spendCapMessage(used, cap);
|
|
4935
|
+
}
|
|
4936
|
+
/**
|
|
4223
4937
|
* Record a due occurrence that opened no execution: roll a recurring rule to
|
|
4224
4938
|
* its next occurrence (budget untouched), or stop it when there is none. A
|
|
4225
4939
|
* one-shot has no second occurrence, so it always stops here with the reason.
|
|
@@ -4255,8 +4969,8 @@ var HostTaskLedger = class {
|
|
|
4255
4969
|
* failed without creating a session (see
|
|
4256
4970
|
* {@link applyScheduleRefund}). Called by the service on the failed-launch
|
|
4257
4971
|
* path only; a manual run and a launch that did reach a session are never
|
|
4258
|
-
* refunded. A no-op for a task with no rule, so a failed
|
|
4259
|
-
*
|
|
4972
|
+
* refunded. A no-op for a task with no rule, so a failed run does not touch
|
|
4973
|
+
* anything.
|
|
4260
4974
|
* @param taskId - the task whose occurrence is being refunded.
|
|
4261
4975
|
* @param now - clock instant (ms epoch).
|
|
4262
4976
|
*/
|
|
@@ -4322,19 +5036,25 @@ var HostTaskLedger = class {
|
|
|
4322
5036
|
this.commit(false);
|
|
4323
5037
|
}
|
|
4324
5038
|
/**
|
|
4325
|
-
* Settle one execution. A
|
|
4326
|
-
*
|
|
4327
|
-
*
|
|
4328
|
-
*
|
|
5039
|
+
* Settle one execution. A NEW run is a single-member group, so it settles on
|
|
5040
|
+
* its own turn. A run group the Host opened before it stopped spreading one
|
|
5041
|
+
* run across a subtree is folded here instead: a stored participant records
|
|
5042
|
+
* its OWN outcome and only finalizes once every child execution in its group
|
|
5043
|
+
* has settled, so a parent card leaves 'running' with the whole group's
|
|
5044
|
+
* verdict rather than its own turn alone.
|
|
5045
|
+
*
|
|
5046
|
+
* `summary` is what the run left behind (see `ExecutionSummary`), passed in
|
|
5047
|
+
* by whichever reader observed the session. It is informational: a caller
|
|
5048
|
+
* without one settles exactly as before, and a settlement never waits on it.
|
|
4329
5049
|
*/
|
|
4330
|
-
settle(taskId, executionId, outcome, error) {
|
|
5050
|
+
settle(taskId, executionId, outcome, error, summary) {
|
|
4331
5051
|
const now = this.now();
|
|
4332
5052
|
const task = this.document.tasks.find((item) => item.id === taskId);
|
|
4333
5053
|
const execution = task?.executions.find((entry) => entry.id === executionId);
|
|
4334
5054
|
if (task === void 0 || execution === void 0 || execution.endedAt !== void 0) return;
|
|
4335
5055
|
const groupId = execution.runGroupId;
|
|
4336
5056
|
if (groupId === void 0) {
|
|
4337
|
-
this.document.tasks = this.document.tasks.map((item) => item.id === taskId ? settleExecution(item, executionId, outcome, now, error) : item);
|
|
5057
|
+
this.document.tasks = this.document.tasks.map((item) => item.id === taskId ? settleExecution(item, executionId, outcome, now, error, summary) : item);
|
|
4338
5058
|
this.commit();
|
|
4339
5059
|
return;
|
|
4340
5060
|
}
|
|
@@ -4346,20 +5066,87 @@ var HostTaskLedger = class {
|
|
|
4346
5066
|
executions: item.executions.map((entry) => entry.id === executionId ? {
|
|
4347
5067
|
...entry,
|
|
4348
5068
|
ownResult: outcome,
|
|
4349
|
-
ownError: error
|
|
5069
|
+
ownError: error,
|
|
5070
|
+
...summary === void 0 ? {} : { summary }
|
|
4350
5071
|
} : entry)
|
|
4351
5072
|
});
|
|
4352
5073
|
changed = true;
|
|
4353
5074
|
}
|
|
4354
5075
|
if (task.teamRun === true && this.closeTeamMembers(taskId, groupId, execution.ownResult ?? outcome, execution.ownError ?? error, now)) changed = true;
|
|
4355
5076
|
if (this.settleCascade(taskId, groupId, now)) changed = true;
|
|
5077
|
+
if (this.inheritVerdictForDescendants(taskId, executionId, groupId, now)) changed = true;
|
|
4356
5078
|
if (changed) this.commit();
|
|
4357
5079
|
}
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
5080
|
+
/**
|
|
5081
|
+
* Record the run's verdict on the outstanding descendants its root was asked
|
|
5082
|
+
* to dispatch.
|
|
5083
|
+
*
|
|
5084
|
+
* A card with unfinished subtasks runs as an autonomous dispatcher: its
|
|
5085
|
+
* session reads the subtasks, dispatches them with subagents, and is asked to
|
|
5086
|
+
* write their conclusions back with
|
|
5087
|
+
* `task_board_manage({action:'record-external-outcome'})` before it finishes.
|
|
5088
|
+
* A run that never wrote one back would leave those cards parked with no
|
|
5089
|
+
* record of what the parent decided about them, so once the RUN CARD's
|
|
5090
|
+
* execution reached a decisive terminal record, every outstanding descendant
|
|
5091
|
+
* this run opened no execution for inherits that verdict as an external
|
|
5092
|
+
* record.
|
|
5093
|
+
*
|
|
5094
|
+
* Idempotent by construction: a card that already carries an execution in
|
|
5095
|
+
* this run group (the fold owns it), an open execution (it is running on its
|
|
5096
|
+
* own), or a terminal record stamped after this run started (the dispatching
|
|
5097
|
+
* agent's own backfill, or an earlier pass of this one) is left alone. Only a
|
|
5098
|
+
* decisive verdict is inherited: a cancelled run judged nothing about the
|
|
5099
|
+
* subtasks, and a subtask already in the done column has nothing left to
|
|
5100
|
+
* inherit.
|
|
5101
|
+
* @param taskId - the card whose execution just settled.
|
|
5102
|
+
* @param executionId - that execution.
|
|
5103
|
+
* @param groupId - its run group.
|
|
5104
|
+
* @param now - clock instant (ms epoch).
|
|
5105
|
+
* @returns whether the document changed.
|
|
5106
|
+
*/
|
|
5107
|
+
inheritVerdictForDescendants(taskId, executionId, groupId, now) {
|
|
5108
|
+
const root = this.document.tasks.find((item) => item.id === taskId);
|
|
5109
|
+
if (root === void 0) return false;
|
|
5110
|
+
const execution = root.executions.find((entry) => entry.id === executionId);
|
|
5111
|
+
if (execution?.endedAt === void 0 || execution.result === void 0) return false;
|
|
5112
|
+
if (execution.result !== "succeeded" && execution.result !== "failed") return false;
|
|
5113
|
+
const verdict = execution.result;
|
|
5114
|
+
if (ancestorChain(this.document.tasks, root).some((ancestor) => ancestor.executions.some((entry) => entry.runGroupId === groupId))) return false;
|
|
5115
|
+
const descendants = new Set(outstandingDescendants(this.document.tasks, root.id, this.maxSubtaskDepth).map((task) => task.id));
|
|
5116
|
+
if (descendants.size === 0) return false;
|
|
5117
|
+
const note = `本次执行由父卡「${root.title}」统一判定,本卡未单独开会话执行;结论继承自父卡运行`;
|
|
5118
|
+
let changed = false;
|
|
5119
|
+
this.document.tasks = this.document.tasks.map((task) => {
|
|
5120
|
+
if (!descendants.has(task.id)) return task;
|
|
5121
|
+
if (task.executions.some((entry) => entry.runGroupId === groupId)) return task;
|
|
5122
|
+
if (task.executions.some((entry) => entry.endedAt === void 0)) return task;
|
|
5123
|
+
if (task.executions.some((entry) => entry.endedAt !== void 0 && entry.startedAt >= execution.startedAt)) return task;
|
|
5124
|
+
changed = true;
|
|
5125
|
+
const inherited = {
|
|
5126
|
+
id: crypto.randomUUID(),
|
|
5127
|
+
sessionId: void 0,
|
|
5128
|
+
startedAt: now,
|
|
5129
|
+
endedAt: now,
|
|
5130
|
+
result: verdict,
|
|
5131
|
+
error: note,
|
|
5132
|
+
initiatedBy: PARENT_RUN_INITIATOR_PREFIX + root.id,
|
|
5133
|
+
external: true,
|
|
5134
|
+
runGroupId: groupId
|
|
5135
|
+
};
|
|
5136
|
+
return {
|
|
5137
|
+
...task,
|
|
5138
|
+
status: settledStatus(task, verdict),
|
|
5139
|
+
updatedAt: now,
|
|
5140
|
+
executions: retainRecentExecutions([...task.executions, inherited])
|
|
5141
|
+
};
|
|
5142
|
+
});
|
|
5143
|
+
return changed;
|
|
5144
|
+
}
|
|
5145
|
+
attachSession(taskId, executionId, sessionId) {
|
|
5146
|
+
const now = this.now();
|
|
5147
|
+
if (this.document.tasks.find((item) => item.id === taskId)?.executions.find((entry) => entry.id === executionId)?.endedAt !== void 0) return;
|
|
5148
|
+
this.document.tasks = this.document.tasks.map((item) => item.id !== taskId ? item : {
|
|
5149
|
+
...item,
|
|
4363
5150
|
updatedAt: now,
|
|
4364
5151
|
executions: item.executions.map((entry) => entry.id === executionId ? {
|
|
4365
5152
|
...entry,
|
|
@@ -4409,7 +5196,7 @@ var HostTaskLedger = class {
|
|
|
4409
5196
|
frozenBy: initiator
|
|
4410
5197
|
}
|
|
4411
5198
|
};
|
|
4412
|
-
const result = applyCreateTask(this.document.tasks, input, now, action.id, this.maxSubtaskDepth, timeZone());
|
|
5199
|
+
const result = applyCreateTask(this.document.tasks, input, now, action.id, this.maxSubtaskDepth, timeZone(), this.cardDefaults());
|
|
4413
5200
|
if (result.task === void 0) throw new Error(result.error ?? "invalid task");
|
|
4414
5201
|
this.document.tasks = [...result.tasks];
|
|
4415
5202
|
break;
|
|
@@ -4489,7 +5276,7 @@ var HostTaskLedger = class {
|
|
|
4489
5276
|
if (task.archivedAt !== void 0) throw new Error("archived task is read-only");
|
|
4490
5277
|
if (!task.executions.some((entry) => entry.endedAt === void 0)) throw new Error("task has no open execution");
|
|
4491
5278
|
const reason = "execution closed manually by " + (initiator === void 0 || initiator === "" ? "the operator" : initiator) + ": no verdict was recorded";
|
|
4492
|
-
for (const member of
|
|
5279
|
+
for (const member of subtreeTasks(this.document.tasks, action.taskId, this.maxSubtaskDepth)) for (const execution of member.executions) {
|
|
4493
5280
|
if (execution.endedAt !== void 0) continue;
|
|
4494
5281
|
this.document.tasks = this.document.tasks.map((item) => item.id !== member.id ? item : settleExecution(item, execution.id, "cancelled", now, reason));
|
|
4495
5282
|
}
|
|
@@ -4553,16 +5340,19 @@ var HostTaskLedger = class {
|
|
|
4553
5340
|
this.document.tasks = [...result.tasks];
|
|
4554
5341
|
break;
|
|
4555
5342
|
}
|
|
5343
|
+
case "rework":
|
|
4556
5344
|
case "rerun":
|
|
4557
5345
|
case "run": {
|
|
4558
5346
|
const task = this.document.tasks.find((item) => item.id === action.taskId);
|
|
4559
5347
|
if (task?.archivedAt !== void 0) throw new Error("archived task is read-only");
|
|
4560
5348
|
if (task === void 0 || hasOpenExecution(task)) throw new Error("task is already running or missing");
|
|
5349
|
+
const rework = action.kind === "rework" ? this.reworkInput(task, action.instructions) : void 0;
|
|
4561
5350
|
const refusal = this.bindingRefusal(task);
|
|
4562
5351
|
if (refusal !== void 0) throw new Error(bindingRefusalMessage(refusal, this.sessionDefaultPermission, "run"));
|
|
4563
|
-
runs = this.
|
|
5352
|
+
runs = this.startRun(task, now, initiator, action.kind !== "run", void 0, rework);
|
|
4564
5353
|
break;
|
|
4565
5354
|
}
|
|
5355
|
+
default: throw new Error(`unknown task board action kind: ${String(action.kind)}`);
|
|
4566
5356
|
}
|
|
4567
5357
|
if (runs === void 0 || runs.length === 0) this.commit();
|
|
4568
5358
|
return {
|
|
@@ -4588,98 +5378,88 @@ var HostTaskLedger = class {
|
|
|
4588
5378
|
/**
|
|
4589
5379
|
* The binding that makes a run illegal, if any.
|
|
4590
5380
|
*
|
|
4591
|
-
*
|
|
4592
|
-
*
|
|
4593
|
-
*
|
|
4594
|
-
* teammate inherits that session's permission, so a subtask's OWN pin is
|
|
4595
|
-
* refused exactly when the Lead session does not already carry it — the
|
|
4596
|
-
* teammate could never be given that authority, and dropping the pin
|
|
4597
|
-
* silently would misreport the work (an inherited binding is the Lead's own
|
|
4598
|
-
* and stays allowed once the Lead is confirmed).
|
|
5381
|
+
* Only the card being run gets a session, so only ITS resolved binding gates
|
|
5382
|
+
* the run: a subtask's own elevated permission is that subtask's gate when the
|
|
5383
|
+
* subtask is run, and no longer blocks its parent from running.
|
|
4599
5384
|
* @param root - the task being run.
|
|
4600
5385
|
* @returns the first refusal, or undefined when the run may start.
|
|
4601
5386
|
*/
|
|
4602
5387
|
bindingRefusal(root) {
|
|
4603
|
-
|
|
4604
|
-
if (root.teamRun === true) {
|
|
4605
|
-
const lead = participants.find((participant) => participant.id === root.id);
|
|
4606
|
-
if (lead !== void 0 && requiresPermissionConfirmation(lead, this.sessionDefaultPermission)) return {
|
|
4607
|
-
kind: "root",
|
|
4608
|
-
title: lead.title
|
|
4609
|
-
};
|
|
4610
|
-
const leadPermission = effectivePermission(lead ?? root) ?? this.sessionDefaultPermission;
|
|
4611
|
-
const pinned = participants.find((participant) => {
|
|
4612
|
-
if (participant.id === root.id) return false;
|
|
4613
|
-
const raw = this.document.tasks.find((task) => task.id === participant.id);
|
|
4614
|
-
return raw !== void 0 && !permissionCarriedBy(leadPermission, effectivePermission(raw));
|
|
4615
|
-
});
|
|
4616
|
-
return pinned === void 0 ? void 0 : {
|
|
4617
|
-
kind: "subtask-pin",
|
|
4618
|
-
title: pinned.title
|
|
4619
|
-
};
|
|
4620
|
-
}
|
|
4621
|
-
const unconfirmed = participants.find((participant) => requiresPermissionConfirmation(participant, this.sessionDefaultPermission));
|
|
4622
|
-
if (unconfirmed === void 0) return void 0;
|
|
5388
|
+
if (!requiresPermissionConfirmation(resolveExecutionTargets(root, this.document.tasks, this.maxSubtaskDepth), this.sessionDefaultPermission)) return void 0;
|
|
4623
5389
|
return {
|
|
4624
|
-
kind:
|
|
4625
|
-
title:
|
|
5390
|
+
kind: root.parentId === void 0 ? "root" : "inherited",
|
|
5391
|
+
title: root.title
|
|
4626
5392
|
};
|
|
4627
5393
|
}
|
|
4628
5394
|
/**
|
|
4629
|
-
* The
|
|
4630
|
-
*
|
|
4631
|
-
*
|
|
4632
|
-
*
|
|
5395
|
+
* The rework block a rework request opens its execution with, or the refusal
|
|
5396
|
+
* that names why there is nothing to rework.
|
|
5397
|
+
*
|
|
5398
|
+
* Read from the ledger alone: a card that never ran, and a card whose runs
|
|
5399
|
+
* recorded no session, have no conversation to send the reviewer's
|
|
5400
|
+
* instructions into. Minting one would hand those instructions to an agent
|
|
5401
|
+
* that never saw the work being sent back, which is the opposite of what a
|
|
5402
|
+
* rework asks for.
|
|
5403
|
+
* @param task - the card being reworked.
|
|
5404
|
+
* @param instructions - the reviewer's instructions, already validated.
|
|
5405
|
+
* @returns the block recorded on the opened execution.
|
|
4633
5406
|
*/
|
|
4634
|
-
|
|
4635
|
-
|
|
5407
|
+
reworkInput(task, instructions) {
|
|
5408
|
+
if (task.executions.length === 0) throw new Error("task " + task.id + " has never executed; there is no run to rework");
|
|
5409
|
+
if ([...task.executions].reverse().find((entry) => entry.endedAt !== void 0 && entry.sessionId !== void 0)?.sessionId === void 0) throw new Error("task " + task.id + " records no execution session to continue");
|
|
5410
|
+
return { instructions };
|
|
4636
5411
|
}
|
|
4637
5412
|
/** Whether a task or any of its subtasks still has an open execution. */
|
|
4638
5413
|
subtreeHasOpenExecution(id) {
|
|
4639
|
-
return
|
|
5414
|
+
return subtreeTasks(this.document.tasks, id, this.maxSubtaskDepth).some((task) => hasOpenExecution(task));
|
|
5415
|
+
}
|
|
5416
|
+
/** The descendants of a card that still hold work, as the launch prompt names them. */
|
|
5417
|
+
outstandingDescendants(taskId) {
|
|
5418
|
+
return outstandingDescendants(this.document.tasks, taskId, this.maxSubtaskDepth);
|
|
5419
|
+
}
|
|
5420
|
+
/** Whether a card still has a subtask outside the done column. */
|
|
5421
|
+
hasOutstandingDescendants(taskId) {
|
|
5422
|
+
return hasOutstandingDescendants(this.document.tasks, taskId, this.maxSubtaskDepth);
|
|
4640
5423
|
}
|
|
4641
5424
|
/**
|
|
4642
|
-
* Open
|
|
4643
|
-
*
|
|
4644
|
-
*
|
|
4645
|
-
*
|
|
5425
|
+
* Open ONE execution for the requested card, under a fresh run group, and
|
|
5426
|
+
* commit the ledger once. The group stays single-member on purpose: a run
|
|
5427
|
+
* never opens a session for a subtask (that card's own agent dispatches
|
|
5428
|
+
* subagents inside this session), and the group id is what later lets the
|
|
5429
|
+
* settlement fold a HISTORICAL multi-member group it opened before this
|
|
5430
|
+
* behavior changed.
|
|
4646
5431
|
* @param root - the task the user ran.
|
|
4647
5432
|
* @param now - clock instant (ms epoch).
|
|
4648
5433
|
* @param initiator - the DSH session that asked for the run (audit only).
|
|
4649
5434
|
* @param rerun - true to reset the root to 'todo' before starting it.
|
|
4650
5435
|
* @param progress - when set, this run was a due occurrence and the root's
|
|
4651
5436
|
* rule is advanced (counter, next target, stop/skip record) in the same
|
|
4652
|
-
* atomic commit that opened the
|
|
5437
|
+
* atomic commit that opened the execution.
|
|
5438
|
+
* @param rework - the reviewer's instructions, when this run redoes previous
|
|
5439
|
+
* work; recorded on the execution it opens.
|
|
4653
5440
|
*/
|
|
4654
|
-
|
|
5441
|
+
startRun(root, now, initiator, rerun = false, progress, rework) {
|
|
4655
5442
|
const before = this.document.tasks;
|
|
5443
|
+
const [participant] = cascadeTargets(before, root.id);
|
|
5444
|
+
if (participant === void 0 || participant.archivedAt !== void 0) return [];
|
|
5445
|
+
if (hasOpenExecution(participant)) return [];
|
|
4656
5446
|
const groupId = crypto.randomUUID();
|
|
4657
|
-
const
|
|
4658
|
-
|
|
4659
|
-
const runs = [];
|
|
4660
|
-
for (const task of cascadeTargets(before, root.id, this.maxSubtaskDepth)) {
|
|
4661
|
-
if (task.archivedAt !== void 0) continue;
|
|
4662
|
-
if (hasOpenExecution(task)) continue;
|
|
4663
|
-
const opened = startExecution(rerun && task.id === root.id ? withStatus(task, "todo", now) : task, now, crypto.randomUUID(), initiator, groupId);
|
|
4664
|
-
started.set(task.id, opened.task);
|
|
4665
|
-
runs.push({
|
|
4666
|
-
task: resolveExecutionTargets(opened.task, before, this.maxSubtaskDepth),
|
|
4667
|
-
execution: opened.execution,
|
|
4668
|
-
...team && task.id !== root.id ? { dispatch: "teammate" } : {}
|
|
4669
|
-
});
|
|
4670
|
-
}
|
|
4671
|
-
if (runs.length === 0) return [];
|
|
4672
|
-
let tasks = before.map((task) => started.get(task.id) ?? task);
|
|
5447
|
+
const opened = startExecution(rerun ? withStatus(participant, "todo", now) : participant, now, crypto.randomUUID(), initiator, groupId, rework);
|
|
5448
|
+
let tasks = before.map((task) => task.id === participant.id ? opened.task : task);
|
|
4673
5449
|
if (progress !== void 0) tasks = applyScheduleProgress(tasks, root.id, progress, now);
|
|
4674
5450
|
this.document.tasks = [...tasks];
|
|
4675
5451
|
this.commit();
|
|
4676
|
-
return
|
|
5452
|
+
return [{
|
|
5453
|
+
task: resolveExecutionTargets(opened.task, before, this.maxSubtaskDepth),
|
|
5454
|
+
execution: opened.execution
|
|
5455
|
+
}];
|
|
4677
5456
|
}
|
|
4678
5457
|
/**
|
|
4679
|
-
* Finalize every
|
|
4680
|
-
* lineage: a member settles once its own outcome is recorded and none
|
|
4681
|
-
* group children is still open, and its verdict folds those children in
|
|
4682
|
-
* (failure dominates, then cancellation).
|
|
5458
|
+
* Finalize every stored run-group parent that is ready, walking from `taskId`
|
|
5459
|
+
* up the lineage: a member settles once its own outcome is recorded and none
|
|
5460
|
+
* of its group children is still open, and its verdict folds those children in
|
|
5461
|
+
* (failure dominates, then cancellation). A single-member group — every run
|
|
5462
|
+
* this Host opens now — settles on its own turn exactly as any plain run does.
|
|
4683
5463
|
*/
|
|
4684
5464
|
settleCascade(taskId, groupId, now) {
|
|
4685
5465
|
let changed = false;
|
|
@@ -4717,11 +5497,12 @@ var HostTaskLedger = class {
|
|
|
4717
5497
|
* members are all settled. The Host poll calls this on every tick, so a run
|
|
4718
5498
|
* can no longer be left in the running column by a settle nobody observed:
|
|
4719
5499
|
*
|
|
4720
|
-
* - A team run is governed by its Lead. Once the Lead's own outcome is
|
|
5500
|
+
* - A stored team run is governed by its Lead. Once the Lead's own outcome is
|
|
4721
5501
|
* recorded, its still-open members are settled with that verdict. A
|
|
4722
5502
|
* teammate is a durable member of the Team and may never report a turn of
|
|
4723
|
-
* its own, and without this the whole lineage waits on it forever.
|
|
4724
|
-
*
|
|
5503
|
+
* its own, and without this the whole lineage waits on it forever. New runs
|
|
5504
|
+
* never start a team, so this only closes a group the ledger already holds.
|
|
5505
|
+
* - A stored group parent whose members are all settled is finalized here even
|
|
4725
5506
|
* when the settle that completed the tree happened in another process, or
|
|
4726
5507
|
* was interrupted between its child write and its parent write.
|
|
4727
5508
|
*
|
|
@@ -4971,10 +5752,10 @@ var HostTaskLedger = class {
|
|
|
4971
5752
|
if (typeof parsed.schemaVersion === "number" && TASK_BOARD_MIGRATABLE_SCHEMA_VERSIONS.includes(parsed.schemaVersion)) try {
|
|
4972
5753
|
return this.migrateLegacyDocument(parsed);
|
|
4973
5754
|
} catch (error) {
|
|
4974
|
-
throw new Error(`ledger v${String(parsed.schemaVersion)} to
|
|
5755
|
+
throw new Error(`ledger v${String(parsed.schemaVersion)} to v7 migration failed; original file kept at ${this.file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
4975
5756
|
}
|
|
4976
5757
|
try {
|
|
4977
|
-
if (parsed.schemaVersion !==
|
|
5758
|
+
if (parsed.schemaVersion !== 7 || !Array.isArray(parsed.tasks)) throw new Error("unsupported ledger schema");
|
|
4978
5759
|
return this.normalizeDocument(parsed);
|
|
4979
5760
|
} catch (error) {
|
|
4980
5761
|
return this.recoverCorrupt(dir, existed, error);
|
|
@@ -4997,7 +5778,7 @@ var HostTaskLedger = class {
|
|
|
4997
5778
|
const sidecarLastTickAt = this.readSchedulerSidecar();
|
|
4998
5779
|
const lastTickAt = sidecarLastTickAt === void 0 || documentLastTickAt !== void 0 && documentLastTickAt >= sidecarLastTickAt ? documentLastTickAt : sidecarLastTickAt;
|
|
4999
5780
|
return {
|
|
5000
|
-
schemaVersion:
|
|
5781
|
+
schemaVersion: 7,
|
|
5001
5782
|
revision: Number.isSafeInteger(parsed.revision) && parsed.revision >= 0 ? parsed.revision : 0,
|
|
5002
5783
|
tasks,
|
|
5003
5784
|
scheduler: {
|
|
@@ -5023,7 +5804,7 @@ var HostTaskLedger = class {
|
|
|
5023
5804
|
if (existed) renameSync(this.file, `${this.file}.corrupt-${this.now()}-${process.pid}-${crypto.randomUUID()}`);
|
|
5024
5805
|
mkdirSync(dir, { recursive: true });
|
|
5025
5806
|
return {
|
|
5026
|
-
schemaVersion:
|
|
5807
|
+
schemaVersion: 7,
|
|
5027
5808
|
revision: 0,
|
|
5028
5809
|
tasks: [],
|
|
5029
5810
|
scheduler: {
|
|
@@ -5211,8 +5992,532 @@ function mostRecentWorkspaceId(items) {
|
|
|
5211
5992
|
}
|
|
5212
5993
|
return best?.id ?? items[0]?.id;
|
|
5213
5994
|
}
|
|
5995
|
+
/**
|
|
5996
|
+
* The failure text the Host records when a card names no workspace and the
|
|
5997
|
+
* deployment has none to resolve it to: the run is refused before any session
|
|
5998
|
+
* exists instead of letting `session.create` fall back to the Host process
|
|
5999
|
+
* working directory (the desktop app's profile directory), which is never the
|
|
6000
|
+
* project the user meant.
|
|
6001
|
+
*
|
|
6002
|
+
* A finished sentence rather than a code: the ledger stores it as the
|
|
6003
|
+
* execution's failure text, which the agent tools serve to a model and which
|
|
6004
|
+
* any client prints verbatim. It names the fix, not the mechanism.
|
|
6005
|
+
*/
|
|
6006
|
+
const MISSING_WORKSPACE_REASON = "this card pins no workspace; choose a workspace on the card before running";
|
|
6007
|
+
//#endregion
|
|
6008
|
+
//#region src/core/reasoning-effort.ts
|
|
6009
|
+
/** Trim one optional effort: blank text means "not set", like every other pinned target. */
|
|
6010
|
+
function normalizeReasoningEffort(value) {
|
|
6011
|
+
const trimmed = value?.trim();
|
|
6012
|
+
return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
|
|
6013
|
+
}
|
|
6014
|
+
/**
|
|
6015
|
+
* Complete one route through the host catalog: a qualified route must match its
|
|
6016
|
+
* provider group, and a bare model id matches the first group carrying it —
|
|
6017
|
+
* which is the provider the request then names.
|
|
6018
|
+
* @param catalog - the host model catalog, when this deployment serves one.
|
|
6019
|
+
* @param route - the route as the card pins it.
|
|
6020
|
+
* @returns the completed route with its reasoning metadata, or undefined when
|
|
6021
|
+
* the catalog declares no such model.
|
|
6022
|
+
*/
|
|
6023
|
+
function declaredRoute(catalog, route) {
|
|
6024
|
+
const groups = catalog?.groups ?? [];
|
|
6025
|
+
const matched = route.provider === void 0 || route.provider === "" ? groups.find((group) => group.models.some((model) => model.id === route.model)) : groups.find((group) => group.id === route.provider);
|
|
6026
|
+
const model = matched?.models.find((candidate) => candidate.id === route.model);
|
|
6027
|
+
if (matched === void 0 || model === void 0) return void 0;
|
|
6028
|
+
return {
|
|
6029
|
+
provider: matched.id,
|
|
6030
|
+
model: model.id,
|
|
6031
|
+
...model.reasoning === void 0 ? {} : { reasoning: model.reasoning }
|
|
6032
|
+
};
|
|
6033
|
+
}
|
|
6034
|
+
/**
|
|
6035
|
+
* Resolve the effort one execution sends.
|
|
6036
|
+
* @param requested - the card's stored effort (absent or blank = inherit).
|
|
6037
|
+
* @param catalog - the host model catalog, when this deployment serves one.
|
|
6038
|
+
* @param route - the route the execution will actually run at.
|
|
6039
|
+
* @returns the effort to send, or the dropped value that will not be sent.
|
|
6040
|
+
*/
|
|
6041
|
+
function resolveReasoningEffort(requested, catalog, route) {
|
|
6042
|
+
const effort = normalizeReasoningEffort(requested);
|
|
6043
|
+
if (effort === void 0) return {};
|
|
6044
|
+
if (route === void 0) return { dropped: effort };
|
|
6045
|
+
return declaredRoute(catalog, route)?.reasoning?.efforts.some((option) => option.id === effort) === true ? { effort } : { dropped: effort };
|
|
6046
|
+
}
|
|
6047
|
+
//#endregion
|
|
6048
|
+
//#region src/host/attachments.ts
|
|
6049
|
+
/**
|
|
6050
|
+
* Host-side attachment plumbing: the trusted upload path, the verification
|
|
6051
|
+
* against the official attachment storage, and the execution-time resolution
|
|
6052
|
+
* of a card's attachments into prompt parts.
|
|
6053
|
+
*
|
|
6054
|
+
* The board keeps METADATA in the ledger; the bytes live in the official
|
|
6055
|
+
* storage (`ctx.attachments`). This module is the only place that touches
|
|
6056
|
+
* both: it publishes bytes into the storage, proves a recorded claim against
|
|
6057
|
+
* it, and reads the objects back for an execution.
|
|
6058
|
+
*
|
|
6059
|
+
* The official storage has NO deletion API. Removing an attachment or deleting
|
|
6060
|
+
* a card therefore removes METADATA only: the stored object stays where it is.
|
|
6061
|
+
*/
|
|
6062
|
+
/**
|
|
6063
|
+
* One attachment failure, carrying the class the route maps to a status and a
|
|
6064
|
+
* message that never contains raw bytes or a host path.
|
|
6065
|
+
*/
|
|
6066
|
+
var TaskBoardAttachmentError = class extends Error {
|
|
6067
|
+
code;
|
|
6068
|
+
constructor(code, message, options) {
|
|
6069
|
+
super(message, options);
|
|
6070
|
+
this.code = code;
|
|
6071
|
+
this.name = "TaskBoardAttachmentError";
|
|
6072
|
+
}
|
|
6073
|
+
};
|
|
6074
|
+
/** The HTTP status one attachment failure class answers with. */
|
|
6075
|
+
function attachmentErrorStatus(code) {
|
|
6076
|
+
if (code === "invalid-request" || code === "invalid-image" || code === "unreadable") return 400;
|
|
6077
|
+
if (code === "unsupported-type") return 415;
|
|
6078
|
+
if (code === "too-large") return 413;
|
|
6079
|
+
if (code === "not-found") return 404;
|
|
6080
|
+
return 503;
|
|
6081
|
+
}
|
|
6082
|
+
/** Lowercase hex sha256 digest of the exact bytes. */
|
|
6083
|
+
function sha256Hex(bytes) {
|
|
6084
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
6085
|
+
}
|
|
6086
|
+
/** Whether a value names one of the raster media types the image path accepts. */
|
|
6087
|
+
function isImageMediaType(value) {
|
|
6088
|
+
return typeof value === "string" && TASK_ATTACHMENT_IMAGE_MEDIA_TYPES.includes(value.toLowerCase());
|
|
6089
|
+
}
|
|
6090
|
+
/**
|
|
6091
|
+
* Normalize a client-declared file media type: a well-formed type is kept
|
|
6092
|
+
* (lowercased), anything else falls back to the opaque binary type. The type
|
|
6093
|
+
* of a verbatim file is a declaration, not something the storage can prove.
|
|
6094
|
+
*/
|
|
6095
|
+
function normalizeFileMediaType(value) {
|
|
6096
|
+
if (typeof value !== "string") return "application/octet-stream";
|
|
6097
|
+
const trimmed = value.trim().toLowerCase();
|
|
6098
|
+
if (trimmed === "" || trimmed.length > 255) return "application/octet-stream";
|
|
6099
|
+
return /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/.test(trimmed) ? trimmed : "application/octet-stream";
|
|
6100
|
+
}
|
|
6101
|
+
/**
|
|
6102
|
+
* The canonical display name of an upload.
|
|
6103
|
+
*
|
|
6104
|
+
* The Host publishes the canonical name, and the ledger stores the same
|
|
6105
|
+
* string: the wire gate accepts only a name that already IS canonical, so a
|
|
6106
|
+
* client cannot rename an object into something the storage never saw. The
|
|
6107
|
+
* canonical form is single-line and free of any path part, which is what
|
|
6108
|
+
* makes it safe to place in an execution prompt.
|
|
6109
|
+
*/
|
|
6110
|
+
function sanitizeAttachmentName(value) {
|
|
6111
|
+
return canonicalAttachmentName(value);
|
|
6112
|
+
}
|
|
6113
|
+
/**
|
|
6114
|
+
* The per-image byte cap this deployment enforces: the board's own ceiling
|
|
6115
|
+
* lowered by the storage's own policy when that policy is stricter.
|
|
6116
|
+
*/
|
|
6117
|
+
function effectiveImageByteLimit(store) {
|
|
6118
|
+
const deployment = store?.imageLimits?.maxImageBytes;
|
|
6119
|
+
if (typeof deployment !== "number" || !Number.isFinite(deployment) || deployment <= 0) return TASK_ATTACHMENT_MAX_BYTES;
|
|
6120
|
+
return Math.min(TASK_ATTACHMENT_MAX_BYTES, deployment);
|
|
6121
|
+
}
|
|
6122
|
+
/**
|
|
6123
|
+
* Read a whole request body, refusing it the moment it grows past the cap.
|
|
6124
|
+
* The count is the ACTUAL byte length of the stream, not a declared length.
|
|
6125
|
+
*/
|
|
6126
|
+
async function readRequestBytes(req, limit) {
|
|
6127
|
+
const chunks = [];
|
|
6128
|
+
let size = 0;
|
|
6129
|
+
let overflow = false;
|
|
6130
|
+
for await (const chunk of req) {
|
|
6131
|
+
const buffer = chunk;
|
|
6132
|
+
size += buffer.length;
|
|
6133
|
+
if (size > limit) {
|
|
6134
|
+
overflow = true;
|
|
6135
|
+
chunks.length = 0;
|
|
6136
|
+
continue;
|
|
6137
|
+
}
|
|
6138
|
+
chunks.push(buffer);
|
|
6139
|
+
}
|
|
6140
|
+
if (overflow) throw new TaskBoardAttachmentError("too-large", `attachment exceeds the ${limit} byte limit`);
|
|
6141
|
+
return new Uint8Array(Buffer.concat(chunks));
|
|
6142
|
+
}
|
|
6143
|
+
/**
|
|
6144
|
+
* A byte stream that measures and digests what it yields.
|
|
6145
|
+
*
|
|
6146
|
+
* The file path streams the request straight into the official storage: the
|
|
6147
|
+
* bytes are never collected in memory, and the count and digest the board
|
|
6148
|
+
* records are the ones computed from the bytes that actually went in.
|
|
6149
|
+
*/
|
|
6150
|
+
var MeasuredStream = class {
|
|
6151
|
+
limit;
|
|
6152
|
+
hash = createHash("sha256");
|
|
6153
|
+
size = 0;
|
|
6154
|
+
finished = false;
|
|
6155
|
+
constructor(limit) {
|
|
6156
|
+
this.limit = limit;
|
|
6157
|
+
}
|
|
6158
|
+
/** The byte length seen so far. */
|
|
6159
|
+
get bytes() {
|
|
6160
|
+
return this.size;
|
|
6161
|
+
}
|
|
6162
|
+
/** The digest of the bytes seen so far; final once the stream ended. */
|
|
6163
|
+
digest() {
|
|
6164
|
+
return this.hash.digest("hex");
|
|
6165
|
+
}
|
|
6166
|
+
/** Whether the whole stream was consumed. */
|
|
6167
|
+
get complete() {
|
|
6168
|
+
return this.finished;
|
|
6169
|
+
}
|
|
6170
|
+
/** The chunks, refusing the stream the moment it grows past the cap. */
|
|
6171
|
+
async *chunks(source) {
|
|
6172
|
+
for await (const chunk of source) {
|
|
6173
|
+
this.size += chunk.byteLength;
|
|
6174
|
+
if (this.size > this.limit) throw new TaskBoardAttachmentError("too-large", `attachment exceeds the ${this.limit} byte limit`);
|
|
6175
|
+
this.hash.update(chunk);
|
|
6176
|
+
yield chunk;
|
|
6177
|
+
}
|
|
6178
|
+
this.finished = true;
|
|
6179
|
+
}
|
|
6180
|
+
};
|
|
6181
|
+
/**
|
|
6182
|
+
* The request body as a byte stream: the file path hands it straight to the
|
|
6183
|
+
* official storage, so the bytes are never collected in memory.
|
|
6184
|
+
*/
|
|
6185
|
+
function requestChunks(req) {
|
|
6186
|
+
return req;
|
|
6187
|
+
}
|
|
6188
|
+
/**
|
|
6189
|
+
* The image reference a recorded attachment stands for. The stored object is
|
|
6190
|
+
* addressed by its opaque identifier; the rest of the fields are the board's
|
|
6191
|
+
* own record of what the storage holds.
|
|
6192
|
+
*/
|
|
6193
|
+
function imageRefOf(attachment) {
|
|
6194
|
+
if (attachment.width === void 0 || attachment.height === void 0) throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.attachmentId} carries no image dimensions`);
|
|
6195
|
+
return {
|
|
6196
|
+
attachmentId: attachment.attachmentId,
|
|
6197
|
+
mediaType: attachment.mediaType,
|
|
6198
|
+
bytes: attachment.bytes,
|
|
6199
|
+
width: attachment.width,
|
|
6200
|
+
height: attachment.height,
|
|
6201
|
+
...attachment.name === "" ? {} : { name: attachment.name }
|
|
6202
|
+
};
|
|
6203
|
+
}
|
|
6204
|
+
/** The file reference a recorded attachment stands for. */
|
|
6205
|
+
function fileRefOf(attachment) {
|
|
6206
|
+
return {
|
|
6207
|
+
attachmentId: attachment.attachmentId,
|
|
6208
|
+
name: attachment.name,
|
|
6209
|
+
bytes: attachment.bytes
|
|
6210
|
+
};
|
|
6211
|
+
}
|
|
6212
|
+
/**
|
|
6213
|
+
* Publish one image into the official storage and describe it with
|
|
6214
|
+
* host-computed metadata.
|
|
6215
|
+
*
|
|
6216
|
+
* The image is validated before it is stored (the storage checks the decoded
|
|
6217
|
+
* bytes against the declared type), and the recorded digest is computed over
|
|
6218
|
+
* the NORMALIZED bytes the storage actually kept — not over what the client
|
|
6219
|
+
* sent — so the metadata and the object can never disagree.
|
|
6220
|
+
*/
|
|
6221
|
+
async function storeImage(store, data, name, mediaType) {
|
|
6222
|
+
if (!isImageMediaType(mediaType)) throw new TaskBoardAttachmentError("unsupported-type", `${mediaType} is not an accepted image type`);
|
|
6223
|
+
const limit = effectiveImageByteLimit(store);
|
|
6224
|
+
if (data.byteLength > limit) throw new TaskBoardAttachmentError("too-large", `image exceeds the ${limit} byte limit`);
|
|
6225
|
+
const type = mediaType.toLowerCase();
|
|
6226
|
+
try {
|
|
6227
|
+
await store.validateImage({
|
|
6228
|
+
data,
|
|
6229
|
+
mediaType: type,
|
|
6230
|
+
name
|
|
6231
|
+
});
|
|
6232
|
+
const ref = await store.saveImage({
|
|
6233
|
+
data,
|
|
6234
|
+
mediaType: type,
|
|
6235
|
+
name
|
|
6236
|
+
});
|
|
6237
|
+
const stored = await store.readImage(ref);
|
|
6238
|
+
return {
|
|
6239
|
+
kind: "image",
|
|
6240
|
+
attachmentId: String(ref.attachmentId),
|
|
6241
|
+
name: canonicalAttachmentName(stored.ref.name ?? name),
|
|
6242
|
+
bytes: stored.ref.bytes,
|
|
6243
|
+
mediaType: stored.ref.mediaType,
|
|
6244
|
+
sha256: sha256Hex(stored.data),
|
|
6245
|
+
width: stored.ref.width,
|
|
6246
|
+
height: stored.ref.height
|
|
6247
|
+
};
|
|
6248
|
+
} catch (error) {
|
|
6249
|
+
throw asAttachmentError(error);
|
|
6250
|
+
}
|
|
6251
|
+
}
|
|
6252
|
+
/**
|
|
6253
|
+
* Publish one file into the official storage and describe it with
|
|
6254
|
+
* host-computed metadata. The digest is computed from the streamed bytes, so
|
|
6255
|
+
* the record and the stored object agree by construction.
|
|
6256
|
+
*/
|
|
6257
|
+
async function storeFile(store, chunks, name, mediaType, signal) {
|
|
6258
|
+
const measured = new MeasuredStream(TASK_ATTACHMENT_MAX_BYTES);
|
|
6259
|
+
try {
|
|
6260
|
+
const ref = await store.saveFileStream({
|
|
6261
|
+
data: measured.chunks(chunks),
|
|
6262
|
+
...signal === void 0 ? {} : { signal },
|
|
6263
|
+
name
|
|
6264
|
+
});
|
|
6265
|
+
const sha256 = measured.digest();
|
|
6266
|
+
return {
|
|
6267
|
+
attachment: {
|
|
6268
|
+
kind: "file",
|
|
6269
|
+
attachmentId: String(ref.attachmentId),
|
|
6270
|
+
name: canonicalAttachmentName(ref.name || name),
|
|
6271
|
+
bytes: ref.bytes,
|
|
6272
|
+
mediaType: normalizeFileMediaType(mediaType),
|
|
6273
|
+
sha256
|
|
6274
|
+
},
|
|
6275
|
+
bytes: measured.bytes,
|
|
6276
|
+
sha256
|
|
6277
|
+
};
|
|
6278
|
+
} catch (error) {
|
|
6279
|
+
throw asAttachmentError(error);
|
|
6280
|
+
}
|
|
6281
|
+
}
|
|
6282
|
+
/**
|
|
6283
|
+
* Map an official attachment failure onto the board's own classes, so a
|
|
6284
|
+
* storage fault reads as "the storage is unavailable" and a rejected image
|
|
6285
|
+
* reads as "the image is not acceptable" — never as an internal error.
|
|
6286
|
+
*/
|
|
6287
|
+
function asAttachmentError(error) {
|
|
6288
|
+
if (error instanceof TaskBoardAttachmentError) return error;
|
|
6289
|
+
const code = error?.code;
|
|
6290
|
+
if (typeof code === "string") {
|
|
6291
|
+
if (code === "IMAGE_TOO_LARGE" || code === "IMAGES_TOO_LARGE") return new TaskBoardAttachmentError("too-large", "the attachment exceeds the deployment size limit", { cause: error });
|
|
6292
|
+
if (code === "TOO_MANY_IMAGES") return new TaskBoardAttachmentError("too-large", "the attachment exceeds the deployment image count limit", { cause: error });
|
|
6293
|
+
if (code === "UNSUPPORTED_IMAGE_TYPE" || code === "IMAGE_TYPE_MISMATCH") return new TaskBoardAttachmentError("unsupported-type", "the attachment is not an accepted image type", { cause: error });
|
|
6294
|
+
if (code === "INVALID_IMAGE" || code === "INVALID_IMAGE_BASE64" || code === "IMAGE_TOO_MANY_PIXELS" || code === "IMAGE_DIMENSION_TOO_LARGE") return new TaskBoardAttachmentError("invalid-image", "the attachment is not a readable image", { cause: error });
|
|
6295
|
+
if (code === "ATTACHMENT_NOT_FOUND") return new TaskBoardAttachmentError("not-found", "the attachment is not in the storage", { cause: error });
|
|
6296
|
+
if (code === "ATTACHMENT_READ_FAILED" || code === "ATTACHMENT_CORRUPT") return new TaskBoardAttachmentError("unreadable", "the stored attachment could not be read back", { cause: error });
|
|
6297
|
+
if (code === "ATTACHMENT_WRITE_FAILED" || code === "ATTACHMENT_FILES_UNSUPPORTED" || code === "ATTACHMENT_PROJECTION_UNSUPPORTED") return new TaskBoardAttachmentError("storage-unavailable", "the attachment storage refused the write", { cause: error });
|
|
6298
|
+
}
|
|
6299
|
+
return new TaskBoardAttachmentError("storage-unavailable", "the attachment storage is unavailable", { cause: error });
|
|
6300
|
+
}
|
|
6301
|
+
/**
|
|
6302
|
+
* Prove every recorded attachment against the official storage: an image is
|
|
6303
|
+
* read back and compared, a file is streamed and its digest recomputed.
|
|
6304
|
+
*
|
|
6305
|
+
* A reference the storage does not know, and a record whose metadata does not
|
|
6306
|
+
* match the stored bytes, are both a refusal: the action never reaches the
|
|
6307
|
+
* ledger, so a spoofed client claim can never become a stored fact.
|
|
6308
|
+
*/
|
|
6309
|
+
async function verifyAttachments(store, attachments) {
|
|
6310
|
+
assertImageBatchWithinLimits(store, attachments);
|
|
6311
|
+
for (const attachment of attachments) if (attachment.kind === "image") await verifyImage(store, attachment);
|
|
6312
|
+
else await verifyFile(store, attachment);
|
|
6313
|
+
}
|
|
6314
|
+
/**
|
|
6315
|
+
* The official image batch limits of a deployment: how many images one
|
|
6316
|
+
* message may carry and how many bytes they may add up to.
|
|
6317
|
+
*
|
|
6318
|
+
* The board's own caps (eight attachments, 10 MiB each, 32 MiB per card) stay
|
|
6319
|
+
* in force; the deployment's policy can only lower them, and it governs the
|
|
6320
|
+
* IMAGES of one card because that is what one prompt carries.
|
|
6321
|
+
*/
|
|
6322
|
+
function officialImageBatchLimits(store) {
|
|
6323
|
+
const limits = store?.imageLimits;
|
|
6324
|
+
const maxImages = typeof limits?.maxImagesPerMessage === "number" && limits.maxImagesPerMessage > 0 ? Math.min(8, limits.maxImagesPerMessage) : 8;
|
|
6325
|
+
const maxMessageImageBytes = typeof limits?.maxMessageImageBytes === "number" && limits.maxMessageImageBytes > 0 ? Math.min(TASK_ATTACHMENT_TOTAL_MAX_BYTES, limits.maxMessageImageBytes) : TASK_ATTACHMENT_TOTAL_MAX_BYTES;
|
|
6326
|
+
return {
|
|
6327
|
+
maxImages,
|
|
6328
|
+
maxImageBytes: effectiveImageByteLimit(store),
|
|
6329
|
+
maxMessageImageBytes
|
|
6330
|
+
};
|
|
6331
|
+
}
|
|
6332
|
+
/**
|
|
6333
|
+
* Refuse a card whose images exceed the deployment's per-message budget.
|
|
6334
|
+
*
|
|
6335
|
+
* The check counts only the images: plain files travel as paths and never
|
|
6336
|
+
* enter the prompt admission, so they are not part of that budget.
|
|
6337
|
+
* @param store - the official attachment storage.
|
|
6338
|
+
* @param attachments - the card's attachments.
|
|
6339
|
+
*/
|
|
6340
|
+
function assertImageBatchWithinLimits(store, attachments) {
|
|
6341
|
+
if (store === void 0) return;
|
|
6342
|
+
const limits = officialImageBatchLimits(store);
|
|
6343
|
+
const images = attachments.filter((attachment) => attachment.kind === "image");
|
|
6344
|
+
if (images.length > limits.maxImages) throw new TaskBoardAttachmentError("too-large", `the card carries ${images.length} images, the deployment admits ${limits.maxImages} per message`);
|
|
6345
|
+
const bytes = images.reduce((sum, attachment) => sum + attachment.bytes, 0);
|
|
6346
|
+
if (bytes > limits.maxMessageImageBytes) throw new TaskBoardAttachmentError("too-large", `the card's images total ${bytes} bytes, the deployment admits ${limits.maxMessageImageBytes} per message`);
|
|
6347
|
+
for (const image of images) if (image.bytes > limits.maxImageBytes) throw new TaskBoardAttachmentError("too-large", `an image exceeds the deployment limit of ${limits.maxImageBytes} bytes`);
|
|
6348
|
+
}
|
|
6349
|
+
/** Read one image back and compare it with the recorded metadata. */
|
|
6350
|
+
async function verifyImage(store, attachment) {
|
|
6351
|
+
let stored;
|
|
6352
|
+
try {
|
|
6353
|
+
stored = await store.readImage(imageRefOf(attachment));
|
|
6354
|
+
} catch (error) {
|
|
6355
|
+
throw asAttachmentError(error);
|
|
6356
|
+
}
|
|
6357
|
+
const digest = sha256Hex(stored.data);
|
|
6358
|
+
const storedName = stored.ref.name;
|
|
6359
|
+
if (stored.ref.bytes !== attachment.bytes || stored.ref.mediaType !== attachment.mediaType || digest !== attachment.sha256 || stored.ref.width !== attachment.width || stored.ref.height !== attachment.height || storedName !== void 0 && canonicalAttachmentName(storedName) !== attachment.name) throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.attachmentId} does not match the stored object`);
|
|
6360
|
+
}
|
|
6361
|
+
/** Stream one file back and recompute its digest. */
|
|
6362
|
+
async function verifyFile(store, attachment) {
|
|
6363
|
+
const hash = createHash("sha256");
|
|
6364
|
+
let bytes = 0;
|
|
6365
|
+
try {
|
|
6366
|
+
for await (const chunk of store.readFileStream(fileRefOf(attachment))) {
|
|
6367
|
+
bytes += chunk.byteLength;
|
|
6368
|
+
hash.update(chunk);
|
|
6369
|
+
}
|
|
6370
|
+
} catch (error) {
|
|
6371
|
+
throw asAttachmentError(error);
|
|
6372
|
+
}
|
|
6373
|
+
if (bytes !== attachment.bytes || hash.digest("hex") !== attachment.sha256) throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.attachmentId} does not match the stored object`);
|
|
6374
|
+
}
|
|
6375
|
+
/**
|
|
6376
|
+
* The limits the board publishes for its attachments: the board's own caps,
|
|
6377
|
+
* lowered by the deployment's image policy where that policy is stricter.
|
|
6378
|
+
*/
|
|
6379
|
+
function publishedAttachmentLimits(store) {
|
|
6380
|
+
const batch = officialImageBatchLimits(store);
|
|
6381
|
+
return {
|
|
6382
|
+
maxAttachments: 8,
|
|
6383
|
+
maxBytes: TASK_ATTACHMENT_MAX_BYTES,
|
|
6384
|
+
maxTotalBytes: TASK_ATTACHMENT_TOTAL_MAX_BYTES,
|
|
6385
|
+
maxImages: batch.maxImages,
|
|
6386
|
+
maxImageBytes: batch.maxImageBytes,
|
|
6387
|
+
maxMessageImageBytes: batch.maxMessageImageBytes
|
|
6388
|
+
};
|
|
6389
|
+
}
|
|
6390
|
+
/**
|
|
6391
|
+
* Resolve a card's attachments for one execution: images become prompt image
|
|
6392
|
+
* parts, files become readable host paths.
|
|
6393
|
+
*
|
|
6394
|
+
* Every execution resolves the attachments afresh — the recorded metadata is
|
|
6395
|
+
* never trusted on its own, and a file whose host path is missing or
|
|
6396
|
+
* unreadable fails the run instead of being silently dropped.
|
|
6397
|
+
*/
|
|
6398
|
+
async function resolveExecutionAttachments(store, attachments) {
|
|
6399
|
+
assertImageBatchWithinLimits(store, attachments);
|
|
6400
|
+
const images = [];
|
|
6401
|
+
const files = [];
|
|
6402
|
+
for (const attachment of attachments) {
|
|
6403
|
+
if (attachment.kind === "image") {
|
|
6404
|
+
let stored;
|
|
6405
|
+
try {
|
|
6406
|
+
stored = await store.readImage(imageRefOf(attachment));
|
|
6407
|
+
} catch (error) {
|
|
6408
|
+
throw asAttachmentError(error);
|
|
6409
|
+
}
|
|
6410
|
+
images.push({
|
|
6411
|
+
type: "image",
|
|
6412
|
+
mediaType: stored.ref.mediaType,
|
|
6413
|
+
data: Buffer.from(stored.data).toString("base64"),
|
|
6414
|
+
name: attachment.name
|
|
6415
|
+
});
|
|
6416
|
+
continue;
|
|
6417
|
+
}
|
|
6418
|
+
const ref = fileRefOf(attachment);
|
|
6419
|
+
let path;
|
|
6420
|
+
try {
|
|
6421
|
+
path = store.fileHostPath(ref);
|
|
6422
|
+
} catch (error) {
|
|
6423
|
+
throw asAttachmentError(error);
|
|
6424
|
+
}
|
|
6425
|
+
if (path === void 0 || path === "") throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.attachmentId} has no readable path in this deployment`);
|
|
6426
|
+
try {
|
|
6427
|
+
accessSync(path, constants.R_OK);
|
|
6428
|
+
} catch (error) {
|
|
6429
|
+
throw new TaskBoardAttachmentError("unreadable", `attachment ${attachment.name} is not readable in this deployment`, { cause: error });
|
|
6430
|
+
}
|
|
6431
|
+
files.push({
|
|
6432
|
+
name: attachment.name,
|
|
6433
|
+
path,
|
|
6434
|
+
bytes: attachment.bytes,
|
|
6435
|
+
mediaType: attachment.mediaType
|
|
6436
|
+
});
|
|
6437
|
+
}
|
|
6438
|
+
return {
|
|
6439
|
+
images,
|
|
6440
|
+
files
|
|
6441
|
+
};
|
|
6442
|
+
}
|
|
6443
|
+
/**
|
|
6444
|
+
* The attachment section of an execution prompt: the readable paths of the
|
|
6445
|
+
* card's files, marked read-only.
|
|
6446
|
+
*
|
|
6447
|
+
* It is a section of its own — never folded into the handover preamble — so
|
|
6448
|
+
* the two kinds of reference stay distinguishable to the reading agent.
|
|
6449
|
+
*/
|
|
6450
|
+
function attachmentPromptPreamble(files) {
|
|
6451
|
+
if (files.length === 0) return void 0;
|
|
6452
|
+
return `附件文件(任务看板附件,只读路径;请直接读取这些文件,不要修改或移动它们):
|
|
6453
|
+
${files.map((file) => `- ${file.name}(${file.path},${file.bytes} 字节,${file.mediaType})`).join("\n")}`;
|
|
6454
|
+
}
|
|
6455
|
+
/**
|
|
6456
|
+
* Refuse an execution whose route cannot read images.
|
|
6457
|
+
*
|
|
6458
|
+
* The check uses the ACTUAL route of the session the run is about to use and
|
|
6459
|
+
* the model's own declared input modalities. A route that declares no
|
|
6460
|
+
* modalities is UNKNOWN, and an unknown route is allowed: the official model
|
|
6461
|
+
* catalog publishes no modality information, so it cannot answer this
|
|
6462
|
+
* question, and refusing on its silence would block every image run.
|
|
6463
|
+
*/
|
|
6464
|
+
async function assertRouteAcceptsImages(resolveModelInfo, provider, model) {
|
|
6465
|
+
if (resolveModelInfo === void 0) return;
|
|
6466
|
+
const modalities = (await resolveModelInfo(provider, model))?.inputModalities;
|
|
6467
|
+
if (!Array.isArray(modalities)) return;
|
|
6468
|
+
if (!modalities.includes("image")) throw new Error(`the model route ${provider}/${model} does not accept image input`);
|
|
6469
|
+
}
|
|
5214
6470
|
//#endregion
|
|
5215
6471
|
//#region src/host-runner.ts
|
|
6472
|
+
/**
|
|
6473
|
+
* Mint the in-process owner peer this plugin's Host calls speak for.
|
|
6474
|
+
*
|
|
6475
|
+
* The 0.2.1 gateway made `peer` mandatory on every request, and the
|
|
6476
|
+
* authorization layer reads only `peer.principal`: a principal of
|
|
6477
|
+
* `{ kind: 'owner' }` is how host-local code states that the call IS the local
|
|
6478
|
+
* user driving their own Host, so the gateway answers it directly instead of
|
|
6479
|
+
* running a remote-access decision (only non-owner principals are judged).
|
|
6480
|
+
* That is exactly the task board's position — it creates, renames, prompts,
|
|
6481
|
+
* and reads sessions as the Host itself, which before 0.2.1 was the implicit
|
|
6482
|
+
* privilege of every in-process caller. The board claims owner explicitly, and
|
|
6483
|
+
* only ever inside its own Host process: no wire field can set a principal,
|
|
6484
|
+
* and this plugin never forwards a browser-supplied one.
|
|
6485
|
+
*
|
|
6486
|
+
* `interactions` stays `'none'`: the board only invokes methods and opens the
|
|
6487
|
+
* short `session/follow` stream. The gateway's interactions check gates
|
|
6488
|
+
* exactly the forwarded-event endpoints (opening an event stream, answering a
|
|
6489
|
+
* waterfall), which this caller never touches; an `'answer'` peer would
|
|
6490
|
+
* additionally receive forwarded Host events, a capability the board neither
|
|
6491
|
+
* needs nor wants.
|
|
6492
|
+
*
|
|
6493
|
+
* The peer's signal aborts once `ctx` disposes, so streams opened for it end
|
|
6494
|
+
* with the plugin fiber, and `dispose()` is idempotent with racing calls
|
|
6495
|
+
* sharing one completion. The id carries no credential — the protocol fixes
|
|
6496
|
+
* `principal` as the only identity persisted in a session log — so a fresh
|
|
6497
|
+
* unique id per mount is sufficient.
|
|
6498
|
+
*/
|
|
6499
|
+
function createOwnerPeer(ctx) {
|
|
6500
|
+
const controller = new AbortController();
|
|
6501
|
+
let completion;
|
|
6502
|
+
const peer = {
|
|
6503
|
+
id: `task-board-owner:${crypto.randomUUID()}`,
|
|
6504
|
+
ctx,
|
|
6505
|
+
principal: { kind: "owner" },
|
|
6506
|
+
signal: controller.signal,
|
|
6507
|
+
interactions: "none",
|
|
6508
|
+
dispose() {
|
|
6509
|
+
if (completion === void 0) {
|
|
6510
|
+
controller.abort();
|
|
6511
|
+
completion = Promise.resolve();
|
|
6512
|
+
}
|
|
6513
|
+
return completion;
|
|
6514
|
+
}
|
|
6515
|
+
};
|
|
6516
|
+
ctx.effect(() => () => {
|
|
6517
|
+
peer.dispose();
|
|
6518
|
+
}, "task-board owner peer");
|
|
6519
|
+
return peer;
|
|
6520
|
+
}
|
|
5216
6521
|
function sessionAddress(sessionId) {
|
|
5217
6522
|
return {
|
|
5218
6523
|
kind: "session",
|
|
@@ -5254,7 +6559,7 @@ const SERVICE_UNAVAILABLE_BACKOFF_MS = 2e3;
|
|
|
5254
6559
|
*/
|
|
5255
6560
|
const HISTORY_PAGE_LIMIT = 100;
|
|
5256
6561
|
/** One-line text of a gateway or stream failure, for a decideable reason. */
|
|
5257
|
-
function failureText(error) {
|
|
6562
|
+
function failureText$1(error) {
|
|
5258
6563
|
return error instanceof Error ? error.message : String(error);
|
|
5259
6564
|
}
|
|
5260
6565
|
function delay(ms) {
|
|
@@ -5287,19 +6592,17 @@ function escapeProvenanceDelimiter(value) {
|
|
|
5287
6592
|
return value.replaceAll("来源声明 开始", "来源声明·开始").replaceAll("来源声明 结束", "来源声明·结束");
|
|
5288
6593
|
}
|
|
5289
6594
|
/**
|
|
5290
|
-
* The
|
|
5291
|
-
*
|
|
5292
|
-
*
|
|
6595
|
+
* The dispatch section: this run is the card's own session, and the card still
|
|
6596
|
+
* has unfinished subtasks. The Host opens no session for them, so the prompt
|
|
6597
|
+
* states what the session must do itself — read each card, dispatch subagents
|
|
6598
|
+
* in dependency order, and write the conclusions back before finishing. A card
|
|
6599
|
+
* with no outstanding descendant gets no section at all.
|
|
5293
6600
|
*/
|
|
5294
|
-
function
|
|
5295
|
-
const
|
|
5296
|
-
if (
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
return `本任务是 Agent Team 的 Lead:本次运行不额外开启独立会话,以下 ${peers.length} 个子任务成员已在本会话中作为 teammate 启动。用 list_agents / send_message / wait_agent 协调它们,用任务看板工具读写它们在看板上的卡片:\n${lines.join("\n")}`;
|
|
5300
|
-
}
|
|
5301
|
-
const lines = peers.map((peer) => `- ${escapeProvenanceDelimiter(peer.title)}(任务 ${peer.id})`);
|
|
5302
|
-
return `本次运行同时并发开启 ${peers.length} 个独立 DSH 会话执行下列子任务成员(可用 task_board_* 工具查看它们的进度):\n${lines.join("\n")}`;
|
|
6601
|
+
function dispatchPromptPreamble(context) {
|
|
6602
|
+
const descendants = context.descendants ?? [];
|
|
6603
|
+
if (descendants.length === 0) return void 0;
|
|
6604
|
+
const lines = descendants.map((descendant) => `- ${escapeProvenanceDelimiter(descendant.title)}(任务 ${descendant.id},状态 ${descendant.status})`);
|
|
6605
|
+
return `本卡还有 ${descendants.length} 个未完成的子任务,本次执行不会为它们额外开启会话,由你在本会话内自行派发:\n${lines.join("\n")}\n先用 task_board_get 读取每张子卡的内容与执行目标,再用 subagent 按依赖顺序派发(互不依赖的可以并发),完工前用 task_board_manage({action:'record-external-outcome', result, initiatedBy, summary}) 一次性回填各子卡的结论。`;
|
|
5303
6606
|
}
|
|
5304
6607
|
/**
|
|
5305
6608
|
* The scheduled-run section: this execution was triggered by the card's
|
|
@@ -5317,6 +6620,18 @@ function schedulePromptPreamble(context) {
|
|
|
5317
6620
|
return `本次执行由任务看板的定时规则自动触发:触发时间 ${stamp}(UTC),规则时区 ${schedule.timeZone},cron 表达式 ${schedule.cron}。需要判断「今天」「现在」或计算时间窗口时,以该时区的触发时间为准。`;
|
|
5318
6621
|
}
|
|
5319
6622
|
/**
|
|
6623
|
+
* The rework section: this execution continues the card's own conversation
|
|
6624
|
+
* because a reviewer sent the previous attempt back. It states both halves the
|
|
6625
|
+
* agent must not guess — that the earlier work is the starting point, and what
|
|
6626
|
+
* the reviewer actually wants changed — and marks the instruction block with a
|
|
6627
|
+
* delimiter pair, so reviewer text cannot pass for board text.
|
|
6628
|
+
*/
|
|
6629
|
+
function reworkPromptPreamble(context) {
|
|
6630
|
+
const rework = context.rework;
|
|
6631
|
+
if (rework === void 0) return void 0;
|
|
6632
|
+
return `本次执行是同一会话上的返工:上一轮的结果被人工审阅打回,请在已完成的工作上继续修改,不要从头重做。返工意见 开始\n${escapeProvenanceDelimiter(rework.instructions)}\n返工意见 结束`;
|
|
6633
|
+
}
|
|
6634
|
+
/**
|
|
5320
6635
|
* Build the execution prompt for one task.
|
|
5321
6636
|
* @param task - the task being launched.
|
|
5322
6637
|
* @param context - the run's other members, for the execution-shape section.
|
|
@@ -5328,9 +6643,11 @@ function promptText(task, context = {}) {
|
|
|
5328
6643
|
const handoverPreamble = handover === void 0 || handover.references.length === 0 ? void 0 : `交接包引用(来自任务看板续接卡片,冻结于 ${new Date(handover.bundledAt).toISOString()}):\n${handover.references.map((reference) => `- ${reference}`).join("\n")}`;
|
|
5329
6644
|
const preambles = [
|
|
5330
6645
|
tagPromptPreamble(task),
|
|
6646
|
+
context.files === void 0 ? void 0 : attachmentPromptPreamble(context.files),
|
|
5331
6647
|
handoverPreamble,
|
|
5332
6648
|
schedulePromptPreamble(context),
|
|
5333
|
-
|
|
6649
|
+
dispatchPromptPreamble(context),
|
|
6650
|
+
reworkPromptPreamble(context)
|
|
5334
6651
|
].filter((part) => part !== void 0);
|
|
5335
6652
|
const preamble = preambles.length === 0 ? void 0 : preambles.join("\n\n");
|
|
5336
6653
|
const freeze = task.freeze;
|
|
@@ -5413,42 +6730,51 @@ function invokeWireArgs(namespace, method, request) {
|
|
|
5413
6730
|
if (namespace === "session" && method === "list") return { _request: request };
|
|
5414
6731
|
return { request };
|
|
5415
6732
|
}
|
|
5416
|
-
var HostExecutionRunner = class {
|
|
6733
|
+
var HostExecutionRunner = class HostExecutionRunner {
|
|
5417
6734
|
gateway;
|
|
5418
6735
|
commands;
|
|
5419
6736
|
workspaceRegistry;
|
|
5420
|
-
|
|
5421
|
-
/**
|
|
6737
|
+
faces;
|
|
6738
|
+
/**
|
|
6739
|
+
* Newest event sequence per session whose COMPLETE history walk (reaching
|
|
6740
|
+
* the execution boundary) found no matching execution end. A later walk may
|
|
6741
|
+
* trust everything at or below it and examine only newer records.
|
|
6742
|
+
*/
|
|
5422
6743
|
scanMemos = /* @__PURE__ */ new Map();
|
|
5423
6744
|
unavailableAttempts;
|
|
5424
6745
|
unavailableBackoffMs;
|
|
6746
|
+
/**
|
|
6747
|
+
* The peer every request speaks for. Production passes the peer bound to the
|
|
6748
|
+
* plugin fiber; a bare runner (unit tests around fake gateways) gets one
|
|
6749
|
+
* bound to a fresh root context instead.
|
|
6750
|
+
*/
|
|
6751
|
+
ownerPeer;
|
|
5425
6752
|
unsupportedSessionListWarned = false;
|
|
5426
|
-
constructor(gateway, commands, workspaceRegistry, unavailableRetry,
|
|
6753
|
+
constructor(gateway, commands, workspaceRegistry, unavailableRetry, ownerPeer, faces = {}) {
|
|
5427
6754
|
this.gateway = gateway;
|
|
5428
6755
|
this.commands = commands;
|
|
5429
6756
|
this.workspaceRegistry = workspaceRegistry;
|
|
5430
|
-
this.
|
|
6757
|
+
this.faces = faces;
|
|
5431
6758
|
this.unavailableAttempts = unavailableRetry?.attempts ?? SERVICE_UNAVAILABLE_ATTEMPTS;
|
|
5432
6759
|
this.unavailableBackoffMs = unavailableRetry?.backoffMs ?? SERVICE_UNAVAILABLE_BACKOFF_MS;
|
|
6760
|
+
this.ownerPeer = ownerPeer ?? createOwnerPeer(new Context());
|
|
5433
6761
|
}
|
|
5434
6762
|
invoke(namespace, method, request, signal) {
|
|
5435
|
-
const peer = this.operatorPeer?.();
|
|
5436
6763
|
return this.gateway.invoke({
|
|
5437
6764
|
namespace,
|
|
5438
6765
|
method,
|
|
5439
6766
|
args: invokeWireArgs(namespace, method, request),
|
|
5440
|
-
|
|
6767
|
+
peer: this.ownerPeer,
|
|
5441
6768
|
...signal === void 0 ? {} : { signal }
|
|
5442
6769
|
});
|
|
5443
6770
|
}
|
|
5444
6771
|
stream(namespace, method, request, signal) {
|
|
5445
6772
|
if (!("stream" in this.gateway) || this.gateway.stream === void 0) throw new Error("gateway stream is unavailable");
|
|
5446
|
-
const peer = this.operatorPeer?.();
|
|
5447
6773
|
return this.gateway.stream({
|
|
5448
6774
|
namespace,
|
|
5449
6775
|
method,
|
|
5450
6776
|
args: { request },
|
|
5451
|
-
|
|
6777
|
+
peer: this.ownerPeer,
|
|
5452
6778
|
...signal === void 0 ? {} : { signal }
|
|
5453
6779
|
});
|
|
5454
6780
|
}
|
|
@@ -5475,29 +6801,32 @@ var HostExecutionRunner = class {
|
|
|
5475
6801
|
*/
|
|
5476
6802
|
async launch(task, options = {}) {
|
|
5477
6803
|
const workspaceId = task.handover?.workspaceId ?? task.workspaceId ?? this.recentWorkspaceId();
|
|
5478
|
-
const mode = task.handover?.mode ?? task.mode;
|
|
6804
|
+
const mode = options.agentPreset ?? task.handover?.mode ?? task.mode;
|
|
5479
6805
|
const permission = task.handover?.permission ?? task.permission;
|
|
5480
6806
|
if (workspaceId !== void 0 && this.workspaceRegistry !== void 0) {
|
|
5481
6807
|
if (!this.workspaceRegistry.list().some((item) => item.id === workspaceId)) throw new Error("workspace not found: " + workspaceId);
|
|
5482
6808
|
}
|
|
5483
6809
|
if (mode !== void 0) {
|
|
5484
6810
|
const preset = (await this.invoke("agentPresets", "list", {})).presets?.find((item) => item.id === mode);
|
|
6811
|
+
if (preset === void 0 && options.agentPreset !== void 0) throw new Error("agent preset not found: " + mode + " (a card with unfinished subtasks runs under the liangshen preset, which this deployment does not serve)");
|
|
5485
6812
|
if (preset === void 0) throw new Error("agent preset not found: " + mode);
|
|
5486
6813
|
if (preset.broken !== void 0) throw new Error("agent preset is unavailable: " + preset.broken);
|
|
6814
|
+
if (options.agentPreset !== void 0 && this.faces.legacyAgentTeams?.() === true) throw new Error(LEGACY_AGENT_TEAMS_REASON);
|
|
5487
6815
|
}
|
|
5488
6816
|
const reused = options.reuseSessionId;
|
|
5489
6817
|
if (reused !== void 0) {
|
|
5490
6818
|
try {
|
|
5491
6819
|
options.onSession?.(reused);
|
|
5492
6820
|
await this.assertReusedPreset(reused, mode);
|
|
5493
|
-
await this.pinAndPrompt(reused, task, permission, options.promptContext, options.onGoalArmed, options.goalEnabled === true);
|
|
6821
|
+
await this.pinAndPrompt(reused, task, permission, options.promptContext, options.onGoalArmed, options.goalEnabled === true, options.catalog);
|
|
5494
6822
|
} catch (error) {
|
|
5495
6823
|
throw new SessionLaunchError(reused, error);
|
|
5496
6824
|
}
|
|
5497
6825
|
return reused;
|
|
5498
6826
|
}
|
|
6827
|
+
if (workspaceId === void 0) throw new Error(MISSING_WORKSPACE_REASON);
|
|
5499
6828
|
const sessionId = (await this.invoke("session", "create", {
|
|
5500
|
-
|
|
6829
|
+
workspaceId,
|
|
5501
6830
|
...mode === void 0 ? {} : { agentPreset: mode }
|
|
5502
6831
|
})).sessionId;
|
|
5503
6832
|
options.onSession?.(sessionId);
|
|
@@ -5506,13 +6835,35 @@ var HostExecutionRunner = class {
|
|
|
5506
6835
|
sessionId,
|
|
5507
6836
|
title: task.title
|
|
5508
6837
|
});
|
|
5509
|
-
await this.pinAndPrompt(sessionId, task, permission, options.promptContext, options.onGoalArmed, options.goalEnabled === true);
|
|
6838
|
+
await this.pinAndPrompt(sessionId, task, permission, options.promptContext, options.onGoalArmed, options.goalEnabled === true, options.catalog);
|
|
5510
6839
|
} catch (error) {
|
|
5511
6840
|
throw new SessionLaunchError(sessionId, error);
|
|
5512
6841
|
}
|
|
5513
6842
|
return sessionId;
|
|
5514
6843
|
}
|
|
5515
6844
|
/**
|
|
6845
|
+
* Queue one follow-up user message into an existing execution session.
|
|
6846
|
+
*
|
|
6847
|
+
* This is the same `session/prompt` call a launch makes, with none of the
|
|
6848
|
+
* launch pins: a follow-up continues a conversation the board already
|
|
6849
|
+
* composed, so it must not re-assert the permission, rename the session, or
|
|
6850
|
+
* switch the model. The message is queued behind whatever that session is
|
|
6851
|
+
* doing, which is what lets a caller reach a run that is still working.
|
|
6852
|
+
* @param sessionId - the session the card's execution recorded.
|
|
6853
|
+
* @param text - the message to deliver, already validated by the caller.
|
|
6854
|
+
*/
|
|
6855
|
+
async followUp(sessionId, text) {
|
|
6856
|
+
await this.invoke("session", "prompt", {
|
|
6857
|
+
sessionId,
|
|
6858
|
+
requestId: "task-board-follow-up-" + crypto.randomUUID(),
|
|
6859
|
+
mode: "queue",
|
|
6860
|
+
content: [{
|
|
6861
|
+
type: "text",
|
|
6862
|
+
text
|
|
6863
|
+
}]
|
|
6864
|
+
});
|
|
6865
|
+
}
|
|
6866
|
+
/**
|
|
5516
6867
|
* Fail closed when a reused session records a different Agent preset than
|
|
5517
6868
|
* the one this task pins.
|
|
5518
6869
|
*
|
|
@@ -5533,45 +6884,127 @@ var HostExecutionRunner = class {
|
|
|
5533
6884
|
throw new Error("reused session " + sessionId + " was composed from agent preset " + (typeof recorded === "string" ? "\"" + recorded + "\"" : "an unreadable value") + ", but the task pins \"" + pinned + "\"");
|
|
5534
6885
|
}
|
|
5535
6886
|
/**
|
|
6887
|
+
* Split a `provider/model` pin. A pin without a provider keeps only the model
|
|
6888
|
+
* id: the provider is the one the host catalog declares for it, resolved at
|
|
6889
|
+
* launch because the session wire contract requires a provider.
|
|
6890
|
+
*/
|
|
6891
|
+
static pinnedRoute(model) {
|
|
6892
|
+
const raw = model?.trim();
|
|
6893
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
6894
|
+
const slash = raw.indexOf("/");
|
|
6895
|
+
if (slash < 0) return { model: raw };
|
|
6896
|
+
const provider = raw.slice(0, slash).trim();
|
|
6897
|
+
const modelId = raw.slice(slash + 1).trim();
|
|
6898
|
+
if (provider === "" || modelId === "") return void 0;
|
|
6899
|
+
return {
|
|
6900
|
+
provider,
|
|
6901
|
+
model: modelId
|
|
6902
|
+
};
|
|
6903
|
+
}
|
|
6904
|
+
/**
|
|
6905
|
+
* The route a card that pins no model actually runs at: the session's own
|
|
6906
|
+
* recorded selection (the durable fold the GUI reads; `next` is the pending
|
|
6907
|
+
* user choice, `lastUsed` what the last request consumed), or — for a session
|
|
6908
|
+
* that has selected none yet, which is exactly a session that would start at
|
|
6909
|
+
* the deployment default — the host default from the catalog.
|
|
6910
|
+
*
|
|
6911
|
+
* A route that cannot be READ is undefined and the effort is not sent:
|
|
6912
|
+
* falling back to the host default there would silently switch the model of a
|
|
6913
|
+
* session this run only meant to continue.
|
|
6914
|
+
*/
|
|
6915
|
+
async sessionRoute(sessionId, catalog) {
|
|
6916
|
+
let selection;
|
|
6917
|
+
try {
|
|
6918
|
+
const projections = await this.invoke("session", "projections", { sessionId });
|
|
6919
|
+
selection = projections?.values?.modelSelection?.next ?? projections?.values?.modelSelection?.lastUsed;
|
|
6920
|
+
} catch (error) {
|
|
6921
|
+
console.warn("[dsh-task-board] session/projections failed while resolving the execution model route", error);
|
|
6922
|
+
return;
|
|
6923
|
+
}
|
|
6924
|
+
if (typeof selection?.provider === "string" && selection.provider !== "" && typeof selection.model === "string" && selection.model !== "") return {
|
|
6925
|
+
provider: selection.provider,
|
|
6926
|
+
model: selection.model
|
|
6927
|
+
};
|
|
6928
|
+
return catalog?.default === void 0 ? void 0 : {
|
|
6929
|
+
provider: catalog.default.provider,
|
|
6930
|
+
model: catalog.default.model
|
|
6931
|
+
};
|
|
6932
|
+
}
|
|
6933
|
+
/**
|
|
5536
6934
|
* Re-assert the pinned execution contract on a session and queue the task
|
|
5537
6935
|
* prompt. Shared by the fresh-session and reuse paths so both apply exactly
|
|
5538
|
-
* the same permission/model pins before the prompt.
|
|
6936
|
+
* the same permission/model/effort pins before the prompt. A session that
|
|
6937
|
+
* refuses a selection carrying a catalog-confirmed effort throws here, so the
|
|
6938
|
+
* prompt is never queued behind a run at the wrong level.
|
|
5539
6939
|
*/
|
|
5540
|
-
async pinAndPrompt(sessionId, task, permission, context = {}, onGoalArmed, goalEnabled = false) {
|
|
6940
|
+
async pinAndPrompt(sessionId, task, permission, context = {}, onGoalArmed, goalEnabled = false, catalog) {
|
|
5541
6941
|
if (permission !== void 0) {
|
|
5542
6942
|
if (this.commands === void 0) throw new Error("permission command dispatcher is unavailable");
|
|
5543
6943
|
const command = await this.commands.execute(sessionId, "/permission " + permission, AbortSignal.timeout(3e4));
|
|
5544
6944
|
if (command === void 0) throw new Error("permission command was not acknowledged");
|
|
5545
6945
|
if (command.kind !== "success") throw new Error(command.text ?? "permission command failed");
|
|
5546
6946
|
}
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
6947
|
+
const requestedEffort = normalizeReasoningEffort(task.reasoningEffort);
|
|
6948
|
+
const pinned = HostExecutionRunner.pinnedRoute(task.model);
|
|
6949
|
+
const attachments = task.attachments ?? [];
|
|
6950
|
+
const carriesImages = attachments.some((attachment) => attachment.kind === "image");
|
|
6951
|
+
const route = pinned ?? (requestedEffort === void 0 && !carriesImages ? void 0 : await this.sessionRoute(sessionId, catalog));
|
|
6952
|
+
if (route !== void 0) {
|
|
6953
|
+
const routeLabel = `${route.provider === void 0 ? "" : route.provider + "/"}${route.model}`;
|
|
6954
|
+
const decision = resolveReasoningEffort(requestedEffort, catalog, route);
|
|
6955
|
+
if (decision.dropped !== void 0) console.warn(`[dsh-task-board] model route ${routeLabel} does not declare reasoning effort "${decision.dropped}"; session ${sessionId} runs at the model default`);
|
|
6956
|
+
const declared = declaredRoute(catalog, route);
|
|
6957
|
+
const provider = declared?.provider ?? route.provider;
|
|
6958
|
+
const modelId = declared?.model ?? route.model;
|
|
6959
|
+
if (carriesImages && provider !== void 0 && modelId !== void 0) await assertRouteAcceptsImages(this.faces.llm?.(), provider, modelId);
|
|
5552
6960
|
try {
|
|
5553
6961
|
await this.invoke("session", "selectModel", {
|
|
5554
6962
|
sessionId,
|
|
5555
|
-
...provider ? {
|
|
5556
|
-
model: modelId
|
|
6963
|
+
...provider === void 0 ? {} : { provider },
|
|
6964
|
+
model: modelId,
|
|
6965
|
+
...decision.effort === void 0 ? {} : { reasoningEffort: decision.effort }
|
|
5557
6966
|
});
|
|
5558
6967
|
} catch (modelError) {
|
|
5559
|
-
|
|
6968
|
+
if (decision.effort !== void 0) throw new Error(`session ${sessionId} refused the model selection "${provider === void 0 ? modelId : provider + "/" + modelId}" with reasoning effort "${decision.effort}": ` + (modelError instanceof Error ? modelError.message : String(modelError)));
|
|
6969
|
+
console.warn(`[dsh-task-board] failed to select model "${provider === void 0 ? modelId : provider + "/" + modelId}" for session ${sessionId}, falling back to default:`, modelError);
|
|
5560
6970
|
}
|
|
5561
6971
|
}
|
|
6972
|
+
const resolved = await this.resolveAttachments(attachments);
|
|
6973
|
+
const promptContext = resolved.files.length === 0 ? context : {
|
|
6974
|
+
...context,
|
|
6975
|
+
files: resolved.files
|
|
6976
|
+
};
|
|
5562
6977
|
await this.invoke("session", "prompt", {
|
|
5563
6978
|
sessionId,
|
|
5564
6979
|
requestId: "task-board-" + crypto.randomUUID(),
|
|
5565
6980
|
mode: "queue",
|
|
5566
6981
|
content: [{
|
|
5567
6982
|
type: "text",
|
|
5568
|
-
text: promptText(task,
|
|
5569
|
-
}]
|
|
6983
|
+
text: promptText(task, promptContext)
|
|
6984
|
+
}, ...resolved.images]
|
|
5570
6985
|
});
|
|
5571
|
-
const armed = await this.armGoal(sessionId, task,
|
|
6986
|
+
const armed = await this.armGoal(sessionId, task, promptContext, goalEnabled);
|
|
5572
6987
|
onGoalArmed?.(armed);
|
|
5573
6988
|
}
|
|
5574
6989
|
/**
|
|
6990
|
+
* Resolve a card's attachments for one execution.
|
|
6991
|
+
*
|
|
6992
|
+
* A card without attachments resolves to nothing, even in a deployment that
|
|
6993
|
+
* serves no attachment storage at all. A card WITH attachments cannot run
|
|
6994
|
+
* without the storage: the run fails with a readable reason instead of
|
|
6995
|
+
* silently dropping the attachment and running the card as if it carried
|
|
6996
|
+
* none.
|
|
6997
|
+
*/
|
|
6998
|
+
async resolveAttachments(attachments) {
|
|
6999
|
+
if (attachments.length === 0) return {
|
|
7000
|
+
images: [],
|
|
7001
|
+
files: []
|
|
7002
|
+
};
|
|
7003
|
+
const store = this.faces.attachments?.();
|
|
7004
|
+
if (store === void 0) throw new Error("this deployment serves no attachment storage");
|
|
7005
|
+
return await resolveExecutionAttachments(store, attachments);
|
|
7006
|
+
}
|
|
7007
|
+
/**
|
|
5575
7008
|
* Read the host's model catalog: the default route an unconfigured session
|
|
5576
7009
|
* starts at, and each provider's models with the reasoning metadata its
|
|
5577
7010
|
* adapter exposes. The acceptance settings card and the frozen contract both
|
|
@@ -5766,15 +7199,18 @@ var HostExecutionRunner = class {
|
|
|
5766
7199
|
return {
|
|
5767
7200
|
outcome: "pending",
|
|
5768
7201
|
unreadable: true,
|
|
5769
|
-
reason: "session/follow failed: " + failureText(error)
|
|
7202
|
+
reason: "session/follow failed: " + failureText$1(error)
|
|
5770
7203
|
};
|
|
5771
7204
|
}
|
|
5772
7205
|
const openingEvents = opening.records.map((record) => ({ event: recordEvent(record) }));
|
|
5773
7206
|
const newestSeq = openingEvents.reduce((newest, entry) => newest === void 0 ? entry.event.seq : Math.max(newest, entry.event.seq), void 0);
|
|
5774
|
-
|
|
7207
|
+
const scannedThrough = this.scanMemos.get(sessionId);
|
|
7208
|
+
if (newestSeq !== void 0 && scannedThrough === newestSeq) return { outcome: "pending" };
|
|
7209
|
+
const oldestOpeningSeq = openingEvents.reduce((oldest, entry) => oldest === void 0 ? entry.event.seq : Math.min(oldest, entry.event.seq), void 0);
|
|
7210
|
+
const coveredThrough = scannedThrough !== void 0 && oldestOpeningSeq !== void 0 && oldestOpeningSeq <= scannedThrough;
|
|
5775
7211
|
const events = [...openingEvents];
|
|
5776
7212
|
let beforeSeq;
|
|
5777
|
-
let reachedExecutionBoundary = !opening.hasMore;
|
|
7213
|
+
let reachedExecutionBoundary = !opening.hasMore || coveredThrough;
|
|
5778
7214
|
for (let page = 0; page < HISTORY_PAGE_LIMIT && !reachedExecutionBoundary; page += 1) {
|
|
5779
7215
|
let history;
|
|
5780
7216
|
try {
|
|
@@ -5789,17 +7225,17 @@ var HostExecutionRunner = class {
|
|
|
5789
7225
|
return {
|
|
5790
7226
|
outcome: "pending",
|
|
5791
7227
|
unreadable: true,
|
|
5792
|
-
reason: "session/page failed: " + failureText(error)
|
|
7228
|
+
reason: "session/page failed: " + failureText$1(error)
|
|
5793
7229
|
};
|
|
5794
7230
|
}
|
|
5795
7231
|
const pageEntries = pageEvents(history);
|
|
5796
7232
|
events.push(...pageEntries);
|
|
5797
7233
|
const oldestTime = pageEntries.reduce((oldest, entry) => oldest === void 0 ? entry.event.time : Math.min(oldest, entry.event.time), void 0);
|
|
5798
|
-
|
|
7234
|
+
const oldestSeq = pageEntries.reduce((oldest, entry) => oldest === void 0 ? entry.event.seq : Math.min(oldest, entry.event.seq), void 0);
|
|
7235
|
+
if (!history.hasMore || oldestTime !== void 0 && oldestTime <= startedAt || scannedThrough !== void 0 && oldestSeq !== void 0 && oldestSeq <= scannedThrough) {
|
|
5799
7236
|
reachedExecutionBoundary = true;
|
|
5800
7237
|
break;
|
|
5801
7238
|
}
|
|
5802
|
-
const oldestSeq = pageEntries.reduce((oldest, entry) => oldest === void 0 ? entry.event.seq : Math.min(oldest, entry.event.seq), void 0);
|
|
5803
7239
|
if (oldestSeq === void 0 || oldestSeq === beforeSeq) return { outcome: "pending" };
|
|
5804
7240
|
beforeSeq = oldestSeq;
|
|
5805
7241
|
}
|
|
@@ -5814,14 +7250,21 @@ var HostExecutionRunner = class {
|
|
|
5814
7250
|
return { outcome: "pending" };
|
|
5815
7251
|
}
|
|
5816
7252
|
this.scanMemos.delete(sessionId);
|
|
7253
|
+
const closing = executionSummaryOf(events.map((entry) => entry.event), startedAt);
|
|
7254
|
+
const carried = closing === void 0 ? {} : { summary: closing };
|
|
5817
7255
|
const reason = nonCompletedTurnEnd(turnEnd.event.data);
|
|
5818
|
-
if (reason === void 0) return
|
|
7256
|
+
if (reason === void 0) return {
|
|
7257
|
+
...await this.goalVerdict(sessionId) ?? { outcome: "succeeded" },
|
|
7258
|
+
...carried
|
|
7259
|
+
};
|
|
5819
7260
|
return reason === "error" ? {
|
|
5820
7261
|
outcome: "failed",
|
|
5821
|
-
error: "agent turn ended with an error"
|
|
7262
|
+
error: "agent turn ended with an error",
|
|
7263
|
+
...carried
|
|
5822
7264
|
} : {
|
|
5823
7265
|
outcome: "failed",
|
|
5824
|
-
error: "agent turn ended without completing: " + reason
|
|
7266
|
+
error: "agent turn ended without completing: " + reason,
|
|
7267
|
+
...carried
|
|
5825
7268
|
};
|
|
5826
7269
|
}
|
|
5827
7270
|
};
|
|
@@ -6128,6 +7571,71 @@ var PowerInhibitor = class {
|
|
|
6128
7571
|
}
|
|
6129
7572
|
};
|
|
6130
7573
|
//#endregion
|
|
7574
|
+
//#region src/core/wire-projection.ts
|
|
7575
|
+
/**
|
|
7576
|
+
* Keys stripped from an integration payload at every depth, as whole keys and
|
|
7577
|
+
* compared case-insensitively.
|
|
7578
|
+
*
|
|
7579
|
+
* `leaseToken` is the name `dsh-task-board-team` writes for its mirror-card
|
|
7580
|
+
* lease and `lease_token` the snake spelling, while the rest are the generic
|
|
7581
|
+
* names a bearer credential hides under. The match is the whole key rather than
|
|
7582
|
+
* a substring: a payload field that merely mentions one of these words while
|
|
7583
|
+
* holding something the provider's own UI renders is not a credential and must
|
|
7584
|
+
* keep travelling.
|
|
7585
|
+
*/
|
|
7586
|
+
const CREDENTIAL_KEYS = /* @__PURE__ */ new Set([
|
|
7587
|
+
"leasetoken",
|
|
7588
|
+
"lease_token",
|
|
7589
|
+
"token",
|
|
7590
|
+
"secret",
|
|
7591
|
+
"password",
|
|
7592
|
+
"apikey",
|
|
7593
|
+
"credential"
|
|
7594
|
+
]);
|
|
7595
|
+
/** Copy one JSON value with every credential-keyed entry removed, at any depth. */
|
|
7596
|
+
function withoutCredentials(value) {
|
|
7597
|
+
if (Array.isArray(value)) return value.map(withoutCredentials);
|
|
7598
|
+
if (value === null || typeof value !== "object") return value;
|
|
7599
|
+
const copy = {};
|
|
7600
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
7601
|
+
if (CREDENTIAL_KEYS.has(key.toLowerCase())) continue;
|
|
7602
|
+
copy[key] = withoutCredentials(entry);
|
|
7603
|
+
}
|
|
7604
|
+
return copy;
|
|
7605
|
+
}
|
|
7606
|
+
/**
|
|
7607
|
+
* The card as the wire may show it: the ledger record with its integration
|
|
7608
|
+
* entries copied and stripped.
|
|
7609
|
+
*
|
|
7610
|
+
* A card that carries no integrations is returned untouched, so a provider that
|
|
7611
|
+
* stores nothing sees exactly the record the board has always published.
|
|
7612
|
+
* @param task - the ledger record about to be serialized.
|
|
7613
|
+
* @returns the projected record; the ledger object is never mutated.
|
|
7614
|
+
*/
|
|
7615
|
+
function projectTaskForWire(task) {
|
|
7616
|
+
const stored = task.integrations;
|
|
7617
|
+
if (stored === void 0) return task;
|
|
7618
|
+
const integrations = {};
|
|
7619
|
+
for (const [id, payload] of Object.entries(stored)) integrations[id] = withoutCredentials(payload);
|
|
7620
|
+
return {
|
|
7621
|
+
...task,
|
|
7622
|
+
integrations
|
|
7623
|
+
};
|
|
7624
|
+
}
|
|
7625
|
+
/**
|
|
7626
|
+
* The snapshot as every read path serializes it: the HTTP `state` answer, the
|
|
7627
|
+
* HTTP `action` answer, and the remote bridge's `board.snapshot` all start from
|
|
7628
|
+
* the object this returns.
|
|
7629
|
+
* @param snapshot - the snapshot the Host service built from its live state.
|
|
7630
|
+
* @returns the same snapshot with each card projected through {@link projectTaskForWire}.
|
|
7631
|
+
*/
|
|
7632
|
+
function projectSnapshotForWire(snapshot) {
|
|
7633
|
+
return {
|
|
7634
|
+
...snapshot,
|
|
7635
|
+
tasks: snapshot.tasks.map(projectTaskForWire)
|
|
7636
|
+
};
|
|
7637
|
+
}
|
|
7638
|
+
//#endregion
|
|
6131
7639
|
//#region src/host/extension-registry.ts
|
|
6132
7640
|
/** Diagnosable refusal raised by the registry and the capability face. */
|
|
6133
7641
|
var TaskBoardExtensionError = class extends Error {
|
|
@@ -6186,10 +7694,50 @@ function mergePayload(current, patch) {
|
|
|
6186
7694
|
function readPayload(value) {
|
|
6187
7695
|
return isTaskBoardExtensionPayload(value) ? value : void 0;
|
|
6188
7696
|
}
|
|
7697
|
+
/** One-line text of a delivery failure, for a diagnosable refusal. */
|
|
7698
|
+
function failureText(error) {
|
|
7699
|
+
return error instanceof Error ? error.message : String(error);
|
|
7700
|
+
}
|
|
7701
|
+
/**
|
|
7702
|
+
* Validate one free text a provider pushes into an execution. Blank text would
|
|
7703
|
+
* queue an empty turn, and an unbounded one would let a single provider call
|
|
7704
|
+
* inject an arbitrarily large instruction, so both are refused here rather
|
|
7705
|
+
* than at the gateway.
|
|
7706
|
+
*/
|
|
7707
|
+
function extensionText(value, what) {
|
|
7708
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
7709
|
+
if (text === "") throw new TaskBoardExtensionError("invalid-text", `a ${what} must be a non-blank string`);
|
|
7710
|
+
if (text.length > 4e3) throw new TaskBoardExtensionError("invalid-text", `a ${what} is limited to ${TASK_BOARD_MESSAGE_MAX_LENGTH} characters`);
|
|
7711
|
+
return text;
|
|
7712
|
+
}
|
|
7713
|
+
/**
|
|
7714
|
+
* The session a follow-up message goes to, or the refusal that says why there
|
|
7715
|
+
* is none. The open execution owns the answer while one is running: delivering
|
|
7716
|
+
* into the previous conversation instead would answer a question the current
|
|
7717
|
+
* run never asked.
|
|
7718
|
+
*/
|
|
7719
|
+
function followUpTarget(task) {
|
|
7720
|
+
if (task.executions.length === 0) return {
|
|
7721
|
+
refusal: "not-executed",
|
|
7722
|
+
message: `task ${task.id} has never executed, so it has no session to deliver to`
|
|
7723
|
+
};
|
|
7724
|
+
const open = [...task.executions].reverse().find((record) => record.endedAt === void 0);
|
|
7725
|
+
if (open !== void 0) return open.sessionId === void 0 ? {
|
|
7726
|
+
refusal: "session-unreachable",
|
|
7727
|
+
message: `the current execution of task ${task.id} has not attached a session yet`
|
|
7728
|
+
} : { sessionId: open.sessionId };
|
|
7729
|
+
const settled = [...task.executions].reverse().find((record) => record.sessionId !== void 0);
|
|
7730
|
+
return settled?.sessionId === void 0 ? {
|
|
7731
|
+
refusal: "session-unreachable",
|
|
7732
|
+
message: `task ${task.id} records no execution session to deliver to`
|
|
7733
|
+
} : { sessionId: settled.sessionId };
|
|
7734
|
+
}
|
|
6189
7735
|
var TaskBoardExtensionRegistry = class {
|
|
6190
7736
|
entries = /* @__PURE__ */ new Map();
|
|
6191
7737
|
ledger;
|
|
6192
7738
|
applyAction;
|
|
7739
|
+
followUpDelivery;
|
|
7740
|
+
reworkApply;
|
|
6193
7741
|
now;
|
|
6194
7742
|
uuid;
|
|
6195
7743
|
logger;
|
|
@@ -6200,6 +7748,8 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6200
7748
|
constructor(options) {
|
|
6201
7749
|
this.ledger = options.ledger;
|
|
6202
7750
|
this.applyAction = options.apply;
|
|
7751
|
+
this.followUpDelivery = options.followUp;
|
|
7752
|
+
this.reworkApply = options.rework;
|
|
6203
7753
|
this.now = options.now ?? Date.now;
|
|
6204
7754
|
this.uuid = options.uuid ?? (() => crypto.randomUUID());
|
|
6205
7755
|
this.logger = options.logger ?? DEFAULT_LOGGER;
|
|
@@ -6403,8 +7953,14 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6403
7953
|
create: (draft, options) => this.createTask(entry, draft, options),
|
|
6404
7954
|
patchContent: (taskId, patch) => this.patchContent(entry, taskId, patch),
|
|
6405
7955
|
setStatus: (taskId, status, initiator) => this.setStatus(entry, taskId, status, initiator),
|
|
6406
|
-
linked: () => this.linkedTasks(entry)
|
|
7956
|
+
linked: () => this.linkedTasks(entry),
|
|
7957
|
+
rework: (taskId, instructions, initiator) => {
|
|
7958
|
+
this.rework(entry, taskId, instructions, initiator);
|
|
7959
|
+
}
|
|
6407
7960
|
},
|
|
7961
|
+
sessions: { followUp: async (taskId, text) => {
|
|
7962
|
+
await this.followUp(entry, taskId, text);
|
|
7963
|
+
} },
|
|
6408
7964
|
integration: {
|
|
6409
7965
|
read: (taskId) => {
|
|
6410
7966
|
assertActive("read");
|
|
@@ -6445,6 +8001,9 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6445
8001
|
...draft.status === void 0 ? {} : { status: draft.status },
|
|
6446
8002
|
...draft.parentId === void 0 ? {} : { parentId: draft.parentId },
|
|
6447
8003
|
...draft.workspaceId === void 0 ? {} : { workspaceId: draft.workspaceId },
|
|
8004
|
+
...draft.mode === void 0 ? {} : { mode: draft.mode },
|
|
8005
|
+
...draft.model === void 0 ? {} : { model: draft.model },
|
|
8006
|
+
...draft.reasoningEffort === void 0 ? {} : { reasoningEffort: draft.reasoningEffort },
|
|
6448
8007
|
...payload === void 0 ? {} : { integrations: { [entry.extension.id]: payload } },
|
|
6449
8008
|
...options?.hidden === true ? { hidden: true } : {}
|
|
6450
8009
|
}
|
|
@@ -6455,9 +8014,7 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6455
8014
|
patchContent(entry, taskId, patch) {
|
|
6456
8015
|
this.assertActive(entry, "patch content");
|
|
6457
8016
|
if (this.applyAction === void 0) throw new TaskBoardExtensionError("unavailable", "this deployment serves no action applier");
|
|
6458
|
-
|
|
6459
|
-
if (task === void 0) throw new TaskBoardExtensionError("task-not-found", `no task with id ${taskId}`);
|
|
6460
|
-
if (!canEditTaskContent(task)) throw new TaskBoardExtensionError("content-frozen", `task ${taskId} has started executing; its content is read-only`);
|
|
8017
|
+
if (!canEditTaskContent(this.requireTask(taskId))) throw new TaskBoardExtensionError("content-frozen", `task ${taskId} has started executing; its content is read-only`);
|
|
6461
8018
|
if ([
|
|
6462
8019
|
"title",
|
|
6463
8020
|
"description",
|
|
@@ -6479,6 +8036,57 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6479
8036
|
status
|
|
6480
8037
|
}, initiator);
|
|
6481
8038
|
}
|
|
8039
|
+
/**
|
|
8040
|
+
* Queue one follow-up message into the session of a card's current or most
|
|
8041
|
+
* recent execution.
|
|
8042
|
+
*
|
|
8043
|
+
* A running card is the point of the capability, so an open execution is not
|
|
8044
|
+
* a refusal: the message is queued behind the turn that is already going. What
|
|
8045
|
+
* IS refused is a card with no conversation to deliver into, and a session
|
|
8046
|
+
* this Host no longer reaches — the delivery refuses, and that refusal must
|
|
8047
|
+
* reach the provider as such instead of looking like a silent success.
|
|
8048
|
+
*/
|
|
8049
|
+
async followUp(entry, taskId, text) {
|
|
8050
|
+
this.assertActive(entry, "deliver a follow-up message");
|
|
8051
|
+
const task = this.requireTask(taskId);
|
|
8052
|
+
const message = extensionText(text, "follow-up message");
|
|
8053
|
+
if (task.archivedAt !== void 0) throw new TaskBoardExtensionError("task-archived", `task ${taskId} is archived; an archived card's execution is closed`);
|
|
8054
|
+
const target = followUpTarget(task);
|
|
8055
|
+
if ("refusal" in target) throw new TaskBoardExtensionError(target.refusal, target.message);
|
|
8056
|
+
if (this.followUpDelivery === void 0) throw new TaskBoardExtensionError("unavailable", "this deployment serves no session delivery");
|
|
8057
|
+
try {
|
|
8058
|
+
await this.followUpDelivery(target.sessionId, message);
|
|
8059
|
+
} catch (error) {
|
|
8060
|
+
throw new TaskBoardExtensionError("session-unreachable", `session ${target.sessionId} of task ${taskId} did not accept the message: ${failureText(error)}`);
|
|
8061
|
+
}
|
|
8062
|
+
}
|
|
8063
|
+
/**
|
|
8064
|
+
* Re-run an executed card in its own session with rework instructions.
|
|
8065
|
+
*
|
|
8066
|
+
* The registry decides only what it can read from the ledger — the card
|
|
8067
|
+
* exists, is not archived, is not running, and has a conversation to continue
|
|
8068
|
+
* — and then hands the request to the board's own run path, so the running
|
|
8069
|
+
* lock, the permission confirmation, the acceptance contract and the spend cap
|
|
8070
|
+
* keep judging it. A board refusal surfaces unchanged, exactly as it does for
|
|
8071
|
+
* {@link setStatus}, because those are the board's own words.
|
|
8072
|
+
*/
|
|
8073
|
+
rework(entry, taskId, instructions, initiator) {
|
|
8074
|
+
this.assertActive(entry, "rework a task");
|
|
8075
|
+
if (this.reworkApply === void 0) throw new TaskBoardExtensionError("unavailable", "this deployment serves no rework applier");
|
|
8076
|
+
const task = this.requireTask(taskId);
|
|
8077
|
+
const text = extensionText(instructions, "rework instructions");
|
|
8078
|
+
if (task.archivedAt !== void 0) throw new TaskBoardExtensionError("task-archived", `task ${taskId} is archived; an archived card is read-only`);
|
|
8079
|
+
if (task.executions.some((record) => record.endedAt === void 0)) throw new TaskBoardExtensionError("running", `task ${taskId} is still running; a card is reworked once its run settles`);
|
|
8080
|
+
if (task.executions.length === 0) throw new TaskBoardExtensionError("not-executed", `task ${taskId} has never executed, so there is no run to rework`);
|
|
8081
|
+
if (!task.executions.some((record) => record.sessionId !== void 0)) throw new TaskBoardExtensionError("session-unreachable", `task ${taskId} records no execution session to continue`);
|
|
8082
|
+
this.reworkApply(taskId, text, initiator);
|
|
8083
|
+
}
|
|
8084
|
+
/** One task by id, or the refusal that names the unknown id. */
|
|
8085
|
+
requireTask(taskId) {
|
|
8086
|
+
const task = this.ledger.getTask(taskId);
|
|
8087
|
+
if (task === void 0) throw new TaskBoardExtensionError("task-not-found", `no task with id ${taskId}`);
|
|
8088
|
+
return task;
|
|
8089
|
+
}
|
|
6482
8090
|
linkedTasks(entry) {
|
|
6483
8091
|
const id = entry.extension.id;
|
|
6484
8092
|
const result = [];
|
|
@@ -6495,8 +8103,7 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6495
8103
|
writeIntegration(entry, taskId, payload) {
|
|
6496
8104
|
this.assertActive(entry, "write integration data");
|
|
6497
8105
|
if (!isTaskBoardExtensionPayload(payload)) throw new TaskBoardExtensionError("invalid-payload", "integration payload must be a pure JSON object within the size limit");
|
|
6498
|
-
const task = this.
|
|
6499
|
-
if (task === void 0) throw new TaskBoardExtensionError("task-not-found", `no task with id ${taskId}`);
|
|
8106
|
+
const task = this.requireTask(taskId);
|
|
6500
8107
|
const id = entry.extension.id;
|
|
6501
8108
|
const next = mergePayload(readPayload(task.integrations?.[id]), payload);
|
|
6502
8109
|
if (!isTaskBoardExtensionPayload(next)) throw new TaskBoardExtensionError("invalid-payload", `merged integration payload for ${id} exceeds ${taskBoardPayloadBytes(next) ?? "?"} bytes`);
|
|
@@ -6556,6 +8163,20 @@ const MAX_TIMER_DELAY_MS = 2147483647;
|
|
|
6556
8163
|
*/
|
|
6557
8164
|
const UNREADABLE_SETTLE_POLLS = 24;
|
|
6558
8165
|
/**
|
|
8166
|
+
* Why a member of a run never started: the Host stopped while its launch was
|
|
8167
|
+
* still waiting for an admission slot. Recorded rather than left open, so the
|
|
8168
|
+
* card leaves the running column instead of waiting for the next Host start's
|
|
8169
|
+
* interrupted-start recovery.
|
|
8170
|
+
*/
|
|
8171
|
+
const ABANDONED_LAUNCH_REASON = "host stopped before this execution started";
|
|
8172
|
+
/**
|
|
8173
|
+
* Why a rework could not launch: it redoes work in the card's own
|
|
8174
|
+
* conversation, so a session the Host cannot continue means there is nothing to
|
|
8175
|
+
* send the reviewer's instructions into. Starting a fresh conversation instead
|
|
8176
|
+
* would hand those instructions to an agent that never saw the work.
|
|
8177
|
+
*/
|
|
8178
|
+
const REWORK_SESSION_REASON = "rework: the card's previous execution session is not present and idle in the host session roster, so there is no conversation to send the rework instructions into";
|
|
8179
|
+
/**
|
|
6559
8180
|
* Why an enforced goal execution settled failed while its acceptance DID run:
|
|
6560
8181
|
* attempts were recorded and none of them passed. The judge answered about the
|
|
6561
8182
|
* work and the work did not pass.
|
|
@@ -6613,10 +8234,74 @@ const PROCESS_TIMERS = {
|
|
|
6613
8234
|
};
|
|
6614
8235
|
}
|
|
6615
8236
|
};
|
|
8237
|
+
/**
|
|
8238
|
+
* The new-card defaults a snapshot publishes, or undefined when this
|
|
8239
|
+
* deployment configures none. A target the board configures nothing for is
|
|
8240
|
+
* omitted instead of published blank, so the browser can tell "no default
|
|
8241
|
+
* model" from "a blank one" (only a hand-edited settings document can express
|
|
8242
|
+
* the latter).
|
|
8243
|
+
*/
|
|
8244
|
+
function cardDefaultsOf(defaults) {
|
|
8245
|
+
const mode = normalizeTargetId(defaults.mode);
|
|
8246
|
+
const permission = normalizeTargetId(defaults.permission);
|
|
8247
|
+
const model = normalizeTargetId(defaults.model);
|
|
8248
|
+
const reasoningEffort = normalizeTargetId(defaults.reasoningEffort);
|
|
8249
|
+
const published = {
|
|
8250
|
+
...mode === void 0 ? {} : { mode },
|
|
8251
|
+
...isTaskPermission(permission) ? { permission } : {},
|
|
8252
|
+
...model === void 0 ? {} : { model },
|
|
8253
|
+
...reasoningEffort === void 0 ? {} : { reasoningEffort }
|
|
8254
|
+
};
|
|
8255
|
+
return Object.keys(published).length === 0 ? void 0 : published;
|
|
8256
|
+
}
|
|
8257
|
+
/**
|
|
8258
|
+
* Every action kind this board accepts, keyed by the kind itself.
|
|
8259
|
+
*
|
|
8260
|
+
* Written as a total record of `TaskBoardAction['kind']` on purpose: a new member
|
|
8261
|
+
* of that union does not compile until it is listed here, so the table cannot
|
|
8262
|
+
* drift behind the protocol. `apply()` validates against it because a caller
|
|
8263
|
+
* reaching the board through the in-process capability face forwards its action
|
|
8264
|
+
* object verbatim, with no envelope parser in front of it — the HTTP route was the
|
|
8265
|
+
* only entrance before that face existed, and its parser is what used to turn an
|
|
8266
|
+
* unknown kind into a refusal.
|
|
8267
|
+
*/
|
|
8268
|
+
const ACTION_KINDS = {
|
|
8269
|
+
import: true,
|
|
8270
|
+
create: true,
|
|
8271
|
+
update: true,
|
|
8272
|
+
delete: true,
|
|
8273
|
+
move: true,
|
|
8274
|
+
archive: true,
|
|
8275
|
+
restore: true,
|
|
8276
|
+
settle: true,
|
|
8277
|
+
"reset-verification": true,
|
|
8278
|
+
"record-external-outcome": true,
|
|
8279
|
+
"set-schedule": true,
|
|
8280
|
+
run: true,
|
|
8281
|
+
rerun: true,
|
|
8282
|
+
rework: true,
|
|
8283
|
+
"confirm-permission": true,
|
|
8284
|
+
"set-parent": true,
|
|
8285
|
+
"rename-tag": true,
|
|
8286
|
+
"delete-tag": true,
|
|
8287
|
+
"extension-action": true
|
|
8288
|
+
};
|
|
8289
|
+
/**
|
|
8290
|
+
* The attachments an action carries, or undefined when it carries none.
|
|
8291
|
+
*
|
|
8292
|
+
* Only a create and an update can carry attachments: an import refuses them
|
|
8293
|
+
* outright, and every other action kind has no attachment surface at all.
|
|
8294
|
+
*/
|
|
8295
|
+
function attachmentsOfAction(action) {
|
|
8296
|
+
if (action.kind === "create") return action.input.attachments;
|
|
8297
|
+
if (action.kind === "update") return action.patch.attachments ?? void 0;
|
|
8298
|
+
}
|
|
6616
8299
|
var TaskBoardHostService = class {
|
|
6617
8300
|
ledger;
|
|
6618
8301
|
runner;
|
|
6619
8302
|
power;
|
|
8303
|
+
/** The official attachment storage, read live so a late mount is honoured. */
|
|
8304
|
+
attachmentStore;
|
|
6620
8305
|
listeners = /* @__PURE__ */ new Set();
|
|
6621
8306
|
/** The one recurring timer: the session-roster poll. */
|
|
6622
8307
|
pollTimer;
|
|
@@ -6634,6 +8319,12 @@ var TaskBoardHostService = class {
|
|
|
6634
8319
|
pollInFlight = false;
|
|
6635
8320
|
active = true;
|
|
6636
8321
|
/**
|
|
8322
|
+
* Admission control for the session-creating half of a run: one board action
|
|
8323
|
+
* opens a whole subtree, and this is what keeps the Host from asking DSH for
|
|
8324
|
+
* every member's session at once (see {@link LaunchAdmissionQueue}).
|
|
8325
|
+
*/
|
|
8326
|
+
launches;
|
|
8327
|
+
/**
|
|
6637
8328
|
* Consecutive unreadable-history polls per open execution (see
|
|
6638
8329
|
* {@link noteUnreadableInspection}). Cleared as soon as an inspection
|
|
6639
8330
|
* resolves, so a transient reader failure never fails a card.
|
|
@@ -6642,10 +8333,24 @@ var TaskBoardHostService = class {
|
|
|
6642
8333
|
preventIdleSleep = false;
|
|
6643
8334
|
verificationSettings;
|
|
6644
8335
|
verificationCatalog;
|
|
6645
|
-
team;
|
|
6646
8336
|
timers;
|
|
6647
8337
|
/** Live reader of the global native-/goal switch; frozen per execution. */
|
|
6648
8338
|
goalRunEnabled;
|
|
8339
|
+
/** Live reader of the deployment's new-card defaults (published and applied per create). */
|
|
8340
|
+
cardDefaults;
|
|
8341
|
+
/**
|
|
8342
|
+
* Live reader of the run-launch admission width: how many launches may be in
|
|
8343
|
+
* flight at once. Read at every admission, so a settings edit bounds the next
|
|
8344
|
+
* launch without remounting the row. Absent means the default.
|
|
8345
|
+
*/
|
|
8346
|
+
runLaunchWidth;
|
|
8347
|
+
/**
|
|
8348
|
+
* Live reader of the daily token cap; 0 means no gate. Read at each run
|
|
8349
|
+
* action, so closing or raising the cap binds the next action.
|
|
8350
|
+
*/
|
|
8351
|
+
spendBudgetTokens;
|
|
8352
|
+
/** Today's measured spend: absent measurement reads as "cannot see", never as zero. */
|
|
8353
|
+
spendUsedToday;
|
|
6649
8354
|
lastPowerJson = "";
|
|
6650
8355
|
now;
|
|
6651
8356
|
/** The deployment's workspaces, consulted to resolve a card that pins none. */
|
|
@@ -6659,15 +8364,27 @@ var TaskBoardHostService = class {
|
|
|
6659
8364
|
constructor(gateway, options = {}) {
|
|
6660
8365
|
this.ledger = options.ledger ?? new HostTaskLedger(void 0, void 0, {
|
|
6661
8366
|
sessionDefaultPermission: options.sessionDefaultPermission,
|
|
6662
|
-
maxSubtaskDepth: options.maxSubtaskDepth
|
|
8367
|
+
maxSubtaskDepth: options.maxSubtaskDepth,
|
|
8368
|
+
cardDefaults: options.cardDefaults,
|
|
8369
|
+
spendBudgetTokens: options.spendBudgetTokens,
|
|
8370
|
+
spendUsedToday: options.spendUsedToday
|
|
8371
|
+
});
|
|
8372
|
+
this.attachmentStore = options.attachments ?? (() => void 0);
|
|
8373
|
+
this.runner = new HostExecutionRunner(gateway, options.commandDispatcher, options.workspaceRegistry, void 0, options.ownerPeer, {
|
|
8374
|
+
attachments: this.attachmentStore,
|
|
8375
|
+
llm: options.modelInfo,
|
|
8376
|
+
...options.legacyAgentTeams === void 0 ? {} : { legacyAgentTeams: options.legacyAgentTeams }
|
|
6663
8377
|
});
|
|
6664
|
-
this.runner = new HostExecutionRunner(gateway, options.commandDispatcher, options.workspaceRegistry, void 0, options.operatorPeer);
|
|
6665
8378
|
this.workspaceRegistry = options.workspaceRegistry;
|
|
6666
|
-
this.team = options.team;
|
|
6667
8379
|
this.timers = options.timers ?? PROCESS_TIMERS;
|
|
6668
8380
|
this.power = options.power ?? new PowerInhibitor();
|
|
6669
8381
|
this.now = options.now ?? Date.now;
|
|
6670
8382
|
this.goalRunEnabled = options.goalRunEnabled ?? (() => false);
|
|
8383
|
+
this.cardDefaults = options.cardDefaults ?? (() => ({}));
|
|
8384
|
+
this.runLaunchWidth = options.runLaunchWidth ?? (() => 3);
|
|
8385
|
+
this.spendBudgetTokens = options.spendBudgetTokens ?? (() => 0);
|
|
8386
|
+
this.spendUsedToday = options.spendUsedToday ?? ((now) => usedTokensToday(now));
|
|
8387
|
+
this.launches = new LaunchAdmissionQueue(() => normalizeRunLaunchWidth(this.runLaunchWidth()));
|
|
6671
8388
|
this.verificationSettings = options.verificationSettings ?? (() => ({
|
|
6672
8389
|
enabled: false,
|
|
6673
8390
|
model: "",
|
|
@@ -6677,6 +8394,14 @@ var TaskBoardHostService = class {
|
|
|
6677
8394
|
this.extensions = new TaskBoardExtensionRegistry({
|
|
6678
8395
|
ledger: this.ledger,
|
|
6679
8396
|
apply: (action, initiator) => this.applyBoardAction(crypto.randomUUID(), action, initiator),
|
|
8397
|
+
followUp: (sessionId, text) => this.runner.followUp(sessionId, text),
|
|
8398
|
+
rework: (taskId, instructions, initiator) => {
|
|
8399
|
+
this.applyBoardAction(crypto.randomUUID(), {
|
|
8400
|
+
kind: "rework",
|
|
8401
|
+
taskId,
|
|
8402
|
+
instructions
|
|
8403
|
+
}, initiator);
|
|
8404
|
+
},
|
|
6680
8405
|
now: this.now
|
|
6681
8406
|
});
|
|
6682
8407
|
installStreamErrorGuards();
|
|
@@ -6741,21 +8466,32 @@ var TaskBoardHostService = class {
|
|
|
6741
8466
|
} else if (!active) this.clearScheduleTimer();
|
|
6742
8467
|
this.emit();
|
|
6743
8468
|
}
|
|
8469
|
+
/**
|
|
8470
|
+
* The board's published snapshot.
|
|
8471
|
+
*
|
|
8472
|
+
* Every read path serializes this object — the HTTP `state` answer, the
|
|
8473
|
+
* `action` answer through {@link apply}, and the remote bridge's
|
|
8474
|
+
* `board.snapshot` — so a provider's integration credentials are stripped
|
|
8475
|
+
* once, here, instead of at each exit. The ledger keeps them verbatim for the
|
|
8476
|
+
* provider's own in-process read.
|
|
8477
|
+
*/
|
|
6744
8478
|
snapshot() {
|
|
6745
8479
|
const state = this.ledger.state();
|
|
6746
8480
|
const published = this.extensions.published();
|
|
6747
|
-
|
|
6748
|
-
|
|
8481
|
+
const cardDefaults = cardDefaultsOf(this.cardDefaults());
|
|
8482
|
+
return projectSnapshotForWire({
|
|
8483
|
+
schemaVersion: 7,
|
|
6749
8484
|
revision: state.revision,
|
|
6750
8485
|
tasks: state.tasks,
|
|
6751
8486
|
scheduler: state.scheduler,
|
|
6752
8487
|
power: this.power.snapshot(),
|
|
6753
8488
|
sessionDefaultPermission: this.ledger.sessionDefaultPermission,
|
|
6754
8489
|
maxSubtaskDepth: this.ledger.maxSubtaskDepth,
|
|
6755
|
-
teamRunAvailable: this.team !== void 0,
|
|
6756
8490
|
goalRunEnabled: this.goalRunEnabled(),
|
|
8491
|
+
...cardDefaults === void 0 ? {} : { cardDefaults },
|
|
8492
|
+
...this.attachmentStore() === void 0 ? {} : { attachmentLimits: publishedAttachmentLimits(this.attachmentStore()) },
|
|
6757
8493
|
...Object.keys(published).length === 0 ? {} : { extensions: published }
|
|
6758
|
-
};
|
|
8494
|
+
});
|
|
6759
8495
|
}
|
|
6760
8496
|
/**
|
|
6761
8497
|
* Admit one external provider. Idempotent by extension id; the returned
|
|
@@ -6829,34 +8565,83 @@ var TaskBoardHostService = class {
|
|
|
6829
8565
|
}
|
|
6830
8566
|
};
|
|
6831
8567
|
}
|
|
8568
|
+
/**
|
|
8569
|
+
* Apply an action whose attachments the Host proved against the official
|
|
8570
|
+
* storage first.
|
|
8571
|
+
*
|
|
8572
|
+
* This is the board's trust boundary for attachment metadata: the browser
|
|
8573
|
+
* asserts the size, the type and the digest of every object it uploaded, and
|
|
8574
|
+
* the Host reads the stored objects back (an image is compared, a file is
|
|
8575
|
+
* streamed and its digest recomputed) before the ledger commits the claim.
|
|
8576
|
+
* An attachment the storage cannot prove is refused, so a spoofed client
|
|
8577
|
+
* claim never becomes a stored fact.
|
|
8578
|
+
*/
|
|
8579
|
+
async applyVerified(requestId, action, initiator) {
|
|
8580
|
+
if (!this.active) throw new Error("task board is disabled");
|
|
8581
|
+
if (action.kind === "extension-action") return await this.apply(requestId, action, initiator);
|
|
8582
|
+
await this.verifyActionAttachments(action);
|
|
8583
|
+
return projectSnapshotForWire(this.applyBoardAction(requestId, action, initiator, true));
|
|
8584
|
+
}
|
|
8585
|
+
/**
|
|
8586
|
+
* Prove every attachment of an action against the official storage.
|
|
8587
|
+
*
|
|
8588
|
+
* An action without attachments is untouched: the board keeps working in a
|
|
8589
|
+
* deployment that serves no attachment storage at all.
|
|
8590
|
+
*/
|
|
8591
|
+
async verifyActionAttachments(action) {
|
|
8592
|
+
const attachments = attachmentsOfAction(action);
|
|
8593
|
+
if (attachments === void 0 || attachments.length === 0) return;
|
|
8594
|
+
const store = this.attachmentStore();
|
|
8595
|
+
if (store === void 0) throw new Error("this deployment serves no attachment storage");
|
|
8596
|
+
await verifyAttachments(store, attachments);
|
|
8597
|
+
}
|
|
6832
8598
|
apply(requestId, action, initiator) {
|
|
6833
8599
|
if (!this.active) throw new Error("task board is disabled");
|
|
8600
|
+
const kind = action?.kind;
|
|
8601
|
+
if (typeof kind !== "string" || !Object.hasOwn(ACTION_KINDS, kind)) throw new Error(`unknown task board action kind: ${String(kind)}`);
|
|
6834
8602
|
if (action.kind === "extension-action") return this.handleExtensionAction(action);
|
|
6835
|
-
return this.applyBoardAction(requestId, action, initiator);
|
|
8603
|
+
return projectSnapshotForWire(this.applyBoardAction(requestId, action, initiator));
|
|
6836
8604
|
}
|
|
6837
8605
|
/**
|
|
6838
8606
|
* Apply one board-owned action with every gate intact. Provider capability
|
|
6839
8607
|
* calls and the same-origin wire both land here, so the two surfaces can
|
|
6840
8608
|
* never disagree about a card.
|
|
6841
8609
|
*/
|
|
6842
|
-
applyBoardAction(requestId, action, initiator) {
|
|
8610
|
+
applyBoardAction(requestId, action, initiator, attachmentVerified = false) {
|
|
8611
|
+
if (!attachmentVerified && attachmentsOfAction(action) !== void 0) throw new Error("attachments must be applied through the verified attachment action route");
|
|
6843
8612
|
const before = this.statusMap();
|
|
6844
|
-
if (
|
|
6845
|
-
if (this.ledger.state().tasks.find((item) => item.id === action.taskId)?.teamRun === true) throw new Error("Agent Teams is unavailable in this deployment");
|
|
6846
|
-
}
|
|
8613
|
+
if (action.kind === "run" || action.kind === "rerun" || action.kind === "rework") this.assertSpendCap();
|
|
6847
8614
|
const result = this.ledger.applyRequest(requestId, this.withInheritedWorkspace(action, initiator), initiator);
|
|
6848
8615
|
if (result.runs !== void 0) this.dispatchRuns(result.runs);
|
|
6849
8616
|
if (SCHEDULE_WRITE_ACTIONS.has(action.kind)) this.refreshSchedule();
|
|
6850
8617
|
this.emitStatusChanges(before, initiator);
|
|
6851
8618
|
if (action.kind === "delete") this.extensions.emitTaskDeleted({ taskId: action.taskId });
|
|
6852
8619
|
return {
|
|
6853
|
-
schemaVersion:
|
|
8620
|
+
schemaVersion: 7,
|
|
6854
8621
|
revision: result.state.revision,
|
|
6855
8622
|
tasks: result.state.tasks,
|
|
6856
8623
|
scheduler: result.state.scheduler,
|
|
6857
8624
|
power: this.power.snapshot()
|
|
6858
8625
|
};
|
|
6859
8626
|
}
|
|
8627
|
+
/**
|
|
8628
|
+
* Refuse a run whose day already spent the cap.
|
|
8629
|
+
*
|
|
8630
|
+
* A cap of 0 — the shipped default — answers before the measurement is read:
|
|
8631
|
+
* no ledger file is opened and nothing is summed, which is what keeps a board
|
|
8632
|
+
* that never configured a cap identical to the one before it existed.
|
|
8633
|
+
*
|
|
8634
|
+
* The refusal is a thrown message rather than a code: the wire hands its text
|
|
8635
|
+
* to the caller as board-refused, exactly like every other refusal this board
|
|
8636
|
+
* makes.
|
|
8637
|
+
*/
|
|
8638
|
+
assertSpendCap() {
|
|
8639
|
+
const cap = this.spendBudgetTokens();
|
|
8640
|
+
if (!(cap > 0)) return;
|
|
8641
|
+
const used = this.spendUsedToday(this.now());
|
|
8642
|
+
if (used === void 0 || !spendCapReached(used, cap)) return;
|
|
8643
|
+
throw new Error(spendCapMessage(used, cap));
|
|
8644
|
+
}
|
|
6860
8645
|
/** Route one provider action and answer the resulting board snapshot. */
|
|
6861
8646
|
async handleExtensionAction(action) {
|
|
6862
8647
|
await this.extensions.handleAction({
|
|
@@ -6886,6 +8671,8 @@ var TaskBoardHostService = class {
|
|
|
6886
8671
|
}
|
|
6887
8672
|
dispose() {
|
|
6888
8673
|
this.disposed = true;
|
|
8674
|
+
const abandoned = this.launches.drain();
|
|
8675
|
+
if (abandoned.length > 0) safeConsoleError(`[dsh-task-board] ${abandoned.length} run member(s) were still waiting for a launch slot when the Host stopped; each is settled as cancelled`);
|
|
6889
8676
|
this.extensions.dispose();
|
|
6890
8677
|
this.clearScheduleTimer();
|
|
6891
8678
|
this.clearPollBackoff();
|
|
@@ -6895,94 +8682,102 @@ var TaskBoardHostService = class {
|
|
|
6895
8682
|
this.ledger.dispose();
|
|
6896
8683
|
this.listeners.clear();
|
|
6897
8684
|
}
|
|
6898
|
-
async launch(opened,
|
|
8685
|
+
async launch(opened, schedule, freezeContract) {
|
|
6899
8686
|
/** The session this launch attached to the execution, once it exists. */
|
|
6900
8687
|
let attached;
|
|
6901
8688
|
try {
|
|
6902
|
-
const
|
|
6903
|
-
const
|
|
6904
|
-
const
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
...
|
|
8689
|
+
const forcedPreset = this.ledger.hasOutstandingDescendants(opened.task.id) ? LIANGSHEN_PRESET_ID : void 0;
|
|
8690
|
+
const descendants = forcedPreset === void 0 ? [] : this.ledger.outstandingDescendants(opened.task.id);
|
|
8691
|
+
const rework = opened.execution.rework;
|
|
8692
|
+
let reuseSessionId;
|
|
8693
|
+
if (rework === void 0) reuseSessionId = forcedPreset === void 0 ? await this.reuseSessionFor(opened.task) : void 0;
|
|
8694
|
+
else {
|
|
8695
|
+
if (forcedPreset !== void 0) throw new Error(REWORK_SESSION_REASON);
|
|
8696
|
+
reuseSessionId = await this.reworkSessionFor(opened.task);
|
|
8697
|
+
}
|
|
8698
|
+
const contextParts = {
|
|
8699
|
+
...descendants.length === 0 ? {} : { descendants: descendants.map((descendant) => ({
|
|
8700
|
+
id: descendant.id,
|
|
8701
|
+
title: descendant.title,
|
|
8702
|
+
status: descendant.status
|
|
8703
|
+
})) },
|
|
8704
|
+
...schedule === void 0 ? {} : { schedule },
|
|
8705
|
+
...rework === void 0 ? {} : { rework }
|
|
6913
8706
|
};
|
|
6914
|
-
const
|
|
6915
|
-
const globalGoalEnabled = this.
|
|
8707
|
+
const promptContext = Object.keys(contextParts).length === 0 ? void 0 : contextParts;
|
|
8708
|
+
const { settings, globalGoalEnabled, catalog } = await (freezeContract ?? (() => this.freezeRunContract()))();
|
|
6916
8709
|
const goalEnabled = globalGoalEnabled && opened.task.goalRun === true;
|
|
6917
8710
|
const skippedBy = opened.task.skipVerification === true ? "skipped" : "disabled";
|
|
6918
8711
|
const contract = resolveContract({
|
|
6919
8712
|
...settings,
|
|
6920
8713
|
enabled: settings.enabled && opened.task.skipVerification !== true
|
|
6921
|
-
},
|
|
8714
|
+
}, catalog);
|
|
6922
8715
|
const notArmed = globalGoalEnabled ? "goal-unavailable" : "goal-disabled";
|
|
6923
8716
|
const initial = {
|
|
6924
8717
|
contract,
|
|
6925
8718
|
attempts: [],
|
|
6926
|
-
applicability:
|
|
8719
|
+
applicability: !contract.enabled ? skippedBy : notArmed
|
|
6927
8720
|
};
|
|
6928
8721
|
this.ledger.setVerification(opened.task.id, opened.execution.id, initial);
|
|
6929
8722
|
const sessionId = await this.runner.launch(opened.task, {
|
|
6930
8723
|
...reuseSessionId === void 0 ? {} : { reuseSessionId },
|
|
8724
|
+
...forcedPreset === void 0 ? {} : { agentPreset: forcedPreset },
|
|
6931
8725
|
...promptContext === void 0 ? {} : { promptContext },
|
|
6932
8726
|
goalEnabled,
|
|
8727
|
+
catalog,
|
|
6933
8728
|
onSession: (id) => {
|
|
6934
8729
|
attached = id;
|
|
6935
8730
|
this.ledger.attachSession(opened.task.id, opened.execution.id, id);
|
|
6936
8731
|
},
|
|
6937
8732
|
onGoalArmed: (armed) => {
|
|
6938
|
-
this.setApplicability(opened.task.id, opened.execution.id,
|
|
8733
|
+
this.setApplicability(opened.task.id, opened.execution.id, !contract.enabled ? skippedBy : armed ? "enforced" : notArmed);
|
|
6939
8734
|
}
|
|
6940
8735
|
});
|
|
6941
8736
|
if (attached === void 0) this.ledger.attachSession(opened.task.id, opened.execution.id, sessionId);
|
|
6942
|
-
if (team) for (const teammate of others) this.scheduleTeammate(teammate, sessionId);
|
|
6943
8737
|
} catch (error) {
|
|
6944
8738
|
const launchedSession = error instanceof SessionLaunchError ? error.sessionId : void 0;
|
|
6945
8739
|
if (launchedSession !== void 0) this.ledger.attachSession(opened.task.id, opened.execution.id, launchedSession);
|
|
6946
|
-
if (schedule !== void 0 && attached === void 0 && launchedSession === void 0)
|
|
6947
|
-
this.ledger.refundScheduledOccurrence(opened.task.id, this.now());
|
|
6948
|
-
this.refreshSchedule();
|
|
6949
|
-
}
|
|
8740
|
+
if (schedule !== void 0 && attached === void 0 && launchedSession === void 0) this.refundUnstartedSchedule(opened.task.id);
|
|
6950
8741
|
this.settleAndNotify(opened.task.id, opened.execution.id, "failed", error instanceof Error ? error.message : String(error));
|
|
6951
8742
|
}
|
|
6952
8743
|
}
|
|
6953
|
-
|
|
6954
|
-
|
|
6955
|
-
|
|
6956
|
-
|
|
8744
|
+
/**
|
|
8745
|
+
* Read the acceptance contract one run group freezes, in the order the board
|
|
8746
|
+
* has always read it: the acceptance settings, then the global native-/goal
|
|
8747
|
+
* switch, then the model catalog that both resolves the contract's route and
|
|
8748
|
+
* decides the reasoning effort the session may be given.
|
|
8749
|
+
*/
|
|
8750
|
+
async freezeRunContract() {
|
|
8751
|
+
return {
|
|
8752
|
+
settings: this.verificationSettings(),
|
|
8753
|
+
globalGoalEnabled: this.goalRunEnabled() === true,
|
|
8754
|
+
catalog: await this.verificationCatalog()
|
|
8755
|
+
};
|
|
6957
8756
|
}
|
|
6958
8757
|
/**
|
|
6959
|
-
*
|
|
6960
|
-
*
|
|
6961
|
-
*
|
|
6962
|
-
* fails settles the subtask as failed immediately, which then folds into the
|
|
6963
|
-
* Lead's cascade verdict.
|
|
8758
|
+
* A {@link RunContractFreezer} that reads once and hands the SAME value to
|
|
8759
|
+
* every later caller of one run group. A read that fails is not cached: the
|
|
8760
|
+
* next member reads again, exactly as a per-execution read would have.
|
|
6964
8761
|
*/
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
this.
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
try {
|
|
6972
|
-
const member = await team.spawn({
|
|
6973
|
-
leadSessionId,
|
|
6974
|
-
name: teammateName(opened.task.title, opened.execution.runGroupId ?? opened.task.id, opened.task.id),
|
|
6975
|
-
description: opened.task.title,
|
|
6976
|
-
prompt: promptText(opened.task)
|
|
8762
|
+
contractFreezerForRunGroup() {
|
|
8763
|
+
let pending;
|
|
8764
|
+
return () => {
|
|
8765
|
+
pending ??= this.freezeRunContract().catch((error) => {
|
|
8766
|
+
pending = void 0;
|
|
8767
|
+
throw error;
|
|
6977
8768
|
});
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
8769
|
+
return pending;
|
|
8770
|
+
};
|
|
8771
|
+
}
|
|
8772
|
+
/**
|
|
8773
|
+
* Give back the occurrence a launch consumed, for a launch that never reached
|
|
8774
|
+
* a session: a failed launch, or one the Host abandoned while it was still
|
|
8775
|
+
* waiting for an admission slot. A manual run, and a launch that DID reach a
|
|
8776
|
+
* session, are never refunded.
|
|
8777
|
+
*/
|
|
8778
|
+
refundUnstartedSchedule(taskId) {
|
|
8779
|
+
this.ledger.refundScheduledOccurrence(taskId, this.now());
|
|
8780
|
+
this.refreshSchedule();
|
|
6986
8781
|
}
|
|
6987
8782
|
/**
|
|
6988
8783
|
* One roster pass, and whether it could read the session tree.
|
|
@@ -7034,10 +8829,13 @@ var TaskBoardHostService = class {
|
|
|
7034
8829
|
* reads no roster at all, and a read that fails mints a fresh conversation
|
|
7035
8830
|
* exactly as an unknown roster always did.
|
|
7036
8831
|
* @param task - the task about to run.
|
|
8832
|
+
* @param force - continue the settled session regardless of the card's own
|
|
8833
|
+
* opt-in (a rework), which the reuse rule accepts without waiving any of its
|
|
8834
|
+
* evidence conditions.
|
|
7037
8835
|
* @returns the session id to continue in, or undefined for a fresh session.
|
|
7038
8836
|
*/
|
|
7039
|
-
async reuseSessionFor(task) {
|
|
7040
|
-
if (task.reuseSession !== true) return void 0;
|
|
8837
|
+
async reuseSessionFor(task, force) {
|
|
8838
|
+
if (task.reuseSession !== true && force !== true) return void 0;
|
|
7041
8839
|
let running;
|
|
7042
8840
|
try {
|
|
7043
8841
|
running = await this.runner.listRunning();
|
|
@@ -7047,7 +8845,24 @@ var TaskBoardHostService = class {
|
|
|
7047
8845
|
return;
|
|
7048
8846
|
}
|
|
7049
8847
|
if (!running.known) return void 0;
|
|
7050
|
-
return reusableSessionId(task, new Set(running.items.filter((item) => !item.running).map((item) => item.sessionId)));
|
|
8848
|
+
return reusableSessionId(task, new Set(running.items.filter((item) => !item.running).map((item) => item.sessionId)), force === true ? { force: true } : {});
|
|
8849
|
+
}
|
|
8850
|
+
/**
|
|
8851
|
+
* The session a rework continues, or the refusal that says why it cannot.
|
|
8852
|
+
*
|
|
8853
|
+
* A rework exists for one conversation — the one the reviewer read before
|
|
8854
|
+
* sending the work back — so the evidence that this Host still reaches it is
|
|
8855
|
+
* required, exactly as it is for a card that opted into reuse. What a rework
|
|
8856
|
+
* does NOT get is the fresh-conversation fallback: launching there would hand
|
|
8857
|
+
* the reviewer's instructions to an agent that never saw the work, so the run
|
|
8858
|
+
* fails with a readable reason instead.
|
|
8859
|
+
* @param task - the card being reworked.
|
|
8860
|
+
* @returns the session id this rework continues in.
|
|
8861
|
+
*/
|
|
8862
|
+
async reworkSessionFor(task) {
|
|
8863
|
+
const sessionId = await this.reuseSessionFor(task, true);
|
|
8864
|
+
if (sessionId === void 0) throw new Error(REWORK_SESSION_REASON);
|
|
8865
|
+
return sessionId;
|
|
7051
8866
|
}
|
|
7052
8867
|
/** Reuse the session list this poll already fetched: one list RPC per tick, not 1 + E. */
|
|
7053
8868
|
async reconcileExecutions(sessions, executions) {
|
|
@@ -7067,10 +8882,10 @@ var TaskBoardHostService = class {
|
|
|
7067
8882
|
}
|
|
7068
8883
|
this.unreadablePolls.delete(execution.executionId);
|
|
7069
8884
|
if (result.outcome === "succeeded" && verificationRequired(verification) && passedAttempt(verification) === void 0) {
|
|
7070
|
-
this.settleAndNotify(execution.taskId, execution.executionId, "failed", verificationNeverInvoked(verification) ? NEVER_INVOKED_VERIFICATION_REASON : verificationOnlyInvalid(verification) ? INVALID_ONLY_VERIFICATION_REASON : NO_MATCHING_PASS_VERIFICATION_REASON);
|
|
8885
|
+
this.settleAndNotify(execution.taskId, execution.executionId, "failed", verificationNeverInvoked(verification) ? NEVER_INVOKED_VERIFICATION_REASON : verificationOnlyInvalid(verification) ? INVALID_ONLY_VERIFICATION_REASON : NO_MATCHING_PASS_VERIFICATION_REASON, result.summary);
|
|
7071
8886
|
continue;
|
|
7072
8887
|
}
|
|
7073
|
-
this.settleAndNotify(execution.taskId, execution.executionId, result.outcome, "error" in result ? result.error : void 0);
|
|
8888
|
+
this.settleAndNotify(execution.taskId, execution.executionId, result.outcome, "error" in result ? result.error : void 0, result.summary);
|
|
7074
8889
|
} catch {}
|
|
7075
8890
|
}
|
|
7076
8891
|
const open = new Set(executions.map((execution) => execution.executionId));
|
|
@@ -7085,20 +8900,14 @@ var TaskBoardHostService = class {
|
|
|
7085
8900
|
* ancestor of it — in the running column with no way out. The first poll of
|
|
7086
8901
|
* each streak is logged, so the Host log names the session.
|
|
7087
8902
|
*/
|
|
7088
|
-
settleAndNotify(taskId, executionId, outcome, error) {
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
this.ledger.settle(taskId, executionId, outcome, error);
|
|
8903
|
+
settleAndNotify(taskId, executionId, outcome, error, summary) {
|
|
8904
|
+
if (this.ledger.getTask(taskId)?.executions.find((entry) => entry.id === executionId)?.endedAt !== void 0) {
|
|
8905
|
+
this.ledger.settle(taskId, executionId, outcome, error, summary);
|
|
7092
8906
|
return;
|
|
7093
8907
|
}
|
|
7094
|
-
const
|
|
7095
|
-
this.ledger.settle(taskId, executionId, outcome, error);
|
|
7096
|
-
|
|
7097
|
-
if (task !== void 0 && previousStatus !== void 0 && previousStatus !== task.status) this.extensions.emitStatusChanged({
|
|
7098
|
-
taskId,
|
|
7099
|
-
status: task.status,
|
|
7100
|
-
previous: previousStatus
|
|
7101
|
-
});
|
|
8908
|
+
const statuses = this.statusMap();
|
|
8909
|
+
this.ledger.settle(taskId, executionId, outcome, error, summary);
|
|
8910
|
+
this.emitStatusChanges(statuses);
|
|
7102
8911
|
this.extensions.emitExecutionSettled({
|
|
7103
8912
|
taskId,
|
|
7104
8913
|
executionId,
|
|
@@ -7238,18 +9047,18 @@ var TaskBoardHostService = class {
|
|
|
7238
9047
|
return this.ledger.armedScheduleCount();
|
|
7239
9048
|
}
|
|
7240
9049
|
/**
|
|
7241
|
-
* Launch one run
|
|
7242
|
-
*
|
|
7243
|
-
*
|
|
7244
|
-
*
|
|
7245
|
-
*
|
|
9050
|
+
* Launch the one run a run request opened. A run request names one card and
|
|
9051
|
+
* opens one execution for it; the card's own session dispatches its subtasks
|
|
9052
|
+
* as subagents, so nothing else is enqueued here.
|
|
9053
|
+
*
|
|
9054
|
+
* The launch still goes through the admission queue, which admits at most
|
|
9055
|
+
* `runLaunchWidth` launches at a time — that bound now applies across
|
|
9056
|
+
* concurrent runs rather than across the members of one run.
|
|
7246
9057
|
*/
|
|
7247
9058
|
dispatchRuns(runs, schedule) {
|
|
7248
|
-
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
this.scheduleLaunch(root, others, schedule);
|
|
7252
|
-
for (const run of others) if (run.dispatch !== "teammate") this.scheduleLaunch(run, [], schedule);
|
|
9059
|
+
const root = runs[0];
|
|
9060
|
+
if (root === void 0) return;
|
|
9061
|
+
this.scheduleLaunch(root, schedule, this.contractFreezerForRunGroup());
|
|
7253
9062
|
}
|
|
7254
9063
|
/**
|
|
7255
9064
|
* Move one execution's applicability without touching its frozen contract or
|
|
@@ -7263,10 +9072,50 @@ var TaskBoardHostService = class {
|
|
|
7263
9072
|
applicability
|
|
7264
9073
|
});
|
|
7265
9074
|
}
|
|
7266
|
-
scheduleLaunch(opened,
|
|
7267
|
-
this.launch(opened,
|
|
9075
|
+
scheduleLaunch(opened, schedule, freezeContract) {
|
|
9076
|
+
this.enqueueLaunch(opened, () => this.launch(opened, schedule, freezeContract).catch((error) => {
|
|
7268
9077
|
safeConsoleError("[dsh-task-board] execution launch settlement failed", error);
|
|
7269
|
-
});
|
|
9078
|
+
}), schedule);
|
|
9079
|
+
}
|
|
9080
|
+
/**
|
|
9081
|
+
* Hand one launch to the admission queue, or abandon it on the spot when the
|
|
9082
|
+
* Host is already stopping: a queue entry created after {@link dispose} would
|
|
9083
|
+
* otherwise never be drained, and its card would sit in the running column
|
|
9084
|
+
* until the next Host start recovered it.
|
|
9085
|
+
*/
|
|
9086
|
+
enqueueLaunch(opened, start, schedule) {
|
|
9087
|
+
const launch = {
|
|
9088
|
+
groupId: opened.execution.runGroupId ?? opened.task.id,
|
|
9089
|
+
start: async () => {
|
|
9090
|
+
if (!this.isExecutionOpen(opened)) return;
|
|
9091
|
+
await start();
|
|
9092
|
+
},
|
|
9093
|
+
abandon: () => this.abandonQueuedRun(opened, schedule)
|
|
9094
|
+
};
|
|
9095
|
+
if (this.disposed) {
|
|
9096
|
+
launch.abandon();
|
|
9097
|
+
return;
|
|
9098
|
+
}
|
|
9099
|
+
this.launches.enqueue(launch);
|
|
9100
|
+
}
|
|
9101
|
+
/** Whether one opened execution is still open in the ledger. */
|
|
9102
|
+
isExecutionOpen(opened) {
|
|
9103
|
+
const execution = this.ledger.getTask(opened.task.id)?.executions.find((entry) => entry.id === opened.execution.id);
|
|
9104
|
+
return execution !== void 0 && execution.endedAt === void 0;
|
|
9105
|
+
}
|
|
9106
|
+
/**
|
|
9107
|
+
* Take one launch that never started out of the running column.
|
|
9108
|
+
*
|
|
9109
|
+
* Settled as CANCELLED, not failed: nothing about the run's work went wrong —
|
|
9110
|
+
* the Host stopped before the launch got a slot, which is exactly what the
|
|
9111
|
+
* next start's interrupted-start recovery records for an execution that never
|
|
9112
|
+
* reached a session. A scheduled occurrence that never reached a session is
|
|
9113
|
+
* refunded on the same terms as any other pre-session failure, so a run the
|
|
9114
|
+
* Host never started cannot silently spend the user's run budget.
|
|
9115
|
+
*/
|
|
9116
|
+
abandonQueuedRun(opened, schedule) {
|
|
9117
|
+
if (schedule !== void 0) this.refundUnstartedSchedule(opened.task.id);
|
|
9118
|
+
this.settleAndNotify(opened.task.id, opened.execution.id, "cancelled", ABANDONED_LAUNCH_REASON);
|
|
7270
9119
|
}
|
|
7271
9120
|
schedulePoll() {
|
|
7272
9121
|
if (this.pollInFlight || this.disposed) return;
|
|
@@ -7731,6 +9580,7 @@ function taskSummary(task, tasks, sessionDefault) {
|
|
|
7731
9580
|
...task.mode === void 0 ? {} : { mode: task.mode },
|
|
7732
9581
|
...task.permission === void 0 ? {} : { permission: task.permission },
|
|
7733
9582
|
...task.model === void 0 ? {} : { model: task.model },
|
|
9583
|
+
...task.reasoningEffort === void 0 ? {} : { reasoningEffort: task.reasoningEffort },
|
|
7734
9584
|
...task.reuseSession === true ? { reuseSession: true } : {},
|
|
7735
9585
|
...task.teamRun === true ? { teamRun: true } : {},
|
|
7736
9586
|
...task.goalRun === true ? { goalRun: true } : {},
|
|
@@ -7827,8 +9677,8 @@ function buildSetParentTool(host) {
|
|
|
7827
9677
|
description: [
|
|
7828
9678
|
"Attach an existing task under a parent (making it a subtask) or detach it back to the root board by setting its parentId.",
|
|
7829
9679
|
"Pass an empty parentId to detach.",
|
|
7830
|
-
"The Host refuses the link when the parent is unknown or archived, when the moved task is one of its own descendants, when the resulting depth exceeds the deployment subtask limit (default one level, maximum three), or while the task has an unsettled execution (its link may still be a
|
|
7831
|
-
"Running a task
|
|
9680
|
+
"The Host refuses the link when the parent is unknown or archived, when the moved task is one of its own descendants, when the resulting depth exceeds the deployment subtask limit (default one level, maximum three), or while the task has an unsettled execution (its link may still be a stored run group parent pointer).",
|
|
9681
|
+
"Running a task opens one run group over its subtree concurrently and leaves a subtask that already sits in the done column alone; a parent card settles only after its own turn and every direct subtask it opened have settled."
|
|
7832
9682
|
].join(" "),
|
|
7833
9683
|
parameters: {
|
|
7834
9684
|
taskId: {
|
|
@@ -7870,17 +9720,16 @@ function buildRunTool(host) {
|
|
|
7870
9720
|
name: "task_board_run",
|
|
7871
9721
|
description: [
|
|
7872
9722
|
"Run a task on the board now, or re-run a settled one.",
|
|
7873
|
-
"Running a
|
|
7874
|
-
"
|
|
9723
|
+
"Running a card opens ONE session for that card: no session is opened for its subtasks, and the card agent dispatches them itself with subagent. A card whose subtasks are still unfinished runs under the liangshen agent preset and is told which cards to pick up.",
|
|
9724
|
+
"Clicking a subtask runs that subtask as its own root, again without opening anything for its descendants.",
|
|
7875
9725
|
"A card whose effective permission is above the deployment session default is refused with confirmation-required until a HUMAN confirms the binding in the board UI; this tool cannot confirm it.",
|
|
7876
|
-
"A card whose task carries teamRun instead starts ONE Team Lead session and the Host spawns a teammate per subtask inside it, so those cards run as an Agent Team rather than as independent sessions; that mode needs the deployment Agent Teams service and is refused when it is missing.",
|
|
7877
9726
|
"Executions consume real API quota. Sessions are created asynchronously, so read their ids and outcomes back with task_board_get."
|
|
7878
9727
|
].join(" "),
|
|
7879
9728
|
parameters: {
|
|
7880
9729
|
taskId: {
|
|
7881
9730
|
type: "string",
|
|
7882
9731
|
required: true,
|
|
7883
|
-
description: "The task to run;
|
|
9732
|
+
description: "The task to run; only this card gets a session, its unfinished subtasks are dispatched by that session own agent."
|
|
7884
9733
|
},
|
|
7885
9734
|
rerun: {
|
|
7886
9735
|
type: "boolean",
|
|
@@ -7912,7 +9761,7 @@ function buildRunTool(host) {
|
|
|
7912
9761
|
ok: true,
|
|
7913
9762
|
started,
|
|
7914
9763
|
...root === void 0 ? {} : { task: taskSummary(root, snapshot.tasks, snapshot.sessionDefaultPermission) },
|
|
7915
|
-
note: "Executions run asynchronously; call task_board_get to read session ids and the settled outcome.
|
|
9764
|
+
note: "Executions run asynchronously; call task_board_get to read session ids and the settled outcome."
|
|
7916
9765
|
});
|
|
7917
9766
|
} catch (error) {
|
|
7918
9767
|
const message = messageOf(error);
|
|
@@ -7928,7 +9777,7 @@ function buildManageTool(host) {
|
|
|
7928
9777
|
"Move, archive, restore, delete, or settle one task board card.",
|
|
7929
9778
|
"move-backlog, move-todo, move-running, move-done and move-failed are the manual column moves and cover every column; a card the runner is executing (one with an open execution) cannot be moved.",
|
|
7930
9779
|
"A manual move writes the card column only and never fabricates an execution record, so the card reports a declaration rather than evidence of a run: done/failed declare work finished (or failed) outside a Host-run execution — human work, an external system, a decision made elsewhere — and running says the work is under way without a tracked session. Use task_board_run when the work should actually run in a session here.",
|
|
7931
|
-
"record-external-outcome is the record-backed version of move-done and move-failed: use it when YOU, or another agent outside this Host, actually finished or failed the card with your own model, so the terminal column and the run history both derive from one execution record. It takes result (succeeded or failed) and initiatedBy (who completed it, for example your own agent name) plus an optional summary, and it is refused while the card still has an open execution: the Host stays the only authority over a run it is executing. It cannot record running or cancelled — those remain Host-only.",
|
|
9780
|
+
"record-external-outcome is the record-backed version of move-done and move-failed: use it when YOU, or another agent outside this Host, actually finished or failed the card with your own model, so the terminal column and the run history both derive from one execution record. It takes result (succeeded or failed) and initiatedBy (who completed it, for example your own agent name) plus an optional summary, and it is refused while the card still has an open execution: the Host stays the only authority over a run it is executing. It cannot record running or cancelled — those remain Host-only. A parent card that dispatched its subtasks uses it once, at the end, to backfill every subtask card with the conclusion it reached; the Host records an inherited verdict on a subtask the parent never wrote back, so the write-back is what keeps each subtask conclusion its own.",
|
|
7932
9781
|
"settle force-closes the open execution of a card the board can no longer observe (a stuck running card) and records it cancelled with the caller as the reason, so the card returns to the todo column and can be run again.",
|
|
7933
9782
|
"reset-verification clears the acceptance anomalies (timeouts, authentication failures, an unresolvable judge route, or an attempt the time budget ended) recorded on a card open execution, so the next update_goal(action: complete) runs a fresh acceptance. It is refused unless that execution really carries such anomalies, it never clears a quality verdict, and a spent anomaly budget otherwise HOLDS the card open instead of failing it: tell the user the acceptance environment is unusable and that this action is how they clear it once they have fixed it.",
|
|
7934
9783
|
"archive takes the whole subtask tree off the board and is refused while any member has an unsettled execution; restore brings the task, its ancestors and its subtree back; delete removes one card and is refused while it still has subtasks (detach or delete them first) or while it runs.",
|
|
@@ -8079,7 +9928,7 @@ function buildScheduleTool(host) {
|
|
|
8079
9928
|
"Arm, change, or disarm a task scheduled runs. Two kinds of plan exist: a recurring 5-field cron rule (day-of-month and day-of-week follow Vixie semantics: both restricted means OR, otherwise AND), and a one-shot that runs once at a future instant.",
|
|
8080
9929
|
"For a one-shot pass mode \"once\" with at (the planned instant, ms since epoch UTC). For a recurring rule pass mode \"cron\" (or omit mode) with a cron expression, optionally capped by maxRuns (a positive whole number of scheduled executions; omit for unlimited, pass 0 to clear a cap).",
|
|
8081
9930
|
"The wall clock is read in the rule stored IANA time zone; omit timeZone to use the Host zone reported by task_board_list/task_board_get. DST gaps are skipped and an ambiguous fall-back time fires once, at the earlier instant.",
|
|
8082
|
-
"A due scheduled task runs
|
|
9931
|
+
"A due scheduled task runs exactly what a manual run of that card does: one session for the card, never one per subtask.",
|
|
8083
9932
|
"The scheduler counts executions it actually starts; once a rule reaches its run budget it stops itself in the ledger, and a manual run never consumes the budget. A schedule whose tree contains an unconfirmed above-default permission is refused and does not consume the budget; the reason is reported in the list board summary as schedulerError.",
|
|
8084
9933
|
"Missed occurrences during Host downtime are skipped, never queued (a one-shot whose instant passed while the Host was down is stopped as missed); a task that is already running skips its occurrence without consuming the budget."
|
|
8085
9934
|
].join(" "),
|
|
@@ -8233,7 +10082,11 @@ function buildListTool(host) {
|
|
|
8233
10082
|
function buildGetTool(host) {
|
|
8234
10083
|
return defineTool({
|
|
8235
10084
|
name: "task_board_get",
|
|
8236
|
-
description: [
|
|
10085
|
+
description: [
|
|
10086
|
+
"Read one task board card in full: prompt, description, labels, column, parent link, direct subtasks, execution targets, schedule, permission gate state, and the last ten execution attempts with their session ids and outcomes.",
|
|
10087
|
+
"Use it before running or editing a card, after a run to read the settled outcome, and to read each subtask card before dispatching it with subagent.",
|
|
10088
|
+
"A card written before team runs were retired may still report teamRun: true; the field is history and never changes how the Host runs the card."
|
|
10089
|
+
].join(" "),
|
|
8237
10090
|
parameters: { taskId: {
|
|
8238
10091
|
type: "string",
|
|
8239
10092
|
required: true,
|
|
@@ -8260,7 +10113,7 @@ function buildCreateTool(host) {
|
|
|
8260
10113
|
name: "task_board_create",
|
|
8261
10114
|
description: [
|
|
8262
10115
|
"Create a task on the DSH task board, or a subtask by passing parentId.",
|
|
8263
|
-
"A subtask inherits every execution target it does not override (workspace, agent preset, permission, model) from its parent, and inherits the parent human permission confirmation together with an inherited binding.",
|
|
10116
|
+
"A subtask inherits every execution target it does not override (workspace, agent preset, permission, model, reasoning effort) from its parent, and inherits the parent human permission confirmation together with an inherited binding.",
|
|
8264
10117
|
"The deployment caps subtask depth (default one level, maximum three): a subtask of a subtask is refused unless the board is configured deeper.",
|
|
8265
10118
|
"The task lands in the todo column and does NOT run; call task_board_run to execute it."
|
|
8266
10119
|
].join(" "),
|
|
@@ -8288,25 +10141,25 @@ function buildCreateTool(host) {
|
|
|
8288
10141
|
},
|
|
8289
10142
|
mode: {
|
|
8290
10143
|
type: "string",
|
|
8291
|
-
description: "Agent preset id the execution session is composed from; omit
|
|
10144
|
+
description: "Agent preset id the execution session is composed from; omit to adopt the board new-card default, and the deployment default when none is configured."
|
|
8292
10145
|
},
|
|
8293
10146
|
permission: {
|
|
8294
10147
|
type: "string",
|
|
8295
10148
|
enum: [...TASK_PERMISSIONS],
|
|
8296
|
-
description: "Permission preset for the execution session
|
|
10149
|
+
description: "Permission preset for the execution session; omit to adopt the board new-card default. An omitted permission is never taken from a parent: the launch resolves the parent binding instead. A value above the session default needs a human confirmation in the board UI before the card can run."
|
|
8297
10150
|
},
|
|
8298
10151
|
model: {
|
|
8299
10152
|
type: "string",
|
|
8300
|
-
description: "Pinned model as provider/model (or a model id); omit
|
|
10153
|
+
description: "Pinned model as provider/model (or a model id); omit to adopt the board new-card default, and the host default when none is configured."
|
|
10154
|
+
},
|
|
10155
|
+
reasoningEffort: {
|
|
10156
|
+
type: "string",
|
|
10157
|
+
description: "Reasoning effort id for that model (an adapter-owned level such as \"high\"); omit to adopt the board new-card default for that model, and the model own default when none applies. Only an effort the target model declares is sent; an empty string clears it back to the default."
|
|
8301
10158
|
},
|
|
8302
10159
|
reuseSession: {
|
|
8303
10160
|
type: "boolean",
|
|
8304
10161
|
description: "Continue later runs in the previous execution session instead of a fresh conversation."
|
|
8305
10162
|
},
|
|
8306
|
-
teamRun: {
|
|
8307
|
-
type: "boolean",
|
|
8308
|
-
description: "Run this task as an Agent Team: running it starts one Team Lead session and the Host spawns a teammate per subtask inside it. Omit or false for one independent session per member. Refused when the deployment serves no Agent Teams service."
|
|
8309
|
-
},
|
|
8310
10163
|
goalRun: {
|
|
8311
10164
|
type: "boolean",
|
|
8312
10165
|
description: "Start each run with dsh built-in /goal so the session keeps working continuation rounds until the goal completes. Off by default: omit (or pass false) for a single plain turn, and pass true to opt this card in. It only takes effect while the deployment global native /goal switch is on."
|
|
@@ -8384,8 +10237,9 @@ function buildCreateTool(host) {
|
|
|
8384
10237
|
...args.mode === void 0 || args.mode === "" ? {} : { mode: args.mode },
|
|
8385
10238
|
...args.permission === void 0 ? {} : { permission: args.permission },
|
|
8386
10239
|
...args.model === void 0 || args.model === "" ? {} : { model: args.model },
|
|
10240
|
+
...args.reasoningEffort === void 0 || args.reasoningEffort === "" ? {} : { reasoningEffort: args.reasoningEffort },
|
|
10241
|
+
applyCardDefaults: true,
|
|
8387
10242
|
...args.reuseSession === true ? { reuseSession: true } : {},
|
|
8388
|
-
...args.teamRun === true ? { teamRun: true } : {},
|
|
8389
10243
|
...args.goalRun === true ? { goalRun: true } : {},
|
|
8390
10244
|
...args.skipVerification === true ? { skipVerification: true } : {},
|
|
8391
10245
|
...tags.length === 0 ? {} : { tags },
|
|
@@ -8419,7 +10273,7 @@ function buildUpdateTool(host) {
|
|
|
8419
10273
|
return defineTool({
|
|
8420
10274
|
name: "task_board_update",
|
|
8421
10275
|
description: [
|
|
8422
|
-
"Edit a task board card: title, description, prompt, labels, and the execution targets (workspace, agent preset, permission, model, session reuse).",
|
|
10276
|
+
"Edit a task board card: title, description, prompt, labels, and the execution targets (workspace, agent preset, permission, model, reasoning effort, session reuse).",
|
|
8423
10277
|
"Only the fields you pass change; pass an empty string to clear a target, or an empty labels array to clear the labels.",
|
|
8424
10278
|
"Title, description and prompt freeze once the task has started executing; the execution targets stay editable because they only affect future runs.",
|
|
8425
10279
|
"Changing the pinned permission re-arms the permission confirmation gate."
|
|
@@ -8464,14 +10318,14 @@ function buildUpdateTool(host) {
|
|
|
8464
10318
|
type: "string",
|
|
8465
10319
|
description: "New pinned model; an empty string clears it."
|
|
8466
10320
|
},
|
|
10321
|
+
reasoningEffort: {
|
|
10322
|
+
type: "string",
|
|
10323
|
+
description: "New reasoning effort id for the pinned model; an empty string clears it back to the model own default. Only an effort the target model declares is sent at run time."
|
|
10324
|
+
},
|
|
8467
10325
|
reuseSession: {
|
|
8468
10326
|
type: "boolean",
|
|
8469
10327
|
description: "Continue later runs in the previous execution session."
|
|
8470
10328
|
},
|
|
8471
|
-
teamRun: {
|
|
8472
|
-
type: "boolean",
|
|
8473
|
-
description: "Switches this task between a plain cascade (one session per member) and an Agent Team run (Lead session plus a teammate per subtask)."
|
|
8474
|
-
},
|
|
8475
10329
|
goalRun: {
|
|
8476
10330
|
type: "boolean",
|
|
8477
10331
|
description: "Whether each run starts with dsh built-in /goal (default false, one plain turn). Pass true to opt this card in, or false to return it to the default."
|
|
@@ -8512,9 +10366,9 @@ function buildUpdateTool(host) {
|
|
|
8512
10366
|
if (has(args, "workspaceId") && typeof args.workspaceId === "string") patch.workspaceId = args.workspaceId;
|
|
8513
10367
|
if (has(args, "mode") && typeof args.mode === "string") patch.mode = args.mode;
|
|
8514
10368
|
if (has(args, "model") && typeof args.model === "string") patch.model = args.model;
|
|
10369
|
+
if (has(args, "reasoningEffort") && typeof args.reasoningEffort === "string") patch.reasoningEffort = args.reasoningEffort;
|
|
8515
10370
|
if (has(args, "permission") && typeof args.permission === "string") patch.permission = args.permission === "" ? void 0 : args.permission;
|
|
8516
10371
|
if (has(args, "reuseSession")) patch.reuseSession = args.reuseSession === true;
|
|
8517
|
-
if (has(args, "teamRun")) patch.teamRun = args.teamRun === true;
|
|
8518
10372
|
if (has(args, "goalRun")) patch.goalRun = args.goalRun === true ? true : false;
|
|
8519
10373
|
if (has(args, "skipVerification")) patch.skipVerification = args.skipVerification === true ? true : false;
|
|
8520
10374
|
if (has(args, "tags")) {
|
|
@@ -8576,7 +10430,8 @@ function buildUpdateTool(host) {
|
|
|
8576
10430
|
*/
|
|
8577
10431
|
const PLUGIN_TOOL_SECTION_ORDERS = {
|
|
8578
10432
|
ssh: 150,
|
|
8579
|
-
"task-board": 200
|
|
10433
|
+
"task-board": 200,
|
|
10434
|
+
agents: 220
|
|
8580
10435
|
};
|
|
8581
10436
|
/**
|
|
8582
10437
|
* Build a section provider that renders \`text\` only while at least one of
|
|
@@ -8644,12 +10499,26 @@ function isLoopbackHostname(hostname) {
|
|
|
8644
10499
|
return isIPv4Loopback(hostname);
|
|
8645
10500
|
}
|
|
8646
10501
|
/**
|
|
10502
|
+
* Whether a reverse proxy stood between the client and this host: the request
|
|
10503
|
+
* carries CF-Connecting-IP or X-Forwarded-For. Either header is stamped by a
|
|
10504
|
+
* hop that forwards traffic, so the request did not originate on this machine.
|
|
10505
|
+
* @param request - node HTTP request.
|
|
10506
|
+
* @returns true when a forwarding header is present.
|
|
10507
|
+
*/
|
|
10508
|
+
function isProxiedRequest(request) {
|
|
10509
|
+
return request.headers["cf-connecting-ip"] !== void 0 || request.headers["x-forwarded-for"] !== void 0;
|
|
10510
|
+
}
|
|
10511
|
+
/**
|
|
8647
10512
|
* Request-level trust fence: a loopback socket address AND a loopback Host
|
|
8648
10513
|
* header, plus browser same-origin markers. The socket address is
|
|
8649
|
-
* authoritative;
|
|
10514
|
+
* authoritative for a direct connection; a request that carries a forwarding
|
|
10515
|
+
* header is refused outright, because a proxy in front of the host makes both
|
|
10516
|
+
* the socket address and the Host header describe the proxy rather than the
|
|
10517
|
+
* client. X-Forwarded-For is therefore never evidence *for* loopback.
|
|
8650
10518
|
*/
|
|
8651
10519
|
function isLoopbackRequest(request) {
|
|
8652
10520
|
if (!isLoopbackAddress(request.socket.remoteAddress)) return false;
|
|
10521
|
+
if (isProxiedRequest(request)) return false;
|
|
8653
10522
|
const host = request.headers.host;
|
|
8654
10523
|
if (typeof host !== "string") return false;
|
|
8655
10524
|
let hostUrl;
|
|
@@ -8668,10 +10537,41 @@ function isLoopbackRequest(request) {
|
|
|
8668
10537
|
return false;
|
|
8669
10538
|
}
|
|
8670
10539
|
}
|
|
10540
|
+
/**
|
|
10541
|
+
* Whether a forwarded request landed on this machine's loopback upstream: a
|
|
10542
|
+
* forwarding header (the proxy's own stamp), a loopback socket address (the
|
|
10543
|
+
* proxy dials 127.0.0.1:<port>), and a loopback Host header (the proxy rewrote
|
|
10544
|
+
* the authority to its upstream literal).
|
|
10545
|
+
*
|
|
10546
|
+
* This is a fact about the route, not a trust decision. A public request to a
|
|
10547
|
+
* tunnel satisfies all three by construction, because the proxy is the client
|
|
10548
|
+
* of this process: only a caller that operates the proxy can decide it stands
|
|
10549
|
+
* for the browser, which is why every consumer keeps this behind an explicit
|
|
10550
|
+
* default-off switch and its own browser markers. isLoopbackRequest is
|
|
10551
|
+
* unchanged and still refuses a forwarded request (issue #1906).
|
|
10552
|
+
* @param request - node HTTP request.
|
|
10553
|
+
* @returns true when a forwarding header, a loopback socket, and a loopback Host all hold.
|
|
10554
|
+
*/
|
|
10555
|
+
function isForwardedLoopbackRequest(request) {
|
|
10556
|
+
if (!isProxiedRequest(request)) return false;
|
|
10557
|
+
if (!isLoopbackAddress(request.socket.remoteAddress)) return false;
|
|
10558
|
+
const host = request.headers.host;
|
|
10559
|
+
if (typeof host !== "string") return false;
|
|
10560
|
+
try {
|
|
10561
|
+
return isLoopbackHostname(new URL("http://" + host).hostname);
|
|
10562
|
+
} catch {
|
|
10563
|
+
return false;
|
|
10564
|
+
}
|
|
10565
|
+
}
|
|
8671
10566
|
//#endregion
|
|
8672
10567
|
//#region src/host-routes.ts
|
|
8673
10568
|
const ACTION_LIMIT = 64 * 1024;
|
|
8674
10569
|
const IMPORT_LIMIT = 2 * 1024 * 1024;
|
|
10570
|
+
/**
|
|
10571
|
+
* Comment-frame cadence on the event stream. It keeps the connection alive
|
|
10572
|
+
* through intermediaries that would close an idle one; it is not a frame the
|
|
10573
|
+
* browser reports to the panel (an SSE comment is invisible to EventSource).
|
|
10574
|
+
*/
|
|
8675
10575
|
const HEARTBEAT_MS = 15e3;
|
|
8676
10576
|
/** Header replaced by an authenticated same-host reverse proxy. */
|
|
8677
10577
|
const TASK_BOARD_PROXY_TOKEN_HEADER = "x-dsh-task-board-proxy-token";
|
|
@@ -8702,7 +10602,9 @@ function resolveAccess(access) {
|
|
|
8702
10602
|
if (trustedProxyHosts.size > 0 && (access.proxyToken === void 0 || access.proxyToken === "")) throw new Error("task-board: authenticated proxy hosts require a non-empty proxy token");
|
|
8703
10603
|
return {
|
|
8704
10604
|
trustedProxyHosts,
|
|
8705
|
-
|
|
10605
|
+
trustForwardedProxy: access.trustForwardedProxy ?? (() => false),
|
|
10606
|
+
...access.proxyToken === void 0 ? {} : { proxyToken: access.proxyToken },
|
|
10607
|
+
...access.connection === void 0 ? {} : { connection: access.connection }
|
|
8706
10608
|
};
|
|
8707
10609
|
}
|
|
8708
10610
|
/**
|
|
@@ -8772,10 +10674,29 @@ function matchesToken(candidate, expected) {
|
|
|
8772
10674
|
* tripwire, the socket/Host/origin-equality checks carry the authority).
|
|
8773
10675
|
* Authenticated proxies must be explicitly allowlisted and replace the
|
|
8774
10676
|
* internal token header after their own authentication step.
|
|
10677
|
+
*
|
|
10678
|
+
* A third party's proxy cannot inject that token, so a deployment whose own
|
|
10679
|
+
* tunnel dials the loopback upstream (issue #1918) can instead turn on
|
|
10680
|
+
* trustForwardedProxy: a forwarded request that landed on this machine
|
|
10681
|
+
* (loopback socket AND loopback Host) is then admitted on the same browser
|
|
10682
|
+
* marker alone. The switch defaults off, so an unconfigured board keeps
|
|
10683
|
+
* refusing every forwarded request (issue #1906).
|
|
10684
|
+
*
|
|
10685
|
+
* A deployment behind a reverse proxy or ingress that DSH itself serves
|
|
10686
|
+
* (`--trusted-host`, TLS terminated at the edge) is admitted by the Host's
|
|
10687
|
+
* `connection` service instead: a request whose Host/Origin fence and signed
|
|
10688
|
+
* browser session it accepts needs no board-specific allowlist, which is why
|
|
10689
|
+
* the check runs first when the service is mounted (issue #1930). The fence
|
|
10690
|
+
* below stays untouched as the fallback, so a deployment without the service,
|
|
10691
|
+
* and every direct client the service does not admit, keeps exactly the
|
|
10692
|
+
* pre-existing decision.
|
|
8775
10693
|
*/
|
|
8776
10694
|
function isTrustedTaskBoardRequest(req, access) {
|
|
10695
|
+
const connection = access.connection?.();
|
|
10696
|
+
if (connection !== void 0 && connection.requestRejection(req) === void 0) return true;
|
|
8777
10697
|
if (!browserSameOriginMarker(req)) return false;
|
|
8778
10698
|
if (isLoopbackRequest(req)) return true;
|
|
10699
|
+
if (access.trustForwardedProxy() && req.headers["sec-fetch-site"] !== "cross-site" && isForwardedLoopbackRequest(req)) return true;
|
|
8779
10700
|
if (!isLoopbackAddress(req.socket.remoteAddress)) return false;
|
|
8780
10701
|
const host = req.headers.host;
|
|
8781
10702
|
if (typeof host !== "string") return false;
|
|
@@ -8799,6 +10720,17 @@ async function readBody(req) {
|
|
|
8799
10720
|
value: JSON.parse(raw)
|
|
8800
10721
|
};
|
|
8801
10722
|
}
|
|
10723
|
+
/**
|
|
10724
|
+
* The query parameters of one request, read against a fixed base so a
|
|
10725
|
+
* relative request target still parses.
|
|
10726
|
+
*/
|
|
10727
|
+
function requestQuery(req) {
|
|
10728
|
+
try {
|
|
10729
|
+
return new URL(req.url ?? "/", "http://localhost").searchParams;
|
|
10730
|
+
} catch {
|
|
10731
|
+
return new URLSearchParams();
|
|
10732
|
+
}
|
|
10733
|
+
}
|
|
8802
10734
|
function makeTaskBoardRoutes(service, access = {}, options = {}) {
|
|
8803
10735
|
const resolvedAccess = resolveAccess(access);
|
|
8804
10736
|
const guard = (req, res) => {
|
|
@@ -8846,9 +10778,17 @@ function makeTaskBoardRoutes(service, access = {}, options = {}) {
|
|
|
8846
10778
|
ok: false,
|
|
8847
10779
|
error: "body-too-large"
|
|
8848
10780
|
}, { "cache-control": "no-store" });
|
|
8849
|
-
writeJson(res, 200, await service.
|
|
10781
|
+
writeJson(res, 200, await service.applyVerified(parsed.requestId, parsed.action, parsed.initiator), { "cache-control": "no-store" });
|
|
8850
10782
|
} catch (error) {
|
|
8851
10783
|
const message = error instanceof Error ? error.message : String(error);
|
|
10784
|
+
if (error instanceof TaskBoardAttachmentError) {
|
|
10785
|
+
writeJson(res, attachmentErrorStatus(error.code), {
|
|
10786
|
+
ok: false,
|
|
10787
|
+
code: error.code,
|
|
10788
|
+
error: message
|
|
10789
|
+
}, { "cache-control": "no-store" });
|
|
10790
|
+
return;
|
|
10791
|
+
}
|
|
8852
10792
|
writeJson(res, message === "body-too-large" ? 413 : 400, {
|
|
8853
10793
|
ok: false,
|
|
8854
10794
|
error: message
|
|
@@ -8871,20 +10811,40 @@ function makeTaskBoardRoutes(service, access = {}, options = {}) {
|
|
|
8871
10811
|
"cache-control": "no-cache",
|
|
8872
10812
|
connection: "keep-alive"
|
|
8873
10813
|
});
|
|
10814
|
+
let heartbeat;
|
|
10815
|
+
let release;
|
|
10816
|
+
const stop = () => {
|
|
10817
|
+
if (heartbeat !== void 0) {
|
|
10818
|
+
clearInterval(heartbeat);
|
|
10819
|
+
heartbeat = void 0;
|
|
10820
|
+
}
|
|
10821
|
+
const unsubscribe = release;
|
|
10822
|
+
release = void 0;
|
|
10823
|
+
unsubscribe?.();
|
|
10824
|
+
};
|
|
10825
|
+
const drop = () => {
|
|
10826
|
+
if (release === void 0) return;
|
|
10827
|
+
stop();
|
|
10828
|
+
res.destroy();
|
|
10829
|
+
};
|
|
10830
|
+
const write = (chunk) => {
|
|
10831
|
+
if (release === void 0 || res.writableEnded || res.destroyed) return;
|
|
10832
|
+
res.write(chunk, (error) => {
|
|
10833
|
+
if (error !== null && error !== void 0) drop();
|
|
10834
|
+
});
|
|
10835
|
+
};
|
|
8874
10836
|
const push = () => {
|
|
8875
|
-
|
|
8876
|
-
res.write(`data: ${JSON.stringify(payload)}\n\n`);
|
|
10837
|
+
write(`data: ${JSON.stringify(service.eventPayload())}\n\n`);
|
|
8877
10838
|
};
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
10839
|
+
release = service.subscribe(push);
|
|
10840
|
+
heartbeat = setInterval(() => {
|
|
10841
|
+
write(": ping\n\n");
|
|
8881
10842
|
}, HEARTBEAT_MS);
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
res.once("close", close);
|
|
10843
|
+
req.once("close", stop);
|
|
10844
|
+
res.once("close", stop);
|
|
10845
|
+
res.on("error", () => {
|
|
10846
|
+
drop();
|
|
10847
|
+
});
|
|
8888
10848
|
push();
|
|
8889
10849
|
}
|
|
8890
10850
|
},
|
|
@@ -8966,6 +10926,98 @@ function makeTaskBoardRoutes(service, access = {}, options = {}) {
|
|
|
8966
10926
|
}, { "cache-control": "no-store" });
|
|
8967
10927
|
}
|
|
8968
10928
|
}
|
|
10929
|
+
},
|
|
10930
|
+
{
|
|
10931
|
+
kind: "exact",
|
|
10932
|
+
path: `${TASK_BOARD_API_PREFIX}/attachments/upload`,
|
|
10933
|
+
handler: async (req, res) => {
|
|
10934
|
+
if (req.method !== "POST") return writeJson(res, 405, {
|
|
10935
|
+
ok: false,
|
|
10936
|
+
error: "method-not-allowed"
|
|
10937
|
+
}, { "cache-control": "no-store" });
|
|
10938
|
+
if (!guard(req, res)) return;
|
|
10939
|
+
const store = options.attachments?.();
|
|
10940
|
+
if (store === void 0) return writeJson(res, 503, {
|
|
10941
|
+
ok: false,
|
|
10942
|
+
code: "storage-unavailable",
|
|
10943
|
+
error: "this deployment serves no attachment storage"
|
|
10944
|
+
}, { "cache-control": "no-store" });
|
|
10945
|
+
const query = requestQuery(req);
|
|
10946
|
+
const kind = query.get("kind");
|
|
10947
|
+
if (kind !== "image" && kind !== "file") return writeJson(res, 400, {
|
|
10948
|
+
ok: false,
|
|
10949
|
+
code: "invalid-request",
|
|
10950
|
+
error: "the attachment kind must be image or file"
|
|
10951
|
+
}, { "cache-control": "no-store" });
|
|
10952
|
+
const name = sanitizeAttachmentName(query.get("name"));
|
|
10953
|
+
const mediaType = query.get("mediaType") ?? "";
|
|
10954
|
+
try {
|
|
10955
|
+
if (kind === "image") {
|
|
10956
|
+
if (mediaType === "") return writeJson(res, 400, {
|
|
10957
|
+
ok: false,
|
|
10958
|
+
code: "invalid-request",
|
|
10959
|
+
error: "an image upload must declare its media type"
|
|
10960
|
+
}, { "cache-control": "no-store" });
|
|
10961
|
+
writeJson(res, 200, {
|
|
10962
|
+
ok: true,
|
|
10963
|
+
attachment: await storeImage(store, await readRequestBytes(req, effectiveImageByteLimit(store)), name, mediaType)
|
|
10964
|
+
}, { "cache-control": "no-store" });
|
|
10965
|
+
return;
|
|
10966
|
+
}
|
|
10967
|
+
writeJson(res, 200, {
|
|
10968
|
+
ok: true,
|
|
10969
|
+
attachment: (await storeFile(store, requestChunks(req), name, mediaType)).attachment
|
|
10970
|
+
}, { "cache-control": "no-store" });
|
|
10971
|
+
} catch (error) {
|
|
10972
|
+
req.resume();
|
|
10973
|
+
const failure = error instanceof TaskBoardAttachmentError ? error : new TaskBoardAttachmentError("storage-unavailable", "the attachment storage is unavailable", { cause: error });
|
|
10974
|
+
writeJson(res, attachmentErrorStatus(failure.code), {
|
|
10975
|
+
ok: false,
|
|
10976
|
+
code: failure.code,
|
|
10977
|
+
error: failure.message
|
|
10978
|
+
}, { "cache-control": "no-store" });
|
|
10979
|
+
}
|
|
10980
|
+
}
|
|
10981
|
+
},
|
|
10982
|
+
{
|
|
10983
|
+
kind: "exact",
|
|
10984
|
+
path: `${TASK_BOARD_API_PREFIX}/attachments/image`,
|
|
10985
|
+
handler: async (req, res) => {
|
|
10986
|
+
if (req.method !== "GET") return writeJson(res, 405, {
|
|
10987
|
+
ok: false,
|
|
10988
|
+
error: "method-not-allowed"
|
|
10989
|
+
}, { "cache-control": "no-store" });
|
|
10990
|
+
if (!guard(req, res)) return;
|
|
10991
|
+
const store = options.attachments?.();
|
|
10992
|
+
if (store === void 0) return writeJson(res, 503, {
|
|
10993
|
+
ok: false,
|
|
10994
|
+
code: "storage-unavailable",
|
|
10995
|
+
error: "this deployment serves no attachment storage"
|
|
10996
|
+
}, { "cache-control": "no-store" });
|
|
10997
|
+
const id = requestQuery(req).get("id") ?? "";
|
|
10998
|
+
const referenced = service.ledger.allTasks().flatMap((task) => task.attachments ?? []).find((attachment) => attachment.kind === "image" && attachment.attachmentId === id);
|
|
10999
|
+
if (referenced === void 0) return writeJson(res, 404, {
|
|
11000
|
+
ok: false,
|
|
11001
|
+
code: "not-found",
|
|
11002
|
+
error: "no card references this attachment"
|
|
11003
|
+
}, { "cache-control": "no-store" });
|
|
11004
|
+
try {
|
|
11005
|
+
const stored = await store.readImage(imageRefOf(referenced));
|
|
11006
|
+
res.writeHead(200, {
|
|
11007
|
+
"content-type": stored.ref.mediaType,
|
|
11008
|
+
"content-length": String(stored.data.byteLength),
|
|
11009
|
+
"cache-control": "no-store"
|
|
11010
|
+
});
|
|
11011
|
+
res.end(Buffer.from(stored.data));
|
|
11012
|
+
} catch (error) {
|
|
11013
|
+
const failure = error instanceof TaskBoardAttachmentError ? error : new TaskBoardAttachmentError("unreadable", "the stored attachment could not be read back", { cause: error });
|
|
11014
|
+
writeJson(res, attachmentErrorStatus(failure.code), {
|
|
11015
|
+
ok: false,
|
|
11016
|
+
code: failure.code,
|
|
11017
|
+
error: failure.message
|
|
11018
|
+
}, { "cache-control": "no-store" });
|
|
11019
|
+
}
|
|
11020
|
+
}
|
|
8969
11021
|
}
|
|
8970
11022
|
];
|
|
8971
11023
|
}
|
|
@@ -10078,7 +12130,6 @@ const DEFAULT_PROXY_TOKEN_ENV = "DSH_TASK_BOARD_PROXY_TOKEN";
|
|
|
10078
12130
|
const inject = [
|
|
10079
12131
|
"systemPrompt",
|
|
10080
12132
|
"typertGateway",
|
|
10081
|
-
"connection",
|
|
10082
12133
|
"workspaceRegistry",
|
|
10083
12134
|
"webServer",
|
|
10084
12135
|
"agents",
|
|
@@ -10086,22 +12137,23 @@ const inject = [
|
|
|
10086
12137
|
];
|
|
10087
12138
|
/** Model-facing announcement: plugin presence, capabilities, and limits. */
|
|
10088
12139
|
const TASK_BOARD_GUIDANCE = "本机已安装 dsh-task-board 插件(DSH Web GUI 的任务看板):侧边栏「任务看板」入口;在 dsh-web 插件全家桶仓库(packages/dsh-task-board)统一维护,经聚合包 web-ui-all 一键安装。能力:多列看板管理任务;Host 权威账本;关闭浏览器后仍由 Host 执行和结算;任务可钉住工作区、agent 预设和权限;任务可建子任务(深度上限可配 1..3,默认 1 层,子任务不能再带子任务),执行父任务会并发执行其子任务树,子任务可单独覆盖权限与模型;另注册 task_board_* agent 工具(list/get/create/update/set_parent/run/manage/schedule),任何会话都可直接读写看板、子任务与定时计划,但运行任务会真实执行并消耗额度,高于会话默认权限的绑定仍必须由用户在 GUI 人工确认(工具刻意不提供确认能力);支持 Host 本地时区的 5 段 cron,错过的触发点不补跑;可选且默认关闭的空闲系统睡眠保护允许屏幕熄灭,但不承诺拦截合盖、手动睡眠、休眠、关机或唤醒已睡眠机器。执行消耗 API 额度。用户提到「任务看板 / 看板 / 定时任务」时即指本插件,请据此协作。若你同时用 todo_write 维护会话顶部的可见计划列表,最终回复前必须再次调用 todo_write 收尾:没有剩余工作时不要保留 in_progress,已完成的最后一步要标为 completed。";
|
|
10089
|
-
/**
|
|
10090
|
-
* Continuable-subagent provider for fresh teammates, matching the Agent Teams
|
|
10091
|
-
* tool plugin's own `freshProvider` default.
|
|
10092
|
-
*/
|
|
10093
|
-
const DEFAULT_TEAM_PROVIDER = "spawn";
|
|
10094
12140
|
const Config = z.object({
|
|
10095
12141
|
announceToAgent: z.boolean().default(false).volatile(),
|
|
10096
12142
|
enabled: z.boolean().default(true).volatile(),
|
|
10097
12143
|
preventIdleSleep: z.boolean().default(false).volatile(),
|
|
10098
12144
|
trustedProxyHosts: z.array(z.string()).default([]),
|
|
10099
12145
|
proxyTokenEnv: z.string().min(1).default(DEFAULT_PROXY_TOKEN_ENV),
|
|
12146
|
+
trustForwardedProxy: z.boolean().default(false).volatile(),
|
|
10100
12147
|
sessionDefaultPermission: z.union(TASK_PERMISSIONS),
|
|
10101
12148
|
maxSubtaskDepth: z.number().min(1).max(3).default(1).volatile(),
|
|
10102
12149
|
sessionPollSeconds: z.number().min(1).max(300).default(5).volatile(),
|
|
10103
|
-
|
|
12150
|
+
runLaunchWidth: z.number().min(1).max(16).default(3).volatile(),
|
|
12151
|
+
spendBudgetTokens: z.number().min(0).default(0).volatile(),
|
|
10104
12152
|
goalRunEnabled: z.boolean().default(false).volatile(),
|
|
12153
|
+
cardDefaultMode: z.string().default("").volatile(),
|
|
12154
|
+
cardDefaultPermission: z.union([...TASK_PERMISSIONS, ""]).default("").volatile(),
|
|
12155
|
+
cardDefaultModel: z.string().default("").volatile(),
|
|
12156
|
+
cardDefaultReasoningEffort: z.string().default("").volatile(),
|
|
10105
12157
|
goalVerification: z.boolean().default(true).volatile(),
|
|
10106
12158
|
goalVerificationModel: z.string().default("").volatile(),
|
|
10107
12159
|
goalVerificationReasoningEffort: z.string().default("").volatile(),
|
|
@@ -10132,19 +12184,64 @@ function readConfigField(field, fallback) {
|
|
|
10132
12184
|
if (typeof field === "object" && field !== null && typeof field.get === "function") return field.get();
|
|
10133
12185
|
return field;
|
|
10134
12186
|
}
|
|
10135
|
-
/**
|
|
12187
|
+
/**
|
|
12188
|
+
* Resolve proxy access without ever placing the token value in plugin config.
|
|
12189
|
+
*
|
|
12190
|
+
* The forwarded-proxy switch travels as a reader rather than a value: it is
|
|
12191
|
+
* schema-volatile, so the fence must read it when a request arrives instead of
|
|
12192
|
+
* when the routes are registered.
|
|
12193
|
+
* @param config - the resolved plugin config.
|
|
12194
|
+
* @param env - environment holding the proxy token value.
|
|
12195
|
+
* @returns the route access handed to {@link makeTaskBoardRoutes}.
|
|
12196
|
+
*/
|
|
10136
12197
|
function resolveProxyAccess(config, env = process.env) {
|
|
12198
|
+
const trustForwardedProxy = () => readConfigField(config?.trustForwardedProxy, false);
|
|
10137
12199
|
const trustedProxyHosts = config?.trustedProxyHosts ?? [];
|
|
10138
|
-
if (trustedProxyHosts.length === 0) return {
|
|
12200
|
+
if (trustedProxyHosts.length === 0) return {
|
|
12201
|
+
trustedProxyHosts,
|
|
12202
|
+
trustForwardedProxy
|
|
12203
|
+
};
|
|
10139
12204
|
const proxyTokenEnv = config?.proxyTokenEnv ?? "DSH_TASK_BOARD_PROXY_TOKEN";
|
|
10140
12205
|
if (proxyTokenEnv.trim() === "") throw new Error("task-board: proxyTokenEnv must not be empty");
|
|
10141
12206
|
const proxyToken = env[proxyTokenEnv];
|
|
10142
12207
|
if (proxyToken === void 0 || proxyToken === "") throw new Error(`task-board: trustedProxyHosts requires a non-empty ${proxyTokenEnv} environment variable`);
|
|
10143
12208
|
return {
|
|
10144
12209
|
trustedProxyHosts,
|
|
10145
|
-
proxyToken
|
|
12210
|
+
proxyToken,
|
|
12211
|
+
trustForwardedProxy
|
|
10146
12212
|
};
|
|
10147
12213
|
}
|
|
12214
|
+
/**
|
|
12215
|
+
/**
|
|
12216
|
+
* Schema default for the forwarded-proxy switch, re-read for hand-built
|
|
12217
|
+
* contexts. Deliberately false: a deployment that never configured it keeps
|
|
12218
|
+
* refusing every forwarded request, which is the #1906 fence.
|
|
12219
|
+
*/
|
|
12220
|
+
const DEFAULT_TRUST_FORWARDED_PROXY = false;
|
|
12221
|
+
/**
|
|
12222
|
+
* Resolve the composition's optional `connection` service.
|
|
12223
|
+
*
|
|
12224
|
+
* The service is the Host's own browser-session authority: it fronts every
|
|
12225
|
+
* `/api` request with the Host/Origin fence and the signed `dsh-auth-*` cookie,
|
|
12226
|
+
* which is what a deployment behind a reverse proxy or ingress validates on the
|
|
12227
|
+
* same authority the GUI is served from. The board bridges it instead of
|
|
12228
|
+
* repeating that check, so a proxy request the Host already authenticated is
|
|
12229
|
+
* admitted without a board-specific host allowlist (issue #1930). It is
|
|
12230
|
+
* deliberately resolved like the agent-tool registry rather than injected:
|
|
12231
|
+
* a composition that serves no connection keeps mounting the board on the
|
|
12232
|
+
* pre-existing loopback fence, and one that mounts the service later is picked
|
|
12233
|
+
* up on the next request because the fence asks this resolver each time.
|
|
12234
|
+
* @param ctx - the plugin context.
|
|
12235
|
+
* @returns the trust face, or undefined when this deployment serves none.
|
|
12236
|
+
*/
|
|
12237
|
+
function resolveConnectionTrust(ctx) {
|
|
12238
|
+
try {
|
|
12239
|
+
const connection = ctx.get("connection");
|
|
12240
|
+
return connection !== void 0 && typeof connection.requestRejection === "function" ? connection : void 0;
|
|
12241
|
+
} catch {
|
|
12242
|
+
return;
|
|
12243
|
+
}
|
|
12244
|
+
}
|
|
10148
12245
|
/** The lookup half of a resolved registry, when it exposes one. */
|
|
10149
12246
|
function lookupOf(registry) {
|
|
10150
12247
|
return registry !== void 0 && typeof registry.get === "function" ? { get: registry.get.bind(registry) } : void 0;
|
|
@@ -10210,80 +12307,106 @@ function resolveHostDefaultPermission(ctx) {
|
|
|
10210
12307
|
}
|
|
10211
12308
|
}
|
|
10212
12309
|
/**
|
|
10213
|
-
*
|
|
10214
|
-
*
|
|
10215
|
-
*
|
|
12310
|
+
* Read the optional `llm` service. The board deliberately does not inject it:
|
|
12311
|
+
* a deployment without a model must still mount the board, and the parse route
|
|
12312
|
+
* answers a typed failure instead of the plugin failing to load (issue #1540).
|
|
12313
|
+
* @param ctx - the plugin context.
|
|
12314
|
+
* @returns the llm service, or undefined when this deployment serves none.
|
|
10216
12315
|
*/
|
|
10217
|
-
|
|
12316
|
+
function resolveLlmRuntime(ctx) {
|
|
12317
|
+
try {
|
|
12318
|
+
const llm = ctx.get("llm");
|
|
12319
|
+
return llm !== void 0 && typeof llm.stream === "function" ? llm : void 0;
|
|
12320
|
+
} catch {
|
|
12321
|
+
return;
|
|
12322
|
+
}
|
|
12323
|
+
}
|
|
10218
12324
|
/**
|
|
10219
|
-
* Resolve the optional
|
|
10220
|
-
*
|
|
10221
|
-
*
|
|
12325
|
+
* Resolve the optional attachment storage.
|
|
12326
|
+
*
|
|
12327
|
+
* The board does not inject the service: a deployment without one must still
|
|
12328
|
+
* mount the board, and every attachment surface then answers with a typed
|
|
12329
|
+
* "storage unavailable" failure instead of the plugin failing to load.
|
|
10222
12330
|
* @param ctx - the plugin context.
|
|
10223
|
-
* @returns the
|
|
12331
|
+
* @returns the attachment storage, or undefined when this deployment serves none.
|
|
10224
12332
|
*/
|
|
10225
|
-
function
|
|
12333
|
+
function resolveAttachmentStore(ctx) {
|
|
10226
12334
|
try {
|
|
10227
|
-
const
|
|
10228
|
-
return
|
|
12335
|
+
const store = ctx.get("attachments");
|
|
12336
|
+
return store !== void 0 && typeof store.saveImage === "function" ? store : void 0;
|
|
10229
12337
|
} catch {
|
|
10230
12338
|
return;
|
|
10231
12339
|
}
|
|
10232
12340
|
}
|
|
10233
12341
|
/**
|
|
10234
|
-
*
|
|
10235
|
-
*
|
|
10236
|
-
*
|
|
10237
|
-
*
|
|
10238
|
-
*
|
|
12342
|
+
* The model-info reader the image preflight uses.
|
|
12343
|
+
*
|
|
12344
|
+
* It asks the OFFICIAL model service about one exact route. The model catalog
|
|
12345
|
+
* the board already publishes carries no modality information and must not be
|
|
12346
|
+
* used to answer that question: only the model's own declared input
|
|
12347
|
+
* modalities can refuse an image route, and a route whose modalities cannot be
|
|
12348
|
+
* read is UNKNOWN and therefore allowed.
|
|
10239
12349
|
* @param ctx - the plugin context.
|
|
10240
|
-
* @
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
|
|
10244
|
-
|
|
10245
|
-
|
|
10246
|
-
if (typeof ctx.agents?.get !== "function") return void 0;
|
|
10247
|
-
return { async spawn(input) {
|
|
10248
|
-
const lead = ctx.agents.get(input.leadSessionId);
|
|
10249
|
-
if (lead === void 0) return { error: `lead session ${input.leadSessionId} is not live` };
|
|
12350
|
+
* @returns the reader, or undefined when the deployment serves no model service.
|
|
12351
|
+
*/
|
|
12352
|
+
function resolveModelInfoReader(ctx) {
|
|
12353
|
+
return async (provider, model) => {
|
|
12354
|
+
const llm = resolveLlmRuntime(ctx);
|
|
12355
|
+
if (llm === void 0) return void 0;
|
|
10250
12356
|
try {
|
|
10251
|
-
const
|
|
10252
|
-
|
|
10253
|
-
description: input.description,
|
|
10254
|
-
prompt: [{
|
|
10255
|
-
type: "text",
|
|
10256
|
-
text: input.prompt
|
|
10257
|
-
}],
|
|
10258
|
-
context: "fresh",
|
|
10259
|
-
provider,
|
|
10260
|
-
signal: AbortSignal.timeout(TEAMMATE_PROVISION_TIMEOUT_MS)
|
|
10261
|
-
}))?.member;
|
|
10262
|
-
if (member === void 0) return { error: "Agent Teams returned no teammate" };
|
|
10263
|
-
if (member.phase === "failed") return { error: member.error ?? "teammate provisioning failed" };
|
|
10264
|
-
if (typeof member.id !== "string" || member.id === "") return { error: "Agent Teams returned no teammate session" };
|
|
10265
|
-
return { sessionId: member.id };
|
|
12357
|
+
const info = await llm.resolveModelInfo(provider, model);
|
|
12358
|
+
return { ...info.inputModalities === void 0 ? {} : { inputModalities: info.inputModalities } };
|
|
10266
12359
|
} catch (error) {
|
|
10267
|
-
|
|
12360
|
+
console.warn("[dsh-task-board] could not resolve the model info of " + provider + "/" + model + "; the image preflight allows the route", error);
|
|
12361
|
+
return;
|
|
10268
12362
|
}
|
|
10269
|
-
}
|
|
12363
|
+
};
|
|
10270
12364
|
}
|
|
10271
12365
|
/**
|
|
10272
|
-
*
|
|
10273
|
-
*
|
|
10274
|
-
*
|
|
12366
|
+
* Resolve the optional `sessionController` service. Like the tool registry and
|
|
12367
|
+
* the llm runtime, it is read dynamically so capture-only test contexts that do
|
|
12368
|
+
* not mount the full session controller still activate the board.
|
|
10275
12369
|
* @param ctx - the plugin context.
|
|
10276
|
-
* @returns the
|
|
12370
|
+
* @returns the session controller face, or undefined when unavailable.
|
|
10277
12371
|
*/
|
|
10278
|
-
function
|
|
12372
|
+
function resolveSessionController(ctx) {
|
|
10279
12373
|
try {
|
|
10280
|
-
const
|
|
10281
|
-
return
|
|
12374
|
+
const controller = ctx.get?.("sessionController");
|
|
12375
|
+
return controller !== void 0 && typeof controller.resolveAgent === "function" ? controller : void 0;
|
|
10282
12376
|
} catch {
|
|
10283
12377
|
return;
|
|
10284
12378
|
}
|
|
10285
12379
|
}
|
|
10286
12380
|
/**
|
|
12381
|
+
* Resolve the live Agent for an execution session, resuming a cold persisted
|
|
12382
|
+
* session through `sessionController.resolveAgent` when it is not yet in
|
|
12383
|
+
* `ctx.agents` (issue #1861).
|
|
12384
|
+
*
|
|
12385
|
+
* A fresh run (`session/create`) or a session the browser is currently
|
|
12386
|
+
* following is already in `ctx.agents`, so the fast path returns immediately.
|
|
12387
|
+
* A scheduled or manual reuse of a cold session — one that `session/list`
|
|
12388
|
+
* reports as idle from disk without activating its Agent — is not in
|
|
12389
|
+
* `ctx.agents` when `pinAndPrompt` runs `/permission` ahead of
|
|
12390
|
+
* `session/selectModel` and `session/prompt`; delegating to
|
|
12391
|
+
* `sessionController.resolveAgent` resumes it with its recorded preset and
|
|
12392
|
+
* model-selection state, matching what those gateway endpoints do next.
|
|
12393
|
+
* @param ctx - the plugin context.
|
|
12394
|
+
* @param sessionId - the target execution session id.
|
|
12395
|
+
* @returns the live Agent for `sessionId`.
|
|
12396
|
+
*/
|
|
12397
|
+
async function resolveExecutionAgent(ctx, sessionId) {
|
|
12398
|
+
const live = ctx.agents.get(sessionId);
|
|
12399
|
+
if (live !== void 0) return live;
|
|
12400
|
+
const controller = resolveSessionController(ctx);
|
|
12401
|
+
if (controller !== void 0) {
|
|
12402
|
+
const resolved = await controller.resolveAgent(sessionId);
|
|
12403
|
+
if ("agent" in resolved && resolved.agent !== void 0) return resolved.agent;
|
|
12404
|
+
const detail = "error" in resolved && typeof resolved.error?.message === "string" && resolved.error.message !== "" ? `: ${resolved.error.message}` : "";
|
|
12405
|
+
throw new Error(`execution session ${sessionId} is not available${detail}`);
|
|
12406
|
+
}
|
|
12407
|
+
throw new Error(`execution session ${sessionId} is not available`);
|
|
12408
|
+
}
|
|
12409
|
+
/**
|
|
10287
12410
|
* Activate the board's host half: ledger, routes, cron scheduler, power
|
|
10288
12411
|
* inhibitor, and the model-facing announcement.
|
|
10289
12412
|
*
|
|
@@ -10309,6 +12432,18 @@ function applyImpl(ctx, config) {
|
|
|
10309
12432
|
/** Current roster-poll cadence in seconds (read live: the settings card edits it in place). */
|
|
10310
12433
|
const sessionPollSeconds = () => readConfigField(config?.sessionPollSeconds, 5);
|
|
10311
12434
|
/**
|
|
12435
|
+
* Current run-launch admission width. Read live on every admission, so the
|
|
12436
|
+
* settings card bounds the next launch of a run that is still queueing without
|
|
12437
|
+
* remounting the row; the Host clamps a hand-edited value into the schema range.
|
|
12438
|
+
*/
|
|
12439
|
+
const runLaunchWidth = () => readConfigField(config?.runLaunchWidth, 3);
|
|
12440
|
+
/**
|
|
12441
|
+
* Current daily token cap, read at each gate like the width above. The value
|
|
12442
|
+
* decides first: 0 — the default — ends the gate before a file is opened, so
|
|
12443
|
+
* a board that never set a cap pays nothing for it.
|
|
12444
|
+
*/
|
|
12445
|
+
const spendBudgetTokens = () => readConfigField(config?.spendBudgetTokens, 0);
|
|
12446
|
+
/**
|
|
10312
12447
|
* The baseline the permission confirmation gate judges against: the row's own
|
|
10313
12448
|
* `sessionDefaultPermission` when the deployment pins one, otherwise the Host's
|
|
10314
12449
|
* default preset. Read per call through the ledger, so a Host Settings change
|
|
@@ -10340,19 +12475,48 @@ function applyImpl(ctx, config) {
|
|
|
10340
12475
|
* executions that start afterwards.
|
|
10341
12476
|
*/
|
|
10342
12477
|
const goalRunEnabled = () => readConfigField(config?.goalRunEnabled, false);
|
|
12478
|
+
/**
|
|
12479
|
+
* Live reader of the new-card defaults, read at every use like the switch
|
|
12480
|
+
* above: the create dialog prefills from the published snapshot, and each
|
|
12481
|
+
* creating session re-reads them when it submits the create. A blank value
|
|
12482
|
+
* means "not set" and reaches the resolver as an absent target.
|
|
12483
|
+
*/
|
|
12484
|
+
const cardDefaults = () => {
|
|
12485
|
+
const permission = readConfigField(config?.cardDefaultPermission, "");
|
|
12486
|
+
return {
|
|
12487
|
+
mode: readConfigField(config?.cardDefaultMode, "").trim() || void 0,
|
|
12488
|
+
permission: isTaskPermission(permission) ? permission : void 0,
|
|
12489
|
+
model: readConfigField(config?.cardDefaultModel, "").trim() || void 0,
|
|
12490
|
+
reasoningEffort: readConfigField(config?.cardDefaultReasoningEffort, "").trim() || void 0
|
|
12491
|
+
};
|
|
12492
|
+
};
|
|
12493
|
+
const ownerPeer = createOwnerPeer(ctx);
|
|
12494
|
+
const legacyAgentTeams = () => {
|
|
12495
|
+
const lookup = lookupOf(resolveToolRegistry(ctx));
|
|
12496
|
+
if (lookup === void 0) return false;
|
|
12497
|
+
try {
|
|
12498
|
+
return lookup.get(LEGACY_AGENT_TEAMS_TOOL) !== void 0;
|
|
12499
|
+
} catch {
|
|
12500
|
+
return false;
|
|
12501
|
+
}
|
|
12502
|
+
};
|
|
10343
12503
|
const host = new TaskBoardHostService(ctx.typertGateway, {
|
|
10344
12504
|
workspaceRegistry: ctx.workspaceRegistry,
|
|
10345
|
-
|
|
12505
|
+
ownerPeer,
|
|
10346
12506
|
sessionDefaultPermission,
|
|
10347
12507
|
maxSubtaskDepth: maxSubtaskDepth(),
|
|
10348
12508
|
goalRunEnabled,
|
|
12509
|
+
runLaunchWidth,
|
|
12510
|
+
spendBudgetTokens,
|
|
12511
|
+
cardDefaults,
|
|
10349
12512
|
verificationSettings,
|
|
10350
12513
|
verificationCatalog,
|
|
12514
|
+
attachments: () => resolveAttachmentStore(ctx),
|
|
12515
|
+
modelInfo: () => resolveModelInfoReader(ctx),
|
|
12516
|
+
legacyAgentTeams,
|
|
10351
12517
|
timers: resolveHostTimers(ctx),
|
|
10352
|
-
team: buildTeamDispatcher(ctx, config?.teamProvider ?? "spawn"),
|
|
10353
12518
|
commandDispatcher: { async execute(sessionId, line, signal) {
|
|
10354
|
-
const agent = ctx
|
|
10355
|
-
if (agent === void 0) throw new Error(`execution session ${sessionId} is not available`);
|
|
12519
|
+
const agent = await resolveExecutionAgent(ctx, sessionId);
|
|
10356
12520
|
return (await ctx.commands.execute(agent, line, [], signal))?.result;
|
|
10357
12521
|
} }
|
|
10358
12522
|
});
|
|
@@ -10361,7 +12525,11 @@ function applyImpl(ctx, config) {
|
|
|
10361
12525
|
host.start();
|
|
10362
12526
|
if (typeof ctx.provide === "function") ctx.provide(TASK_BOARD_SERVICE_NAME, {
|
|
10363
12527
|
registerExtension: (extension) => host.registerExtension(extension),
|
|
10364
|
-
isExtensionEnabled: (extensionId) => host.extensions.isActive(extensionId)
|
|
12528
|
+
isExtensionEnabled: (extensionId) => host.extensions.isActive(extensionId),
|
|
12529
|
+
snapshot: () => host.snapshot(),
|
|
12530
|
+
apply: (requestId, action, initiator) => host.apply(requestId, action, initiator),
|
|
12531
|
+
subscribe: (listener) => host.subscribe(listener),
|
|
12532
|
+
verificationOptions: () => host.verificationOptions()
|
|
10365
12533
|
});
|
|
10366
12534
|
let disposeTools;
|
|
10367
12535
|
const setToolsEnabled = (active) => {
|
|
@@ -10426,11 +12594,17 @@ function applyImpl(ctx, config) {
|
|
|
10426
12594
|
handle.dispose();
|
|
10427
12595
|
});
|
|
10428
12596
|
}
|
|
10429
|
-
const routes = makeTaskBoardRoutes(host,
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
12597
|
+
const routes = makeTaskBoardRoutes(host, {
|
|
12598
|
+
...resolveProxyAccess(config),
|
|
12599
|
+
connection: () => resolveConnectionTrust(ctx)
|
|
12600
|
+
}, {
|
|
12601
|
+
attachments: () => resolveAttachmentStore(ctx),
|
|
12602
|
+
parseTask: async (request, signal) => {
|
|
12603
|
+
const llm = resolveLlmRuntime(ctx);
|
|
12604
|
+
if (llm === void 0) throw new TaskParseError("no-model", "this deployment serves no llm service");
|
|
12605
|
+
return await parseTaskDraft(llm, request, signal);
|
|
12606
|
+
}
|
|
12607
|
+
});
|
|
10434
12608
|
for (const route of routes) disposers.push(ctx.webServer.register(route));
|
|
10435
12609
|
} catch (error) {
|
|
10436
12610
|
setToolsEnabled(false);
|
|
@@ -10476,4 +12650,4 @@ function applyImpl(ctx, config) {
|
|
|
10476
12650
|
sync();
|
|
10477
12651
|
}
|
|
10478
12652
|
//#endregion
|
|
10479
|
-
export { Config, DEFAULT_GOAL_RUN, DEFAULT_GOAL_VERIFICATION, DEFAULT_PROXY_TOKEN_ENV,
|
|
12653
|
+
export { Config, DEFAULT_GOAL_RUN, DEFAULT_GOAL_VERIFICATION, DEFAULT_PROXY_TOKEN_ENV, DEFAULT_TRUST_FORWARDED_PROXY, TASK_BOARD_GUIDANCE, apply, inject, readConfigField, resolveAttachmentStore, resolveConnectionTrust, resolveExecutionAgent, resolveHostDefaultPermission, resolveHostTimers, resolveLlmRuntime, resolveModelInfoReader, resolveProxyAccess, resolveSessionController, resolveToolRegistry };
|