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 { describe, it, expect, beforeEach, afterEach } from 'bun:test';
import { mkdirSync, writeFileSync, existsSync, rmSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
import {
readCursorRegistry,
writeCursorRegistry,
registerCursorProject,
unregisterCursorProject
} from '../src/utils/cursor-utils';
describe('Cursor Project Registry', () => {
let tempDir: string;
let registryFile: string;
beforeEach(() => {
tempDir = join(tmpdir(), `cursor-registry-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
mkdirSync(tempDir, { recursive: true });
registryFile = join(tempDir, 'cursor-projects.json');
});
afterEach(() => {
try {
rmSync(tempDir, { recursive: true, force: true });
} catch {
// Ignore cleanup errors
}
});
describe('readCursorRegistry', () => {
it('returns empty object when registry file does not exist', () => {
const registry = readCursorRegistry(registryFile);
expect(registry).toEqual({});
});
it('returns empty object when registry file is corrupt JSON', () => {
writeFileSync(registryFile, 'not valid json {{{');
const registry = readCursorRegistry(registryFile);
expect(registry).toEqual({});
});
it('returns parsed registry when file exists', () => {
const expected = {
'my-project': {
workspacePath: '/home/user/projects/my-project',
installedAt: '2025-01-01T00:00:00.000Z'
}
};
writeFileSync(registryFile, JSON.stringify(expected));
const registry = readCursorRegistry(registryFile);
expect(registry).toEqual(expected);
});
});
describe('registerCursorProject', () => {
it('stores project with workspacePath and installedAt', () => {
const before = Date.now();
registerCursorProject(registryFile, 'test-project', '/workspace/test');
const after = Date.now();
const registry = readCursorRegistry(registryFile);
expect(registry['test-project']).toBeDefined();
expect(registry['test-project'].workspacePath).toBe('/workspace/test');
const installedAt = new Date(registry['test-project'].installedAt).getTime();
expect(installedAt).toBeGreaterThanOrEqual(before);
expect(installedAt).toBeLessThanOrEqual(after);
});
it('preserves existing projects when registering new one', () => {
registerCursorProject(registryFile, 'project-a', '/path/a');
registerCursorProject(registryFile, 'project-b', '/path/b');
const registry = readCursorRegistry(registryFile);
expect(Object.keys(registry)).toHaveLength(2);
expect(registry['project-a'].workspacePath).toBe('/path/a');
expect(registry['project-b'].workspacePath).toBe('/path/b');
});
it('overwrites existing project with same name', () => {
registerCursorProject(registryFile, 'my-project', '/old/path');
registerCursorProject(registryFile, 'my-project', '/new/path');
const registry = readCursorRegistry(registryFile);
expect(Object.keys(registry)).toHaveLength(1);
expect(registry['my-project'].workspacePath).toBe('/new/path');
});
});
describe('unregisterCursorProject', () => {
it('removes specified project from registry', () => {
registerCursorProject(registryFile, 'project-a', '/path/a');
registerCursorProject(registryFile, 'project-b', '/path/b');
unregisterCursorProject(registryFile, 'project-a');
const registry = readCursorRegistry(registryFile);
expect(registry['project-a']).toBeUndefined();
expect(registry['project-b']).toBeDefined();
});
it('does nothing when unregistering non-existent project', () => {
registerCursorProject(registryFile, 'existing', '/path');
unregisterCursorProject(registryFile, 'non-existent');
const registry = readCursorRegistry(registryFile);
expect(registry['existing']).toBeDefined();
});
it('handles unregister when registry file does not exist', () => {
unregisterCursorProject(registryFile, 'any-project');
expect(existsSync(registryFile)).toBe(false);
});
});
});