mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-27 00:17:29 +00:00
fix(cli): support --query in memory search command (#25904)
This commit is contained in:
@@ -382,6 +382,49 @@ describe("memory cli", () => {
|
||||
expect(close).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("accepts --query 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();
|
||||
expect(process.exitCode).toBeUndefined();
|
||||
});
|
||||
|
||||
it("prefers --query when positional and flag are both provided", async () => {
|
||||
const close = vi.fn(async () => {});
|
||||
const search = vi.fn(async () => []);
|
||||
mockManager({ search, close });
|
||||
|
||||
spyRuntimeLogs();
|
||||
await runMemoryCli(["search", "positional", "--query", "flagged"]);
|
||||
|
||||
expect(search).toHaveBeenCalledWith("flagged", {
|
||||
maxResults: undefined,
|
||||
minScore: undefined,
|
||||
});
|
||||
expect(close).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("fails when neither positional query nor --query is provided", async () => {
|
||||
const error = spyRuntimeErrors();
|
||||
await runMemoryCli(["search"]);
|
||||
|
||||
expect(error).toHaveBeenCalledWith(
|
||||
"Missing search query. Provide a positional query or use --query <text>.",
|
||||
);
|
||||
expect(getMemorySearchManager).not.toHaveBeenCalled();
|
||||
expect(process.exitCode).toBe(1);
|
||||
});
|
||||
|
||||
it("prints search results as json when requested", async () => {
|
||||
const close = vi.fn(async () => {});
|
||||
const search = vi.fn(async () => [
|
||||
|
||||
@@ -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 (alternative to positional argument)")
|
||||
.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 query = opts.query ?? queryArg;
|
||||
if (!query) {
|
||||
defaultRuntime.error(
|
||||
"Missing search query. Provide a positional query or use --query <text>.",
|
||||
);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
const cfg = loadConfig();
|
||||
const agentId = resolveAgent(cfg, opts.agent);
|
||||
await withMemoryManagerForAgent({
|
||||
|
||||
Reference in New Issue
Block a user