/** * AnchorManager - Manages anchors (critical information that survives context compaction) */ import type { Anchor, AnchorInput, AnchorQueryOptions, AnchorClearOptions, AnchorManagerOptions, AnchorEventHandler } from './types.js'; /** * AnchorManager - Manages critical information that survives context compaction * * @example * ```typescript * const manager = new AnchorManager({ * maxAnchors: 20, * maxTokens: 2000, * persistPath: '~/.myapp/anchors.json', * }); * * // Add a session anchor * manager.add({ * content: 'This session we implemented: edit tool, grep tool', * priority: 'critical', * scope: 'session', * }); * * // Get formatted anchors for injection into LLM messages * const formatted = manager.format(); * ``` */ export declare class AnchorManager { private readonly anchors; private readonly options; private eventHandler?; constructor(options?: AnchorManagerOptions); /** * Set the event handler for anchor events */ onEvent(handler: AnchorEventHandler): void; /** * Emit an event */ private emit; /** * Add a new anchor * * @param input - Anchor input (id and createdAt auto-generated if not provided) * @returns The created anchor */ add(input: AnchorInput): Anchor; /** * Get an anchor by ID */ get(id: string): Anchor | undefined; /** * Get all anchors, optionally filtered */ getAll(options?: AnchorQueryOptions): Anchor[]; /** * Check if an anchor exists */ has(id: string): boolean; /** * Remove an anchor by ID * * @returns true if anchor was removed, false if not found */ remove(id: string): boolean; /** * Clear anchors based on criteria */ clear(options?: AnchorClearOptions): number; /** * Get all anchors for a specific project * * @param projectId - The project ID to filter by * @param options - Additional query options (priority, scope, tags) */ getByProject(projectId: string, options?: Omit): Anchor[]; /** * Get all global anchors (those without a projectId) * * @param options - Additional query options (priority, scope, tags) */ getGlobal(options?: Omit): Anchor[]; /** * Clear all anchors for a specific project * * @param projectId - The project ID * @returns Number of anchors removed */ clearByProject(projectId: string): number; /** * Get list of unique project IDs that have anchors */ getProjectIds(): string[]; /** * Check if a project has any anchors */ hasProjectAnchors(projectId: string): boolean; /** * Get anchor counts grouped by project * * @returns Map where keys are project IDs (null for global) and values are counts */ getProjectStats(): Map; /** * Get the current number of anchors */ get size(): number; /** * Get total tokens used by all anchors */ getTotalTokens(): number; /** * Get token budget utilization (0-1) */ getUtilization(): number; /** * Format anchors for injection into LLM messages * * Groups anchors by priority and formats them for the system message. */ format(): string; /** * Check if an anchor is expired */ private isExpired; /** * Clean up expired temporary anchors */ private cleanupExpired; /** * Make room for new content by removing low-priority anchors */ private makeRoom; /** * Remove the oldest low-priority anchor to make room */ private removeOldestLowPriority; /** * Load persistent anchors from disk */ private loadPersistent; /** * Save persistent anchors to disk */ private savePersistent; /** * Expand ~ in paths */ private expandPath; }