import { type AgentMessage } from "@oh-my-pi/pi-agent-core"; import type { AssistantMessage, ToolResultMessage } from "@oh-my-pi/pi-ai"; import type { SessionEntry } from "./session-entries.js"; export declare const TOOL_EXECUTION_START_CUSTOM_TYPE = "tool_execution_start"; export declare const SESSION_EXIT_CUSTOM_TYPE = "session_exit"; /** * Compact projection of tool-call arguments persisted with the start marker. * The assistant message already carries the full arguments; this exists only * so `appendArgumentSummary` can name the command/path in resume warnings * without duplicating whole argument payloads into the session JSONL. */ export interface ToolArgumentSummary { command?: string; path?: string; } /** Persisted marker written before a tool implementation starts running. */ export interface ToolExecutionStartData { toolCallId: string; toolName: string; args?: ToolArgumentSummary; intent?: string; startedAt: string; } /** Tool call left without a matching toolResult at the end of a branch. */ export interface PendingToolCallDiagnostic { toolCallId?: string; toolName: string; args?: unknown; intent?: string; assistantTimestamp?: number; startedAt?: string; } /** Session shutdown marker written during normal and fatal process teardown. */ export interface SessionExitData { reason: string; kind: "normal" | "signal" | "fatal" | "process_exit"; recordedAt: string; pendingToolCalls?: PendingToolCallDiagnostic[]; } export interface AssistantModelMetadata { api: AssistantMessage["api"]; provider: string; model: string; } /** Why an interrupted-turn abort record ends a turn its process never finished. */ export declare const INTERRUPTED_TURN_ERROR = "Previous OMP process exited before completing the turn."; /** How exit recovery reads a branch whose last process may have died without recording its exit. */ export interface InterruptedTurnOptions { /** * The branch's writer is gone even without a `session_exit` after its tail (a * crash, SIGKILL or power loss records none): `omp --restore` says so. */ assumeExit?: boolean; } /** Whether `message` is the record exit recovery closed an unfinished turn with. */ export declare function isInterruptedTurnAbort(message: AgentMessage): boolean; /** * Whether `omp --restore` has a turn to go on with on this branch: one its last * process left unfinished ({@link findUnfinishedTurn}, the exit assumed), or one exit * recovery already closed that nothing followed, not even a normal exit. */ export declare function hasRestorableTurn(entries: readonly SessionEntry[]): boolean; /** * createInterruptedTurnAbortMessage returns a terminal assistant record when * the latest persisted process exit follows a non-terminal conversation tail * ({@link findUnfinishedTurn}; with `assumeExit`, also when no exit was recorded). */ export declare function createInterruptedTurnAbortMessage(entries: readonly SessionEntry[], fallbackModel?: AssistantModelMetadata, options?: InterruptedTurnOptions): AssistantMessage | undefined; /** * Whether a persisted process exit follows the branch's last message: the * branch's writer is gone, so resume recovery owns its interrupted tail. */ export declare function sessionExitFollowsLastMessage(entries: readonly SessionEntry[]): boolean; /** Pairs unresolved calls at the end of an interrupted turn with result messages. */ export declare function createInterruptedToolResults(entries: readonly SessionEntry[], context?: "process-exit" | "fork"): ToolResultMessage[]; /** * Project full tool-call arguments down to the fields the pending-tool-call * resume warning actually renders (`command`/`path`), truncated. Returns * `undefined` when the arguments carry neither, so callers can omit `args` * entirely instead of persisting an empty object. */ export declare function summarizeToolArguments(args: unknown): ToolArgumentSummary | undefined; /** Finds tool calls left pending at the end of a session branch. */ export declare function collectPendingToolCalls(entries: readonly SessionEntry[]): PendingToolCallDiagnostic[]; /** Builds the resume warning shown when a prior branch ended mid-tool-call. */ export declare function describePendingToolCalls(entries: readonly SessionEntry[]): string | undefined;