UNPKG

@code-yeongyu/senpi

Version:

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

103 lines • 5.2 kB
import type { SessionEntry } from "../../../session-manager.ts"; import type { AgentEndEvent, ExtensionMode } from "../../types.ts"; import type { DelayedContinuationKind } from "./monitor-continuation-types.ts"; export declare const TURN_END_LIVENESS_EVENT = "turn_end_liveness"; /** Durable entry appended only for a `stalled` verdict: the session's last readable resume point. */ export declare const TURN_END_LIVENESS_ENTRY_TYPE = "turn-end-liveness"; export type TurnEndKind = "clean" | "user-abort" | "system-abort" | "provider-abort" | "unknown-abort" | "provider-error" | "policy-rejection"; /** Something that will re-enter the session by itself. */ export type WakeExpectation = { readonly kind: "wake-source"; readonly source: string; } | { readonly kind: "armed-timer"; readonly timer: DelayedContinuationKind; } | { readonly kind: "recovery-staged"; } | { readonly kind: "pending-messages"; } | { readonly kind: "user-input-queued"; } | { readonly kind: "question-to-user"; }; export type OpenWork = { readonly kind: "active-goal"; readonly goalId: string; } | { readonly kind: "open-todos"; readonly count: number; } | { readonly kind: "none"; }; export interface TurnEndLivenessInput { readonly isChildSession: boolean; readonly mode: ExtensionMode; readonly endedBy: TurnEndKind; /** An active hold-ledger kind: every engine-originated wake is held until input or resume_session. */ readonly ledgerHold: HoldLedgerKind | undefined; /** The core will retry or fall back after this end (`AgentEndEvent.willRetry`). */ readonly willRetry: boolean; /** A turn-deadline stop is never auto-continued; it waits for user input. */ readonly deadlineStop: boolean; /** Paused or blocked goal: it waits for a person by design. */ readonly goalStopped: boolean; readonly openWork: OpenWork; /** The lane that queued a hidden continuation at this turn end, if any. */ readonly continuationQueued: "goal" | "todo-backstop" | undefined; readonly expectations: readonly WakeExpectation[]; /** An existing guard refused to continue: the goal's continuation stopped, or the todo chain hit its cap. */ readonly budgetSpent: boolean; /** The earliest future instant the failed turn's error names (a usage-limit reset). */ readonly providerRetryAtMs: number | undefined; } /** An active kind in the session hold ledger (senpi#3860 owns `unattended`; #3811 adds the rest). */ export type HoldLedgerKind = "unattended" | "session_hold" | "run_fence" | "inherited_hold"; export type HeldReason = HoldLedgerKind | "user-abort" | "child-session" | "non-interactive" | "deadline-stop" | "goal-stopped"; export type StalledReason = "budget" | "provider-error" | "aborted" | "no-wake"; export type TurnEndLivenessVerdict = { readonly kind: "continuing"; readonly via: "retry" | "goal" | "todo-backstop"; } | { readonly kind: "held"; readonly reason: HeldReason; } | { readonly kind: "waiting"; readonly on: readonly WakeExpectation[]; readonly heldBy?: HeldReason; } | { readonly kind: "done"; } | { readonly kind: "stalled"; readonly reason: StalledReason; readonly retryAtMs?: number; readonly abortSource?: "system" | "provider"; }; export declare function classifyTurnEnd(event: AgentEndEvent): TurnEndKind; /** * The wakes that will really start a turn. A question counts only on a turn that completed (an errored turn's * trailing "?" is not a question to answer), and a deadline stop suppresses the goal lane's own timer and * recovery. Monitors, background work, child tasks and queued messages still deliver during a deadline hold * (the hold is read only by the goal lane), so they stay. */ export declare function effectiveWakes(input: TurnEndLivenessInput): readonly WakeExpectation[]; export interface TurnEndRule { readonly id: string; readonly when: (input: TurnEndLivenessInput) => boolean; readonly verdict: (input: TurnEndLivenessInput) => TurnEndLivenessVerdict; } /** * The whole decision, as one ordered table: the first matching row decides. Every input matches a row (the last * row has no condition). A retry is part of the run in flight; an active hold-ledger kind then holds every * engine-originated wake (child, monitor, goal, an extension's queued message) until input or resume_session, * unless the user's own queued message is that input; then a queued continuation; a run * that exits; a wake that will deliver a turn (with the stop reason, when one applies, as `heldBy`); a stop that * waits for a person; open work that nothing will bring back; and a completed turn with nothing open. */ export declare const TURN_END_RULES: readonly TurnEndRule[]; export declare function evaluateTurnEndLiveness(input: TurnEndLivenessInput): TurnEndLivenessVerdict; /** True when the branch already records this exact stall (reason, reset time, abort source) since the last user message. */ export declare function repeatsLastStall(branch: readonly SessionEntry[], verdict: Extract<TurnEndLivenessVerdict, { kind: "stalled"; }>): boolean; //# sourceMappingURL=turn-end-liveness.d.ts.map