export interface ResourceLimits { /** Minimum free memory (bytes) required before spawning. Default: 15% of total. */ minFreeMemBytes: number; /** Maximum concurrent claude-agent-sdk processes across all orgs. Default: cpus - 2, min 2. */ maxSdkProcesses: number; /** Delay between sequential agent spawns (ms). Default: 2000. */ spawnStaggerMs: number; } export declare function configureResourceLimits(o: Partial): void; export declare function getResourceLimits(): ResourceLimits; /** Available memory in bytes — free + reclaimable (inactive/speculative/purgeable on macOS). * os.freemem() on macOS returns only wired-free pages, which is near-zero on * a warm system even though GB of file-cache are instantly reclaimable. */ export declare function getAvailableMemBytes(): number; /** * Number of live SDK sessions in a process table. Each role session is the SDK * process itself; the wrappers around it repeat its command line and are skipped, * so a role under any number of bwrap layers counts once. Pure — the table is an input. */ export declare function countSdkSessions(table: ProcEntry[]): number; export declare function countSdkProcesses(): number; export interface ResourceCheck { ok: boolean; freeMemMB: number; freeMemPct: number; sdkProcesses: number; maxSdkProcesses: number; reason?: string; } export declare function checkResources(): ResourceCheck; /** Wait until resources are available, with a timeout. Returns false if timed out. */ export declare function waitForCapacity(timeoutMs?: number): Promise; /** One row of the process table: identity plus the ownership fields reaping needs. */ export interface ProcEntry { pid: number; ppid: number; /** Process group id. */ pgrp?: number; /** Session id. Only known from /proc (Linux). */ sid?: number; /** Start time in clock ticks since boot (/proc stat field 22) — guards PID reuse. */ start?: number; cmd: string; } /** * Parse /proc//stat. `comm` (field 2) may contain spaces and parens, so * fields are counted from the LAST ')'. */ export declare function parseProcStat(stat: string): Pick | null; /** * Decide which claude-agent-sdk processes are reapable. Pure — the process * table and the invoking pid are inputs — so every ownership rule is testable. * * With `ownerPid`, only that owner's direct SDK children are selected (the * org daemon reaping its own agents). * * Without it (`cleanup --force`), a process is an orphan only when ownership * says so, never by the name of pid 1: * - it is not the invoking process, one of its ancestors, or a descendant; * - it shares neither the invoking process's session nor its process group * (a dummy whose parent reads as pid 1 but which belongs to the invoking * session is still the invoker's); * - no process up its parent chain is a still-running claude/monomind * session (Claude Code running as a container's pid 1 keeps its SDK * children, whose ppid is 1); * - it is not in its live parent's session: a spawned child stays in its * parent's session, while an orphan adopted by init, systemd --user, * tini, bwrap or any other subreaper does not. A parent that is not * visible counts as adoption only for ppid 1 (the true init outside a * PID namespace's view). * Without session ids (macOS `ps`), the last rule falls back to "ppid is 1 or * the parent is an init/systemd", as before. */ export declare function selectOrphanedSdkPids(table: ProcEntry[], selfPid: number, protectedPids: Set, ownerPid?: number): number[]; /** Kill orphaned claude-agent-sdk processes. * @param protectedPids PIDs to never kill (e.g. sibling org agents). * @param ownerPid Only kill SDK processes whose parent is this PID. * When undefined, only kills processes `selectOrphanedSdkPids` proves * orphaned by ownership (see there). * @param source Test seam (#671): a process table and invoking pid to judge * instead of reading the real ones, so the orphan path can be exercised * where real session ids can't be arranged (e.g. every process in a bwrap * sandbox shares session 1). */ export declare function reapOrphanedSdkProcesses(protectedPids: Set, ownerPid?: number, source?: { table: ProcEntry[]; selfPid: number; }): number; //# sourceMappingURL=resource-governor.d.ts.map