Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/core/tools/ReadFileTool.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path from "path"
import { isBinaryFile } from "isbinaryfile"
import type { FileEntry, LineRange } from "@roo-code/types"
import { isNativeProtocol } from "@roo-code/types"
import { isNativeProtocol, ANTHROPIC_DEFAULT_MAX_TOKENS } from "@roo-code/types"

import { Task } from "../task/Task"
import { ClineSayTool } from "../../shared/ExtensionMessage"
import { formatResponse } from "../prompts/responses"
import { getModelMaxOutputTokens } from "../../shared/api"
import { t } from "../../i18n"
import { RecordSource } from "../context-tracking/FileContextTrackerTypes"
import { isPathOutsideWorkspace } from "../../utils/pathUtils"
Expand Down Expand Up @@ -480,11 +481,22 @@ export class ReadFileTool extends BaseTool<"read_file"> {
continue
}

const modelInfo = task.api.getModel().info
const { id: modelId, info: modelInfo } = task.api.getModel()
const { contextTokens } = task.getTokenUsage()
const contextWindow = modelInfo.contextWindow

const budgetResult = await validateFileTokenBudget(fullPath, contextWindow, contextTokens || 0)
const maxOutputTokens =
getModelMaxOutputTokens({
modelId,
model: modelInfo,
settings: task.apiConfiguration,
}) ?? ANTHROPIC_DEFAULT_MAX_TOKENS

const budgetResult = await validateFileTokenBudget(
fullPath,
contextWindow - maxOutputTokens,
contextTokens || 0,
)

let content = await extractTextFromFile(fullPath)
let xmlInfo = ""
Expand Down
2 changes: 2 additions & 0 deletions src/core/tools/__tests__/readFileTool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ function createMockCline(): any {
// CRITICAL: Always ensure image support is enabled
api: {
getModel: vi.fn().mockReturnValue({
id: "test-model",
info: {
supportsImages: true,
contextWindow: 200000,
Expand All @@ -228,6 +229,7 @@ function createMockCline(): any {
function setImageSupport(mockCline: any, supportsImages: boolean | undefined): void {
mockCline.api = {
getModel: vi.fn().mockReturnValue({
id: "test-model",
info: { supportsImages },
}),
}
Expand Down
Loading