@@ -36,57 +36,32 @@ public static async Task<ToolChatMessage> Process(ChatToolCall call, Action<stri
3636 {
3737 using var doc = JsonDocument . Parse ( call . FunctionArguments ) ;
3838
39- switch ( call . FunctionName )
39+ if ( call . FunctionName . Equals ( Tool_GetDetailChangesInFile . FunctionName ) )
4040 {
41- case nameof ( GetDetailChangesInFile ) :
42- {
43- var hasRepo = doc . RootElement . TryGetProperty ( "repo" , out var repoPath ) ;
44- var hasFile = doc . RootElement . TryGetProperty ( "file" , out var filePath ) ;
45- var hasOriginalFile = doc . RootElement . TryGetProperty ( "originalFile" , out var originalFilePath ) ;
46- if ( ! hasRepo )
47- throw new ArgumentException ( "repo" , "The repo argument is required" ) ;
48- if ( ! hasFile )
49- throw new ArgumentException ( "file" , "The file argument is required" ) ;
41+ var hasRepo = doc . RootElement . TryGetProperty ( "repo" , out var repoPath ) ;
42+ var hasFile = doc . RootElement . TryGetProperty ( "file" , out var filePath ) ;
43+ var hasOriginalFile = doc . RootElement . TryGetProperty ( "originalFile" , out var originalFilePath ) ;
44+ if ( ! hasRepo )
45+ throw new ArgumentException ( "repo" , "The repo argument is required" ) ;
46+ if ( ! hasFile )
47+ throw new ArgumentException ( "file" , "The file argument is required" ) ;
5048
51- output ? . Invoke ( $ "Read changes in file: { filePath . GetString ( ) } ") ;
49+ output ? . Invoke ( $ "Read changes in file: { filePath . GetString ( ) } ") ;
5250
53- var toolResult = await ChatTools . GetDetailChangesInFile (
54- repoPath . GetString ( ) ,
55- filePath . GetString ( ) ,
56- hasOriginalFile ? originalFilePath . GetString ( ) : string . Empty ) ;
57- return new ToolChatMessage ( call . Id , toolResult ) ;
58- }
59- default :
60- throw new NotSupportedException ( $ "The tool { call . FunctionName } is not supported") ;
51+ var toolResult = await ChatTools . GetDetailChangesInFile (
52+ repoPath . GetString ( ) ,
53+ filePath . GetString ( ) ,
54+ hasOriginalFile ? originalFilePath . GetString ( ) : string . Empty ) ;
55+ return new ToolChatMessage ( call . Id , toolResult ) ;
6156 }
57+
58+ throw new NotSupportedException ( $ "The tool { call . FunctionName } is not supported") ;
6259 }
6360
6461 private static async Task < string > GetDetailChangesInFile ( string repo , string file , string originalFile )
6562 {
66- var rs = await new GetDiffContentCommand ( repo , file , originalFile ) . ReadAsync ( ) ;
63+ var rs = await new Commands . GetFileChangeForAI ( repo , file , originalFile ) . ReadAsync ( ) ;
6764 return rs . IsSuccess ? rs . StdOut : string . Empty ;
6865 }
69-
70- private class GetDiffContentCommand : Commands . Command
71- {
72- public GetDiffContentCommand ( string repo , string file , string originalFile )
73- {
74- WorkingDirectory = repo ;
75- Context = repo ;
76-
77- var builder = new StringBuilder ( ) ;
78- builder . Append ( "diff --no-color --no-ext-diff --diff-algorithm=minimal --cached -- " ) ;
79- if ( ! string . IsNullOrEmpty ( originalFile ) && ! file . Equals ( originalFile , StringComparison . Ordinal ) )
80- builder . Append ( originalFile . Quoted ( ) ) . Append ( ' ' ) ;
81- builder . Append ( file . Quoted ( ) ) ;
82-
83- Args = builder . ToString ( ) ;
84- }
85-
86- public async Task < Result > ReadAsync ( )
87- {
88- return await ReadToEndAsync ( ) . ConfigureAwait ( false ) ;
89- }
90- }
9166 }
9267}
0 commit comments