/** * Script: cli-migrate.ts * Purpose: User-facing `hmem migrate` — safely upgrade a v1 (.hmem) store to v2. * Author: DEVELOPER * Created: 2026-05-27 * * Safety contract (see docs/.../2026-05-26-v2-hmem-migrate-command-plan.md §2): * Until the single atomic rename in the swap step, LIVE is byte-for-byte the * original. A timestamped backup (live + -wal/-shm sidecars, copied verbatim) * is the safety net for the rename window and is ALWAYS kept. * * The migrator itself (./migrate/v1-to-v2.js) opens --in READ-ONLY and writes only * --out, so it never mutates the live file. This module orchestrates classify → * quiesce → confirm → backup → migrate-to-temp → validate → atomic-swap → verify. */ import { type MigrationReport } from './migrate/v1-to-v2.js'; export type Classification = 'missing' | 'v1' | 'v2' | 'ambiguous'; export type MigrateAction = 'migrated' | 'side-by-side' | 'dry-run' | 'noop-already-v2' | 'noop-missing' | 'refused-locked' | 'refused-ambiguous' | 'aborted' | 'failed'; export interface MigrateOutcome { action: MigrateAction; exitCode: number; message: string; backupPath?: string; report?: MigrationReport; } /** Probe for a serve lockfile next to LIVE. Returns null if none, else {pid, alive}. */ export type LockProbe = (dir: string, livePath: string) => { pid: number; alive: boolean; } | null; /** Source counts captured before migration, passed to the validator for sanity checks. */ export interface SourceCounts { memories: number; memoryNodes: number; } /** Validates the freshly-written TMP v2 store (read-only). Throws on any failure. */ export type Validator = (tmpPath: string, source: SourceCounts) => void; export interface MigratePlanOpts { in: string; out?: string; dryRun?: boolean; yes?: boolean; keepBackup?: boolean; confirm?: () => Promise; probeLock?: LockProbe; validate?: Validator; log?: (msg: string) => void; } /** * Classify a store path WITHOUT mutating it. Opens read-only and inspects * sqlite_master + schema_version, mirroring openDb()'s precheck. */ export declare function classify(path: string): Classification; /** Default lock probe: read /.hmem.serve.lock and report PID liveness. */ export declare const defaultLockProbe: LockProbe; export declare function migratePlan(opts: MigratePlanOpts): Promise; export declare function runMigrate(argv: string[]): Promise;