Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(memory): content-hash dedupe in memory_import_claude (#1791.8) (#1808)

rUv3eb6b4d65620
diff --git a/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts
index 669672d1ea..65185b81c0 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts
@@ -13,6 +13,7 @@
import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
import { homedir } from 'os';
import { join, resolve } from 'path';
+import { createHash } from 'crypto';
import type { MCPTool } from './types.js';
import { validateIdentifier } from './validate-input.js';
@@ -711,12 +712,31 @@ export const memoryTools: MCPTool[] = [
let imported = 0;
let skipped = 0;
+ // #1791.8 — Claude Code's `~/.claude/projects/` accumulates historical
+ // project_id directories (truncated forms, sandbox cwds, renamed
+ // workspaces) that all contain copies of the same memory files. The
+ // previous import indexed each copy under a different `project_id`
+ // prefix, producing 5–8x duplication on long-lived homes. Dedupe by
+ // file content hash so the same memory is imported once even if it
+ // appears under several project directories.
+ const seenContentHashes = new Set<string>();
+ let duplicatesSkipped = 0;
const projects = new Set<string>();
for (const memFile of memoryFiles) {
projects.add(memFile.project);
try {
const content = readFileSync(memFile.path, 'utf-8');
+
+ // #1791.8 — Skip if we've already imported this exact content under
+ // a different project_id directory.
+ const contentHash = createHash('sha256').update(content).digest('hex').slice(0, 16);
+ if (seenContentHashes.has(contentHash)) {
+ duplicatesSkipped++;
+ continue;
+ }
+ seenContentHashes.add(contentHash);
+
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
let name = memFile.file.replace('.md', '');
let body = content;
@@ -753,6 +773,7 @@ export const memoryTools: MCPTool[] = [
success: true,
imported,
skipped,
+ duplicatesSkipped,
files: memoryFiles.length,
projects: projects.size,
namespace: ns,