@@ -2,7 +2,7 @@ import { z } from "zod"
22import { search } from "@/features/search"
33import { InferToolInput , InferToolOutput , InferUITool , tool , ToolUIPart } from "ai" ;
44import { isServiceError } from "@/lib/utils" ;
5- import { FileSourceResponse , getFileSource } from '@/features/git' ;
5+ import { FileSourceResponse , getFileSource , listCommits } from '@/features/git' ;
66import { findSearchBasedSymbolDefinitions , findSearchBasedSymbolReferences } from "../codeNav/api" ;
77import { addLineNumbers } from "./utils" ;
88import { toolNames } from "./constants" ;
@@ -267,3 +267,45 @@ export type ListReposTool = InferUITool<typeof listReposTool>;
267267export type ListReposToolInput = InferToolInput < typeof listReposTool > ;
268268export type ListReposToolOutput = InferToolOutput < typeof listReposTool > ;
269269export type ListReposToolUIPart = ToolUIPart < { [ toolNames . listRepos ] : ListReposTool } > ;
270+
271+ export const listCommitsTool = tool ( {
272+ description : 'Lists commits in a repository with optional filtering by date range, author, and commit message.' ,
273+ inputSchema : z . object ( {
274+ repository : z . string ( ) . describe ( "The repository to list commits from" ) ,
275+ query : z . string ( ) . describe ( "Search query to filter commits by message (case-insensitive)" ) . optional ( ) ,
276+ since : z . string ( ) . describe ( "Start date for commit range (e.g., '30 days ago', '2024-01-01', 'last week')" ) . optional ( ) ,
277+ until : z . string ( ) . describe ( "End date for commit range (e.g., 'yesterday', '2024-12-31', 'today')" ) . optional ( ) ,
278+ author : z . string ( ) . describe ( "Filter commits by author name or email (case-insensitive)" ) . optional ( ) ,
279+ maxCount : z . number ( ) . describe ( "Maximum number of commits to return (default: 50)" ) . optional ( ) ,
280+ } ) ,
281+ execute : async ( { repository, query, since, until, author, maxCount } ) => {
282+ const response = await listCommits ( {
283+ repo : repository ,
284+ query,
285+ since,
286+ until,
287+ author,
288+ maxCount,
289+ } ) ;
290+
291+ if ( isServiceError ( response ) ) {
292+ return response ;
293+ }
294+
295+ return {
296+ commits : response . commits . map ( ( commit ) => ( {
297+ hash : commit . hash ,
298+ date : commit . date ,
299+ message : commit . message ,
300+ author : `${ commit . author_name } <${ commit . author_email } >` ,
301+ refs : commit . refs ,
302+ } ) ) ,
303+ totalCount : response . totalCount ,
304+ } ;
305+ }
306+ } ) ;
307+
308+ export type ListCommitsTool = InferUITool < typeof listCommitsTool > ;
309+ export type ListCommitsToolInput = InferToolInput < typeof listCommitsTool > ;
310+ export type ListCommitsToolOutput = InferToolOutput < typeof listCommitsTool > ;
311+ export type ListCommitsToolUIPart = ToolUIPart < { [ toolNames . listCommits ] : ListCommitsTool } > ;
0 commit comments