MCPcopy Create free account
hub / github.com/WJX20/claude-code / getChangedFiles

Function getChangedFiles

src/utils/attachments.ts:2064–2162  ·  view source on GitHub ↗
(
  toolUseContext: ToolUseContext,
)

Source from the content-addressed store, hash-verified

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

Callers 1

getAttachmentsFunction · 0.70

Calls 11

cacheKeysFunction · 0.85
expandPathFunction · 0.85
isFileReadDeniedFunction · 0.85
getSnippetForTwoFileDiffFunction · 0.85
readImageWithTokenBudgetFunction · 0.85
logEventFunction · 0.85
isENOENTFunction · 0.85
deleteMethod · 0.80
logErrorFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected