/** * MemPalace — high-level API. * * Combines the global (cross-project) and project (per-repo) stores into * one façade. Most callers use these functions rather than poking the * JsonStore directly because they handle the scope selection: * * - Reads with scope: 'both' search both stores and merge results * - Writes with scope: 'global' or 'project' target one * - Writes with scope: 'both' rejected at runtime — every drawer lives * in exactly one store * * This module is the boundary between the storage internals (types.ts, * store.ts, search.ts) and the agent-facing tools (src/tools/memory.ts) * + slash commands. */ import { JsonStore } from './store.js'; import type { Drawer, Tunnel, KGTriple, Scope, SearchOptions, SearchHit, WingMeta, RoomMeta } from './types.js'; export declare function getGlobalStore(): JsonStore; /** * Is MemPalace enabled in the user's config? Read directly from * ~/.compact-agent/config.json so this can be checked at module-load * time by src/tools/index.ts without creating an import cycle through * src/config.ts (which imports types.ts which we import here). * * Resolves the dir manually (same priority as config.ts) instead of * importing getHomeStateDir to keep this side of the import graph free * of side-effecting modules. * * Treats missing config / missing memory block / undefined enabled as * TRUE (default-on for the featured capability). Only explicit false * disables. */ export declare function isMemoryEnabled(): boolean; /** * Per-project store keyed by `cwd`. If the cwd changes mid-session (the * user `/cd`s elsewhere), the next call gets a fresh store pointing at * the new location. The old one stays valid for any held references. */ export declare function getProjectStore(cwd: string): JsonStore; /** * Heuristic: should a piece of content live in the global or project * store? Used when the agent calls memory_add with scope: 'auto'. * * Signals pushing GLOBAL: content mentions the user by name, talks about * preferences, recurring patterns, identity, or cross-project facts. * Default lean is PROJECT since per-repo facts dominate by volume. */ export declare function inferScope(content: string, tags: string[]): Scope; export interface AddDrawerInput { wing: string; room: string; content: string; tags?: string[]; importance?: number; scope?: Scope | 'auto'; sourceSessionId?: string; cwd: string; } export declare function addDrawer(input: AddDrawerInput): Drawer; export declare function getDrawer(id: string, cwd: string): Drawer | null; export declare function listDrawers(opts: { wing?: string; room?: string; tag?: string; scope?: Scope; cwd: string; }): Drawer[]; /** * Search both stores by default and merge results, re-sorted by score. * Specify scope to limit to one. Returns the top `limit` hits across * the union. */ export declare function search(query: string, cwd: string, opts?: SearchOptions): SearchHit[]; /** * Link two drawers with a labelled relation. Both drawers must live in * the same store — we don't cross global ↔ project boundaries because * the link would silently break if either side is moved/deleted. */ export declare function linkDrawers(fromId: string, toId: string, relation: string, cwd: string): Tunnel; export declare function traverseTunnels(startId: string, cwd: string, maxDepth?: number): { drawer: Drawer; depth: number; via: string[]; }[]; export declare function kgAdd(triple: { subject: string; predicate: string; object: string; confidence?: number; sourceSessionId?: string; sourceDrawerId?: string; }, scope: Scope, cwd: string): KGTriple; export declare function kgQuery(q: { subject?: string; predicate?: string; object?: string; asOf?: string | 'all'; }, cwd: string, scope?: Scope): KGTriple[]; /** * Invalidate a triple by id — finds it in whichever scope owns it, * sets validTo. Use for "this fact stopped being true" without * deleting historical record. */ export declare function kgInvalidate(id: string, cwd: string, endedAt?: string): KGTriple | null; /** * Per-agent timestamped journal. Stored as drawers with * wing="diary", room=`agent_`, tags including the agent name. * * MemPalace's hard-won lesson: lowercase the agent name on both * write and read so "Claude" and "claude" don't silently store/return * disjoint sets. */ export declare function diaryWrite(opts: { agentName: string; entry: string; topic?: string; cwd: string; sourceSessionId?: string; }): Drawer; export declare function diaryRead(opts: { agentName: string; lastN?: number; cwd: string; }): Drawer[]; export declare function kgTimeline(cwd: string, limit?: number, scope?: Scope): KGTriple[]; export declare function listWings(cwd: string, scope?: Scope): { global: WingMeta[]; project: WingMeta[]; }; export declare function listRooms(cwd: string, wing?: string, scope?: Scope): { global: RoomMeta[]; project: RoomMeta[]; }; export declare function stats(cwd: string): { global: ReturnType; project: ReturnType; globalPath: string; projectPath: string; projectExists: boolean; }; export type { Drawer, Tunnel, KGTriple, Scope, SearchHit, SearchOptions, WingMeta, RoomMeta } from './types.js';