MCPcopy
hub / github.com/claude-code-best/claude-code / processAtMentionedFiles

Function processAtMentionedFiles

src/utils/attachments.ts:1946–2016  ·  view source on GitHub ↗
(
  input: string,
  toolUseContext: ToolUseContext,
)

Source from the content-addressed store, hash-verified

1944}
1945
1946async function processAtMentionedFiles(
1947 input: string,
1948 toolUseContext: ToolUseContext,
1949): Promise<Attachment[]> {
1950 const files = extractAtMentionedFiles(input)
1951 if (files.length === 0) return []
1952
1953 const appState = toolUseContext.getAppState()
1954 const results = await Promise.all(
1955 files.map(async file => {
1956 try {
1957 const { filename, lineStart, lineEnd } = parseAtMentionedFileLines(file)
1958 const absoluteFilename = expandPath(filename)
1959
1960 if (
1961 isFileReadDenied(absoluteFilename, appState.toolPermissionContext)
1962 ) {
1963 return null
1964 }
1965
1966 // Check if it's a directory
1967 try {
1968 const stats = await stat(absoluteFilename)
1969 if (stats.isDirectory()) {
1970 try {
1971 const entries = await readdir(absoluteFilename, {
1972 withFileTypes: true,
1973 })
1974 const MAX_DIR_ENTRIES = 1000
1975 const truncated = entries.length > MAX_DIR_ENTRIES
1976 const names = entries.slice(0, MAX_DIR_ENTRIES).map(e => e.name)
1977 if (truncated) {
1978 names.push(
1979 `\u2026 and ${entries.length - MAX_DIR_ENTRIES} more entries`,
1980 )
1981 }
1982 const stdout = names.join('\n')
1983 logEvent('tengu_at_mention_extracting_directory_success', {})
1984
1985 return {
1986 type: 'directory' as const,
1987 path: absoluteFilename,
1988 content: stdout,
1989 displayPath: relative(getCwd(), absoluteFilename),
1990 }
1991 } catch {
1992 return null
1993 }
1994 }
1995 } catch {
1996 // If stat fails, continue with file logic
1997 }
1998
1999 return await generateFileAttachment(
2000 absoluteFilename,
2001 toolUseContext,
2002 'tengu_at_mention_extracting_filename_success',
2003 'tengu_at_mention_extracting_filename_error',

Callers 1

getAttachmentsFunction · 0.85

Calls 10

extractAtMentionedFilesFunction · 0.85
expandPathFunction · 0.85
isFileReadDeniedFunction · 0.85
statFunction · 0.85
readdirFunction · 0.85
logEventFunction · 0.85
getCwdFunction · 0.85
generateFileAttachmentFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected