UNPKG

@phren/cli

Version:

Knowledge layer for AI agents - CLI, MCP server, and data layer

71 lines (70 loc) • 2.63 kB
import { type PaneRef, type ProcessRow } from "../bridge/resources.js"; /** * `phren reap`: what agents left running that nobody stops: dev servers, * build daemons, test watchers, headless browsers whose parent is gone, shell * wait loops and Postgres test database clones. Read-only: every row carries * the exact command that would stop it, and the owner runs the ones they want. */ export type ReapKind = "dev server" | "build daemon" | "test watcher" | "headless browser" | "wait loop"; /** `ancestors` is the pid chain above the row, nearest first; `pane` the terminal pane whose shell or foreground process is the row or one of them. */ export interface ReapRow { kind: ReapKind; name: string; pid: number; startedAt?: number; ancestors: number[]; pane?: PaneRef; ageMs?: number; idleMs?: number; cpuShare?: number; rssBytes: number; by: string; cwd?: string; stop: string; } export interface ReapDatabase { name: string; template: string; bytes?: number; connections: number; stop: string; } /** What a process is, when it is something agents start and forget. */ export declare function classify(row: ProcessRow, parentGone: boolean): { kind: ReapKind; name: string; } | undefined; export interface Sample { cpuSeconds: number; since: number; } /** * Report rows from a process table. `cpu` is each pid's cumulative CPU * seconds; `samples` is what an earlier report saw, so a process whose CPU * time has not moved since is idle at least that long. Returns the samples to * keep for next time. Without `all`, only work an agent started (or whose * parent is gone) is listed. */ export declare function reapRows(rows: ProcessRow[], options: { now: number; cpu: Map<number, number>; samples: Record<string, Sample>; all?: boolean; env?: (pid: number) => string | undefined; cwd?: (pid: number) => string | undefined; self?: number; /** Pane pids (bridge/resources.ts `paneOwners()`), to name the pane each row runs in. */ owners?: Map<number, PaneRef>; }): { rows: ReapRow[]; samples: Record<string, Sample>; }; /** `ps -o pid=,time=` cumulative CPU: `[[dd-]hh:]mm:ss[.cc]`. */ export declare function parseCpuTimes(output: string): Map<number, number>; /** Databases cloned from a test template (`hub_test_797` beside `hub_test`): name, template, size and open connections. */ export declare function testClones(rows: Array<{ name: string; bytes?: number; connections: number; }>): ReapDatabase[]; export declare function runReap(args: string[]): Promise<number>;