import { Anthropic } from "@anthropic-ai/sdk" import { AssistantMessageContent } from "@core/assistant-message" import { ClineAskResponse } from "@shared/WebviewMessage" import type { HookExecution } from "./types/HookExecution" export class TaskState { // Task-level timing taskStartTimeMs = Date.now() taskFirstTokenTimeMs?: number // Streaming flags isStreaming = false isWaitingForFirstChunk = false didCompleteReadingStream = false // Content processing currentStreamingContentIndex = 0 assistantMessageContent: AssistantMessageContent[] = [] userMessageContent: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam | Anthropic.ToolResultBlockParam)[] = [] userMessageContentReady = false // Map of tool names to their tool_use_id for creating proper ToolResultBlockParam toolUseIdMap: Map = new Map() // Presentation locks presentAssistantMessageLocked = false presentAssistantMessageHasPendingUpdates = false // Ask/Response handling askResponse?: ClineAskResponse askResponseText?: string askResponseImages?: string[] askResponseFiles?: string[] lastMessageTs?: number // Plan mode specific state isAwaitingPlanResponse = false didRespondToPlanAskBySwitchingMode = false // Context and history conversationHistoryDeletedRange?: [number, number] // Tool execution flags didRejectTool = false didAlreadyUseTool = false didEditFile = false lastToolName = "" // Track last tool used for consecutive call detection lastToolParams = "" // Canonical signature of last tool's params (via toolCallSignature) consecutiveIdenticalToolCount = 0 // Consecutive calls with identical tool name + params // File read deduplication cache - prevents the model from endlessly reading the same files // Maps absolute file path → { readCount: times read in this task, mtime: last modified timestamp, imageBlock: optional image data for multimodal models } fileReadCache: Map = new Map() // Error tracking consecutiveMistakeCount = 0 doubleCheckCompletionPending = false didAutomaticallyRetryFailedApiRequest = false hasNotifiedImageStripping = false checkpointManagerErrorMessage?: string // Retry tracking for auto-retry feature autoRetryAttempts = 0 // Task Initialization isInitialized = false // Focus Chain / Todo List Management apiRequestCount = 0 apiRequestsSinceLastTodoUpdate = 0 currentFocusChainChecklist: string | null = null todoListWasUpdatedByUser = false // Task Abort / Cancellation abort = false didFinishAbortingStream = false abandoned = false // Hook execution tracking for cancellation activeHookExecution?: HookExecution // Auto-context summarization currentlySummarizing = false lastAutoCompactTriggerIndex?: number }