Context Compression: - auto-condense extended to all models with >=200K context window - 500K+ context windows use 92% buffer (was conservative formula) - added summarizeTaskLite template for <200K models - fileOptimizationThreshold now configurable (default 0.3) Multimodal Image Handling: - auto-strip images when switching from vision to text-only models - one-time notification per task session - images preserved in history, auto-restored when switching back Bug Fixes: - fixed API errors when switching multimodal to text-only model mid-conversation
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
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<string, string> = 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<string, { readCount: number; mtime: number; imageBlock?: Anthropic.ImageBlockParam }> = 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
|
|
}
|