@linxin666/dsh-client-ui-task-board-ssh 0.4.20 → 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 +13 -2
- package/README.zh.md +13 -2
- package/lib/client.js +9 -3
- package/lib/index.js +1071 -89
- package/lib/types/core/contract.d.ts +8 -0
- package/lib/types/core/target.d.ts +6 -0
- package/lib/types/core/task-record.d.ts +11 -0
- package/lib/types/host/board.d.ts +4 -0
- package/lib/types/host/engine.d.ts +145 -0
- package/lib/types/host/extension.d.ts +2 -0
- package/lib/types/host/inspect.d.ts +99 -0
- package/lib/types/host/remote.d.ts +17 -0
- package/lib/types/host/tools.d.ts +5 -3
- package/package.json +1 -1
- package/src/core/contract.ts +5 -0
- package/src/core/ledger.ts +5 -0
- package/src/core/target.ts +10 -3
- package/src/core/task-record.ts +8 -0
- package/src/host/board.ts +4 -0
- package/src/host/engine.ts +430 -6
- package/src/host/extension.ts +6 -0
- package/src/host/inspect.ts +264 -0
- package/src/host/remote.ts +28 -0
- package/src/host/tools.ts +250 -60
package/lib/index.js
CHANGED
|
@@ -506,7 +506,10 @@ function parseSshRunRecord(value) {
|
|
|
506
506
|
"branch",
|
|
507
507
|
"summary",
|
|
508
508
|
"error",
|
|
509
|
-
"followUps"
|
|
509
|
+
"followUps",
|
|
510
|
+
"executionId",
|
|
511
|
+
"lastActivityAt",
|
|
512
|
+
"errorCode"
|
|
510
513
|
], "", issues);
|
|
511
514
|
if ((typeof value.runId === "string" && value.runId !== "." && value.runId !== ".." && /^[A-Za-z0-9._-]{1,128}$/.test(value.runId) ? value.runId : void 0) === void 0) issues.add("runId", "must be 1-128 characters of letters, digits, dots, underscores or hyphens");
|
|
512
515
|
if (!oneOf(value.phase, [
|
|
@@ -522,7 +525,8 @@ function parseSshRunRecord(value) {
|
|
|
522
525
|
"finishedAt",
|
|
523
526
|
"exitCode",
|
|
524
527
|
"bytes",
|
|
525
|
-
"followUps"
|
|
528
|
+
"followUps",
|
|
529
|
+
"lastActivityAt"
|
|
526
530
|
]) {
|
|
527
531
|
if (value[key] === void 0) continue;
|
|
528
532
|
if (typeof value[key] !== "number" || !Number.isFinite(value[key])) issues.add(key, "must be a finite number");
|
|
@@ -531,7 +535,9 @@ function parseSshRunRecord(value) {
|
|
|
531
535
|
"sessionId",
|
|
532
536
|
"branch",
|
|
533
537
|
"summary",
|
|
534
|
-
"error"
|
|
538
|
+
"error",
|
|
539
|
+
"executionId",
|
|
540
|
+
"errorCode"
|
|
535
541
|
]) {
|
|
536
542
|
if (value[key] === void 0) continue;
|
|
537
543
|
readText(value[key], key, issues);
|
|
@@ -1192,6 +1198,9 @@ function boundRun(record) {
|
|
|
1192
1198
|
if (summary !== void 0) next.summary = summary;
|
|
1193
1199
|
if (error !== void 0) next.error = error;
|
|
1194
1200
|
if (record.followUps !== void 0) next.followUps = record.followUps;
|
|
1201
|
+
if (record.executionId !== void 0) next.executionId = boundText(record.executionId, 128);
|
|
1202
|
+
if (record.lastActivityAt !== void 0) next.lastActivityAt = record.lastActivityAt;
|
|
1203
|
+
if (record.errorCode !== void 0) next.errorCode = boundText(record.errorCode, 64);
|
|
1195
1204
|
return next;
|
|
1196
1205
|
}
|
|
1197
1206
|
/** Copy one run record with the optional free text removed. */
|
|
@@ -1206,6 +1215,8 @@ function stripRunText(record) {
|
|
|
1206
1215
|
if (record.sessionId !== void 0) stripped.sessionId = record.sessionId;
|
|
1207
1216
|
if (record.bytes !== void 0) stripped.bytes = record.bytes;
|
|
1208
1217
|
if (record.followUps !== void 0) stripped.followUps = record.followUps;
|
|
1218
|
+
if (record.executionId !== void 0) stripped.executionId = record.executionId;
|
|
1219
|
+
if (record.lastActivityAt !== void 0) stripped.lastActivityAt = record.lastActivityAt;
|
|
1209
1220
|
return stripped;
|
|
1210
1221
|
}
|
|
1211
1222
|
/** Copy one instruction with both free-text fields cut to their stored budget. */
|
|
@@ -2385,6 +2396,10 @@ var SshRemote = class {
|
|
|
2385
2396
|
this.ssh = ssh;
|
|
2386
2397
|
this.timeoutMs = options.timeoutMs ?? 3e4;
|
|
2387
2398
|
}
|
|
2399
|
+
/** The state directory of a host when it was already resolved, without a round trip. */
|
|
2400
|
+
cachedStateDir(alias) {
|
|
2401
|
+
return this.stateDirs.get(alias);
|
|
2402
|
+
}
|
|
2388
2403
|
/** Forget every cached path of one host, or of all hosts when none is named. */
|
|
2389
2404
|
forget(alias) {
|
|
2390
2405
|
if (alias === void 0) {
|
|
@@ -2564,6 +2579,34 @@ var SshRemote = class {
|
|
|
2564
2579
|
async removeRun(ref) {
|
|
2565
2580
|
await this.run(ref.alias, shellRemoveDir(runDirectory(ref.stateDir, ref.runId)), "run directory removal");
|
|
2566
2581
|
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Run one read-only diagnostic command and hand back the raw result, whether
|
|
2584
|
+
* or not it succeeded: the caller decides what a failure means.
|
|
2585
|
+
* @param alias - host alias.
|
|
2586
|
+
* @param command - command line, already quoted.
|
|
2587
|
+
* @param timeoutMs - ceiling for this command.
|
|
2588
|
+
* @returns what the forwarder reported; a thrown forwarder becomes a failed result.
|
|
2589
|
+
*/
|
|
2590
|
+
async probe(alias, command, timeoutMs = this.timeoutMs) {
|
|
2591
|
+
try {
|
|
2592
|
+
const result = await this.ssh.exec(alias, command, { timeoutMs });
|
|
2593
|
+
return {
|
|
2594
|
+
success: result.success,
|
|
2595
|
+
stdout: result.stdout,
|
|
2596
|
+
stderr: result.stderr,
|
|
2597
|
+
timedOut: result.timedOut,
|
|
2598
|
+
...result.error === void 0 ? {} : { error: result.error }
|
|
2599
|
+
};
|
|
2600
|
+
} catch (error) {
|
|
2601
|
+
return {
|
|
2602
|
+
success: false,
|
|
2603
|
+
stdout: "",
|
|
2604
|
+
stderr: "",
|
|
2605
|
+
timedOut: false,
|
|
2606
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2567
2610
|
/** Run one command and refuse a failed one in the host's own words. */
|
|
2568
2611
|
async run(alias, command, what, timeoutMs = this.timeoutMs) {
|
|
2569
2612
|
const result = await this.ssh.exec(alias, command, { timeoutMs });
|
|
@@ -2573,6 +2616,198 @@ var SshRemote = class {
|
|
|
2573
2616
|
}
|
|
2574
2617
|
};
|
|
2575
2618
|
//#endregion
|
|
2619
|
+
//#region src/host/inspect.ts
|
|
2620
|
+
/**
|
|
2621
|
+
* What an agent asks about a remote run before and while it runs: whether the
|
|
2622
|
+
* target can work at all (preflight), what the log says without its noise
|
|
2623
|
+
* (filtered log query), and what the agent did last (activity).
|
|
2624
|
+
*
|
|
2625
|
+
* Every command here is read-only and composed through `shellQuote`; none of it
|
|
2626
|
+
* touches the launcher script, so the remote side of a run is unchanged.
|
|
2627
|
+
*
|
|
2628
|
+
* @module dsh-task-board-ssh/host/inspect
|
|
2629
|
+
*/
|
|
2630
|
+
/** Program a built-in agent kind starts on the host, or undefined when it is configured. */
|
|
2631
|
+
function agentProgram(agent, override) {
|
|
2632
|
+
if (override !== void 0) return override;
|
|
2633
|
+
switch (agent.kind) {
|
|
2634
|
+
case "dsh": return "dsh";
|
|
2635
|
+
case "claude": return "claude";
|
|
2636
|
+
case "codex": return "codex";
|
|
2637
|
+
default: {
|
|
2638
|
+
const first = agent.command?.trim().split(/\s+/)[0];
|
|
2639
|
+
return first === void 0 || first === "" || first.includes("{") || first.includes("$") ? void 0 : first;
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
/**
|
|
2644
|
+
* The single remote command one preflight runs: it always exits zero and prints
|
|
2645
|
+
* one `key=value` per fact, so a failed channel is told apart from a failed check.
|
|
2646
|
+
*/
|
|
2647
|
+
function preflightCommand(target, program) {
|
|
2648
|
+
const parts = ["echo reach=ok"];
|
|
2649
|
+
if (program !== void 0) parts.push(`if command -v ${shellQuote(program)} >/dev/null 2>&1; then echo agent=ok; else echo agent=missing; fi`);
|
|
2650
|
+
if (target.workspace.kind === "in-place") {
|
|
2651
|
+
const path = shellQuote(target.workspace.path);
|
|
2652
|
+
parts.push(`if [ -d ${path} ]; then echo path=ok; if [ -w ${path} ] && [ -x ${path} ]; then echo write=ok; else echo write=denied; fi; else echo path=missing; fi`);
|
|
2653
|
+
}
|
|
2654
|
+
return parts.join("; ");
|
|
2655
|
+
}
|
|
2656
|
+
/**
|
|
2657
|
+
* Read one preflight answer.
|
|
2658
|
+
* @param target - the checked target.
|
|
2659
|
+
* @param program - the probed program, if any.
|
|
2660
|
+
* @param result - what `exec` returned.
|
|
2661
|
+
* @returns the first failed check, or undefined when the target can work.
|
|
2662
|
+
*/
|
|
2663
|
+
function readPreflight(target, program, result) {
|
|
2664
|
+
const facts = /* @__PURE__ */ new Map();
|
|
2665
|
+
for (const line of result.stdout.split("\n")) {
|
|
2666
|
+
const at = line.indexOf("=");
|
|
2667
|
+
if (at > 0) facts.set(line.slice(0, at).trim(), line.slice(at + 1).trim());
|
|
2668
|
+
}
|
|
2669
|
+
if (facts.get("reach") !== "ok") {
|
|
2670
|
+
const why = result.error ?? (result.stderr.trim() || (result.timedOut === true ? "the connection timed out" : "no answer"));
|
|
2671
|
+
return {
|
|
2672
|
+
code: "host-unreachable",
|
|
2673
|
+
message: `host "${target.host}" did not answer an ssh command: ${why.slice(0, 200)}`,
|
|
2674
|
+
hint: "Check the alias and credentials in the dsh-ssh settings (or use task_board_ssh action \"hosts\" to list the aliases), then retry."
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
if (program !== void 0 && facts.get("agent") !== "ok") return {
|
|
2678
|
+
code: "agent-missing",
|
|
2679
|
+
message: `"${program}" is not on the PATH of host "${target.host}"`,
|
|
2680
|
+
hint: `Install ${program} there, or pick another agent (dsh, claude, codex, custom).`
|
|
2681
|
+
};
|
|
2682
|
+
if (target.workspace.kind === "in-place") {
|
|
2683
|
+
if (facts.get("path") !== "ok") return {
|
|
2684
|
+
code: "path-missing",
|
|
2685
|
+
message: `directory ${target.workspace.path} does not exist on host "${target.host}"; an in-place target never creates it`,
|
|
2686
|
+
hint: "Create the directory on the host first, or use workspaceKind \"git\" to get a per-run worktree."
|
|
2687
|
+
};
|
|
2688
|
+
if (facts.get("write") !== "ok") return {
|
|
2689
|
+
code: "permission-required",
|
|
2690
|
+
message: `directory ${target.workspace.path} on host "${target.host}" is not writable by the ssh user`,
|
|
2691
|
+
hint: "Grant that user write access (or pick a directory it owns), then retry."
|
|
2692
|
+
};
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
/** Longest line a filtered log returns, in bytes; longer ones are cut and marked. */
|
|
2696
|
+
const LOG_LINE_MAX_BYTES = 2e3;
|
|
2697
|
+
/**
|
|
2698
|
+
* awk program that drops what an agent never needs from a stream-json log:
|
|
2699
|
+
* every `system` event except `init` (thinking_tokens, hooks, status), rate
|
|
2700
|
+
* limit notices and partial stream deltas. It also cuts overlong lines.
|
|
2701
|
+
*/
|
|
2702
|
+
const NOISE_FILTER = [
|
|
2703
|
+
`/^\\{"type":"(stream_event|rate_limit_event)"/ {next}`,
|
|
2704
|
+
`/^\\{"type":"system","subtype":"init"/ {print; next}`,
|
|
2705
|
+
`/^\\{"type":"system"/ {next}`,
|
|
2706
|
+
`{ if (length($0) > ${String(LOG_LINE_MAX_BYTES)}) $0 = substr($0, 1, ${String(LOG_LINE_MAX_BYTES)}) " ...[line cut]"; print }`
|
|
2707
|
+
].join(" ");
|
|
2708
|
+
/** The command that answers one log query, text after a `stats` line. */
|
|
2709
|
+
function logCommand(query) {
|
|
2710
|
+
const file = shellQuote(query.file);
|
|
2711
|
+
const filter = query.raw === true ? "cat" : `LC_ALL=C awk ${shellQuote(NOISE_FILTER)}`;
|
|
2712
|
+
const count = `LC_ALL=C awk '{ l += 1; b += length($0) + 1 } END { printf "%d %d", l, b }'`;
|
|
2713
|
+
const cap = Math.max(1, Math.min(Math.trunc(query.maxBytes ?? 65536), 128 * 1024));
|
|
2714
|
+
const select = query.since !== void 0 ? `tail -n +${String(Math.max(1, Math.trunc(query.since)))}` : `tail -n ${String(Math.max(1, Math.min(Math.trunc(query.tail ?? 40), 2e3)))}`;
|
|
2715
|
+
return `if [ ! -f ${file} ]; then echo "stats none"; exit 0; fi; printf 'stats %s ' "$(wc -c < ${file} | tr -d ' ')"; ${filter} ${file} | ${count}; echo${query.statsOnly === true ? "" : `; ${filter} ${file} | ${select} | head -c ${String(cap + 1)}`}`;
|
|
2716
|
+
}
|
|
2717
|
+
/**
|
|
2718
|
+
* Parse the answer of {@link logCommand}.
|
|
2719
|
+
* @param stdout - what the command printed.
|
|
2720
|
+
* @param query - the query it answered.
|
|
2721
|
+
* @returns stats and the complete lines that fit the cap.
|
|
2722
|
+
*/
|
|
2723
|
+
function readLogAnswer(stdout, query) {
|
|
2724
|
+
const newline = stdout.indexOf("\n");
|
|
2725
|
+
const head = newline === -1 ? stdout : stdout.slice(0, newline);
|
|
2726
|
+
const rest = newline === -1 ? "" : stdout.slice(newline + 1);
|
|
2727
|
+
const match = /^stats (\d+) (\d+) (\d+)$/.exec(head.trim());
|
|
2728
|
+
const stats = match === null ? void 0 : {
|
|
2729
|
+
rawBytes: Number(match[1]),
|
|
2730
|
+
lines: Number(match[2]),
|
|
2731
|
+
bytes: Number(match[3])
|
|
2732
|
+
};
|
|
2733
|
+
const cap = Math.max(1, Math.min(Math.trunc(query.maxBytes ?? 65536), 128 * 1024));
|
|
2734
|
+
let text = rest;
|
|
2735
|
+
let cut = false;
|
|
2736
|
+
if (new TextEncoder().encode(text).length > cap) {
|
|
2737
|
+
cut = true;
|
|
2738
|
+
text = text.slice(0, text.lastIndexOf("\n") + 1);
|
|
2739
|
+
while (new TextEncoder().encode(text).length > cap) text = text.slice(0, text.slice(0, -1).lastIndexOf("\n") + 1);
|
|
2740
|
+
}
|
|
2741
|
+
const lines = text === "" ? 0 : text.split("\n").filter((line, index, all) => line !== "" || index < all.length - 1).length;
|
|
2742
|
+
const firstLine = query.since ?? Math.max(1, (stats?.lines ?? 0) - Math.trunc(query.tail ?? 40) + 1);
|
|
2743
|
+
const more = cut || stats !== void 0 && firstLine + lines - 1 < stats.lines;
|
|
2744
|
+
return {
|
|
2745
|
+
stats,
|
|
2746
|
+
text,
|
|
2747
|
+
lines,
|
|
2748
|
+
more
|
|
2749
|
+
};
|
|
2750
|
+
}
|
|
2751
|
+
/** First filtered line number a tail of `tail` lines starts at, given the totals. */
|
|
2752
|
+
function tailStart(stats, tail) {
|
|
2753
|
+
return Math.max(1, stats.lines - Math.max(1, tail) + 1);
|
|
2754
|
+
}
|
|
2755
|
+
/** One short line out of a tool input. */
|
|
2756
|
+
function inputLine(input) {
|
|
2757
|
+
if (typeof input !== "object" || input === null) return "";
|
|
2758
|
+
const row = input;
|
|
2759
|
+
for (const key of [
|
|
2760
|
+
"command",
|
|
2761
|
+
"file_path",
|
|
2762
|
+
"path",
|
|
2763
|
+
"pattern",
|
|
2764
|
+
"url",
|
|
2765
|
+
"description",
|
|
2766
|
+
"prompt"
|
|
2767
|
+
]) {
|
|
2768
|
+
const value = row[key];
|
|
2769
|
+
if (typeof value === "string" && value !== "") return value.replace(/\s+/g, " ").slice(0, 160);
|
|
2770
|
+
}
|
|
2771
|
+
return JSON.stringify(row).slice(0, 160);
|
|
2772
|
+
}
|
|
2773
|
+
/**
|
|
2774
|
+
* The last tool call (or message) in a stretch of stream-json lines.
|
|
2775
|
+
* @param text - filtered log lines, oldest first.
|
|
2776
|
+
* @returns the last action, or undefined when none parses.
|
|
2777
|
+
*/
|
|
2778
|
+
function lastActivity(text) {
|
|
2779
|
+
const lines = text.split("\n").filter((line) => line.trim() !== "");
|
|
2780
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
2781
|
+
let event;
|
|
2782
|
+
try {
|
|
2783
|
+
event = JSON.parse(lines[index]);
|
|
2784
|
+
} catch {
|
|
2785
|
+
continue;
|
|
2786
|
+
}
|
|
2787
|
+
if (typeof event !== "object" || event === null) continue;
|
|
2788
|
+
const row = event;
|
|
2789
|
+
if (row.type === "result") return {
|
|
2790
|
+
kind: "result",
|
|
2791
|
+
detail: String(row.subtype ?? "result")
|
|
2792
|
+
};
|
|
2793
|
+
if (row.type !== "assistant") continue;
|
|
2794
|
+
const message = row.message;
|
|
2795
|
+
if (!Array.isArray(message?.content)) continue;
|
|
2796
|
+
for (let at = message.content.length - 1; at >= 0; at -= 1) {
|
|
2797
|
+
const block = message.content[at];
|
|
2798
|
+
if (block.type === "tool_use") return {
|
|
2799
|
+
kind: "tool_use",
|
|
2800
|
+
name: String(block.name ?? ""),
|
|
2801
|
+
detail: inputLine(block.input)
|
|
2802
|
+
};
|
|
2803
|
+
if (block.type === "text" && typeof block.text === "string" && block.text.trim() !== "") return {
|
|
2804
|
+
kind: "assistant",
|
|
2805
|
+
detail: block.text.trim().replace(/\s+/g, " ").slice(0, 160)
|
|
2806
|
+
};
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
//#endregion
|
|
2576
2811
|
//#region src/host/workspace-seam.ts
|
|
2577
2812
|
/** Cordis service name of the deployment's workspace registry. */
|
|
2578
2813
|
const WORKSPACE_REGISTRY_SERVICE = "workspaceRegistry";
|
|
@@ -2638,8 +2873,20 @@ function untrackedNote(files) {
|
|
|
2638
2873
|
if (files === void 0 || files <= 0) return "";
|
|
2639
2874
|
return files === 1 ? "1 untracked local file was not sent: a bundle carries commits, not the untracked working tree." : `${String(files)} untracked local files were not sent: a bundle carries commits, not the untracked working tree.`;
|
|
2640
2875
|
}
|
|
2876
|
+
/** Expected run length when no earlier run says better, in milliseconds. */
|
|
2877
|
+
const DEFAULT_ESTIMATED_DURATION_MS = 18e4;
|
|
2641
2878
|
/** Longest tail of a run's log this engine parses, in characters. */
|
|
2642
2879
|
const PARSE_WINDOW = 256 * 1024;
|
|
2880
|
+
/** The target as a model reads it. */
|
|
2881
|
+
function targetView(target) {
|
|
2882
|
+
return {
|
|
2883
|
+
host: target.host,
|
|
2884
|
+
agent: target.agent.kind,
|
|
2885
|
+
mode: target.mode,
|
|
2886
|
+
workspaceKind: target.workspace.kind,
|
|
2887
|
+
...target.workspace.kind === "in-place" ? { workspacePath: target.workspace.path } : {}
|
|
2888
|
+
};
|
|
2889
|
+
}
|
|
2643
2890
|
/** Bound one free-text field to the ledger's stored budget. */
|
|
2644
2891
|
function bound(text, max) {
|
|
2645
2892
|
return text.length <= max ? text : text.slice(0, max);
|
|
@@ -2691,6 +2938,24 @@ function agentResumeSupported(kind, templates) {
|
|
|
2691
2938
|
function agentCommandLine(input, templates) {
|
|
2692
2939
|
return templates === void 0 ? buildAgentCommandLine(input) : customAgentCommand(input, templates);
|
|
2693
2940
|
}
|
|
2941
|
+
/** Stable code of a failed run, from what the launcher and the agent reported. */
|
|
2942
|
+
function failureCode(phase, status, collection, thrown) {
|
|
2943
|
+
if (thrown) return "run-error";
|
|
2944
|
+
if (collection) return "collection-failed";
|
|
2945
|
+
if (phase === "lost") return "run-lost";
|
|
2946
|
+
if (status.exitCode !== void 0 && status.exitCode !== 0) return "agent-exit";
|
|
2947
|
+
return "agent-error";
|
|
2948
|
+
}
|
|
2949
|
+
/** One sentence on whether and how to retry a failed run. */
|
|
2950
|
+
function retryHintFor(code) {
|
|
2951
|
+
switch (code) {
|
|
2952
|
+
case "agent-exit": return "Read the log tail (task_board_ssh action \"log\"), fix the cause, then run again; a follow-up resumes the same remote session.";
|
|
2953
|
+
case "run-lost": return "The remote process vanished (host restart or kill); running again starts a fresh run.";
|
|
2954
|
+
case "collection-failed": return "The agent finished but its result could not be brought back; the remote branch or directory still holds the work.";
|
|
2955
|
+
case "run-error": return "The run could not be driven (see the error text); retry once the host is reachable.";
|
|
2956
|
+
default: return "Read the log tail for the agent error, then run again or send a follow-up.";
|
|
2957
|
+
}
|
|
2958
|
+
}
|
|
2694
2959
|
var SshRunEngine = class {
|
|
2695
2960
|
host;
|
|
2696
2961
|
ssh;
|
|
@@ -2702,6 +2967,9 @@ var SshRunEngine = class {
|
|
|
2702
2967
|
now;
|
|
2703
2968
|
uuid;
|
|
2704
2969
|
pollIntervalMs;
|
|
2970
|
+
sleep;
|
|
2971
|
+
/** Ids handed out at launch, keyed by card, until the run record takes them over. */
|
|
2972
|
+
reserved = /* @__PURE__ */ new Map();
|
|
2705
2973
|
log;
|
|
2706
2974
|
remote;
|
|
2707
2975
|
/** Runs this process follows, keyed by card id: a card has at most one. */
|
|
@@ -2743,6 +3011,9 @@ var SshRunEngine = class {
|
|
|
2743
3011
|
this.now = options.now ?? (() => Date.now());
|
|
2744
3012
|
this.uuid = options.uuid ?? (() => crypto.randomUUID());
|
|
2745
3013
|
this.pollIntervalMs = options.pollIntervalMs ?? 2e3;
|
|
3014
|
+
this.sleep = options.sleep ?? ((ms) => new Promise((resolve) => {
|
|
3015
|
+
setTimeout(resolve, ms);
|
|
3016
|
+
}));
|
|
2746
3017
|
this.log = options.log ?? ((message, detail) => {
|
|
2747
3018
|
if (detail === void 0) console.error("[dsh-task-board-ssh] " + message);
|
|
2748
3019
|
else console.error("[dsh-task-board-ssh] " + message, detail);
|
|
@@ -2793,6 +3064,7 @@ var SshRunEngine = class {
|
|
|
2793
3064
|
this.pumping.clear();
|
|
2794
3065
|
this.pumpAgain.clear();
|
|
2795
3066
|
this.settling.clear();
|
|
3067
|
+
this.reserved.clear();
|
|
2796
3068
|
this.untracked.clear();
|
|
2797
3069
|
this.logs.clear();
|
|
2798
3070
|
this.remote.forget();
|
|
@@ -2837,6 +3109,261 @@ var SshRunEngine = class {
|
|
|
2837
3109
|
targetOf(taskId) {
|
|
2838
3110
|
return this.payloadOf(taskId)?.target;
|
|
2839
3111
|
}
|
|
3112
|
+
/**
|
|
3113
|
+
* One card's run in a single shape, whether it is still running or settled.
|
|
3114
|
+
*
|
|
3115
|
+
* The active run wins; with none, the newest settled one answers, so the same
|
|
3116
|
+
* fields exist before and after the run ends and `phase` is never missing.
|
|
3117
|
+
* Absent facts are `null`, never undefined, so a caller reads one schema.
|
|
3118
|
+
* @param taskId - card to read.
|
|
3119
|
+
* @returns the uniform view.
|
|
3120
|
+
*/
|
|
3121
|
+
statusView(taskId) {
|
|
3122
|
+
const payload = this.payloadOf(taskId);
|
|
3123
|
+
const target = payload?.target;
|
|
3124
|
+
const empty = {
|
|
3125
|
+
taskId,
|
|
3126
|
+
target: target === void 0 ? null : targetView(target),
|
|
3127
|
+
phase: "none",
|
|
3128
|
+
settled: false,
|
|
3129
|
+
runId: null,
|
|
3130
|
+
executionId: null,
|
|
3131
|
+
exitCode: null,
|
|
3132
|
+
result: null,
|
|
3133
|
+
summary: null,
|
|
3134
|
+
error: null,
|
|
3135
|
+
durationMs: null,
|
|
3136
|
+
remoteSessionId: null,
|
|
3137
|
+
lastActivityAt: null,
|
|
3138
|
+
bytes: null,
|
|
3139
|
+
pendingInstruction: payload?.pending?.kind ?? null
|
|
3140
|
+
};
|
|
3141
|
+
if (payload === void 0) return empty;
|
|
3142
|
+
const reservation = this.reserved.get(taskId);
|
|
3143
|
+
if (reservation !== void 0 && payload.activeRun === void 0) return {
|
|
3144
|
+
...empty,
|
|
3145
|
+
phase: "queued",
|
|
3146
|
+
runId: reservation.runId,
|
|
3147
|
+
executionId: reservation.executionId,
|
|
3148
|
+
durationMs: this.now() - reservation.startedAt,
|
|
3149
|
+
lastActivityAt: reservation.startedAt
|
|
3150
|
+
};
|
|
3151
|
+
const run = payload.activeRun ?? payload.history[payload.history.length - 1];
|
|
3152
|
+
if (run === void 0) return empty;
|
|
3153
|
+
const settled = isTerminalRunPhase(run.phase) && !this.settling.has(taskId);
|
|
3154
|
+
const phase = !settled && isTerminalRunPhase(run.phase) ? "running" : run.phase;
|
|
3155
|
+
return {
|
|
3156
|
+
...empty,
|
|
3157
|
+
phase,
|
|
3158
|
+
settled,
|
|
3159
|
+
runId: run.runId,
|
|
3160
|
+
executionId: run.executionId ?? null,
|
|
3161
|
+
exitCode: run.exitCode ?? null,
|
|
3162
|
+
result: settled ? run.phase : null,
|
|
3163
|
+
summary: run.summary ?? null,
|
|
3164
|
+
error: run.error === void 0 ? null : {
|
|
3165
|
+
code: run.errorCode ?? "agent-error",
|
|
3166
|
+
message: run.error,
|
|
3167
|
+
retryHint: retryHintFor(run.errorCode ?? "agent-error")
|
|
3168
|
+
},
|
|
3169
|
+
durationMs: (run.finishedAt ?? this.now()) - run.startedAt,
|
|
3170
|
+
remoteSessionId: run.sessionId ?? null,
|
|
3171
|
+
lastActivityAt: run.lastActivityAt ?? run.finishedAt ?? run.startedAt,
|
|
3172
|
+
bytes: run.bytes ?? null
|
|
3173
|
+
};
|
|
3174
|
+
}
|
|
3175
|
+
/**
|
|
3176
|
+
* Block until the card's run settles or the wait runs out.
|
|
3177
|
+
* @param taskId - card to wait on.
|
|
3178
|
+
* @param timeoutMs - longest wait, clamped to ten minutes.
|
|
3179
|
+
* @returns the uniform view and whether the wait ran out.
|
|
3180
|
+
*/
|
|
3181
|
+
async waitStatus(taskId, timeoutMs = 12e4) {
|
|
3182
|
+
const limit = Math.max(0, Math.min(Math.trunc(timeoutMs), 10 * 6e4));
|
|
3183
|
+
const deadline = this.now() + limit;
|
|
3184
|
+
for (;;) {
|
|
3185
|
+
const view = this.statusView(taskId);
|
|
3186
|
+
if (view.settled || view.phase === "none") return {
|
|
3187
|
+
view,
|
|
3188
|
+
timedOut: false
|
|
3189
|
+
};
|
|
3190
|
+
const left = deadline - this.now();
|
|
3191
|
+
if (left <= 0 || this.disposed) return {
|
|
3192
|
+
view,
|
|
3193
|
+
timedOut: true
|
|
3194
|
+
};
|
|
3195
|
+
await this.sleep(Math.min(1e3, left));
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
/**
|
|
3199
|
+
* What the agent did last, read from the tail of the run's filtered log.
|
|
3200
|
+
* @param taskId - card to inspect.
|
|
3201
|
+
* @returns the last tool call or message, or undefined when none can be read.
|
|
3202
|
+
*/
|
|
3203
|
+
async activityOf(taskId) {
|
|
3204
|
+
const page = await this.queryLog(taskId, {
|
|
3205
|
+
tail: 30,
|
|
3206
|
+
maxBytes: 48 * 1024
|
|
3207
|
+
});
|
|
3208
|
+
return page.ok ? lastActivity(page.text) : void 0;
|
|
3209
|
+
}
|
|
3210
|
+
/**
|
|
3211
|
+
* One filtered, bounded read of a run's log.
|
|
3212
|
+
*
|
|
3213
|
+
* The filter, the line selection and the byte cap all run on the host, so a
|
|
3214
|
+
* 12 MB stream-json log costs one short reply; the reply carries the filtered
|
|
3215
|
+
* line count and size so a caller sees the cost before asking for more.
|
|
3216
|
+
* @param taskId - card whose run to read.
|
|
3217
|
+
* @param options - run, tail/since window, raw switch, cap and stats-only.
|
|
3218
|
+
* @returns the page, or the refusal that says why there is none.
|
|
3219
|
+
*/
|
|
3220
|
+
async queryLog(taskId, options = {}) {
|
|
3221
|
+
const payload = this.payloadOf(taskId);
|
|
3222
|
+
const target = payload?.target;
|
|
3223
|
+
if (payload === void 0 || target === void 0) return {
|
|
3224
|
+
ok: false,
|
|
3225
|
+
code: "no-target",
|
|
3226
|
+
error: `task ${taskId} pins no SSH target`
|
|
3227
|
+
};
|
|
3228
|
+
if (options.runId !== void 0 && findRun(payload, options.runId) === void 0) return {
|
|
3229
|
+
ok: false,
|
|
3230
|
+
code: "unknown-run",
|
|
3231
|
+
error: `task ${taskId} has no run ${options.runId}`
|
|
3232
|
+
};
|
|
3233
|
+
const runId = options.runId ?? payload.activeRun?.runId ?? this.reserved.get(taskId)?.runId ?? payload.history[payload.history.length - 1]?.runId;
|
|
3234
|
+
if (runId === void 0) return {
|
|
3235
|
+
ok: false,
|
|
3236
|
+
code: "no-run",
|
|
3237
|
+
error: `task ${taskId} has never run remotely`
|
|
3238
|
+
};
|
|
3239
|
+
let stateDir;
|
|
3240
|
+
try {
|
|
3241
|
+
stateDir = await this.remote.stateDir(target.host);
|
|
3242
|
+
} catch (error) {
|
|
3243
|
+
return {
|
|
3244
|
+
ok: false,
|
|
3245
|
+
code: "host-unreachable",
|
|
3246
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3247
|
+
};
|
|
3248
|
+
}
|
|
3249
|
+
const query = {
|
|
3250
|
+
file: runFilePath(stateDir, runId, "stdout.log"),
|
|
3251
|
+
...options.tail === void 0 ? {} : { tail: options.tail },
|
|
3252
|
+
...options.since === void 0 ? {} : { since: options.since },
|
|
3253
|
+
...options.raw === true ? { raw: true } : {},
|
|
3254
|
+
...options.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes },
|
|
3255
|
+
...options.statsOnly === true ? { statsOnly: true } : {}
|
|
3256
|
+
};
|
|
3257
|
+
const result = await this.remote.probe(target.host, logCommand(query));
|
|
3258
|
+
if (!result.success) return {
|
|
3259
|
+
ok: false,
|
|
3260
|
+
code: "log-unavailable",
|
|
3261
|
+
error: result.error ?? (result.stderr.trim() || "the log could not be read")
|
|
3262
|
+
};
|
|
3263
|
+
const answer = readLogAnswer(result.stdout, query);
|
|
3264
|
+
if (answer.stats === void 0) return {
|
|
3265
|
+
ok: false,
|
|
3266
|
+
code: "no-log-yet",
|
|
3267
|
+
error: `run ${runId} has not written a log yet`
|
|
3268
|
+
};
|
|
3269
|
+
const from = query.since ?? tailStart(answer.stats, options.tail ?? 40);
|
|
3270
|
+
return {
|
|
3271
|
+
ok: true,
|
|
3272
|
+
runId,
|
|
3273
|
+
filtered: options.raw !== true,
|
|
3274
|
+
stats: answer.stats,
|
|
3275
|
+
from,
|
|
3276
|
+
lines: answer.lines,
|
|
3277
|
+
nextSince: from + answer.lines,
|
|
3278
|
+
more: answer.more,
|
|
3279
|
+
text: answer.text
|
|
3280
|
+
};
|
|
3281
|
+
}
|
|
3282
|
+
/**
|
|
3283
|
+
* Check a target can work before a card is bound to it or a run starts.
|
|
3284
|
+
* @param target - the candidate target.
|
|
3285
|
+
* @returns the first failed check, or undefined when the target is usable.
|
|
3286
|
+
*/
|
|
3287
|
+
async preflight(target) {
|
|
3288
|
+
if (this.hostByAlias(target.host) === void 0) {
|
|
3289
|
+
const known = this.hosts().slice(0, 20).map((host) => host.alias);
|
|
3290
|
+
return {
|
|
3291
|
+
code: "host-unreachable",
|
|
3292
|
+
message: `dsh-ssh has no host with alias "${target.host}"${known.length === 0 ? " (no host is configured at all)" : `; configured aliases: ${known.join(", ")}`}`,
|
|
3293
|
+
hint: "Use one of the configured aliases, or add the host in the dsh-ssh settings first."
|
|
3294
|
+
};
|
|
3295
|
+
}
|
|
3296
|
+
const program = this.settings().agentCommands[target.agent.kind] !== void 0 ? void 0 : agentProgram(target.agent);
|
|
3297
|
+
return readPreflight(target, program, await this.remote.probe(target.host, preflightCommand(target, program), 15e3));
|
|
3298
|
+
}
|
|
3299
|
+
/** Summary of one card this provider owns, for `task_board_get` / `task_board_list`. */
|
|
3300
|
+
describeTask(task) {
|
|
3301
|
+
const payload = readHostPayload(task.integrations?.["ssh"]);
|
|
3302
|
+
const target = payload?.target;
|
|
3303
|
+
if (payload === void 0 || target === void 0) return void 0;
|
|
3304
|
+
const live = liveRunOf(payload);
|
|
3305
|
+
const last = payload.activeRun ?? payload.history[payload.history.length - 1];
|
|
3306
|
+
const canFollowUp = target.mode === "direct" && task.archivedAt === void 0 && payload.pending === void 0;
|
|
3307
|
+
return {
|
|
3308
|
+
kind: "ssh",
|
|
3309
|
+
host: target.host,
|
|
3310
|
+
agent: target.agent.kind,
|
|
3311
|
+
mode: target.mode,
|
|
3312
|
+
workspace: target.workspace.kind,
|
|
3313
|
+
canFollowUp,
|
|
3314
|
+
...canFollowUp ? {} : { followUpBlockedBy: target.mode !== "direct" ? "proxy cards take follow-ups in their local session" : task.archivedAt !== void 0 ? "archived" : "an instruction is already queued" },
|
|
3315
|
+
...last === void 0 ? {} : {
|
|
3316
|
+
phase: this.reserved.has(task.id) ? "queued" : last.phase,
|
|
3317
|
+
runId: last.runId
|
|
3318
|
+
},
|
|
3319
|
+
...live === void 0 && !this.reserved.has(task.id) ? {} : { runActive: true },
|
|
3320
|
+
localPermission: target.mode !== "direct"
|
|
3321
|
+
};
|
|
3322
|
+
}
|
|
3323
|
+
/** The handle of the run just taken over for one card, for `task_board_run`. */
|
|
3324
|
+
describeRun(taskId) {
|
|
3325
|
+
const payload = this.payloadOf(taskId);
|
|
3326
|
+
const target = payload?.target;
|
|
3327
|
+
if (target === void 0 || target.mode !== "direct") return void 0;
|
|
3328
|
+
const reservation = this.reserved.get(taskId);
|
|
3329
|
+
const run = payload?.activeRun;
|
|
3330
|
+
const runId = run?.runId ?? reservation?.runId;
|
|
3331
|
+
if (runId === void 0) return void 0;
|
|
3332
|
+
const stateDir = this.remote.cachedStateDir(target.host) ?? `~/.dsh/task-board-ssh`;
|
|
3333
|
+
const estimate = this.estimateDuration(taskId, target);
|
|
3334
|
+
return {
|
|
3335
|
+
kind: "ssh",
|
|
3336
|
+
executionId: run?.executionId ?? reservation?.executionId ?? null,
|
|
3337
|
+
runId,
|
|
3338
|
+
logPath: `${target.host}:${runFilePath(stateDir, runId, "stdout.log")}`,
|
|
3339
|
+
target: targetView(target),
|
|
3340
|
+
estimatedDurationMs: estimate.ms,
|
|
3341
|
+
estimateBasis: estimate.basis,
|
|
3342
|
+
next: `The run is remote and has no board execution until it settles. Block on it with task_board_ssh {action:"status", taskId:"${taskId}", wait:true}; read its filtered log with {action:"log", taskId:"${taskId}"}.`
|
|
3343
|
+
};
|
|
3344
|
+
}
|
|
3345
|
+
/** Expected duration of a run: the median of earlier successful runs, else a default. */
|
|
3346
|
+
estimateDuration(taskId, target) {
|
|
3347
|
+
const durations = (records) => records.filter((record) => record.phase === "succeeded" && record.finishedAt !== void 0).map((record) => record.finishedAt - record.startedAt);
|
|
3348
|
+
const median = (values) => {
|
|
3349
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
3350
|
+
return sorted[Math.floor(sorted.length / 2)];
|
|
3351
|
+
};
|
|
3352
|
+
const own = durations(this.payloadOf(taskId)?.history ?? []);
|
|
3353
|
+
if (own.length > 0) return {
|
|
3354
|
+
ms: median(own),
|
|
3355
|
+
basis: "card-history"
|
|
3356
|
+
};
|
|
3357
|
+
const shared = this.linkedEntries().filter((entry) => entry.payload?.target?.host === target.host && entry.payload.target.agent.kind === target.agent.kind).flatMap((entry) => durations(entry.payload?.history ?? []));
|
|
3358
|
+
if (shared.length > 0) return {
|
|
3359
|
+
ms: median(shared),
|
|
3360
|
+
basis: "host-history"
|
|
3361
|
+
};
|
|
3362
|
+
return {
|
|
3363
|
+
ms: DEFAULT_ESTIMATED_DURATION_MS,
|
|
3364
|
+
basis: "default"
|
|
3365
|
+
};
|
|
3366
|
+
}
|
|
2840
3367
|
/** One card's remote-run state. */
|
|
2841
3368
|
status(taskId) {
|
|
2842
3369
|
const payload = this.payloadOf(taskId);
|
|
@@ -2912,6 +3439,105 @@ var SshRunEngine = class {
|
|
|
2912
3439
|
};
|
|
2913
3440
|
}
|
|
2914
3441
|
/**
|
|
3442
|
+
* Create a card already bound to a target, in one step.
|
|
3443
|
+
*
|
|
3444
|
+
* The target is checked first and the card is created only when the check
|
|
3445
|
+
* passes, with the target in the same write, so a refused target leaves no
|
|
3446
|
+
* half-made card behind and a created card is never unbound.
|
|
3447
|
+
* @param draft - card content.
|
|
3448
|
+
* @param target - the target to bind.
|
|
3449
|
+
* @param options - `preflight: false` skips the reachability check.
|
|
3450
|
+
* @returns the new card id, or the stable refusal.
|
|
3451
|
+
*/
|
|
3452
|
+
async createBound(draft, target, options = {}) {
|
|
3453
|
+
if (options.preflight !== false) {
|
|
3454
|
+
const failure = await this.preflight(target);
|
|
3455
|
+
if (failure !== void 0) return {
|
|
3456
|
+
ok: false,
|
|
3457
|
+
code: failure.code,
|
|
3458
|
+
error: `${failure.message}. ${failure.hint}`
|
|
3459
|
+
};
|
|
3460
|
+
} else if (this.hostByAlias(target.host) === void 0) return {
|
|
3461
|
+
ok: false,
|
|
3462
|
+
code: "host-unreachable",
|
|
3463
|
+
error: `dsh-ssh has no host with alias "${target.host}"`
|
|
3464
|
+
};
|
|
3465
|
+
try {
|
|
3466
|
+
const task = this.host.tasks.create({
|
|
3467
|
+
title: draft.title,
|
|
3468
|
+
description: draft.description ?? "",
|
|
3469
|
+
prompt: draft.prompt,
|
|
3470
|
+
...draft.workspaceId === void 0 ? {} : { workspaceId: draft.workspaceId },
|
|
3471
|
+
...draft.parentId === void 0 ? {} : { parentId: draft.parentId }
|
|
3472
|
+
}, { payload: writeHostPayload({
|
|
3473
|
+
updatedAt: this.now(),
|
|
3474
|
+
history: [],
|
|
3475
|
+
target
|
|
3476
|
+
}, this.now()) });
|
|
3477
|
+
this.publishSummary();
|
|
3478
|
+
return {
|
|
3479
|
+
ok: true,
|
|
3480
|
+
taskId: task.id,
|
|
3481
|
+
message: "card created with its target"
|
|
3482
|
+
};
|
|
3483
|
+
} catch (error) {
|
|
3484
|
+
return {
|
|
3485
|
+
ok: false,
|
|
3486
|
+
code: "create-refused",
|
|
3487
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3488
|
+
};
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
/**
|
|
3492
|
+
* Start a card's pinned run and wait for the board to accept or refuse it, so
|
|
3493
|
+
* the run's handle exists when this returns.
|
|
3494
|
+
* @param taskId - card to run.
|
|
3495
|
+
* @returns the reply; a board or provider refusal keeps its stable code.
|
|
3496
|
+
*/
|
|
3497
|
+
async runCard(taskId) {
|
|
3498
|
+
const target = this.targetOf(taskId);
|
|
3499
|
+
if (target === void 0) return {
|
|
3500
|
+
ok: false,
|
|
3501
|
+
code: "no-target",
|
|
3502
|
+
error: `task ${taskId} pins no SSH target`
|
|
3503
|
+
};
|
|
3504
|
+
if (target.mode !== "direct") return {
|
|
3505
|
+
ok: false,
|
|
3506
|
+
code: "proxy-mode",
|
|
3507
|
+
error: "a proxy card runs in a local session: start it from the board with task_board_run"
|
|
3508
|
+
};
|
|
3509
|
+
const seat = this.seat?.();
|
|
3510
|
+
if (seat === void 0) return {
|
|
3511
|
+
ok: false,
|
|
3512
|
+
code: "board-unavailable",
|
|
3513
|
+
error: "this board revision serves no action applier"
|
|
3514
|
+
};
|
|
3515
|
+
try {
|
|
3516
|
+
await seat.apply(this.uuid(), {
|
|
3517
|
+
kind: "run",
|
|
3518
|
+
taskId
|
|
3519
|
+
}, "ssh");
|
|
3520
|
+
} catch (error) {
|
|
3521
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3522
|
+
const coded = /^([a-z][a-z0-9-]*): ([\s\S]+)$/.exec(message);
|
|
3523
|
+
return coded === null ? {
|
|
3524
|
+
ok: false,
|
|
3525
|
+
code: "run-refused",
|
|
3526
|
+
error: message
|
|
3527
|
+
} : {
|
|
3528
|
+
ok: false,
|
|
3529
|
+
code: coded[1],
|
|
3530
|
+
error: coded[2]
|
|
3531
|
+
};
|
|
3532
|
+
}
|
|
3533
|
+
return {
|
|
3534
|
+
ok: true,
|
|
3535
|
+
taskId,
|
|
3536
|
+
...this.reserved.get(taskId) === void 0 ? {} : { runId: this.reserved.get(taskId)?.runId },
|
|
3537
|
+
message: "run started"
|
|
3538
|
+
};
|
|
3539
|
+
}
|
|
3540
|
+
/**
|
|
2915
3541
|
* Start a card's pinned run now, through the board's own run action so the
|
|
2916
3542
|
* card reaches the running column the same way the run button puts it there.
|
|
2917
3543
|
* @param taskId - card to run.
|
|
@@ -3296,6 +3922,17 @@ var SshRunEngine = class {
|
|
|
3296
3922
|
this.log(`task ${task.id} pins a remote host but this board revision serves no launch interception or action applier, so it cannot run remotely`);
|
|
3297
3923
|
return { kind: "external" };
|
|
3298
3924
|
}
|
|
3925
|
+
const live = liveRunOf(payload);
|
|
3926
|
+
if (live !== void 0 || this.reserved.has(task.id)) return {
|
|
3927
|
+
kind: "refuse",
|
|
3928
|
+
code: "run-active",
|
|
3929
|
+
reason: `task ${task.id} already has a remote run in flight (${live?.runId ?? this.reserved.get(task.id)?.runId ?? "starting"}); wait for it with task_board_ssh status (wait: true), or cancel it before running again`
|
|
3930
|
+
};
|
|
3931
|
+
this.reserved.set(task.id, {
|
|
3932
|
+
runId: this.newRunId(),
|
|
3933
|
+
executionId: this.uuid(),
|
|
3934
|
+
startedAt: this.now()
|
|
3935
|
+
});
|
|
3299
3936
|
this.openRun(task.id, target.host).catch((error) => {
|
|
3300
3937
|
this.log(`the remote run of task ${task.id} could not be opened`, error);
|
|
3301
3938
|
});
|
|
@@ -3306,14 +3943,27 @@ var SshRunEngine = class {
|
|
|
3306
3943
|
await Promise.resolve();
|
|
3307
3944
|
if (this.disposed) return;
|
|
3308
3945
|
const task = this.host.tasks.get(taskId);
|
|
3309
|
-
if (task === void 0 || task.archivedAt !== void 0 || task.status !== "running")
|
|
3946
|
+
if (task === void 0 || task.archivedAt !== void 0 || task.status !== "running") {
|
|
3947
|
+
this.reserved.delete(taskId);
|
|
3948
|
+
return;
|
|
3949
|
+
}
|
|
3310
3950
|
const payload = this.payloadOf(taskId);
|
|
3311
|
-
if (payload?.target === void 0)
|
|
3951
|
+
if (payload?.target === void 0) {
|
|
3952
|
+
this.reserved.delete(taskId);
|
|
3953
|
+
return;
|
|
3954
|
+
}
|
|
3312
3955
|
if (liveRunOf(payload) !== void 0) return;
|
|
3313
|
-
const
|
|
3956
|
+
const reservation = this.reserved.get(taskId);
|
|
3957
|
+
this.reserved.delete(taskId);
|
|
3958
|
+
const run = reservation === void 0 ? {
|
|
3314
3959
|
runId: this.newRunId(),
|
|
3315
3960
|
phase: "queued",
|
|
3316
3961
|
startedAt: this.now()
|
|
3962
|
+
} : {
|
|
3963
|
+
runId: reservation.runId,
|
|
3964
|
+
phase: "queued",
|
|
3965
|
+
startedAt: reservation.startedAt,
|
|
3966
|
+
executionId: reservation.executionId
|
|
3317
3967
|
};
|
|
3318
3968
|
this.rememberRun(taskId, alias, run.runId, payload.target);
|
|
3319
3969
|
if (!this.writePayload(taskId, {
|
|
@@ -3677,7 +4327,8 @@ var SshRunEngine = class {
|
|
|
3677
4327
|
const current = this.payloadOf(job.taskId);
|
|
3678
4328
|
if (current?.activeRun?.runId === run.runId) this.writePayload(job.taskId, withActiveRun(current, {
|
|
3679
4329
|
...run,
|
|
3680
|
-
bytes
|
|
4330
|
+
bytes,
|
|
4331
|
+
lastActivityAt: this.now()
|
|
3681
4332
|
}));
|
|
3682
4333
|
}
|
|
3683
4334
|
await this.readLogIncrement(job.taskId, target, run, bytes ?? 0);
|
|
@@ -3821,7 +4472,10 @@ var SshRunEngine = class {
|
|
|
3821
4472
|
...branch === void 0 ? {} : { branch },
|
|
3822
4473
|
...run.followUps === void 0 ? {} : { followUps: run.followUps },
|
|
3823
4474
|
...summary === void 0 ? {} : { summary },
|
|
3824
|
-
...errorText === void 0 ? {} : { error: errorText }
|
|
4475
|
+
...errorText === void 0 ? {} : { error: errorText },
|
|
4476
|
+
...run.executionId === void 0 ? {} : { executionId: run.executionId },
|
|
4477
|
+
...run.lastActivityAt === void 0 ? {} : { lastActivityAt: run.lastActivityAt },
|
|
4478
|
+
...errorText === void 0 || phase === "succeeded" ? {} : { errorCode: failureCode(phase, status, collectionError !== void 0, failure !== void 0) }
|
|
3825
4479
|
};
|
|
3826
4480
|
const untracked = this.untracked.get(taskId);
|
|
3827
4481
|
const note = untrackedNote(untracked !== void 0 && untracked.runId === run.runId ? untracked.files : void 0);
|
|
@@ -3863,7 +4517,7 @@ var SshRunEngine = class {
|
|
|
3863
4517
|
}
|
|
3864
4518
|
const marker = degraded ? "[fresh run: this agent cannot resume, so the previous summary was carried in the prompt] " : "";
|
|
3865
4519
|
const room = Math.max(0, 512 - marker.length - (note === "" ? 0 : note.length + 1));
|
|
3866
|
-
const text = run.phase === "succeeded" ? run.summary
|
|
4520
|
+
const text = run.phase === "succeeded" ? run.summary : run.error ?? run.summary;
|
|
3867
4521
|
const composed = [marker + (text === void 0 ? "" : bound(text, room)), note].filter((part) => part !== "").join(" ");
|
|
3868
4522
|
const summary = composed === "" ? void 0 : bound(composed, 512);
|
|
3869
4523
|
try {
|
|
@@ -3872,7 +4526,13 @@ var SshRunEngine = class {
|
|
|
3872
4526
|
taskId: task.id,
|
|
3873
4527
|
result: run.phase === "succeeded" ? "succeeded" : "failed",
|
|
3874
4528
|
initiatedBy: SSH_INITIATOR_PREFIX + run.runId,
|
|
3875
|
-
...summary === void 0 ? {} : { summary }
|
|
4529
|
+
...summary === void 0 ? {} : { summary },
|
|
4530
|
+
startedAt: run.startedAt,
|
|
4531
|
+
...run.executionId === void 0 ? {} : { executionId: run.executionId },
|
|
4532
|
+
...run.phase === "succeeded" || run.errorCode === void 0 ? {} : {
|
|
4533
|
+
errorCode: run.errorCode,
|
|
4534
|
+
retryHint: retryHintFor(run.errorCode)
|
|
4535
|
+
}
|
|
3876
4536
|
}, "ssh");
|
|
3877
4537
|
} catch (error) {
|
|
3878
4538
|
this.log(`the board refused the verdict of run ${run.runId}`, error);
|
|
@@ -4438,66 +5098,389 @@ function targetFromArgs(args) {
|
|
|
4438
5098
|
workspace
|
|
4439
5099
|
};
|
|
4440
5100
|
}
|
|
4441
|
-
/** The target
|
|
4442
|
-
|
|
5101
|
+
/** The target parameters every binding entry shares. */
|
|
5102
|
+
const TARGET_PARAMETERS = {
|
|
5103
|
+
host: {
|
|
5104
|
+
type: "string",
|
|
5105
|
+
description: "dsh-ssh host alias the card addresses (read the available aliases with action \"read\")."
|
|
5106
|
+
},
|
|
5107
|
+
mode: {
|
|
5108
|
+
type: "string",
|
|
5109
|
+
enum: ["direct", "proxy"],
|
|
5110
|
+
description: "direct (default): a headless agent runs on the host, no local session, best for self-contained jobs; proxy: a local session drives the host through ssh_* tools, best when the work needs local context or tools."
|
|
5111
|
+
},
|
|
5112
|
+
agent: {
|
|
5113
|
+
type: "string",
|
|
5114
|
+
description: `Agent CLI the remote run starts: ${SSH_AGENT_KINDS.join(", ")} (default dsh; custom needs agentCommand). Its program must exist on the host; any other name is refused with agent-missing.`
|
|
5115
|
+
},
|
|
5116
|
+
workspaceKind: {
|
|
5117
|
+
type: "string",
|
|
5118
|
+
enum: ["in-place", "git"],
|
|
5119
|
+
description: "in-place (default): work directly inside the existing remote directory workspacePath, nothing is copied or cleaned up; git: a per-run worktree on its own branch dsh-task/<runId>, from repositoryUrl or the local repository workspaceId."
|
|
5120
|
+
},
|
|
5121
|
+
workspacePath: {
|
|
5122
|
+
type: "string",
|
|
5123
|
+
description: "Absolute remote directory of an in-place target. It must exist and be writable."
|
|
5124
|
+
},
|
|
5125
|
+
repositoryUrl: {
|
|
5126
|
+
type: "string",
|
|
5127
|
+
description: "Clone URL a git target prepares its worktree from, when the host can reach it."
|
|
5128
|
+
},
|
|
5129
|
+
repositoryBase: {
|
|
5130
|
+
type: "string",
|
|
5131
|
+
description: "Base branch that worktree starts from; the remote HEAD when absent."
|
|
5132
|
+
},
|
|
5133
|
+
workspaceId: {
|
|
5134
|
+
type: "string",
|
|
5135
|
+
description: "Local workspace id a git target runs from, when its repository is not reachable from the host."
|
|
5136
|
+
},
|
|
5137
|
+
agentCommand: {
|
|
5138
|
+
type: "string",
|
|
5139
|
+
description: "Start command template of a custom agent; must reference {prompt_file}."
|
|
5140
|
+
},
|
|
5141
|
+
agentResumeCommand: {
|
|
5142
|
+
type: "string",
|
|
5143
|
+
description: "Resume command template of a custom agent; without one a follow-up runs fresh."
|
|
5144
|
+
},
|
|
5145
|
+
preflight: {
|
|
5146
|
+
type: "boolean",
|
|
5147
|
+
description: "Check the host, the agent program and the directory before binding (default true)."
|
|
5148
|
+
}
|
|
5149
|
+
};
|
|
5150
|
+
/** Read a boolean argument; undefined when absent. */
|
|
5151
|
+
function flag(value) {
|
|
5152
|
+
return typeof value === "boolean" ? value : void 0;
|
|
5153
|
+
}
|
|
5154
|
+
/**
|
|
5155
|
+
* Parse the flat target arguments, mapping parser issues onto the stable codes
|
|
5156
|
+
* the caller can act on: a bad host alias or agent name is a host/agent refusal,
|
|
5157
|
+
* anything else stays `invalid-target`.
|
|
5158
|
+
*/
|
|
5159
|
+
function parseTarget(args) {
|
|
5160
|
+
const parsed = parseSshTarget(targetFromArgs(args));
|
|
5161
|
+
if (parsed.ok) return {
|
|
5162
|
+
ok: true,
|
|
5163
|
+
target: parsed.value
|
|
5164
|
+
};
|
|
5165
|
+
const first = parsed.errors[0];
|
|
5166
|
+
const issues = parsed.errors.map((issue) => ({
|
|
5167
|
+
path: issue.path,
|
|
5168
|
+
message: issue.message
|
|
5169
|
+
}));
|
|
5170
|
+
if (first !== void 0 && first.path === "host") return {
|
|
5171
|
+
ok: false,
|
|
5172
|
+
reply: json({
|
|
5173
|
+
ok: false,
|
|
5174
|
+
code: "host-unreachable",
|
|
5175
|
+
message: `host ${JSON.stringify(text(args.host) ?? "")} is not a valid dsh-ssh alias. Read the configured aliases with task_board_ssh {action:"read"} and pass one of them.`,
|
|
5176
|
+
issues
|
|
5177
|
+
})
|
|
5178
|
+
};
|
|
5179
|
+
if (first !== void 0 && first.path.startsWith("agent") && !SSH_AGENT_KINDS.includes(String(args.agent ?? "dsh"))) return {
|
|
5180
|
+
ok: false,
|
|
5181
|
+
reply: json({
|
|
5182
|
+
ok: false,
|
|
5183
|
+
code: "agent-missing",
|
|
5184
|
+
message: `agent ${JSON.stringify(args.agent)} is not supported. Use one of: ${SSH_AGENT_KINDS.join(", ")}.`,
|
|
5185
|
+
issues
|
|
5186
|
+
})
|
|
5187
|
+
};
|
|
5188
|
+
return {
|
|
5189
|
+
ok: false,
|
|
5190
|
+
reply: json({
|
|
5191
|
+
ok: false,
|
|
5192
|
+
code: "invalid-target",
|
|
5193
|
+
message: "the target is malformed; issues lists each field.",
|
|
5194
|
+
issues
|
|
5195
|
+
})
|
|
5196
|
+
};
|
|
5197
|
+
}
|
|
5198
|
+
/** Run the preflight and answer its refusal as a tool reply, or undefined when the target is usable. */
|
|
5199
|
+
async function preflightReply(engine, target, args) {
|
|
5200
|
+
if (flag(args.preflight) === false) return void 0;
|
|
5201
|
+
const failure = await engine.preflight(target);
|
|
5202
|
+
return failure === void 0 ? void 0 : json({
|
|
5203
|
+
ok: false,
|
|
5204
|
+
code: failure.code,
|
|
5205
|
+
message: failure.message,
|
|
5206
|
+
hint: failure.hint
|
|
5207
|
+
});
|
|
5208
|
+
}
|
|
5209
|
+
/** Bind a target to an existing card, after parsing and preflight. */
|
|
5210
|
+
async function bindResult(engine, taskId, args) {
|
|
5211
|
+
const parsed = parseTarget(args);
|
|
5212
|
+
if (!parsed.ok) return parsed.reply;
|
|
5213
|
+
const refusal = await preflightReply(engine, parsed.target, args);
|
|
5214
|
+
if (refusal !== void 0) return refusal;
|
|
5215
|
+
const reply = engine.setTarget(taskId, parsed.target);
|
|
5216
|
+
if (!reply.ok) return refused(reply.code, reply.error);
|
|
5217
|
+
return json({
|
|
5218
|
+
ok: true,
|
|
5219
|
+
target: parsed.target,
|
|
5220
|
+
preflight: flag(args.preflight) === false ? "skipped" : "passed",
|
|
5221
|
+
hosts: hostViews(engine)
|
|
5222
|
+
});
|
|
5223
|
+
}
|
|
5224
|
+
/** One run in the uniform shape, optionally blocking until it settles. */
|
|
5225
|
+
async function statusResult(engine, taskId, args) {
|
|
5226
|
+
const waited = args.wait === true ? await engine.waitStatus(taskId, count(args.timeoutMs)) : void 0;
|
|
5227
|
+
const view = waited?.view ?? engine.statusView(taskId);
|
|
5228
|
+
const running = !view.settled && view.phase !== "none";
|
|
5229
|
+
const activity = running && flag(args.activity) !== false ? await engine.activityOf(taskId) : void 0;
|
|
5230
|
+
return json({
|
|
5231
|
+
ok: true,
|
|
5232
|
+
...view,
|
|
5233
|
+
...waited === void 0 ? {} : { timedOut: waited.timedOut },
|
|
5234
|
+
...activity === void 0 ? {} : { lastActivity: activity },
|
|
5235
|
+
...view.settled ? { next: "The run settled; the verdict is on the card (task_board_get) and the log is still readable with action \"log\"." } : running ? { next: "Still running: call status again with wait:true, or read progress with action \"log\"." } : {}
|
|
5236
|
+
});
|
|
5237
|
+
}
|
|
5238
|
+
/** One filtered page of the log, with its cost stated first. */
|
|
5239
|
+
async function logResult(engine, taskId, args) {
|
|
5240
|
+
const runId = text(args.runId);
|
|
5241
|
+
const tail = count(args.tail);
|
|
5242
|
+
const since = count(args.since);
|
|
5243
|
+
const maxBytes = count(args.maxBytes);
|
|
5244
|
+
const page = await engine.queryLog(taskId, {
|
|
5245
|
+
...runId === void 0 ? {} : { runId },
|
|
5246
|
+
...tail === void 0 ? {} : { tail },
|
|
5247
|
+
...since === void 0 ? {} : { since },
|
|
5248
|
+
...maxBytes === void 0 ? {} : { maxBytes },
|
|
5249
|
+
...args.raw === true ? { raw: true } : {},
|
|
5250
|
+
...args.statsOnly === true ? { statsOnly: true } : {}
|
|
5251
|
+
});
|
|
5252
|
+
if (!page.ok) return json({
|
|
5253
|
+
ok: false,
|
|
5254
|
+
code: page.code,
|
|
5255
|
+
message: page.error
|
|
5256
|
+
});
|
|
5257
|
+
return json({
|
|
5258
|
+
ok: true,
|
|
5259
|
+
runId: page.runId,
|
|
5260
|
+
filtered: page.filtered,
|
|
5261
|
+
stats: {
|
|
5262
|
+
rawBytes: page.stats.rawBytes,
|
|
5263
|
+
filteredLines: page.stats.lines,
|
|
5264
|
+
filteredBytes: page.stats.bytes
|
|
5265
|
+
},
|
|
5266
|
+
from: page.from,
|
|
5267
|
+
lines: page.lines,
|
|
5268
|
+
nextSince: page.nextSince,
|
|
5269
|
+
more: page.more,
|
|
5270
|
+
text: page.text
|
|
5271
|
+
});
|
|
5272
|
+
}
|
|
5273
|
+
/** Queue one instruction for the card's remote session. */
|
|
5274
|
+
async function followUpResult(engine, args) {
|
|
5275
|
+
const taskId = text(args.taskId);
|
|
5276
|
+
const rawText = typeof args.text === "string" ? args.text : "";
|
|
5277
|
+
const instruction = rawText.trim();
|
|
5278
|
+
if (taskId === void 0) return refused("task-required", "taskId is required");
|
|
5279
|
+
if (instruction === "") return refused("text-required", "text must be a non-blank instruction");
|
|
5280
|
+
if (rawText.length > 4e3) return refused("text-too-long", `text must be at most ${TASK_BOARD_MESSAGE_MAX_LENGTH} characters`);
|
|
5281
|
+
const rawKind = args.kind;
|
|
5282
|
+
if (rawKind !== void 0 && rawKind !== "follow-up" && rawKind !== "rework") return refused("invalid-kind", "kind must be \"follow-up\" or \"rework\"");
|
|
5283
|
+
const kind = rawKind ?? "follow-up";
|
|
5284
|
+
try {
|
|
5285
|
+
const reply = await engine.instruct(taskId, instruction, kind);
|
|
5286
|
+
if (!reply.ok) return refused(reply.code, reply.error);
|
|
5287
|
+
return json({
|
|
5288
|
+
ok: true,
|
|
5289
|
+
taskId: reply.taskId,
|
|
5290
|
+
...reply.runId === void 0 ? {} : { runId: reply.runId },
|
|
5291
|
+
...reply.phase === void 0 ? {} : { phase: reply.phase },
|
|
5292
|
+
message: reply.message ?? ""
|
|
5293
|
+
});
|
|
5294
|
+
} catch (error) {
|
|
5295
|
+
return refused("follow-up-failed", messageOf$1(error));
|
|
5296
|
+
}
|
|
5297
|
+
}
|
|
5298
|
+
/** The run handle plus, when asked, the settled status: what one `run` answers. */
|
|
5299
|
+
async function runResult(engine, taskId, args) {
|
|
5300
|
+
const reply = await engine.runCard(taskId);
|
|
5301
|
+
if (!reply.ok) return refused(reply.code, reply.error);
|
|
5302
|
+
const handle = engine.describeRun(taskId);
|
|
5303
|
+
const status = args.wait === true ? await statusResult(engine, taskId, args) : void 0;
|
|
5304
|
+
return json({
|
|
5305
|
+
ok: true,
|
|
5306
|
+
taskId,
|
|
5307
|
+
...handle,
|
|
5308
|
+
...status === void 0 ? {} : { status }
|
|
5309
|
+
});
|
|
5310
|
+
}
|
|
5311
|
+
/** The one surface: every action an agent needs against a remote card. */
|
|
5312
|
+
function buildUnifiedTool(engine) {
|
|
4443
5313
|
return defineTool({
|
|
4444
|
-
name: "
|
|
4445
|
-
description:
|
|
5314
|
+
name: "task_board_ssh",
|
|
5315
|
+
description: [
|
|
5316
|
+
"Run a task board card on a remote host over SSH, end to end, with the fewest calls: task_board_ssh {action:\"create\", title, prompt, host, workspacePath, run:true, wait:true} creates the card WITH its target, checks the host/agent/directory first, starts the run and blocks until it settles - one call.",
|
|
5317
|
+
"Actions: create (new card bound to a target; run:true starts it, wait:true blocks for the verdict), bind (set or replace the target of an existing card), read (current target plus the host aliases), run (start a bound direct card and get its handle: executionId, runId, logPath, target, estimatedDurationMs), status (one uniform shape whether running or settled: phase, exitCode, result, summary, error{code,message,retryHint}, durationMs, remoteSessionId, lastActivityAt, plus lastActivity = the agent's last tool call while running; wait:true with timeoutMs blocks until it settles), log (the run log with thinking_tokens/system noise removed; tail N lines or since a cursor, at most 64 KB per reply, stats.filteredLines/filteredBytes tell the cost first; statsOnly:true returns only the counts; raw:true skips the filter), followup (one more instruction for the remote session; kind rework asks again for wrong work).",
|
|
5318
|
+
"Choosing a target: direct mode is for self-contained jobs and keeps no local session; proxy mode runs a local session that drives the host and fits work needing local context. in-place edits an existing remote directory; git makes a per-run worktree on branch dsh-task/<runId>. Agents: dsh, claude, codex, custom.",
|
|
5319
|
+
"A succeeded run records its conclusion as the execution summary; error carries failures only. Stable refusal codes: host-unreachable (alias unknown to dsh-ssh or the host did not answer: fix the alias or the dsh-ssh credentials), agent-missing (the agent name is not one of dsh/claude/codex/custom, or its program is not on the host PATH), path-missing (an in-place directory does not exist; it is never created), permission-required (the directory exists but the ssh user cannot write it, or a human must confirm in the board UI), run-active (the card already has a run in flight: wait for it or cancel it), invalid-target (the other target fields are malformed; issues says which)."
|
|
5320
|
+
].join(" "),
|
|
4446
5321
|
parameters: {
|
|
4447
5322
|
action: {
|
|
4448
5323
|
type: "string",
|
|
4449
5324
|
required: true,
|
|
4450
|
-
enum: [
|
|
4451
|
-
|
|
5325
|
+
enum: [
|
|
5326
|
+
"create",
|
|
5327
|
+
"bind",
|
|
5328
|
+
"read",
|
|
5329
|
+
"run",
|
|
5330
|
+
"status",
|
|
5331
|
+
"log",
|
|
5332
|
+
"followup"
|
|
5333
|
+
],
|
|
5334
|
+
description: "What to do; see the tool description."
|
|
4452
5335
|
},
|
|
4453
5336
|
taskId: {
|
|
4454
5337
|
type: "string",
|
|
4455
|
-
|
|
4456
|
-
description: "Card to read or retarget."
|
|
5338
|
+
description: "Card to act on. Required by every action except create."
|
|
4457
5339
|
},
|
|
4458
|
-
|
|
5340
|
+
title: {
|
|
4459
5341
|
type: "string",
|
|
4460
|
-
|
|
4461
|
-
description: "direct starts a headless agent on the host and keeps no local session; proxy runs a local session told to drive the host through the ssh_* tools. Defaults to direct."
|
|
5342
|
+
description: "create: card title (one line)."
|
|
4462
5343
|
},
|
|
4463
|
-
|
|
5344
|
+
prompt: {
|
|
4464
5345
|
type: "string",
|
|
4465
|
-
description: "
|
|
5346
|
+
description: "create: the instruction the remote agent runs; the title when blank."
|
|
4466
5347
|
},
|
|
4467
|
-
|
|
5348
|
+
description: {
|
|
4468
5349
|
type: "string",
|
|
4469
|
-
|
|
4470
|
-
description: "Agent CLI the remote run starts (default dsh)."
|
|
5350
|
+
description: "create: longer human description."
|
|
4471
5351
|
},
|
|
4472
|
-
|
|
5352
|
+
parentId: {
|
|
4473
5353
|
type: "string",
|
|
4474
|
-
|
|
4475
|
-
description: "in-place works in an existing remote directory; git creates a per-run worktree. Defaults to in-place."
|
|
5354
|
+
description: "create: parent card id, to make a subtask."
|
|
4476
5355
|
},
|
|
4477
|
-
|
|
4478
|
-
type: "
|
|
4479
|
-
description: "
|
|
5356
|
+
run: {
|
|
5357
|
+
type: "boolean",
|
|
5358
|
+
description: "create: start the run right after creating the card."
|
|
5359
|
+
},
|
|
5360
|
+
wait: {
|
|
5361
|
+
type: "boolean",
|
|
5362
|
+
description: "create (with run), run and status: block until the run settles or timeoutMs passes."
|
|
5363
|
+
},
|
|
5364
|
+
timeoutMs: {
|
|
5365
|
+
type: "number",
|
|
5366
|
+
description: "Longest a wait blocks, in milliseconds (default 120000, at most 600000). A timeout is not a failure: the run keeps going, call status with wait again."
|
|
5367
|
+
},
|
|
5368
|
+
activity: {
|
|
5369
|
+
type: "boolean",
|
|
5370
|
+
description: "status: include lastActivity while running (default true)."
|
|
5371
|
+
},
|
|
5372
|
+
tail: {
|
|
5373
|
+
type: "number",
|
|
5374
|
+
description: "log: last N filtered lines (default 40)."
|
|
5375
|
+
},
|
|
5376
|
+
since: {
|
|
5377
|
+
type: "number",
|
|
5378
|
+
description: "log: first filtered line to return, the nextSince of an earlier reply."
|
|
5379
|
+
},
|
|
5380
|
+
raw: {
|
|
5381
|
+
type: "boolean",
|
|
5382
|
+
description: "log: skip the noise filter."
|
|
4480
5383
|
},
|
|
4481
|
-
|
|
5384
|
+
statsOnly: {
|
|
5385
|
+
type: "boolean",
|
|
5386
|
+
description: "log: return only the filtered line count and size."
|
|
5387
|
+
},
|
|
5388
|
+
maxBytes: {
|
|
5389
|
+
type: "number",
|
|
5390
|
+
description: "log: cap on the returned text in bytes (default 65536, at most 131072)."
|
|
5391
|
+
},
|
|
5392
|
+
runId: {
|
|
4482
5393
|
type: "string",
|
|
4483
|
-
description: "
|
|
5394
|
+
description: "log: a specific earlier run; the latest when absent."
|
|
4484
5395
|
},
|
|
4485
|
-
|
|
5396
|
+
text: {
|
|
4486
5397
|
type: "string",
|
|
4487
|
-
description: "
|
|
5398
|
+
description: "followup: the instruction itself."
|
|
4488
5399
|
},
|
|
4489
|
-
|
|
5400
|
+
kind: {
|
|
4490
5401
|
type: "string",
|
|
4491
|
-
|
|
5402
|
+
enum: ["follow-up", "rework"],
|
|
5403
|
+
description: "followup: follow-up adds work; rework asks again for work the previous run got wrong."
|
|
4492
5404
|
},
|
|
4493
|
-
|
|
5405
|
+
...TARGET_PARAMETERS
|
|
5406
|
+
},
|
|
5407
|
+
output: {
|
|
5408
|
+
schema: { type: "json" },
|
|
5409
|
+
render: renderJson
|
|
5410
|
+
},
|
|
5411
|
+
async execute(rawArgs) {
|
|
5412
|
+
const args = rawArgs;
|
|
5413
|
+
const action = text(args.action);
|
|
5414
|
+
const taskId = text(args.taskId);
|
|
5415
|
+
if (action === "create") {
|
|
5416
|
+
const prompt = text(args.prompt) ?? text(args.title);
|
|
5417
|
+
const title = text(args.title) ?? (prompt === void 0 ? void 0 : prompt.split("\n")[0]?.slice(0, 80));
|
|
5418
|
+
if (title === void 0 || prompt === void 0) return refused("title-required", "create needs a title or a prompt");
|
|
5419
|
+
const parsed = parseTarget(args);
|
|
5420
|
+
if (!parsed.ok) return parsed.reply;
|
|
5421
|
+
const target = parsed.target;
|
|
5422
|
+
if (flag(args.preflight) !== false) {
|
|
5423
|
+
const refusal = await preflightReply(engine, target, args);
|
|
5424
|
+
if (refusal !== void 0) return refusal;
|
|
5425
|
+
}
|
|
5426
|
+
const created = await engine.createBound({
|
|
5427
|
+
title,
|
|
5428
|
+
prompt,
|
|
5429
|
+
...text(args.description) === void 0 ? {} : { description: text(args.description) },
|
|
5430
|
+
...text(args.parentId) === void 0 ? {} : { parentId: text(args.parentId) }
|
|
5431
|
+
}, target, { preflight: false });
|
|
5432
|
+
if (!created.ok) return refused(created.code, created.error);
|
|
5433
|
+
if (args.run !== true) return json({
|
|
5434
|
+
ok: true,
|
|
5435
|
+
taskId: created.taskId,
|
|
5436
|
+
target,
|
|
5437
|
+
next: "Start it with task_board_ssh {action:\"run\"} or task_board_run."
|
|
5438
|
+
});
|
|
5439
|
+
return json({
|
|
5440
|
+
created: true,
|
|
5441
|
+
...await runResult(engine, created.taskId, args)
|
|
5442
|
+
});
|
|
5443
|
+
}
|
|
5444
|
+
if (action === "read" && taskId === void 0) return json({
|
|
5445
|
+
ok: true,
|
|
5446
|
+
target: null,
|
|
5447
|
+
hosts: hostViews(engine)
|
|
5448
|
+
});
|
|
5449
|
+
if (taskId === void 0) return refused("task-required", "taskId is required");
|
|
5450
|
+
switch (action) {
|
|
5451
|
+
case "read": return json({
|
|
5452
|
+
ok: true,
|
|
5453
|
+
target: engine.targetOf(taskId) ?? null,
|
|
5454
|
+
hosts: hostViews(engine)
|
|
5455
|
+
});
|
|
5456
|
+
case "bind": return await bindResult(engine, taskId, args);
|
|
5457
|
+
case "run": return await runResult(engine, taskId, args);
|
|
5458
|
+
case "status": return await statusResult(engine, taskId, args);
|
|
5459
|
+
case "log": return await logResult(engine, taskId, args);
|
|
5460
|
+
case "followup": return await followUpResult(engine, args);
|
|
5461
|
+
default: return refused("unknown-action", "action must be create, bind, read, run, status, log or followup");
|
|
5462
|
+
}
|
|
5463
|
+
}
|
|
5464
|
+
});
|
|
5465
|
+
}
|
|
5466
|
+
/** The target tool (compatibility): read or pin where one card runs. */
|
|
5467
|
+
function buildTargetTool(engine) {
|
|
5468
|
+
return defineTool({
|
|
5469
|
+
name: "task_board_ssh_target",
|
|
5470
|
+
description: "Compatibility entry of task_board_ssh (actions read and bind). Read or pin the SSH execution target of one task board card; pinning now checks the host, the agent program and the directory first and refuses with a stable code before anything is saved. direct mode starts a headless agent on the host and keeps no local session; proxy mode runs a local session that drives the host. Stable refusal codes: host-unreachable (alias unknown to dsh-ssh or the host did not answer: fix the alias or the dsh-ssh credentials), agent-missing (the agent name is not one of dsh/claude/codex/custom, or its program is not on the host PATH), path-missing (an in-place directory does not exist; it is never created), permission-required (the directory exists but the ssh user cannot write it, or a human must confirm in the board UI), run-active (the card already has a run in flight: wait for it or cancel it), invalid-target (the other target fields are malformed; issues says which).",
|
|
5471
|
+
parameters: {
|
|
5472
|
+
action: {
|
|
4494
5473
|
type: "string",
|
|
4495
|
-
|
|
5474
|
+
required: true,
|
|
5475
|
+
enum: ["read", "set"],
|
|
5476
|
+
description: "read reports the current pin and the hosts available; set stores a new pin."
|
|
4496
5477
|
},
|
|
4497
|
-
|
|
5478
|
+
taskId: {
|
|
4498
5479
|
type: "string",
|
|
4499
|
-
|
|
4500
|
-
|
|
5480
|
+
required: true,
|
|
5481
|
+
description: "Card to read or retarget."
|
|
5482
|
+
},
|
|
5483
|
+
...TARGET_PARAMETERS
|
|
4501
5484
|
},
|
|
4502
5485
|
output: {
|
|
4503
5486
|
schema: { type: "json" },
|
|
@@ -4513,63 +5496,77 @@ function buildTargetTool(engine) {
|
|
|
4513
5496
|
hosts: hostViews(engine)
|
|
4514
5497
|
});
|
|
4515
5498
|
if (action !== "set") return refused("unknown-action", "action must be read or set");
|
|
4516
|
-
|
|
4517
|
-
if (!parsed.ok) return json({
|
|
4518
|
-
ok: false,
|
|
4519
|
-
code: "invalid-target",
|
|
4520
|
-
issues: parsed.errors.map((issue) => ({
|
|
4521
|
-
path: issue.path,
|
|
4522
|
-
message: issue.message
|
|
4523
|
-
}))
|
|
4524
|
-
});
|
|
4525
|
-
const reply = engine.setTarget(taskId, parsed.value);
|
|
4526
|
-
if (!reply.ok) return refused(reply.code, reply.error);
|
|
4527
|
-
return json({
|
|
4528
|
-
ok: true,
|
|
4529
|
-
target: parsed.value,
|
|
4530
|
-
hosts: hostViews(engine)
|
|
4531
|
-
});
|
|
5499
|
+
return await bindResult(engine, taskId, args);
|
|
4532
5500
|
}
|
|
4533
5501
|
});
|
|
4534
5502
|
}
|
|
4535
|
-
/** The status tool: one card's remote run, and optionally a page of its log. */
|
|
5503
|
+
/** The status tool (compatibility): one card's remote run, and optionally a page of its log. */
|
|
4536
5504
|
function buildStatusTool(engine) {
|
|
4537
5505
|
return defineTool({
|
|
4538
5506
|
name: "task_board_ssh_status",
|
|
4539
|
-
description: "Read the remote run state of one
|
|
5507
|
+
description: "Compatibility entry of task_board_ssh (actions status and log). Read the remote run state of one card. `state` is the uniform shape (phase, exitCode, result, summary, error, durationMs, remoteSessionId, lastActivityAt) for a running and a settled run alike; wait:true with timeoutMs blocks until it settles. `status` keeps the older shape with the run history. Pass logOffset/logLimit for one raw byte page of the log, or tail/since for the filtered log (at most 64 KB by default).",
|
|
4540
5508
|
parameters: {
|
|
4541
5509
|
taskId: {
|
|
4542
5510
|
type: "string",
|
|
4543
5511
|
required: true,
|
|
4544
5512
|
description: "Card whose remote run to inspect."
|
|
4545
5513
|
},
|
|
5514
|
+
wait: {
|
|
5515
|
+
type: "boolean",
|
|
5516
|
+
description: "Block until the run settles or timeoutMs passes."
|
|
5517
|
+
},
|
|
5518
|
+
timeoutMs: {
|
|
5519
|
+
type: "number",
|
|
5520
|
+
description: "Longest a wait blocks, in milliseconds (default 120000, at most 600000)."
|
|
5521
|
+
},
|
|
4546
5522
|
runId: {
|
|
4547
5523
|
type: "string",
|
|
4548
5524
|
description: "One specific run to read the log of; the active run when absent."
|
|
4549
5525
|
},
|
|
5526
|
+
tail: {
|
|
5527
|
+
type: "number",
|
|
5528
|
+
description: "Filtered log: last N lines."
|
|
5529
|
+
},
|
|
5530
|
+
since: {
|
|
5531
|
+
type: "number",
|
|
5532
|
+
description: "Filtered log: first line to return (nextSince of an earlier reply)."
|
|
5533
|
+
},
|
|
5534
|
+
raw: {
|
|
5535
|
+
type: "boolean",
|
|
5536
|
+
description: "Filtered log: skip the noise filter."
|
|
5537
|
+
},
|
|
4550
5538
|
logOffset: {
|
|
4551
5539
|
type: "number",
|
|
4552
|
-
description: "
|
|
5540
|
+
description: "Raw byte offset the log page starts at (default 0)."
|
|
4553
5541
|
},
|
|
4554
5542
|
logLimit: {
|
|
4555
5543
|
type: "number",
|
|
4556
|
-
description: "Largest page to return, in bytes (default 65536, at most 131072)."
|
|
5544
|
+
description: "Largest raw page to return, in bytes (default 65536, at most 131072)."
|
|
4557
5545
|
}
|
|
4558
5546
|
},
|
|
4559
5547
|
output: {
|
|
4560
5548
|
schema: { type: "json" },
|
|
4561
5549
|
render: renderJson
|
|
4562
5550
|
},
|
|
4563
|
-
async execute(
|
|
5551
|
+
async execute(rawArgs) {
|
|
5552
|
+
const args = rawArgs;
|
|
4564
5553
|
const taskId = text(args.taskId);
|
|
4565
5554
|
if (taskId === void 0) return refused("task-required", "taskId is required");
|
|
5555
|
+
const state = await statusResult(engine, taskId, args);
|
|
4566
5556
|
const status = engine.status(taskId);
|
|
4567
5557
|
const runId = text(args.runId);
|
|
4568
5558
|
const offset = count(args.logOffset);
|
|
4569
5559
|
const limit = count(args.logLimit);
|
|
5560
|
+
if (count(args.tail) !== void 0 || count(args.since) !== void 0) return json({
|
|
5561
|
+
ok: true,
|
|
5562
|
+
status,
|
|
5563
|
+
state,
|
|
5564
|
+
log: await logResult(engine, taskId, args)
|
|
5565
|
+
});
|
|
4570
5566
|
if (runId === void 0 && offset === void 0 && limit === void 0) return json({
|
|
4571
5567
|
ok: true,
|
|
4572
|
-
status
|
|
5568
|
+
status,
|
|
5569
|
+
state
|
|
4573
5570
|
});
|
|
4574
5571
|
const page = await engine.readLog(taskId, {
|
|
4575
5572
|
...runId === void 0 ? {} : { runId },
|
|
@@ -4579,12 +5576,14 @@ function buildStatusTool(engine) {
|
|
|
4579
5576
|
if (!page.ok) return json({
|
|
4580
5577
|
ok: false,
|
|
4581
5578
|
status,
|
|
5579
|
+
state,
|
|
4582
5580
|
code: page.code,
|
|
4583
5581
|
message: page.error
|
|
4584
5582
|
});
|
|
4585
5583
|
return json({
|
|
4586
5584
|
ok: true,
|
|
4587
5585
|
status,
|
|
5586
|
+
state,
|
|
4588
5587
|
log: {
|
|
4589
5588
|
runId: page.runId,
|
|
4590
5589
|
offset: page.offset,
|
|
@@ -4597,11 +5596,11 @@ function buildStatusTool(engine) {
|
|
|
4597
5596
|
}
|
|
4598
5597
|
});
|
|
4599
5598
|
}
|
|
4600
|
-
/** The follow-up tool: one more instruction for the card's remote session. */
|
|
5599
|
+
/** The follow-up tool (compatibility): one more instruction for the card's remote session. */
|
|
4601
5600
|
function buildFollowUpTool(engine) {
|
|
4602
5601
|
return defineTool({
|
|
4603
5602
|
name: "task_board_ssh_follow_up",
|
|
4604
|
-
description: "Send one more instruction to the remote agent session of a task board card. On a card whose run is still going the instruction waits for that run to finish and then continues the same remote session; on a settled card it re-enters the card run with the earlier session resumed. An agent that cannot resume degrades to a fresh run that carries the previous summary, which the execution record says.",
|
|
5603
|
+
description: "Compatibility entry of task_board_ssh (action followup). Send one more instruction to the remote agent session of a task board card. On a card whose run is still going the instruction waits for that run to finish and then continues the same remote session; on a settled card it re-enters the card run with the earlier session resumed. An agent that cannot resume degrades to a fresh run that carries the previous summary, which the execution record says.",
|
|
4605
5604
|
parameters: {
|
|
4606
5605
|
taskId: {
|
|
4607
5606
|
type: "string",
|
|
@@ -4624,28 +5623,7 @@ function buildFollowUpTool(engine) {
|
|
|
4624
5623
|
render: renderJson
|
|
4625
5624
|
},
|
|
4626
5625
|
async execute(args) {
|
|
4627
|
-
|
|
4628
|
-
const rawText = typeof args.text === "string" ? args.text : "";
|
|
4629
|
-
const instruction = rawText.trim();
|
|
4630
|
-
if (taskId === void 0) return refused("task-required", "taskId is required");
|
|
4631
|
-
if (instruction === "") return refused("text-required", "text must be a non-blank instruction");
|
|
4632
|
-
if (rawText.length > 4e3) return refused("text-too-long", `text must be at most ${TASK_BOARD_MESSAGE_MAX_LENGTH} characters`);
|
|
4633
|
-
const rawKind = args.kind;
|
|
4634
|
-
if (rawKind !== void 0 && rawKind !== "follow-up" && rawKind !== "rework") return refused("invalid-kind", "kind must be \"follow-up\" or \"rework\"");
|
|
4635
|
-
const kind = rawKind ?? "follow-up";
|
|
4636
|
-
try {
|
|
4637
|
-
const reply = await engine.instruct(taskId, instruction, kind);
|
|
4638
|
-
if (!reply.ok) return refused(reply.code, reply.error);
|
|
4639
|
-
return json({
|
|
4640
|
-
ok: true,
|
|
4641
|
-
taskId: reply.taskId,
|
|
4642
|
-
...reply.runId === void 0 ? {} : { runId: reply.runId },
|
|
4643
|
-
...reply.phase === void 0 ? {} : { phase: reply.phase },
|
|
4644
|
-
message: reply.message ?? ""
|
|
4645
|
-
});
|
|
4646
|
-
} catch (error) {
|
|
4647
|
-
return refused("follow-up-failed", messageOf$1(error));
|
|
4648
|
-
}
|
|
5626
|
+
return await followUpResult(engine, args);
|
|
4649
5627
|
}
|
|
4650
5628
|
});
|
|
4651
5629
|
}
|
|
@@ -4656,6 +5634,7 @@ function buildFollowUpTool(engine) {
|
|
|
4656
5634
|
*/
|
|
4657
5635
|
function buildSshTools(engine) {
|
|
4658
5636
|
return [
|
|
5637
|
+
buildUnifiedTool(engine),
|
|
4659
5638
|
buildTargetTool(engine),
|
|
4660
5639
|
buildStatusTool(engine),
|
|
4661
5640
|
buildFollowUpTool(engine)
|
|
@@ -4897,6 +5876,7 @@ function createSshExtension(options) {
|
|
|
4897
5876
|
...options.localRepository === void 0 ? {} : { localRepository: options.localRepository },
|
|
4898
5877
|
...options.now === void 0 ? {} : { now: options.now },
|
|
4899
5878
|
...options.uuid === void 0 ? {} : { uuid: options.uuid },
|
|
5879
|
+
...options.sleep === void 0 ? {} : { sleep: options.sleep },
|
|
4900
5880
|
...options.pollIntervalMs === void 0 ? {} : { pollIntervalMs: options.pollIntervalMs },
|
|
4901
5881
|
...options.commandTimeoutMs === void 0 ? {} : { commandTimeoutMs: options.commandTimeoutMs },
|
|
4902
5882
|
log
|
|
@@ -4925,6 +5905,8 @@ function createSshExtension(options) {
|
|
|
4925
5905
|
engine?.stop();
|
|
4926
5906
|
engine = void 0;
|
|
4927
5907
|
},
|
|
5908
|
+
describeTask: (task) => engine?.describeTask(task),
|
|
5909
|
+
describeRun: (taskId) => engine?.describeRun(taskId),
|
|
4928
5910
|
async handleAction(request) {
|
|
4929
5911
|
return await routeAction(request, engine, options.settingsWriter);
|
|
4930
5912
|
}
|