@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
48 lines • 2.29 kB
TypeScript
/**
* The supervisor's always-on observer connection to its host's internal socket.
*
* The supervisor cannot see turns directly: it proxies the public socket, so it knows the
* connection count, and it learns about `agent_start` / `agent_settled` only through this one
* connection. That is why its health is load-bearing for the idle decision - an unhealthy
* observer means activity is UNKNOWN rather than zero, and the caller reports unknown as busy
* so that a broken observer can never kill a host mid-turn.
*
* Unknown must not be permanent, which is why the link also records WHEN it went unhealthy:
* the caller can bound how long unknown is allowed to hold a host open.
*/
export interface ObserverSocket {
/** Close and error both mean the same thing here, so the transport registers one handler. */
readonly onLost: (handler: () => void) => void;
}
export interface ObserverLinkOptions {
readonly open: () => Promise<ObserverSocket>;
/** A supervisor already shutting down or draining has nothing left to observe. */
readonly settled: () => boolean;
readonly retryDelayMs: number;
readonly now: () => number;
readonly setTimer: (run: () => void, ms: number) => {
readonly cancel: () => void;
};
}
export interface ObserverLink {
readonly open: () => Promise<void>;
readonly healthy: () => boolean;
readonly unhealthySince: () => number | undefined;
readonly stop: () => void;
}
export interface UnknownActivityInput {
readonly healthy: boolean;
readonly unhealthySince: number | undefined;
readonly now: number;
readonly unknownGraceMs: number;
readonly observedBusy: number;
}
/**
* The turn count the idle decision should see. A healthy observer's count is the truth. An
* unhealthy one cannot see turns at all, so its count is UNKNOWN and reported as 1 (busy) so a
* momentary blip never kills a host mid-turn - but only for `graceMs`; past that, unknown has
* been allowed to hold the host open for a whole idle window and it stops counting as busy.
*/
export declare function activeTurnsForIdleDecision(input: UnknownActivityInput): number;
export declare function createObserverLink(options: ObserverLinkOptions): ObserverLink;
//# sourceMappingURL=observer-link.d.ts.map