From a703fdbe6471683ea5f87faa8fee25d7b60981eb Mon Sep 17 00:00:00 2001 From: rUv Date: Mon, 14 Jul 2025 11:15:20 -0400 Subject: [PATCH] fix: Claude Code 1.0.51+ hooks compatibility and migration command (#247) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: update hooks format for Claude Code 1.0.51+ compatibility - Changed hooks from object format to array format (PreToolUse, PostToolUse, Stop) - Added migration script for existing users - Updated settings.json template in init command - Removed unsupported fields (mcpServers, features, performance) - Added @alpha tag to npx commands in hooks Fixes #235 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * feat: implement hive-mind resume functionality (alpha.50) - Add HiveMindSessionManager for session persistence - Implement auto-save middleware with 30-second intervals - Add 'hive-mind resume ' command - Add 'hive-mind sessions' command to list sessions - Integrate session tracking into spawn workflow - Add comprehensive test suite (80+ tests) - Update documentation and fix README - Bump version to 2.0.0-alpha.50 Fixes #232 🤖 Generated with Claude Code Co-Authored-By: Claude * chore: bump version to 2.0.0-alpha.51 - Update version strings in all CLI files - Prepare for npm publication 🤖 Generated with Claude Code Co-Authored-By: Claude * feat: add migrate-hooks command and bump to alpha.52 - Added migrate-hooks CLI command to migrate settings.json format - Wraps the migration script for easy CLI access - Updated version to 2.0.0-alpha.52 - Added command to help text and registry Addresses issue #235 and discussion #237 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * docs: add release notes for alpha.52 - Document hooks format migration - List all fixes and acknowledgments - Provide upgrade instructions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * fix: Claude Code 1.0.51+ hooks compatibility and migration command - Updated hooks format from object to array structure for Claude Code 1.0.51+ - Added migrate-hooks CLI command for automatic migration - Fixed MCP server fallback issues caused by invalid settings - Removed unsupported fields (mcpServers, features, performance) - Updated templates to generate correct settings format - Added migration script with backup functionality Fixes #235, #236, #237 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --------- Co-authored-by: Claude --- RELEASE_NOTES_ALPHA52.md | 109 +++++++++++++++++++ bin/claude-flow | 2 +- docker-test/test-fallback-alpha51.dockerfile | 28 +++++ docker-test/test-ubuntu-fallback.dockerfile | 25 +++++ package.json | 2 +- src/cli/command-registry.js | 3 + src/cli/help-text.js | 3 +- src/cli/simple-commands/migrate-hooks.js | 64 +++++++++++ test-fallback-simulation.js | 48 ++++++++ test-fallback-simulation.mjs | 56 ++++++++++ 10 files changed, 337 insertions(+), 3 deletions(-) create mode 100644 RELEASE_NOTES_ALPHA52.md create mode 100644 docker-test/test-fallback-alpha51.dockerfile create mode 100644 docker-test/test-ubuntu-fallback.dockerfile create mode 100644 src/cli/simple-commands/migrate-hooks.js create mode 100755 test-fallback-simulation.js create mode 100755 test-fallback-simulation.mjs diff --git a/RELEASE_NOTES_ALPHA52.md b/RELEASE_NOTES_ALPHA52.md new file mode 100644 index 0000000000..7c91862b0f --- /dev/null +++ b/RELEASE_NOTES_ALPHA52.md @@ -0,0 +1,109 @@ +# Claude Flow v2.0.0-alpha.52 Release Notes + +## 🎉 Critical Fix for Claude Code 1.0.51+ Compatibility + +This release addresses the breaking changes introduced in Claude Code 1.0.51 that affected hooks configuration and settings validation. + +## ✨ What's New + +### 🔧 Hooks Format Migration + +**New `migrate-hooks` Command** +- Automatically converts old hook format to new Claude Code 1.0.51+ format +- Creates backups before making changes +- Removes unsupported fields (mcpServers, features, performance) +- Searches common locations automatically + +```bash +# Update to latest alpha +npm install -g claude-flow@alpha + +# Run the migration +claude-flow migrate-hooks + +# Or with npx +npx claude-flow@alpha migrate-hooks +``` + +### 🛠️ Fixed Settings Generation + +- Updated `init` command to generate correct hooks format +- New installations now create Claude Code 1.0.51+ compatible settings +- Proper array-based hooks structure with matchers + +### 📝 Hooks Format Changes + +**Old Format (No longer supported):** +```json +"hooks": { + "preEditHook": { "command": "npx", "args": [...] }, + "postEditHook": { "command": "npx", "args": [...] } +} +``` + +**New Format (Required for Claude Code 1.0.51+):** +```json +"hooks": { + "PreToolUse": [{ + "matcher": "Edit|Write", + "hooks": [{ + "type": "command", + "command": "npx claude-flow@alpha hooks pre-edit..." + }] + }] +} +``` + +## 🐛 Bug Fixes + +- Fixed hooks format incompatibility with Claude Code 1.0.51+ (#235, #236, #237) +- Updated templates to remove unrecognized fields +- Added @alpha tag to hook commands for version consistency + +## 📚 Documentation + +- Added migration instructions for existing users +- Updated documentation to reflect new hooks format +- Added troubleshooting guide for settings validation errors + +## 🙏 Acknowledgments + +Special thanks to: +- @bailejl for reporting the issue (#235, #236) +- @jimweller for the detailed analysis and PR #238 +- @guilleojeda, @pnocera, @pksorensen, and @fmal for additional insights + +## 💡 Upgrade Instructions + +1. **For Existing Users:** + ```bash + npm install -g claude-flow@alpha + claude-flow migrate-hooks + claude mcp add claude-flow npx claude-flow@alpha mcp start + ``` + +2. **For New Users:** + ```bash + npm install -g claude-flow@alpha + claude-flow init --sparc + ``` + +3. **Verify Settings:** + - Run `/doctor` in Claude Code to ensure settings are valid + - Restart Claude Code after migration + +## ⚠️ Breaking Changes + +- Removed support for object-based hooks format +- MCP servers must now be added via `claude mcp add` command +- Removed `mcpServers`, `features`, and `performance` fields from settings.json + +## 🔜 Coming Soon + +- `enabledMcpjsonServers` support for trusted MCP servers +- Enhanced version detection for future Claude Code updates +- Improved error messages for configuration issues + +--- + +For questions or issues, please visit: https://github.com/ruvnet/claude-flow/issues \ No newline at end of file diff --git a/bin/claude-flow b/bin/claude-flow index b11470fd73..d9f3bac3a0 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.50" +VERSION="2.0.0-alpha.52" # Determine the correct path based on how the script is invoked if [ -L "$0" ]; then diff --git a/docker-test/test-fallback-alpha51.dockerfile b/docker-test/test-fallback-alpha51.dockerfile new file mode 100644 index 0000000000..12bc8cac49 --- /dev/null +++ b/docker-test/test-fallback-alpha51.dockerfile @@ -0,0 +1,28 @@ +FROM node:20-alpine + +WORKDIR /app + +# Install required packages +RUN apk add --no-cache bash + +# Run test directly in RUN command to see output during build +RUN echo "=== Testing Claude Flow alpha.51 SQLite Fallback ===" && \ + echo "Node version: $(node --version)" && \ + echo "Platform: $(uname -a)" && \ + echo "" && \ + echo "1. Testing npx init command:" && \ + npx -y claude-flow@alpha init --force --project-name test-fallback && \ + echo "" && \ + echo "2. Checking if .swarm directory was created:" && \ + (ls -la .swarm/ || echo "No .swarm directory (indicates in-memory mode)") && \ + echo "" && \ + echo "3. Testing memory operations:" && \ + npx -y claude-flow@alpha memory store test-key "test-value" --namespace test && \ + npx -y claude-flow@alpha memory retrieve test-key --namespace test && \ + echo "" && \ + echo "4. Testing hive-mind commands:" && \ + npx -y claude-flow@alpha hive-mind init && \ + echo "" && \ + echo "=== Test Complete ===" + +CMD ["echo", "Docker test passed"] \ No newline at end of file diff --git a/docker-test/test-ubuntu-fallback.dockerfile b/docker-test/test-ubuntu-fallback.dockerfile new file mode 100644 index 0000000000..d9882da8ea --- /dev/null +++ b/docker-test/test-ubuntu-fallback.dockerfile @@ -0,0 +1,25 @@ +FROM node:20 + +WORKDIR /app + +# Test in Ubuntu where npx should work +RUN echo "=== Testing Claude Flow SQLite Fallback in Ubuntu ===" && \ + echo "Node version: $(node --version)" && \ + echo "NPM version: $(npm --version)" && \ + echo "" && \ + echo "1. Testing with alpha.51:" && \ + npx -y claude-flow@2.0.0-alpha.51 --version && \ + echo "" && \ + echo "2. Testing init command:" && \ + npx -y claude-flow@2.0.0-alpha.51 init --force --project-name test && \ + echo "" && \ + echo "3. Checking created files:" && \ + ls -la && \ + echo "" && \ + echo "4. Testing memory operations:" && \ + npx -y claude-flow@2.0.0-alpha.51 memory store test-key "test-value" && \ + npx -y claude-flow@2.0.0-alpha.51 memory retrieve test-key && \ + echo "" && \ + echo "=== Test Complete ===" + +CMD ["echo", "Ubuntu test passed"] \ No newline at end of file diff --git a/package.json b/package.json index b679858a6b..251f80a292 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "claude-flow", - "version": "2.0.0-alpha.51", + "version": "2.0.0-alpha.52", "description": "Enterprise-grade AI agent orchestration with ruv-swarm integration (Alpha Release)", "main": "cli.mjs", "bin": { diff --git a/src/cli/command-registry.js b/src/cli/command-registry.js index 80e98409e7..0d680fd0ac 100644 --- a/src/cli/command-registry.js +++ b/src/cli/command-registry.js @@ -22,6 +22,7 @@ import { hookSafetyCommand } from './simple-commands/hook-safety.js'; import { hiveMindCommand } from './simple-commands/hive-mind.js'; import hiveMindOptimizeCommand from './simple-commands/hive-mind-optimize.js'; import { showUnifiedMetrics, fixTaskAttribution } from './simple-commands/swarm-metrics-integration.js'; +import { migrateHooksCommand, migrateHooksCommandConfig } from './simple-commands/migrate-hooks.js'; // Note: TypeScript imports commented out for Node.js compatibility // import { ruvSwarmAction } from './commands/ruv-swarm.ts'; // import { configIntegrationAction } from './commands/config-integration.ts'; @@ -468,6 +469,8 @@ SAFE ALTERNATIVES: For more information: https://github.com/ruvnet/claude-flow/issues/166` }); + commandRegistry.set('migrate-hooks', migrateHooksCommandConfig); + commandRegistry.set('hive', { handler: async (args, flags) => { try { diff --git a/src/cli/help-text.js b/src/cli/help-text.js index 7bb2d7cedc..4764a7e7f7 100644 --- a/src/cli/help-text.js +++ b/src/cli/help-text.js @@ -3,7 +3,7 @@ * Provides clear, actionable command documentation */ -export const VERSION = '2.0.0-alpha.51'; +export const VERSION = '2.0.0-alpha.52'; export const MAIN_HELP = ` 🌊 Claude-Flow v${VERSION} - Enterprise-Grade AI Agent Orchestration Platform @@ -50,6 +50,7 @@ USAGE: analysis Performance & usage analytics (3 commands) automation Intelligent agent & workflow management (3 commands) hooks Lifecycle event management (5 commands) + migrate-hooks Migrate settings.json to Claude Code 1.0.51+ format monitoring Real-time system monitoring (3 commands) optimization Performance & topology optimization (3 commands) diff --git a/src/cli/simple-commands/migrate-hooks.js b/src/cli/simple-commands/migrate-hooks.js new file mode 100644 index 0000000000..f8efa3d36c --- /dev/null +++ b/src/cli/simple-commands/migrate-hooks.js @@ -0,0 +1,64 @@ +#!/usr/bin/env node + +/** + * CLI command wrapper for migrate-hooks script + */ + +import { execSync } from 'child_process'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { promises as fs } from 'fs'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +export async function migrateHooksCommand(flags, args) { + console.log('🔄 Claude Flow Hooks Migration\n'); + + try { + // Find the migration script + const scriptPath = path.join(__dirname, '../../../scripts/migrate-hooks.js'); + + // Check if script exists + try { + await fs.access(scriptPath); + } catch { + console.error('❌ Migration script not found. Please ensure you have the latest version.'); + process.exit(1); + } + + // Build command with any additional arguments + const command = ['node', scriptPath]; + if (args.length > 0) { + command.push(...args); + } + + // Execute the migration script + execSync(command.join(' '), { + stdio: 'inherit', + cwd: process.cwd() + }); + + } catch (error) { + console.error('❌ Migration failed:', error.message); + process.exit(1); + } +} + +// Export the command configuration +export const migrateHooksCommandConfig = { + handler: migrateHooksCommand, + description: 'Migrate settings.json hooks to Claude Code 1.0.51+ format', + usage: 'migrate-hooks [settings-file]', + examples: [ + 'claude-flow migrate-hooks # Migrate all found settings.json files', + 'claude-flow migrate-hooks .claude/settings.json # Migrate specific file' + ], + details: ` +Migrates old hooks format to new Claude Code 1.0.51+ format: + • Converts object-based hooks to array-based format + • Creates backup before making changes + • Removes unsupported fields (mcpServers, features, performance) + • Searches common locations if no file specified + +The migration is safe and creates backups of original files.` +}; \ No newline at end of file diff --git a/test-fallback-simulation.js b/test-fallback-simulation.js new file mode 100755 index 0000000000..91544f1ea6 --- /dev/null +++ b/test-fallback-simulation.js @@ -0,0 +1,48 @@ +#!/usr/bin/env node + +// Simulate missing better-sqlite3 by intercepting require +const Module = require('module'); +const originalRequire = Module.prototype.require; + +Module.prototype.require = function(id) { + if (id === 'better-sqlite3') { + throw new Error('Cannot find module \'better-sqlite3\''); + } + return originalRequire.apply(this, arguments); +}; + +// Now test the memory system +const { EnhancedMemory } = require('./src/memory/enhanced-memory.js'); + +async function testFallback() { + console.log('🧪 Testing SQLite Fallback Mechanism\n'); + + const memory = new EnhancedMemory(); + + try { + await memory.initialize(); + console.log('✅ Memory initialized successfully'); + console.log(`📊 Using fallback: ${memory.useFallback ? 'YES (in-memory)' : 'NO (SQLite)'}`); + + // Test basic operations + console.log('\n🔧 Testing memory operations:'); + + await memory.store('test-key', 'test-value', { namespace: 'test' }); + console.log('✅ Store operation successful'); + + const value = await memory.retrieve('test-key', { namespace: 'test' }); + console.log(`✅ Retrieve operation successful: ${value}`); + + const items = await memory.list({ namespace: 'test' }); + console.log(`✅ List operation successful: ${items.length} items`); + + console.log('\n🎉 All operations completed successfully!'); + console.log('💡 The fallback mechanism is working correctly.'); + + } catch (error) { + console.error('❌ Error:', error.message); + process.exit(1); + } +} + +testFallback(); \ No newline at end of file diff --git a/test-fallback-simulation.mjs b/test-fallback-simulation.mjs new file mode 100755 index 0000000000..7f02d211ff --- /dev/null +++ b/test-fallback-simulation.mjs @@ -0,0 +1,56 @@ +#!/usr/bin/env node + +import { createRequire } from 'module'; +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +// Create a require function for this ES module +const require = createRequire(import.meta.url); + +// Mock better-sqlite3 to simulate it being missing +const Module = require('module'); +const originalRequire = Module.prototype.require; + +Module.prototype.require = function(id) { + if (id === 'better-sqlite3') { + throw new Error('Cannot find module \'better-sqlite3\' - Simulating missing native module'); + } + return originalRequire.apply(this, arguments); +}; + +// Import after mocking +import('./src/memory/enhanced-memory.js').then(async ({ EnhancedMemory }) => { + console.log('🧪 Testing SQLite Fallback Mechanism\n'); + + const memory = new EnhancedMemory(); + + try { + await memory.initialize(); + console.log('✅ Memory initialized successfully'); + console.log(`📊 Using fallback: ${memory.useFallback ? 'YES (in-memory)' : 'NO (SQLite)'}`); + + // Test basic operations + console.log('\n🔧 Testing memory operations:'); + + await memory.store('test-key', 'test-value', { namespace: 'test' }); + console.log('✅ Store operation successful'); + + const value = await memory.retrieve('test-key', { namespace: 'test' }); + console.log(`✅ Retrieve operation successful: ${value}`); + + const items = await memory.list({ namespace: 'test' }); + console.log(`✅ List operation successful: ${items.length} items`); + + console.log('\n🎉 All operations completed successfully!'); + console.log('💡 The fallback mechanism is working correctly.'); + + } catch (error) { + console.error('❌ Error:', error.message); + process.exit(1); + } +}).catch(err => { + console.error('Failed to import:', err); +}); \ No newline at end of file