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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: Windows shell compatibility and CoS fresh-install auto-spawn
[._.]/ Adam Eivy65dd4d9143c0
diff --git a/.changelog/v1.4.x.md b/.changelog/v1.4.x.mdindex 80b93b9ad0..2c5e31f480 100644--- a/.changelog/v1.4.x.md+++ b/.changelog/v1.4.x.md@@ -19,3 +19,14 @@ Cross-platform compatibility improvements for Windows and exFAT filesystems.### Cross-platform path separators in PM2 config- `ecosystem.config.cjs` now uses `path.join()` instead of string concatenation for the Vite script and client cwd paths, avoiding mixed separators on Windows++### Windows: Unix-only shell commands crash server+- Replaced `2>/dev/null || true` bash redirects with try/catch in `subAgentSpawner.js` (was crashing via unhandled rejection)+- Replaced `ps` process checks with cross-platform `process.kill(pid, 0)` in `cos.js` and `subAgentSpawner.js`+- Added Windows `tasklist` alternative for process stats in `cos-runner` and `subAgentSpawner`+- Fixed `platform.js` port detection: removed bash redirects, uses `LISTENING` keyword on Windows+- Fixed `cos.js` health check: platform-specific memory command (`wmic` on Windows, `vm_stat` on macOS, `free` on Linux)++### CoS auto-spawns agents on fresh install+- Skip improvement task generation during initial startup evaluation to prevent auto-spawning agents when no tasks should exist yet+- Regular scheduled evaluations still generate improvement tasks as normaldiff --git a/package-lock.json b/package-lock.jsonindex 62e27ba61b..0380f48908 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "portos",- "version": "1.4.1",+ "version": "1.4.2","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "portos",- "version": "1.4.1",+ "version": "1.4.2","license": "MIT","dependencies": {"express": "^4.21.2",diff --git a/package.json b/package.jsonindex 446957bae8..8d15b8b030 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "portos",- "version": "1.4.1",+ "version": "1.4.2","private": true,"description": "Local dev machine App OS portal","author": "Adam Eivy (@antic|@atomantic)",diff --git a/server/cos-runner/index.js b/server/cos-runner/index.jsindex 3b20b41c4a..070170f378 100644--- a/server/cos-runner/index.js+++ b/server/cos-runner/index.js@@ -303,7 +303,10 @@ async function getProcessStats(pid) {// Get process stats using ps command// %cpu = CPU percentage, rss = resident set size in KB- const result = await execAsync(`ps -p ${safePid} -o pid=,pcpu=,rss=,state= 2>/dev/null`).catch(() => ({ stdout: '' }));+ const psCmd = process.platform === 'win32'+ ? `tasklist /FI "PID eq ${safePid}" /FO CSV /NH`+ : `ps -p ${safePid} -o pid=,pcpu=,rss=,state=`;+ const result = await execAsync(psCmd).catch(() => ({ stdout: '' }));const line = result.stdout.trim();if (!line) {diff --git a/server/lib/platform.js b/server/lib/platform.jsindex b21225d3db..b22d83e32e 100644--- a/server/lib/platform.js+++ b/server/lib/platform.js@@ -14,7 +14,7 @@ export async function getListeningPorts() {if (platform === 'darwin') {// macOS: use lsof- const { stdout } = await execAsync('lsof -iTCP -sTCP:LISTEN -n -P 2>/dev/null || true');+ const { stdout } = await execAsync('lsof -iTCP -sTCP:LISTEN -n -P').catch(() => ({ stdout: '' }));const lines = stdout.split('\n').slice(1); // Skip headerfor (const line of lines) {const match = line.match(/:(\d+)\s+\(LISTEN\)/);@@ -24,7 +24,7 @@ export async function getListeningPorts() {}} else if (platform === 'linux') {// Linux: use ss- const { stdout } = await execAsync('ss -lntp 2>/dev/null || true');+ const { stdout } = await execAsync('ss -lntp').catch(() => ({ stdout: '' }));const lines = stdout.split('\n').slice(1); // Skip headerfor (const line of lines) {const match = line.match(/:(\d+)\s/);@@ -33,11 +33,11 @@ export async function getListeningPorts() {}}} else {- // Windows/other: try netstat- const { stdout } = await execAsync('netstat -an 2>/dev/null || true');+ // Windows: use netstat+ const { stdout } = await execAsync('netstat -an').catch(() => ({ stdout: '' }));const lines = stdout.split('\n');for (const line of lines) {- if (line.includes('LISTEN')) {+ if (line.includes('LISTENING')) {const match = line.match(/:(\d+)\s/);if (match) {ports.add(parseInt(match[1], 10));diff --git a/server/services/cos.js b/server/services/cos.jsindex 95eeea3d32..f23c1a1067 100644--- a/server/services/cos.js+++ b/server/services/cos.js@@ -69,6 +69,7 @@ export function emitLog(level, message, data = {}, prefix = '') {// In-memory daemon statelet daemonRunning = false;+let initialStartup = false;// Lightweight index mapping agentId → YYYY-MM-DD date bucket (~50KB vs 16MB full cache)// Lazy-loaded from data/cos/agents/index.json on first access@@ -604,9 +605,12 @@ export async function start() {// Schedule improvement task checks based on next due timeawait scheduleNextImprovementCheck();- // Run initial evaluation to fill available slots, then health check+ // Run initial evaluation to pick up existing pending tasks, then health check+ // Skip improvement task generation on startup to avoid spawning agents on fresh installsemitLog('info', 'Running initial task evaluation...');+ initialStartup = true;await evaluateTasks();+ initialStartup = false;await runHealthCheck();cosEvents.emit('status', { running: true });@@ -1008,7 +1012,8 @@ export async function evaluateTasks() {// Background: Queue eligible self-improvement tasks as system tasks// Only queue if there are NO pending user tasks (user tasks always take priority)- if (state.config.idleReviewEnabled && !hasPendingUserTasks) {+ // Skip on initial startup to avoid auto-spawning agents on fresh installs+ if (state.config.idleReviewEnabled && !hasPendingUserTasks && !initialStartup) {await queueEligibleImprovementTasks(state, cosTaskData);}@@ -1973,7 +1978,7 @@ export async function runHealthCheck() {};// Check PM2 processes- const pm2Result = await execAsync('pm2 jlist 2>/dev/null || echo "[]"').catch(() => ({ stdout: '[]' }));+ const pm2Result = await execAsync('pm2 jlist').catch(() => ({ stdout: '[]' }));// pm2 jlist may output ANSI codes and warnings before JSON, extract the JSON array// Look for '[{' (array with objects) or '[]' (empty array) to avoid matching ANSI codes like [31mconst pm2Output = pm2Result.stdout || '[]';@@ -2053,7 +2058,9 @@ export async function runHealthCheck() {}// Get system memory- const memResult = await execAsync('vm_stat 2>/dev/null || free -m 2>/dev/null').catch(() => ({ stdout: '' }));+ const memCmd = process.platform === 'win32' ? 'wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /VALUE' :+ process.platform === 'darwin' ? 'vm_stat' : 'free -m';+ const memResult = await execAsync(memCmd).catch(() => ({ stdout: '' }));metrics.memory = { raw: memResult.stdout.slice(0, 500) }; // Truncate for storage// Store health check result with lock to prevent race conditions@@ -2406,11 +2413,12 @@ export async function getAgentProcessStats(agentId) {*/async function isPidAlive(pid) {if (!pid) return false;- const { execFile } = await import('child_process');- const { promisify } = await import('util');- const execFileAsync = promisify(execFile);- const result = await execFileAsync('ps', ['-p', String(pid), '-o', 'pid=']).catch(() => ({ stdout: '' }));- return result.stdout.trim() !== '';+ try {+ process.kill(pid, 0);+ return true;+ } catch {+ return false;+ }}/**diff --git a/server/services/subAgentSpawner.js b/server/services/subAgentSpawner.jsindex 36d35ff5da..130537ba66 100644--- a/server/services/subAgentSpawner.js+++ b/server/services/subAgentSpawner.js@@ -310,10 +310,15 @@ function checkForTaskCommit(taskId, workspacePath = ROOT_DIR) {const gitDir = join(workspacePath, '.git');if (!existsSync(gitDir)) return false;- const searchPattern = `[task-${taskId}]`;- const gitLogCmd = `git log --all --oneline --grep="${searchPattern}" -1 2>/dev/null || true`;- const result = execSync(gitLogCmd, { cwd: workspacePath, encoding: 'utf-8' }).trim();- return result.length > 0;+ try {+ const searchPattern = `[task-${taskId}]`;+ const result = execSync(`git log --all --oneline --grep="${searchPattern}" -1`, {+ cwd: workspacePath, encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe']+ }).trim();+ return result.length > 0;+ } catch {+ return false;+ }}/**@@ -2877,12 +2882,15 @@ export async function getAgentProcessStats(agentId) {return null;}- // Get process stats using ps command+ // Get process statsconst { exec } = await import('child_process');const { promisify } = await import('util');const execAsync = promisify(exec);- const result = await execAsync(`ps -p ${agent.pid} -o pid=,pcpu=,rss=,state= 2>/dev/null`).catch(() => ({ stdout: '' }));+ const psCmd = process.platform === 'win32'+ ? `tasklist /FI "PID eq ${agent.pid}" /FO CSV /NH`+ : `ps -p ${agent.pid} -o pid=,pcpu=,rss=,state=`;+ const result = await execAsync(psCmd).catch(() => ({ stdout: '' }));const line = result.stdout.trim();if (!line) {@@ -2932,11 +2940,12 @@ const MAX_TASK_RETRIES = 3;*/async function isPidAlive(pid) {if (!pid) return false;- const { exec } = await import('child_process');- const { promisify } = await import('util');- const execAsync = promisify(exec);- const result = await execAsync(`ps -p ${pid} -o pid= 2>/dev/null`).catch(() => ({ stdout: '' }));- return result.stdout.trim() !== '';+ try {+ process.kill(pid, 0);+ return true;+ } catch {+ return false;+ }}/**