/** * Worker Manager — supervises per-photon worker threads * * Manages the lifecycle of isolated worker threads for photons tagged with @worker. * Provides the same interface as in-process execution so the daemon's request * handler doesn't need to know whether a photon is in-process or in a worker. */ import { Worker } from 'worker_threads'; import { Logger } from '../shared/logger.js'; export interface WorkerInfo { worker: Worker; photonName: string; photonPath: string; workingDir?: string; tools: Array<{ name: string; description?: string; }>; ready: boolean; crashCount: number; lastCrash?: number; /** Sliding window of crash timestamps (last 5 minutes) for backoff decisions */ crashTimestamps: number[]; /** If set, the worker is in backoff and should not be respawned until this time */ backoffUntil?: number; /** Guard against double-counting crash from error + exit events in the same cycle */ crashHandled: boolean; /** Channels this worker is subscribed to */ subscribedChannels: Set; } export declare class WorkerManager { private workers; private pendingCalls; private logger; /** Callback to resolve @photon deps through the main thread */ depResolver?: (depName: string, depPath: string, workerPhoton: string) => Promise<{ toolNames: string[]; } | null>; /** Callback to execute a dep method through the main thread */ depCaller?: (depName: string, method: string, args: Record) => Promise; /** Callback to forward worker pub/sub to main broker */ onPublish?: (channel: string, message: unknown) => void; /** Callback when worker subscribes to a channel */ onSubscribe?: (workerKey: string, channel: string) => void; /** Callback when worker unsubscribes from a channel */ onUnsubscribe?: (workerKey: string, channel: string) => void; constructor(logger: Logger); /** Check if a photon is running in a worker */ has(key: string): boolean; /** Get info for a worker-hosted photon */ get(key: string): WorkerInfo | undefined; /** Get all worker keys */ keys(): IterableIterator; /** Spawn a worker thread for a photon */ spawn(key: string, photonName: string, photonPath: string, workingDir?: string): Promise; /** Send a tool call to a worker and return the result */ call(key: string, method: string, args: Record, sessionId: string, instanceName?: string, timeoutMs?: number): Promise<{ success: boolean; data?: unknown; error?: string; durationMs?: number; }>; /** Trigger hot-reload in a worker */ reload(key: string, photonPath: string): Promise<{ success: boolean; error?: string; }>; /** Forward a channel message to workers subscribed to that channel */ dispatchToWorkers(channel: string, message: unknown): void; /** Gracefully terminate a worker */ terminate(key: string, reason?: string): Promise; /** Terminate all workers */ terminateAll(): Promise; /** Handle messages from a worker */ private handleWorkerMessage; /** Handle @photon dependency resolution from a worker */ private handleDepResolve; /** Handle @photon dependency method call from a worker */ private handleDepCall; /** Record a crash event in the sliding window */ private recordCrash; /** Schedule auto-respawn with exponential backoff, or enter cooldown if too many crashes */ private scheduleRespawn; /** Reset crash history for a worker (e.g. after hot-reload with new code) */ resetCrashHistory(key: string): void; } //# sourceMappingURL=worker-manager.d.ts.map