@@ -16,12 +16,21 @@ import { initializeTracing, trace } from '../core/trace/index.js';
1616
1717// __filename and __dirname are provided by esbuild banner for ESM compatibility
1818
19+ interface ClaudeSMConfig {
20+ defaultWorktree: boolean ;
21+ defaultSandbox: boolean ;
22+ defaultChrome: boolean ;
23+ defaultTracing: boolean ;
24+ defaultRemote: boolean ;
25+ }
26+
1927interface ClaudeConfig {
2028 instanceId: string ;
2129 worktreePath ? : string ;
2230 useSandbox: boolean ;
2331 useChrome: boolean ;
2432 useWorktree: boolean ;
33+ useRemote: boolean ;
2534 contextEnabled: boolean ;
2635 branch ? : string ;
2736 task ? : string ;
@@ -30,20 +39,59 @@ interface ClaudeConfig {
3039 claudeBin ? : string ;
3140}
3241
42+ const DEFAULT_SM_CONFIG : ClaudeSMConfig = {
43+ defaultWorktree : false ,
44+ defaultSandbox : false ,
45+ defaultChrome : false ,
46+ defaultTracing : true ,
47+ defaultRemote : false ,
48+ } ;
49+
50+ function getConfigPath ( ) : string {
51+ return path . join ( os . homedir ( ) , '.stackmemory' , 'claude-sm.json' ) ;
52+ }
53+
54+ function loadSMConfig ( ) : ClaudeSMConfig {
55+ try {
56+ const configPath = getConfigPath ( ) ;
57+ if ( fs . existsSync ( configPath ) ) {
58+ const content = fs . readFileSync ( configPath , 'utf8' ) ;
59+ return { ...DEFAULT_SM_CONFIG , ...JSON . parse ( content ) } ;
60+ }
61+ } catch {
62+ // Ignore errors, use defaults
63+ }
64+ return { ...DEFAULT_SM_CONFIG } ;
65+ }
66+
67+ function saveSMConfig ( config : ClaudeSMConfig ) : void {
68+ const configPath = getConfigPath ( ) ;
69+ const dir = path . dirname ( configPath ) ;
70+ if ( ! fs . existsSync ( dir ) ) {
71+ fs . mkdirSync ( dir , { recursive : true } ) ;
72+ }
73+ fs . writeFileSync ( configPath , JSON . stringify ( config , null , 2 ) ) ;
74+ }
75+
3376class ClaudeSM {
3477 private config : ClaudeConfig ;
3578 private stackmemoryPath : string ;
3679 private worktreeScriptPath : string ;
3780 private claudeConfigDir : string ;
81+ private smConfig : ClaudeSMConfig ;
3882
3983 constructor ( ) {
84+ // Load persistent defaults
85+ this . smConfig = loadSMConfig ( ) ;
86+
4087 this . config = {
4188 instanceId : this . generateInstanceId ( ) ,
42- useSandbox : false ,
43- useChrome : false ,
44- useWorktree : false ,
89+ useSandbox : this . smConfig . defaultSandbox ,
90+ useChrome : this . smConfig . defaultChrome ,
91+ useWorktree : this . smConfig . defaultWorktree ,
92+ useRemote : this . smConfig . defaultRemote ,
4593 contextEnabled : true ,
46- tracingEnabled : true , // Enable tracing by default for claude-sm
94+ tracingEnabled : this . smConfig . defaultTracing ,
4795 verboseTracing : false ,
4896 } ;
4997
@@ -288,6 +336,17 @@ class ClaudeSM {
288336 case '-w' :
289337 this . config . useWorktree = true ;
290338 break ;
339+ case '--no-worktree' :
340+ case '-W' :
341+ this . config . useWorktree = false ;
342+ break ;
343+ case '--remote' :
344+ case '-r' :
345+ this . config . useRemote = true ;
346+ break ;
347+ case '--no-remote' :
348+ this . config . useRemote = false ;
349+ break ;
291350 case '--sandbox' :
292351 case '-s' :
293352 this . config . useSandbox = true ;
@@ -413,13 +472,21 @@ class ClaudeSM {
413472 if ( this . config . worktreePath ) {
414473 process . env [ 'CLAUDE_WORKTREE_PATH' ] = this . config . worktreePath ;
415474 }
475+ if ( this . config . useRemote ) {
476+ process . env [ 'CLAUDE_REMOTE' ] = '1' ;
477+ }
416478
417479 console . log ( chalk . gray ( `🤖 Instance ID: ${ this . config . instanceId } ` ) ) ;
418480 console . log ( chalk . gray ( `📁 Working in: ${ process . cwd ( ) } ` ) ) ;
419481
420482 if ( this . config . useSandbox ) {
421483 console . log ( chalk . yellow ( '🔒 Sandbox mode enabled' ) ) ;
422484 }
485+ if ( this . config . useRemote ) {
486+ console . log (
487+ chalk . cyan ( '📱 Remote mode: WhatsApp notifications for all questions' )
488+ ) ;
489+ }
423490 if ( this . config . useChrome ) {
424491 console . log ( chalk . yellow ( '🌐 Chrome automation enabled' ) ) ;
425492 }
@@ -529,8 +596,112 @@ class ClaudeSM {
529596program
530597 . name ( 'claude-sm' )
531598 . description ( 'Claude with StackMemory context and worktree isolation' )
532- . version ( '1.0.0' )
599+ . version ( '1.0.0' ) ;
600+
601+ // Config subcommand
602+ const configCmd = program
603+ . command ( 'config' )
604+ . description ( 'Manage claude-sm defaults' ) ;
605+
606+ configCmd
607+ . command ( 'show' )
608+ . description ( 'Show current default settings' )
609+ . action ( ( ) => {
610+ const config = loadSMConfig ( ) ;
611+ console . log ( chalk . blue ( 'claude-sm defaults:' ) ) ;
612+ console . log (
613+ ` defaultWorktree: ${ config . defaultWorktree ? chalk . green ( 'true' ) : chalk . gray ( 'false' ) } `
614+ ) ;
615+ console . log (
616+ ` defaultSandbox: ${ config . defaultSandbox ? chalk . green ( 'true' ) : chalk . gray ( 'false' ) } `
617+ ) ;
618+ console . log (
619+ ` defaultChrome: ${ config . defaultChrome ? chalk . green ( 'true' ) : chalk . gray ( 'false' ) } `
620+ ) ;
621+ console . log (
622+ ` defaultTracing: ${ config . defaultTracing ? chalk . green ( 'true' ) : chalk . gray ( 'false' ) } `
623+ ) ;
624+ console . log (
625+ ` defaultRemote: ${ config . defaultRemote ? chalk . green ( 'true' ) : chalk . gray ( 'false' ) } `
626+ ) ;
627+ console . log ( chalk . gray ( `\nConfig: ${ getConfigPath ( ) } ` ) ) ;
628+ } ) ;
629+
630+ configCmd
631+ . command ( 'set <key> <value>' )
632+ . description ( 'Set a default (e.g., set worktree true)' )
633+ . action ( ( key : string , value : string ) => {
634+ const config = loadSMConfig ( ) ;
635+ const boolValue = value === 'true' || value === '1' || value === 'on' ;
636+
637+ const keyMap : Record < string , keyof ClaudeSMConfig > = {
638+ worktree : 'defaultWorktree' ,
639+ sandbox : 'defaultSandbox' ,
640+ chrome : 'defaultChrome' ,
641+ tracing : 'defaultTracing' ,
642+ remote : 'defaultRemote' ,
643+ } ;
644+
645+ const configKey = keyMap [ key ] ;
646+ if ( ! configKey ) {
647+ console . log ( chalk . red ( `Unknown key: ${ key } ` ) ) ;
648+ console . log (
649+ chalk . gray ( 'Valid keys: worktree, sandbox, chrome, tracing, remote' )
650+ ) ;
651+ process . exit ( 1 ) ;
652+ }
653+
654+ config [ configKey ] = boolValue ;
655+ saveSMConfig ( config ) ;
656+ console . log ( chalk . green ( `Set ${ key } = ${ boolValue } ` ) ) ;
657+ } ) ;
658+
659+ configCmd
660+ . command ( 'worktree-on' )
661+ . description ( 'Enable worktree mode by default' )
662+ . action ( ( ) => {
663+ const config = loadSMConfig ( ) ;
664+ config . defaultWorktree = true ;
665+ saveSMConfig ( config ) ;
666+ console . log ( chalk . green ( 'Worktree mode enabled by default' ) ) ;
667+ } ) ;
668+
669+ configCmd
670+ . command ( 'worktree-off' )
671+ . description ( 'Disable worktree mode by default' )
672+ . action ( ( ) => {
673+ const config = loadSMConfig ( ) ;
674+ config . defaultWorktree = false ;
675+ saveSMConfig ( config ) ;
676+ console . log ( chalk . green ( 'Worktree mode disabled by default' ) ) ;
677+ } ) ;
678+
679+ configCmd
680+ . command ( 'remote-on' )
681+ . description ( 'Enable remote mode by default (WhatsApp for all questions)' )
682+ . action ( ( ) => {
683+ const config = loadSMConfig ( ) ;
684+ config . defaultRemote = true ;
685+ saveSMConfig ( config ) ;
686+ console . log ( chalk . green ( 'Remote mode enabled by default' ) ) ;
687+ } ) ;
688+
689+ configCmd
690+ . command ( 'remote-off' )
691+ . description ( 'Disable remote mode by default' )
692+ . action ( ( ) => {
693+ const config = loadSMConfig ( ) ;
694+ config . defaultRemote = false ;
695+ saveSMConfig ( config ) ;
696+ console . log ( chalk . green ( 'Remote mode disabled by default' ) ) ;
697+ } ) ;
698+
699+ // Main command (default action when no subcommand)
700+ program
533701 . option ( '-w, --worktree' , 'Create isolated worktree for this instance' )
702+ . option ( '-W, --no-worktree' , 'Disable worktree (override default)' )
703+ . option ( '-r, --remote' , 'Enable remote mode (WhatsApp for all questions)' )
704+ . option ( '--no-remote' , 'Disable remote mode (override default)' )
534705 . option ( '-s, --sandbox' , 'Enable sandbox mode (file/network restrictions)' )
535706 . option ( '-c, --chrome' , 'Enable Chrome automation' )
536707 . option ( '-a, --auto' , 'Automatically detect and apply best settings' )
0 commit comments