11import path from "path"
2- import z from "zod"
3- import { Effect } from "effect"
2+ import { Effect , Schema } from "effect"
43import { AppFileSystem } from "@opencode-ai/shared/filesystem"
54import { Git } from "@/git"
65import { assertExternalDirectoryEffect } from "./external-directory"
@@ -9,24 +8,17 @@ import * as Tool from "./tool"
98import { parseRepositoryReference , repositoryCachePath } from "@/util/repository"
109import { Instance } from "@/project/instance"
1110
12- type Parameters = {
13- repository ?: string
14- path ?: string
15- depth ?: number
16- }
17-
18- const parameters : z . ZodType < Parameters > = z
19- . object ( {
20- repository : z
21- . string ( )
22- . optional ( )
23- . describe ( "Cached repository to inspect, as a git URL, host/path reference, or GitHub owner/repo shorthand" ) ,
24- path : z . string ( ) . optional ( ) . describe ( "Directory path to inspect instead of a cached repository" ) ,
25- depth : z . number ( ) . int ( ) . positive ( ) . max ( 6 ) . optional ( ) . describe ( "Maximum structure depth to include. Defaults to 3." ) ,
26- } )
27- . refine ( ( input ) => Boolean ( input . repository || input . path ) , {
28- message : "Either repository or path is required" ,
11+ export const Parameters = Schema . Struct ( {
12+ repository : Schema . optional ( Schema . String ) . annotate ( {
13+ description : "Cached repository to inspect, as a git URL, host/path reference, or GitHub owner/repo shorthand" ,
14+ } ) ,
15+ path : Schema . optional ( Schema . String ) . annotate ( {
16+ description : "Directory path to inspect instead of a cached repository" ,
17+ } ) ,
18+ depth : Schema . optional ( Schema . Number ) . annotate ( {
19+ description : "Maximum structure depth to include. Defaults to 3." ,
2920 } )
21+ } )
3022
3123type Metadata = {
3224 path : string
@@ -84,19 +76,21 @@ function commonEntrypoints(files: Set<string>) {
8476 return [ "index.ts" , "index.tsx" , "index.js" , "index.mjs" , "main.ts" , "main.js" , "src/index.ts" , "src/index.tsx" , "src/index.js" , "src/main.ts" , "src/main.js" ] . filter ( ( file ) => files . has ( file ) )
8577}
8678
87- export const RepoOverviewTool = Tool . define < typeof parameters , Metadata , AppFileSystem . Service | Git . Service > (
79+ export const RepoOverviewTool = Tool . define < typeof Parameters , Metadata , AppFileSystem . Service | Git . Service > (
8880 "repo_overview" ,
8981 Effect . gen ( function * ( ) {
9082 const fs = yield * AppFileSystem . Service
9183 const git = yield * Git . Service
9284
93- const resolveTarget = Effect . fn ( "RepoOverviewTool.resolveTarget" ) ( function * ( params : Parameters ) {
85+ const resolveTarget = Effect . fn ( "RepoOverviewTool.resolveTarget" ) ( function * ( params : Schema . Schema . Type < typeof Parameters > ) {
9486 if ( params . path ) {
9587 const full = path . isAbsolute ( params . path ) ? params . path : path . resolve ( Instance . directory , params . path )
9688 return { path : full , repository : params . repository }
9789 }
9890
99- const parsed = parseRepositoryReference ( params . repository ! )
91+ if ( ! params . repository ) throw new Error ( "Either repository or path is required" )
92+
93+ const parsed = parseRepositoryReference ( params . repository )
10094 if ( ! parsed ) throw new Error ( "Repository must be a git URL, host/path reference, or GitHub owner/repo shorthand" )
10195
10296 const repository = parsed . label
@@ -152,11 +146,11 @@ export const RepoOverviewTool = Tool.define<typeof parameters, Metadata, AppFile
152146
153147 return {
154148 description : DESCRIPTION ,
155- parameters,
156- execute : ( params : Parameters , ctx : Tool . Context < Metadata > ) =>
149+ parameters : Parameters ,
150+ execute : ( params : Schema . Schema . Type < typeof Parameters > , ctx : Tool . Context < Metadata > ) =>
157151 Effect . gen ( function * ( ) {
158152 const target = yield * resolveTarget ( params )
159- const depth = params . depth ?? 3
153+ const depth = ! params . depth || ! Number . isInteger ( params . depth ) || params . depth < 1 || params . depth > 6 ? 3 : params . depth
160154
161155 yield * assertExternalDirectoryEffect ( ctx , target . path , { kind : "directory" } )
162156 yield * ctx . ask ( {
@@ -239,6 +233,6 @@ export const RepoOverviewTool = Tool.define<typeof parameters, Metadata, AppFile
239233 ] . join ( "\n" ) ,
240234 }
241235 } ) . pipe ( Effect . orDie ) ,
242- } satisfies Tool . DefWithoutID < typeof parameters , Metadata >
236+ } satisfies Tool . DefWithoutID < typeof Parameters , Metadata >
243237 } ) ,
244238)
0 commit comments