Bug: Memory protocol injection fails due to invalid fs/promises import in inject-memory-protocol.js
- Dominant language
- TypeScript
- Stars
- 72.7k
- Forks
- 8.6k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 83
Description
## Bug Description
When running swarm commands with the `--claude` flag, the memory protocol injection fails silently with the warning:
```
⚠️ Memory protocol injection not available, using standard prompt
```
This prevents the memory coordination protocol from being injected into CLAUDE.md, causing agents to run without shared memory coordination capabilities.
## Root Cause
**File:** `src/cli/simple-commands/inject-memory-protocol.js` (line 2)
**Buggy code:**
```javascript
import { promises as fs } from 'fs/promises';
```
**Error produced:**
```
SyntaxError: The requested module 'fs/promises' does not provide an export named 'promises'
```
The `fs/promises` module exports functions directly (`readFile`, `writeFile`, `access`, etc.), NOT a `promises` object. This is an ES module syntax error.
## Steps to Reproduce
1. Run any swarm command with `--claude` flag:
```bash
npx claude-flow swarm "Any task" --mode hierarchical --max-agents 8 --claude
```
2. Observe the warning:
```
⚠️ Memory protocol injection not available, using standard prompt
```
3. Verify the error by testing the import directly:
```bash
node -e "import { promises as fs } from 'fs/promises'"
# Output: SyntaxError: The requested module 'fs/promises' does not provide an export named 'promises'
```
## Why the Error is Hidden
In `swarm.js` (lines 708-714), the error is caught but only a generic message is logged:
```javascript
try {
const { injectMemoryProtocol, enhanceSwarmPrompt } =
await import('./inject-memory-protocol.js');
await injectMemoryProtocol();
swarmPrompt = enhanceSwarmPrompt(swarmPrompt, maxAgents);
} catch (err) {
// Bug: actual error is never logged
console.log('⚠️ Memory protocol injection not available, using standard prompt');
}
```
## Proposed Fix
**Option A:** Default import (recommended)
```javascript
import fs from 'fs/promises';
```
**Option B:** Named imports (like hive-mind.js already does correctly)
```javascript
import { readFile, writeFile } from 'fs/promises';
```
Note: `hive-mind.js` already uses the correct syntax on its line 1:
```javascript
import { writeFile, readFile } from 'fs/promises';
```
## Additional Improvement
Consider logging the actual error in the catch block for easier debugging:
```javascript
} catch (err) {
console.log('⚠️ Memory protocol injection not available:', err.message);
console.log(' Using standard prompt instead');
}
```
## Environment
- **Package version:** claude-flow v2.7.47
- **Node.js version:** v25.1.0 (also affects Node 18+)
- **OS:** Windows 11
- **Installation method:** npx
## Impact
- **Severity:** Medium
- **Affected functionality:** Swarm memory coordination
- **Workaround:** Manually add memory protocol to CLAUDE.md or use `npx claude-flow init`
Without the memory protocol injection:
- Agents don't write status to `swarm/[agent]/status`
- No shared memory coordination between agents
- Swarm runs but agents work in isolation
## Fix Effort
One-line change in `inject-memory-protocol.js`.
Contributor guide
Research direction
Start with src/cli/simple-commands/inject-memory-protocol.js and inspect its fs/promises import, then compare the working import in hive-mind.js. Run the provided Node import check and a swarm command with --claude; done means memory protocol injection succeeds without the warning and agents receive the coordination protocol.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100