MCPcopy Create free account
hub / github.com/WJX20/claude-code / readTruncatedFile

Function readTruncatedFile

src/utils/attachments.ts:3129–3170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3127 }
3128
3129 async function readTruncatedFile(): Promise<
3130 | FileAttachment
3131 | CompactFileReferenceAttachment
3132 | AlreadyReadFileAttachment
3133 | null
3134 > {
3135 if (mode === 'compact') {
3136 return {
3137 type: 'compact_file_reference',
3138 filename,
3139 displayPath: relative(getCwd(), filename),
3140 }
3141 }
3142
3143 // Check deny rules before reading truncated file
3144 const appState = toolUseContext.getAppState()
3145 if (isFileReadDenied(filename, appState.toolPermissionContext)) {
3146 return null
3147 }
3148
3149 try {
3150 // Read only the first MAX_LINES_TO_READ lines for files that are too large
3151 const truncatedInput = {
3152 file_path: filename,
3153 offset: offset ?? 1,
3154 limit: MAX_LINES_TO_READ,
3155 }
3156 const result = await FileReadTool.call(truncatedInput, toolUseContext)
3157 logEvent(successEventName, {})
3158
3159 return {
3160 type: 'file' as const,
3161 filename,
3162 content: result.data,
3163 truncated: true,
3164 displayPath: relative(getCwd(), filename),
3165 }
3166 } catch {
3167 logEvent(errorEventName, {})
3168 return null
3169 }
3170 }
3171
3172 // Validate file path is valid
3173 const isValid = await FileReadTool.validateInput(fileInput, toolUseContext)

Callers 1

generateFileAttachmentFunction · 0.85

Calls 3

getCwdFunction · 0.85
isFileReadDeniedFunction · 0.85
logEventFunction · 0.85

Tested by

no test coverage detected