/** * pi-loom: Shared Types & Helpers * * Extracted from store.ts to reduce file size and improve modularity. * All types and helper functions live here — no database dependency. */ import Database from "better-sqlite3"; export type MemStatus = "active" | "expired" | "archived"; /** How a memory was created — replaces the old JSON provenance object. */ export type Provenance = "direct" | "auto_captured" | "extracted_fact" | "consolidated_pattern" | "dream_insight" | "entity_profile"; /** A link in the derivation chain: what this memory was derived from. */ export interface DerivationLink { id: string; type: "event" | "memory"; weight: number; } export interface MemRow { id: string; content: string; fact_summary: string | null; entity_id: string | null; kind: string | null; scope_type: string | null; scope_id: string | null; confidence: number | null; visibility: string | null; valid_at: string; expire_at: string | null; importance: number; status: MemStatus; tags: string | null; content_hash: string | null; created_at: string; recall_count: number; last_recalled_at: string | null; hit_count: number; last_hit_at: string | null; session_ids: string | null; provenance: string | null; derivation: string | null; } export interface RawEventRow { id: string; session_id: string; event_type: string; payload: string; created_at: string; } export interface SessionSummaryRow { id: string; session_id: string; summary: string; decisions: string | null; errors: string | null; changes: string | null; unfinished: string | null; memory_ids: string | null; created_at: string; } export interface EpisodeRow { episode_id: string; session_id: string; summary: string | null; entity_id: string | null; token_count: number | null; created_at: string; } export interface EntityEdgeRow { edge_id: string; source_entity: string; target_entity: string; relation_type: string; memory_id: string | null; episode_id: string | null; confidence: number; created_at: string; } export interface MemoryEdgeRow { edge_id: string; source_id: string; target_id: string; relation: string; confidence: number; created_at: string; } export interface ConstraintRow { id: string; entity_id: string; description: string; path_condition: string | null; enforcement: "warn" | "block" | "log"; state: "active" | "satisfied" | "violated" | "archived"; created_at: string; last_checked_at: string | null; } export declare function parseTags(tags: string | null): string[]; export declare function genId(): string; export declare function estimateTokens(text: string): number; export declare function getDbDir(): string; export declare function getDbPath(): string; export declare function openDb(): Database.Database;