UNPKG

@code-yeongyu/senpi

Version:

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

79 lines • 4.63 kB
import type { HostStopSender } from "./host-crash-record.ts"; import { type HostGenerationPaths } from "./host-daemon-paths.ts"; /** An intent older than this describes some earlier stop, not the death being recorded now. */ export declare const STOP_INTENT_MAX_AGE_MS = 120000; /** Shared with callers so they never kill a supervisor while it is reaping its child. */ export declare const CHILD_STOP_TIMEOUT_MS = 5000; export declare const CHILD_KILL_EXIT_TIMEOUT_MS = 30000; export interface HostStopIntent { readonly sender: HostStopSender; /** Present once a second sender acted on the same stop (the supervisor after an outer caller). */ readonly chain?: readonly HostStopSender[]; readonly targetPid: number; readonly reason: string; readonly signal: string; readonly at: string; } export declare function writeStopIntent(generation: HostGenerationPaths, intent: HostStopIntent, log?: (message: string) => void): Promise<void>; /** This generation's own intent while it is fresh; a stale one is removed and reads as none. */ export declare function readStopIntent(generation: HostGenerationPaths, options?: { readonly now?: number; readonly maxAgeMs?: number; }): Promise<HostStopIntent | undefined>; /** Read-and-clear: the record that cites the intent is the intent's only consumer. */ export declare function consumeStopIntent(generation: HostGenerationPaths, now?: number): Promise<HostStopIntent | undefined>; export declare function clearStopIntent(generation: HostGenerationPaths): Promise<void>; /** * The supervisor's own intent before it signals its child. An OUTER intent for this generation (an * ensure, `host stop`, a handoff) is never overwritten: the supervisor appends itself to its chain and * its shutdown reason to the outer reason, so the record keeps naming the original sender. */ export declare function layeredSupervisorIntent(outer: HostStopIntent | undefined, supervisor: HostStopSender, stop: { readonly targetPid: number; readonly reason: string; readonly at: string; }): HostStopIntent; /** How often a generation looks for a drain request when it cannot watch the directory: the supersession cadence. */ export declare const DRAIN_REQUEST_POLL_MS = 1000; /** * The backup poll while the directory watch is armed (senpi#3747): the watch delivers a request as it lands, * so an idle generation no longer reads the file every second; the poll only covers an event the watch missed. */ export declare const DRAIN_REQUEST_WATCHED_POLL_MS = 5000; export interface HostDrainRequest { readonly sender: HostStopSender; readonly reason: string; readonly at: string; /** Distinguishes one request from the next; a watcher delivers each nonce once. */ readonly nonce: string; } /** Records a drain request for whoever polls `file`. Atomic: a reader sees no request or a whole one. */ export declare function writeDrainRequest(file: string, request: { readonly sender: HostStopSender; readonly reason: string; }): Promise<void>; /** * Calls `onRequest` for every distinct request that appears at `file`, including one already there * when the watch arms. The file's directory is watched, so a request is read when it lands; a poll every * `DRAIN_REQUEST_WATCHED_POLL_MS` backs the watch up, and every `DRAIN_REQUEST_POLL_MS` when the directory * cannot be watched. `pollMs` overrides the poll interval. Unref'd: a drain watch must never be the reason a * process stays up. */ export declare function watchDrainRequest(file: string, onRequest: (request: HostDrainRequest) => void, options?: { readonly pollMs?: number; }): () => void; /** The request at `file`, or nothing when it is absent or does not parse as one. */ export declare function readDrainRequest(file: string): Promise<HostDrainRequest | undefined>; /** What a supervisor publishes once its watch is armed: the pid an asker must prove before asking. */ export interface HostDrainWatch { readonly pid: number; } export declare function writeDrainWatch(file: string, watch: HostDrainWatch): Promise<void>; /** The advertised watcher pid, or nothing: a generation without the marker cannot be asked this way. */ export declare function readDrainWatch(file: string): Promise<HostDrainWatch | undefined>; /** * The relay file a SUPERVISED host child polls, derived from what its supervisor told it at spawn * (daemon directory + instance id). A host started bare has no supervisor to relay anything. */ export declare function hostChildDrainRequestFile(env?: NodeJS.ProcessEnv): string | undefined; //# sourceMappingURL=host-stop-intent.d.ts.map