import type { LogSocketFactory } from "./socket.ts"; /** * The event-hook shape {@link CliStream} exposes for the stream events the CLI observes. Modeled as an overloaded call signature - the same shape `EventEmitter.on`/ * `off` present - so each event's listener is typed to exactly what that event delivers: `"error"` hands the listener the failing error (an `EPIPE` broken pipe, or a * genuine write fault such as `ENOSPC`), while `"drain"` delivers nothing and merely signals that the writable buffer has fallen back below its high-water mark. * * @category Log Client */ export interface CliStreamEventHook { (event: "drain", listener: () => void): void; (event: "error", listener: (error: NodeJS.ErrnoException) => void): void; } /** * A minimal output-stream surface {@link runHblog} writes to. Models the subset of a Node `WriteStream` the CLI actually uses: `write` for output, the optional `isTTY` * flag that drives the auto-color decision, and the optional `on`/`off` event hooks used to trap a broken-pipe (`EPIPE`) error and to await `drain` when a write reports * backpressure. The narrow interface keeps a test sink small (a `write` function is enough) while `process.stdout`/`process.stderr` satisfy it structurally. * * @category Log Client */ export interface CliStream { isTTY?: boolean; off?: CliStreamEventHook; on?: CliStreamEventHook; write: (chunk: string) => boolean; } /** * Options accepted by {@link runHblog}. Every external dependency the CLI touches is an injected seam, so the whole flow runs deterministically in tests. * * @property argv - The argument vector (typically `process.argv.slice(2)`). * @property cwd - The current working directory. Reserved for future relative-path resolution; the home directory is the config-file anchor today. * @property env - The environment map (typically `process.env`). * @property fetch - Optional `fetch` seam forwarded to the engine's auth and REST transports. Defaults to the global `fetch`. * @property homedir - The user's home directory, used to locate `~/.hblog.json` unless `HBLOG_CONFIG` overrides the path. * @property now - Optional wall-clock epoch source (milliseconds) used to resolve the `--since`/`--until` time-range expressions against a single deterministic * instant. Defaults to `systemClock.now`; a test injects a fixed clock so a windowed run's bounds are reproducible. * @property readFile - Optional file-read seam forwarded to the config loader and used to read the package version. Defaults to `node:fs/promises` `readFile`. * @property socketFactory - Optional socket-factory seam forwarded to the engine, so a test drives the live tail without a WebSocket. Defaults to the real factory. * @property stat - Optional file-stat seam forwarded to the config loader for the permissions warning. Defaults to `node:fs/promises` `stat`. * @property stderr - The diagnostics/warnings stream. Production passes `process.stderr`. * @property stdout - The log-data stream. Production passes `process.stdout`. * * @category Log Client */ export interface RunHblogOptions { readonly argv: readonly string[]; readonly cwd: string; readonly env: NodeJS.ProcessEnv; readonly fetch?: typeof fetch; readonly homedir: string; readonly now?: () => number; readonly readFile?: (path: string) => Promise; readonly socketFactory?: LogSocketFactory; readonly stat?: (path: string) => Promise<{ readonly mode: number; }>; readonly stderr: CliStream; readonly stdout: CliStream; } /** * Run the `hblog` command-line flow and return the process exit code. * * Parses {@link RunHblogOptions.argv}, handles `--help`/`--version` immediately, resolves the connection across flags / environment / `~/.hblog.json` (honoring * `HBLOG_CONFIG`), maps the result into a {@link LogClientCredentials} and a {@link TailRequest}, builds a {@link HomebridgeLogClient}, runs the selected channel, * applies the {@link createLogFilter} criteria, and writes log data to stdout (NDJSON for `--json`, raw/stripped lines otherwise) while routing diagnostics and warnings * to stderr. A SIGINT/SIGTERM aborts the run cleanly (exit 0); a broken pipe (`EPIPE`) on stdout also ends cleanly (exit 0); a usage error returns 2; a connection or * authentication failure returns 1. Token redaction is applied at the hard-error stderr writes (the setup failure, a captured stdout write error on either the * normal-completion or the catch path, and the streaming catch's generic error); the usage and advisory writes never carry a token. * * @param options - The injected argument vector, environment, streams, directories, and seams. See {@link RunHblogOptions}. * * @returns The process exit code: 0 success / clean signal / help / version, 1 connection or auth failure, 2 usage error. * * @category Log Client */ export declare function runHblog(options: RunHblogOptions): Promise; //# sourceMappingURL=cli-run.d.ts.map