1
+ import * as path from 'path' ;
2
+
1
3
import chalk from 'chalk' ;
2
4
import { Logger } from 'mycoder-agent' ;
3
5
@@ -8,6 +10,7 @@ import {
8
10
updateConfig ,
9
11
getConfigAtLevel ,
10
12
clearConfigAtLevel ,
13
+ clearConfigKey ,
11
14
ConfigLevel ,
12
15
} from '../settings/config.js' ;
13
16
import { nameToLogIndex } from '../utils/nameToLogIndex.js' ;
@@ -19,6 +22,10 @@ export interface ConfigOptions extends SharedOptions {
19
22
key ?: string ;
20
23
value ?: string ;
21
24
all ?: boolean ;
25
+ global ?: boolean ;
26
+ g ?: boolean ;
27
+ verbose ?: boolean ;
28
+ v ?: boolean ;
22
29
}
23
30
24
31
export const command : CommandModule < SharedOptions , ConfigOptions > = {
@@ -45,6 +52,18 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
45
52
type : 'boolean' ,
46
53
default : false ,
47
54
} )
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
+ } )
48
67
. example ( '$0 config list' , 'List all configuration values' )
49
68
. example (
50
69
'$0 config get githubMode' ,
@@ -115,6 +134,35 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
115
134
// Handle 'list' command
116
135
if ( argv . command === 'list' ) {
117
136
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
+ }
118
166
const defaultConfig = getDefaultConfig ( ) ;
119
167
120
168
// Get all valid config keys
@@ -276,15 +324,8 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
276
324
return ;
277
325
}
278
326
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 ) ;
288
329
289
330
// Get the default value that will now be used
290
331
const defaultValue =
@@ -297,13 +338,23 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
297
338
// Determine where the new value is coming from
298
339
const isDefaultAfterClear =
299
340
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
300
347
const afterClearInGlobal =
301
348
! isDefaultAfterClear &&
302
- argv . key in getConfigAtLevel ( ConfigLevel . GLOBAL ) ;
349
+ argv . key in globalConfig &&
350
+ JSON . stringify ( globalConfig [ argv . key ] ) !== JSON . stringify ( defaultValue ) ;
351
+
303
352
const afterClearInProject =
304
353
! isDefaultAfterClear &&
305
354
! afterClearInGlobal &&
306
- argv . key in getConfigAtLevel ( ConfigLevel . PROJECT ) ;
355
+ argv . key in projectConfig &&
356
+ JSON . stringify ( projectConfig [ argv . key ] ) !==
357
+ JSON . stringify ( defaultValue ) ;
307
358
308
359
let sourceDisplay = '' ;
309
360
if ( isDefaultAfterClear ) {
0 commit comments