UNPKG

@code-yeongyu/senpi

Version:

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

62 lines • 3.35 kB
/** * Runner leases: every `senpi schedule run` process publishes `runners/<pid>.json` in the terminal * lease format (pid + boot instant + process start instant) plus a heartbeat `beatAt`. The identity * lets a reused pid be told apart from the runner that wrote the lease; the heartbeat, refreshed on a * timer even while a delivery is running, tells the tool whether a runner will actually fire jobs. */ import { type RunnerIdentity } from "./store.ts"; /** A lease whose heartbeat is older than this does not count as an available runner. */ export declare const RUNNER_HEARTBEAT_STALE_MS = 120000; /** How often a runner refreshes its heartbeat. */ export declare const RUNNER_HEARTBEAT_INTERVAL_MS = 30000; /** Assumed delivery time limit when a lock does not state one (the CLI default). */ export declare const DEFAULT_MAX_DELIVERY_MS = 900000; export declare function ownRunnerIdentity(): RunnerIdentity; export declare function writeRunnerLease(dir: string, lease: { readonly startedAt: number; readonly watch: boolean; readonly exec: string | null; }, now: number): Promise<void>; export declare function removeRunnerLease(dir: string): Promise<void>; export interface LiveRunner { readonly pid: number; readonly processStartedAtMs: number; readonly beatAt: number; readonly watch: boolean; readonly exec: string | null; } /** Runners whose process is alive (same identity); dead or reused-pid leases are removed. */ export declare function liveRunners(dir: string): Promise<LiveRunner[]>; /** True when a live `--watch` runner has refreshed its heartbeat recently. */ export declare function isWatchRunnerAvailable(dir: string, now: number): Promise<boolean>; /** True when the runner that claimed an occurrence is still the same live process. */ export declare function isOwnerAmong(owner: RunnerIdentity, runners: readonly LiveRunner[]): boolean; export type SessionDeliveryLock = { readonly acquired: true; /** * Records the delivery process (group) so the lock outlives a crashed runner while it runs. * Serialized with `release`; a failure rejects, and the caller must not start the delivery. */ attachDelivery(pid: number): Promise<void>; release(): Promise<void>; } | { readonly acquired: false; readonly heldByPid: number | undefined; }; /** Whether any member of the delivery process group (POSIX) or the delivery process (win32) is alive. */ export declare function isDeliveryGroupAlive(pid: number): boolean; export interface LockProbes { readonly readProcessStartMs?: (pid: number) => Promise<number | undefined>; } /** * Takes the cross-process delivery lock of one session: `sessions/<id>.lock`, published exclusively * in the lease format. Every runner takes it before it claims a job of that session and holds it * until the delivery has settled, so two runner processes never deliver into the same session at * once. The delivery process is attached to the lock before it may start its work, and a lock whose * runner died is reclaimed only once that delivery has exited too. */ export declare function acquireSessionDeliveryLock(dir: string, sessionId: string, options?: LockProbes & { readonly gated?: boolean; readonly maxDeliveryMs?: number; }): Promise<SessionDeliveryLock>; //# sourceMappingURL=runner-lease.d.ts.map