#1 Persistent memory for AI coding agents based on real-world benchmarks
TypeScript agentmemoryagentsaiclaudeclaudecodecodexcopilotcursorgenaiharnesshermesmemoryompopenclawopencodepi
fix(viewer): sort Memories tab newest first (#674) (#701)
Rohit Ghumared4c4061ee095
diff --git a/src/viewer/index.html b/src/viewer/index.htmlindex d0bbc01c..d8b8f1f5 100644--- a/src/viewer/index.html+++ b/src/viewer/index.html@@ -2265,8 +2265,15 @@// corpora. Older endpoints returned the full unbounded list which// hit the iii invocation timeout and the UI fell through to 0.var result = await apiGet('memories?latest=true&limit=2000');- state.memories.items = (result && result.memories) || [];- state.memories.total = (result && typeof result.total === 'number') ? result.total : state.memories.items.length;+ var items = (result && result.memories) || [];+ // Newest first — server returns KV-insertion order.+ items.sort(function(a, b) {+ var ac = (a && a.createdAt) || (a && a.updatedAt) || '';+ var bc = (b && b.createdAt) || (b && b.updatedAt) || '';+ return bc.localeCompare(ac);+ });+ state.memories.items = items;+ state.memories.total = (result && typeof result.total === 'number') ? result.total : items.length;state.memories.loaded = true;renderMemories();}diff --git a/test/viewer-memories-sort.test.ts b/test/viewer-memories-sort.test.tsnew file mode 100644index 00000000..865b6417--- /dev/null+++ b/test/viewer-memories-sort.test.ts@@ -0,0 +1,32 @@+import { describe, it, expect } from "vitest";+import { readFileSync } from "node:fs";++// Viewer Memories tab used to render in KV-insertion order, hiding new+// entries at the bottom of long lists (#674). loadMemories() now sorts+// the response newest-first on `createdAt` (fallback `updatedAt`) before+// renderMemories sees it. Matches the pattern already used by Sessions+// and Metrics tabs which sort on `startedAt` desc via localeCompare.+describe("viewer Memories tab sorts newest first (#674)", () => {+ const viewer = readFileSync("src/viewer/index.html", "utf-8");++ it("loadMemories sorts items by createdAt desc before storing in state", () => {+ expect(viewer).toMatch(+ /loadMemories[\s\S]*?items\.sort\(function\(a,\s*b\)\s*\{[\s\S]*?bc\.localeCompare\(ac\)/,+ );+ });++ it("sort falls back to updatedAt when createdAt is missing", () => {+ expect(viewer).toMatch(+ /\(a && a\.createdAt\) \|\| \(a && a\.updatedAt\)/,+ );+ expect(viewer).toMatch(+ /\(b && b\.createdAt\) \|\| \(b && b\.updatedAt\)/,+ );+ });++ it("Memories sort mirrors the Sessions/Metrics localeCompare descending pattern", () => {+ expect(viewer).toMatch(+ /sessions\.sort\(function\(a, b\) \{ return \(b\.startedAt \|\| ''\)\.localeCompare\(a\.startedAt \|\| ''\); \}\)/,+ );+ });+});