Skip to content

Conversation

@adambkovacs
Copy link

Summary

  • Fixes the __dirname is not defined error in AgentDB CLI when running as an ES module
  • Adds standard ESM polyfill using fileURLToPath and dirname from Node.js built-in modules

Problem

The agentic-flow/src/agentdb/cli/agentdb-cli.ts file uses __dirname (line 62) but runs as an ES module where __dirname is not available. This causes all MCP tools that rely on the CLI to fail:

❌ __dirname is not defined

Affected tools:

  • agentdb_stats
  • agentdb_pattern_store
  • agentdb_pattern_search
  • agentdb_pattern_stats

Solution

Added the standard ESM polyfill:

import { fileURLToPath } from 'url';
import { dirname } from 'path';

// ESM __dirname polyfill (required since ES modules don't have __dirname)
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Note

The packages/agentdb/src/cli/agentdb-cli.ts already has this polyfill (line 35), but the agentic-flow/src/agentdb/cli/agentdb-cli.ts was missing it.

Test plan

  • Verified MCP tools work after applying this fix locally
  • agentdb_stats returns database statistics
  • agentdb_pattern_store successfully stores episodes

Fixes #77

🤖 Generated with Claude Code

The agentdb-cli.ts uses __dirname on line 62 but runs as an ES module
where __dirname is not available. This causes all MCP tools that rely
on the CLI to fail with "__dirname is not defined".

Added the standard ESM polyfill using fileURLToPath and dirname from
Node.js built-in modules.

Fixes ruvnet#77

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: AgentDB CLI fails with '__dirname is not defined' in ESM context

1 participant