import { type ArgsOf, type Event, type Op, type ResultOf } from "./protocol.js"; export declare class DaemonError extends Error { code: string | undefined; /** M51: the daemon answered so (a refusal), not this side (no connection, no answer). */ fromDaemon: boolean; constructor(message: string, code?: string); } /** M51: a request id (docs/protocol.md "Request ids"): new for each request, the same for each resend of it. */ export declare function newRequestId(tag: string): string; /** M51: thrown by a `via` that will never give a connection (its caller is closing): requestOnce stops at once. */ export declare class GiveUp extends Error { } /** * M51: a reply or a dispatch whose answer may be lost: sent with a request id, and when * no answer comes because the connection went (the daemon restarted), sent again with the * same id on the connection `via(deadline)` gives then, until `timeoutMs`; the daemon * takes it once. A refusal (the daemon answered it) is not sent again. Given up after it * was sent, the error is a DaemonError with code `lost`: it may have been taken (a caller * must not undo what a taken request made, such as a new session's worktree). */ export declare function requestOnce(via: (deadline: number) => Promise, op: O, args: ArgsOf, opts?: { timeoutMs?: number; tag?: string; }): Promise>; /** Package root: the nearest ancestor of this module holding package.json. */ export declare function packageRoot(): string; export declare const daemonEntry: () => string; export declare const hostEntry: () => string; export declare class DaemonClient { private sock; private reader; private nextId; private pending; /** M22: lines received so far: an event's or a reply's place in the stream. */ private lines; private listeners; private closeListeners; private closed; private constructor(); /** Connect to a running daemon; rejects when none is listening. */ static connect(socketPath?: string): Promise; /** Connect, starting the daemon first when it is not running. */ static connectOrStart(timeoutMs?: number): Promise; request(op: O, args: ArgsOf): Promise>; /** * M22: a request and where its reply was in the stream: events with a higher `position()` * came after it (an event handled before the reply's continuation runs may be newer). */ requestAt(op: O, args: ArgsOf): Promise<{ result: ResultOf; at: number; }>; /** M22: the place in the stream of the line being handled now. */ position(): number; /** Receive pushed job events; call after request("subscribe", {}). */ onEvent(listener: (event: Event) => void): () => void; /** M51: the connection is gone (dropped, or closed): a request on it fails at once. */ get isClosed(): boolean; /** Called once when the connection drops (not after close()). */ onClose(listener: () => void): () => void; close(): void; private onLine; }