fix(pi): load subagent extension in child sessions

This commit was merged in pull request #39.
This commit is contained in:
2026-08-01 19:23:46 -04:00
parent e143495d6c
commit f5d799c64b
2 changed files with 71 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
import { fileURLToPath } from "node:url";
import type { ChildHandle, ChildRunner, RunnerEvents, SpawnRequest } from "./types.ts";
interface PendingResponse {
@@ -156,7 +157,7 @@ class RpcChildHandle implements ChildHandle {
export class SubprocessRpcRunner implements ChildRunner {
async start(id: string, request: SpawnRequest, cwd: string, events: RunnerEvents): Promise<ChildHandle> {
const args = [process.argv[1], "--mode", "rpc", "--no-extensions", "--name", `subagent ${id}`, ...contextArgs(request), ...toolArgs(request), ...modelArgs(request)];
const args = [process.argv[1], "--mode", "rpc", "--no-extensions", "--extension", subagentsExtensionPath(), "--name", `subagent ${id}`, ...contextArgs(request), ...toolArgs(request), ...modelArgs(request)];
const child = spawn(process.execPath, args, {
cwd,
env: childEnvironment(),
@@ -174,6 +175,10 @@ function delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function subagentsExtensionPath(): string {
return fileURLToPath(new URL("./index.ts", import.meta.url));
}
function contextArgs(request: SpawnRequest): string[] {
if (request.context !== "fork" || !request.parentSessionFile) return [];
return ["--fork", request.parentSessionFile];