/**
 * JSON-RPC 2.0 client for the loop-engine daemon.
 *
 * Connects to a long-running engine process at
 * `~/.opensquid/loop-engine.sock` via Unix domain socket. The daemon
 * is acquired-or-spawned by `acquireOrSpawnEngine()` (singleton.ts),
 * so multiple `EngineClient` instances across hooks + sessions share
 * the same underlying engine process — the keystone for cross-session
 * memory recall.
 *
 * Critical invariants (T.1 audit + T.4 spec):
 *
 *  1. **Singleton transport** — `EngineClient` no longer owns a
 *     subprocess. It holds a `net.Socket` connection to a shared
 *     daemon. Engine lifecycle lives in `singleton.ts`; closing a
 *     client only closes the connection, not the engine.
 *
 *  2. **LOOP_HOME pin** (T.1.D) — handled by `singleton.ts` at spawn
 *     time. Engine defaults `~/.loop`; opensquid pins to
 *     `~/.opensquid`. Stripping the pin would make existing memories
 *     + lessons silently invisible.
 *
 *  3. **Auto-reconnect on socket close** — if the daemon restarts
 *     (kill -9, OOM, manual `engine kill`), the next `call()` will
 *     re-acquire via the singleton. Pending calls reject so callers
 *     can retry.
 *
 *  4. **Error wire shape** — five engine-custom codes in
 *     `-32000..=-32004` range. `RpcError` carries `.code` + `.data`
 *     so callers branch on the structured field, not the message.
 *
 *  5. **Authored_by wire encoding** — INPUT accepts `'user' | 'pack'`
 *     (else maps to engine's `Llm` default); OUTPUT is
 *     `'user' | 'pack' | 'agent'` (`Llm` renders as `"agent"`).
 *
 *  6. **Windows fallback** — UDS is Unix-only. On Windows,
 *     `acquireOrSpawnEngine()` throws; callers wrap with a feature
 *     flag (`OPENSQUID_ENGINE_SOCKET=disable`) to fall back to the
 *     legacy per-process stdio spawn (NOT implemented here yet —
 *     tracked as T.8 follow-up).
 *
 * Types live in `./types.js` — this file owns the transport + class.
 */
import type { CompressParams, CompressResult, ConsolidateParams, ConsolidateResult, CreateMemoryResult, GetMemoryResult, LessonCaptureFeedbackResult, LessonCreateParams, LessonCreateResult, LessonDiscardResult, LessonListResult, LessonPromoteResult, LessonRecallResult, LessonSupersedeResult, ManifestAssembleParams, ManifestAssembleResult, MemoryDeleteResult, MemoryListResult, MemoryOrigin, MemoryScope, MemorySearchParams, MemorySearchResult, MemoryUpdateResult, RecomputeCitationsResult, ScopeFilterWire, TaskGetLedgerResult, TaskLogPhaseResult } from './types.js';
/**
 * JSON-RPC error response surfaced as a JS Error subclass. `.code` +
 * `.data` carry the engine-side fields so callers can branch without
 * pattern-matching `.message`.
 */
export declare class RpcError extends Error {
    readonly code: number;
    readonly data?: unknown;
    constructor(message: string, code: number, data?: unknown);
}
/**
 * Engine error codes (verified against engine/src/serve.rs:226-258).
 *
 * Standard JSON-RPC range (-32700 / -32600 / -32601 / -32602 / -32603)
 * is mirrored for completeness. Engine-custom codes occupy
 * `-32000..=-32004` and carry a structured `data` payload per T.1.E.
 */
export declare const ENGINE_ERROR: {
    readonly PARSE: -32700;
    readonly INVALID_REQUEST: -32600;
    readonly METHOD_NOT_FOUND: -32601;
    readonly INVALID_PARAMS: -32602;
    readonly INTERNAL: -32603;
    /** data: { reasons: string[] } — kebab-case reasons per T.1.E + T.1.F */
    readonly PROMOTION_BLOCKED: -32000;
    /** data: { lesson_id: string } */
    readonly USER_LESSON_IMMUNE: -32001;
    /** data: { id: string } */
    readonly NOT_FOUND: -32002;
    /** data: { memory_id: string, cited_by: number } */
    readonly USER_MEMORY_IMMUNE: -32003;
    /** data: { reason: string } */
    readonly SUPERSEDE_BLOCKED: -32004;
};
/**
 * Socket + JSON-RPC plumbing. One instance ≡ one connection to the
 * shared engine daemon. Connection is established lazily on first
 * `call`. Survives daemon restarts: when the socket closes, the next
 * call re-acquires via `acquireOrSpawnEngine()`.
 */
export declare class EngineClient {
    private socket;
    private reader;
    private pending;
    private nextId;
    private startupAck;
    private spawnedByUs;
    ping(): Promise<{
        ok: true;
        version: string;
    }>;
    lessonCreate(p: LessonCreateParams): Promise<LessonCreateResult>;
    lessonRecall(p: {
        query: string;
        limit?: number;
    }): Promise<LessonRecallResult>;
    lessonPromote(p: {
        id: string;
    }): Promise<LessonPromoteResult>;
    lessonDiscard(p: {
        id: string;
        reason?: string;
        force?: boolean;
    }): Promise<LessonDiscardResult>;
    lessonList(p: {
        statuses?: string[];
        limit?: number;
        offset?: number;
    }): Promise<LessonListResult>;
    lessonCaptureFeedback(p: {
        id: string;
        polarity: 'thumbs_up' | 'thumbs_down';
        source_signal_id?: string;
    }): Promise<LessonCaptureFeedbackResult>;
    lessonSupersede(p: {
        old_id: string;
        new_id: string;
        force?: boolean;
    }): Promise<LessonSupersedeResult>;
    memoryCreate(p: {
        description: string;
        content: string;
        authored_by?: string;
        scope?: MemoryScope;
        origin?: MemoryOrigin;
    }): Promise<CreateMemoryResult>;
    memorySearch(p: MemorySearchParams): Promise<MemorySearchResult>;
    memoryGet(p: {
        id: string;
    }): Promise<GetMemoryResult>;
    memoryList(p: {
        scope_filter?: ScopeFilterWire;
        limit?: number;
        offset?: number;
    }): Promise<MemoryListResult>;
    memoryUpdate(p: {
        id: string;
        description?: string;
        content?: string;
        scope?: MemoryScope;
    }): Promise<MemoryUpdateResult>;
    memoryDelete(p: {
        id: string;
        force?: boolean;
    }): Promise<MemoryDeleteResult>;
    /**
     * Compress a window of memories into one gist `Mc` (CMP.1). Pure
     * exposure of the engine's `compress()` lib fn — mints `Mc` with
     * `derived_from = ids` + summed citation counters; does NOT delete
     * predecessors (that is the host's verified, gated terminal step).
     */
    memoryCompress(p: CompressParams): Promise<CompressResult>;
    /**
     * Atomic safe-compression (CMP.4). The engine compresses the window
     * into one gist `Mc`, VERIFIES via recall-replay that `Mc` preserves
     * each predecessor's recall, and ONLY THEN force-deletes the
     * NON-immune predecessors — user-cited ones are kept. Any error or
     * verify-miss → deletes NOTHING and returns `verified: false` with
     * the minted `Mc` id (so the host keeps `Mc` alongside the originals
     * + surfaces drift).
     *
     * The D2 safety contract (verify + immunity + fail-closed) is
     * GUARANTEED inside the engine (race-free, universal substrate
     * integrity) — the host no longer runs recall-replay or issues any
     * `memory.delete` in the compression path.
     */
    memoryConsolidate(p: ConsolidateParams): Promise<ConsolidateResult>;
    /**
     * Recompute every memory's `consumed_by_user_lessons` counter to
     * ground truth (CMP.1). A host runs this after a batch of
     * compressions / deletions to confirm citation integrity survived
     * the `derived_from` chain.
     */
    memoryRecomputeCitations(): Promise<RecomputeCitationsResult>;
    manifestAssemble(p: ManifestAssembleParams): Promise<ManifestAssembleResult>;
    taskLogPhase(p: {
        task_id: string;
        phase: string;
        note?: string;
    }): Promise<TaskLogPhaseResult>;
    taskGetLedger(p: {
        task_id: string;
    }): Promise<TaskGetLedgerResult>;
    /**
     * Send a JSON-RPC request, await the response. Throws `RpcError` on
     * engine-side errors; throws `Error` on socket close mid-call.
     *
     * The startup `ping` call passes through without re-entering
     * `ensureConnected` to break the chicken-and-egg.
     */
    call<T = unknown>(method: string, params: unknown): Promise<T>;
    /**
     * Close the connection to the engine daemon. Does NOT kill the
     * daemon — engine lifecycle is owned by `singleton.ts` (and by
     * T.7's `engine kill` for explicit teardown). After close(), the
     * next `call()` will re-acquire.
     */
    close(): Promise<void>;
    /**
     * Returns true if this client's last connection was the one that
     * spawned the engine daemon. Useful for telemetry — production
     * callers should not rely on this for correctness.
     */
    get didSpawnEngine(): boolean;
    private ensureConnected;
    private onLine;
    /**
     * Clear connection state on close so the next call re-acquires.
     * Mirrors the pre-T.4 behavior for subprocess exits — the daemon
     * may restart out-of-band (kill -9, OOM, T.7 `engine kill`) and
     * the next call should transparently respawn / reconnect.
     */
    private onClose;
}
//# sourceMappingURL=client.d.ts.map