import { AsyncLocalStorage } from 'node:async_hooks' export const moduleProgress = new AsyncLocalStorage<(message: string) => void>() export function reportModuleProgress(message: string): void { moduleProgress.getStore()?.(message) } export function createModuleProgressParser(): (chunk: string) => void { const report = moduleProgress.getStore() let pending = '' return (chunk) => { if (!report) return pending += chunk const lines = pending.split('\n') pending = lines.pop()!.slice(-4096) for (const line of lines) { if (line.startsWith('LMS_MODULE_PROGRESS:')) report(line.slice('LMS_MODULE_PROGRESS:'.length).trim()) } } }