export interface ToolRecord { toolCallId: string toolName: string inputArgs: Record inputFingerprint: string isError: boolean turnIndex: number timestamp: number tokenEstimate: number } export interface DcpState { toolCalls: Map prunedToolIds: Set currentTurn: number tokensSaved: number totalPruneCount: number previousSummary: string | null compressionCount: number forceCompressNext?: boolean lastCompressionStatus?: string | null activeHermesLayout?: HermesMiddleLayout | null } export interface HermesMiddleLayout { kind: "hermes-middle" headMessageCount: number tailMessageCount: number compactedMessageCount: number originalFirstKeptEntryId: string expandedFirstKeptEntryId: string estimatedTokensAfter: number estimatedTokensSaved: number } export function createState(): DcpState { return { toolCalls: new Map(), prunedToolIds: new Set(), currentTurn: 0, tokensSaved: 0, totalPruneCount: 0, previousSummary: null, compressionCount: 0, forceCompressNext: false, lastCompressionStatus: null, activeHermesLayout: null, } } export function resetState(state: DcpState): void { state.toolCalls.clear() state.prunedToolIds.clear() state.currentTurn = 0 state.tokensSaved = 0 state.totalPruneCount = 0 state.previousSummary = null state.compressionCount = 0 state.forceCompressNext = false state.lastCompressionStatus = null state.activeHermesLayout = null } function sortObjectKeys(value: unknown): unknown { if (Array.isArray(value)) return value.map(sortObjectKeys) if (value !== null && typeof value === "object") { const obj = value as Record const sorted: Record = {} for (const key of Object.keys(obj).sort()) { sorted[key] = sortObjectKeys(obj[key]) } return sorted } return value } export function createInputFingerprint(toolName: string, args: Record): string { const sorted = sortObjectKeys(args) return `${toolName}::${JSON.stringify(sorted)}` }