@@ -175,35 +175,23 @@ async def run_tool(self, arguments: Dict[str, Any]) -> Sequence[TextContent]:
175
175
return [TextContent (type = "text" , text = json .dumps (results , indent = 2 ))]
176
176
177
177
for file_operation in files :
178
- file_path = None
178
+ if "path" not in file_operation :
179
+ raise RuntimeError ("Missing required field: path" )
180
+ if "file_hash" not in file_operation :
181
+ raise RuntimeError ("Missing required field: file_hash" )
182
+ if "patches" not in file_operation :
183
+ raise RuntimeError ("Missing required field: patches" )
184
+
179
185
try :
180
- try :
181
- file_path = file_operation ["path" ]
182
- except KeyError as e :
183
- raise RuntimeError (
184
- "Missing required field: path in file operation"
185
- ) from e
186
-
187
- try :
188
- file_hash = file_operation ["file_hash" ]
189
- except KeyError as e :
190
- raise RuntimeError (
191
- f"Missing required field: file_hash for file { file_path } "
192
- ) from e
193
-
194
- # Ensure patches list is not empty
195
- try :
196
- patches = file_operation ["patches" ]
197
- except KeyError as e :
198
- raise RuntimeError (
199
- f"Missing required field: patches for file { file_path } "
200
- ) from e
186
+ file_path = file_operation ["path" ]
187
+ file_hash = file_operation ["file_hash" ]
188
+ patches = file_operation ["patches" ]
201
189
202
190
if not patches :
203
191
results [file_path ] = {
204
192
"result" : "error" ,
205
193
"reason" : "Empty patches list" ,
206
- "file_hash" : None ,
194
+ "file_hash" : file_hash ,
207
195
"content" : None ,
208
196
}
209
197
continue
@@ -214,15 +202,22 @@ async def run_tool(self, arguments: Dict[str, Any]) -> Sequence[TextContent]:
214
202
)
215
203
results [file_path ] = result
216
204
except Exception as e :
217
- if file_path :
218
- results [file_path ] = {
219
- "result" : "error" ,
220
- "reason" : str (e ),
221
- "file_hash" : None ,
222
- "content" : None ,
223
- }
224
- else :
225
- raise
205
+ current_hash = None
206
+ if "path" in file_operation :
207
+ file_path = file_operation ["path" ]
208
+ try :
209
+ current_content , _ , _ , current_hash , _ , _ = (
210
+ await self .editor .read_file_contents (file_path )
211
+ )
212
+ except Exception :
213
+ current_hash = None
214
+
215
+ results [file_path if "path" in file_operation else "unknown" ] = {
216
+ "result" : "error" ,
217
+ "reason" : str (e ),
218
+ "file_hash" : current_hash ,
219
+ "content" : None ,
220
+ }
226
221
227
222
return [TextContent (type = "text" , text = json .dumps (results , indent = 2 ))]
228
223
except Exception as e :
0 commit comments