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
23 changes: 14 additions & 9 deletions src/prompt.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { describe, expect, test } from "bun:test";

import type { MemoryBlock } from "./memory";

import { renderMemoryBlocks } from "./prompt";

describe("renderMemoryBlocks", () => {
Expand Down Expand Up @@ -47,9 +49,8 @@ describe("renderMemoryBlocks", () => {
expect(xml).toContain("</memory_instructions>");
});

test("includes memory metadata block with timestamps", () => {
const testDate = new Date("2025-01-15T10:30:00Z");
const xml = renderMemoryBlocks([
test("memory metadata is stable across calls (cache-friendly head)", () => {
const blocks: MemoryBlock[] = [
{
scope: "global",
label: "human",
Expand All @@ -58,14 +59,18 @@ describe("renderMemoryBlocks", () => {
readOnly: false,
value: "hi",
filePath: "/tmp/human.md",
lastModified: testDate,
lastModified: new Date("2025-01-15T10:30:00Z"),
},
]);
];

const first = renderMemoryBlocks(blocks);
// small delay simulates two distinct requests
const second = renderMemoryBlocks(blocks);

expect(xml).toContain("<memory_metadata>");
expect(xml).toContain("The current system date is:");
expect(xml).toContain("Memory blocks were last modified:");
expect(xml).toContain("</memory_metadata>");
expect(first).toContain("<memory_metadata>");
expect(first).not.toContain("The current system date is:");
expect(first).not.toContain("Memory blocks were last modified:");
expect(second).toBe(first);
});

test("handles empty value gracefully", () => {
Expand Down
10 changes: 1 addition & 9 deletions src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ const LINE_NUMBER_WARNING =
"# NOTE: Line numbers shown below (with arrows like '1→') are to help during editing. Do NOT include line number prefixes in your memory edit tool calls.";

function renderMemoryMetadata(blocks: MemoryBlock[]): string {
const now = new Date();

const lastModified = blocks.reduce(
(latest, block) => (block.lastModified > latest ? block.lastModified : latest),
new Date(0)
);

return `<memory_metadata>
- The current system date is: ${now.toISOString()}
- Memory blocks were last modified: ${lastModified.toISOString()}
- Memory blocks are editable via memory_set / memory_replace.
- Use memory tools to manage your memory blocks
</memory_metadata>`;
}
Expand Down