Skip to content

Commit c1c8a41

Browse files
authored
fix: unpack spawn helper (#154)
1 parent 1e5eeb6 commit c1c8a41

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

forge.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function copyNativeDependency(
104104
const config: ForgeConfig = {
105105
packagerConfig: {
106106
asar: {
107-
unpack: "{**/*.node,**/.vite/build/claude-cli/**}",
107+
unpack: "{**/*.node,**/spawn-helper,**/.vite/build/claude-cli/**}",
108108
},
109109
prune: false,
110110
name: "Array",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"date-fns": "^3.3.1",
9797
"idb-keyval": "^6.2.2",
9898
"node-addon-api": "^8.5.0",
99-
"node-pty": "1.1.0-beta37",
99+
"node-pty": "1.1.0-beta39",
100100
"posthog-js": "^1.283.0",
101101
"posthog-node": "^4.18.0",
102102
"radix-themes-tw": "0.2.3",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function createWindow(): void {
7575
titleBarStyle: "hiddenInset",
7676
show: false,
7777
webPreferences: {
78-
nodeIntegration: false,
78+
nodeIntegration: true,
7979
contextIsolation: true,
8080
preload: path.join(__dirname, "preload.js"),
8181
enableBlinkFeatures: "GetDisplayMedia",

src/main/services/shell.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from "node:fs";
12
import * as os from "node:os";
23
import { type IpcMainInvokeEvent, ipcMain, type WebContents } from "electron";
34
import * as pty from "node-pty";
@@ -38,13 +39,44 @@ export function registerShellIpc(): void {
3839

3940
const shell = getDefaultShell();
4041
const homeDir = os.homedir();
42+
let workingDir = cwd || homeDir;
43+
44+
// Validate that the directory exists
45+
if (!fs.existsSync(workingDir)) {
46+
console.warn(
47+
`Shell session ${sessionId}: cwd "${workingDir}" does not exist, falling back to home directory`,
48+
);
49+
workingDir = homeDir;
50+
}
51+
52+
console.log(
53+
`Creating shell session ${sessionId}: shell=${shell}, cwd=${workingDir}`,
54+
);
55+
56+
// Build environment with proper locale settings for macOS
57+
const env = { ...process.env } as Record<string, string>;
58+
59+
// On macOS, ensure locale is properly set for shell compatibility
60+
if (os.platform() === "darwin" && !process.env.LC_ALL) {
61+
const locale = process.env.LC_CTYPE || "en_US.UTF-8";
62+
env.LANG = locale;
63+
env.LC_ALL = locale;
64+
env.LC_MESSAGES = locale;
65+
env.LC_NUMERIC = locale;
66+
env.LC_COLLATE = locale;
67+
env.LC_MONETARY = locale;
68+
}
69+
70+
// Spawn as login shell to properly load PATH and environment
71+
const shellArgs = ["-l"];
4172

42-
const ptyProcess = pty.spawn(shell, [], {
73+
const ptyProcess = pty.spawn(shell, shellArgs, {
4374
name: "xterm-256color",
4475
cols: 80,
4576
rows: 24,
46-
cwd: cwd || homeDir,
47-
env: process.env as Record<string, string>,
77+
cwd: workingDir,
78+
env,
79+
encoding: null,
4880
});
4981

5082
// Send data to renderer
@@ -53,7 +85,10 @@ export function registerShellIpc(): void {
5385
});
5486

5587
// Handle exit
56-
ptyProcess.onExit(() => {
88+
ptyProcess.onExit(({ exitCode, signal }) => {
89+
console.error(
90+
`Shell session ${sessionId} exited with code ${exitCode}, signal ${signal}`,
91+
);
5792
event.sender.send(`shell:exit:${sessionId}`);
5893
sessions.delete(sessionId);
5994
});

0 commit comments

Comments
 (0)