/** Minimal session-list fields required to derive a deterministic lineage tree. */ export interface TreeSessionSummary { readonly sessionId: string; readonly parentSessionId?: string; readonly origin?: 'subagent'; readonly updatedAt: number; readonly createdAt?: number; } /** The semantic kind of the session's declared parent relationship. */ export type SessionRelationshipKind = 'root' | 'fork' | 'subagent'; /** Integrity state discovered while projecting untrusted durable lineage. */ export type SessionTreeIntegrity = 'valid' | 'orphan' | 'cycle'; /** One session in the repaired, cycle-free display tree. */ export interface SessionTreeNode { readonly sessionId: string; readonly summary: TSummary; /** Classifies the declared lineage independently from any integrity repair. */ readonly relationship: SessionRelationshipKind; readonly integrity: SessionTreeIntegrity; readonly declaredParentSessionId?: string; /** Parent retained in the display tree; absent for roots and repaired edges. */ readonly treeParentSessionId?: string; readonly children: readonly SessionTreeNode[]; } /** A repeated session id ignored after its first occurrence. */ export interface DuplicateSessionDiagnostic { readonly kind: 'duplicate-session'; readonly sessionId: string; readonly keptIndex: number; readonly duplicateIndex: number; } /** A declared parent absent from the supplied session summaries. */ export interface OrphanSessionDiagnostic { readonly kind: 'orphan-session'; readonly sessionId: string; readonly parentSessionId: string; } /** One complete parent cycle and the edge removed to render it as a tree. */ export interface SessionCycleDiagnostic { readonly kind: 'session-cycle'; readonly sessionIds: readonly string[]; readonly cutSessionId: string; } /** A non-fatal lineage problem found while building the display tree. */ export type SessionTreeDiagnostic = DuplicateSessionDiagnostic | OrphanSessionDiagnostic | SessionCycleDiagnostic; /** Deterministic, cycle-free projection of session summaries. */ export interface SessionTreeModel { readonly roots: readonly SessionTreeNode[]; readonly byId: ReadonlyMap>; readonly diagnostics: readonly SessionTreeDiagnostic[]; } /** One pre-order display row produced without recursively walking the tree. */ export interface SessionTreeRow { readonly node: SessionTreeNode; /** Session id of this row's repaired-tree root, for iterative family filtering. */ readonly rootId: string; readonly depth: number; readonly isLast: boolean; /** Index of the parent row, sufficient to recover ancestor display state iteratively. */ readonly parentRowIndex?: number; } /** * Builds a deterministic display tree without changing the summaries. * Duplicate ids keep their first occurrence. Missing parents become roots. For * each parent cycle, the highest-ranked member's parent edge is removed while * every cycle member and descendant remains visible. * * Roots and siblings sort by descending update time, descending creation time, * then ascending session id. * * @param summaries - Session list records to project. * @returns A cycle-free tree, id lookup, and non-fatal integrity diagnostics. */ export declare function buildSessionTree(summaries: readonly TSummary[]): SessionTreeModel; /** * Flattens tree roots into pre-order rows using an explicit stack. * * @param roots - Cycle-free roots returned by {@link buildSessionTree}. * @returns Rows with depth, sibling position, and parent row indexes. */ export declare function flattenSessionTree(roots: readonly SessionTreeNode[]): readonly SessionTreeRow[];