🌊 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): remove default CLI entries from the AgentDB mirror
Rudy Celekli63d53543717a
diff --git a/v3/@claude-flow/cli/__tests__/memory-cli-mirror-removal.test.ts b/v3/@claude-flow/cli/__tests__/memory-cli-mirror-removal.test.tsnew file mode 100644index 0000000000..4dbe824715--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/memory-cli-mirror-removal.test.ts@@ -0,0 +1,88 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { tmpdir } from 'node:os';++vi.mock('../src/output.js', () => ({ output: new Proxy({}, { get: () => vi.fn() }) }));+vi.mock('../src/prompt.js', () => ({ confirm: vi.fn(async () => true), select: vi.fn(), input: vi.fn() }));+vi.mock('../src/mcp-client.js', () => ({ callMCPTool: vi.fn(), MCPClientError: class extends Error {} }));+import { memoryCommand } from '../src/commands/memory.js';+import { _resetMemoryRootCache, initializeMemoryDatabase, storeEntry, listEntries } from '../src/memory/memory-initializer.js';++let dir: string;+let primary: string;+let mirror: string;+async function invoke(name: string, flags: Record<string, unknown> = {}) {+ return memoryCommand.subcommands!.find(c => c.name === name)!.action!({+ flags: { namespace: 'scratch', key: 'remove', force: true, ...flags }, args: [], interactive: false,+ } as never);+}+async function count(dbPath: string, namespace = 'scratch') {+ return (await listEntries({ dbPath, namespace })).total;+}+beforeEach(async () => {+ dir = mkdtempSync(join(tmpdir(), 'memory-cli-mirror-'));+ vi.stubEnv('CLAUDE_FLOW_MEMORY_PATH', dir);+ vi.stubEnv('CLAUDE_FLOW_DISABLE_BRIDGE', '1');+ vi.stubEnv('CLAUDE_FLOW_DB_PATH', '');+ _resetMemoryRootCache();+ primary = join(dir, 'memory.db');+ mirror = join(dir, 'agentdb-memory.db');+ for (const dbPath of [primary, mirror]) {+ expect((await initializeMemoryDatabase({ dbPath, force: true, migrate: false })).success).toBe(true);+ for (const namespace of ['scratch', 'keep']) {+ expect((await storeEntry({ dbPath, namespace, key: 'remove', value: namespace, generateEmbeddingFlag: false })).success).toBe(true);+ }+ }+});+afterEach(() => {+ vi.unstubAllEnvs();+ _resetMemoryRootCache();+ rmSync(dir, { recursive: true, force: true });+});++describe('CLI removal of default memory and its AgentDB mirror', () => {+ it.each(['delete', 'purge'])('%s removes matching entries from both stores', async (command) => {+ expect((await invoke(command)).success).toBe(true);+ expect(await count(primary)).toBe(0);+ expect(await count(mirror)).toBe(0);+ expect(await count(primary, 'keep')).toBe(1);+ expect(await count(mirror, 'keep')).toBe(1);+ });++ it('refuses an unconfirmed purge without changing either store', async () => {+ expect(await invoke('purge', { force: false })).toMatchObject({ success: false, exitCode: 1 });+ expect(await count(primary)).toBe(1);+ expect(await count(mirror)).toBe(1);+ });++ it('previews both stores without modifying either', async () => {+ const result = await invoke('purge', { dryRun: true });+ expect(result.data).toMatchObject({ wouldDelete: 2 });+ expect(await count(primary)).toBe(1);+ expect(await count(mirror)).toBe(1);+ });++ it.each(['delete', 'purge'])('%s honors an explicit single-store path', async (command) => {+ expect((await invoke(command, { path: primary })).success).toBe(true);+ expect(await count(primary)).toBe(0);+ expect(await count(mirror)).toBe(1);+ });++ it.each(['delete', 'purge'])('%s honors the environment single-store override', async (command) => {+ vi.stubEnv('CLAUDE_FLOW_DB_PATH', primary);+ expect((await invoke(command)).success).toBe(true);+ expect(await count(mirror)).toBe(1);+ });++ it.each(['delete', 'purge'])('%s reports a failure if the mirror cannot be modified', async (command) => {+ writeFileSync(mirror, 'not a database');+ expect(await invoke(command)).toMatchObject({ success: false, exitCode: 1 });+ });++ it('can remove mirror-only rows when the primary store is absent', async () => {+ rmSync(primary);+ expect((await invoke('purge')).success).toBe(true);+ expect(await count(mirror)).toBe(0);+ });+});diff --git a/v3/@claude-flow/cli/src/commands/memory.ts b/v3/@claude-flow/cli/src/commands/memory.tsindex ca06bcaeae..a7d38e0ff8 100644--- a/v3/@claude-flow/cli/src/commands/memory.ts+++ b/v3/@claude-flow/cli/src/commands/memory.ts@@ -11,6 +11,8 @@ import { distillCommand } from './memory-distill.js';import { backupCommand } from './memory-backup.js';import { countSiblingStoreRows } from '../memory/sibling-store.js';import { resolveDbPath } from '../memory/memory-initializer.js';+import { existsSync } from 'node:fs';+import { siblingAgentDbPath } from '../memory/memory-bridge.js';/*** #3228: a miss in one store is not a miss in the memory.@@ -32,6 +34,18 @@ async function warnIfSiblingHasRows(pathFlag: unknown): Promise<void> {}}+/** Default CLI writes may be mirrored into AgentDB; remove both copies. */+function removalDbPaths(pathFlag?: string): string[] {+ const primary = resolveDbPath(pathFlag);+ // An explicit file selection is a single-store operation, as documented by+ // --path. Do not widen a caller's requested destructive scope.+ if (pathFlag || process.env.CLAUDE_FLOW_DB_PATH) return [primary];+ const sibling = siblingAgentDbPath(primary);+ const paths = [primary, ...(sibling ? [sibling] : [])].filter(existsSync);+ // Preserve the existing missing-database error when neither store exists.+ return paths.length ? paths : [primary];+}+// Memory backendsconst BACKENDS = [{ value: 'agentdb', label: 'AgentDB', hint: 'Vector database with HNSW indexing (150x-12,500x faster)' },@@ -881,7 +895,7 @@ function formatRelativeTime(isoDate: string): string {const deleteCommand: Command = {name: 'delete',aliases: ['rm'],- description: 'Delete memory entry',+ description: 'Delete a memory entry from the default store and its AgentDB mirror (use --path to select one store)',options: [{name: 'key',@@ -935,18 +949,23 @@ const deleteCommand: Command = {// Use sql.js directly for consistent data access (Issue #980)try {- const { deleteEntry, resolveDbPath: _rdbDelete } = await import('../memory/memory-initializer.js');- const dbPathDelete = _rdbDelete(ctx.flags.path as string | undefined);- const result = await deleteEntry({ key, namespace, dbPath: dbPathDelete });-- if (!result.success) {- output.printError(result.error || 'Failed to delete');- return { success: false, exitCode: 1 };+ const { deleteEntry } = await import('../memory/memory-initializer.js');+ const paths = removalDbPaths(ctx.flags.path as string | undefined);+ const stores = [];+ for (const dbPath of paths) {+ const entry = await deleteEntry({ key, namespace, dbPath });+ if (!entry.success) throw new Error(`${dbPath}: ${entry.error || 'Failed to delete'}`);+ stores.push({ dbPath, ...entry });}+ const result = {+ success: true, key, namespace, stores,+ deleted: stores.some(entry => entry.deleted),+ remainingEntries: stores.reduce((total, entry) => total + entry.remainingEntries, 0),+ };if (result.deleted) {output.printSuccess(`Deleted "${key}" from namespace "${namespace}"`);- output.printInfo(`Remaining entries: ${result.remainingEntries}`);+ output.printInfo(`Remaining entries across ${paths.length} store(s): ${result.remainingEntries}`);} else {output.printWarning(`Key not found: "${key}" in namespace "${namespace}"`);}@@ -968,7 +987,7 @@ const deleteCommand: Command = {// either interactive confirmation or --force.const purgeCommand: Command = {name: 'purge',- description: 'Permanently delete every entry in a namespace (hard delete — not the soft delete/tombstone that `memory delete` uses)',+ description: 'Permanently delete a namespace from the default store and its AgentDB mirror (use --path to select one store)',options: [{name: 'namespace',@@ -1008,20 +1027,23 @@ const purgeCommand: Command = {}try {- const { listEntries, purgeNamespace, resolveDbPath: _rdbPurge } = await import('../memory/memory-initializer.js');- const resolvedDbPath = _rdbPurge(dbPath);-- const preview = await listEntries({ namespace, limit: 1, dbPath: resolvedDbPath });- const previewCount = preview.total ?? preview.entries?.length ?? 0;+ const { listEntries, purgeNamespace } = await import('../memory/memory-initializer.js');+ const paths = removalDbPaths(dbPath);+ let previewCount = 0;+ for (const target of paths) {+ const preview = await listEntries({ namespace, limit: 1, dbPath: target });+ if (!preview.success) throw new Error(`${target}: ${preview.error || 'Failed to read purge target'}`);+ previewCount += preview.total ?? preview.entries?.length ?? 0;+ }if (dryRun) {- output.printInfo(`Would permanently delete ${previewCount} entr${previewCount === 1 ? 'y' : 'ies'} from namespace "${namespace}" (dry run — nothing deleted)`);+ output.printInfo(`Would permanently delete ${previewCount} entr${previewCount === 1 ? 'y' : 'ies'} from namespace "${namespace}" across ${paths.length} store(s) (dry run — nothing deleted)`);return { success: true, data: { namespace, wouldDelete: previewCount } };}if (!force && ctx.interactive) {const confirmed = await confirm({- message: `Permanently delete ${previewCount} entr${previewCount === 1 ? 'y' : 'ies'} from namespace "${namespace}"? This is a hard delete — not reversible with \`memory delete\`'s soft-undo.`,+ message: `Permanently delete ${previewCount} entr${previewCount === 1 ? 'y' : 'ies'} from namespace "${namespace}" across ${paths.length} store(s)? This is a hard delete — not reversible with \`memory delete\`'s soft-undo.`,default: false});if (!confirmed) {@@ -1033,15 +1055,20 @@ const purgeCommand: Command = {return { success: false, exitCode: 1 };}- const result = await purgeNamespace({ namespace, dbPath: resolvedDbPath });-- if (!result.success) {- output.printError(result.error || 'Failed to purge');- return { success: false, exitCode: 1 };+ const stores = [];+ for (const target of paths) {+ const purged = await purgeNamespace({ namespace, dbPath: target });+ if (!purged.success) throw new Error(`${target}: ${purged.error || 'Failed to purge'}`);+ stores.push({ dbPath: target, ...purged });}+ const result = {+ success: true, stores,+ deletedCount: stores.reduce((total, store) => total + store.deletedCount, 0),+ remainingEntries: stores.reduce((total, store) => total + store.remainingEntries, 0),+ };output.printSuccess(`Purged ${result.deletedCount} entr${result.deletedCount === 1 ? 'y' : 'ies'} from namespace "${namespace}"`);- output.printInfo(`Remaining entries (all namespaces): ${result.remainingEntries}`);+ output.printInfo(`Remaining entries (all namespaces, ${paths.length} store(s)): ${result.remainingEntries}`);return { success: true, data: result };} catch (error) {output.printError(`Failed to purge: ${error instanceof Error ? error.message : 'Unknown error'}`);