From 43ab723db6e6edd77c6a3be5b3d4eeff224c98cd Mon Sep 17 00:00:00 2001 From: rUv Date: Mon, 28 Jul 2025 21:43:51 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Enhanced=20hooks=20pre-ta?= =?UTF-8?q?sk=20exit=20with=20timeout=20protection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added timeout protection for ruv-swarm availability check (3s) - Fallback to skip ruv-swarm hook if timeout occurs - Force process exit with setTimeout to prevent hanging - Handles npx remote execution scenarios properly This addresses the hanging issue when running: npx claude-flow@alpha hooks pre-task --description "task" šŸ¤– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- bin/claude-flow | 2 +- bin/claude-flow.js | 2 +- package.json | 2 +- src/cli/help-text.js | 4 +-- src/cli/simple-commands/hooks.js | 62 ++++++++++++++++++++------------ 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/bin/claude-flow b/bin/claude-flow index 5fa0a04e77..08fe38fee5 100755 --- a/bin/claude-flow +++ b/bin/claude-flow @@ -1,7 +1,7 @@ #!/bin/sh # Claude-Flow Smart Dispatcher - Detects and uses the best available runtime -VERSION="2.0.0-alpha.76" +VERSION="2.0.0-alpha.77" # Determine the correct path based on how the script is invoked if [ -L "$0" ]; then diff --git a/bin/claude-flow.js b/bin/claude-flow.js index 7246b5d252..7a24b5c84c 100644 --- a/bin/claude-flow.js +++ b/bin/claude-flow.js @@ -11,7 +11,7 @@ import { existsSync } from 'fs'; import { spawn } from 'child_process'; import process from 'process'; -const VERSION = "2.0.0-alpha.76"; +const VERSION = "2.0.0-alpha.77"; // Get script directory and root directory const __filename = fileURLToPath(import.meta.url); diff --git a/package.json b/package.json index ee4177ba79..a6eaf27596 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "claude-flow", - "version": "2.0.0-alpha.76", + "version": "2.0.0-alpha.77", "description": "Enterprise-grade AI agent orchestration with ruv-swarm integration (Alpha Release)", "main": "cli.mjs", "bin": { diff --git a/src/cli/help-text.js b/src/cli/help-text.js index 4f7d7bae1f..442f8ca502 100644 --- a/src/cli/help-text.js +++ b/src/cli/help-text.js @@ -5,14 +5,14 @@ import { HelpFormatter } from './help-formatter.js'; -export const VERSION = '2.0.0-alpha.76'; +export const VERSION = '2.0.0-alpha.77'; export const MAIN_HELP = ` 🌊 Claude-Flow v${VERSION} - Enterprise-Grade AI Agent Orchestration Platform šŸŽÆ ENTERPRISE FEATURES: Complete ruv-swarm integration with 87 MCP tools, neural networking, and production-ready infrastructure šŸ NEW: Advanced Hive Mind System with Queen-led coordination, collective intelligence, and unlimited scaling -⚔ ALPHA 76: Fixed hooks pre-task command not exiting properly +⚔ ALPHA 77: Enhanced hooks pre-task exit handling with timeout protection USAGE: claude-flow [options] diff --git a/src/cli/simple-commands/hooks.js b/src/cli/simple-commands/hooks.js index 3276b6ef67..93ef3d9233 100644 --- a/src/cli/simple-commands/hooks.js +++ b/src/cli/simple-commands/hooks.js @@ -137,29 +137,40 @@ async function preTaskCommand(subArgs, flags) { console.log(` šŸ’¾ Saved to .swarm/memory.db`); - // Execute ruv-swarm hook if available - const isAvailable = await checkRuvSwarmAvailable(); - if (isAvailable) { - console.log(`\nšŸ”„ Executing ruv-swarm pre-task hook...`); - const hookResult = await execRuvSwarmHook('pre-task', { - description, - 'task-id': taskId, - 'auto-spawn-agents': autoSpawnAgents, - ...(agentId ? { 'agent-id': agentId } : {}), - }); + // Execute ruv-swarm hook if available (with timeout for npx scenarios) + try { + const checkPromise = checkRuvSwarmAvailable(); + const timeoutPromise = new Promise((_, reject) => + setTimeout(() => reject(new Error('Timeout')), 3000) + ); + + const isAvailable = await Promise.race([checkPromise, timeoutPromise]); + + if (isAvailable) { + console.log(`\nšŸ”„ Executing ruv-swarm pre-task hook...`); + const hookResult = await execRuvSwarmHook('pre-task', { + description, + 'task-id': taskId, + 'auto-spawn-agents': autoSpawnAgents, + ...(agentId ? { 'agent-id': agentId } : {}), + }); - if (hookResult.success) { - await store.store( - `task:${taskId}:ruv-output`, - { - output: hookResult.output, - timestamp: new Date().toISOString(), - }, - { namespace: 'hooks:ruv-swarm' }, - ); + if (hookResult.success) { + await store.store( + `task:${taskId}:ruv-output`, + { + output: hookResult.output, + timestamp: new Date().toISOString(), + }, + { namespace: 'hooks:ruv-swarm' }, + ); - printSuccess(`āœ… Pre-task hook completed successfully`); + printSuccess(`āœ… Pre-task hook completed successfully`); + } } + } catch (err) { + // Skip ruv-swarm hook if it times out or fails + console.log(`\nāš ļø Skipping ruv-swarm hook (${err.message})`); } console.log(`\nšŸŽÆ TASK PREPARATION COMPLETE`); @@ -169,8 +180,10 @@ async function preTaskCommand(subArgs, flags) { memoryStore.close(); } - // Ensure the process exits cleanly - process.exit(0); + // Force exit after a short delay to ensure cleanup + setTimeout(() => { + process.exit(0); + }, 100); } catch (err) { printError(`Pre-task hook failed: ${err.message}`); @@ -179,7 +192,10 @@ async function preTaskCommand(subArgs, flags) { memoryStore.close(); } - process.exit(1); + // Force exit after a short delay to ensure cleanup + setTimeout(() => { + process.exit(1); + }, 100); } }