export interface CacheUsageTotals { input: number; output: number; cacheRead: number; cacheWrite: number; totalTokens: number; assistantMessages: number; } export interface AssistantUsageMetric { sequence: number; activeBranchSequence?: number; entryId: string; timestamp: string; provider: string; model: string; input: number; output: number; cacheRead: number; cacheWrite: number; totalTokens: number; cacheHitPercent: number; isOnActiveBranch: boolean; /** True when provider/model differs from the previous assistant message. */ modelChanged?: boolean; /** Gap in ms to the previous assistant message. */ idleMs?: number; /** True when the idle gap exceeds the TTL applicable to this model's API protocol. */ idleExpired?: boolean; /** True when a compaction/branch summary sits between this turn and the previous one. */ afterCompact?: boolean; /** True when a thinking-level change entry sits between this turn and the previous one. */ thinkingChanged?: boolean; /** * True when the prompt shrank substantially versus the previous assistant * message. Appending never shrinks a prompt and idle expiry never changes * it, so a large shrink is decisive evidence that the context was rebuilt * differently (restart replay, restored session, replay/tool-set change). */ promptShrunk?: boolean; /** * True when a large share of the cached prefix was re-billed with no * recorded cause — the catch-all signal for prefix rewrites pi does not * persist (tool set, context files, extension injection). Co-occurs with * idleExpired: a restart, for example, creates both a long gap and a * rebuilt prefix, and the rebuilt tag must not be suppressed by the gap. */ contextInvalidated?: boolean; /** Prefix tokens re-billed as fresh (pi's cache-miss math), when significant. */ missedTokens?: number; /** Estimated extra cost of the miss in USD, when significant. */ missedCost?: number; /** Missed tokens as a ratio of the previous prompt (cached prefix). */ missRatio?: number; /** * Listed in the miss analysis: the miss ratio exceeded the cached-length- * scaled threshold, i.e. the cacheable prefix was broken. */ missFlagged?: boolean; } export interface CacheSessionMetrics { allMessages: AssistantUsageMetric[]; treeTotals: CacheUsageTotals; activeBranchTotals: CacheUsageTotals; }