Skip to content

Commit df7f968

Browse files
committed
fix(memory-core): align prompt with available tools
1 parent 2c02a62 commit df7f968

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

extensions/memory-core/index.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,31 @@ describe("buildPromptSection", () => {
66
expect(buildPromptSection({ availableTools: new Set() })).toEqual([]);
77
});
88

9-
it("returns Memory Recall section when memory_search is available", () => {
10-
const result = buildPromptSection({ availableTools: new Set(["memory_search"]) });
9+
it("describes the two-step flow when both memory tools are available", () => {
10+
const result = buildPromptSection({
11+
availableTools: new Set(["memory_search", "memory_get"]),
12+
});
1113
expect(result[0]).toBe("## Memory Recall");
14+
expect(result[1]).toContain("run memory_search");
15+
expect(result[1]).toContain("then use memory_get");
1216
expect(result).toContain(
1317
"Citations: include Source: <path#line> when it helps the user verify memory snippets.",
1418
);
1519
expect(result.at(-1)).toBe("");
1620
});
1721

18-
it("returns Memory Recall section when memory_get is available", () => {
22+
it("limits the guidance to memory_search when only search is available", () => {
23+
const result = buildPromptSection({ availableTools: new Set(["memory_search"]) });
24+
expect(result[0]).toBe("## Memory Recall");
25+
expect(result[1]).toContain("run memory_search");
26+
expect(result[1]).not.toContain("then use memory_get");
27+
});
28+
29+
it("limits the guidance to memory_get when only get is available", () => {
1930
const result = buildPromptSection({ availableTools: new Set(["memory_get"]) });
2031
expect(result[0]).toBe("## Memory Recall");
32+
expect(result[1]).toContain("run memory_get");
33+
expect(result[1]).not.toContain("run memory_search");
2134
});
2235

2336
it("includes citations-off instruction when citationsMode is off", () => {

extensions/memory-core/index.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,26 @@ export const buildPromptSection: MemoryPromptSectionBuilder = ({
55
availableTools,
66
citationsMode,
77
}) => {
8-
if (!availableTools.has("memory_search") && !availableTools.has("memory_get")) {
8+
const hasMemorySearch = availableTools.has("memory_search");
9+
const hasMemoryGet = availableTools.has("memory_get");
10+
11+
if (!hasMemorySearch && !hasMemoryGet) {
912
return [];
1013
}
11-
const lines = [
12-
"## Memory Recall",
13-
"Before answering anything about prior work, decisions, dates, people, preferences, or todos: run memory_search on MEMORY.md + memory/*.md; then use memory_get to pull only the needed lines. If low confidence after search, say you checked.",
14-
];
14+
15+
let toolGuidance: string;
16+
if (hasMemorySearch && hasMemoryGet) {
17+
toolGuidance =
18+
"Before answering anything about prior work, decisions, dates, people, preferences, or todos: run memory_search on MEMORY.md + memory/*.md; then use memory_get to pull only the needed lines. If low confidence after search, say you checked.";
19+
} else if (hasMemorySearch) {
20+
toolGuidance =
21+
"Before answering anything about prior work, decisions, dates, people, preferences, or todos: run memory_search on MEMORY.md + memory/*.md and answer from the matching results. If low confidence after search, say you checked.";
22+
} else {
23+
toolGuidance =
24+
"Before answering anything about prior work, decisions, dates, people, preferences, or todos that already point to a specific memory file or note: run memory_get to pull only the needed lines. If low confidence after reading them, say you checked.";
25+
}
26+
27+
const lines = ["## Memory Recall", toolGuidance];
1528
if (citationsMode === "off") {
1629
lines.push(
1730
"Citations are disabled: do not mention file paths or line numbers in replies unless the user explicitly asks.",

0 commit comments

Comments
 (0)