mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-31 19:15:17 +02:00
fix shell env inference
This commit is contained in:
parent
69983ec566
commit
1a7dce35c8
1 changed files with 22 additions and 17 deletions
|
|
@ -24,7 +24,7 @@ import { init as initAgentRunner } from "@x/core/dist/agent-schedule/runner.js";
|
||||||
import { init as initAgentNotes } from "@x/core/dist/knowledge/agent_notes.js";
|
import { init as initAgentNotes } from "@x/core/dist/knowledge/agent_notes.js";
|
||||||
import { initConfigs } from "@x/core/dist/config/initConfigs.js";
|
import { initConfigs } from "@x/core/dist/config/initConfigs.js";
|
||||||
import started from "electron-squirrel-startup";
|
import started from "electron-squirrel-startup";
|
||||||
import { execSync, exec } from "node:child_process";
|
import { execSync, exec, execFileSync } from "node:child_process";
|
||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
import { init as initChromeSync } from "@x/core/dist/knowledge/chrome-extension/server/server.js";
|
import { init as initChromeSync } from "@x/core/dist/knowledge/chrome-extension/server/server.js";
|
||||||
|
|
||||||
|
|
@ -38,25 +38,30 @@ if (started) app.quit();
|
||||||
|
|
||||||
// Fix PATH for packaged Electron apps on macOS/Linux.
|
// Fix PATH for packaged Electron apps on macOS/Linux.
|
||||||
// Packaged apps inherit a minimal environment that doesn't include paths from
|
// Packaged apps inherit a minimal environment that doesn't include paths from
|
||||||
// the user's shell profile (nvm, Homebrew, etc.). Spawn the user's login shell
|
// the user's shell profile (such as those provided by nvm, Homebrew, etc.).
|
||||||
// to resolve the full PATH, using delimiters to safely extract it from any
|
// The function below spawns the user's login shell and runs a Node.js one-liner
|
||||||
// surrounding shell output (motd, greeting messages, etc.).
|
// to print the full environment as JSON, then merges it into process.env.
|
||||||
if (process.platform !== 'win32') {
|
// This ensures the Electron app has the same PATH and environment as user shell
|
||||||
|
// (helping find tools installed via Homebrew/nvm/npm, etc.)
|
||||||
|
function initializeExecutionEnvironment(): void {
|
||||||
|
if (process.platform === 'win32') return;
|
||||||
|
|
||||||
|
const shell = process.env.SHELL || '/bin/zsh';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userShell = process.env.SHELL || '/bin/zsh';
|
const stdout = execFileSync(
|
||||||
const delimiter = '__ROWBOAT_PATH__';
|
shell,
|
||||||
const output = execSync(
|
['-l', '-c', `node -p "JSON.stringify(process.env)"`],
|
||||||
`${userShell} -lc 'echo -n "${delimiter}$PATH${delimiter}"'`,
|
{ encoding: 'utf8' }
|
||||||
{ encoding: 'utf-8', timeout: 5000 },
|
).trim();
|
||||||
);
|
|
||||||
const match = output.match(new RegExp(`${delimiter}(.+?)${delimiter}`));
|
const env = JSON.parse(stdout) as Record<string, string>;
|
||||||
if (match?.[1]) {
|
process.env = { ...env, ...process.env };
|
||||||
process.env.PATH = match[1];
|
} catch (error) {
|
||||||
}
|
console.error('Failed to load shell environment', error);
|
||||||
} catch {
|
|
||||||
// Silently fall back to the existing PATH if shell resolution fails
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
initializeExecutionEnvironment();
|
||||||
|
|
||||||
// Path resolution differs between development and production:
|
// Path resolution differs between development and production:
|
||||||
const preloadPath = app.isPackaged
|
const preloadPath = app.isPackaged
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue