import { AsyncLocalStorage } from 'node:async_hooks'; type Sink = (chunk: Buffer) => void; const storage = new AsyncLocalStorage(); export function operationOutput(chunk: Buffer): void { const sink = storage.getStore(); if (sink) sink(chunk); else process.stderr.write(chunk); } export function withOperationOutput( sink: Sink, operation: () => Promise, ): Promise { return storage.run(sink, operation); }