@linxin666/dsh-client-ui-task-board 0.4.19 → 0.4.21
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/README.i18n.yaml +2 -2
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/client.js +190 -63
- package/lib/client.js.map +1 -1
- package/lib/index.js +599 -95
- package/lib/types/client/board/TaskForm.d.ts +3 -1
- package/lib/types/client/index.d.ts +7 -1
- package/lib/types/client/native-panel.d.ts +1 -1
- package/lib/types/client/seats.d.ts +36 -2
- package/lib/types/client/settings-form.d.ts +2 -0
- package/lib/types/core/controller.d.ts +1 -1
- package/lib/types/core/extension.d.ts +160 -1
- package/lib/types/core/session-reuse.d.ts +46 -13
- package/lib/types/core/tasks.d.ts +16 -5
- package/lib/types/host/agent-tools.d.ts +12 -2
- package/lib/types/host/extension-registry.d.ts +38 -1
- package/lib/types/host-ledger.d.ts +86 -1
- package/lib/types/host-runner.d.ts +20 -1
- package/lib/types/host-service.d.ts +64 -15
- package/lib/types/protocol.d.ts +18 -1
- package/package.json +1 -1
- package/src/client/board/ExecutionLog.tsx +15 -2
- package/src/client/board/NewTaskModal.tsx +88 -3
- package/src/client/board/TaskDetail.tsx +18 -11
- package/src/client/board/TaskForm.tsx +13 -2
- package/src/client/board.module.css +67 -1
- package/src/client/index.ts +3 -0
- package/src/client/locales.ts +7 -6
- package/src/client/native-panel.tsx +2 -1
- package/src/client/seats.tsx +32 -4
- package/src/client/service.ts +3 -0
- package/src/client/settings-form.ts +21 -2
- package/src/core/controller.ts +9 -3
- package/src/core/execution-summary.ts +3 -2
- package/src/core/extension.ts +159 -1
- package/src/core/session-reuse.ts +58 -21
- package/src/core/store.ts +2 -0
- package/src/core/tasks.ts +16 -5
- package/src/host/agent-tools.ts +70 -17
- package/src/host/extension-registry.ts +157 -2
- package/src/host-ledger.ts +274 -23
- package/src/host-runner.ts +44 -5
- package/src/host-service.ts +190 -37
- package/src/protocol.ts +37 -3
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
|
-
import { accessSync, chmodSync, closeSync, constants, 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, utimesSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, join, win32 } from "node:path";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { isAbsolute as isAbsolute$1, join as join$1 } from "node:path/posix";
|
|
@@ -199,39 +199,47 @@ function sessionPollMs(seconds) {
|
|
|
199
199
|
//#endregion
|
|
200
200
|
//#region src/core/session-reuse.ts
|
|
201
201
|
/**
|
|
202
|
+
* The session the newest settled execution ran in, or undefined when no
|
|
203
|
+
* execution carries one.
|
|
204
|
+
*
|
|
205
|
+
* The launch path calls the reuse rule after `startExecution` appended this
|
|
206
|
+
* run's own open record, so the array tail is always an unsettled row at that
|
|
207
|
+
* point and the scan has to skip it (issue #1587).
|
|
208
|
+
* @param task - the task whose history is read.
|
|
209
|
+
* @returns the newest settled session id, if any.
|
|
210
|
+
*/
|
|
211
|
+
function newestSettledSessionId(task) {
|
|
212
|
+
for (let index = task.executions.length - 1; index >= 0; index -= 1) {
|
|
213
|
+
const candidate = task.executions[index];
|
|
214
|
+
if (candidate !== void 0 && candidate.sessionId !== void 0 && candidate.endedAt !== void 0) return candidate.sessionId;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
202
218
|
* Pick the session a new execution of this task may continue in, or undefined
|
|
203
219
|
* to mint a fresh conversation. Reuse requires ALL of:
|
|
204
|
-
* - the task opted in (`reuseSession === true`);
|
|
205
|
-
* - the task's newest
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* - the roster is known and that session is present and idle.
|
|
220
|
+
* - the task opted in (`reuseSession === true`) unless the caller forces it;
|
|
221
|
+
* - the task's newest settled execution carries a session id (issue #1587);
|
|
222
|
+
* - the roster is known and that session is present and idle;
|
|
223
|
+
* - that session is not archived, when the deployment reports an archive set
|
|
224
|
+
* (issue #2068).
|
|
210
225
|
*
|
|
211
226
|
* An unknown roster (session/list unavailable) never reuses: minting a fresh
|
|
212
227
|
* conversation is always safe, prompting into a session we cannot see is not.
|
|
228
|
+
* An archived session is refused for the same reason — the Host will not run a
|
|
229
|
+
* turn in it, so continuing there can only fail the run that tried.
|
|
213
230
|
* @param task - the task about to run.
|
|
214
231
|
* @param idleSessionIds - ids the last roster saw as present and not running;
|
|
215
232
|
* undefined when that roster is unknown.
|
|
216
|
-
* @param options
|
|
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.
|
|
233
|
+
* @param options - force and the archive set; see {@link ReuseOptions}.
|
|
220
234
|
* @returns the session id to continue in, or undefined for a fresh session.
|
|
221
235
|
*/
|
|
222
236
|
function reusableSessionId(task, idleSessionIds, options = {}) {
|
|
223
237
|
if (options.force !== true && task.reuseSession !== true) return void 0;
|
|
224
238
|
if (idleSessionIds === void 0) return void 0;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
last = candidate;
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (last === void 0 || last.sessionId === void 0) return void 0;
|
|
234
|
-
return idleSessionIds.has(last.sessionId) ? last.sessionId : void 0;
|
|
239
|
+
const newest = newestSettledSessionId(task);
|
|
240
|
+
if (newest === void 0) return void 0;
|
|
241
|
+
if (options.archivedSessionIds?.has(newest) === true) return void 0;
|
|
242
|
+
return idleSessionIds.has(newest) ? newest : void 0;
|
|
235
243
|
}
|
|
236
244
|
//#endregion
|
|
237
245
|
//#region src/host/launch-admission.ts
|
|
@@ -1611,12 +1619,13 @@ function executionSummaryOf(events, startedAt) {
|
|
|
1611
1619
|
function normalizeExecutionSummary(value) {
|
|
1612
1620
|
if (typeof value !== "object" || value === null) return void 0;
|
|
1613
1621
|
const row = value;
|
|
1614
|
-
if (typeof row.text !== "string"
|
|
1622
|
+
if (typeof row.text !== "string") return void 0;
|
|
1623
|
+
if (row.seq !== void 0 && (typeof row.seq !== "number" || !Number.isFinite(row.seq))) return void 0;
|
|
1615
1624
|
const text = row.text.trim();
|
|
1616
1625
|
if (text === "") return void 0;
|
|
1617
1626
|
return {
|
|
1618
1627
|
text: truncateExecutionSummary(text),
|
|
1619
|
-
seq: row.seq
|
|
1628
|
+
...row.seq === void 0 ? {} : { seq: row.seq }
|
|
1620
1629
|
};
|
|
1621
1630
|
}
|
|
1622
1631
|
/** Marker replacing every sensitive match. */
|
|
@@ -2011,7 +2020,9 @@ function parseLedger(raw) {
|
|
|
2011
2020
|
ownError: typeof execution.ownError === "string" ? execution.ownError : void 0,
|
|
2012
2021
|
summary: normalizeExecutionSummary(execution.summary),
|
|
2013
2022
|
rework: normalizeExecutionRework(execution.rework),
|
|
2014
|
-
external: execution.external === true ? true : void 0
|
|
2023
|
+
external: execution.external === true ? true : void 0,
|
|
2024
|
+
errorCode: typeof execution.errorCode === "string" && execution.errorCode !== "" ? execution.errorCode : void 0,
|
|
2025
|
+
retryHint: typeof execution.retryHint === "string" && execution.retryHint !== "" ? execution.retryHint : void 0
|
|
2015
2026
|
}));
|
|
2016
2027
|
task.workspaceId = normalizeTargetId(row.workspaceId);
|
|
2017
2028
|
task.mode = normalizeTargetId(row.mode);
|
|
@@ -3258,7 +3269,11 @@ function parseEnvelopeAction(value) {
|
|
|
3258
3269
|
"taskId",
|
|
3259
3270
|
"result",
|
|
3260
3271
|
"initiatedBy",
|
|
3261
|
-
"summary"
|
|
3272
|
+
"summary",
|
|
3273
|
+
"executionId",
|
|
3274
|
+
"startedAt",
|
|
3275
|
+
"errorCode",
|
|
3276
|
+
"retryHint"
|
|
3262
3277
|
])) return void 0;
|
|
3263
3278
|
if (taskId === void 0) return void 0;
|
|
3264
3279
|
if (action.result !== "succeeded" && action.result !== "failed") return void 0;
|
|
@@ -3267,6 +3282,11 @@ function parseEnvelopeAction(value) {
|
|
|
3267
3282
|
if (initiatedBy === "" || initiatedBy.length > 200) return void 0;
|
|
3268
3283
|
if (action.summary !== void 0 && typeof action.summary !== "string") return void 0;
|
|
3269
3284
|
const summary = typeof action.summary === "string" ? action.summary.trim().slice(0, EXTERNAL_SUMMARY_MAX_LENGTH) : "";
|
|
3285
|
+
if (action.executionId !== void 0 && (typeof action.executionId !== "string" || action.executionId === "" || action.executionId.length > 128)) return void 0;
|
|
3286
|
+
if (action.startedAt !== void 0 && (typeof action.startedAt !== "number" || !Number.isFinite(action.startedAt) || action.startedAt < 0)) return void 0;
|
|
3287
|
+
for (const key of ["errorCode", "retryHint"]) if (action[key] !== void 0 && typeof action[key] !== "string") return void 0;
|
|
3288
|
+
const errorCode = typeof action.errorCode === "string" ? action.errorCode.trim().slice(0, 64) : "";
|
|
3289
|
+
const retryHint = typeof action.retryHint === "string" ? action.retryHint.trim().slice(0, EXTERNAL_SUMMARY_MAX_LENGTH) : "";
|
|
3270
3290
|
return {
|
|
3271
3291
|
requestId: envelope.requestId,
|
|
3272
3292
|
action: {
|
|
@@ -3274,7 +3294,11 @@ function parseEnvelopeAction(value) {
|
|
|
3274
3294
|
taskId,
|
|
3275
3295
|
result: action.result,
|
|
3276
3296
|
initiatedBy,
|
|
3277
|
-
...summary === "" ? {} : { summary }
|
|
3297
|
+
...summary === "" ? {} : { summary },
|
|
3298
|
+
...action.executionId === void 0 ? {} : { executionId: action.executionId },
|
|
3299
|
+
...action.startedAt === void 0 ? {} : { startedAt: action.startedAt },
|
|
3300
|
+
...errorCode === "" ? {} : { errorCode },
|
|
3301
|
+
...retryHint === "" ? {} : { retryHint }
|
|
3278
3302
|
}
|
|
3279
3303
|
};
|
|
3280
3304
|
}
|
|
@@ -3544,8 +3568,25 @@ const LEGACY_START_TOLERANCE_MS = 2e3;
|
|
|
3544
3568
|
* live owner; only one that has been unreadable for longer than any write can
|
|
3545
3569
|
* take is treated as an unclean-shutdown leftover (issue #1528: a 0-byte lock
|
|
3546
3570
|
* kept the Host half from mounting until it was deleted by hand).
|
|
3571
|
+
*
|
|
3572
|
+
* The same window bounds the identity-unprobeable takeover below: it is two
|
|
3573
|
+
* heartbeat intervals, so an owner that keeps beating is never mistaken for a
|
|
3574
|
+
* leftover (issue #2061).
|
|
3547
3575
|
*/
|
|
3548
3576
|
const UNREADABLE_LOCK_GRACE_MS = 6e4;
|
|
3577
|
+
/**
|
|
3578
|
+
* How often the lock owner refreshes its lock file's mtime (issue #2061). The
|
|
3579
|
+
* record itself never changes, only the timestamp moves, so a later start can
|
|
3580
|
+
* tell a live owner from a hard-kill leftover even when the platform identity
|
|
3581
|
+
* probe reads nothing (a protected process, a WMI/CIM timeout). Two missed
|
|
3582
|
+
* beats age the lock past UNREADABLE_LOCK_GRACE_MS and make it reclaimable; a
|
|
3583
|
+
* beating owner stays protected.
|
|
3584
|
+
*/
|
|
3585
|
+
const LOCK_HEARTBEAT_MS = 3e4;
|
|
3586
|
+
const defaultLockProcessProbe = {
|
|
3587
|
+
isAlive: processIsAlive,
|
|
3588
|
+
startTimeMs: processStartTimeMs
|
|
3589
|
+
};
|
|
3549
3590
|
/** Whether the recorded start time proves the recorded PID is another process. */
|
|
3550
3591
|
function startTimeMismatch(recorded, actual, exact) {
|
|
3551
3592
|
return exact ? recorded !== actual : Math.abs(recorded - actual) > LEGACY_START_TOLERANCE_MS;
|
|
@@ -3633,6 +3674,10 @@ var HostTaskLedger = class {
|
|
|
3633
3674
|
requestCache = /* @__PURE__ */ new Map();
|
|
3634
3675
|
lockToken = crypto.randomUUID();
|
|
3635
3676
|
lockFd;
|
|
3677
|
+
lockHeartbeat;
|
|
3678
|
+
processProbe;
|
|
3679
|
+
/** Warning sink; defaults to console.warn, tests inject a collector. */
|
|
3680
|
+
warn;
|
|
3636
3681
|
file;
|
|
3637
3682
|
lockFile;
|
|
3638
3683
|
/** Small sidecar for the 30 s scheduler heartbeat (lastTickAt only). */
|
|
@@ -3663,6 +3708,16 @@ var HostTaskLedger = class {
|
|
|
3663
3708
|
spendBudget;
|
|
3664
3709
|
/** Today's measured spend in tokens, or undefined when nothing can be measured. */
|
|
3665
3710
|
spendUsed;
|
|
3711
|
+
/**
|
|
3712
|
+
* The board's launch gate, or undefined when no consumer is attached.
|
|
3713
|
+
*
|
|
3714
|
+
* The ledger is where every run is opened — the run actions, a due schedule,
|
|
3715
|
+
* the run tool, a rework all arrive here — so this is the one point a run can
|
|
3716
|
+
* be handed to someone else before an execution record exists. Installed by
|
|
3717
|
+
* the Host service after construction, because the gate belongs to the
|
|
3718
|
+
* extension registry that is built around this ledger.
|
|
3719
|
+
*/
|
|
3720
|
+
launchGate;
|
|
3666
3721
|
constructor(dir = join(dshHome(), "task-board"), now = Date.now, options = {}) {
|
|
3667
3722
|
this.now = now;
|
|
3668
3723
|
const baseline = options.sessionDefaultPermission;
|
|
@@ -3671,12 +3726,18 @@ var HostTaskLedger = class {
|
|
|
3671
3726
|
this.cardDefaults = options.cardDefaults ?? (() => ({}));
|
|
3672
3727
|
this.spendBudget = options.spendBudgetTokens ?? (() => 0);
|
|
3673
3728
|
this.spendUsed = options.spendUsedToday ?? ((now) => usedTokensToday(now));
|
|
3729
|
+
this.launchGate = options.launchGate;
|
|
3730
|
+
this.processProbe = options.processProbe ?? defaultLockProcessProbe;
|
|
3731
|
+
this.warn = options.warn ?? ((message) => {
|
|
3732
|
+
console.warn(message);
|
|
3733
|
+
});
|
|
3674
3734
|
mkdirSync(dir, { recursive: true });
|
|
3675
3735
|
this.file = join(dir, "ledger-v2.json");
|
|
3676
3736
|
this.lockFile = join(dir, "ledger-v2.lock");
|
|
3677
3737
|
this.schedulerFile = join(dir, "scheduler-v2.json");
|
|
3678
3738
|
this.cleanStaleTemporaryFiles(dir);
|
|
3679
3739
|
this.lockFd = this.acquireLock();
|
|
3740
|
+
this.startLockHeartbeat();
|
|
3680
3741
|
try {
|
|
3681
3742
|
this.document = this.load(dir);
|
|
3682
3743
|
for (const request of this.document.recentRequests) this.requestCache.set(request.requestId, { fingerprint: request.fingerprint });
|
|
@@ -3704,6 +3765,18 @@ var HostTaskLedger = class {
|
|
|
3704
3765
|
this.depthLimit = next;
|
|
3705
3766
|
this.notify();
|
|
3706
3767
|
}
|
|
3768
|
+
/**
|
|
3769
|
+
* Install the launch gate, or remove it with undefined.
|
|
3770
|
+
*
|
|
3771
|
+
* The Host service owns it: the board's extension registry is built around
|
|
3772
|
+
* this ledger, so the gate is attached once that registry exists. A ledger
|
|
3773
|
+
* with no gate — every ledger a test drives on its own — opens every run
|
|
3774
|
+
* itself, exactly as it did before the seam existed.
|
|
3775
|
+
* @param gate - the gate to consult before a run opens, or undefined.
|
|
3776
|
+
*/
|
|
3777
|
+
setLaunchGate(gate) {
|
|
3778
|
+
this.launchGate = gate;
|
|
3779
|
+
}
|
|
3707
3780
|
/** Remove leftover *.tmp-* files from previous crashes or interrupted writes. */
|
|
3708
3781
|
cleanStaleTemporaryFiles(dir) {
|
|
3709
3782
|
try {
|
|
@@ -3815,7 +3888,39 @@ var HostTaskLedger = class {
|
|
|
3815
3888
|
this.listeners.delete(listener);
|
|
3816
3889
|
};
|
|
3817
3890
|
}
|
|
3891
|
+
/**
|
|
3892
|
+
* Refresh the lock's mtime so a later start can distinguish a live owner from
|
|
3893
|
+
* a hard-kill leftover without reading the process identity (issue #2061).
|
|
3894
|
+
* Best-effort: a failed beat only ages the lock, and a record that no longer
|
|
3895
|
+
* carries this owner's token stops the heartbeat instead of beating for
|
|
3896
|
+
* whoever holds the lock now.
|
|
3897
|
+
*/
|
|
3898
|
+
renewLock() {
|
|
3899
|
+
if (this.lockFd === void 0) return;
|
|
3900
|
+
try {
|
|
3901
|
+
if (JSON.parse(readFileSync(this.lockFile, "utf8")).token !== this.lockToken) {
|
|
3902
|
+
this.warn(`[task-board] lost the ledger lock to another owner; this instance stops renewing ${this.lockFile}`);
|
|
3903
|
+
this.stopLockHeartbeat();
|
|
3904
|
+
return;
|
|
3905
|
+
}
|
|
3906
|
+
const seconds = this.now() / 1e3;
|
|
3907
|
+
utimesSync(this.lockFile, seconds, seconds);
|
|
3908
|
+
} catch {}
|
|
3909
|
+
}
|
|
3910
|
+
startLockHeartbeat() {
|
|
3911
|
+
const timer = setInterval(() => {
|
|
3912
|
+
this.renewLock();
|
|
3913
|
+
}, LOCK_HEARTBEAT_MS);
|
|
3914
|
+
timer.unref?.();
|
|
3915
|
+
this.lockHeartbeat = timer;
|
|
3916
|
+
}
|
|
3917
|
+
stopLockHeartbeat() {
|
|
3918
|
+
if (this.lockHeartbeat === void 0) return;
|
|
3919
|
+
clearInterval(this.lockHeartbeat);
|
|
3920
|
+
this.lockHeartbeat = void 0;
|
|
3921
|
+
}
|
|
3818
3922
|
dispose() {
|
|
3923
|
+
this.stopLockHeartbeat();
|
|
3819
3924
|
const fd = this.lockFd;
|
|
3820
3925
|
if (fd === void 0) return;
|
|
3821
3926
|
this.lockFd = void 0;
|
|
@@ -3824,7 +3929,7 @@ var HostTaskLedger = class {
|
|
|
3824
3929
|
if (JSON.parse(readFileSync(this.lockFile, "utf8")).token === this.lockToken) unlinkSync(this.lockFile);
|
|
3825
3930
|
} catch {}
|
|
3826
3931
|
}
|
|
3827
|
-
applyRequest(requestId, action, initiator) {
|
|
3932
|
+
applyRequest(requestId, action, initiator, trigger) {
|
|
3828
3933
|
const fingerprint = createHash("sha256").update(JSON.stringify(action)).digest("hex");
|
|
3829
3934
|
const cached = this.requestCache.get(requestId);
|
|
3830
3935
|
if (cached !== void 0) {
|
|
@@ -3835,7 +3940,7 @@ var HostTaskLedger = class {
|
|
|
3835
3940
|
while (this.requestCache.size > MAX_REQUEST_CACHE) this.requestCache.delete(this.requestCache.keys().next().value);
|
|
3836
3941
|
this.syncRecentRequests();
|
|
3837
3942
|
try {
|
|
3838
|
-
return this.apply(action, initiator);
|
|
3943
|
+
return this.apply(action, initiator, trigger);
|
|
3839
3944
|
} catch (error) {
|
|
3840
3945
|
this.requestCache.delete(requestId);
|
|
3841
3946
|
this.syncRecentRequests();
|
|
@@ -3843,6 +3948,25 @@ var HostTaskLedger = class {
|
|
|
3843
3948
|
}
|
|
3844
3949
|
}
|
|
3845
3950
|
/**
|
|
3951
|
+
* Open the run one due occurrence produced, with the occurrence's own progress
|
|
3952
|
+
* written in the same commit.
|
|
3953
|
+
*
|
|
3954
|
+
* The occurrence is spent either way: a launch gate that hands the run to a
|
|
3955
|
+
* provider still consumed this trigger, so the rule's budget advances here
|
|
3956
|
+
* exactly as it does for a run the Host opens itself. A call that opened
|
|
3957
|
+
* nothing commits the progress it recorded on its own, because the fire path
|
|
3958
|
+
* has no other commit behind it.
|
|
3959
|
+
* @param task - the card whose rule fired.
|
|
3960
|
+
* @param triggeredAt - the instant the occurrence came due.
|
|
3961
|
+
* @param progress - the rule's advance, recorded atomically with the launch.
|
|
3962
|
+
* @returns the executions the occurrence opened.
|
|
3963
|
+
*/
|
|
3964
|
+
scheduledRun(task, triggeredAt, progress) {
|
|
3965
|
+
const started = this.startRun(task, triggeredAt, void 0, false, progress, void 0, "schedule");
|
|
3966
|
+
if (!started.committed) this.commit();
|
|
3967
|
+
return started.runs;
|
|
3968
|
+
}
|
|
3969
|
+
/**
|
|
3846
3970
|
* Open the one run a due schedule triggers: an empty array means nothing ran
|
|
3847
3971
|
* (already running, a card whose elevated permission is still unconfirmed, a
|
|
3848
3972
|
* one-shot whose instant was missed, or an exhausted budget), and the rule's
|
|
@@ -3873,7 +3997,7 @@ var HostTaskLedger = class {
|
|
|
3873
3997
|
this.skipOccurrence(taskId, "permission", triggeredAt);
|
|
3874
3998
|
return [];
|
|
3875
3999
|
}
|
|
3876
|
-
if (hasOpenExecution(task)) {
|
|
4000
|
+
if (hasOpenExecution(task) || task.status === "running") {
|
|
3877
4001
|
this.skipOccurrence(taskId, "busy", triggeredAt);
|
|
3878
4002
|
return [];
|
|
3879
4003
|
}
|
|
@@ -3883,7 +4007,7 @@ var HostTaskLedger = class {
|
|
|
3883
4007
|
this.skipOccurrence(taskId, "limit", triggeredAt);
|
|
3884
4008
|
return [];
|
|
3885
4009
|
}
|
|
3886
|
-
if (schedule.mode === "once") return this.
|
|
4010
|
+
if (schedule.mode === "once") return this.scheduledRun(task, triggeredAt, {
|
|
3887
4011
|
consumed: 1,
|
|
3888
4012
|
lastTriggeredAt: triggeredAt,
|
|
3889
4013
|
endedReason: "fired"
|
|
@@ -3899,7 +4023,7 @@ var HostTaskLedger = class {
|
|
|
3899
4023
|
const consumed = schedule.runCount + 1;
|
|
3900
4024
|
const budget = scheduleRunBudget(schedule);
|
|
3901
4025
|
const spent = budget !== void 0 && consumed >= budget;
|
|
3902
|
-
return this.
|
|
4026
|
+
return this.scheduledRun(task, triggeredAt, {
|
|
3903
4027
|
consumed: 1,
|
|
3904
4028
|
nextRunAt: spent ? void 0 : next,
|
|
3905
4029
|
lastTriggeredAt: triggeredAt,
|
|
@@ -4153,9 +4277,11 @@ var HostTaskLedger = class {
|
|
|
4153
4277
|
else this.document.tasks = [...this.document.tasks, task];
|
|
4154
4278
|
this.commit();
|
|
4155
4279
|
}
|
|
4156
|
-
apply(action, initiator) {
|
|
4280
|
+
apply(action, initiator, trigger) {
|
|
4157
4281
|
const now = this.now();
|
|
4158
4282
|
let runs;
|
|
4283
|
+
/** Whether the run path already committed this action's write. */
|
|
4284
|
+
let startCommitted = false;
|
|
4159
4285
|
switch (action.kind) {
|
|
4160
4286
|
case "import": {
|
|
4161
4287
|
const sources = new Set(this.document.scheduler.importedSources ?? []);
|
|
@@ -4239,13 +4365,18 @@ var HostTaskLedger = class {
|
|
|
4239
4365
|
if (task === void 0) throw new Error("task not found");
|
|
4240
4366
|
if (task.archivedAt !== void 0) throw new Error("archived task is read-only");
|
|
4241
4367
|
if (hasOpenExecution(task)) throw new Error("running task cannot receive an external outcome");
|
|
4368
|
+
if (action.executionId !== void 0 && task.executions.some((entry) => entry.id === action.executionId)) throw new Error("execution id already recorded");
|
|
4369
|
+
const succeeded = action.result === "succeeded";
|
|
4242
4370
|
const execution = {
|
|
4243
|
-
id: crypto.randomUUID(),
|
|
4371
|
+
id: action.executionId ?? crypto.randomUUID(),
|
|
4244
4372
|
sessionId: void 0,
|
|
4245
|
-
startedAt: now,
|
|
4373
|
+
startedAt: action.startedAt === void 0 ? now : Math.min(action.startedAt, now),
|
|
4246
4374
|
endedAt: now,
|
|
4247
4375
|
result: action.result,
|
|
4248
|
-
error: action.summary,
|
|
4376
|
+
error: succeeded ? void 0 : action.summary,
|
|
4377
|
+
...succeeded || action.errorCode === void 0 ? {} : { errorCode: action.errorCode },
|
|
4378
|
+
...succeeded || action.retryHint === void 0 ? {} : { retryHint: action.retryHint },
|
|
4379
|
+
...succeeded && action.summary !== void 0 ? { summary: { text: action.summary } } : {},
|
|
4249
4380
|
initiatedBy: action.initiatedBy,
|
|
4250
4381
|
external: true
|
|
4251
4382
|
};
|
|
@@ -4316,12 +4447,14 @@ var HostTaskLedger = class {
|
|
|
4316
4447
|
const rework = action.kind === "rework" ? this.reworkInput(task, action.instructions) : void 0;
|
|
4317
4448
|
const refusal = this.bindingRefusal(task);
|
|
4318
4449
|
if (refusal !== void 0) throw new Error(bindingRefusalMessage(refusal, this.sessionDefaultPermission, "run"));
|
|
4319
|
-
|
|
4450
|
+
const started = this.startRun(task, now, initiator, action.kind !== "run", void 0, rework, action.kind === "run" ? trigger ?? "manual" : action.kind === "rerun" ? "rerun" : "manual");
|
|
4451
|
+
runs = started.runs;
|
|
4452
|
+
startCommitted = started.committed;
|
|
4320
4453
|
break;
|
|
4321
4454
|
}
|
|
4322
4455
|
default: throw new Error(`unknown task board action kind: ${String(action.kind)}`);
|
|
4323
4456
|
}
|
|
4324
|
-
if (runs === void 0 ||
|
|
4457
|
+
if (runs === void 0 || !startCommitted) this.commit();
|
|
4325
4458
|
return {
|
|
4326
4459
|
state: this.state(),
|
|
4327
4460
|
...runs === void 0 ? {} : { runs }
|
|
@@ -4395,6 +4528,15 @@ var HostTaskLedger = class {
|
|
|
4395
4528
|
* subagents inside this session), and the group id is what later lets the
|
|
4396
4529
|
* settlement fold a HISTORICAL multi-member group it opened before this
|
|
4397
4530
|
* behavior changed.
|
|
4531
|
+
*
|
|
4532
|
+
* This is also the launch gate: every entry that opens a run — the run and
|
|
4533
|
+
* rerun actions, a due schedule, the run tool, a rework — arrives here, which
|
|
4534
|
+
* makes it the only point where a provider can take a run over before an
|
|
4535
|
+
* execution record exists and before any session can be created. A gate that
|
|
4536
|
+
* answers `external` writes the running column instead of an execution and
|
|
4537
|
+
* nothing else: no session, no run record, no settlement. A gate that answers
|
|
4538
|
+
* `local` runs the card exactly as it would have, carrying the preamble the
|
|
4539
|
+
* provider asked for to the prompt.
|
|
4398
4540
|
* @param root - the task the user ran.
|
|
4399
4541
|
* @param now - clock instant (ms epoch).
|
|
4400
4542
|
* @param initiator - the DSH session that asked for the run (audit only).
|
|
@@ -4404,22 +4546,52 @@ var HostTaskLedger = class {
|
|
|
4404
4546
|
* atomic commit that opened the execution.
|
|
4405
4547
|
* @param rework - the reviewer's instructions, when this run redoes previous
|
|
4406
4548
|
* work; recorded on the execution it opens.
|
|
4549
|
+
* @param trigger - which entry asked for this run, handed to the gate.
|
|
4407
4550
|
*/
|
|
4408
|
-
startRun(root, now, initiator, rerun = false, progress, rework) {
|
|
4551
|
+
startRun(root, now, initiator, rerun = false, progress, rework, trigger = "manual") {
|
|
4409
4552
|
const before = this.document.tasks;
|
|
4410
4553
|
const [participant] = cascadeTargets(before, root.id);
|
|
4411
|
-
if (participant === void 0 || participant.archivedAt !== void 0) return
|
|
4412
|
-
|
|
4554
|
+
if (participant === void 0 || participant.archivedAt !== void 0) return {
|
|
4555
|
+
runs: [],
|
|
4556
|
+
committed: false
|
|
4557
|
+
};
|
|
4558
|
+
if (hasOpenExecution(participant)) return {
|
|
4559
|
+
runs: [],
|
|
4560
|
+
committed: false
|
|
4561
|
+
};
|
|
4562
|
+
const decision = this.launchGate?.(participant, { trigger });
|
|
4563
|
+
if (decision?.kind === "refuse") {
|
|
4564
|
+
if (progress !== void 0) return {
|
|
4565
|
+
runs: [],
|
|
4566
|
+
committed: false
|
|
4567
|
+
};
|
|
4568
|
+
throw new Error(`${decision.code}: ${decision.reason}`);
|
|
4569
|
+
}
|
|
4570
|
+
if (decision?.kind === "external") {
|
|
4571
|
+
let handed = before.map((task) => task.id === participant.id ? withStatus(participant, "running", now) : task);
|
|
4572
|
+
if (progress !== void 0) handed = applyScheduleProgress(handed, root.id, progress, now);
|
|
4573
|
+
this.document.tasks = [...handed];
|
|
4574
|
+
this.commit();
|
|
4575
|
+
return {
|
|
4576
|
+
runs: [],
|
|
4577
|
+
committed: true
|
|
4578
|
+
};
|
|
4579
|
+
}
|
|
4413
4580
|
const groupId = crypto.randomUUID();
|
|
4414
4581
|
const opened = startExecution(rerun ? withStatus(participant, "todo", now) : participant, now, crypto.randomUUID(), initiator, groupId, rework);
|
|
4415
4582
|
let tasks = before.map((task) => task.id === participant.id ? opened.task : task);
|
|
4416
4583
|
if (progress !== void 0) tasks = applyScheduleProgress(tasks, root.id, progress, now);
|
|
4417
4584
|
this.document.tasks = [...tasks];
|
|
4418
4585
|
this.commit();
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4586
|
+
const preamble = decision?.kind === "local" ? decision.promptPreamble : void 0;
|
|
4587
|
+
return {
|
|
4588
|
+
runs: [{
|
|
4589
|
+
task: resolveExecutionTargets(opened.task, before, this.maxSubtaskDepth),
|
|
4590
|
+
execution: opened.execution,
|
|
4591
|
+
...preamble === void 0 ? {} : { promptPreamble: preamble }
|
|
4592
|
+
}],
|
|
4593
|
+
committed: true
|
|
4594
|
+
};
|
|
4423
4595
|
}
|
|
4424
4596
|
/**
|
|
4425
4597
|
* Finalize every stored run-group parent that is ready, walking from `taskId`
|
|
@@ -4815,6 +4987,29 @@ var HostTaskLedger = class {
|
|
|
4815
4987
|
notify() {
|
|
4816
4988
|
for (const listener of [...this.listeners]) listener();
|
|
4817
4989
|
}
|
|
4990
|
+
/**
|
|
4991
|
+
* Move an unidentifiable, heartbeat-aged lock aside instead of deleting it:
|
|
4992
|
+
* the record is the only evidence of which process held the ledger, and the
|
|
4993
|
+
* takeover is a judgment call an operator may need to audit (issue #2061).
|
|
4994
|
+
* A refused rename falls back to removal, because the takeover itself must
|
|
4995
|
+
* not depend on the filesystem allowing the rename.
|
|
4996
|
+
*/
|
|
4997
|
+
quarantineOrphanLock(pid, age) {
|
|
4998
|
+
const orphan = `${this.lockFile}.orphan-${this.now()}`;
|
|
4999
|
+
let kept = true;
|
|
5000
|
+
try {
|
|
5001
|
+
renameSync(this.lockFile, orphan);
|
|
5002
|
+
} catch {
|
|
5003
|
+
kept = false;
|
|
5004
|
+
try {
|
|
5005
|
+
unlinkSync(this.lockFile);
|
|
5006
|
+
} catch (unlinkError) {
|
|
5007
|
+
if (unlinkError.code !== "ENOENT") throw unlinkError;
|
|
5008
|
+
}
|
|
5009
|
+
}
|
|
5010
|
+
const seconds = Number.isFinite(age) ? `${Math.round(age / 1e3)}s` : "an unreadable age";
|
|
5011
|
+
this.warn(`[task-board] reclaimed the ledger lock of process ${pid}: its identity could not be probed and its heartbeat is ${seconds} old${kept ? `; the record was kept as ${orphan}` : ""}`);
|
|
5012
|
+
}
|
|
4818
5013
|
acquireLock() {
|
|
4819
5014
|
for (let attempt = 0; attempt < 2; attempt += 1) try {
|
|
4820
5015
|
const fd = openSync(this.lockFile, "wx", 384);
|
|
@@ -4856,18 +5051,28 @@ var HostTaskLedger = class {
|
|
|
4856
5051
|
}
|
|
4857
5052
|
continue;
|
|
4858
5053
|
}
|
|
4859
|
-
if (pid !== void 0 &&
|
|
4860
|
-
const actualStartedAt = pid === process.pid ? ownProcessStartTimeMs() :
|
|
4861
|
-
|
|
5054
|
+
if (pid !== void 0 && this.processProbe.isAlive(pid)) {
|
|
5055
|
+
const actualStartedAt = pid === process.pid ? ownProcessStartTimeMs() : this.processProbe.startTimeMs(pid);
|
|
5056
|
+
const staleReuse = actualStartedAt !== void 0 && (ownerStartedAt !== void 0 ? startTimeMismatch(ownerStartedAt, actualStartedAt, ownerExact) : (() => {
|
|
4862
5057
|
try {
|
|
4863
5058
|
return statSync(this.lockFile).mtimeMs < actualStartedAt;
|
|
4864
5059
|
} catch {
|
|
4865
5060
|
return true;
|
|
4866
5061
|
}
|
|
4867
|
-
})())
|
|
5062
|
+
})());
|
|
5063
|
+
const lockAge = (() => {
|
|
5064
|
+
try {
|
|
5065
|
+
return this.now() - statSync(this.lockFile).mtimeMs;
|
|
5066
|
+
} catch {
|
|
5067
|
+
return Number.POSITIVE_INFINITY;
|
|
5068
|
+
}
|
|
5069
|
+
})();
|
|
5070
|
+
const staleHeartbeat = actualStartedAt === void 0 && lockAge >= UNREADABLE_LOCK_GRACE_MS;
|
|
5071
|
+
if (!staleReuse && !staleHeartbeat) {
|
|
4868
5072
|
const hint = ownerStartedAt !== void 0 && actualStartedAt !== void 0 && !startTimeMismatch(ownerStartedAt, actualStartedAt, ownerExact) ? "" : `; if this PID was reused after a crash and no other DSH host is running, remove ${this.lockFile} manually and retry`;
|
|
4869
5073
|
throw new Error(`task-board ledger is already owned by process ${pid}${hint}`, { cause: error });
|
|
4870
5074
|
}
|
|
5075
|
+
if (staleHeartbeat && !staleReuse) this.quarantineOrphanLock(pid, lockAge);
|
|
4871
5076
|
}
|
|
4872
5077
|
try {
|
|
4873
5078
|
unlinkSync(this.lockFile);
|
|
@@ -5560,6 +5765,7 @@ function promptText(task, context = {}) {
|
|
|
5560
5765
|
const handover = task.handover;
|
|
5561
5766
|
const handoverPreamble = handover === void 0 || handover.references.length === 0 ? void 0 : `交接包引用(来自任务看板续接卡片,冻结于 ${new Date(handover.bundledAt).toISOString()}):\n${handover.references.map((reference) => `- ${reference}`).join("\n")}`;
|
|
5562
5767
|
const preambles = [
|
|
5768
|
+
launchPromptPreamble(context),
|
|
5563
5769
|
tagPromptPreamble(task),
|
|
5564
5770
|
context.files === void 0 ? void 0 : attachmentPromptPreamble(context.files),
|
|
5565
5771
|
handoverPreamble,
|
|
@@ -5575,6 +5781,21 @@ function promptText(task, context = {}) {
|
|
|
5575
5781
|
return preamble === void 0 ? declaration : `${preamble}\n\n${declaration}`;
|
|
5576
5782
|
}
|
|
5577
5783
|
/**
|
|
5784
|
+
* Build the launch-gate section of the execution prompt.
|
|
5785
|
+
*
|
|
5786
|
+
* A provider that answered `local` keeps the board's own execution and only
|
|
5787
|
+
* adds context for it, so its text is a preamble like the tag prompts: same
|
|
5788
|
+
* injection path, same placement rules, and the same delimiter neutralization —
|
|
5789
|
+
* a preamble a provider composed from card text can therefore not counterfeit
|
|
5790
|
+
* the freeze wrap either. A blank preamble yields undefined and the prompt is
|
|
5791
|
+
* exactly what an unintercepted run produces.
|
|
5792
|
+
*/
|
|
5793
|
+
function launchPromptPreamble(context) {
|
|
5794
|
+
const preamble = context.launchPreamble?.trim();
|
|
5795
|
+
if (preamble === void 0 || preamble === "") return void 0;
|
|
5796
|
+
return escapeProvenanceDelimiter(preamble);
|
|
5797
|
+
}
|
|
5798
|
+
/**
|
|
5578
5799
|
* Build the tag section of the execution prompt (issue #1521). Only tags with
|
|
5579
5800
|
* a non-blank `promptPrefix` contribute; a task whose tags are all bare names
|
|
5580
5801
|
* (or which has no tags at all) yields undefined and the prompt is byte-for-byte
|
|
@@ -6526,6 +6747,54 @@ function extensionText(value, what) {
|
|
|
6526
6747
|
return text;
|
|
6527
6748
|
}
|
|
6528
6749
|
/**
|
|
6750
|
+
* Read one handler answer as a launch decision.
|
|
6751
|
+
*
|
|
6752
|
+
* A handler is provider code reached synchronously from the launch path, so its
|
|
6753
|
+
* return value is judged here instead of trusted: anything the board cannot act
|
|
6754
|
+
* on is reported and treated as "not mine", exactly like a throw. A local
|
|
6755
|
+
* decision with a blank preamble is normalized to no preamble, so a provider
|
|
6756
|
+
* that answers local to take no visible part changes nothing at all.
|
|
6757
|
+
* @param answer - what the handler returned.
|
|
6758
|
+
* @param warn - sink for a refusal the provider can read.
|
|
6759
|
+
* @returns the decision to act on, or undefined.
|
|
6760
|
+
*/
|
|
6761
|
+
function launchDecision(answer, warn) {
|
|
6762
|
+
if (answer === void 0) return void 0;
|
|
6763
|
+
if (typeof answer !== "object" || answer === null) {
|
|
6764
|
+
warn("returned a non-object decision");
|
|
6765
|
+
return;
|
|
6766
|
+
}
|
|
6767
|
+
const kind = answer.kind;
|
|
6768
|
+
if (kind === "external") return { kind: "external" };
|
|
6769
|
+
if (kind === "refuse") {
|
|
6770
|
+
const { code, reason } = answer;
|
|
6771
|
+
if (typeof code !== "string" || !/^[a-z][a-z0-9-]*$/.test(code) || typeof reason !== "string" || reason.trim() === "") {
|
|
6772
|
+
warn("returned a malformed refusal");
|
|
6773
|
+
return;
|
|
6774
|
+
}
|
|
6775
|
+
return {
|
|
6776
|
+
kind: "refuse",
|
|
6777
|
+
code,
|
|
6778
|
+
reason: reason.trim()
|
|
6779
|
+
};
|
|
6780
|
+
}
|
|
6781
|
+
if (kind !== "local") {
|
|
6782
|
+
warn("returned an unknown decision kind");
|
|
6783
|
+
return;
|
|
6784
|
+
}
|
|
6785
|
+
const preamble = answer.promptPreamble;
|
|
6786
|
+
if (preamble === void 0) return { kind: "local" };
|
|
6787
|
+
if (typeof preamble !== "string") {
|
|
6788
|
+
warn("returned a non-string promptPreamble");
|
|
6789
|
+
return;
|
|
6790
|
+
}
|
|
6791
|
+
const trimmed = preamble.trim();
|
|
6792
|
+
return trimmed === "" ? { kind: "local" } : {
|
|
6793
|
+
kind: "local",
|
|
6794
|
+
promptPreamble: trimmed
|
|
6795
|
+
};
|
|
6796
|
+
}
|
|
6797
|
+
/**
|
|
6529
6798
|
* The session a follow-up message goes to, or the refusal that says why there
|
|
6530
6799
|
* is none. The open execution owns the answer while one is running: delivering
|
|
6531
6800
|
* into the previous conversation instead would answer a question the current
|
|
@@ -6557,6 +6826,8 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6557
6826
|
uuid;
|
|
6558
6827
|
logger;
|
|
6559
6828
|
toolResolver;
|
|
6829
|
+
onPublished;
|
|
6830
|
+
publishedVersionCounter = 0;
|
|
6560
6831
|
/** Board master switch (enabled config); providers start only while it is on. */
|
|
6561
6832
|
boardEnabled = true;
|
|
6562
6833
|
disposed = false;
|
|
@@ -6569,6 +6840,11 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6569
6840
|
this.uuid = options.uuid ?? (() => crypto.randomUUID());
|
|
6570
6841
|
this.logger = options.logger ?? DEFAULT_LOGGER;
|
|
6571
6842
|
this.toolResolver = options.toolRegistry;
|
|
6843
|
+
this.onPublished = options.onPublished;
|
|
6844
|
+
}
|
|
6845
|
+
/** Monotonic revision of the published extension summaries map. */
|
|
6846
|
+
get publishedRevision() {
|
|
6847
|
+
return this.publishedVersionCounter;
|
|
6572
6848
|
}
|
|
6573
6849
|
/**
|
|
6574
6850
|
* Pin (or replace) the deployment's tool registry. A registry that appears
|
|
@@ -6617,7 +6893,8 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6617
6893
|
extension,
|
|
6618
6894
|
active: false,
|
|
6619
6895
|
subscriptions: emptySubscriptions(),
|
|
6620
|
-
tools: []
|
|
6896
|
+
tools: [],
|
|
6897
|
+
launchHandlers: /* @__PURE__ */ new Set()
|
|
6621
6898
|
};
|
|
6622
6899
|
this.entries.set(extension.id, entry);
|
|
6623
6900
|
this.reconcile(entry);
|
|
@@ -6644,6 +6921,65 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6644
6921
|
if (typeof handler !== "function") throw new TaskBoardExtensionError("unsupported-action", `extension "${request.extensionId}" handles no actions`);
|
|
6645
6922
|
return await handler.call(entry.extension, request);
|
|
6646
6923
|
}
|
|
6924
|
+
/**
|
|
6925
|
+
* The board's single launch gate: ask every running provider whether this run
|
|
6926
|
+
* is theirs.
|
|
6927
|
+
*
|
|
6928
|
+
* Consulted by the ledger at the one point every trigger passes — before a
|
|
6929
|
+
* session exists and before an execution record is written — so the order
|
|
6930
|
+
* here is the only ordering a provider can observe: registration order, first
|
|
6931
|
+
* decision wins. A handler that throws is isolated and treated as "not mine",
|
|
6932
|
+
* exactly as if it had answered undefined, because a provider's bug must cost
|
|
6933
|
+
* its own interception and never the launch. Without a registered handler
|
|
6934
|
+
* this answers nothing at all and the launch path is untouched.
|
|
6935
|
+
* @param task - the card about to run.
|
|
6936
|
+
* @param context - which entry asked for this run.
|
|
6937
|
+
* @returns the first decision a running provider made, or undefined.
|
|
6938
|
+
*/
|
|
6939
|
+
interceptLaunch(task, context) {
|
|
6940
|
+
if (this.disposed) return void 0;
|
|
6941
|
+
for (const entry of this.entries.values()) {
|
|
6942
|
+
if (!entry.active) continue;
|
|
6943
|
+
for (const handler of [...entry.launchHandlers]) {
|
|
6944
|
+
let answer;
|
|
6945
|
+
try {
|
|
6946
|
+
answer = handler(task, context);
|
|
6947
|
+
} catch (error) {
|
|
6948
|
+
this.logger.error(`[dsh-task-board] extension "${entry.extension.id}" launch handler failed; the launch proceeds unhandled`, error);
|
|
6949
|
+
continue;
|
|
6950
|
+
}
|
|
6951
|
+
const decision = launchDecision(answer, (message) => {
|
|
6952
|
+
this.logger.warn(`[dsh-task-board] extension "${entry.extension.id}" launch handler ${message}; the launch proceeds unhandled`);
|
|
6953
|
+
});
|
|
6954
|
+
if (decision !== void 0) return decision;
|
|
6955
|
+
}
|
|
6956
|
+
}
|
|
6957
|
+
}
|
|
6958
|
+
/**
|
|
6959
|
+
* What the running providers say about one card, keyed by extension id.
|
|
6960
|
+
* Isolated per provider: a throw drops that provider's entry only.
|
|
6961
|
+
*/
|
|
6962
|
+
describeTask(task) {
|
|
6963
|
+
return this.describe((entry) => entry.extension.describeTask?.(task));
|
|
6964
|
+
}
|
|
6965
|
+
/** The run handle a running provider holds for one card, keyed by extension id. */
|
|
6966
|
+
describeRun(taskId) {
|
|
6967
|
+
return this.describe((entry) => entry.extension.describeRun?.(taskId));
|
|
6968
|
+
}
|
|
6969
|
+
describe(read) {
|
|
6970
|
+
if (this.disposed) return void 0;
|
|
6971
|
+
const result = {};
|
|
6972
|
+
for (const entry of this.entries.values()) {
|
|
6973
|
+
if (!entry.active) continue;
|
|
6974
|
+
try {
|
|
6975
|
+
const view = read(entry);
|
|
6976
|
+
if (typeof view === "object" && view !== null && !Array.isArray(view)) result[entry.extension.id] = view;
|
|
6977
|
+
} catch (error) {
|
|
6978
|
+
this.logger.error(`[dsh-task-board] extension "${entry.extension.id}" description failed`, error);
|
|
6979
|
+
}
|
|
6980
|
+
}
|
|
6981
|
+
return Object.keys(result).length === 0 ? void 0 : result;
|
|
6982
|
+
}
|
|
6647
6983
|
/** Published summaries of currently running providers, keyed by extension id. */
|
|
6648
6984
|
published() {
|
|
6649
6985
|
const result = {};
|
|
@@ -6701,6 +7037,7 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6701
7037
|
this.syncTools(entry);
|
|
6702
7038
|
}
|
|
6703
7039
|
stopEntry(entry) {
|
|
7040
|
+
const hadPublished = entry.published !== void 0;
|
|
6704
7041
|
if (entry.active) {
|
|
6705
7042
|
entry.active = false;
|
|
6706
7043
|
for (const kind of Object.keys(entry.subscriptions)) entry.subscriptions[kind].clear();
|
|
@@ -6710,8 +7047,14 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6710
7047
|
this.logger.error(`[dsh-task-board] extension "${entry.extension.id}" stop() failed`, error);
|
|
6711
7048
|
}
|
|
6712
7049
|
}
|
|
7050
|
+
entry.published = void 0;
|
|
6713
7051
|
this.disposeTools(entry);
|
|
6714
7052
|
entry.tools.length = 0;
|
|
7053
|
+
entry.launchHandlers.clear();
|
|
7054
|
+
if (hadPublished) {
|
|
7055
|
+
this.publishedVersionCounter += 1;
|
|
7056
|
+
if (!this.disposed) this.onPublished?.();
|
|
7057
|
+
}
|
|
6715
7058
|
}
|
|
6716
7059
|
/** (Re)register every buffered tool against the current tool registry. */
|
|
6717
7060
|
syncTools(entry) {
|
|
@@ -6776,6 +7119,10 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6776
7119
|
sessions: { followUp: async (taskId, text) => {
|
|
6777
7120
|
await this.followUp(entry, taskId, text);
|
|
6778
7121
|
} },
|
|
7122
|
+
launch: { intercept: (handler) => {
|
|
7123
|
+
assertActive("intercept a launch");
|
|
7124
|
+
return this.addLaunchHandler(entry, handler);
|
|
7125
|
+
} },
|
|
6779
7126
|
integration: {
|
|
6780
7127
|
read: (taskId) => {
|
|
6781
7128
|
assertActive("read");
|
|
@@ -6935,6 +7282,20 @@ var TaskBoardExtensionRegistry = class {
|
|
|
6935
7282
|
this.assertActive(entry, "publish a summary");
|
|
6936
7283
|
if (!isTaskBoardExtensionPayload(summary)) throw new TaskBoardExtensionError("invalid-payload", "published summary must be a pure JSON object within the size limit");
|
|
6937
7284
|
entry.published = summary;
|
|
7285
|
+
this.publishedVersionCounter += 1;
|
|
7286
|
+
this.onPublished?.();
|
|
7287
|
+
}
|
|
7288
|
+
/**
|
|
7289
|
+
* Hold one launch handler for a running provider. The handler is dropped when
|
|
7290
|
+
* the provider stops or is unregistered, so the disposer only has to cover the
|
|
7291
|
+
* provider's own early withdrawal.
|
|
7292
|
+
*/
|
|
7293
|
+
addLaunchHandler(entry, handler) {
|
|
7294
|
+
if (typeof handler !== "function") throw new TaskBoardExtensionError("invalid-handler", "a launch handler must be a function");
|
|
7295
|
+
entry.launchHandlers.add(handler);
|
|
7296
|
+
return () => {
|
|
7297
|
+
entry.launchHandlers.delete(handler);
|
|
7298
|
+
};
|
|
6938
7299
|
}
|
|
6939
7300
|
registerTool(entry, definition) {
|
|
6940
7301
|
const tool = { definition };
|
|
@@ -6986,11 +7347,21 @@ const UNREADABLE_SETTLE_POLLS = 24;
|
|
|
6986
7347
|
const ABANDONED_LAUNCH_REASON = "host stopped before this execution started";
|
|
6987
7348
|
/**
|
|
6988
7349
|
* Why a rework could not launch: it redoes work in the card's own
|
|
6989
|
-
* conversation, so a session the Host cannot
|
|
6990
|
-
* send the reviewer's instructions into. Starting a fresh
|
|
6991
|
-
* would hand those instructions to an agent that never saw
|
|
7350
|
+
* conversation, so a session the Host cannot confirm as reachable means there is
|
|
7351
|
+
* nothing to send the reviewer's instructions into. Starting a fresh
|
|
7352
|
+
* conversation instead would hand those instructions to an agent that never saw
|
|
7353
|
+
* the work. "Could not be confirmed" also covers an unreadable roster, which is
|
|
7354
|
+
* neither "idle" nor "gone".
|
|
7355
|
+
*/
|
|
7356
|
+
const REWORK_SESSION_REASON = "rework: the card's previous execution session could not be confirmed as present and idle in the host session roster, so there is no conversation to send the rework instructions into";
|
|
7357
|
+
/**
|
|
7358
|
+
* Why a rework could not launch into an archived conversation (issue #2068).
|
|
7359
|
+
* The session still exists, so the generic reason would misdirect: the operator
|
|
7360
|
+
* has to unarchive that conversation before the rework can be sent into it.
|
|
7361
|
+
* @param sessionId - the archived conversation the rework addressed.
|
|
7362
|
+
* @returns the refusal the operator reads on the card.
|
|
6992
7363
|
*/
|
|
6993
|
-
const
|
|
7364
|
+
const reworkArchivedReason = (sessionId) => "rework: the card's previous execution session " + sessionId + " is archived, so the Host will not run a turn in it; unarchive that session and start the rework again";
|
|
6994
7365
|
/**
|
|
6995
7366
|
* Actions that can change the instant the schedule timer is armed at. Only
|
|
6996
7367
|
* these re-arm the native timer; an unrelated card edit leaves the pending fire
|
|
@@ -7184,8 +7555,13 @@ var TaskBoardHostService = class {
|
|
|
7184
7555
|
instructions
|
|
7185
7556
|
}, initiator);
|
|
7186
7557
|
},
|
|
7187
|
-
now: this.now
|
|
7558
|
+
now: this.now,
|
|
7559
|
+
onPublished: () => {
|
|
7560
|
+
this.emit();
|
|
7561
|
+
},
|
|
7562
|
+
...options.extensionLogger === void 0 ? {} : { logger: options.extensionLogger }
|
|
7188
7563
|
});
|
|
7564
|
+
this.ledger.setLaunchGate((task, context) => this.extensions.interceptLaunch(task, context));
|
|
7189
7565
|
installStreamErrorGuards();
|
|
7190
7566
|
this.ledger.subscribe(() => {
|
|
7191
7567
|
this.syncPowerReasons();
|
|
@@ -7270,7 +7646,8 @@ var TaskBoardHostService = class {
|
|
|
7270
7646
|
maxSubtaskDepth: this.ledger.maxSubtaskDepth,
|
|
7271
7647
|
...cardDefaults === void 0 ? {} : { cardDefaults },
|
|
7272
7648
|
...this.attachmentStore() === void 0 ? {} : { attachmentLimits: publishedAttachmentLimits(this.attachmentStore()) },
|
|
7273
|
-
...Object.keys(published).length === 0 ? {} : { extensions: published }
|
|
7649
|
+
...Object.keys(published).length === 0 ? {} : { extensions: published },
|
|
7650
|
+
extensionsRevision: this.extensions.publishedRevision
|
|
7274
7651
|
});
|
|
7275
7652
|
}
|
|
7276
7653
|
/**
|
|
@@ -7280,6 +7657,14 @@ var TaskBoardHostService = class {
|
|
|
7280
7657
|
registerExtension(extension) {
|
|
7281
7658
|
return this.extensions.registerExtension(extension);
|
|
7282
7659
|
}
|
|
7660
|
+
/** What running providers say about one card, for the model-facing tools. */
|
|
7661
|
+
describeTask(task) {
|
|
7662
|
+
return this.extensions.describeTask(task);
|
|
7663
|
+
}
|
|
7664
|
+
/** The run handle a running provider holds for one card, for `task_board_run`. */
|
|
7665
|
+
describeRun(taskId) {
|
|
7666
|
+
return this.extensions.describeRun(taskId);
|
|
7667
|
+
}
|
|
7283
7668
|
/**
|
|
7284
7669
|
* The host model catalog the settings card's model and reasoning-level
|
|
7285
7670
|
* choices come from.
|
|
@@ -7293,6 +7678,7 @@ var TaskBoardHostService = class {
|
|
|
7293
7678
|
const { revision, scheduler } = this.ledger.summary();
|
|
7294
7679
|
return {
|
|
7295
7680
|
revision,
|
|
7681
|
+
extensionsRevision: this.extensions.publishedRevision,
|
|
7296
7682
|
scheduler,
|
|
7297
7683
|
power: this.power.snapshot()
|
|
7298
7684
|
};
|
|
@@ -7365,23 +7751,23 @@ var TaskBoardHostService = class {
|
|
|
7365
7751
|
if (store === void 0) throw new Error("this deployment serves no attachment storage");
|
|
7366
7752
|
await verifyAttachments(store, attachments);
|
|
7367
7753
|
}
|
|
7368
|
-
apply(requestId, action, initiator) {
|
|
7754
|
+
apply(requestId, action, initiator, trigger) {
|
|
7369
7755
|
if (!this.active) throw new Error("task board is disabled");
|
|
7370
7756
|
const kind = action?.kind;
|
|
7371
7757
|
if (typeof kind !== "string" || !Object.hasOwn(ACTION_KINDS, kind)) throw new Error(`unknown task board action kind: ${String(kind)}`);
|
|
7372
7758
|
if (action.kind === "extension-action") return this.handleExtensionAction(action);
|
|
7373
|
-
return projectSnapshotForWire(this.applyBoardAction(requestId, action, initiator));
|
|
7759
|
+
return projectSnapshotForWire(this.applyBoardAction(requestId, action, initiator, false, trigger));
|
|
7374
7760
|
}
|
|
7375
7761
|
/**
|
|
7376
7762
|
* Apply one board-owned action with every gate intact. Provider capability
|
|
7377
7763
|
* calls and the same-origin wire both land here, so the two surfaces can
|
|
7378
7764
|
* never disagree about a card.
|
|
7379
7765
|
*/
|
|
7380
|
-
applyBoardAction(requestId, action, initiator, attachmentVerified = false) {
|
|
7766
|
+
applyBoardAction(requestId, action, initiator, attachmentVerified = false, trigger) {
|
|
7381
7767
|
if (!attachmentVerified && attachmentsOfAction(action) !== void 0) throw new Error("attachments must be applied through the verified attachment action route");
|
|
7382
7768
|
const before = this.statusMap();
|
|
7383
7769
|
if (action.kind === "run" || action.kind === "rerun" || action.kind === "rework") this.assertSpendCap();
|
|
7384
|
-
const result = this.ledger.applyRequest(requestId, this.withInheritedWorkspace(action, initiator), initiator);
|
|
7770
|
+
const result = this.ledger.applyRequest(requestId, this.withInheritedWorkspace(action, initiator), initiator, trigger);
|
|
7385
7771
|
if (result.runs !== void 0) this.dispatchRuns(result.runs);
|
|
7386
7772
|
if (SCHEDULE_WRITE_ACTIONS.has(action.kind)) this.refreshSchedule();
|
|
7387
7773
|
this.emitStatusChanges(before, initiator);
|
|
@@ -7414,12 +7800,16 @@ var TaskBoardHostService = class {
|
|
|
7414
7800
|
}
|
|
7415
7801
|
/** Route one provider action and answer the resulting board snapshot. */
|
|
7416
7802
|
async handleExtensionAction(action) {
|
|
7417
|
-
await this.extensions.handleAction({
|
|
7803
|
+
const answer = await this.extensions.handleAction({
|
|
7418
7804
|
extensionId: action.extensionId,
|
|
7419
7805
|
action: action.action,
|
|
7420
7806
|
...action.taskId === void 0 ? {} : { taskId: action.taskId },
|
|
7421
7807
|
...action.payload === void 0 ? {} : { payload: action.payload }
|
|
7422
7808
|
});
|
|
7809
|
+
if (typeof answer === "object" && answer !== null && answer.ok === false) {
|
|
7810
|
+
const reason = answer.error;
|
|
7811
|
+
throw new Error(typeof reason === "string" && reason.trim() !== "" ? reason : `extension "${action.extensionId}" refused action "${action.action}"`);
|
|
7812
|
+
}
|
|
7423
7813
|
return this.snapshot();
|
|
7424
7814
|
}
|
|
7425
7815
|
/** Current task id -> status map, for change detection around a mutation. */
|
|
@@ -7466,6 +7856,7 @@ var TaskBoardHostService = class {
|
|
|
7466
7856
|
reuseSessionId = await this.reworkSessionFor(opened.task);
|
|
7467
7857
|
}
|
|
7468
7858
|
const contextParts = {
|
|
7859
|
+
...opened.promptPreamble === void 0 ? {} : { launchPreamble: opened.promptPreamble },
|
|
7469
7860
|
...descendants.length === 0 ? {} : { descendants: descendants.map((descendant) => ({
|
|
7470
7861
|
id: descendant.id,
|
|
7471
7862
|
title: descendant.title,
|
|
@@ -7569,30 +7960,90 @@ var TaskBoardHostService = class {
|
|
|
7569
7960
|
/**
|
|
7570
7961
|
* The session a run may continue in, for a card that opted into reuse
|
|
7571
7962
|
* (issue #1419). Reuse requires positive evidence that the previous session
|
|
7572
|
-
* is present and
|
|
7573
|
-
* idle board no longer polls, so a roster cached from an earlier
|
|
7574
|
-
* be hours old — either refusing a session that has been idle all
|
|
7575
|
-
* prompting into one that started running since. A card that did not
|
|
7576
|
-
* reads no roster at all, and a read that fails mints a fresh
|
|
7577
|
-
* exactly as an unknown roster always did.
|
|
7963
|
+
* is present, idle, and not archived, and that evidence must be read for THIS
|
|
7964
|
+
* launch: an idle board no longer polls, so a roster cached from an earlier
|
|
7965
|
+
* pass could be hours old — either refusing a session that has been idle all
|
|
7966
|
+
* along, or prompting into one that started running since. A card that did not
|
|
7967
|
+
* opt in reads no roster at all, and a read that fails mints a fresh
|
|
7968
|
+
* conversation exactly as an unknown roster always did.
|
|
7578
7969
|
* @param task - the task about to run.
|
|
7579
|
-
* @param force - continue the settled session regardless of the card's own
|
|
7580
|
-
* opt-in (a rework), which the reuse rule accepts without waiving any of its
|
|
7581
|
-
* evidence conditions.
|
|
7582
7970
|
* @returns the session id to continue in, or undefined for a fresh session.
|
|
7583
7971
|
*/
|
|
7584
|
-
async reuseSessionFor(task
|
|
7585
|
-
if (task.reuseSession !== true
|
|
7972
|
+
async reuseSessionFor(task) {
|
|
7973
|
+
if (task.reuseSession !== true) return void 0;
|
|
7974
|
+
const decision = await this.reuseDecision(task, false);
|
|
7975
|
+
if (decision.sessionId !== void 0) return decision.sessionId;
|
|
7976
|
+
if (decision.archivedSessionId !== void 0) safeConsoleWarn(`[dsh-task-board] session reuse skipped for task ${task.id}: session ${decision.archivedSessionId} is archived, starting a fresh conversation`);
|
|
7977
|
+
}
|
|
7978
|
+
/**
|
|
7979
|
+
* One reuse decision for this launch: the session to continue in, or nothing
|
|
7980
|
+
* plus the reason nothing was chosen, so each caller can report it.
|
|
7981
|
+
*
|
|
7982
|
+
* Reuse never targets a session in the Workspace registry's archive set
|
|
7983
|
+
* (issue #2068). The Host's archived-session gate rejects the first step of a
|
|
7984
|
+
* turn in an archived session before any model request is issued, so the
|
|
7985
|
+
* run would settle as the opaque failure `agent turn ended without
|
|
7986
|
+
* completing: blocked` — the fate of every scheduled run of a card whose
|
|
7987
|
+
* conversation the user archived while cleaning the sidebar. Starting a fresh
|
|
7988
|
+
* conversation is the only safe answer: archiving is a live user decision,
|
|
7989
|
+
* and the board must not unarchive a conversation behind the user's back to
|
|
7990
|
+
* keep reusing it.
|
|
7991
|
+
* @param task - the task about to run.
|
|
7992
|
+
* @param force - reuse without the card's own opt-in (a rework).
|
|
7993
|
+
* @returns the reuse decision for this launch.
|
|
7994
|
+
*/
|
|
7995
|
+
async reuseDecision(task, force) {
|
|
7586
7996
|
let running;
|
|
7587
7997
|
try {
|
|
7588
7998
|
running = await this.runner.listRunning();
|
|
7589
7999
|
} catch (error) {
|
|
7590
8000
|
this.notePollFailure();
|
|
7591
|
-
safeConsoleError("[dsh-task-board]
|
|
8001
|
+
safeConsoleError("[dsh-task-board] the session reuse probe failed; reuse is skipped for this launch", error);
|
|
8002
|
+
return {};
|
|
8003
|
+
}
|
|
8004
|
+
if (!running.known) return {};
|
|
8005
|
+
const archived = this.archivedSessionIds();
|
|
8006
|
+
const sessionId = reusableSessionId(task, new Set(running.items.filter((item) => !item.running).map((item) => item.sessionId)), {
|
|
8007
|
+
...force ? { force: true } : {},
|
|
8008
|
+
...archived === void 0 ? {} : { archivedSessionIds: archived }
|
|
8009
|
+
});
|
|
8010
|
+
if (sessionId !== void 0) return { sessionId };
|
|
8011
|
+
const archivedSessionId = this.archivedReuseTarget(task, archived);
|
|
8012
|
+
return archivedSessionId === void 0 ? {} : { archivedSessionId };
|
|
8013
|
+
}
|
|
8014
|
+
/**
|
|
8015
|
+
* The archived conversation the reuse rule refused, when it refused one.
|
|
8016
|
+
*
|
|
8017
|
+
* Reuse skipping an archived conversation is otherwise invisible: the board
|
|
8018
|
+
* simply opens a new one, and only the caller knows which outcome it produced.
|
|
8019
|
+
* @param task - the task about to run.
|
|
8020
|
+
* @param archived - the archive set read for this launch, when reported.
|
|
8021
|
+
* @returns the newest settled session id when it is archived, else undefined.
|
|
8022
|
+
*/
|
|
8023
|
+
archivedReuseTarget(task, archived) {
|
|
8024
|
+
if (archived === void 0) return void 0;
|
|
8025
|
+
const newest = newestSettledSessionId(task);
|
|
8026
|
+
return newest !== void 0 && archived.has(newest) ? newest : void 0;
|
|
8027
|
+
}
|
|
8028
|
+
/**
|
|
8029
|
+
* The Workspace registry's archive set, or undefined when this deployment's
|
|
8030
|
+
* registry face cannot report one. An unreportable set is unknown evidence,
|
|
8031
|
+
* never proof that nothing is archived: the rule then keeps its pre-archive
|
|
8032
|
+
* behavior instead of inventing a refusal, because a registry face without
|
|
8033
|
+
* the getter serves no archive action for the board to defend against.
|
|
8034
|
+
*
|
|
8035
|
+
* Read per launch rather than cached: archiving is a live user action, and an
|
|
8036
|
+
* idle board no longer polls, so a set kept from an earlier pass could already
|
|
8037
|
+
* claim a session that the user archived a moment ago.
|
|
8038
|
+
* @returns the archived session ids, or undefined when unreportable.
|
|
8039
|
+
*/
|
|
8040
|
+
archivedSessionIds() {
|
|
8041
|
+
try {
|
|
8042
|
+
const archived = this.workspaceRegistry?.archivedSessionIds;
|
|
8043
|
+
return archived === void 0 ? void 0 : new Set(archived);
|
|
8044
|
+
} catch {
|
|
7592
8045
|
return;
|
|
7593
8046
|
}
|
|
7594
|
-
if (!running.known) return void 0;
|
|
7595
|
-
return reusableSessionId(task, new Set(running.items.filter((item) => !item.running).map((item) => item.sessionId)), force === true ? { force: true } : {});
|
|
7596
8047
|
}
|
|
7597
8048
|
/**
|
|
7598
8049
|
* The session a rework continues, or the refusal that says why it cannot.
|
|
@@ -7607,9 +8058,9 @@ var TaskBoardHostService = class {
|
|
|
7607
8058
|
* @returns the session id this rework continues in.
|
|
7608
8059
|
*/
|
|
7609
8060
|
async reworkSessionFor(task) {
|
|
7610
|
-
const
|
|
7611
|
-
if (sessionId
|
|
7612
|
-
|
|
8061
|
+
const decision = await this.reuseDecision(task, true);
|
|
8062
|
+
if (decision.sessionId !== void 0) return decision.sessionId;
|
|
8063
|
+
throw new Error(decision.archivedSessionId === void 0 ? REWORK_SESSION_REASON : reworkArchivedReason(decision.archivedSessionId));
|
|
7613
8064
|
}
|
|
7614
8065
|
/** Reuse the session list this poll already fetched: one list RPC per tick, not 1 + E. */
|
|
7615
8066
|
async reconcileExecutions(sessions, executions) {
|
|
@@ -7875,6 +8326,15 @@ function safeConsoleError(message, ...args) {
|
|
|
7875
8326
|
console.error(message, ...args);
|
|
7876
8327
|
} catch {}
|
|
7877
8328
|
}
|
|
8329
|
+
/**
|
|
8330
|
+
* Defensively log to console.warn, for a diagnostic that must never turn a
|
|
8331
|
+
* launch decision into a failed run when the stderr write itself fails.
|
|
8332
|
+
*/
|
|
8333
|
+
function safeConsoleWarn(message, ...args) {
|
|
8334
|
+
try {
|
|
8335
|
+
console.warn(message, ...args);
|
|
8336
|
+
} catch {}
|
|
8337
|
+
}
|
|
7878
8338
|
//#endregion
|
|
7879
8339
|
//#region src/host/llm-dispatch.ts
|
|
7880
8340
|
/**
|
|
@@ -8088,6 +8548,24 @@ async function parseTaskDraft(llm, request, signal) {
|
|
|
8088
8548
|
}
|
|
8089
8549
|
//#endregion
|
|
8090
8550
|
//#region src/host/agent-tools.ts
|
|
8551
|
+
/**
|
|
8552
|
+
* The one provider view a card carries, with its extension id as `provider`.
|
|
8553
|
+
* A provider that says `localPermission: false` marks a card the board's
|
|
8554
|
+
* session permission gate does not govern (it runs outside this Host).
|
|
8555
|
+
*/
|
|
8556
|
+
function remoteView(views) {
|
|
8557
|
+
if (views === void 0) return void 0;
|
|
8558
|
+
const [id, view] = Object.entries(views)[0] ?? [];
|
|
8559
|
+
if (id === void 0 || view === void 0) return void 0;
|
|
8560
|
+
const { localPermission, ...rest } = view;
|
|
8561
|
+
return {
|
|
8562
|
+
view: {
|
|
8563
|
+
provider: id,
|
|
8564
|
+
...rest
|
|
8565
|
+
},
|
|
8566
|
+
localPermission: localPermission !== false
|
|
8567
|
+
};
|
|
8568
|
+
}
|
|
8091
8569
|
/** Registered tool names, in registration order. */
|
|
8092
8570
|
const TASK_BOARD_TOOL_NAMES = [
|
|
8093
8571
|
"task_board_list",
|
|
@@ -8163,7 +8641,10 @@ function executionView(execution) {
|
|
|
8163
8641
|
startedAt: execution.startedAt,
|
|
8164
8642
|
...execution.endedAt === void 0 ? {} : { endedAt: execution.endedAt },
|
|
8165
8643
|
...execution.result === void 0 ? {} : { result: execution.result },
|
|
8644
|
+
...execution.summary === void 0 ? {} : { summary: execution.summary.text },
|
|
8166
8645
|
...execution.error === void 0 ? {} : { error: execution.error },
|
|
8646
|
+
...execution.errorCode === void 0 ? {} : { errorCode: execution.errorCode },
|
|
8647
|
+
...execution.retryHint === void 0 ? {} : { retryHint: execution.retryHint },
|
|
8167
8648
|
...execution.initiatedBy === void 0 ? {} : { initiatedBy: execution.initiatedBy },
|
|
8168
8649
|
...execution.external === true ? { external: true } : {},
|
|
8169
8650
|
...execution.runGroupId === void 0 ? {} : { cascade: true },
|
|
@@ -8178,8 +8659,9 @@ function executionView(execution) {
|
|
|
8178
8659
|
* targets, schedule, and the latest run. The prompt body rides only
|
|
8179
8660
|
* task_board_get, so a fifty-task list stays readable.
|
|
8180
8661
|
*/
|
|
8181
|
-
function taskSummary(task, tasks, sessionDefault) {
|
|
8662
|
+
function taskSummary(task, tasks, sessionDefault, host) {
|
|
8182
8663
|
const latest = task.executions.at(-1);
|
|
8664
|
+
const remote = remoteView(host?.describeTask?.(task));
|
|
8183
8665
|
const subtaskCount = directSubtasks(tasks, task.id).length;
|
|
8184
8666
|
return {
|
|
8185
8667
|
id: task.id,
|
|
@@ -8200,7 +8682,8 @@ function taskSummary(task, tasks, sessionDefault) {
|
|
|
8200
8682
|
...task.schedule === void 0 ? {} : { schedule: scheduleView(task.schedule) },
|
|
8201
8683
|
...task.freeze === void 0 ? {} : { continuationCard: true },
|
|
8202
8684
|
...task.permissionConfirmedAt === void 0 ? {} : { permissionConfirmedAt: task.permissionConfirmedAt },
|
|
8203
|
-
...requiresPermissionConfirmation(task, sessionDefault ?? "read-only") ? { permissionPending: true } : {},
|
|
8685
|
+
...remote?.localPermission !== false && requiresPermissionConfirmation(task, sessionDefault ?? "read-only") ? { permissionPending: true } : {},
|
|
8686
|
+
...remote === void 0 ? {} : { remote: remote.view },
|
|
8204
8687
|
executionCount: task.executions.length,
|
|
8205
8688
|
...latest === void 0 ? {} : { latestExecution: executionView(latest) },
|
|
8206
8689
|
createdAt: task.createdAt,
|
|
@@ -8208,10 +8691,10 @@ function taskSummary(task, tasks, sessionDefault) {
|
|
|
8208
8691
|
};
|
|
8209
8692
|
}
|
|
8210
8693
|
/** One task's full detail: content, lineage, schedule, and recent runs. */
|
|
8211
|
-
function taskDetail(task, tasks, sessionDefault) {
|
|
8694
|
+
function taskDetail(task, tasks, sessionDefault, host) {
|
|
8212
8695
|
const parent = task.parentId === void 0 ? void 0 : tasks.find((item) => item.id === task.parentId);
|
|
8213
8696
|
return {
|
|
8214
|
-
...taskSummary(task, tasks, sessionDefault),
|
|
8697
|
+
...taskSummary(task, tasks, sessionDefault, host),
|
|
8215
8698
|
prompt: task.prompt,
|
|
8216
8699
|
depth: taskDepth(tasks, task.id),
|
|
8217
8700
|
...parent === void 0 ? {} : { parent: {
|
|
@@ -8234,7 +8717,7 @@ function taskDetail(task, tasks, sessionDefault) {
|
|
|
8234
8717
|
references: task.handover.references,
|
|
8235
8718
|
bundledAt: task.handover.bundledAt
|
|
8236
8719
|
} },
|
|
8237
|
-
subtasks: directSubtasks(tasks, task.id).map((child) => taskSummary(child, tasks, sessionDefault)),
|
|
8720
|
+
subtasks: directSubtasks(tasks, task.id).map((child) => taskSummary(child, tasks, sessionDefault, host)),
|
|
8238
8721
|
executions: task.executions.slice(-10).map(executionView)
|
|
8239
8722
|
};
|
|
8240
8723
|
}
|
|
@@ -8243,6 +8726,18 @@ function openedExecutions(before, after) {
|
|
|
8243
8726
|
const known = new Set(before.map((execution) => execution.id));
|
|
8244
8727
|
return after.filter((execution) => !known.has(execution.id));
|
|
8245
8728
|
}
|
|
8729
|
+
/** The identifiers of a run handle, lifted to the top level of the run output. */
|
|
8730
|
+
function liftHandle(handle) {
|
|
8731
|
+
const lifted = {};
|
|
8732
|
+
for (const key of [
|
|
8733
|
+
"executionId",
|
|
8734
|
+
"runId",
|
|
8735
|
+
"logPath",
|
|
8736
|
+
"target",
|
|
8737
|
+
"estimatedDurationMs"
|
|
8738
|
+
]) if (handle[key] !== void 0) lifted[key] = handle[key];
|
|
8739
|
+
return lifted;
|
|
8740
|
+
}
|
|
8246
8741
|
/** Board summary attached to task_board_list. */
|
|
8247
8742
|
function boardView(snapshot, maxSubtaskDepth) {
|
|
8248
8743
|
const counts = {
|
|
@@ -8319,7 +8814,7 @@ function buildSetParentTool(host) {
|
|
|
8319
8814
|
if (task === void 0) return refused("task-not-found", "no task with id " + args.taskId);
|
|
8320
8815
|
return json({
|
|
8321
8816
|
ok: true,
|
|
8322
|
-
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission)
|
|
8817
|
+
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host)
|
|
8323
8818
|
});
|
|
8324
8819
|
} catch (error) {
|
|
8325
8820
|
return refused("refused", messageOf(error));
|
|
@@ -8335,6 +8830,7 @@ function buildRunTool(host) {
|
|
|
8335
8830
|
"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.",
|
|
8336
8831
|
"Clicking a subtask runs that subtask as its own root, again without opening anything for its descendants.",
|
|
8337
8832
|
"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.",
|
|
8833
|
+
"A card whose run a provider takes over (for example a card pinned to a remote host) answers with that run handle at the top level - executionId, runId, logPath, target, estimatedDurationMs - and a note naming the call that blocks until it settles; a second run request against a card that already has a run in flight is refused with a stable code instead of overwriting it.",
|
|
8338
8834
|
"Executions consume real API quota. Sessions are created asynchronously, so read their ids and outcomes back with task_board_get."
|
|
8339
8835
|
].join(" "),
|
|
8340
8836
|
parameters: {
|
|
@@ -8358,7 +8854,7 @@ function buildRunTool(host) {
|
|
|
8358
8854
|
const snapshot = await host.apply(crypto.randomUUID(), {
|
|
8359
8855
|
kind: args.rerun === true ? "rerun" : "run",
|
|
8360
8856
|
taskId: args.taskId
|
|
8361
|
-
}, callingSessionId(exec));
|
|
8857
|
+
}, callingSessionId(exec), "tool");
|
|
8362
8858
|
const beforeById = new Map(before.tasks.map((task) => [task.id, task]));
|
|
8363
8859
|
const started = snapshot.tasks.flatMap((task) => {
|
|
8364
8860
|
return openedExecutions(beforeById.get(task.id)?.executions ?? [], task.executions).map((execution) => ({
|
|
@@ -8369,15 +8865,23 @@ function buildRunTool(host) {
|
|
|
8369
8865
|
}));
|
|
8370
8866
|
});
|
|
8371
8867
|
const root = snapshot.tasks.find((task) => task.id === args.taskId);
|
|
8868
|
+
const handle = remoteView(host.describeRun?.(String(args.taskId)))?.view;
|
|
8869
|
+
const waitHint = typeof handle?.next === "string" ? handle.next : void 0;
|
|
8372
8870
|
return json({
|
|
8373
8871
|
ok: true,
|
|
8374
8872
|
started,
|
|
8375
|
-
...
|
|
8376
|
-
|
|
8873
|
+
...handle === void 0 ? {} : {
|
|
8874
|
+
run: handle,
|
|
8875
|
+
...liftHandle(handle)
|
|
8876
|
+
},
|
|
8877
|
+
...root === void 0 ? {} : { task: taskSummary(root, snapshot.tasks, snapshot.sessionDefaultPermission, host) },
|
|
8878
|
+
note: waitHint ?? "Executions run asynchronously; call task_board_get to read session ids and the settled outcome."
|
|
8377
8879
|
});
|
|
8378
8880
|
} catch (error) {
|
|
8379
8881
|
const message = messageOf(error);
|
|
8380
|
-
|
|
8882
|
+
if (message.startsWith("confirmation-required")) return refused("confirmation-required", message);
|
|
8883
|
+
const coded = /^([a-z][a-z0-9-]*): ([\s\S]+)$/.exec(message);
|
|
8884
|
+
return coded === null ? refused("refused", message) : refused(coded[1], coded[2]);
|
|
8381
8885
|
}
|
|
8382
8886
|
}
|
|
8383
8887
|
});
|
|
@@ -8455,7 +8959,7 @@ function buildManageTool(host) {
|
|
|
8455
8959
|
return json({
|
|
8456
8960
|
ok: true,
|
|
8457
8961
|
action: args.action,
|
|
8458
|
-
...task === void 0 ? {} : { task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission) },
|
|
8962
|
+
...task === void 0 ? {} : { task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host) },
|
|
8459
8963
|
note: "The outcome is recorded as its own execution, so the terminal column and the run history agree. Read it back with task_board_get."
|
|
8460
8964
|
});
|
|
8461
8965
|
} catch (error) {
|
|
@@ -8519,7 +9023,7 @@ function buildManageTool(host) {
|
|
|
8519
9023
|
return json({
|
|
8520
9024
|
ok: true,
|
|
8521
9025
|
action: args.action,
|
|
8522
|
-
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission)
|
|
9026
|
+
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host)
|
|
8523
9027
|
});
|
|
8524
9028
|
} catch (error) {
|
|
8525
9029
|
return refused("refused", messageOf(error));
|
|
@@ -8596,7 +9100,7 @@ function buildScheduleTool(host) {
|
|
|
8596
9100
|
return json({
|
|
8597
9101
|
ok: true,
|
|
8598
9102
|
schedule: task.schedule === void 0 ? null : scheduleView(task.schedule),
|
|
8599
|
-
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission)
|
|
9103
|
+
task: taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host)
|
|
8600
9104
|
});
|
|
8601
9105
|
} catch (error) {
|
|
8602
9106
|
return refused("refused", messageOf(error));
|
|
@@ -8610,7 +9114,7 @@ function buildListTool(host) {
|
|
|
8610
9114
|
description: [
|
|
8611
9115
|
"List tasks on the DSH task board (the Host-authoritative ledger behind the Web GUI task board).",
|
|
8612
9116
|
"Filters: status column, parentId (direct subtasks), rootsOnly, tag, free-text query, and archived inclusion.",
|
|
8613
|
-
"Returns each task id, title, column, parent/subtask link, execution targets, schedule and latest run outcome, plus the board summary (revision, time zone, subtask depth limit, session-default permission).",
|
|
9117
|
+
"Returns each task id, title, column, parent/subtask link, execution targets, schedule and latest run outcome (a card a provider runs remotely also carries a `remote` summary: host, agent, mode, whether a follow-up is possible), plus the board summary (revision, time zone, subtask depth limit, session-default permission).",
|
|
8614
9118
|
"Use task_board_get for one task in full, task_board_create to add work, and task_board_run to execute it."
|
|
8615
9119
|
].join(" "),
|
|
8616
9120
|
parameters: {
|
|
@@ -8680,7 +9184,7 @@ function buildListTool(host) {
|
|
|
8680
9184
|
board: boardView(snapshot, snapshot.maxSubtaskDepth ?? 1),
|
|
8681
9185
|
total: matched.length,
|
|
8682
9186
|
count: Math.min(matched.length, limit),
|
|
8683
|
-
tasks: matched.slice(0, limit).map((task) => taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission))
|
|
9187
|
+
tasks: matched.slice(0, limit).map((task) => taskSummary(task, snapshot.tasks, snapshot.sessionDefaultPermission, host))
|
|
8684
9188
|
});
|
|
8685
9189
|
}
|
|
8686
9190
|
});
|
|
@@ -8709,7 +9213,7 @@ function buildGetTool(host) {
|
|
|
8709
9213
|
if (task === void 0) return refused("task-not-found", "no task with id " + args.taskId);
|
|
8710
9214
|
return json({
|
|
8711
9215
|
ok: true,
|
|
8712
|
-
task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission)
|
|
9216
|
+
task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host)
|
|
8713
9217
|
});
|
|
8714
9218
|
}
|
|
8715
9219
|
});
|
|
@@ -8857,7 +9361,7 @@ function buildCreateTool(host) {
|
|
|
8857
9361
|
if (task === void 0) return refused("create-failed", "the Host did not confirm the new task");
|
|
8858
9362
|
return json({
|
|
8859
9363
|
ok: true,
|
|
8860
|
-
task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission)
|
|
9364
|
+
task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host)
|
|
8861
9365
|
});
|
|
8862
9366
|
} catch (error) {
|
|
8863
9367
|
return refused("refused", messageOf(error));
|
|
@@ -8975,7 +9479,7 @@ function buildUpdateTool(host) {
|
|
|
8975
9479
|
if (task === void 0) return refused("task-not-found", "no task with id " + args.taskId);
|
|
8976
9480
|
return json({
|
|
8977
9481
|
ok: true,
|
|
8978
|
-
task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission)
|
|
9482
|
+
task: taskDetail(task, snapshot.tasks, snapshot.sessionDefaultPermission, host)
|
|
8979
9483
|
});
|
|
8980
9484
|
} catch (error) {
|
|
8981
9485
|
return refused("refused", messageOf(error));
|