From d08dfda9179d1eddaad382c46a3ec331fbf5d89d Mon Sep 17 00:00:00 2001 From: Prateek Date: Mon, 16 Feb 2026 15:16:51 +0530 Subject: [PATCH] fix: automate node-pty rebuild to eliminate terminal issues - Add postinstall hook to automatically rebuild node-pty after pnpm install - Create scripts/rebuild-node-pty.js for automatic rebuild with error handling - Remove manual node-pty rebuild from setup.sh (now automatic) This ensures DirectTerminal works correctly on every installation without manual intervention. Fixes posix_spawnp errors from incompatible prebuilt binaries across different systems and installations. Resolves issue where users would encounter blank terminals after setup. Co-Authored-By: Claude Sonnet 4.5 --- package.json | 3 ++- scripts/rebuild-node-pty.js | 39 +++++++++++++++++++++++++++++++++++++ scripts/setup.sh | 5 ----- 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 scripts/rebuild-node-pty.js diff --git a/package.json b/package.json index b82db78a5..70aaa7220 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "changeset": "changeset", "version-packages": "changeset version", "release": "pnpm -r --filter '!@composio/ao-web' build && changeset publish", - "prepare": "husky" + "prepare": "husky", + "postinstall": "node scripts/rebuild-node-pty.js" }, "devDependencies": { "@changesets/cli": "^2.29.8", diff --git a/scripts/rebuild-node-pty.js b/scripts/rebuild-node-pty.js new file mode 100644 index 000000000..a659f9a2f --- /dev/null +++ b/scripts/rebuild-node-pty.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node +// Automatically rebuild node-pty from source after pnpm install +// This fixes DirectTerminal "posix_spawnp failed" errors from incompatible prebuilt binaries + +import { execSync } from "node:child_process"; +import { existsSync } from "node:fs"; +import { join, dirname } from "node:path"; +import { fileURLToPath } from "node:url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +const repoRoot = join(__dirname, ".."); + +// Find node-pty in pnpm node_modules +const nodePtyPath = join( + repoRoot, + "node_modules/.pnpm/node-pty@1.1.0/node_modules/node-pty", +); + +if (!existsSync(nodePtyPath)) { + console.log("â„šī¸ node-pty not found, skipping rebuild"); + process.exit(0); +} + +console.log("🔧 Rebuilding node-pty from source..."); + +try { + execSync("npx node-gyp rebuild", { + cwd: nodePtyPath, + stdio: "inherit", + }); + console.log("✅ node-pty rebuilt successfully"); +} catch (error) { + console.warn("âš ī¸ node-pty rebuild failed (non-critical)"); + console.warn(" DirectTerminal may not work correctly"); + console.warn(" Run manually: cd node_modules/.pnpm/node-pty@1.1.0/node_modules/node-pty && npx node-gyp rebuild"); + // Don't fail the install - node-pty rebuild failure is non-critical + process.exit(0); +} diff --git a/scripts/setup.sh b/scripts/setup.sh index 9f56d63a6..2d495a38c 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -19,11 +19,6 @@ pnpm install echo "🔨 Building all packages..." pnpm build -echo "🔧 Rebuilding node-pty from source (fixes DirectTerminal)..." -cd node_modules/.pnpm/node-pty@1.1.0/node_modules/node-pty -npx node-gyp rebuild > /dev/null 2>&1 || echo "âš ī¸ node-pty rebuild failed (non-critical)" -cd ../../../../.. - echo "🔗 Linking CLI globally..." cd packages/cli npm link