1+ import * as path from 'path' ;
2+
13import chalk from 'chalk' ;
24import { Logger } from 'mycoder-agent' ;
35
@@ -8,6 +10,7 @@ import {
810 updateConfig ,
911 getConfigAtLevel ,
1012 clearConfigAtLevel ,
13+ clearConfigKey ,
1114 ConfigLevel ,
1215} from '../settings/config.js' ;
1316import { nameToLogIndex } from '../utils/nameToLogIndex.js' ;
@@ -18,7 +21,9 @@ export interface ConfigOptions extends SharedOptions {
1821 command : 'get' | 'set' | 'list' | 'clear' ;
1922 key ?: string ;
2023 value ?: string ;
21- all ?: boolean ;
24+ all : boolean ; // Has default value in builder, so it's always defined
25+ global : boolean ; // Has default value in builder, so it's always defined
26+ verbose : boolean ; // Has default value in builder, so it's always defined
2227}
2328
2429export const command : CommandModule < SharedOptions , ConfigOptions > = {
@@ -45,6 +50,18 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
4550 type : 'boolean' ,
4651 default : false ,
4752 } )
53+ . option ( 'global' , {
54+ alias : 'g' ,
55+ describe : 'Use global configuration instead of project-level' ,
56+ type : 'boolean' ,
57+ default : false ,
58+ } )
59+ . option ( 'verbose' , {
60+ alias : 'v' ,
61+ describe : 'Show detailed information including config file paths' ,
62+ type : 'boolean' ,
63+ default : false ,
64+ } )
4865 . example ( '$0 config list' , 'List all configuration values' )
4966 . example (
5067 '$0 config get githubMode' ,
@@ -115,6 +132,35 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
115132 // Handle 'list' command
116133 if ( argv . command === 'list' ) {
117134 logger . info ( 'Current configuration:' ) ;
135+
136+ // Show config file locations
137+ const {
138+ getSettingsDir,
139+ getProjectSettingsDir,
140+ } = require ( '../settings/settings.js' ) ;
141+ const globalConfigPath = path . join ( getSettingsDir ( ) , 'config.json' ) ;
142+ const projectDir = getProjectSettingsDir ( ) ;
143+ const projectConfigPath = projectDir
144+ ? path . join ( projectDir , 'config.json' )
145+ : 'Not available' ;
146+
147+ logger . info ( `Global config file: ${ chalk . blue ( globalConfigPath ) } ` ) ;
148+ logger . info ( `Project config file: ${ chalk . blue ( projectConfigPath ) } ` ) ;
149+ logger . info ( '' ) ;
150+
151+ // Show config file paths in verbose mode
152+ if ( argv . verbose || argv . v ) {
153+ const { getProjectConfigFile } = await import ( '../settings/config.js' ) ;
154+ const { getSettingsDir } = await import ( '../settings/settings.js' ) ;
155+ const globalConfigPath = path . join ( getSettingsDir ( ) , 'config.json' ) ;
156+ const projectConfigPath = getProjectConfigFile ( ) ;
157+
158+ logger . info ( `Global config: ${ chalk . blue ( globalConfigPath ) } ` ) ;
159+ logger . info (
160+ `Project config: ${ projectConfigPath ? chalk . blue ( projectConfigPath ) : chalk . dim ( '(not set)' ) } ` ,
161+ ) ;
162+ logger . info ( '' ) ;
163+ }
118164 const defaultConfig = getDefaultConfig ( ) ;
119165
120166 // Get all valid config keys
@@ -276,15 +322,8 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
276322 return ;
277323 }
278324
279- // Get the current config, create a new object without the specified key
280- const currentConfig = getConfig ( ) ;
281- const { [ argv . key ] : _ , ...newConfig } = currentConfig as Record <
282- string ,
283- any
284- > ;
285-
286- // Update the config file with the new object
287- updateConfig ( newConfig ) ;
325+ // Clear the specified key from the configuration at the current level
326+ clearConfigKey ( argv . key , configLevel ) ;
288327
289328 // Get the default value that will now be used
290329 const defaultValue =
@@ -297,13 +336,23 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
297336 // Determine where the new value is coming from
298337 const isDefaultAfterClear =
299338 JSON . stringify ( newValue ) === JSON . stringify ( defaultValue ) ;
339+
340+ // Get the actual config values at each level
341+ const globalConfig = getConfigAtLevel ( ConfigLevel . GLOBAL ) ;
342+ const projectConfig = getConfigAtLevel ( ConfigLevel . PROJECT ) ;
343+
344+ // Check if key exists AND has a non-default value in each level
300345 const afterClearInGlobal =
301346 ! isDefaultAfterClear &&
302- argv . key in getConfigAtLevel ( ConfigLevel . GLOBAL ) ;
347+ argv . key in globalConfig &&
348+ JSON . stringify ( globalConfig [ argv . key ] ) !== JSON . stringify ( defaultValue ) ;
349+
303350 const afterClearInProject =
304351 ! isDefaultAfterClear &&
305352 ! afterClearInGlobal &&
306- argv . key in getConfigAtLevel ( ConfigLevel . PROJECT ) ;
353+ argv . key in projectConfig &&
354+ JSON . stringify ( projectConfig [ argv . key ] ) !==
355+ JSON . stringify ( defaultValue ) ;
307356
308357 let sourceDisplay = '' ;
309358 if ( isDefaultAfterClear ) {
0 commit comments