@phren/cli
Version:
Knowledge layer for AI agents - CLI, MCP server, and data layer
154 lines (153 loc) • 5.08 kB
TypeScript
import type { ActionKind, Area, PaneLink } from "./report.js";
import { type BoundPane, cacheRules, type LiveProcess, type PaneDispatch } from "./safety.js";
/**
* The inventory: everything on this computer the owner may want to see and
* handle, not just what crossed a threshold. Every worktree, the largest space
* users, and every agent pane, each with an action that says whether it is
* allowed now and, if not, why in a plain sentence. Scanning sizes is slow, so
* the Hook runs it in the background (hourly and on request) and serves the
* last scan; every action re-checks against the disk when approved.
*/
export interface InventoryAction {
id: string;
kind: ActionKind;
label: string;
allowed: boolean;
reason?: string;
confirm?: string;
}
export interface InventoryWorktree {
id: string;
repo: string;
branch?: string;
path: string;
main: boolean;
sizeBytes?: number;
lastCommitAt?: string;
dirty: number;
untracked: number;
unpushed: number;
stashes: number;
inProgress?: string;
locked?: true;
sessions: Array<{
pane: PaneLink;
agent?: string;
title?: string;
}>;
processes: Array<{
pid: number;
command?: string;
}>;
action: InventoryAction;
}
export type SpaceKind = "cache" | "derived-data" | "xctest-devices" | "device-support" | "simulator" | "docker" | "tmp" | "node_modules";
export interface InventorySpace {
id: string;
area: Area;
kind: SpaceKind;
title: string;
path?: string;
udid?: string;
sizeBytes: number;
lastUsedAt?: string;
action?: InventoryAction;
/** Who is using it now, when that is why it stays. */
inUse?: string;
/** Why a row with no action is never handled here. */
note?: string;
}
export interface InventorySession {
id: string;
pane: PaneLink;
agent?: string;
title?: string;
project?: string;
status?: string;
idleSeconds?: number;
cwd?: string;
dispatch?: string;
role?: string;
receipt?: {
id: string;
returnRead: boolean;
};
action: InventoryAction;
}
export interface Inventory {
collectedAt: string;
durationMs: number;
worktrees: InventoryWorktree[];
space: InventorySpace[];
sessions: InventorySession[];
errors?: Array<{
check: string;
message: string;
}>;
}
/** An agent pane as the Hook's overview shows it. */
export interface SessionRow {
pane: PaneLink;
agent?: string;
title?: string;
project?: string;
status?: string;
role?: string;
idleSeconds?: number;
cwd?: string;
dispatch?: string;
}
export interface InventoryOptions {
home?: string;
platform?: NodeJS.Platform;
/** Folders whose direct children are checked for checkouts. */
roots?: string[];
tmpRoots?: string[];
rules?: ReturnType<typeof cacheRules>;
processes: () => Promise<LiveProcess[]>;
panes: () => Promise<BoundPane[]>;
sessions?: () => Promise<SessionRow[]>;
dispatches?: () => Promise<PaneDispatch[]>;
/** Bytes under a path; `du` by default. Undefined when it could not be measured. */
sizeOf?: (target: string) => Promise<number | undefined>;
simulators?: () => Promise<Array<{
udid: string;
name: string;
state: string;
dataPath: string;
}>>;
docker?: () => Promise<Array<{
type: string;
sizeBytes: number;
reclaimableBytes: number;
}>>;
xcodebuildRunning?: () => Promise<boolean>;
now?: number;
/** How many space rows to keep. */
spaceLimit?: number;
}
export declare const LABELS: Record<ActionKind, string>;
/** An action id: the row's kind, target and state, so a changed row gets a new id. */
export declare function actionId(kind: ActionKind, target: string, state: unknown): string;
export declare function duBytes(target: string): Promise<number | undefined>;
/** Checkouts under the roots (their direct children, plus each repo's linked worktrees and .claude/worktrees). */
export declare function findCheckouts(roots: string[], limit?: number): Promise<string[]>;
export declare function defaultRoots(home?: string, platform?: NodeJS.Platform): string[];
export declare function scanInventory(options: InventoryOptions): Promise<Inventory>;
/** Simulators with their data folders (macOS). */
export declare function listSimulators(home?: string): Promise<Array<{
udid: string;
name: string;
state: string;
dataPath: string;
}>>;
export declare function parseDockerSize(text: string): number;
/** `docker system df`, when docker answers. */
export declare function dockerUsage(): Promise<Array<{
type: string;
sizeBytes: number;
reclaimableBytes: number;
}>>;
export declare function xcodebuildRunning(): Promise<boolean>;
/** Agent panes from one server's workspace overview (the Hook's `/v1/workspaces` shape). */
export declare function sessionRowsFromOverview(overview: Record<string, unknown>, now?: number): SessionRow[];