🌊 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
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(memory): preserve user index content when generated views grow
Rudy Celekli5350afae99f1
diff --git a/v3/@claude-flow/memory/src/auto-memory-bridge.ts b/v3/@claude-flow/memory/src/auto-memory-bridge.tsindex 0f60baec3c..2838286a08 100644--- a/v3/@claude-flow/memory/src/auto-memory-bridge.ts+++ b/v3/@claude-flow/memory/src/auto-memory-bridge.ts@@ -524,14 +524,21 @@ export class AutoMemoryBridge extends EventEmitter {try { existing = await fs.readFile(indexPath, 'utf-8'); } catch { /* first run */ }const linksIn = (text: string) => (text.match(/\]\(/g) ?? []).length;+ // Counts alone do not prove preservation: replacing one user note with+ // several generated notes grows the file while still deleting that note.+ // Require every existing nonblank line to survive, allowing reordering and+ // additional generated content without taking ownership of unknown text.+ const generatedLines = new Set(lines.map(line => line.trim()));+ const losesContent = existing.split('\n').some(line =>+ line.trim().length > 0 && !generatedLines.has(line.trim()));const wouldLose = existing.trim().length > 0- && (linksIn(existing) > linksIn(generated) || existing.split('\n').length > lines.length);+ && (losesContent || linksIn(existing) > linksIn(generated) || existing.split('\n').length > lines.length);if (wouldLose) {const sidecar = indexPath.replace(/\.md$/, '') + '.generated.md';await fs.writeFile(sidecar, generated, 'utf-8');this.emit('index:preserved', {- reason: 'would-shrink-user-index',+ reason: losesContent ? 'would-lose-index-content' : 'would-shrink-user-index',indexPath,sidecar,existingLines: existing.split('\n').length,diff --git a/v3/@claude-flow/memory/src/auto-memory-index-3224.test.ts b/v3/@claude-flow/memory/src/auto-memory-index-3224.test.tsindex cf96a0476d..62e4c70719 100644--- a/v3/@claude-flow/memory/src/auto-memory-index-3224.test.ts+++ b/v3/@claude-flow/memory/src/auto-memory-index-3224.test.ts@@ -45,6 +45,31 @@ describe('#3224 curateIndex must not destroy a user index', () => {expect(existsSync(join(dir, 'MEMORY.generated.md')), 'generated view goes beside it').toBe(true);});+ it.each([+ '# Claude Flow V3 Project Memory\n\nKeep the production recovery code in the offline vault.',+ '# Claude Flow V3 Project Memory\n\n## Project Patterns\n- User-only recovery note\n- See `patterns.md` for details\n',+ ])('preserves user content even when the generated index is as large or larger', async (before) => {+ writeFileSync(join(dir, 'MEMORY.md'), before, 'utf-8');+ writeFileSync(join(dir, 'patterns.md'), '# Patterns\n\n- generated detail\n', 'utf-8');+ const bridge = new AutoMemoryBridge({} as never, { memoryDir: dir });+ await bridge.curateIndex();+ expect(readFileSync(join(dir, 'MEMORY.md'), 'utf-8')).toBe(before);+ expect(readFileSync(join(dir, 'MEMORY.generated.md'), 'utf-8')).toContain('generated detail');+ });++ it('allows an existing generated index to grow without losing its content', async () => {+ const topic = join(dir, 'patterns.md');+ writeFileSync(topic, '# Patterns\n\n- original detail\n', 'utf-8');+ const bridge = new AutoMemoryBridge({} as never, { memoryDir: dir });+ await bridge.curateIndex();+ writeFileSync(topic, '# Patterns\n\n- original detail\n- new detail\n', 'utf-8');+ await bridge.curateIndex();+ const index = readFileSync(join(dir, 'MEMORY.md'), 'utf-8');+ expect(index).toContain('original detail');+ expect(index).toContain('new detail');+ expect(existsSync(join(dir, 'MEMORY.generated.md'))).toBe(false);+ });+it('still writes the index when there is nothing to lose', async () => {writeFileSync(join(dir, 'patterns.md'), '# Patterns\n\n- generated\n', 'utf-8');const bridge = new AutoMemoryBridge({} as never, { memoryDir: dir } as never);