fix(init): use real memory subcommands in the installed memory command pages (#5167) (#5168)

Co-authored-by: Lenin Mookiah <2639584+leninworld@users.noreply.github.com>
This commit is contained in:
Lenin MookiahandLenin Mookiah authored and GitHub committed 2026-11-28 16:03:59 -05:00
1 parent c4d6d6d0a4
commit 3e2fcdf4fd
4 files changed
+161 -20

No files matched your search

@@ -4,22 +4,25 @@ Persist memory across sessions.
## Usage
```bash
npx @claude-flow/cli@latest memory persist [options]
npx @claude-flow/cli@latest memory export --output <file> [options]
npx @claude-flow/cli@latest memory import --input <file> [options]
```
## Options
- `--export <file>` - Export to file
- `--import <file>` - Import from file
- `--compress` - Compress memory data
- `--output <file>` - JSON export output file
- `--input <file>` - JSON export file to import
- `--namespace <namespace>` (export) - Limit the export to one namespace
- `--namespace <namespace>` (import) - Store every imported entry under this namespace, overriding namespaces in the export
- `--merge` - Merge is the default; update (overwrite) entries with the same key in the target namespace
- `--no-merge` - Leave entries whose key already exists in the target namespace unchanged and report them as failed
Exports are JSON; embeddings are not included (the import re-embeds).
## Examples
```bash
# Export memory
npx @claude-flow/cli@latest memory persist --export memory-backup.json
npx @claude-flow/cli@latest memory export --output memory-backup.json
# Import memory
npx @claude-flow/cli@latest memory persist --import memory-backup.json
# Compressed export
npx @claude-flow/cli@latest memory persist --export memory.gz --compress
npx @claude-flow/cli@latest memory import --input memory-backup.json
```
@@ -9,7 +9,7 @@ npx @claude-flow/cli@latest memory search [options]
## Options
- `--query <text>` - Search query
- `--pattern <regex>` - Pattern matching
- `--type <type>` - Search type (semantic, keyword, hybrid)
- `--limit <n>` - Result limit
## Examples
@@ -17,8 +17,8 @@ npx @claude-flow/cli@latest memory search [options]
# Search memory
npx @claude-flow/cli@latest memory search --query "authentication"
# Pattern search
npx @claude-flow/cli@latest memory search --pattern "api-.*"
# Keyword search
npx @claude-flow/cli@latest memory search --query "api" --type keyword
# Limited results
npx @claude-flow/cli@latest memory search --query "config" --limit 10
@@ -4,22 +4,37 @@ Manage persistent memory storage.
## Usage
```bash
npx @claude-flow/cli@latest memory usage [options]
npx @claude-flow/cli@latest memory store --key <key> --value <data> [--namespace <namespace>]
npx @claude-flow/cli@latest memory retrieve --key <key> [--namespace <namespace>]
npx @claude-flow/cli@latest memory list [--namespace <namespace>] [--limit <n>]
npx @claude-flow/cli@latest memory delete --key <key> [--namespace <namespace>] [--force]
npx @claude-flow/cli@latest memory purge --namespace <namespace> [--dry-run] [--force]
```
`memory purge` permanently deletes every entry in a namespace.
## Options
- `--action <type>` - Action (store, retrieve, list, clear)
- `--key <key>` - Memory key
- `--value <data>` - Data to store (JSON)
- `--key <key>` - Memory key for store, retrieve, or delete
- `--value <data>` - Data to store
- `--namespace <namespace>` - Memory namespace
- `--limit <n>` - Maximum entries to list
- `--force` - Delete without confirmation
- `--dry-run` - Report how many entries a purge would permanently delete without deleting them
## Examples
```bash
# Store memory
npx @claude-flow/cli@latest memory usage --action store --key "project-config" --value '{"api": "v2"}'
npx @claude-flow/cli@latest memory store --key "project-config" --value '{"api": "v2"}'
# Retrieve memory
npx @claude-flow/cli@latest memory usage --action retrieve --key "project-config"
npx @claude-flow/cli@latest memory retrieve --key "project-config"
# List all keys
npx @claude-flow/cli@latest memory usage --action list
# List entries
npx @claude-flow/cli@latest memory list --limit 20
# Delete one key
npx @claude-flow/cli@latest memory delete --key "project-config" --force
# Preview permanently deleting every entry in a namespace
npx @claude-flow/cli@latest memory purge --namespace "stale-cache" --dry-run
```
@@ -0,0 +1,123 @@
import { describe, expect, it, vi } from 'vitest';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
vi.mock('../src/output.js', () => ({
output: new Proxy({}, { get: () => (value: unknown) => value }),
}));
vi.mock('../src/prompt.js', () => ({ select: vi.fn(), confirm: vi.fn(), input: vi.fn() }));
vi.mock('../src/mcp-client.js', () => ({ callMCPTool: vi.fn(), MCPClientError: class extends Error {} }));
vi.mock('../src/mcp-tools/path-containment.js', () => ({ localCliContext: () => ({}) }));
vi.mock('../src/mcp-tools/validate-input.js', () => ({
validateIdentifier: () => ({ valid: true }),
}));
vi.mock('../src/mcp-tools/memory-tools.js', () => ({
memoryKeyError: () => null,
MEMORY_SCOPES: ['project', 'local', 'user'],
resolveScopedNamespace: ({ namespace }: { namespace: string }) => ({ ok: true, namespace }),
}));
vi.mock('../src/commands/memory-distill.js', () => ({ distillCommand: {} }));
vi.mock('../src/commands/memory-backup.js', () => ({ backupCommand: {} }));
vi.mock('../src/memory/memory-initializer.js', () => ({ resolveDbPath: (path?: string) => path ?? 'memory.db' }));
import { memoryCommand } from '../src/commands/memory.js';
import { extractInvocations, loadCommandTree, resolveCommand } from '../../../../scripts/audit-skill-cli-commands.mjs';
const MEMORY_COMMANDS_ROOT = join(
fileURLToPath(new URL('..', import.meta.url)),
'.claude',
'commands',
'memory',
);
const PAGES = ['memory-usage.md', 'memory-persist.md', 'memory-search.md'];
function commandFlags(subcommand: string): Set<string> {
const command = memoryCommand.subcommands?.find(
(candidate) => candidate.name === subcommand || candidate.aliases?.includes(subcommand),
);
expect(command, `memory ${subcommand} must be registered`).toBeDefined();
const flags = new Set<string>();
for (const option of command?.options ?? []) {
flags.add(`--${option.name}`);
if (option.short) flags.add(`-${option.short}`);
}
return flags;
}
function flagsOnLine(line: string): string[] {
return [...line.matchAll(/(^|[\s\[])(--?[a-z][a-z0-9-]*)\b/g)].map((match) => match[2]);
}
function declaredFlag(subcommand: string, flag: string): string {
if (!flag.startsWith('--no-')) return flag;
const baseName = flag.slice('--no-'.length);
const command = memoryCommand.subcommands?.find(
(candidate) => candidate.name === subcommand || candidate.aliases?.includes(subcommand),
);
const option = command?.options?.find((candidate) => candidate.name === baseName);
return option?.type === 'boolean' ? `--${baseName}` : flag;
}
function optionsSection(markdown: string): string[] {
const section = markdown.match(/## Options\s*\n([\s\S]*?)(?=\n## |$)/)?.[1] ?? '';
return [...section.matchAll(/`(--[a-z][a-z0-9-]*)\b/g)].map((match) => match[1]);
}
describe('default init memory command pages use the CLI that v3 ships', () => {
it('ships the default memory command directory', () => {
expect(existsSync(MEMORY_COMMANDS_ROOT)).toBe(true);
});
it.each(PAGES)('%s references only registered memory subcommands and their declared options', async (page) => {
const tree = await loadCommandTree();
const file = join(MEMORY_COMMANDS_ROOT, page);
expect(existsSync(file), `${page} must remain in the init command kit`).toBe(true);
const markdown = readFileSync(file, 'utf8');
const lines = markdown.split('\n');
const invocations = extractInvocations(markdown);
expect(invocations.length, `${page} must contain at least one CLI invocation`).toBeGreaterThan(0);
const pageSubcommands = new Set<string>();
for (const invocation of invocations) {
const command = resolveCommand(tree, invocation.command);
expect(command, `${page}:${invocation.line} must use a registered command`).toBe('memory');
const subcommands = tree.get(command!)?.subcommands;
const subcommand = invocation.subcommand;
const resolvedSubcommand = subcommand && subcommands
? (subcommands.has(subcommand)
? subcommand
: [...subcommands].find(([, aliases]) => aliases.includes(subcommand))?.[0])
: null;
expect(
resolvedSubcommand,
`${page}:${invocation.line} must use a registered memory subcommand`,
).toBeTruthy();
pageSubcommands.add(resolvedSubcommand!);
const declared = commandFlags(resolvedSubcommand!);
for (const flag of flagsOnLine(lines[invocation.line - 1])) {
expect(
declared.has(declaredFlag(resolvedSubcommand!, flag)),
`${page}:${invocation.line} memory ${resolvedSubcommand} does not declare ${flag}`,
).toBe(true);
}
}
const listedOptions = optionsSection(markdown);
expect(listedOptions.length, `${page} must document at least one option`).toBeGreaterThan(0);
for (const option of listedOptions) {
expect(
[...pageSubcommands].some((subcommand) => (
commandFlags(subcommand).has(declaredFlag(subcommand, option))
)),
`${page} lists ${option}, but none of its example subcommands declare it`,
).toBe(true);
}
}, 120_000);
});