Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/cli/memory-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,22 @@ describe("memory cli", () => {
expect(close).toHaveBeenCalled();
});

it("accepts --query flag for memory search", async () => {
const close = vi.fn(async () => {});
const search = vi.fn(async () => []);
mockManager({ search, close });

const log = spyRuntimeLogs();
await runMemoryCli(["search", "--query", "deployment notes"]);

expect(search).toHaveBeenCalledWith("deployment notes", {
maxResults: undefined,
minScore: undefined,
});
expect(log).toHaveBeenCalledWith("No matches.");
expect(close).toHaveBeenCalled();
});

it("prints search results as json when requested", async () => {
const close = vi.fn(async () => {});
const search = vi.fn(async () => [
Expand Down
16 changes: 13 additions & 3 deletions src/cli/memory-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,19 +702,29 @@ export function registerMemoryCli(program: Command) {
memory
.command("search")
.description("Search memory files")
.argument("<query>", "Search query")
.argument("[query]", "Search query")
.option("--query <text>", "Search query (flag alias)")
.option("--agent <id>", "Agent id (default: default agent)")
.option("--max-results <n>", "Max results", (value: string) => Number(value))
.option("--min-score <n>", "Minimum score", (value: string) => Number(value))
.option("--json", "Print JSON")
.action(
async (
query: string,
queryArg: string | undefined,
opts: MemoryCommandOptions & {
query?: string;
maxResults?: number;
minScore?: number;
},
) => {
const resolvedQuery = (opts.query ?? queryArg)?.trim() ?? "";
if (!resolvedQuery) {
defaultRuntime.error(
'Missing search query. Use `openclaw memory search "<query>"` or `--query "<query>"`.',
);
process.exitCode = 1;
return;
}
const cfg = loadConfig();
const agentId = resolveAgent(cfg, opts.agent);
await withMemoryManagerForAgent({
Expand All @@ -723,7 +733,7 @@ export function registerMemoryCli(program: Command) {
run: async (manager) => {
let results: Awaited<ReturnType<typeof manager.search>>;
try {
results = await manager.search(query, {
results = await manager.search(resolvedQuery, {
maxResults: opts.maxResults,
minScore: opts.minScore,
});
Expand Down
Loading