UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

79 lines • 4.66 kB
export declare const PROCESS_START_TOLERANCE_MS = 3000; /** FILETIME and C/localized lstart/ISO identities share one millisecond representation. */ export declare function processStartTimeMs(identity: string): number | undefined; export declare function sameProcessStartMs(recorded: number | undefined, observed: number | undefined): boolean; export interface DaemonPidFile { readonly pid: number; /** * Identity guard for the recorded pid. `null` means the host was registered while its * identity probe was starved: the pid is known, ownership is not provable, and no caller * may signal it on that record. */ readonly processStartTime: string | null; } export declare function parseDaemonPidFile(text: string): DaemonPidFile | undefined; export type ProcessIdentityResult = { readonly kind: "present"; readonly identity: string; } | { readonly kind: "absent"; } | { readonly kind: "error"; readonly error: unknown; }; /** Thrown when a live process refuses to yield an identity after the retry budget. */ export declare class ProcessIdentityUnreadableError extends Error { readonly pid: number; readonly attempts: number; readonly cause: unknown; constructor(pid: number, attempts: number, cause: unknown); } export interface IdentityProbeRetry { /** Probe attempts against a live pid before giving up (default 5). */ readonly attempts?: number; /** Pause between attempts in ms (default 200). */ readonly delayMs?: number; } /** * True when the pidfile still describes the running process. A probe FAILURE is not * an answer: on a pid that is no longer live it means "gone" (false); on a live pid it * is an observation gap — the platform query was starved or exited non-zero — so the * probe is retried within a bounded budget and only then surfaces as * ProcessIdentityUnreadableError. It never leaks the raw probe error as a verdict. */ export declare function processMatchesPidFile(pidFile: DaemonPidFile, readStartTime?: (pid: number) => Promise<string | undefined>, isLive?: (pid: number) => boolean, retry?: IdentityProbeRetry): Promise<boolean>; export declare function readProcessIdentity(pid: number, platform?: NodeJS.Platform, timeoutMs?: number, isLive?: (pid: number) => boolean, /** Owner records cross launch environments; legacy pidfiles keep their existing local-time format. */ timeZone?: "UTC"): Promise<ProcessIdentityResult>; export declare function stopValidatedPid(pidFile: DaemonPidFile, signal: NodeJS.Signals): Promise<void>; export declare function waitForGone(pidFile: DaemonPidFile, timeoutMs: number): Promise<boolean>; /** * The live start time of `pid` as one string, or undefined when the process is gone. * Throws when the probe fails against a live pid. * * Probes read in UTC by default: a local-form start time is ambiguous in a DST fall-back * hour, so a UTC-tagged record compared against a local probe can read one hour off and a * live child stops counting as a holder (senpi#3067 L1). Legacy local-format records are * still parsed as local time by `processStartTimeMs`. */ export declare function readProcessStartTime(pid: number, platform?: NodeJS.Platform, timeoutMs?: number, timeZone?: "UTC"): Promise<string | undefined>; /** * `processIsLive` minus processes that have exited but are not reaped yet (state Z): a SIGKILLed host * stays a zombie until its parent's loop, or init, waits on it, and `kill(pid, 0)` still succeeds for it * (senpi#4119). One `ps` snapshot decides; a probe that fails any other way reads as running, so a * starved probe on a live process is never taken for a dead one (#1609). */ export declare function processIsRunning(pid: number): boolean; export declare function processIsLive(pid: number): boolean; /** * Wait for a spawned pid's process identity. * * Returns `undefined` (UNKNOWN) when the budget is exhausted but the process is still alive: * budget exhaustion is an OBSERVABILITY failure, not evidence the child failed to start. On a * loaded Windows runner every `Get-CimInstance` probe can outlive `readProcessIdentity`'s 1s win32 * default, so all ~9 attempts inside a 10s budget time out and throw while the process runs * normally (PR #1351/#1352 CI, runs 33839093178 / 33842155236). Only a pid that is really gone is * a startup failure, so callers can distinguish "no identity yet" from "child died". */ export declare function waitForStartTime(pid: number, timeoutMs: number, readStartTime?: (pid: number) => Promise<string | undefined>, isLive?: (pid: number) => boolean): Promise<string | undefined>; //# sourceMappingURL=process-identity.d.ts.map