( toolUseContext: ToolUseContext, )
| 2113 | } |
| 2114 | |
| 2115 | export async function getChangedFiles( |
| 2116 | toolUseContext: ToolUseContext, |
| 2117 | ): Promise<Attachment[]> { |
| 2118 | const filePaths = cacheKeys(toolUseContext.readFileState) |
| 2119 | if (filePaths.length === 0) return [] |
| 2120 | |
| 2121 | const appState = toolUseContext.getAppState() |
| 2122 | const results = await Promise.all( |
| 2123 | filePaths.map(async filePath => { |
| 2124 | const fileState = toolUseContext.readFileState.get(filePath) |
| 2125 | if (!fileState) return null |
| 2126 | |
| 2127 | // TODO: Implement offset/limit support for changed files |
| 2128 | if (fileState.offset !== undefined || fileState.limit !== undefined) { |
| 2129 | return null |
| 2130 | } |
| 2131 | |
| 2132 | const normalizedPath = expandPath(filePath) |
| 2133 | |
| 2134 | // Check if file has a deny rule configured |
| 2135 | if (isFileReadDenied(normalizedPath, appState.toolPermissionContext)) { |
| 2136 | return null |
| 2137 | } |
| 2138 | |
| 2139 | try { |
| 2140 | const mtime = await getFileModificationTimeAsync(normalizedPath) |
| 2141 | if (mtime <= fileState.timestamp) { |
| 2142 | return null |
| 2143 | } |
| 2144 | |
| 2145 | const fileInput = { file_path: normalizedPath } |
| 2146 | |
| 2147 | // Validate file path is valid |
| 2148 | const isValid = await FileReadTool.validateInput( |
| 2149 | fileInput, |
| 2150 | toolUseContext, |
| 2151 | ) |
| 2152 | if (!isValid.result) { |
| 2153 | return null |
| 2154 | } |
| 2155 | |
| 2156 | const result = await FileReadTool.call(fileInput, toolUseContext) |
| 2157 | // Extract only the changed section |
| 2158 | if (result.data.type === 'text') { |
| 2159 | const snippet = getSnippetForTwoFileDiff( |
| 2160 | fileState.content, |
| 2161 | result.data.file.content, |
| 2162 | ) |
| 2163 | |
| 2164 | // File was touched but not modified |
| 2165 | if (snippet === '') { |
| 2166 | return null |
| 2167 | } |
| 2168 | |
| 2169 | return { |
| 2170 | type: 'edited_text_file' as const, |
| 2171 | filename: normalizedPath, |
| 2172 | snippet, |
no test coverage detected