Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix: Add preinstall/preuninstall cleanup for npm ENOTEMPTY error
trohitg5880d8b4b7ef
diff --git a/package.json b/package.jsonindex 07319f6f..d09a0353 100644--- a/package.json+++ b/package.json@@ -94,7 +94,9 @@"daemon:restart": "node scripts/daemon.js restart","version:sync": "node scripts/sync-version.js","prepublishOnly": "node scripts/sync-version.js && node -e \"const p=require('./package.json'); if(!p.bin||!p.version){process.exit(1)}\"",- "postinstall": "node scripts/postinstall.js"+ "preinstall": "node scripts/preinstall.js",+ "postinstall": "node scripts/postinstall.js",+ "preuninstall": "node scripts/preinstall.js"},"dependencies": {"whatsapp-rpc": "^0.0.10",diff --git a/scripts/preinstall.js b/scripts/preinstall.jsnew file mode 100755index 00000000..ffac9ad9--- /dev/null+++ b/scripts/preinstall.js@@ -0,0 +1,67 @@+#!/usr/bin/env node+/**+ * Preinstall cleanup script for MachinaOS.+ *+ * Fixes npm ENOTEMPTY error by cleaning up leftover temp directories+ * that npm fails to remove during failed install/uninstall operations.+ *+ * @see https://github.com/anthropics/claude-code/issues/7373+ * @see https://bobbyhadz.com/blog/npm-err-code-enotempty+ */+import { readdirSync, rmSync, statSync } from 'fs';+import { resolve, dirname } from 'path';+import { fileURLToPath } from 'url';+import { execSync } from 'child_process';++const __dirname = dirname(fileURLToPath(import.meta.url));++// Skip in CI+if (process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true') {+ process.exit(0);+}++function getGlobalNodeModules() {+ try {+ const prefix = execSync('npm config get prefix', {+ encoding: 'utf-8',+ stdio: ['pipe', 'pipe', 'pipe']+ }).trim();++ if (prefix) {+ return process.platform === 'win32'+ ? resolve(prefix, 'node_modules')+ : resolve(prefix, 'lib', 'node_modules');+ }+ } catch {+ // Ignore+ }+ return null;+}++function cleanup() {+ const nodeModules = getGlobalNodeModules();+ if (!nodeModules) return;++ try {+ const entries = readdirSync(nodeModules);++ // Clean .machinaos-* temp directories+ for (const name of entries) {+ if (name.startsWith('.machinaos-')) {+ const fullPath = resolve(nodeModules, name);+ try {+ if (statSync(fullPath).isDirectory()) {+ rmSync(fullPath, { recursive: true, force: true });+ console.log(`Cleaned: ${name}`);+ }+ } catch {+ // Ignore+ }+ }+ }+ } catch {+ // Can't read node_modules - that's fine+ }+}++cleanup();