/** * The single path of a subagent worker's log records to the main thread. * * The main thread owns the process log file (`omp...log`, shared by * every thread) and the out-of-band sinks (`registerLogSink`, e.g. the OTLP * exporter). A worker never opens the file: from the first module its entry * evaluates ({@link installWorkerLogPort}), the worker's logger posts every * record (scoped `withContext` fields merged in) as a raw * {@link SubagentWorkerLog} message on `parentPort`. The main side handles those * from spawn, before the RPC link exists ({@link receiveWorkerLog}): it tags * each record with the worker's `thread` id and writes it with its original * timestamp (`logger.emitForeign`). Records and RPC frames share the port, so * they arrive in send order; once the logger thread service connects a flush * ({@link WorkerLogPort.connectFlush}), `logger.flush()` in the worker blocks * until main wrote every record posted before it. */ import { logger } from "@oh-my-pi/pi-utils"; import type { ThreadId } from "./identity.js"; /** Raw message a subagent worker posts on `parentPort` for each log record. */ export interface SubagentWorkerLog { readonly type: "subagent-worker-log"; readonly event: logger.LogEvent; } /** Port surface the forwarder posts on (`parentPort`). */ interface LogMessagePort { postMessage(message: unknown): void; } /** A worker's log forwarder: posts every record on the parent port. */ export declare class WorkerLogPort implements logger.LogForwarder { #private; constructor(port: LogMessagePort); /** Post one record; ordered with every earlier record and RPC frame. */ emit(event: logger.LogEvent): void; /** Block until main wrote every record posted so far; a no-op until {@link connectFlush}. */ flush(): void; /** Install the synchronous main-side flush (a call over the same port, so it follows every posted record). */ connectFlush(flush: () => void): void; } /** Worker thread: route every later record of this thread to main through `port`; idempotent. */ export declare function installWorkerLogPort(port: LogMessagePort): WorkerLogPort; /** The forwarder {@link installWorkerLogPort} installed on this thread, if any. */ export declare function workerLogPort(): WorkerLogPort | undefined; /** Whether `value` is a raw {@link SubagentWorkerLog} message. */ export declare function isSubagentWorkerLog(value: unknown): value is SubagentWorkerLog; /** Main thread: write a worker's log record to main's transports and sinks, tagged with `thread`. */ export declare function receiveWorkerLog(thread: ThreadId, message: SubagentWorkerLog): void; export {};