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