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

add resilient dependency installation with retry logic

[._.]/ Adam Eivy6b8161b1bbf9
diff --git a/package.json b/package.json
index 3bddc327c4..59de4fa859 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
"dev": "node scripts/dev-start.js",
"dev:stop": "node ./node_modules/pm2/bin/pm2 stop ecosystem.config.cjs",
"build": "npm run build --prefix client",
- "start": "npm run build && node scripts/setup-db.js && (node ./node_modules/pm2/bin/pm2 delete ecosystem.config.cjs --silent || echo pm2 delete skipped) && node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs && node ./node_modules/pm2/bin/pm2 save",
+ "start": "node scripts/ensure-deps.js && npm run build && node scripts/setup-db.js && (node ./node_modules/pm2/bin/pm2 delete ecosystem.config.cjs --silent || echo pm2 delete skipped) && node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs && node ./node_modules/pm2/bin/pm2 save",
"pm2:start": "node ./node_modules/pm2/bin/pm2 start ecosystem.config.cjs",
"pm2:stop": "node ./node_modules/pm2/bin/pm2 stop ecosystem.config.cjs",
"pm2:restart": "node ./node_modules/pm2/bin/pm2 restart ecosystem.config.cjs",
@@ -25,7 +25,7 @@
"setup:db": "node scripts/setup-db.js",
"setup:browser": "node scripts/setup-browser.js",
"setup:ghostty": "node scripts/setup-ghostty.js",
- "update": "npm install && npm install --prefix client && npm install --prefix server && npm run setup && npm run setup:ghostty",
+ "update": "bash update.sh",
"test": "npm test --prefix server"
},
"devDependencies": {
diff --git a/scripts/dev-start.js b/scripts/dev-start.js
index 868b4d44ed..32dcef80c4 100644
--- a/scripts/dev-start.js
+++ b/scripts/dev-start.js
@@ -22,6 +22,12 @@ function pm2(...args) {
});
}
+// Ensure dependencies are installed (handles missing node_modules, ENOTEMPTY retries)
+execFileSync(process.execPath, [join(__dirname, 'ensure-deps.js')], {
+ stdio: 'inherit',
+ windowsHide: true
+});
+
// Ensure PostgreSQL is running (gracefully skips if Docker unavailable)
execFileSync(process.execPath, [join(__dirname, 'setup-db.js')], {
stdio: 'inherit',
diff --git a/scripts/ensure-deps.js b/scripts/ensure-deps.js
new file mode 100644
index 0000000000..fac0e0bf57
--- /dev/null
+++ b/scripts/ensure-deps.js
@@ -0,0 +1,53 @@
+/**
+ * Ensures all workspace dependencies are installed before starting.
+ * Runs npm install only for workspaces with missing node_modules.
+ * Handles ENOTEMPTY npm bug by retrying with clean node_modules.
+ */
+import { existsSync, rmSync } from 'fs';
+import { execSync } from 'child_process';
+import { join, dirname } from 'path';
+import { fileURLToPath } from 'url';
+
+const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
+
+const WORKSPACES = [
+ { dir: ROOT, label: 'root' },
+ { dir: join(ROOT, 'client'), label: 'client' },
+ { dir: join(ROOT, 'server'), label: 'server' }
+];
+
+function install(dir, label) {
+ try {
+ execSync('npm install', { cwd: dir, stdio: 'inherit' });
+ return true;
+ } catch {
+ console.log(`⚠️ npm install failed for ${label} — cleaning node_modules and retrying...`);
+ rmSync(join(dir, 'node_modules'), { recursive: true, force: true });
+ try {
+ execSync('npm install', { cwd: dir, stdio: 'inherit' });
+ return true;
+ } catch {
+ console.error(`❌ npm install failed for ${label} after retry`);
+ return false;
+ }
+ }
+}
+
+let needed = false;
+for (const { dir, label } of WORKSPACES) {
+ if (!existsSync(join(dir, 'node_modules'))) {
+ console.log(`📦 Missing node_modules for ${label} — installing...`);
+ if (!install(dir, label)) process.exit(1);
+ needed = true;
+ }
+}
+
+// Verify critical binary exists even if node_modules dirs were present
+const vitePath = join(ROOT, 'client', 'node_modules', 'vite', 'bin', 'vite.js');
+if (!existsSync(vitePath)) {
+ console.log('📦 Vite not found — reinstalling client deps...');
+ if (!install(join(ROOT, 'client'), 'client')) process.exit(1);
+ needed = true;
+}
+
+if (needed) console.log('✅ Dependencies verified');
diff --git a/update.sh b/update.sh
index 67c06ae5e4..37f7e9a5b7 100755
--- a/update.sh
+++ b/update.sh
@@ -6,6 +6,28 @@ echo " PortOS Update"
echo "==================================="
echo ""
+# Resilient npm install — retries once after cleaning node_modules on failure
+# Handles ENOTEMPTY and other transient npm bugs
+safe_install() {
+ local dir="${1:-.}"
+ local label="${dir}"
+ [ "$dir" = "." ] && label="root"
+
+ echo "📦 Installing deps ($label)..."
+ if (cd "$dir" && npm install 2>&1); then
+ return 0
+ fi
+
+ echo "⚠️ npm install failed for $label — cleaning node_modules and retrying..."
+ rm -rf "$dir/node_modules"
+ if (cd "$dir" && npm install 2>&1); then
+ return 0
+ fi
+
+ echo "❌ npm install failed for $label after retry"
+ return 1
+}
+
# Pull latest
echo "Pulling latest changes..."
git pull --rebase --autostash
@@ -16,13 +38,20 @@ echo "Stopping PortOS apps..."
npm run pm2:stop 2>/dev/null || true
echo ""
-# Update dependencies
+# Update dependencies with retry logic
echo "Updating dependencies..."
-npm install
-(cd client && npm install)
-(cd server && npm install)
+safe_install .
+safe_install client
+safe_install server
echo ""
+# Verify critical dependencies exist
+if [ ! -f "client/node_modules/vite/bin/vite.js" ]; then
+ echo "❌ Critical dependency missing: client/node_modules/vite"
+ echo " Try running: npm run install:all"
+ exit 1
+fi
+
# Run setup (data dirs + browser deps)
echo "Ensuring data & browser setup..."
npm run setup
@@ -38,6 +67,6 @@ npm run pm2:restart
echo ""
echo "==================================="
-echo " Update Complete!"
+echo " ✅ Update Complete!"
echo "==================================="
echo ""