@phren/cli
Version:
Knowledge layer for AI agents - CLI, MCP server, and data layer
49 lines (48 loc) • 2.57 kB
TypeScript
import { type StoreEntry } from "../store-registry.js";
import type { ComputerResources, ProcessRow } from "./resources.js";
/**
* Named machine health findings from numbers the resource monitor already
* reads (load, memory, swap, disk, the process table): no extra scans. Each
* finding has a stable `id` (check plus subject) so clients and the conductor
* can track it across reads, a severity, and a suggested fix in plain words.
* Trends come from a short in-memory history of samples, one per
* `SAMPLE_EVERY_MS`, so a leak or a filling disk shows before the threshold.
*/
export type HealthSeverity = "info" | "warn" | "high";
export type HealthCheck = "swap" | "disk" | "load" | "memory-hog" | "memory-leak" | "orphan" | "simulator-clones" | "uptime" | "store-sync-auth" | "restart-loop" | "failed-units" | "backup" | "os-updates" | "crashes" | "oom" | "journal" | "gpu" | "stale-lock";
export interface HealthFinding {
id: string;
check: HealthCheck;
severity: HealthSeverity;
title: string;
detail: string;
fix: string;
}
export interface HealthSample {
at: number;
swapUsedBytes?: number;
/** Cumulative bytes read back from swap, for the paging rate. */
swapInBytes?: number;
diskFreeBytes?: number;
/** Resident bytes of the largest processes, by program name. */
rss: Record<string, number>;
}
export declare const SAMPLE_EVERY_MS: number;
/** Two hours of samples. */
export declare const HISTORY_SAMPLES = 24;
/** One sample from a resource read, keeping the eight largest resident programs. */
export declare function healthSample(value: ComputerResources, rows: readonly ProcessRow[], at: number): HealthSample;
/** The findings for one read, worst first. `history` is oldest first and may be empty. */
export declare function assessHealth(value: ComputerResources, rows: readonly ProcessRow[], history: readonly HealthSample[], now: number): HealthFinding[];
/** Shared by machine health and the owner Inbox so both use the same threshold and store ID. */
export declare function storeSyncAuthFinding(store: StoreEntry, now: number): HealthFinding | undefined;
/** Keeps the sample history and adds store auth blocks and cached platform findings. */
export declare class MachineHealth {
private readonly probes?;
private readonly primaryStore?;
private history;
constructor(probes?: {
current(): HealthFinding[];
} | undefined, primaryStore?: string | undefined);
assess(value: ComputerResources, rows: readonly ProcessRow[], now: number): HealthFinding[];
}