/** * Transcript rows persisted on disk may include non-LLM entries (e.g. `kind: 'context'`). * {@link buildSessionContextForLlm} is the single choke point for provider-facing history. * * Do not pass raw on-disk JSONL rows into pi-agent / providers — always run * {@link buildSessionContextForLlm} first (or use {@link SessionStore.loadMessages}, which already does). */ import type { AgentMessage } from '@earendil-works/pi-agent-core'; /** Persisted-only row: never sent to the model as a chat message. */ export interface XopcTranscriptContextEntry { kind: 'context'; id?: string; /** Short human-readable line for UIs / logs. */ text?: string; /** Structured payload (tool summaries, delivery metadata, etc.). */ data?: Record; createdAt?: string; } /** Persisted-only row for replaying local shell executions in clients. */ export interface XopcTranscriptBashExecutionEntry { role: 'bashExecution'; command?: string; output?: string | unknown[]; exitCode?: number | null; signal?: string | null; excludeFromContext?: boolean; excludedFromContext?: boolean; truncated?: boolean; fullOutputPath?: string; timestamp?: string | number; } /** Persisted extension-injected message row for client replay. */ export interface XopcTranscriptCustomMessageEntry { role: 'custom'; customType?: string; content?: string | unknown[]; display?: boolean; details?: unknown; timestamp?: string | number; } /** Persisted extension custom_message entry shape before conversion to an agent message. */ export interface XopcTranscriptCustomMessageFileEntry { type: 'custom_message'; customType?: string; content?: string | unknown[]; display?: boolean; details?: unknown; timestamp?: string | number; } /** Persisted extension state entry for replay by extension sessionManager APIs. */ export interface XopcTranscriptCustomStateEntry { type: 'custom'; customType?: string; data?: unknown; timestamp?: string | number; } /** Persisted branch summary row generated when returning from a branch. */ export interface XopcTranscriptBranchSummaryEntry { role: 'branchSummary'; summary?: string; fromId?: string; timestamp?: string | number; } /** Persisted compaction summary row generated after transcript compaction. */ export interface XopcTranscriptCompactionSummaryEntry { role: 'compactionSummary'; summary?: string; tokensBefore?: number; timestamp?: string | number; } /** Append-only compaction boundary containing the exact LLM context at that point. */ export interface XopcTranscriptCompactionEntry { type: 'compaction'; at: string; baseSeq: number; plannerVersion: number; summaryModelRef: string; qualityAudit: 'passed' | 'disabled'; summary: string; messages: AgentMessage[]; firstKeptIndex: number; tokensBefore: number; tokensAfter: number; restoredFromCompactionId?: string; } /** Persisted label change for a transcript entry. */ export interface XopcTranscriptLabelEntry { type: 'label'; id?: string; parentId?: string | null; targetId?: string; label?: string; timestamp?: string | number; } /** Persisted thinking level change metadata row. */ export interface XopcTranscriptThinkingLevelChangeEntry { type: 'thinking_level_change'; id?: string; parentId?: string | null; thinkingLevel?: string; timestamp?: string | number; } /** Persisted model change metadata row. */ export interface XopcTranscriptModelChangeEntry { type: 'model_change'; id?: string; parentId?: string | null; provider?: string; modelId?: string; timestamp?: string | number; } /** Persisted session info metadata row. */ export interface XopcTranscriptSessionInfoEntry { type: 'session_info'; id?: string; parentId?: string | null; name?: string; timestamp?: string | number; } export type TranscriptStoredRow = AgentMessage | XopcTranscriptContextEntry | XopcTranscriptBashExecutionEntry | XopcTranscriptCustomMessageEntry | XopcTranscriptCustomMessageFileEntry | XopcTranscriptCustomStateEntry | XopcTranscriptBranchSummaryEntry | XopcTranscriptCompactionSummaryEntry | XopcTranscriptCompactionEntry | XopcTranscriptLabelEntry | XopcTranscriptThinkingLevelChangeEntry | XopcTranscriptModelChangeEntry | XopcTranscriptSessionInfoEntry; export declare function isTranscriptContextEntry(x: unknown): x is XopcTranscriptContextEntry; export declare function isTranscriptBashExecutionEntry(x: unknown): x is XopcTranscriptBashExecutionEntry; export declare function isTranscriptCustomMessageEntry(x: unknown): x is XopcTranscriptCustomMessageEntry | XopcTranscriptCustomMessageFileEntry; export declare function isTranscriptCustomStateEntry(x: unknown): x is XopcTranscriptCustomStateEntry; export declare function isTranscriptSummaryMessageEntry(x: unknown): x is XopcTranscriptBranchSummaryEntry | XopcTranscriptCompactionSummaryEntry; export declare function isTranscriptCompactionEntry(x: unknown): x is XopcTranscriptCompactionEntry; export declare function isTranscriptLabelEntry(x: unknown): x is XopcTranscriptLabelEntry; export declare function isTranscriptMetadataEntry(x: unknown): x is XopcTranscriptThinkingLevelChangeEntry | XopcTranscriptModelChangeEntry | XopcTranscriptSessionInfoEntry; /** Runtime-derived messages are never authoritative transcript rows. */ export declare function isRuntimeOnlyTranscriptMessage(x: unknown): boolean; /** * Normalize a JSON array from on-disk transcript into stored rows (drops unrecognized objects). */ export declare function transcriptRowsFromJsonArray(arr: unknown[]): TranscriptStoredRow[]; /** Messages only — what providers and pi-agent should see. */ export declare function buildSessionContextForLlm(rows: TranscriptStoredRow[]): AgentMessage[]; /** Visible chat messages only - no LLM-only audit/context expansion. */ export declare function buildSessionDisplayMessages(rows: TranscriptStoredRow[]): AgentMessage[]; /** * When persisting LLM messages, keep prior `kind: 'context'` rows in their relative positions: * each non-context slot in the previous file is replaced by the next incoming LLM message; * trailing new LLM rows are appended. Extra old LLM rows are dropped if the new list is shorter. */ export declare function mergeLlmMessagesPreservingContextRows(prevRows: TranscriptStoredRow[], llmMessages: AgentMessage[]): TranscriptStoredRow[];