MCPcopy Create free account
hub / github.com/Noumena-Network/code / readTruncatedFile

Function readTruncatedFile

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

Source from the content-addressed store, hash-verified

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

Callers 1

generateFileAttachmentFunction · 0.85

Calls 3

getCwdFunction · 0.85
isFileReadDeniedFunction · 0.85
logEventFunction · 0.50

Tested by

no test coverage detected