pi-subagents 0.83.1 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-5YIITCPD.js → chunk-3UZ5FVVJ.js} +322 -110
- package/bundle/{chunk-F4ASL6OV.js → chunk-7MAE3DJV.js} +1 -1
- package/bundle/{chunk-YXFJVCOL.js → chunk-CS4O36CZ.js} +11 -156
- package/bundle/{chunk-AHIFYGR3.js → chunk-DV2NCNPR.js} +22 -11
- package/bundle/{chunk-G2Z6ZH26.js → chunk-GCSLVFCX.js} +1 -1
- package/bundle/{chunk-2S4K53MV.js → chunk-H2NLFTC5.js} +1 -1
- package/bundle/{chunk-MABL3FUM.js → chunk-HFTBF7SG.js} +2 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-UFL7IYCW.js → chunk-IQIWF2VX.js} +190 -1177
- package/bundle/{chunk-NPIYWVOD.js → chunk-JNXT3MPI.js} +15 -6
- package/bundle/{chunk-C7JMPU5F.js → chunk-JO67XSKD.js} +59 -27
- package/bundle/{chunk-UUP372DR.js → chunk-JWYG26RE.js} +223 -93
- package/bundle/{chunk-C5P5CHYK.js → chunk-KDMFBYFM.js} +1 -1
- package/bundle/{chunk-V2BZYLEP.js → chunk-KEY3UQMQ.js} +7 -2
- package/bundle/{chunk-VLFZIN6D.js → chunk-KZ34KQQH.js} +9 -6
- package/bundle/{chunk-ZVOAMTUQ.js → chunk-L2ENOFVZ.js} +76 -58
- package/bundle/{chunk-RNIZLSEA.js → chunk-LGMILZNE.js} +323 -18
- package/bundle/{chunk-UYK5MZWE.js → chunk-LTPH2DXH.js} +247 -153
- package/bundle/{chunk-2D52JFLF.js → chunk-N7B2KD74.js} +41 -117
- package/bundle/{chunk-IPGZMQXV.js → chunk-O7CPL6H4.js} +183 -28
- package/bundle/{chunk-D3JAFGMO.js → chunk-PHZP3KHB.js} +1 -1
- package/bundle/{chunk-2DHZTCOL.js → chunk-PVIVCDG2.js} +2 -2
- package/bundle/{chunk-LFDBD4PW.js → chunk-QO75KJBT.js} +2 -2
- package/bundle/{chunk-SSG7IEP5.js → chunk-RQAUNAWG.js} +2 -2
- package/bundle/{chunk-QP5ZWNIS.js → chunk-RV5OGHLO.js} +6 -3
- package/bundle/chunk-T5V5BRCL.js +1067 -0
- package/bundle/{chunk-LNRJCP2Y.js → chunk-UX4SCV5N.js} +337 -207
- package/bundle/{chunk-F5DBXJ2G.js → chunk-WOVMHDES.js} +234 -182
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +17 -2
- package/docs/configuration.md +2 -2
- package/docs/extension-api.md +16 -1
- package/docs/workflows.md +30 -2
- package/package.json +1 -1
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +8 -3
- package/src/extension/schemas.js +5 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +25 -11
- package/src/extension/tool-description.js +6 -0
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +8 -9
- package/src/runs/background/async-execution.js +77 -27
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +112 -39
- package/src/runs/background/async-retention.d.ts +1 -0
- package/src/runs/background/async-retention.js +22 -11
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -1
- package/src/runs/background/run-child-session.js +10 -2
- package/src/runs/background/run-status.js +4 -3
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +10 -6
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +3 -2
- package/src/runs/foreground/subagent-executor.js +112 -26
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +3 -1
- package/src/runs/shared/child-session.js +22 -2
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +11 -1
- package/src/runs/shared/model-resolution-diagnostic.js +25 -0
- package/src/runs/shared/model-resolution.d.ts +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +2 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +30 -2
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/types.d.ts +28 -11
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +81 -47
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +243 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +453 -176
|
@@ -1,89 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CODE_OWNED_EXTERNAL_CLI_ADAPTER_IDS,
|
|
3
|
+
REX_LOCAL_MACHINE,
|
|
3
4
|
getAgentDir,
|
|
4
|
-
getProjectConfigDir
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// src/runs/shared/rex-machine.ts
|
|
8
|
-
import { spawnSync } from "node:child_process";
|
|
9
|
-
import * as fs from "node:fs";
|
|
10
|
-
import * as os from "node:os";
|
|
11
|
-
import * as path from "node:path";
|
|
12
|
-
var REX_LOCAL_MACHINE = "local";
|
|
13
|
-
var REX_EXIT_GONE = 3;
|
|
14
|
-
var REX_EXIT_UNREACHABLE = 4;
|
|
15
|
-
function isRexLocalMachine(machine) {
|
|
16
|
-
return machine?.provider === "rex" && !("target" in machine);
|
|
17
|
-
}
|
|
18
|
-
var REX_BUNDLE_BIN = "Library/Application Support/com.superlogical.rex/RexServer/Versions/Current/Rex Server.app/Contents/MacOS/rex";
|
|
19
|
-
var REX_CALL_TIMEOUT_MS = 15e3;
|
|
20
|
-
var REX_MAX_OUTPUT = 1024 * 1024;
|
|
21
|
-
function rexGlobalArgs(server) {
|
|
22
|
-
return server ? ["--autostart=false", "-S", server] : ["--autostart=false"];
|
|
23
|
-
}
|
|
24
|
-
function executable(file) {
|
|
25
|
-
try {
|
|
26
|
-
fs.accessSync(file, fs.constants.X_OK);
|
|
27
|
-
return fs.statSync(file).isFile();
|
|
28
|
-
} catch {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function resolveRexBinary(env = process.env) {
|
|
33
|
-
const fromDir = env.REX_BIN_DIR ? [path.join(env.REX_BIN_DIR, "rex")] : [];
|
|
34
|
-
const fromPath = (env.PATH ?? "").split(path.delimiter).filter((dir) => path.isAbsolute(dir)).map((dir) => path.join(dir, "rex"));
|
|
35
|
-
const found = [...fromDir, ...fromPath, path.join(os.homedir(), REX_BUNDLE_BIN)].find(executable);
|
|
36
|
-
if (!found) throw new Error("The Rex CLI was not found: set REX_BIN_DIR, put rex on PATH, or install Rex.");
|
|
37
|
-
return found;
|
|
38
|
-
}
|
|
39
|
-
function rexCommandEnv(source = process.env) {
|
|
40
|
-
const { REX_SESSION: _session, REX_BLOCK: _block, REX_SERVER: _server, ...env } = source;
|
|
41
|
-
return env;
|
|
42
|
-
}
|
|
43
|
-
function sessionConfirmed(stdout, session) {
|
|
44
|
-
try {
|
|
45
|
-
const parsed = JSON.parse(stdout);
|
|
46
|
-
return parsed?.session_id === session;
|
|
47
|
-
} catch {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function resolveRexLocalPlacement(input) {
|
|
52
|
-
if (process.platform === "win32") throw new Error("Machine 'local' runs the child in a Rex pane, which is not supported on Windows.");
|
|
53
|
-
const env = input.env ?? process.env, session = env.REX_SESSION?.trim(), server = env.REX_SERVER?.trim();
|
|
54
|
-
if (!session) throw new Error("Machine 'local' opens the child in a new tab of this Rex session, but this Pi is not running inside Rex (REX_SESSION is not set).");
|
|
55
|
-
const result = spawnSync(resolveRexBinary(env), [...rexGlobalArgs(server), "session", "inspect", session, "--json"], { encoding: "utf8", env: rexCommandEnv(env), timeout: REX_CALL_TIMEOUT_MS, maxBuffer: REX_MAX_OUTPUT, windowsHide: true });
|
|
56
|
-
if (result.error) throw new Error(`Could not ask Rex about this session: ${result.error.message}`, { cause: result.error });
|
|
57
|
-
if (result.status === REX_EXIT_GONE) throw new Error(`Machine 'local' needs this Pi's Rex session, but the Rex server does not know session ${session}.`);
|
|
58
|
-
if (result.status === REX_EXIT_UNREACHABLE) throw new Error("Machine 'local' needs the Rex server, but it is unreachable.");
|
|
59
|
-
if (result.status !== 0) throw new Error(`rex session inspect exited with code ${result.status}: ${(result.stderr || result.stdout).trim().slice(0, 512)}`);
|
|
60
|
-
if (!sessionConfirmed(result.stdout, session)) throw new Error(`The Rex server did not confirm session ${session}.`);
|
|
61
|
-
const stepCwd = input.stepCwd?.trim();
|
|
62
|
-
const home = stepCwd === "~" || stepCwd?.startsWith("~/") ? path.join(os.homedir(), stepCwd.slice(1)) : void 0;
|
|
63
|
-
const requested = home ?? (stepCwd ? path.resolve(input.cwd, stepCwd) : input.cwd);
|
|
64
|
-
let cwd;
|
|
65
|
-
try {
|
|
66
|
-
cwd = fs.realpathSync(requested);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
throw new Error(`Machine 'local' cwd does not exist: ${requested}.`, { cause: error });
|
|
69
|
-
}
|
|
70
|
-
if (!fs.statSync(cwd).isDirectory()) throw new Error(`Machine 'local' cwd is not a directory: ${requested}.`);
|
|
71
|
-
const machine = { provider: "rex", id: REX_LOCAL_MACHINE, session, cwd };
|
|
72
|
-
if (server) machine.server = server;
|
|
73
|
-
return machine;
|
|
74
|
-
}
|
|
5
|
+
getProjectConfigDir,
|
|
6
|
+
resolveRexLocalPlacement
|
|
7
|
+
} from "./chunk-UX4SCV5N.js";
|
|
75
8
|
|
|
76
9
|
// src/runs/shared/herdr-machine.ts
|
|
77
|
-
import { spawnSync as
|
|
78
|
-
import * as
|
|
79
|
-
import * as
|
|
10
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
11
|
+
import * as fs2 from "node:fs";
|
|
12
|
+
import * as path2 from "node:path";
|
|
80
13
|
|
|
81
14
|
// src/runs/shared/herdr-connection.ts
|
|
82
|
-
import { spawn, spawnSync
|
|
83
|
-
import * as
|
|
15
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
16
|
+
import * as fs from "node:fs";
|
|
84
17
|
import * as net from "node:net";
|
|
85
|
-
import * as
|
|
86
|
-
import * as
|
|
18
|
+
import * as os from "node:os";
|
|
19
|
+
import * as path from "node:path";
|
|
87
20
|
var MAX_DISCOVERY_BYTES = 256 * 1024;
|
|
88
21
|
var MAX_RPC_BYTES = 4 * 1024 * 1024;
|
|
89
22
|
var SUBSCRIPTION_ACK_TIMEOUT_MS = 15e3;
|
|
@@ -132,13 +65,13 @@ function sshEnvCommand(session, command) {
|
|
|
132
65
|
return `/usr/bin/env -u HERDR_SOCKET_PATH -u HERDR_SESSION${assignment} ${remoteShellCommand(command)}`;
|
|
133
66
|
}
|
|
134
67
|
function runHerdrRemoteCommand(machine, command, options = {}) {
|
|
135
|
-
return
|
|
68
|
+
return spawnSync(options.sshBin ?? "ssh", [...herdrSshArgs(options.env), machine.target, command], { encoding: "utf8", env: hardenedSshEnv(options.env), timeout: options.timeout ?? 15e3, maxBuffer: options.maxBuffer ?? MAX_DISCOVERY_BYTES, windowsHide: true });
|
|
136
69
|
}
|
|
137
70
|
function runHerdrRemoteCommandAsync(machine, command, options = {}) {
|
|
138
71
|
return runBoundedCommand(options.sshBin ?? "ssh", [...herdrSshArgs(options.env), machine.target, command], { env: hardenedSshEnv(options.env), timeout: options.timeout, maxBuffer: options.maxBuffer });
|
|
139
72
|
}
|
|
140
73
|
function runBoundedCommand(file, args, options) {
|
|
141
|
-
return new Promise((
|
|
74
|
+
return new Promise((resolve2) => {
|
|
142
75
|
const child = spawn(file, args, { env: options.env, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
143
76
|
const stdout = [], stderr = [], maxBuffer = options.maxBuffer ?? MAX_DISCOVERY_BYTES;
|
|
144
77
|
let stdoutBytes = 0, stderrBytes = 0, error, settled = false, escalation;
|
|
@@ -147,7 +80,7 @@ function runBoundedCommand(file, args, options) {
|
|
|
147
80
|
settled = true;
|
|
148
81
|
clearTimeout(timer);
|
|
149
82
|
if (escalation) clearTimeout(escalation);
|
|
150
|
-
|
|
83
|
+
resolve2({ status, stdout: Buffer.concat(stdout).toString("utf8"), stderr: Buffer.concat(stderr).toString("utf8"), ...spawnError ? { error: spawnError } : {} });
|
|
151
84
|
};
|
|
152
85
|
const terminate = () => {
|
|
153
86
|
child.kill("SIGTERM");
|
|
@@ -183,7 +116,7 @@ function parseHerdrEndpoint(value, expectedSession) {
|
|
|
183
116
|
}
|
|
184
117
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("Remote Herdr endpoint discovery returned no endpoint.");
|
|
185
118
|
const p = parsed;
|
|
186
|
-
if (typeof p.socket !== "string" || !
|
|
119
|
+
if (typeof p.socket !== "string" || !path.posix.isAbsolute(p.socket) || typeof p.version !== "string" || typeof p.protocol !== "number") throw new Error("Remote Herdr endpoint discovery returned incomplete identity.");
|
|
187
120
|
const session = canonicalHerdrSession(typeof p.session === "string" ? p.session : null), expected = canonicalHerdrSession(expectedSession);
|
|
188
121
|
if (expected !== session) throw new Error(`Remote Herdr session identity mismatch: expected ${expected ?? "default"}, received ${session ?? "default"}.`);
|
|
189
122
|
if (p.running !== true || p.compatible !== true || p.endpoint_compatible === false) throw new Error("The selected remote Herdr session is stopped or incompatible.");
|
|
@@ -205,7 +138,7 @@ var SocketRpcClient = class {
|
|
|
205
138
|
this.#subscriptionAckTimeoutMs = subscriptionAckTimeoutMs;
|
|
206
139
|
}
|
|
207
140
|
call(method, params = {}, timeoutMs = 15e3) {
|
|
208
|
-
return new Promise((
|
|
141
|
+
return new Promise((resolve2, reject) => {
|
|
209
142
|
const socket = net.createConnection(this.#socketPath);
|
|
210
143
|
let bytes = 0;
|
|
211
144
|
let data = Buffer.alloc(0);
|
|
@@ -218,7 +151,7 @@ var SocketRpcClient = class {
|
|
|
218
151
|
finished = true;
|
|
219
152
|
clearTimeout(timer);
|
|
220
153
|
socket.destroy();
|
|
221
|
-
error ? reject(error) :
|
|
154
|
+
error ? reject(error) : resolve2(value);
|
|
222
155
|
};
|
|
223
156
|
socket.on("connect", () => socket.write(`${JSON.stringify({ id, method, params })}
|
|
224
157
|
`));
|
|
@@ -255,8 +188,8 @@ var SocketRpcClient = class {
|
|
|
255
188
|
const id = String(++this.#next);
|
|
256
189
|
let buffer = Buffer.alloc(0), bytes = 0, acknowledged = false, intentional = false, notified = false, settled = false;
|
|
257
190
|
let resolveAck, rejectAck;
|
|
258
|
-
const acknowledgement = new Promise((
|
|
259
|
-
resolveAck =
|
|
191
|
+
const acknowledgement = new Promise((resolve2, reject) => {
|
|
192
|
+
resolveAck = resolve2;
|
|
260
193
|
rejectAck = reject;
|
|
261
194
|
});
|
|
262
195
|
const failHandshake = (error) => {
|
|
@@ -343,19 +276,19 @@ async function waitForSocket(socketPath, child) {
|
|
|
343
276
|
for (let attempt = 0; attempt < 100; attempt++) {
|
|
344
277
|
if (child.exitCode !== null) throw new Error(`SSH StreamLocal forwarding exited with code ${child.exitCode}.`);
|
|
345
278
|
try {
|
|
346
|
-
const stat =
|
|
279
|
+
const stat = fs.lstatSync(socketPath);
|
|
347
280
|
if (stat.isSocket()) {
|
|
348
|
-
|
|
281
|
+
fs.chmodSync(socketPath, 384);
|
|
349
282
|
return;
|
|
350
283
|
}
|
|
351
284
|
} catch {
|
|
352
285
|
}
|
|
353
|
-
await new Promise((
|
|
286
|
+
await new Promise((resolve2) => setTimeout(resolve2, 25));
|
|
354
287
|
}
|
|
355
288
|
throw new Error("SSH StreamLocal forwarding did not create its local socket.");
|
|
356
289
|
}
|
|
357
290
|
async function terminateChild(child) {
|
|
358
|
-
const wait = (ms) => child.exitCode !== null || child.signalCode !== null ? Promise.resolve() : Promise.race([new Promise((
|
|
291
|
+
const wait = (ms) => child.exitCode !== null || child.signalCode !== null ? Promise.resolve() : Promise.race([new Promise((resolve2) => child.once("exit", () => resolve2())), new Promise((resolve2) => setTimeout(resolve2, ms))]);
|
|
359
292
|
if (child.exitCode === null && child.signalCode === null) child.kill("SIGTERM");
|
|
360
293
|
await wait(1e3);
|
|
361
294
|
if (child.exitCode === null && child.signalCode === null) {
|
|
@@ -364,19 +297,19 @@ async function terminateChild(child) {
|
|
|
364
297
|
}
|
|
365
298
|
}
|
|
366
299
|
function openSshSockets(machine, options) {
|
|
367
|
-
const dir =
|
|
368
|
-
|
|
300
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-subagents-herdr-"));
|
|
301
|
+
fs.chmodSync(dir, 448);
|
|
369
302
|
const children = /* @__PURE__ */ new Set();
|
|
370
303
|
const forward = async (remotePath, name) => {
|
|
371
|
-
if (!
|
|
372
|
-
const local =
|
|
373
|
-
const child = spawn(options.sshBin ?? "ssh", [...herdrSshArgs(options.env), "-
|
|
304
|
+
if (!path.posix.isAbsolute(remotePath)) throw new Error("Remote socket path must be absolute.");
|
|
305
|
+
const local = path.join(dir, `${name}.sock`);
|
|
306
|
+
const child = spawn(options.sshBin ?? "ssh", [...herdrSshArgs(options.env), "-o", "StreamLocalBindUnlink=yes", "-L", `${local}:${remotePath}`, machine.target, remoteShellCommand("exec cat >/dev/null")], { env: hardenedSshEnv(options.env), stdio: ["pipe", "ignore", "ignore"], windowsHide: true });
|
|
374
307
|
children.add(child);
|
|
375
308
|
const stop = async () => {
|
|
376
309
|
await terminateChild(child);
|
|
377
310
|
children.delete(child);
|
|
378
311
|
try {
|
|
379
|
-
|
|
312
|
+
fs.rmSync(local, { force: true });
|
|
380
313
|
} catch {
|
|
381
314
|
}
|
|
382
315
|
};
|
|
@@ -391,7 +324,7 @@ function openSshSockets(machine, options) {
|
|
|
391
324
|
return { forwardRemoteSocket: forward, close: async () => {
|
|
392
325
|
await Promise.all([...children].map(terminateChild));
|
|
393
326
|
children.clear();
|
|
394
|
-
|
|
327
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
395
328
|
} };
|
|
396
329
|
}
|
|
397
330
|
function sshMachineAccess(machine, options = {}) {
|
|
@@ -460,7 +393,7 @@ function parseMachineCatalog(json) {
|
|
|
460
393
|
});
|
|
461
394
|
}
|
|
462
395
|
function readHerdrMachineCatalog(env, herdrBin) {
|
|
463
|
-
const result =
|
|
396
|
+
const result = spawnSync2(herdrBin, ["machine", "list", "--json"], {
|
|
464
397
|
env,
|
|
465
398
|
encoding: "utf-8",
|
|
466
399
|
maxBuffer: MAX_HERDR_MACHINE_LIST_BYTES,
|
|
@@ -488,10 +421,10 @@ function selectMachine(catalog, requested) {
|
|
|
488
421
|
return machine;
|
|
489
422
|
}
|
|
490
423
|
function readJsonObject(filePath) {
|
|
491
|
-
if (!
|
|
424
|
+
if (!fs2.existsSync(filePath)) return {};
|
|
492
425
|
let parsed;
|
|
493
426
|
try {
|
|
494
|
-
parsed = JSON.parse(
|
|
427
|
+
parsed = JSON.parse(fs2.readFileSync(filePath, "utf-8"));
|
|
495
428
|
} catch (error) {
|
|
496
429
|
throw new Error(`Failed to read settings file '${filePath}': ${error instanceof Error ? error.message : String(error)}`);
|
|
497
430
|
}
|
|
@@ -530,8 +463,8 @@ function machineSettingsFrom(settings, keys, filePath) {
|
|
|
530
463
|
return entry;
|
|
531
464
|
}
|
|
532
465
|
function readMachineSettings(cwd, keys) {
|
|
533
|
-
const userPath =
|
|
534
|
-
const projectPath =
|
|
466
|
+
const userPath = path2.join(getAgentDir(), "settings.json");
|
|
467
|
+
const projectPath = path2.join(getProjectConfigDir(findProjectRootForSettings(cwd)), "settings.json");
|
|
535
468
|
const user = machineSettingsFrom(readJsonObject(userPath), keys, userPath);
|
|
536
469
|
const project = projectPath === userPath ? void 0 : machineSettingsFrom(readJsonObject(projectPath), keys, projectPath);
|
|
537
470
|
if (project?.rex) throw new Error(`Project settings '${projectPath}' set a Rex SSH host in 'machines'. Move the rex entry to your user settings '${userPath}'; only user settings choose which host a task runs on.`);
|
|
@@ -539,15 +472,15 @@ function readMachineSettings(cwd, keys) {
|
|
|
539
472
|
return { ...user, ...project };
|
|
540
473
|
}
|
|
541
474
|
function userRexMachine(machine) {
|
|
542
|
-
const userPath =
|
|
475
|
+
const userPath = path2.join(getAgentDir(), "settings.json");
|
|
543
476
|
return machineSettingsFrom(readJsonObject(userPath), [machine], userPath)?.rex !== void 0;
|
|
544
477
|
}
|
|
545
478
|
function findProjectRootForSettings(cwd) {
|
|
546
|
-
let current =
|
|
479
|
+
let current = path2.resolve(cwd);
|
|
547
480
|
while (true) {
|
|
548
|
-
if (
|
|
549
|
-
const parent =
|
|
550
|
-
if (parent === current) return
|
|
481
|
+
if (fs2.existsSync(path2.join(getProjectConfigDir(current), "settings.json"))) return current;
|
|
482
|
+
const parent = path2.dirname(current);
|
|
483
|
+
if (parent === current) return path2.resolve(cwd);
|
|
551
484
|
current = parent;
|
|
552
485
|
}
|
|
553
486
|
}
|
|
@@ -555,7 +488,7 @@ function remoteMachineCwd(stepCwd, root, name) {
|
|
|
555
488
|
const step = stepCwd?.trim();
|
|
556
489
|
if (step && isRemoteAbsolute(step)) return step;
|
|
557
490
|
if (!root) throw new Error(`No root for ${name} in this repo. Set subagents.machines.${name}.cwd in .pi/settings.json or pass an absolute cwd on that machine.`);
|
|
558
|
-
return step ?
|
|
491
|
+
return step ? path2.posix.join(root, step) : root;
|
|
559
492
|
}
|
|
560
493
|
function resolveHerdrMachinePlacement(input) {
|
|
561
494
|
const requested = validateMachineName(input.machine);
|
|
@@ -622,15 +555,6 @@ export {
|
|
|
622
555
|
runBoundedCommand,
|
|
623
556
|
sshMachineAccess,
|
|
624
557
|
connectHerdrMachine,
|
|
625
|
-
REX_EXIT_GONE,
|
|
626
|
-
REX_EXIT_UNREACHABLE,
|
|
627
|
-
isRexLocalMachine,
|
|
628
|
-
REX_BUNDLE_BIN,
|
|
629
|
-
REX_CALL_TIMEOUT_MS,
|
|
630
|
-
REX_MAX_OUTPUT,
|
|
631
|
-
rexGlobalArgs,
|
|
632
|
-
resolveRexBinary,
|
|
633
|
-
rexCommandEnv,
|
|
634
558
|
resolveMachinePlacement,
|
|
635
559
|
PLACED_RESTORE_UNSUPPORTED,
|
|
636
560
|
formatHerdrMachineRunnerUnsupported
|
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getLivePromptAudit,
|
|
3
3
|
handleInspectorAction,
|
|
4
|
+
objectValue,
|
|
4
5
|
readFleetTranscript,
|
|
5
|
-
renderFleetTranscript,
|
|
6
6
|
resolveWorkflowForegroundSteeringTarget,
|
|
7
|
+
safeTranscriptEvent,
|
|
7
8
|
steerAsyncRun,
|
|
8
9
|
steerWorkflowForegroundTarget
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-CS4O36CZ.js";
|
|
10
11
|
import {
|
|
11
12
|
FLEET_STATUS_WIDGET_KEY,
|
|
12
|
-
reportFleetWarning,
|
|
13
13
|
runningTone,
|
|
14
14
|
stepTaskSummary
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-L2ENOFVZ.js";
|
|
16
16
|
import {
|
|
17
17
|
foregroundChildStateLabel,
|
|
18
18
|
formatAsyncRunTranscript,
|
|
19
19
|
stopAsyncRun
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-KZ34KQQH.js";
|
|
21
21
|
import {
|
|
22
22
|
contextModeBadge,
|
|
23
23
|
contextModeLabel,
|
|
24
24
|
decodeUtf8Tail,
|
|
25
25
|
listAsyncRuns
|
|
26
|
-
} from "./chunk-
|
|
27
|
-
import
|
|
28
|
-
|
|
26
|
+
} from "./chunk-LTPH2DXH.js";
|
|
27
|
+
import {
|
|
28
|
+
reportSessionWarning
|
|
29
|
+
} from "./chunk-HXRB42AF.js";
|
|
30
|
+
import "./chunk-LGMILZNE.js";
|
|
31
|
+
import "./chunk-7MAE3DJV.js";
|
|
29
32
|
import "./chunk-NIXWDZZV.js";
|
|
30
|
-
import "./chunk-
|
|
33
|
+
import "./chunk-KDMFBYFM.js";
|
|
31
34
|
import "./chunk-7F6RKT6W.js";
|
|
32
35
|
import "./chunk-CTPAE36Y.js";
|
|
33
36
|
import "./chunk-7J4ZXMY7.js";
|
|
34
37
|
import {
|
|
35
38
|
getArtifactPaths,
|
|
36
39
|
getArtifactsDir
|
|
37
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-PHZP3KHB.js";
|
|
38
41
|
import {
|
|
39
42
|
snapshotExternalRuns
|
|
40
43
|
} from "./chunk-UKG4V45O.js";
|
|
@@ -46,18 +49,20 @@ import {
|
|
|
46
49
|
formatTokens,
|
|
47
50
|
readStatus,
|
|
48
51
|
shortenPath
|
|
49
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-UX4SCV5N.js";
|
|
50
53
|
import {
|
|
51
54
|
DIRS
|
|
52
55
|
} from "./chunk-JEZOSEWG.js";
|
|
53
|
-
import
|
|
56
|
+
import {
|
|
57
|
+
safeTerminalText
|
|
58
|
+
} from "./chunk-YFCK7H2S.js";
|
|
54
59
|
import "./chunk-QXASAHIA.js";
|
|
55
60
|
|
|
56
61
|
// src/tui/fleet.ts
|
|
57
62
|
import * as fs from "node:fs";
|
|
58
63
|
import * as path from "node:path";
|
|
59
64
|
import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
|
|
60
|
-
import { matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
65
|
+
import { matchesKey, truncateToWidth as truncateToWidth2, visibleWidth as visibleWidth2, wrapTextWithAnsi as wrapTextWithAnsi2 } from "@earendil-works/pi-tui";
|
|
61
66
|
|
|
62
67
|
// src/tui/fleet-layout.ts
|
|
63
68
|
function fleetLayout(width, rows, selected, items) {
|
|
@@ -116,6 +121,156 @@ var FleetViewport = class {
|
|
|
116
121
|
}
|
|
117
122
|
};
|
|
118
123
|
|
|
124
|
+
// src/tui/fleet-transcript.ts
|
|
125
|
+
import { getLanguageFromPath, highlightCode } from "@earendil-works/pi-coding-agent";
|
|
126
|
+
import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
127
|
+
var TOOL_PREVIEW_LINES = 7;
|
|
128
|
+
function statusGlyph(event, theme) {
|
|
129
|
+
if (event.status === "running") return theme.fg("warning", "\u25CF");
|
|
130
|
+
if (event.status === "error") return theme.fg("error", "\u2717");
|
|
131
|
+
return theme.fg("success", "\u2713");
|
|
132
|
+
}
|
|
133
|
+
function jsonScalar(value) {
|
|
134
|
+
if (typeof value === "string" && value.trim()) return value;
|
|
135
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
136
|
+
return void 0;
|
|
137
|
+
}
|
|
138
|
+
function parseToolArgs(event) {
|
|
139
|
+
if (!event.argsPayload) return void 0;
|
|
140
|
+
try {
|
|
141
|
+
return objectValue(JSON.parse(event.argsPayload));
|
|
142
|
+
} catch {
|
|
143
|
+
return void 0;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function toolDuration(event) {
|
|
147
|
+
if (event.startedAt === void 0 || event.endedAt === void 0) return void 0;
|
|
148
|
+
return `${((event.endedAt - event.startedAt) / 1e3).toFixed(1)}s`;
|
|
149
|
+
}
|
|
150
|
+
function renderExpandedTool(event, width, theme) {
|
|
151
|
+
const lines = [];
|
|
152
|
+
const args = parseToolArgs(event);
|
|
153
|
+
const glyph = statusGlyph(event, theme);
|
|
154
|
+
const output = event.output ?? event.error;
|
|
155
|
+
const outputColor = event.status === "error" ? "error" : "toolOutput";
|
|
156
|
+
if (event.name === "bash") {
|
|
157
|
+
const command = jsonScalar(args?.command) ?? event.args ?? "(unknown command)";
|
|
158
|
+
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(`$ ${command}`))}`, width, theme));
|
|
159
|
+
if (output) {
|
|
160
|
+
for (const outputLine of output.replace(/\s+$/, "").split(/\r?\n/)) {
|
|
161
|
+
for (const wrapped of renderWrapped(theme.fg(outputColor, outputLine), Math.max(1, width - 4))) {
|
|
162
|
+
lines.push(railLine(` ${wrapped}`, width, theme));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const duration = toolDuration(event);
|
|
167
|
+
if (duration) lines.push(railLine(theme.fg("dim", ` Took ${duration}`), width, theme));
|
|
168
|
+
return lines;
|
|
169
|
+
}
|
|
170
|
+
if (event.name === "read") {
|
|
171
|
+
const filePath = jsonScalar(args?.path ?? args?.file_path);
|
|
172
|
+
const language = filePath ? getLanguageFromPath(filePath) : void 0;
|
|
173
|
+
const rendered = !output ? [] : event.status === "error" ? output.split("\n").map((line) => theme.fg("error", line)) : language ? highlightCode(output, language) : output.split("\n");
|
|
174
|
+
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(`read ${filePath ?? event.args ?? ""}`))}`, width, theme));
|
|
175
|
+
for (const line of rendered) {
|
|
176
|
+
for (const wrapped of renderWrapped(line, Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
177
|
+
}
|
|
178
|
+
return lines;
|
|
179
|
+
}
|
|
180
|
+
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(event.name))}`, width, theme));
|
|
181
|
+
if (event.argsPayload) {
|
|
182
|
+
lines.push(railLine(theme.fg("dim", " args"), width, theme));
|
|
183
|
+
for (const argLine of event.argsPayload.split(/\r?\n/)) {
|
|
184
|
+
for (const wrapped of renderWrapped(theme.fg("muted", argLine), Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (output) {
|
|
188
|
+
lines.push(railLine(theme.fg(event.status === "error" ? "error" : "dim", event.status === "error" ? " error" : " output"), width, theme));
|
|
189
|
+
for (const outputLine of output.split(/\r?\n/)) {
|
|
190
|
+
for (const wrapped of renderWrapped(theme.fg(outputColor, outputLine), Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return lines;
|
|
194
|
+
}
|
|
195
|
+
function bounded(text, width) {
|
|
196
|
+
return truncateToWidth(text, Math.max(0, width));
|
|
197
|
+
}
|
|
198
|
+
function railLine(content, width, theme) {
|
|
199
|
+
return bounded(`${theme.fg("borderMuted", "\u2502")} ${content}`, width);
|
|
200
|
+
}
|
|
201
|
+
function renderWrapped(text, width) {
|
|
202
|
+
return wrapTextWithAnsi(text, Math.max(1, width));
|
|
203
|
+
}
|
|
204
|
+
function renderFleetTranscript(transcript, width, theme, markdownTheme, options = {}) {
|
|
205
|
+
if (width <= 0) return [];
|
|
206
|
+
const lines = [];
|
|
207
|
+
if (transcript.truncated) lines.push(bounded(theme.fg("dim", "\u2191 Earlier activity omitted"), width));
|
|
208
|
+
if (transcript.warning) {
|
|
209
|
+
for (const line of renderWrapped(safeTerminalText(transcript.warning), Math.max(1, width - 2))) {
|
|
210
|
+
lines.push(bounded(`${theme.fg("warning", "!")} ${theme.fg("warning", line)}`, width));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const rawEvent of transcript.events) {
|
|
214
|
+
const event = safeTranscriptEvent(rawEvent);
|
|
215
|
+
if (event.kind === "tool") {
|
|
216
|
+
if (options.expandedTools && (event.output || event.argsPayload || event.error)) {
|
|
217
|
+
lines.push(...renderExpandedTool(event, width, theme));
|
|
218
|
+
lines.push(railLine(theme.fg("dim", " x to collapse"), width, theme));
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const title = theme.fg("toolTitle", theme.bold(event.name));
|
|
222
|
+
const args = event.args ? ` ${theme.fg("dim", event.args)}` : "";
|
|
223
|
+
const suffix = event.status === "running" ? theme.fg("warning", " running") : "";
|
|
224
|
+
lines.push(bounded(`${theme.fg("borderMuted", "\u251C\u2500")} ${statusGlyph(event, theme)} ${title}${args}${suffix}`, width));
|
|
225
|
+
if (event.output && event.status !== "error" && event.name === "bash") {
|
|
226
|
+
const outputLines = event.output.replace(/\s+$/, "").split(/\r?\n/);
|
|
227
|
+
const visible = outputLines.slice(-TOOL_PREVIEW_LINES);
|
|
228
|
+
const hidden = Math.max(0, outputLines.length - visible.length);
|
|
229
|
+
for (const outputLine of visible) {
|
|
230
|
+
for (const wrapped of renderWrapped(theme.fg("toolOutput", outputLine), Math.max(1, width - 4))) {
|
|
231
|
+
lines.push(railLine(` ${wrapped}`, width, theme));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (hidden > 0) lines.push(railLine(theme.fg("dim", ` \u2026 ${hidden} earlier lines \xB7 x to expand`), width, theme));
|
|
235
|
+
const duration = toolDuration(event);
|
|
236
|
+
lines.push(railLine(theme.fg("dim", ` Took${duration ? ` ${duration}` : ""}`), width, theme));
|
|
237
|
+
} else if (event.output && event.status !== "error") {
|
|
238
|
+
const summary = truncateToWidth(event.output.replace(/\s+/g, " ").trim(), Math.max(1, width - 18), "\u2026");
|
|
239
|
+
if (summary) lines.push(railLine(theme.fg("dim", ` ${summary} \xB7 x to expand`), width, theme));
|
|
240
|
+
}
|
|
241
|
+
if (event.error) {
|
|
242
|
+
for (const errorLine of renderWrapped(event.error, Math.max(1, width - 4))) {
|
|
243
|
+
lines.push(railLine(theme.fg("error", ` ${errorLine}`), width, theme));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (event.kind === "notice") {
|
|
249
|
+
const color = event.tone === "error" ? "error" : event.tone === "warning" ? "warning" : "dim";
|
|
250
|
+
for (const noticeLine of renderWrapped(event.text, Math.max(1, width - 2))) {
|
|
251
|
+
lines.push(railLine(theme.fg(color, noticeLine), width, theme));
|
|
252
|
+
}
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const assistant = event.kind === "assistant";
|
|
256
|
+
const label = assistant ? "Assistant" : "Supervisor";
|
|
257
|
+
const marker = assistant ? theme.fg("accent", "\u25C6") : theme.fg("warning", "\u25C7");
|
|
258
|
+
const model = assistant && event.model ? theme.fg("dim", ` \xB7 ${event.model}`) : "";
|
|
259
|
+
lines.push(bounded(`${marker} ${theme.bold(label)}${model}`, width));
|
|
260
|
+
if (assistant) {
|
|
261
|
+
const rendered = new Markdown(event.text, 0, 0, markdownTheme).render(Math.max(1, width - 2));
|
|
262
|
+
for (const markdownLine of rendered) lines.push(railLine(markdownLine, width, theme));
|
|
263
|
+
} else {
|
|
264
|
+
for (const userLine of renderWrapped(event.text, Math.max(1, width - 2))) {
|
|
265
|
+
lines.push(railLine(userLine, width, theme));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
lines.push(theme.fg("borderMuted", "\u2502"));
|
|
269
|
+
}
|
|
270
|
+
while (lines.length > 0 && visibleWidth(lines.at(-1) ?? "") === 1) lines.pop();
|
|
271
|
+
return lines;
|
|
272
|
+
}
|
|
273
|
+
|
|
119
274
|
// src/tui/fleet.ts
|
|
120
275
|
var REFRESH_MS = 750;
|
|
121
276
|
var MIN_REFRESH_MS = 250;
|
|
@@ -303,7 +458,7 @@ function collectFleetSnapshot(state, options = {}) {
|
|
|
303
458
|
entryLimit: MAX_FLEET_HISTORY_CANDIDATES,
|
|
304
459
|
resultsDir: options.resultsDir ?? DIRS.results,
|
|
305
460
|
reconcile: false,
|
|
306
|
-
onCorruptStatus: (warning) =>
|
|
461
|
+
onCorruptStatus: (warning) => reportSessionWarning(state, warning)
|
|
307
462
|
}).filter((run) => !trackedIds.has(run.id));
|
|
308
463
|
runs = [...trackedRuns, ...history];
|
|
309
464
|
} else {
|
|
@@ -317,7 +472,7 @@ function collectFleetSnapshot(state, options = {}) {
|
|
|
317
472
|
}
|
|
318
473
|
if (state.currentSessionId) {
|
|
319
474
|
try {
|
|
320
|
-
for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) =>
|
|
475
|
+
for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportSessionWarning(state, `Removed ${message}`) })) {
|
|
321
476
|
items.push({
|
|
322
477
|
key: `external:${run.id}`,
|
|
323
478
|
kind: "external",
|
|
@@ -384,7 +539,7 @@ function fleetItemThinkingLevel(item) {
|
|
|
384
539
|
return void 0;
|
|
385
540
|
}
|
|
386
541
|
}
|
|
387
|
-
function
|
|
542
|
+
function statusGlyph2(item, theme) {
|
|
388
543
|
if (item.state === "running") return runningTone(theme, fleetItemThinkingLevel(item))("\u25CF");
|
|
389
544
|
if (item.state === "queued" || item.state === "pending") return theme.fg("muted", "\u25E6");
|
|
390
545
|
if (item.state === "complete" || item.state === "completed") return theme.fg("success", "\u2713");
|
|
@@ -402,7 +557,7 @@ function promptAuditString(value) {
|
|
|
402
557
|
function authoredPromptSummary(text) {
|
|
403
558
|
if (typeof text !== "string") return void 0;
|
|
404
559
|
const summary = text.replace(/\s+/g, " ").trim();
|
|
405
|
-
return summary ?
|
|
560
|
+
return summary ? truncateToWidth2(summary, PROMPT_AUDIT_SUMMARY_WIDTH, "\u2026") : void 0;
|
|
406
561
|
}
|
|
407
562
|
function foregroundAuthoredPromptSummary(item, state) {
|
|
408
563
|
if (!state.currentSessionId || item.control.sessionId !== state.currentSessionId) return void 0;
|
|
@@ -740,7 +895,7 @@ function itemStats(item) {
|
|
|
740
895
|
}
|
|
741
896
|
function structuredHeader(item, width, theme, conversationState, promptSummary) {
|
|
742
897
|
const lines = [];
|
|
743
|
-
lines.push(rightAligned(` ${
|
|
898
|
+
lines.push(rightAligned(` ${statusGlyph2(item, theme)} ${theme.bold(item.agent)}`, theme.fg("dim", item.state), width));
|
|
744
899
|
const child = "index" in item && item.index !== void 0 ? ` \xB7 child ${item.index + 1}` : "";
|
|
745
900
|
const context = itemContext(item);
|
|
746
901
|
const identity = `${itemSource(item)} \xB7 ${item.runId.slice(0, 8)}${child} \xB7 ${itemMode(item)}${context ? ` ${context}` : ""}`;
|
|
@@ -749,14 +904,14 @@ function structuredHeader(item, width, theme, conversationState, promptSummary)
|
|
|
749
904
|
if (stats.length) lines.push(` ${theme.fg("muted", stats.join(" \xB7 "))}`);
|
|
750
905
|
if (promptSummary) lines.push(` ${theme.fg("muted", `Task: ${promptSummary}`)}`);
|
|
751
906
|
lines.push(`${theme.fg("accent", "Conversation")} ${theme.fg("dim", `\xB7 ${conversationState}`)}`);
|
|
752
|
-
return lines.map((line) =>
|
|
907
|
+
return lines.map((line) => truncateToWidth2(line, width));
|
|
753
908
|
}
|
|
754
909
|
function fit(text, width) {
|
|
755
|
-
const clipped =
|
|
756
|
-
return clipped + " ".repeat(Math.max(0, width -
|
|
910
|
+
const clipped = truncateToWidth2(text, Math.max(0, width));
|
|
911
|
+
return clipped + " ".repeat(Math.max(0, width - visibleWidth2(clipped)));
|
|
757
912
|
}
|
|
758
913
|
function rightAligned(left, right, width) {
|
|
759
|
-
const rightWidth =
|
|
914
|
+
const rightWidth = visibleWidth2(right);
|
|
760
915
|
const leftWidth = Math.max(0, width - rightWidth - 1);
|
|
761
916
|
return fit(left, leftWidth) + " ".repeat(Math.max(1, width - leftWidth - rightWidth)) + fit(right, rightWidth);
|
|
762
917
|
}
|
|
@@ -1190,7 +1345,7 @@ var SubagentFleetComponent = class {
|
|
|
1190
1345
|
const name = task && item.kind === "async" && item.step ? item.step.agent : item.agent;
|
|
1191
1346
|
const agent = index === this.selected ? this.theme.bold(name) : name;
|
|
1192
1347
|
const identity = task ?? item.runId.slice(0, 8);
|
|
1193
|
-
const left = `${marker} ${
|
|
1348
|
+
const left = `${marker} ${statusGlyph2(item, this.theme)} ${agent}${context} ${this.theme.fg("dim", `\xB7 ${identity}`)}`;
|
|
1194
1349
|
return rightAligned(left, this.theme.fg("dim", item.state), layout.roster.width);
|
|
1195
1350
|
});
|
|
1196
1351
|
}
|
|
@@ -1230,7 +1385,7 @@ var SubagentFleetComponent = class {
|
|
|
1230
1385
|
this.theme.fg("accent", viewLabel),
|
|
1231
1386
|
promptText
|
|
1232
1387
|
];
|
|
1233
|
-
const body = raw.filter((line) => line !== void 0).flatMap((line) =>
|
|
1388
|
+
const body = raw.filter((line) => line !== void 0).flatMap((line) => wrapTextWithAnsi2(line, Math.max(1, width)));
|
|
1234
1389
|
return { header: [], body: this.withActionLines(body) };
|
|
1235
1390
|
}
|
|
1236
1391
|
wrappedDetail(width) {
|
|
@@ -1256,7 +1411,7 @@ var SubagentFleetComponent = class {
|
|
|
1256
1411
|
const lines = [];
|
|
1257
1412
|
for (const line of raw) {
|
|
1258
1413
|
const styled = /^(Run|State|Mode|Source|Child|Agent|Model|Task):/.test(line) ? this.theme.bold(line) : /^(Transcript|Result transcript tail)/.test(line) ? this.theme.fg("accent", line) : /^(Output|Session|Transcript file|Artifacts):/.test(line) ? this.theme.fg("muted", line) : /^Transcript preview warning:/.test(line) ? this.theme.fg("warning", line) : line;
|
|
1259
|
-
const wrapped =
|
|
1414
|
+
const wrapped = wrapTextWithAnsi2(styled, Math.max(1, width));
|
|
1260
1415
|
lines.push(...wrapped.length ? wrapped : [""]);
|
|
1261
1416
|
}
|
|
1262
1417
|
return { header: [], body: this.withActionLines(lines) };
|
|
@@ -1264,7 +1419,7 @@ var SubagentFleetComponent = class {
|
|
|
1264
1419
|
render(width) {
|
|
1265
1420
|
const layout = fleetLayout(width, this.tui.terminal?.rows ?? 32, this.selected, this.snapshot.items);
|
|
1266
1421
|
this.renderedLayout = layout;
|
|
1267
|
-
if (!layout) return [
|
|
1422
|
+
if (!layout) return [truncateToWidth2("Subagent fleet needs at least 36 columns. Esc closes.", width)];
|
|
1268
1423
|
const innerWidth = width - 2;
|
|
1269
1424
|
const { bodyHeight } = layout;
|
|
1270
1425
|
const rosterWidth = layout.roster.width;
|
|
@@ -1280,7 +1435,7 @@ var SubagentFleetComponent = class {
|
|
|
1280
1435
|
const lines = [this.theme.fg("border", `\u256D${"\u2500".repeat(innerWidth)}\u256E`)];
|
|
1281
1436
|
const selected = this.snapshot.items[this.selected];
|
|
1282
1437
|
const title = selected?.kind === "external" ? ` ${this.theme.bold("Fleet inspector")} ${this.theme.fg("dim", "\xB7 external display-only")}` : ` ${this.theme.bold("Subagent fleet inspector")} ${this.theme.fg("dim", "\xB7 live controls")}`;
|
|
1283
|
-
const selectedStatus = selected ? `${
|
|
1438
|
+
const selectedStatus = selected ? `${statusGlyph2(selected, this.theme)} ${selected.agent} \xB7 ${selected.state} ` : this.theme.fg("dim", "no children ");
|
|
1284
1439
|
lines.push(this.theme.fg("border", "\u2502") + rightAligned(title, selectedStatus, innerWidth) + this.theme.fg("border", "\u2502"));
|
|
1285
1440
|
lines.push(this.theme.fg("border", `\u251C${"\u2500".repeat(rosterWidth)}\u252C${"\u2500".repeat(detailWidth)}\u2524`));
|
|
1286
1441
|
for (let index = 0; index < bodyHeight; index++) {
|
|
@@ -1293,7 +1448,7 @@ var SubagentFleetComponent = class {
|
|
|
1293
1448
|
const footer = this.promptAuditOpen ? ` j/k child \xB7 1/2/3 view \xB7 g redo with guidance \xB7 c copy \xB7 Esc close Prompt Audit \xB7 ${position}` : selected?.kind === "external" ? ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} job \xB7 display-only \xB7 ${bindingLabel(this.keybindings, "refresh")} refresh \xB7 ${bindingLabel(this.keybindings, "close")} close \xB7 ${position}` : ` ${bindingLabel(this.keybindings, "selectUp")}/${bindingLabel(this.keybindings, "selectDown")} agent \xB7 p Prompt Audit \xB7 ${bindingLabel(this.keybindings, "inspect")} Inspect \xB7 ${bindingLabel(this.keybindings, "steer")} steer \xB7 ${bindingLabel(this.keybindings, "stop")} stop \xB7 ${bindingLabel(this.keybindings, "toggleTools")} tools \xB7 ${bindingLabel(this.keybindings, "refresh")} refresh \xB7 ${bindingLabel(this.keybindings, "close")} close \xB7 ${position}`;
|
|
1294
1449
|
lines.push(this.theme.fg("border", "\u2502") + fit(this.theme.fg("dim", footer), innerWidth) + this.theme.fg("border", "\u2502"));
|
|
1295
1450
|
lines.push(this.theme.fg("border", `\u2570${"\u2500".repeat(innerWidth)}\u256F`));
|
|
1296
|
-
return lines.map((line) =>
|
|
1451
|
+
return lines.map((line) => truncateToWidth2(line, width));
|
|
1297
1452
|
}
|
|
1298
1453
|
invalidate() {
|
|
1299
1454
|
this.renderedLayout = void 0;
|