( toolUseContext: ToolUseContext, )
| 2067 | } |
| 2068 | |
| 2069 | export async function getChangedFiles( |
| 2070 | toolUseContext: ToolUseContext, |
| 2071 | ): Promise<Attachment[]> { |
| 2072 | const filePaths = cacheKeys(toolUseContext.readFileState) |
| 2073 | if (filePaths.length === 0) return [] |
| 2074 | |
| 2075 | const appState = toolUseContext.getAppState() |
| 2076 | const results = await Promise.all( |
| 2077 | filePaths.map(async filePath => { |
| 2078 | const fileState = toolUseContext.readFileState.get(filePath) |
| 2079 | if (!fileState) return null |
| 2080 | |
| 2081 | // TODO: Implement offset/limit support for changed files |
| 2082 | if (fileState.offset !== undefined || fileState.limit !== undefined) { |
| 2083 | return null |
| 2084 | } |
| 2085 | |
| 2086 | const normalizedPath = expandPath(filePath) |
| 2087 | |
| 2088 | // Check if file has a deny rule configured |
| 2089 | if (isFileReadDenied(normalizedPath, appState.toolPermissionContext)) { |
| 2090 | return null |
| 2091 | } |
| 2092 | |
| 2093 | try { |
| 2094 | const mtime = await getFileModificationTimeAsync(normalizedPath) |
| 2095 | if (mtime <= fileState.timestamp) { |
| 2096 | return null |
| 2097 | } |
| 2098 | |
| 2099 | const fileInput = { file_path: normalizedPath } |
| 2100 | |
| 2101 | // Validate file path is valid |
| 2102 | const isValid = await FileReadTool.validateInput( |
| 2103 | fileInput, |
| 2104 | toolUseContext, |
| 2105 | ) |
| 2106 | if (!isValid.result) { |
| 2107 | return null |
| 2108 | } |
| 2109 | |
| 2110 | const result = await FileReadTool.call(fileInput, toolUseContext) |
| 2111 | // Extract only the changed section |
| 2112 | if (result.data.type === 'text') { |
| 2113 | const snippet = getSnippetForTwoFileDiff( |
| 2114 | fileState.content, |
| 2115 | result.data.file.content, |
| 2116 | ) |
| 2117 | |
| 2118 | // File was touched but not modified |
| 2119 | if (snippet === '') { |
| 2120 | return null |
| 2121 | } |
| 2122 | |
| 2123 | return { |
| 2124 | type: 'edited_text_file' as const, |
| 2125 | filename: normalizedPath, |
| 2126 | snippet, |
no test coverage detected