@@ -4,6 +4,8 @@ import { listCommits, SearchCommitsResult } from "@/features/git";
44import { ToolDefinition } from "./types" ;
55import { logger } from "./logger" ;
66import description from "./listCommits.txt" ;
7+ import { CodeHostType } from "@sourcebot/db" ;
8+ import { getRepoInfoByName } from "@/actions" ;
79
810const listCommitsShape = {
911 repo : z . string ( ) . describe ( "The repository to list commits from" ) ,
@@ -12,11 +14,21 @@ const listCommitsShape = {
1214 until : z . string ( ) . describe ( "End date for commit range (e.g., 'yesterday', '2024-12-31', 'today')" ) . optional ( ) ,
1315 author : z . string ( ) . describe ( "Filter commits by author name or email (case-insensitive)" ) . optional ( ) ,
1416 ref : z . string ( ) . describe ( "Commit SHA, branch or tag name to list commits of. If not provided, uses the default branch." ) . optional ( ) ,
17+ path : z . string ( ) . describe ( "Filter commits to only those that touched this file or directory path (relative to repo root)." ) . optional ( ) ,
1518 page : z . number ( ) . int ( ) . positive ( ) . describe ( "Page number for pagination (min 1). Default: 1" ) . optional ( ) . default ( 1 ) ,
1619 perPage : z . number ( ) . int ( ) . positive ( ) . max ( 100 ) . describe ( "Results per page for pagination (min 1, max 100). Default: 50" ) . optional ( ) . default ( 50 ) ,
1720} ;
1821
19- export type ListCommitsMetadata = SearchCommitsResult ;
22+ export type ListCommitsRepoInfo = {
23+ name : string ;
24+ displayName : string ;
25+ codeHostType : CodeHostType ;
26+ } ;
27+
28+ export type ListCommitsMetadata = SearchCommitsResult & {
29+ repo : string ;
30+ repoInfo : ListCommitsRepoInfo ;
31+ } ;
2032
2133export const listCommitsDefinition : ToolDefinition < "list_commits" , typeof listCommitsShape , ListCommitsMetadata > = {
2234 name : "list_commits" ,
@@ -28,7 +40,7 @@ export const listCommitsDefinition: ToolDefinition<"list_commits", typeof listCo
2840 execute : async ( params , _context ) => {
2941 logger . debug ( 'list_commits' , params ) ;
3042
31- const { repo, query, since, until, author, ref, page, perPage } = params ;
43+ const { repo, query, since, until, author, ref, path , page, perPage } = params ;
3244 const skip = ( page - 1 ) * perPage ;
3345
3446 const response = await listCommits ( {
@@ -38,6 +50,7 @@ export const listCommitsDefinition: ToolDefinition<"list_commits", typeof listCo
3850 until,
3951 author,
4052 ref,
53+ path,
4154 maxCount : perPage ,
4255 skip,
4356 } ) ;
@@ -46,9 +59,19 @@ export const listCommitsDefinition: ToolDefinition<"list_commits", typeof listCo
4659 throw new Error ( response . message ) ;
4760 }
4861
62+ const repoInfoResult = await getRepoInfoByName ( repo ) ;
63+ if ( isServiceError ( repoInfoResult ) || ! repoInfoResult ) {
64+ throw new Error ( `Repository "${ repo } " not found.` ) ;
65+ }
66+ const repoInfo : ListCommitsRepoInfo = {
67+ name : repoInfoResult . name ,
68+ displayName : repoInfoResult . displayName ?? repoInfoResult . name ,
69+ codeHostType : repoInfoResult . codeHostType ,
70+ } ;
71+
4972 return {
5073 output : JSON . stringify ( response ) ,
51- metadata : response ,
74+ metadata : { ... response , repo , repoInfo } ,
5275 } ;
5376 } ,
5477} ;
0 commit comments