()
| 3208 | } |
| 3209 | |
| 3210 | async function readTruncatedFile(): Promise< |
| 3211 | | FileAttachment |
| 3212 | | CompactFileReferenceAttachment |
| 3213 | | AlreadyReadFileAttachment |
| 3214 | | null |
| 3215 | > { |
| 3216 | if (mode === 'compact') { |
| 3217 | return { |
| 3218 | type: 'compact_file_reference', |
| 3219 | filename, |
| 3220 | displayPath: relative(getCwd(), filename), |
| 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | // Check deny rules before reading truncated file |
| 3225 | const appState = toolUseContext.getAppState() |
| 3226 | if (isFileReadDenied(filename, appState.toolPermissionContext)) { |
| 3227 | return null |
| 3228 | } |
| 3229 | |
| 3230 | try { |
| 3231 | // Read only the first MAX_LINES_TO_READ lines for files that are too large |
| 3232 | const truncatedInput = { |
| 3233 | file_path: filename, |
| 3234 | offset: offset ?? 1, |
| 3235 | limit: MAX_LINES_TO_READ, |
| 3236 | } |
| 3237 | const result = await FileReadTool.call(truncatedInput, toolUseContext) |
| 3238 | logEvent(successEventName, {}) |
| 3239 | |
| 3240 | return { |
| 3241 | type: 'file' as const, |
| 3242 | filename, |
| 3243 | content: result.data, |
| 3244 | truncated: true, |
| 3245 | displayPath: relative(getCwd(), filename), |
| 3246 | } |
| 3247 | } catch { |
| 3248 | logEvent(errorEventName, {}) |
| 3249 | return null |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | // Validate file path is valid |
| 3254 | const isValid = await FileReadTool.validateInput(fileInput, toolUseContext) |
no test coverage detected