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

Function processAtMentionedFiles

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

Source from the content-addressed store, hash-verified

1898}
1899
1900async function processAtMentionedFiles(
1901 input: string,
1902 toolUseContext: ToolUseContext,
1903): Promise<Attachment[]> {
1904 const files = extractAtMentionedFiles(input)
1905 if (files.length === 0) return []
1906
1907 const appState = toolUseContext.getAppState()
1908 const results = await Promise.all(
1909 files.map(async file => {
1910 try {
1911 const { filename, lineStart, lineEnd } = parseAtMentionedFileLines(file)
1912 const absoluteFilename = expandPath(filename)
1913
1914 if (
1915 isFileReadDenied(absoluteFilename, appState.toolPermissionContext)
1916 ) {
1917 return null
1918 }
1919
1920 // Check if it's a directory
1921 try {
1922 const stats = await stat(absoluteFilename)
1923 if (stats.isDirectory()) {
1924 try {
1925 const entries = await readdir(absoluteFilename, {
1926 withFileTypes: true,
1927 })
1928 const MAX_DIR_ENTRIES = 1000
1929 const truncated = entries.length > MAX_DIR_ENTRIES
1930 const names = entries.slice(0, MAX_DIR_ENTRIES).map(e => e.name)
1931 if (truncated) {
1932 names.push(
1933 `\u2026 and ${entries.length - MAX_DIR_ENTRIES} more entries`,
1934 )
1935 }
1936 const stdout = names.join('\n')
1937 logEvent('ncode_at_mention_extracting_directory_success', {})
1938
1939 return {
1940 type: 'directory' as const,
1941 path: absoluteFilename,
1942 content: stdout,
1943 displayPath: relative(getCwd(), absoluteFilename),
1944 }
1945 } catch {
1946 return null
1947 }
1948 }
1949 } catch {
1950 // If stat fails, continue with file logic
1951 }
1952
1953 return await generateFileAttachment(
1954 absoluteFilename,
1955 toolUseContext,
1956 'ncode_at_mention_extracting_filename_success',
1957 'ncode_at_mention_extracting_filename_error',

Callers 1

getAttachmentsFunction · 0.85

Calls 9

extractAtMentionedFilesFunction · 0.85
expandPathFunction · 0.85
isFileReadDeniedFunction · 0.85
statFunction · 0.85
readdirFunction · 0.85
getCwdFunction · 0.85
generateFileAttachmentFunction · 0.85
logEventFunction · 0.50

Tested by

no test coverage detected