@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
90 lines • 4.58 kB
TypeScript
import type { AgentEvent } from "@earendil-works/pi-agent-core";
import { type TurnEndLivenessInput } from "./extensions/builtin/goal/turn-end-liveness.ts";
import type { Goal } from "./extensions/builtin/goal/types.ts";
import { LifecycleChildren } from "./lifecycle-children.ts";
import { LifecycleLedger, type LifecyclePersistence } from "./lifecycle-ledger.ts";
import { type RunStopFacts } from "./lifecycle-stop.ts";
import type { SessionActivitySnapshot } from "./session-activity.ts";
import type { ChildLifecycleReport, HumanWait, LifecycleHold, SessionLifecycle } from "./session-lifecycle-types.ts";
import type { TurnDeadlineKind } from "./turn-deadline.ts";
import type { WorkCustodyRecord } from "./work-custody-record.ts";
import { SessionWorkObligations } from "./work-obligations.ts";
export interface LifecycleRuntimeFacts {
readonly activity: SessionActivitySnapshot;
readonly pendingMessages: number;
readonly holds: readonly LifecycleHold[];
readonly human: readonly HumanWait[];
readonly inputAdmissionPending?: boolean;
}
export interface SessionLifecycleOptions extends LifecyclePersistence {
readRuntime(): LifecycleRuntimeFacts;
appendChild(report: ChildLifecycleReport): void;
appendCustody(record: WorkCustodyRecord): void;
}
/** One event-driven reducer per session, shared by every client surface. */
export declare class SessionLifecycleController {
readonly ledger: LifecycleLedger;
readonly obligations: SessionWorkObligations;
readonly children: LifecycleChildren;
private readonly options;
private idleBoundaryPassed;
private pendingHuman;
/** A host restart continues the engine-started run it cut short (senpi#7020); cleared when that run starts. */
private restartContinues;
private admittingHuman;
private runAdmitted;
private goal;
private liveness;
private ownTask;
private evaluating;
private deferred;
private stopFacts;
private deadlineStop;
private readonly outstandingTools;
private modelSince;
/** A run that ended before this process keeps exactly the stop its record carries; none is derived for it. */
private readonly restoredRunId;
constructor(options: SessionLifecycleOptions);
get snapshot(): SessionLifecycle;
get lastTurnInput(): TurnEndLivenessInput | undefined;
get requiresHumanContinuation(): boolean;
get nextRunOrigin(): "human" | "automatic";
/**
* The current run when this process started it, not the run the session file left current. `startRun` settles what the
* previous run consumed, so this run's consumed custody is the only custody a run of this process holds.
*/
get runStartedHere(): string | undefined;
/** The host's clean stop cut the running run short: record it interrupted, as a kill leaves it (senpi#7020). */
cutByHostShutdown(): void;
/** The interrupted run was the engine's and a host restart cut it: its continuation needs no person (senpi#7020). */
continueAfterRestart(): void;
restoreComplete(): void;
humanInput(at: string): void;
/** A turn was admitted and its run is about to start. */
noteRunAdmitted(): void;
admissionSettled(): void;
startRun(origin?: "human" | "automatic"): void;
idle(): void;
/** Synchronous core boundaries only; token/progress events never cause activity writes. */
observeActivity(event: AgentEvent & {
readonly parentToolCallId?: string;
}): void;
/** The turn deadline fired: captured before its durable write, for the run it stopped only. */
deadlineStopped(kind: TurnDeadlineKind, atMs: number): void;
/** The deadline-stop entry was refused; the captured stop says so, and the snapshot's `persisted` is untouched. */
deadlineStopWriteFailed(): void;
goalFacts(goal: Goal | null, input?: TurnEndLivenessInput, stop?: RunStopFacts): void;
goalChanged(goal: Goal | null): void;
reportChild(report: ChildLifecycleReport): void;
requestSelfSettle(): import("./session-lifecycle-types.ts").SelfSettleResult;
markRunCompleted(runId: string): void;
recompute(): void;
private evaluate;
/**
* Derived only from the current run's own end, bound when its agent_end was emitted: an end processed after a
* later run started sets nothing, and so does a fact refresh that carries no bound turn end, even when the goal
* collector still returns the previous run's end. An unchanged stop keeps its first `at`.
*/
private lastStop;
}
//# sourceMappingURL=session-lifecycle.d.ts.map