import type { ThinkingLevel } from "@earendil-works/pi-agent-core"; export const LABEL_KINDS = ["branch-root", "decision", "checkpoint", "outcome", "endpoint"] as const; export type LabelKind = (typeof LABEL_KINDS)[number]; export type ExposureMode = "balanced" | "tree" | "branch" | "neighborhood"; export type ApplyMode = "review" | "auto" | "manual"; export interface TreeLabelerSettings { enabled: boolean; model: string; thinkingLevel: ThinkingLevel; prompt: string; exposure: ExposureMode; applyMode: ApplyMode; automation: { enabled: boolean; afterTurns: number; onBranchCreated: boolean; onTreeNavigation: boolean; onCompaction: boolean; }; sessionNaming: { enabled: boolean; fallbackToMessage: boolean; maxChars: number; }; autoLimits: boolean; offerLimitIncreases: boolean; maxNodes: number; excerptChars: number; maxInputChars: number; maxLabels: number; maxLabelChars: number; outputTokens: number | undefined; timeoutMs: number; includeToolNames: boolean; persistPayloads: boolean; } export interface SemanticNode { id: string; parentId: string | null; role: "user" | "assistant" | "compaction" | "branch-summary" | "custom"; excerpt: string; existingLabel?: string; ownership: "owned" | "manual" | "none"; active: boolean; depth: number; childCount: number; branchRoot: boolean; branchPoint: boolean; leaf: boolean; excerptTruncated: boolean; } export type LimitKey = "maxNodes" | "excerptChars" | "maxInputChars" | "maxLabels" | "maxLabelChars" | "outputTokens" | "timeoutMs"; export interface SerializedTree { text: string; exposedIds: Set; nodeCount: number; omittedCount: number; limitsHit: LimitKey[]; } export interface LabelProposal { entryId: string; label: string; kind: LabelKind; rationale?: string; confidence?: number; } export interface ProposalConflict extends LabelProposal { conflict: string; } export interface LabelRun { version: 1; id: string; sessionId: string; createdAt: string; status: "proposed" | "applied" | "discarded" | "failed"; trigger: "manual" | "automatic"; model: string; settings: Omit & { promptHash: string }; treeDigest: string; leafId: string | null; exposedNodes: number; omittedNodes: number; proposals: LabelProposal[]; conflicts: ProposalConflict[]; applied?: Array<{ entryId: string; label: string; labelEntryId: string }>; warnings?: string[]; error?: string; diagnostic?: { stage: string; errorType: string; code?: string; rootCause?: string; guidance?: string[]; outputShape?: unknown; }; prompt?: string; response?: unknown; } export interface OwnershipState { latestLabelEntryByTarget: Map; ownedLabelEntryIds: Set; manuallyClearedTargets: Set; } export interface ApplyLedger { version: 1; runId: string; changes: Array<{ targetId: string; previousLabel?: string; label: string; labelEntryId: string; }>; }