/** * Read-only observability over the local SQLite authority for first-party * * tooling (the `spreadsheet-db-mcp` server).. * * This module is deliberately NOT part of the public application contract: * it is exposed only through the unstable `hikoutei/internal/sync-status` * subpath so the MCP layer can report outbox delivery state and unresolved * conflicts without widening `src/index.ts`. It opens its own read-only * `node:sqlite` connection and never mutates the database, so it coexists * with a running sync worker (the WAL lets multiple readers share the file). * * Failure model: malformed arguments raise a structured * {@link HikouteiSyncStatusError}; a database file that does not exist yet or * a database without sync tables (local-only mode) is not an error — it maps * to `{ mode: "local" }` and an empty conflict list respectively. */ import { CONFLICT_STATUSES } from "../contracts/domain/model/constants.js"; /** Stable machine-readable codes raised by the internal status reader. */ export declare const HIKOUTEI_SYNC_STATUS_ERROR_CODES: { /** The dbName argument is not a non-empty string. */ readonly INVALID_DB_NAME: "invalid_db_name"; /** The SQLite file exists but could not be opened read-only. */ readonly OPEN_FAILED: "open_failed"; /** A status query failed against an unexpected storage state. */ readonly READ_FAILED: "read_failed"; }; /** Closed set of internal status-reader error codes. */ export type HikouteiSyncStatusErrorCode = (typeof HIKOUTEI_SYNC_STATUS_ERROR_CODES)[keyof typeof HIKOUTEI_SYNC_STATUS_ERROR_CODES]; /** Structured error raised by this module; never part of the public API. */ export declare class HikouteiSyncStatusError extends Error { readonly code: HikouteiSyncStatusErrorCode; constructor(code: HikouteiSyncStatusErrorCode, message: string, cause?: unknown); } /** Plain scalar value extracted from a stored normalized cell. */ export type HikouteiStoredValue = string | number | boolean | null; /** Unresolved conflict lifecycle states surfaced by `listHikouteiConflicts`. */ export type HikouteiOpenConflictStatus = (typeof CONFLICT_STATUSES)["OPEN"] | (typeof CONFLICT_STATUSES)["NEEDS_REBASE"]; /** Delivery-focused counts over the durable Sheet effect outbox. */ export interface HikouteiSyncEffectCounts { readonly pending: number; readonly processing: number; readonly deliveryUncertain: number; readonly failed: number; } /** Unresolved conflict counts. */ export interface HikouteiSyncConflictCounts { readonly open: number; readonly needsRebase: number; } /** * Sync observability snapshot. * * - `{ mode: "local" }`: no sync tables exist (local-only runtime, or the * database file has not been created yet). * - `{ mode: "sync" }`: sync state exists; `spreadsheetId` is the bound * spreadsheet's ID (full URLs are never returned) or `null` when the * authority row has not been written yet. */ export type HikouteiSyncStatus = { readonly mode: "local"; } | { readonly mode: "sync"; readonly spreadsheetId: string | null; readonly effects: HikouteiSyncEffectCounts; readonly conflicts: HikouteiSyncConflictCounts; }; /** One unresolved human-edit conflict, values decoded to plain scalars. */ export interface HikouteiConflictSummary { readonly conflictId: string; readonly entityId: string; readonly fieldName: string; readonly userValue: HikouteiStoredValue; readonly currentCanonicalValue: HikouteiStoredValue; readonly userBaseRevision: number; readonly currentCanonicalRevision: number; readonly candidateEpoch: number; readonly status: HikouteiOpenConflictStatus; readonly updatedAt: number; } /** Options accepted by the read-only status queries. */ export interface HikouteiSyncStatusOptions { /** SQLite database file path used by the runtime. */ readonly dbName: string; } /** Options accepted by `listHikouteiConflicts`. */ export interface HikouteiConflictListOptions extends HikouteiSyncStatusOptions { /** Maximum number of conflicts to return; default 50, capped at 500. */ readonly limit?: number; } /** Default conflict page size when `limit` is omitted. */ export declare const DEFAULT_CONFLICT_LIST_LIMIT = 50; /** Hard upper bound for one conflict page; protects caller context windows. */ export declare const MAX_CONFLICT_LIST_LIMIT = 500; /** * Reads a delivery/conflict snapshot from the SQLite authority. * * Returns `{ mode: "local" }` when the database file does not exist yet or * was created by a local-only runtime (no sync tables). Never writes, never * opens the network, and never returns spreadsheet URLs — only the ID. */ export declare function readHikouteiSyncStatus(options: HikouteiSyncStatusOptions): Promise; /** * Lists unresolved (OPEN / NEEDS_REBASE) conflicts, newest first. * * Stored cell values are decoded from normalized cells into plain scalars; * a value that fails decoding falls back to its raw stored text so a corrupt * row can still be inspected instead of failing the whole listing. Returns * an empty list for local-only databases. */ export declare function listHikouteiConflicts(options: HikouteiConflictListOptions): Promise; //# sourceMappingURL=syncStatus.d.ts.map