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' ;
@@ -19,6 +22,10 @@ export interface ConfigOptions extends SharedOptions {
1922 key ?: string ;
2023 value ?: string ;
2124 all ?: boolean ;
25+ global ?: boolean ;
26+ g ?: boolean ;
27+ verbose ?: boolean ;
28+ v ?: boolean ;
2229}
2330
2431export const command : CommandModule < SharedOptions , ConfigOptions > = {
@@ -45,6 +52,18 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
4552 type : 'boolean' ,
4653 default : false ,
4754 } )
55+ . option ( 'global' , {
56+ alias : 'g' ,
57+ describe : 'Use global configuration instead of project-level' ,
58+ type : 'boolean' ,
59+ default : false ,
60+ } )
61+ . option ( 'verbose' , {
62+ alias : 'v' ,
63+ describe : 'Show detailed information including config file paths' ,
64+ type : 'boolean' ,
65+ default : false ,
66+ } )
4867 . example ( '$0 config list' , 'List all configuration values' )
4968 . example (
5069 '$0 config get githubMode' ,
@@ -115,6 +134,35 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
115134 // Handle 'list' command
116135 if ( argv . command === 'list' ) {
117136 logger . info ( 'Current configuration:' ) ;
137+
138+ // Show config file locations
139+ const {
140+ getSettingsDir,
141+ getProjectSettingsDir,
142+ } = require ( '../settings/settings.js' ) ;
143+ const globalConfigPath = path . join ( getSettingsDir ( ) , 'config.json' ) ;
144+ const projectDir = getProjectSettingsDir ( ) ;
145+ const projectConfigPath = projectDir
146+ ? path . join ( projectDir , 'config.json' )
147+ : 'Not available' ;
148+
149+ logger . info ( `Global config file: ${ chalk . blue ( globalConfigPath ) } ` ) ;
150+ logger . info ( `Project config file: ${ chalk . blue ( projectConfigPath ) } ` ) ;
151+ logger . info ( '' ) ;
152+
153+ // Show config file paths in verbose mode
154+ if ( argv . verbose || argv . v ) {
155+ const { getProjectConfigFile } = await import ( '../settings/config.js' ) ;
156+ const { getSettingsDir } = await import ( '../settings/settings.js' ) ;
157+ const globalConfigPath = path . join ( getSettingsDir ( ) , 'config.json' ) ;
158+ const projectConfigPath = getProjectConfigFile ( ) ;
159+
160+ logger . info ( `Global config: ${ chalk . blue ( globalConfigPath ) } ` ) ;
161+ logger . info (
162+ `Project config: ${ projectConfigPath ? chalk . blue ( projectConfigPath ) : chalk . dim ( '(not set)' ) } ` ,
163+ ) ;
164+ logger . info ( '' ) ;
165+ }
118166 const defaultConfig = getDefaultConfig ( ) ;
119167
120168 // Get all valid config keys
@@ -276,15 +324,8 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
276324 return ;
277325 }
278326
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 ) ;
327+ // Clear the specified key from the configuration at the current level
328+ clearConfigKey ( argv . key , configLevel ) ;
288329
289330 // Get the default value that will now be used
290331 const defaultValue =
@@ -297,13 +338,23 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
297338 // Determine where the new value is coming from
298339 const isDefaultAfterClear =
299340 JSON . stringify ( newValue ) === JSON . stringify ( defaultValue ) ;
341+
342+ // Get the actual config values at each level
343+ const globalConfig = getConfigAtLevel ( ConfigLevel . GLOBAL ) ;
344+ const projectConfig = getConfigAtLevel ( ConfigLevel . PROJECT ) ;
345+
346+ // Check if key exists AND has a non-default value in each level
300347 const afterClearInGlobal =
301348 ! isDefaultAfterClear &&
302- argv . key in getConfigAtLevel ( ConfigLevel . GLOBAL ) ;
349+ argv . key in globalConfig &&
350+ JSON . stringify ( globalConfig [ argv . key ] ) !== JSON . stringify ( defaultValue ) ;
351+
303352 const afterClearInProject =
304353 ! isDefaultAfterClear &&
305354 ! afterClearInGlobal &&
306- argv . key in getConfigAtLevel ( ConfigLevel . PROJECT ) ;
355+ argv . key in projectConfig &&
356+ JSON . stringify ( projectConfig [ argv . key ] ) !==
357+ JSON . stringify ( defaultValue ) ;
307358
308359 let sourceDisplay = '' ;
309360 if ( isDefaultAfterClear ) {
0 commit comments