/** * MemPalace data model — TypeScript port of the core MemPalace concepts. * * Mental model: * * Wing ─ a top-level domain ("projects", "people", "code", "wisdom") * Room ─ a category inside a wing ("crowcoder", "abc-reborn", ...) * Drawer ─ an individual memory item: a chunk of text + tags + metadata * Tunnel ─ a directed link between two drawers, typed by relation * Triple ─ a knowledge-graph fact: (subject, predicate, object) * * Drawers are the atomic unit of memory. Wings + rooms give them addressable * structure. Tunnels and KG triples give them relational structure. * * Two stores live side-by-side: * GLOBAL ~/.compact-agent/memory/ cross-project knowledge (user prefs, * recurring patterns, skills) * PROJECT /.compact-agent/memory/ this-codebase-specific (e.g. "build * is broken because X", "the queue lives * in services/queue/...") * * The agent picks which store to query based on the request. User-modeling * queries hit global; codebase queries hit project. Search APIs accept a * Scope hint or 'both' to search across. */ /** * Which memory store an operation targets. * * 'global' — ~/.compact-agent/memory/ (cross-project) * 'project' — /.compact-agent/memory/ (per-repo) * 'both' — search both; writes pick based on content (global for user * preferences, project for codebase facts) */ export type Scope = 'global' | 'project' | 'both'; /** * A drawer is one memory item — a chunk of text living at wing/room. Tags * are free-form lowercase strings used for filtering. Importance is a 0–1 * heuristic the agent or user can set to bias search ordering. */ export interface Drawer { id: string; wing: string; room: string; content: string; tags: string[]; importance: number; createdAt: string; updatedAt: string; scope: Scope; sourceSessionId?: string; } /** * Convenience metadata about a wing — populated by `listWings` for UI/ * status output. Not stored separately; derived from drawer counts. */ export interface WingMeta { name: string; rooms: string[]; drawerCount: number; } /** * Same for rooms. */ export interface RoomMeta { wing: string; name: string; drawerCount: number; lastTouched: string; } /** * A tunnel is a directed link from one drawer to another with a labelled * relation. Use cases: * - "drawer A inspired drawer B" (relation: "inspired") * - "drawer A supersedes drawer B" (relation: "supersedes") * - "drawer A is part of drawer B's project" (relation: "in-project") * * Bidirectional traversal is supported by following tunnels in reverse. */ export interface Tunnel { id: string; fromDrawerId: string; toDrawerId: string; relation: string; createdAt: string; scope: Scope; } /** * A knowledge-graph triple — semantic-web style. Stored separately from * drawers because triples express *facts* (small, atomic, queryable in * aggregate) whereas drawers express *content* (larger, narrative). * * Example: ("rsfit", "owns", "Crowcoder") or ("compact-agent", "uses", * "OpenRouter"). */ export interface KGTriple { id: string; subject: string; predicate: string; object: string; confidence: number; sourceDrawerId?: string; sourceSessionId?: string; createdAt: string; scope: Scope; validFrom?: string; validTo?: string; } /** * Internal disk schema. One JSON file per store containing all drawers, * tunnels, and triples. Simple, atomic-write-via-rename safe. * * For very large stores (>10k drawers) this approach will get slow; the * intent is to swap to SQLite/FTS5 later behind the same Store interface. */ export interface StoreState { schemaVersion: number; drawers: Drawer[]; tunnels: Tunnel[]; triples: KGTriple[]; } export declare const SCHEMA_VERSION = 1; /** * Search options shared across query APIs. */ export interface SearchOptions { scope?: Scope; wing?: string; room?: string; tags?: string[]; limit?: number; minImportance?: number; } /** * A scored search hit — the drawer plus the relevance score the search * function computed. Higher = more relevant. Score is unitless; only * meaningful for ordering, not absolute comparison. */ export interface SearchHit { drawer: Drawer; score: number; matchedFields: ('content' | 'tags' | 'wing' | 'room')[]; }