@@ -25,19 +25,34 @@ export interface SearchConfig {
2525 contextLines : number ;
2626}
2727
28+ export type LogLevel = "error" | "warn" | "info" | "debug" ;
29+
30+ export interface DebugConfig {
31+ enabled : boolean ;
32+ logLevel : LogLevel ;
33+ logSearch : boolean ;
34+ logEmbedding : boolean ;
35+ logCache : boolean ;
36+ logGc : boolean ;
37+ logBranch : boolean ;
38+ metrics : boolean ;
39+ }
40+
2841export interface CodebaseIndexConfig {
2942 embeddingProvider : EmbeddingProvider ;
3043 embeddingModel : string ;
3144 scope : IndexScope ;
3245 indexing ?: Partial < IndexingConfig > ;
3346 search ?: Partial < SearchConfig > ;
47+ debug ?: Partial < DebugConfig > ;
3448 include : string [ ] ;
3549 exclude : string [ ] ;
3650}
3751
3852export type ParsedCodebaseIndexConfig = CodebaseIndexConfig & {
3953 indexing : IndexingConfig ;
4054 search : SearchConfig ;
55+ debug : DebugConfig ;
4156} ;
4257
4358const DEFAULT_INCLUDE = [
@@ -94,8 +109,22 @@ function getDefaultSearchConfig(): SearchConfig {
94109 } ;
95110}
96111
112+ function getDefaultDebugConfig ( ) : DebugConfig {
113+ return {
114+ enabled : false ,
115+ logLevel : "info" ,
116+ logSearch : true ,
117+ logEmbedding : true ,
118+ logCache : true ,
119+ logGc : true ,
120+ logBranch : true ,
121+ metrics : true ,
122+ } ;
123+ }
124+
97125const VALID_PROVIDERS : EmbeddingProvider [ ] = [ "auto" , "github-copilot" , "openai" , "google" , "ollama" ] ;
98126const VALID_SCOPES : IndexScope [ ] = [ "project" , "global" ] ;
127+ const VALID_LOG_LEVELS : LogLevel [ ] = [ "error" , "warn" , "info" , "debug" ] ;
99128
100129function isValidProvider ( value : unknown ) : value is EmbeddingProvider {
101130 return typeof value === "string" && VALID_PROVIDERS . includes ( value as EmbeddingProvider ) ;
@@ -109,11 +138,17 @@ function isStringArray(value: unknown): value is string[] {
109138 return Array . isArray ( value ) && value . every ( item => typeof item === "string" ) ;
110139}
111140
141+ function isValidLogLevel ( value : unknown ) : value is LogLevel {
142+ return typeof value === "string" && VALID_LOG_LEVELS . includes ( value as LogLevel ) ;
143+ }
144+
112145export function parseConfig ( raw : unknown ) : ParsedCodebaseIndexConfig {
113146 const input = ( raw && typeof raw === "object" ? raw : { } ) as Record < string , unknown > ;
114147
115148 const defaultIndexing = getDefaultIndexingConfig ( ) ;
116149 const defaultSearch = getDefaultSearchConfig ( ) ;
150+ const defaultDebug = getDefaultDebugConfig ( ) ;
151+
117152 const rawIndexing = ( input . indexing && typeof input . indexing === "object" ? input . indexing : { } ) as Record < string , unknown > ;
118153 const indexing : IndexingConfig = {
119154 autoIndex : typeof rawIndexing . autoIndex === "boolean" ? rawIndexing . autoIndex : defaultIndexing . autoIndex ,
@@ -137,6 +172,18 @@ export function parseConfig(raw: unknown): ParsedCodebaseIndexConfig {
137172 contextLines : typeof rawSearch . contextLines === "number" ? Math . min ( 50 , Math . max ( 0 , rawSearch . contextLines ) ) : defaultSearch . contextLines ,
138173 } ;
139174
175+ const rawDebug = ( input . debug && typeof input . debug === "object" ? input . debug : { } ) as Record < string , unknown > ;
176+ const debug : DebugConfig = {
177+ enabled : typeof rawDebug . enabled === "boolean" ? rawDebug . enabled : defaultDebug . enabled ,
178+ logLevel : isValidLogLevel ( rawDebug . logLevel ) ? rawDebug . logLevel : defaultDebug . logLevel ,
179+ logSearch : typeof rawDebug . logSearch === "boolean" ? rawDebug . logSearch : defaultDebug . logSearch ,
180+ logEmbedding : typeof rawDebug . logEmbedding === "boolean" ? rawDebug . logEmbedding : defaultDebug . logEmbedding ,
181+ logCache : typeof rawDebug . logCache === "boolean" ? rawDebug . logCache : defaultDebug . logCache ,
182+ logGc : typeof rawDebug . logGc === "boolean" ? rawDebug . logGc : defaultDebug . logGc ,
183+ logBranch : typeof rawDebug . logBranch === "boolean" ? rawDebug . logBranch : defaultDebug . logBranch ,
184+ metrics : typeof rawDebug . metrics === "boolean" ? rawDebug . metrics : defaultDebug . metrics ,
185+ } ;
186+
140187 return {
141188 embeddingProvider : isValidProvider ( input . embeddingProvider ) ? input . embeddingProvider : "auto" ,
142189 embeddingModel : typeof input . embeddingModel === "string" ? input . embeddingModel : "auto" ,
@@ -145,6 +192,7 @@ export function parseConfig(raw: unknown): ParsedCodebaseIndexConfig {
145192 exclude : isStringArray ( input . exclude ) ? input . exclude : DEFAULT_EXCLUDE ,
146193 indexing,
147194 search,
195+ debug,
148196 } ;
149197}
150198
0 commit comments