( input: string, toolUseContext: ToolUseContext, )
| 1898 | } |
| 1899 | |
| 1900 | async 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', |
no test coverage detected