@@ -2,13 +2,17 @@ import chalk from 'chalk';
22import { Logger } from 'mycoder-agent' ;
33
44import { SharedOptions } from '../options.js' ;
5- import { getConfig , updateConfig } from '../settings/config.js' ;
5+ import {
6+ getConfig ,
7+ getDefaultConfig ,
8+ updateConfig ,
9+ } from '../settings/config.js' ;
610import { nameToLogIndex } from '../utils/nameToLogIndex.js' ;
711
812import type { CommandModule , ArgumentsCamelCase } from 'yargs' ;
913
1014export interface ConfigOptions extends SharedOptions {
11- command : 'get' | 'set' | 'list' ;
15+ command : 'get' | 'set' | 'list' | 'clear' ;
1216 key ?: string ;
1317 value ?: string ;
1418}
@@ -20,7 +24,7 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
2024 return yargs
2125 . positional ( 'command' , {
2226 describe : 'Config command to run' ,
23- choices : [ 'get' , 'set' , 'list' ] ,
27+ choices : [ 'get' , 'set' , 'list' , 'clear' ] ,
2428 type : 'string' ,
2529 demandOption : true ,
2630 } )
@@ -37,7 +41,11 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
3741 '$0 config get githubMode' ,
3842 'Get the value of githubMode setting' ,
3943 )
40- . example ( '$0 config set githubMode true' , 'Enable GitHub mode' ) as any ; // eslint-disable-line @typescript-eslint/no-explicit-any
44+ . example ( '$0 config set githubMode true' , 'Enable GitHub mode' )
45+ . example (
46+ '$0 config clear customPrompt' ,
47+ 'Reset customPrompt to default value' ,
48+ ) as any ; // eslint-disable-line @typescript-eslint/no-explicit-any
4149 } ,
4250 handler : async ( argv : ArgumentsCamelCase < ConfigOptions > ) => {
4351 const logger = new Logger ( {
@@ -50,8 +58,16 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
5058 // Handle 'list' command
5159 if ( argv . command === 'list' ) {
5260 logger . info ( 'Current configuration:' ) ;
61+ const defaultConfig = getDefaultConfig ( ) ;
5362 Object . entries ( config ) . forEach ( ( [ key , value ] ) => {
54- logger . info ( ` ${ key } : ${ chalk . green ( value ) } ` ) ;
63+ const isDefault =
64+ JSON . stringify ( value ) ===
65+ JSON . stringify ( defaultConfig [ key as keyof typeof defaultConfig ] ) ;
66+ const valueDisplay = chalk . green ( value ) ;
67+ const statusIndicator = isDefault
68+ ? chalk . dim ( ' (default)' )
69+ : chalk . blue ( ' (custom)' ) ;
70+ logger . info ( ` ${ key } : ${ valueDisplay } ${ statusIndicator } ` ) ;
5571 } ) ;
5672 return ;
5773 }
@@ -116,8 +132,51 @@ export const command: CommandModule<SharedOptions, ConfigOptions> = {
116132 return ;
117133 }
118134
135+ // Handle 'clear' command
136+ if ( argv . command === 'clear' ) {
137+ if ( ! argv . key ) {
138+ logger . error ( 'Key is required for clear command' ) ;
139+ return ;
140+ }
141+
142+ const defaultConfig = getDefaultConfig ( ) ;
143+
144+ // Check if the key exists in the config
145+ if ( ! ( argv . key in config ) ) {
146+ logger . error ( `Configuration key '${ argv . key } ' not found` ) ;
147+ return ;
148+ }
149+
150+ // Check if the key exists in the default config
151+ if ( ! ( argv . key in defaultConfig ) ) {
152+ logger . error (
153+ `Configuration key '${ argv . key } ' does not have a default value` ,
154+ ) ;
155+ return ;
156+ }
157+
158+ // Get the current config, create a new object without the specified key
159+ const currentConfig = getConfig ( ) ;
160+ const { [ argv . key ] : _ , ...newConfig } = currentConfig as Record <
161+ string ,
162+ any
163+ > ;
164+
165+ // Update the config file with the new object
166+ updateConfig ( newConfig ) ;
167+
168+ // Get the default value that will now be used
169+ const defaultValue =
170+ defaultConfig [ argv . key as keyof typeof defaultConfig ] ;
171+
172+ logger . info (
173+ `Cleared ${ argv . key } , now using default value: ${ chalk . green ( defaultValue ) } ` ,
174+ ) ;
175+ return ;
176+ }
177+
119178 // If command not recognized
120179 logger . error ( `Unknown config command: ${ argv . command } ` ) ;
121- logger . info ( 'Available commands: get, set, list' ) ;
180+ logger . info ( 'Available commands: get, set, list, clear ' ) ;
122181 } ,
123182} ;
0 commit comments