Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit d24af58

Browse files
authored
fix(agent): unbreak Pi local runs in packaged desktop (#3966)
1 parent 1e858aa commit d24af58

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎packages/agent/src/pi/rpc-client.test.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { mkdtemp, rm, writeFile } from "node:fs/promises";
1+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
22
import { tmpdir } from "node:os";
33
import { join } from "node:path";
44
import { RpcClient } from "@earendil-works/pi-coding-agent";
5-
import { describe, expect, it } from "vitest";
5+
import { describe, expect, it, vi } from "vitest";
66
import { createPiRpcClient } from "./rpc-client";
77

88
describe("createPiRpcClient", () => {
@@ -31,6 +31,37 @@ describe("createPiRpcClient", () => {
3131
).toBeUndefined();
3232
});
3333

34+
it("runs the RPC host with Electron's Node mode enabled", async () => {
35+
const directory = await mkdtemp(join(tmpdir(), "pi-electron-node-mode-"));
36+
const hostPath = join(directory, "host.mjs");
37+
const capturePath = join(directory, "capture.txt");
38+
await writeFile(
39+
hostPath,
40+
`
41+
import { closeSync, writeFileSync } from "node:fs";
42+
43+
closeSync(3);
44+
writeFileSync(${JSON.stringify(capturePath)}, process.env.ELECTRON_RUN_AS_NODE ?? "");
45+
process.stdin.resume();
46+
`,
47+
);
48+
const client = createPiRpcClient({
49+
cliPath: hostPath,
50+
cwd: directory,
51+
providerOptions: { apiKey: "proxy-key" },
52+
});
53+
54+
try {
55+
await client.start();
56+
await vi.waitFor(async () => {
57+
await expect(readFile(capturePath, "utf8")).resolves.toBe("1");
58+
});
59+
} finally {
60+
await client.stop();
61+
await rm(directory, { recursive: true });
62+
}
63+
});
64+
3465
it("uses the private host channel without changing Pi RPC", async () => {
3566
const directory = await mkdtemp(join(tmpdir(), "pi-host-channel-"));
3667
const hostPath = join(directory, "host.mjs");

‎packages/agent/src/pi/rpc-client.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ class SecurePiRpcClient extends RpcClient {
111111
[this.secureOptions.cliPath ?? "dist/cli.js", ...args],
112112
{
113113
cwd: this.secureOptions.cwd,
114-
env: safePiEnvironment(process.env),
114+
env: {
115+
...safePiEnvironment(process.env),
116+
ELECTRON_RUN_AS_NODE: "1",
117+
},
115118
stdio: ["pipe", "pipe", "pipe", "pipe", "ipc"],
116119
},
117120
);

0 commit comments

Comments
 (0)