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: use update.sh for auto-updates instead of portos-update.sh
Adam Eivy1e212fd18460
diff --git a/client/src/components/apps/tabs/UpdateTab.jsx b/client/src/components/apps/tabs/UpdateTab.jsxindex c4b837a3be..81a00aa92c 100644--- a/client/src/components/apps/tabs/UpdateTab.jsx+++ b/client/src/components/apps/tabs/UpdateTab.jsx@@ -8,8 +8,8 @@ import socket from '../../../services/socket';const STEP_LABELS = {starting: 'Starting update',- 'git-fetch': 'Fetching tags',- 'git-checkout': 'Checking out release',+ 'git-pull': 'Pulling latest changes',+ 'pm2-stop': 'Stopping apps','npm-install': 'Installing dependencies',migrations: 'Running migrations',build: 'Building client',diff --git a/scripts/portos-update.sh b/scripts/portos-update.shdeleted file mode 100755index 52f76c519f..0000000000--- a/scripts/portos-update.sh+++ /dev/null@@ -1,76 +0,0 @@-#!/usr/bin/env bash-set -euo pipefail--# Ignore SIGPIPE: when PM2 restarts the server mid-update (watch detects-# git-checkout file changes), the parent Node process dies and our stdout-# pipe breaks. Without this trap, SIGPIPE kills the script before-# `|| true` can fire, leaving the update incomplete.-trap '' PIPE--# PortOS Auto-Update Script-# Usage: bash scripts/portos-update.sh <tag>-# Outputs structured STEP markers for progress tracking:-# STEP:name:status:message--TAG="${1:?Usage: portos-update.sh <tag>}"-SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"-ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"-mkdir -p "$ROOT_DIR/data"-LOG_FILE="$ROOT_DIR/data/update.log"--cd "$ROOT_DIR"--# Log helper-log() {- echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] $*" >> "$LOG_FILE"- echo "$*" || true-}--# Step output helper-step() {- local name="$1" status="$2" message="$3"- log "STEP:$name:$status:$message"-}--log "=== PortOS update to $TAG started ==="--# Step 1: Git fetch-step "git-fetch" "running" "Fetching tags from origin..."-git fetch origin --tags >> "$LOG_FILE" 2>&1-step "git-fetch" "done" "Tags fetched"--# Step 2: Git checkout-step "git-checkout" "running" "Checking out $TAG..."-git checkout "$TAG" >> "$LOG_FILE" 2>&1-step "git-checkout" "done" "Checked out $TAG"--# Step 3: npm install (root + client + server + setup)-step "npm-install" "running" "Installing all dependencies..."-npm run install:all >> "$LOG_FILE" 2>&1-step "npm-install" "done" "Dependencies installed"--# Step 4: Migrations-step "migrations" "running" "Running data migrations..."-if [ -f "$ROOT_DIR/scripts/run-migrations.js" ]; then- node "$ROOT_DIR/scripts/run-migrations.js" >> "$LOG_FILE" 2>&1-fi-step "migrations" "done" "Migrations complete"--# Step 5: Build client-step "build" "running" "Building client..."-npm run build --prefix client >> "$LOG_FILE" 2>&1-step "build" "done" "Client built"--# Step 6: Restart via PM2-step "restart" "running" "Restarting PortOS..."--log "=== PortOS update to $TAG restarting ==="--# Write completion marker atomically before restart so server reads it on boot-echo "{\"version\":\"${TAG#v}\",\"completedAt\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" > "$ROOT_DIR/data/update-complete.json.tmp"-mv "$ROOT_DIR/data/update-complete.json.tmp" "$ROOT_DIR/data/update-complete.json"--# Use the local pm2 binary to restart-node "$ROOT_DIR/node_modules/pm2/bin/pm2" restart ecosystem.config.cjs >> "$LOG_FILE" 2>&1--step "restart" "done" "PortOS restarted"diff --git a/server/routes/update.js b/server/routes/update.jsindex 3a8f308528..bfdafdd7dd 100644--- a/server/routes/update.js+++ b/server/routes/update.js@@ -52,11 +52,6 @@ router.post('/execute', asyncHandler(async (req, res) => {throw new ServerError('Invalid release tag format', { status: 400, code: 'INVALID_TAG' });}- // Reject unsupported platforms before locking, so the flag isn't left stuck- if (process.platform === 'win32') {- throw new ServerError('Auto-update is not supported on Windows', { status: 400, code: 'UNSUPPORTED_PLATFORM' });- }-// Atomic check-and-set: rejects if already in progress, preventing concurrent updatesconst acquired = await updateChecker.setUpdateInProgress(true);if (!acquired) {diff --git a/server/services/updateExecutor.js b/server/services/updateExecutor.jsindex c2bd50ff15..965b522b5a 100644--- a/server/services/updateExecutor.js+++ b/server/services/updateExecutor.js@@ -3,29 +3,27 @@ import { join } from 'path';import { PATHS } from '../lib/fileUtils.js';import { recordUpdateResult } from './updateChecker.js';-const SCRIPT_PATH = join(PATHS.root, 'scripts', 'portos-update.sh');+const UPDATE_SH = join(PATHS.root, 'update.sh');+const UPDATE_PS1 = join(PATHS.root, 'update.ps1');/*** Execute the PortOS update script for a given release tag.- * Spawns the script detached so it survives the Node process dying.+ * Spawns update.sh (or update.ps1 on Windows) detached so it survives+ * the Node process dying during the PM2 restart phase.** @param {string} tag - The git tag to update to (e.g. "v1.27.0")* @param {function} emit - Callback (step, status, message) for progress* @returns {Promise<{success: boolean, failedStep?: string, errorMessage?: string}>}*/export async function executeUpdate(tag, emit) {- if (process.platform === 'win32') {- const msg = 'Auto-update execution is not supported on Windows — the update script requires bash';- emit('starting', 'error', msg);- return { success: false, failedStep: 'starting', errorMessage: msg };- }+ const isWindows = process.platform === 'win32';+ const cmd = isWindows ? 'powershell' : 'bash';+ const args = isWindows ? ['-ExecutionPolicy', 'Bypass', '-File', UPDATE_PS1] : [UPDATE_SH];- // The route sets updateInProgress synchronously before calling us,- // so skip the redundant write here (it's already true)emit('starting', 'running', `Starting update to ${tag}...`);return new Promise((resolve) => {- const child = spawn('bash', [SCRIPT_PATH, tag], {+ const child = spawn(cmd, args, {detached: true,stdio: ['ignore', 'pipe', 'pipe'],cwd: PATHS.rootdiff --git a/server/services/updateExecutor.test.js b/server/services/updateExecutor.test.jsindex a7b6807b6b..99c613af35 100644--- a/server/services/updateExecutor.test.js+++ b/server/services/updateExecutor.test.js@@ -31,14 +31,22 @@ beforeEach(() => {});describe('executeUpdate', () => {- it('returns failure on Windows', async () => {+ it('spawns powershell on Windows', async () => {const originalPlatformDescriptor = Object.getOwnPropertyDescriptor(process, 'platform');try {Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });- const emits = [];- const result = await executeUpdate('v1.0.0', (...args) => emits.push(args));- expect(result.success).toBe(false);- expect(emits[0][1]).toBe('error');+ const child = createMockChild();+ spawn.mockReturnValue(child);++ const promise = executeUpdate('v1.0.0', () => {});+ child.emit('close', 0);+ await promise;++ expect(spawn).toHaveBeenCalledWith(+ 'powershell',+ expect.arrayContaining(['-ExecutionPolicy', 'Bypass', '-File']),+ expect.any(Object)+ );} finally {if (originalPlatformDescriptor) {Object.defineProperty(process, 'platform', originalPlatformDescriptor);@@ -54,16 +62,15 @@ describe('executeUpdate', () => {const promise = executeUpdate('v1.0.0', (...args) => emits.push(args));// Simulate STEP output- child.stdout.emit('data', Buffer.from('STEP:git-fetch:running:Fetching tags\n'));- child.stdout.emit('data', Buffer.from('STEP:git-fetch:done:Tags fetched\n'));+ child.stdout.emit('data', Buffer.from('STEP:git-pull:running:Pulling latest changes\n'));+ child.stdout.emit('data', Buffer.from('STEP:git-pull:done:Latest changes pulled\n'));child.emit('close', 0);const result = await promise;expect(result.success).toBe(true);- // Should have starting + git-fetch running + git-fetch done = 3 step emits- expect(emits.some(e => e[0] === 'git-fetch' && e[1] === 'running')).toBe(true);- expect(emits.some(e => e[0] === 'git-fetch' && e[1] === 'done')).toBe(true);+ expect(emits.some(e => e[0] === 'git-pull' && e[1] === 'running')).toBe(true);+ expect(emits.some(e => e[0] === 'git-pull' && e[1] === 'done')).toBe(true);});it('records update result on close', async () => {diff --git a/update.ps1 b/update.ps1index bb5fa42876..4ddd0ca5ba 100644--- a/update.ps1+++ b/update.ps1@@ -1,11 +1,21 @@# PortOS Update Script for Windows PowerShell$ErrorActionPreference = "Stop"+$RootDir = Split-Path -Parent $MyInvocation.MyCommand.Path+Set-Location $RootDir+New-Item -ItemType Directory -Force -Path "$RootDir\data" | Out-Null+Write-Host "===================================" -ForegroundColor CyanWrite-Host " PortOS Update" -ForegroundColor CyanWrite-Host "===================================" -ForegroundColor CyanWrite-Host ""+# Step output helper (parsed by updateExecutor for UI progress)+function Step {+ param([string]$Name, [string]$Status, [string]$Message)+ Write-Host "STEP:${Name}:${Status}:${Message}"+}+# Resilient npm install — retries once after cleaning node_modules on failurefunction Safe-Install {param([string]$Dir = ".", [string]$Label = "root")@@ -30,18 +40,20 @@ function Safe-Install {}# Pull latest-Write-Host "Pulling latest changes..." -ForegroundColor Yellow+Step "git-pull" "running" "Pulling latest changes..."git pull --rebase --autostashif ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+Step "git-pull" "done" "Latest changes pulled"Write-Host ""# Stop PM2 apps to release file locks before updating-Write-Host "Stopping PortOS apps..." -ForegroundColor Yellow+Step "pm2-stop" "running" "Stopping PortOS apps..."npm run pm2:stop 2>$null+Step "pm2-stop" "done" "Apps stopped"Write-Host ""# Update dependencies with retry logic-Write-Host "Updating dependencies..." -ForegroundColor Yellow+Step "npm-install" "running" "Installing all dependencies..."Safe-Install -Dir "." -Label "root"Safe-Install -Dir "client" -Label "client"Safe-Install -Dir "server" -Label "server"@@ -53,6 +65,7 @@ if (-not (Test-Path "client/node_modules/vite/bin/vite.js")) {Write-Host " Try running: npm run install:all"exit 1}+Step "npm-install" "done" "Dependencies installed"# Run setup (data dirs + browser deps)Write-Host "Ensuring data & browser setup..." -ForegroundColor Yellow@@ -64,6 +77,15 @@ Write-Host ""node scripts/setup-ghostty.jsWrite-Host ""+# Run data migrations+Step "migrations" "running" "Running data migrations..."+$migrationsScript = Join-Path $RootDir "scripts\run-migrations.js"+if (Test-Path $migrationsScript) {+ node $migrationsScript+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+}+Step "migrations" "done" "Migrations complete"+# Check for slash-do (optional, used by the PR Reviewer schedule task)$slashDoFound = Get-Command slash-do -ErrorAction SilentlyContinueif (-not $slashDoFound) {@@ -86,15 +108,24 @@ if (-not $slashDoFound) {}# Build UI assets for production serving-Write-Host "Building UI assets..." -ForegroundColor Yellow+Step "build" "running" "Building client..."npm run buildif ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+Step "build" "done" "Client built"Write-Host ""+# Write completion marker atomically before restart so server reads it on boot+$Tag = (Get-Content package.json | ConvertFrom-Json).version+$completedAt = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")+$marker = "{`"version`":`"$Tag`",`"completedAt`":`"$completedAt`"}"+$marker | Out-File -Encoding utf8 -FilePath "$RootDir\data\update-complete.json.tmp"+Move-Item -Force "$RootDir\data\update-complete.json.tmp" "$RootDir\data\update-complete.json"+# Restart PM2 apps-Write-Host "Restarting PortOS..." -ForegroundColor Yellow+Step "restart" "running" "Restarting PortOS..."npm run pm2:restartif ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+Step "restart" "done" "PortOS restarted"Write-Host ""Write-Host "===================================" -ForegroundColor Greendiff --git a/update.sh b/update.shindex 9ef2e7866f..0996f47a59 100755--- a/update.sh+++ b/update.sh@@ -1,11 +1,25 @@#!/bin/bash-set -e+set -euo pipefail++# Ignore SIGPIPE: when PM2 restarts the server mid-update (watch detects+# git changes), the parent Node process dies and our stdout pipe breaks.+trap '' PIPE++ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"+cd "$ROOT_DIR"+mkdir -p "$ROOT_DIR/data"echo "==================================="echo " PortOS Update"echo "==================================="echo ""+# Step output helper (parsed by updateExecutor for UI progress)+step() {+ local name="$1" status="$2" message="$3"+ echo "STEP:$name:$status:$message"+}+# Resilient npm install — retries once after cleaning node_modules on failure# Handles ENOTEMPTY and other transient npm bugssafe_install() {@@ -29,17 +43,19 @@ safe_install() {}# Pull latest-echo "Pulling latest changes..."+step "git-pull" "running" "Pulling latest changes..."git pull --rebase --autostash+step "git-pull" "done" "Latest changes pulled"echo ""# Stop PM2 apps to release file locks before updating-echo "Stopping PortOS apps..."+step "pm2-stop" "running" "Stopping PortOS apps..."npm run pm2:stop 2>/dev/null || true+step "pm2-stop" "done" "Apps stopped"echo ""# Update dependencies with retry logic-echo "Updating dependencies..."+step "npm-install" "running" "Installing all dependencies..."safe_install .safe_install clientsafe_install server@@ -51,6 +67,7 @@ if [ ! -f "client/node_modules/vite/bin/vite.js" ]; thenecho " Try running: npm run install:all"exit 1fi+step "npm-install" "done" "Dependencies installed"# Run setup (data dirs + browser deps)echo "Ensuring data & browser setup..."@@ -61,6 +78,13 @@ echo ""node scripts/setup-ghostty.jsecho ""+# Run data migrations+step "migrations" "running" "Running data migrations..."+if [ -f "$ROOT_DIR/scripts/run-migrations.js" ]; then+ node "$ROOT_DIR/scripts/run-migrations.js"+fi+step "migrations" "done" "Migrations complete"+# Check for slash-do (optional, used by the PR Reviewer schedule task)if ! command -v slash-do >/dev/null 2>&1; thenecho "slash-do is not installed. It is used by the PR Reviewer schedule task."@@ -82,13 +106,20 @@ if ! command -v slash-do >/dev/null 2>&1; thenfi# Build UI assets for production serving-echo "Building UI assets..."+step "build" "running" "Building client..."npm run build+step "build" "done" "Client built"echo ""+# Write completion marker atomically before restart so server reads it on boot+TAG=$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' package.json | head -1)+echo "{\"version\":\"${TAG}\",\"completedAt\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" > "$ROOT_DIR/data/update-complete.json.tmp"+mv "$ROOT_DIR/data/update-complete.json.tmp" "$ROOT_DIR/data/update-complete.json"+# Restart PM2 apps-echo "Restarting PortOS..."+step "restart" "running" "Restarting PortOS..."npm run pm2:restart+step "restart" "done" "PortOS restarted"echo ""echo "==================================="