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
// Memory's saved theme on <html> before the first paint, so a dark choice never flashes light. scripts/build-viewer.js
// puts this script inline in viewer.html's <head>, where the template has its mark; it runs before the page draws, and
// the bundle loads later, so the script cannot import anything. Its key and choices come from their one definition,
// src/ui/theme-choice.ts (My Work saves its choice under the same key), as My Work's own pre-paint script takes them
// (src/ui/my-work/src/lib/theme-pre-paint.ts). The reading appearance comes from its own definition,
// src/ui/theme-appearance.ts, and is put on <html> here too, so a warm palette or a larger reading size never flashes
// the default first. The app's useTheme and useAppearance keep both after. No imports beyond those modules, so the build
// script and the browser tests can load this file outside the bundle.
import { THEME_CHOICE_STORAGE_KEY, THEME_CHOICES, type ResolvedTheme, type ThemeChoice } from '../../theme-choice';
import {
DEFAULT_THEME_APPEARANCE, FONT_CHOICES, READING_CHOICES, THEME_APPEARANCE_STORAGE_KEY, THEME_PRESETS,
} from '../../theme-appearance';
/** The choice that follows the operating system, and the two themes it resolves to. */
const FOLLOWS_SYSTEM: ThemeChoice = 'system';
const DARK: ResolvedTheme = 'dark';
const LIGHT: ResolvedTheme = 'light';
/** Where viewer-template.html wants the script; the build puts it there and fails when the mark is missing. */
export const VIEWER_THEME_PRE_PAINT_MARK = '<!-- theme-pre-paint -->';
/** The saved choice, else the system's theme; storage that cannot be read follows the system and says why. */
export const VIEWER_THEME_PRE_PAINT_SCRIPT = `(function (key, choices, followsSystem, dark, light, appearanceKey, presets, fonts, readings, defaultAppearance) {
var choice = followsSystem
try {
var saved = localStorage.getItem(key)
if (choices.indexOf(saved) >= 0) choice = saved
} catch (error) {
console.warn('The saved theme could not be read, so the page follows the system theme:', error)
}
if (choice === followsSystem) choice = matchMedia('(prefers-color-scheme: dark)').matches ? dark : light
var root = document.documentElement
root.setAttribute('data-theme', choice)
var look = defaultAppearance
try {
var stored = JSON.parse(localStorage.getItem(appearanceKey) || 'null')
if (stored) look = {
preset: presets.indexOf(stored.preset) >= 0 ? stored.preset : defaultAppearance.preset,
font: fonts.indexOf(stored.font) >= 0 ? stored.font : defaultAppearance.font,
reading: readings.indexOf(stored.reading) >= 0 ? stored.reading : defaultAppearance.reading
}
} catch (error) {
console.warn('The saved reading appearance could not be read, so the default is used:', error)
}
root.setAttribute('data-palette', look.preset)
root.setAttribute('data-font', look.font)
root.setAttribute('data-reading', look.reading)
})(${[THEME_CHOICE_STORAGE_KEY, THEME_CHOICES, FOLLOWS_SYSTEM, DARK, LIGHT,
THEME_APPEARANCE_STORAGE_KEY, THEME_PRESETS, FONT_CHOICES, READING_CHOICES, DEFAULT_THEME_APPEARANCE]
.map(value => JSON.stringify(value)).join(', ')})`;
/** The template with the script where its mark is. Fails loudly when the mark is missing, so no build ships without it. */
export function withViewerThemePrePaintScript(html: string): string {
if (!html.includes(VIEWER_THEME_PRE_PAINT_MARK)) {
throw new Error(`viewer-template.html has no ${VIEWER_THEME_PRE_PAINT_MARK} mark for the pre-paint theme script`);
}
// A function, so no `$` in the script is read as a replacement pattern.
return html.replace(VIEWER_THEME_PRE_PAINT_MARK, () => `<script>${VIEWER_THEME_PRE_PAINT_SCRIPT}</script>`);
}