/** * Tuning knobs for the dispatcher daemon. * * # Why this exists * * The dispatcher has several rate-limit / concurrency knobs that need * to be tunable WITHOUT a code change: * * - `maxConcurrentWorkers` — global worker cap (default 50) * - `maxWakesPerThread` — wakes per (agent, thread) per window (default 10) * - `wakeWindowMs` — the window itself (default 24h) * - `wakeCoalesceMs` — burst-debounce window (default 30s) * - `accountSyncIntervalMs` — how often to poll /accounts (default 30s) * * The DEFAULTS are conservative — protect a fresh install from runaway * cost. Power users running active coordination on a single thread * routinely hit the 10/24h wake cap and need it raised. Today (before * this module) the only way to do that was edit dispatcher.ts and rebuild, * which is absurd. * * # Three input sources, in precedence order * * 1. Explicit constructor args (programmatic callers, tests) * 2. Env vars (PM2 ecosystem.config.cjs lives here) * 3. `~/.agenticmail/dispatcher.json` (persistent operator preference, * written by the CLI's `agenticmail dispatcher tune` command) * 4. Hard-coded defaults * * Earlier sources win. * * # File format * * { "version": 1, * "maxConcurrentWorkers": 200, * "maxWakesPerThread": 50, * "wakeWindowMs": 86400000, * "wakeCoalesceMs": 30000, * "accountSyncIntervalMs": 30000 } * * Missing keys fall through to the next precedence level. All values * are integers; non-positive / non-finite values fall through (so a * broken edit produces a slightly-stale config, not a broken * dispatcher). */ interface DispatcherTuning { maxConcurrentWorkers?: number; maxWakesPerThread?: number; wakeWindowMs?: number; wakeCoalesceMs?: number; accountSyncIntervalMs?: number; } declare function defaultDispatcherConfigPath(): string; /** * Resolve final tuning values by merging the three precedence layers: * explicit args > env vars > file > defaults (left to the consumer). * * Returns ONLY the keys that were explicitly set — the caller passes * the result through to the Dispatcher constructor, whose defaults * fill in anything still undefined. */ declare function resolveDispatcherTuning(opts?: { explicit?: DispatcherTuning; env?: NodeJS.ProcessEnv; configPath?: string; }): DispatcherTuning; /** * Persist the operator's preferences to ~/.agenticmail/dispatcher.json * atomically (.tmp + rename) so a power outage mid-write never produces * a half-written config. Only writes the keys that are explicitly set * in the patch — preserves keys the user already configured. * * Returns the resulting on-disk shape so the caller can echo it back. */ declare function writeDispatcherTuning(patch: DispatcherTuning, configPath?: string): DispatcherTuning & { version: number; updatedAtMs: number; }; export { type DispatcherTuning, defaultDispatcherConfigPath, resolveDispatcherTuning, writeDispatcherTuning };