fix(viewer): sort Memories tab newest first (#674)#701
Conversation
Memories list rendered in KV-insertion order from `GET /agentmemory/memories?latest=true`, so newly saved memories landed at the bottom of long lists. Sessions and Metrics tabs already sort on `startedAt` desc via `localeCompare`; Memories now does the same on `createdAt` (fallback `updatedAt`) inside `loadMemories()` before items reach state. Sort happens once on load, not per render — same approach the Sessions/Metrics tabs use. No new dependencies, no API change.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe Memories tab in the viewer now sorts entries newest-first by ChangesMemory List Sorting
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
test/viewer-memories-sort.test.ts (1)
27-30: ⚡ Quick winLoosen the Sessions/Metrics parity regex to avoid brittle failures.
The exact one-line
sessions.sort(...)pattern is formatting-sensitive and can fail on harmless refactors. Match the semantic shape (descendinglocaleCompare) with a less rigid regex.Proposed adjustment
- /sessions\.sort\(function\(a, b\) \{ return \(b\.startedAt \|\| ''\)\.localeCompare\(a\.startedAt \|\| ''\); \}\)/, + /sessions\.sort\([\s\S]*?\(b\.startedAt\s*\|\|\s*['"]{2}\)\.localeCompare\(\s*a\.startedAt\s*\|\|\s*['"]{2}\s*\)/,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/viewer-memories-sort.test.ts` around lines 27 - 30, The test's strict regex for the "Memories sort mirrors the Sessions/Metrics localeCompare descending pattern" assertion is brittle; update the matcher for the viewer variable to allow formatting differences while still ensuring a descending localeCompare on startedAt — i.e., relax the pattern to look for sessions.sort(...) that contains localeCompare and the operands in descending order (b.startedAt vs a.startedAt), permit arbitrary whitespace/newlines and optional || '' or other minor variations, and avoid matching the entire one-line function text verbatim so harmless reformatting won't break the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/viewer-memories-sort.test.ts`:
- Around line 27-30: The test's strict regex for the "Memories sort mirrors the
Sessions/Metrics localeCompare descending pattern" assertion is brittle; update
the matcher for the viewer variable to allow formatting differences while still
ensuring a descending localeCompare on startedAt — i.e., relax the pattern to
look for sessions.sort(...) that contains localeCompare and the operands in
descending order (b.startedAt vs a.startedAt), permit arbitrary
whitespace/newlines and optional || '' or other minor variations, and avoid
matching the entire one-line function text verbatim so harmless reformatting
won't break the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cb4886f9-5156-4233-a22f-aee98e4d3ace
📒 Files selected for processing (2)
src/viewer/index.htmltest/viewer-memories-sort.test.ts
* chore(release): v0.9.23 Bumps version across 9 files + adds CHANGELOG entry summarizing the 18 commits since v0.9.22. Highlights: - GitHub Copilot CLI first-class support (#534) — plugin + hooks + MCP with LSP-style Content-Length framing on the standalone stdio transport. - Five new MCP adapters: Warp, Cline, Continue, Zed, Droid (#677); ADAPTERS count 11 → 17. - Three silent DX bugs fixed: graph extraction never fired on session end (#666 / #698), status reported zero memories (#666), consolidation defaulted off even with an LLM provider configured (#612 / #696). - Nine telemetry hooks switched to fire-and-forget so they don't block Claude Code's next-prompt boundary (#573 / #688). - Hook project field now sends repo basename instead of full filesystem path so auto-injected context isn't silently filtered out (#474 / #687). - Local-LLM docs: Ollama / LM Studio / vLLM section added (#671 / #697). Version-bump files: package.json, plugin/.claude-plugin/plugin.json, plugin/plugin.json, plugin/.codex-plugin/plugin.json, packages/mcp/package.json, src/version.ts, src/types.ts, src/functions/export-import.ts, test/export-import.test.ts. * chore(release): add #701 + #709 to v0.9.23 CHANGELOG
Summary
#674 — viewer Memories tab renders in KV-insertion order, so newly-saved memories appear at the bottom of long lists. Sessions and Metrics tabs already sort
startedAtdesc vialocaleCompare; Memories should match.Changes
src/viewer/index.html—loadMemories()now sorts items newest-first oncreatedAt(fallbackupdatedAt) before storing instate.memories.items. Sort runs once on load, not per render — same pattern the Sessions / Metrics tabs use at viewer:1426 / :2407 / :2420 / :2636. No new deps, no API change.test/viewer-memories-sort.test.ts— 3 source-string assertions confirming the sort + fallback + parallel structure with sessions sort.Test plan
npx vitest run test/viewer-memories-sort.test.ts— 3/3 passmemory_save, refresh Memories tab — new entry appears at top.Closes #674.
Summary by CodeRabbit
New Features
Tests