* Execute new single-file format with slice/indentation mode support.
(params: ReadFileParams, task: Task, callbacks: ToolCallbacks)
| 84 | * Execute new single-file format with slice/indentation mode support. |
| 85 | */ |
| 86 | private async executeNew(params: ReadFileParams, task: Task, callbacks: ToolCallbacks): Promise<void> { |
| 87 | const { pushToolResult } = callbacks |
| 88 | const modelInfo = task.api.getModel().info |
| 89 | const filePath = params.path |
| 90 | |
| 91 | // Validate input |
| 92 | if (!filePath) { |
| 93 | task.consecutiveMistakeCount++ |
| 94 | task.recordToolError("read_file") |
| 95 | const errorMsg = await task.sayAndCreateMissingParamError("read_file", "path") |
| 96 | pushToolResult(`Error: ${errorMsg}`) |
| 97 | return |
| 98 | } |
| 99 | |
| 100 | const supportsImages = modelInfo.supportsImages ?? false |
| 101 | |
| 102 | // Initialize file results tracking |
| 103 | // Validate line number parameters (must be 1-indexed positive integers) |
| 104 | if (params.offset !== undefined && params.offset < 1) { |
| 105 | const errorMsg = `offset must be a 1-indexed line number (got ${params.offset}). Line numbers start at 1.` |
| 106 | pushToolResult(`Error: ${errorMsg}`) |
| 107 | return |
| 108 | } |
| 109 | if (params.indentation?.anchor_line !== undefined && params.indentation.anchor_line < 1) { |
| 110 | const errorMsg = `anchor_line must be a 1-indexed line number (got ${params.indentation.anchor_line}). Line numbers start at 1.` |
| 111 | pushToolResult(`Error: ${errorMsg}`) |
| 112 | return |
| 113 | } |
| 114 | |
| 115 | const fileEntry: InternalFileEntry = { |
| 116 | path: filePath, |
| 117 | mode: params.mode, |
| 118 | offset: params.offset, |
| 119 | limit: params.limit, |
| 120 | anchor_line: params.indentation?.anchor_line, |
| 121 | max_levels: params.indentation?.max_levels, |
| 122 | include_siblings: params.indentation?.include_siblings, |
| 123 | include_header: params.indentation?.include_header, |
| 124 | max_lines: params.indentation?.max_lines, |
| 125 | } |
| 126 | |
| 127 | const fileResults: FileResult[] = [ |
| 128 | { |
| 129 | path: filePath, |
| 130 | status: "pending" as const, |
| 131 | entry: fileEntry, |
| 132 | }, |
| 133 | ] |
| 134 | |
| 135 | const updateFileResult = (filePath: string, updates: Partial<FileResult>) => { |
| 136 | const index = fileResults.findIndex((result) => result.path === filePath) |
| 137 | if (index !== -1) { |
| 138 | fileResults[index] = { ...fileResults[index], ...updates } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | try { |
| 143 | // Phase 1: Validate and filter files for approval |
no test coverage detected