@xzzpig/pi-subagents 0.24.2 → 0.25.1
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 +37 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
- package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- 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/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- 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 +12 -3
- package/src/extension/schemas.js +7 -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 +55 -15
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- 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 +7 -10
- package/src/runs/background/async-execution.js +66 -29
- 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 +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- 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 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- 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-subscriptions.js +124 -12
- 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/async-steering-action.js +24 -9
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +68 -84
- package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
- package/src/runs/foreground/fork-tool-result-handler.js +83 -0
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- 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 +6 -5
- package/src/runs/shared/child-session.js +85 -38
- 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-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- 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 +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- 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 +0 -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 +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- 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/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- 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 +64 -0
- package/src/shared/fleet-transcript-reader.js +376 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- 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/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -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-native-transcript.js +1 -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 -57
- package/src/tui/fleet-transcript.js +4 -370
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
|
@@ -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-XAC2XNAP.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
|