import { fileURLToPath } from 'node:url' import type { Client } from '@enkaku/client' import type { Protocol } from '@mokei/host-protocol' import { createDaemonClient, ensureDaemon } from '@tejika/process' export type HostClient = Client export type DaemonOptions = { socketPath?: string entry?: string } const DAEMON_ENTRY = fileURLToPath(new URL('./server.js', import.meta.url)) /** * Connect to a running daemon. Throws if the socket is absent or refused. * Uses `@tejika/env` default socket path for app "mokei" when `socketPath` is omitted. */ export async function createClient(socketPath?: string): Promise { return createDaemonClient({ app: 'mokei', socketPath }) } /** * Ensure a daemon is running and return a connected client. Spawns the daemon * on first call (or after a crash) and reconnects automatically. */ export async function runDaemon(options: DaemonOptions = {}): Promise { return ensureDaemon({ app: 'mokei', entry: options.entry ?? DAEMON_ENTRY, socketPath: options.socketPath, }) }