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