Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More
TypeScript aiai-agentsai-memoryanthropicartificial-intelligencechromadbclaudeclaude-agent-sdkclaude-agentsclaude-codeclaude-code-pluginclaude-skillsembeddingslong-term-memorymem0memory-engineopenmemoryragsqlitesupermemory
import { expect, it } from 'bun:test';
import {
FIXTURE_PAGE_HTML, UNTHROTTLED_TIMER_FLAGS, chromeExecutablePath, compileBrowserFixture,
failOnCiWithoutChrome, htmlResponse, launchChrome, scriptResponse, withTimeout, type OwnedChrome,
} from '../../helpers/chrome-devtools';
failOnCiWithoutChrome('CI requires Chrome for selected category clearing.');
(chromeExecutablePath ? it : it.skip)('can clear the type chosen in All types after deleting its last memory', async () => {
const bundle = compileBrowserFixture(`
import React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './src/ui/viewer/App';
import { setStoredWelcomeDismissed } from './src/ui/viewer/components/WelcomeCard';
setStoredWelcomeDismissed(true);
window.confirm = () => { throw new Error('The viewer must not use the browser confirm box'); };
createRoot(document.getElementById('root')).render(<App />);
async function until(predicate) {
const deadline = Date.now() + 6000;
while (!predicate()) {
if (Date.now() > deadline) throw new Error('Category fixture did not settle');
await new Promise(resolve => setTimeout(resolve, 20));
}
}
const titles = () => [...document.querySelectorAll('.mem-record .mem-row-title')].map(node => node.textContent);
// The All types menu, opened; each kind is a checkbox item with its words and its count.
async function typesMenu() {
const trigger = document.querySelector('.mem-types-trigger');
if (trigger.getAttribute('aria-expanded') !== 'true') trigger.click();
await until(() => trigger.getAttribute('aria-expanded') === 'true');
return [...document.querySelectorAll('.mem-types-menu [role="menuitemcheckbox"]')];
}
const kind = (items, words) => items.find(item => item.querySelector('.menu-item-label').textContent === words);
(async () => {
try {
await until(() => titles().length === 2);
kind(await typesMenu(), 'Bugfix').click();
await until(() => titles().length === 1 && titles()[0] === 'OWNED_BUGFIX');
// Delete through the opened row's Record actions and its in-page question (no browser confirm box).
document.querySelector('.mem-record--observation .mem-record-row').click();
await until(() => document.querySelector('.mem-record-menu'));
document.querySelector('.mem-record-menu').click();
await until(() => document.querySelector('.mem-record .menu-button--open'));
[...document.querySelectorAll('.mem-record--observation [role="menuitem"]')].find(item => item.textContent.includes('Delete')).click();
await until(() => document.querySelector('.inline-confirm-danger'));
document.querySelector('.inline-confirm-danger').click();
await until(() => !document.body.textContent.includes('OWNED_BUGFIX'));
const afterDelete = titles();
const items = await typesMenu();
const bugfix = kind(items, 'Bugfix');
const selected = bugfix?.getAttribute('aria-checked') === 'true';
const zeroLabel = bugfix?.querySelector('.menu-item-hint').textContent === '0';
const unrelatedEmptyChip = !!kind(items, 'Feature');
const button = document.querySelector('.mem-types-value').textContent;
if (bugfix) {
bugfix.click();
await until(() => titles().includes('OWNED_DISCOVERY'));
}
await fetch('/result', { method: 'POST', body: JSON.stringify({ afterDelete, selected, zeroLabel,
unrelatedEmptyChip, button, afterClear: titles(), cleared: document.querySelector('.mem-types-value').textContent }) });
} catch (error) { await fetch('/result', { method: 'POST', body: JSON.stringify({ failure: String(error) }) }); }
})();
`);
let report!: (value: unknown) => void;
const result = new Promise<unknown>(resolve => { report = resolve; });
let deletes = 0;
const common = { project: 'owned-project', content_session_id: 'owned-session', platform_source: 'claude',
created_at: new Date().toISOString(), created_at_epoch: Date.now(), narrative: 'Owned fixture',
facts: '[]', concepts: '[]', files_read: '[]', files_modified: '[]' };
const observations = [{ ...common, id: 1, type: 'bugfix', title: 'OWNED_BUGFIX' },
{ ...common, id: 2, type: 'discovery', title: 'OWNED_DISCOVERY' }];
const server = Bun.serve({ hostname: '127.0.0.1', port: 0, async fetch(request) {
const url = new URL(request.url);
if (url.pathname === '/') return htmlResponse(FIXTURE_PAGE_HTML);
if (url.pathname === '/fixture.js') return scriptResponse(bundle);
if (url.pathname === '/stream') return new Response(new ReadableStream({ start(controller) {
controller.enqueue(new TextEncoder().encode('data: {"type":"initial_load","projects":["owned-project"]}\n\n'));
} }), { headers: { 'Content-Type': 'text/event-stream' } });
if (url.pathname === '/api/observations') return Response.json({ items: observations, hasMore: false });
if (url.pathname === '/api/summaries' || url.pathname === '/api/prompts') return Response.json({ items: [], hasMore: false });
if (url.pathname === '/api/observation/1' && request.method === 'DELETE') {
deletes++; return Response.json({ success: true });
}
if (url.pathname === '/api/processing-status') return Response.json({ isProcessing: false, queueDepth: 0 });
if (url.pathname === '/api/projects') return Response.json({ projects: ['owned-project'], sources: ['claude'],
projectsBySource: { claude: ['owned-project'] } });
if (url.pathname === '/result') { report(await request.json()); return new Response('received'); }
return Response.json({});
} });
let chrome: OwnedChrome | undefined;
try {
chrome = launchChrome(server.url.href, { profilePrefix: 'claude-mem-category-clear-', extraFlags: UNTHROTTLED_TIMER_FLAGS });
const actual = await withTimeout(result, 30000, 'Owned selected category fixture timed out');
console.log('SELECTED_CATEGORY_PROOF', JSON.stringify(actual));
expect(deletes).toBe(1);
// The chosen kind stays in the menu, checked, at 0, so it can be cleared; a kind with no rows is not offered.
expect(actual).toEqual({ afterDelete: [], selected: true, zeroLabel: true, unrelatedEmptyChip: false,
button: 'Bugfix', afterClear: ['OWNED_DISCOVERY'], cleared: 'All types' });
} finally {
await chrome?.close(); server.stop(true);
}
}, 80000);