Skip to content

Commit c98889c

Browse files
committed
fix: remove cache logic from read_file deduplication feature
- Removed cache window logic from deduplicateReadFileHistory method - Removed getRecentFileContent method from Task.ts - Removed cache-related code from readFileTool.ts - Removed readFileDeduplicationCacheMinutes setting from all type definitions - Updated tests to remove cache-related test cases - Verified all cache-related code has been removed The deduplication feature now deduplicates all duplicate read_file results regardless of their age.
1 parent 44f4bd5 commit c98889c

File tree

9 files changed

+1
-659
lines changed

9 files changed

+1
-659
lines changed

packages/types/src/global-settings.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ export const globalSettingsSchema = z.object({
120120
diffEnabled: z.boolean().optional(),
121121
fuzzyMatchThreshold: z.number().optional(),
122122
experiments: experimentsSchema.optional(),
123-
readFileDeduplicationCacheMinutes: z.number().optional(),
124123

125124
codebaseIndexModels: codebaseIndexModelsSchema.optional(),
126125
codebaseIndexConfig: codebaseIndexConfigSchema.optional(),

src/core/task/Task.ts

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -329,90 +329,13 @@ export class Task extends EventEmitter<ClineEvents> {
329329
return readApiMessages({ taskId: this.taskId, globalStoragePath: this.globalStoragePath })
330330
}
331331

332-
public async getRecentFileContent(filePath: string): Promise<string | null> {
333-
// Check if the experimental feature is enabled
334-
const state = await this.providerRef.deref()?.getState()
335-
if (!state?.experiments || !experiments.isEnabled(state.experiments, EXPERIMENT_IDS.READ_FILE_DEDUPLICATION)) {
336-
return null
337-
}
338-
339-
// Get the cache window from settings
340-
const cacheMinutes = state?.readFileDeduplicationCacheMinutes ?? 5
341-
if (cacheMinutes === 0) {
342-
// Cache is disabled
343-
return null
344-
}
345-
346-
const cacheWindowMs = cacheMinutes * 60 * 1000
347-
const now = Date.now()
348-
349-
// Check recent conversation history for this file
350-
for (let i = this.apiConversationHistory.length - 1; i >= 0; i--) {
351-
const message = this.apiConversationHistory[i]
352-
353-
// Only process user messages
354-
if (message.role !== "user") {
355-
continue
356-
}
357-
358-
// Skip messages outside the cache window
359-
if (message.ts && now - message.ts > cacheWindowMs) {
360-
break
361-
}
362-
363-
// Process content blocks
364-
if (Array.isArray(message.content)) {
365-
for (const block of message.content) {
366-
if (block.type === "text" && typeof block.text === "string") {
367-
// Check for read_file results in text blocks
368-
const readFileMatch = block.text.match(/\[read_file(?:\s+for\s+'([^']+)')?.*?\]\s*Result:/i)
369-
370-
if (readFileMatch) {
371-
// Extract file paths from the result content
372-
const resultContent = block.text.substring(block.text.indexOf("Result:") + 7).trim()
373-
374-
// Handle new XML format
375-
const xmlFileMatches = resultContent.matchAll(
376-
/<file>\s*<path>([^<]+)<\/path>[\s\S]*?<content[^>]*?>([\s\S]*?)<\/content>/g,
377-
)
378-
for (const match of xmlFileMatches) {
379-
const matchedPath = match[1].trim()
380-
const content = match[2].trim()
381-
if (matchedPath === filePath) {
382-
return content
383-
}
384-
}
385-
386-
// Handle legacy format (single file)
387-
if (
388-
readFileMatch[1] &&
389-
readFileMatch[1] === filePath &&
390-
!resultContent.includes("<files>")
391-
) {
392-
// For legacy format, the content is directly after "Result:"
393-
// Remove any leading/trailing whitespace
394-
return resultContent.trim()
395-
}
396-
}
397-
}
398-
}
399-
}
400-
}
401-
402-
return null
403-
}
404-
405332
public async deduplicateReadFileHistory(): Promise<void> {
406333
// Check if the experimental feature is enabled
407334
const state = await this.providerRef.deref()?.getState()
408335
if (!state?.experiments || !experiments.isEnabled(state.experiments, EXPERIMENT_IDS.READ_FILE_DEDUPLICATION)) {
409336
return
410337
}
411338

412-
// Get the cache window from settings, defaulting to 5 minutes if not set
413-
const cacheMinutes = state?.readFileDeduplicationCacheMinutes ?? 5
414-
const cacheWindowMs = cacheMinutes * 60 * 1000
415-
const now = Date.now()
416339
const seenFiles = new Map<string, { messageIndex: number; blockIndex: number }>()
417340
const blocksToRemove = new Map<number, Set<number>>() // messageIndex -> Set of blockIndexes to remove
418341

@@ -425,11 +348,6 @@ export class Task extends EventEmitter<ClineEvents> {
425348
continue
426349
}
427350

428-
// Skip messages within the cache window
429-
if (message.ts && now - message.ts < cacheWindowMs) {
430-
continue
431-
}
432-
433351
// Process content blocks
434352
if (Array.isArray(message.content)) {
435353
for (let j = 0; j < message.content.length; j++) {

0 commit comments

Comments
 (0)