From b77c2967b415da67f45fc77d386d2e340687c3ca Mon Sep 17 00:00:00 2001 From: rUv Date: Fri, 24 Oct 2025 19:30:39 +0000 Subject: [PATCH] fix: Add automatic AgentDB import extension patch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes ERR_MODULE_NOT_FOUND error when using npx claude-flow@alpha ## Problem AgentDB v1.3.9 has missing .js extensions in controller imports: ```javascript // node_modules/agentdb/dist/controllers/index.js export { ReflexionMemory } from './ReflexionMemory'; // ❌ Missing .js ``` This causes MODULE_NOT_FOUND errors in ESM environments, especially when using npx which gets fresh installs without local patches. ## Solution Added automatic postinstall patch that fixes AgentDB imports: 1. **patches/agentdb-fix-imports.patch** - Patch definition 2. **scripts/fix-agentdb-imports.sh** - Auto-apply script 3. **package.json** - Updated postinstall to run fix The fix is applied automatically on: - npm install - npm update - npx claude-flow@alpha (fresh installs) ## Changes - Added patches/agentdb-fix-imports.patch - Added scripts/fix-agentdb-imports.sh (executable) - Updated package.json postinstall script ## Testing ✅ Verified locally with npx claude-flow@alpha memory list ✅ Import errors resolved ✅ All memory commands working ## Note This is a temporary workaround until agentdb@1.3.9 is fixed upstream. The patch adds .js extensions to ESM imports: - ReflexionMemory.js - SkillLibrary.js - EmbeddingService.js 🚀 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- package.json | 2 +- patches/agentdb-fix-imports.patch | 12 ++++++++++++ scripts/fix-agentdb-imports.sh | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 patches/agentdb-fix-imports.patch create mode 100755 scripts/fix-agentdb-imports.sh diff --git a/package.json b/package.json index 3db84836a4..162ac3371f 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "format": "prettier --write 'src/**/*.{ts,js,json}'", "diagnostics": "node -e \"import('./dist/monitoring/diagnostics.js').then(m => m.DiagnosticManager.quickDiagnostic().then(console.log))\"", "health-check": "node -e \"import('./dist/monitoring/health-check.js').then(m => new m.HealthCheckManager().performHealthCheck().then(console.log))\"", - "postinstall": "node scripts/install-arm64.js", + "postinstall": "node scripts/install-arm64.js && bash scripts/fix-agentdb-imports.sh", "prepublishOnly": "npm run update-version", "publish:alpha": "npm publish --tag alpha", "publish:major": "npm version major && npm publish", diff --git a/patches/agentdb-fix-imports.patch b/patches/agentdb-fix-imports.patch new file mode 100644 index 0000000000..9d98c068ab --- /dev/null +++ b/patches/agentdb-fix-imports.patch @@ -0,0 +1,12 @@ +--- a/node_modules/agentdb/dist/controllers/index.js ++++ b/node_modules/agentdb/dist/controllers/index.js +@@ -3,6 +3,6 @@ + * + * Export all memory controllers for agent systems + */ +-export { ReflexionMemory } from './ReflexionMemory'; +-export { SkillLibrary } from './SkillLibrary'; +-export { EmbeddingService } from './EmbeddingService'; ++export { ReflexionMemory } from './ReflexionMemory.js'; ++export { SkillLibrary } from './SkillLibrary.js'; ++export { EmbeddingService } from './EmbeddingService.js'; diff --git a/scripts/fix-agentdb-imports.sh b/scripts/fix-agentdb-imports.sh new file mode 100755 index 0000000000..a0e25733ad --- /dev/null +++ b/scripts/fix-agentdb-imports.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Fix AgentDB missing .js extensions in imports +# This is a workaround until agentdb@1.3.9 is fixed upstream + +AGENTDB_INDEX="node_modules/agentdb/dist/controllers/index.js" + +if [ -f "$AGENTDB_INDEX" ]; then + echo "🔧 Fixing AgentDB import extensions..." + + # Fix missing .js extensions + sed -i "s/from '\.\/ReflexionMemory'/from '.\/ReflexionMemory.js'/g" "$AGENTDB_INDEX" + sed -i "s/from '\.\/SkillLibrary'/from '.\/SkillLibrary.js'/g" "$AGENTDB_INDEX" + sed -i "s/from '\.\/EmbeddingService'/from '.\/EmbeddingService.js'/g" "$AGENTDB_INDEX" + + echo "✅ AgentDB imports fixed" +else + echo "⚠️ AgentDB not installed, skipping patch" +fi