fix(subagent): reuse current pi invocation for child agents closes #2464 (#2465)

This commit is contained in:
Ziphyrien
2026-03-21 00:12:24 +08:00
committed by GitHub
parent 47ea28b584
commit 7c92bb8151

View File

@@ -217,6 +217,21 @@ async function writePromptToTempFile(agentName: string, prompt: string): Promise
return { dir: tmpDir, filePath };
}
function getPiInvocation(args: string[]): { command: string; args: string[] } {
const currentScript = process.argv[1];
if (currentScript && fs.existsSync(currentScript)) {
return { command: process.execPath, args: [currentScript, ...args] };
}
const execName = path.basename(process.execPath).toLowerCase();
const isGenericRuntime = /^(node|bun)(\.exe)?$/.test(execName);
if (!isGenericRuntime) {
return { command: process.execPath, args };
}
return { command: "pi", args };
}
type OnUpdateCallback = (partial: AgentToolResult<SubagentDetails>) => void;
async function runSingleAgent(
@@ -286,7 +301,12 @@ async function runSingleAgent(
let wasAborted = false;
const exitCode = await new Promise<number>((resolve) => {
const proc = spawn("pi", args, { cwd: cwd ?? defaultCwd, shell: false, stdio: ["ignore", "pipe", "pipe"] });
const invocation = getPiInvocation(args);
const proc = spawn(invocation.command, invocation.args, {
cwd: cwd ?? defaultCwd,
shell: false,
stdio: ["ignore", "pipe", "pipe"],
});
let buffer = "";
const processLine = (line: string) => {