Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(windows): use shell:true for spawn on win32 to fix EINVAL on .cmd shims

[._.]/ Adam Eivy801cb94ec55e
diff --git a/server/routes/apps.js b/server/routes/apps.js
index e5980048f9..fb548125eb 100644
--- a/server/routes/apps.js
+++ b/server/routes/apps.js
@@ -656,18 +656,17 @@ router.post('/:id/build', loadApp, asyncHandler(async (req, res) => {
if (await pathExists(join(subDir, 'package.json'))) {
const label = sub || 'root';
console.log(`📦 Installing ${label} dependencies for ${app.name}`);
- const INSTALL_TIMEOUT_MS = 3 * 60 * 1000; // 3 minutes
const installResult = await new Promise((resolve) => {
- const child = spawn(resolveCmd('npm'), ['install'], { cwd: subDir, windowsHide: true });
+ const child = spawn('npm', ['install'], { cwd: subDir, windowsHide: true, shell: IS_WIN32 });
let stdout = '';
let stderr = '';
let settled = false;
- const MAX = 16 * 1024;
+ const MAX = 64 * 1024;
const timer = setTimeout(() => {
if (!settled) { settled = true; child.kill('SIGTERM'); resolve({ success: false, exitCode: -1, output: `npm install timed out after ${INSTALL_TIMEOUT_MS / 1000}s` }); }
}, INSTALL_TIMEOUT_MS);
- child.stdout.on('data', d => { if (stdout.length < MAX) stdout += d; });
- child.stderr.on('data', d => { if (stderr.length < MAX) stderr += d; });
+ child.stdout.on('data', d => { stdout += d; if (stdout.length > MAX) stdout = stdout.slice(-MAX); });
+ child.stderr.on('data', d => { stderr += d; if (stderr.length > MAX) stderr = stderr.slice(-MAX); });
child.on('close', exitCode => { if (!settled) { settled = true; clearTimeout(timer); resolve({ success: exitCode === 0, exitCode, output: (stderr.trim() || stdout.trim()).slice(0, 1024) }); } });
child.on('error', err => { if (!settled) { settled = true; clearTimeout(timer); resolve({ success: false, exitCode: -1, output: err.message }); } });
});
@@ -679,9 +678,8 @@ router.post('/:id/build', loadApp, asyncHandler(async (req, res) => {
}
}
- const BUILD_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
const result = await new Promise((resolve) => {
- const child = spawn(resolveCmd(cmd), args, { cwd: app.repoPath, windowsHide: true });
+ const child = spawn(cmd, args, { cwd: app.repoPath, windowsHide: true, shell: IS_WIN32 });
let stdout = '';
let stderr = '';
let settled = false;
@@ -774,9 +772,9 @@ const ALLOWED_BUILD_CMDS = new Set([
'cargo' // Rust
]);
-// On Windows, Node-based CLI tools resolve to .cmd shims
-const WIN_CMD_SHIMS = new Set(['npm', 'npx']);
-const resolveCmd = (cmd) => process.platform === 'win32' && WIN_CMD_SHIMS.has(cmd) ? `${cmd}.cmd` : cmd;
+const IS_WIN32 = process.platform === 'win32';
+const INSTALL_TIMEOUT_MS = 3 * 60 * 1000;
+const BUILD_TIMEOUT_MS = 5 * 60 * 1000;
// Allowlist of safe editor commands
// Security: Only allow known-safe editor commands to prevent arbitrary code execution
diff --git a/server/services/appUpdater.js b/server/services/appUpdater.js
index c76ba28b09..61b89dcc5d 100644
--- a/server/services/appUpdater.js
+++ b/server/services/appUpdater.js
@@ -5,29 +5,27 @@ import { readFile } from 'fs/promises';
import * as gitService from './git.js';
import * as pm2Service from './pm2.js';
-/**
- * Run a command and return stdout/stderr
- */
-const MAX_OUTPUT_BYTES = 64 * 1024; // 64KB tail per stream
+const IS_WIN32 = process.platform === 'win32';
+const MAX_OUTPUT_BYTES = 64 * 1024;
+const CMD_TIMEOUT_MS = 5 * 60 * 1000;
function runCommand(cmd, args, cwd) {
return new Promise((resolve, reject) => {
- const child = spawn(cmd, args, { cwd, shell: false, windowsHide: true });
+ const child = spawn(cmd, args, { cwd, shell: IS_WIN32, windowsHide: true });
let stdout = '';
let stderr = '';
- child.stdout.on('data', d => {
- stdout += d;
- if (stdout.length > MAX_OUTPUT_BYTES) stdout = stdout.slice(-MAX_OUTPUT_BYTES);
- });
- child.stderr.on('data', d => {
- stderr += d;
- if (stderr.length > MAX_OUTPUT_BYTES) stderr = stderr.slice(-MAX_OUTPUT_BYTES);
- });
+ let settled = false;
+ const timer = setTimeout(() => {
+ if (!settled) { settled = true; child.kill('SIGTERM'); reject(new Error(`${cmd} timed out after ${CMD_TIMEOUT_MS / 1000}s`)); }
+ }, CMD_TIMEOUT_MS);
+ child.stdout.on('data', d => { stdout += d; if (stdout.length > MAX_OUTPUT_BYTES) stdout = stdout.slice(-MAX_OUTPUT_BYTES); });
+ child.stderr.on('data', d => { stderr += d; if (stderr.length > MAX_OUTPUT_BYTES) stderr = stderr.slice(-MAX_OUTPUT_BYTES); });
child.on('close', code => {
+ if (!settled) { settled = true; clearTimeout(timer); }
if (code !== 0) reject(new Error(stderr.trim() || `${cmd} exited with code ${code}`));
else resolve({ stdout, stderr });
});
- child.on('error', reject);
+ child.on('error', err => { if (!settled) { settled = true; clearTimeout(timer); } reject(err); });
});
}
@@ -63,14 +61,12 @@ async function _doUpdate(app, emit) {
const dir = app.repoPath;
const steps = [];
- // Step 1: Git pull
emit('git-pull', 'running', 'Pulling latest changes...');
const pullResult = await gitService.pull(dir);
const pullMsg = pullResult.output?.trim() || 'Up to date';
emit('git-pull', 'done', pullMsg);
steps.push({ step: 'git-pull', success: true, message: pullMsg });
- // Step 2: Install deps for each subdir that has package.json
for (const sub of ['', 'client', 'server', 'admin']) {
const subDir = sub ? join(dir, sub) : dir;
if (existsSync(join(subDir, 'package.json'))) {
@@ -83,7 +79,6 @@ async function _doUpdate(app, emit) {
}
}
- // Step 3: Run setup if available
const pkgPath = join(dir, 'package.json');
if (existsSync(pkgPath)) {
const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'));
@@ -95,7 +90,6 @@ async function _doUpdate(app, emit) {
}
}
- // Step 4: Restart PM2 processes
const processNames = app.pm2ProcessNames || [];
if (processNames.length > 0) {
emit('restart', 'running', 'Restarting app...');