MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getFileOrFolderContentWithMetadata

Function getFileOrFolderContentWithMetadata

src/core/mentions/index.ts:265–391  ·  view source on GitHub ↗

* Gets file or folder content and returns it as a MentionContentBlock * formatted to look like a read_file tool result.

(
	mentionPath: string,
	cwd: string,
	rooIgnoreController?: any,
	showRooIgnoredFiles: boolean = false,
	fileContextTracker?: FileContextTracker,
)

Source from the content-addressed store, hash-verified

263 * formatted to look like a read_file tool result.
264 */
265async function getFileOrFolderContentWithMetadata(
266 mentionPath: string,
267 cwd: string,
268 rooIgnoreController?: any,
269 showRooIgnoredFiles: boolean = false,
270 fileContextTracker?: FileContextTracker,
271): Promise<MentionContentBlock> {
272 const unescapedPath = unescapeSpaces(mentionPath)
273 const absPath = path.resolve(cwd, unescapedPath)
274 const isFolder = mentionPath.endsWith("/")
275
276 try {
277 const stats = await fs.stat(absPath)
278
279 if (stats.isFile()) {
280 // Avoid trying to include image binary content as text context.
281 // Image mentions are handled separately via image attachment flow.
282 const isBinary = await isBinaryFile(absPath).catch(() => false)
283 if (isBinary) {
284 return {
285 type: "file",
286 path: mentionPath,
287 content: `[read_file for '${mentionPath}']\nNote: Binary file omitted from context.`,
288 }
289 }
290 if (rooIgnoreController && !rooIgnoreController.validateAccess(unescapedPath)) {
291 return {
292 type: "file",
293 path: mentionPath,
294 content: `[read_file for '${mentionPath}']\nNote: File is ignored by .rooignore.`,
295 }
296 }
297 try {
298 const result = await extractTextFromFileWithMetadata(absPath)
299
300 // Track file context
301 if (fileContextTracker) {
302 await fileContextTracker.trackFileContext(mentionPath, "file_mentioned")
303 }
304
305 return {
306 type: "file",
307 path: mentionPath,
308 content: formatFileReadResult(mentionPath, result),
309 metadata: {
310 totalLines: result.totalLines,
311 returnedLines: result.returnedLines,
312 wasTruncated: result.wasTruncated,
313 linesShown: result.linesShown,
314 },
315 }
316 } catch (error) {
317 const errorMsg = error instanceof Error ? error.message : String(error)
318 return {
319 type: "file",
320 path: mentionPath,
321 content: `[read_file for '${mentionPath}']\nError: ${errorMsg}`,
322 }

Callers 1

parseMentionsFunction · 0.85

Calls 8

unescapeSpacesFunction · 0.90
formatFileReadResultFunction · 0.85
statMethod · 0.80
trackFileContextMethod · 0.80
toPosixMethod · 0.65
StringInterface · 0.50
validateAccessMethod · 0.45

Tested by

no test coverage detected