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
// The theme a person picks, one choice for My Work and Memory (the memory viewer) (My Work design pass, Phase 11): the
// choices' one definition and the one place both apps save the choice, so a choice made in one is the other's on its
// next load (both are served from the same origin). No imports and no React, so My Work, its pre-paint script, its
// node tests, vite.config.ts and the viewer bundle (whose tsconfig cannot leave src/ui) can all load it.
/** The theme choices, in the order both apps offer them. "System" follows the operating system. */
export const THEME_CHOICES = ['system', 'light', 'dark'] as const
export type ThemeChoice = (typeof THEME_CHOICES)[number]
export type ResolvedTheme = Exclude<ThemeChoice, 'system'>
/**
* The localStorage key both apps save the choice under. It is Memory's own key from before the two shared one, kept so
* the choice every Memory user already saved stays theirs (a new key would drop it). My Work saved its choice inside
* its display preferences before; it moves that value here once (src/ui/my-work/src/lib/theme.ts).
*/
export const THEME_CHOICE_STORAGE_KEY = 'claude-mem-theme'
/** The part of localStorage the theme uses. My Work's store passes its own; left out, the browser's localStorage. */
export type ThemeStorage = Pick<Storage, 'getItem' | 'setItem'>
export function isThemeChoice(value: unknown): value is ThemeChoice {
return THEME_CHOICES.includes(value as ThemeChoice)
}
export function resolveTheme(choice: ThemeChoice, systemDark: boolean): ResolvedTheme {
if (choice !== 'system') return choice
return systemDark ? 'dark' : 'light'
}
/**
* The saved choice, or null when none is saved or the saved value is not a choice. Storage that cannot be read (blocked
* site data) is said in the console and reads as none, so the page follows the system.
*/
export function readSavedThemeChoice(storage?: ThemeStorage): ThemeChoice | null {
try {
const saved = (storage ?? localStorage).getItem(THEME_CHOICE_STORAGE_KEY)
return isThemeChoice(saved) ? saved : null
} catch (error: unknown) {
console.warn('The saved theme could not be read, so the page follows the system theme:', error instanceof Error ? error.message : String(error))
return null
}
}
/**
* Saves the choice for both apps. Storage that cannot be written (blocked site data) is said in the console; the choice
* then lasts only while the page is open.
*/
export function saveThemeChoice(choice: ThemeChoice, storage?: ThemeStorage): void {
try {
(storage ?? localStorage).setItem(THEME_CHOICE_STORAGE_KEY, choice)
} catch (error: unknown) {
console.warn('The theme could not be saved, so it lasts only while this page is open:', error instanceof Error ? error.message : String(error))
}
}