docs(cli): improve memory command examples (#31803)

Merged via squash.

Prepared head SHA: 15dcda3027
Co-authored-by: JasonOA888 <101583541+JasonOA888@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
This commit is contained in:
Jason
2026-03-08 00:03:23 +08:00
committed by GitHub
parent 1eb7198bad
commit 786ec21b5a
4 changed files with 62 additions and 10 deletions

View File

@@ -113,6 +113,29 @@ describe("memory cli", () => {
await program.parseAsync(["memory", ...args], { from: "user" });
}
function captureHelpOutput(command: Command | undefined) {
let output = "";
const writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(((
chunk: string | Uint8Array,
) => {
output += String(chunk);
return true;
}) as typeof process.stdout.write);
try {
command?.outputHelp();
return output;
} finally {
writeSpy.mockRestore();
}
}
function getMemoryHelpText() {
const program = new Command();
registerMemoryCli(program);
const memoryCommand = program.commands.find((command) => command.name() === "memory");
return captureHelpOutput(memoryCommand);
}
async function withQmdIndexDb(content: string, run: (dbPath: string) => Promise<void>) {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "memory-cli-qmd-index-"));
const dbPath = path.join(tmpDir, "index.sqlite");
@@ -220,6 +243,17 @@ describe("memory cli", () => {
expect(hasLoggedInactiveSecretDiagnostic(log)).toBe(true);
});
it("documents memory help examples", () => {
const helpText = getMemoryHelpText();
expect(helpText).toContain("openclaw memory status --deep");
expect(helpText).toContain("Probe embedding provider readiness.");
expect(helpText).toContain('openclaw memory search "meeting notes"');
expect(helpText).toContain("Quick search using positional query.");
expect(helpText).toContain('openclaw memory search --query "deployment" --max-results 20');
expect(helpText).toContain("Limit results for focused troubleshooting.");
});
it("prints vector error when unavailable", async () => {
const close = vi.fn(async () => {});
mockManager({

View File

@@ -582,9 +582,14 @@ export function registerMemoryCli(program: Command) {
() =>
`\n${theme.heading("Examples:")}\n${formatHelpExamples([
["openclaw memory status", "Show index and provider status."],
["openclaw memory status --deep", "Probe embedding provider readiness."],
["openclaw memory index --force", "Force a full reindex."],
['openclaw memory search --query "deployment notes"', "Search indexed memory entries."],
["openclaw memory status --json", "Output machine-readable JSON."],
['openclaw memory search "meeting notes"', "Quick search using positional query."],
[
'openclaw memory search --query "deployment" --max-results 20',
"Limit results for focused troubleshooting.",
],
["openclaw memory status --json", "Output machine-readable JSON (good for scripts)."],
])}\n\n${theme.muted("Docs:")} ${formatDocsLink("/cli/memory", "docs.openclaw.ai/cli/memory")}\n`,
);