@@ -85,6 +85,39 @@ function buildCliInstallCommands(ctx) {
8585 return envelope
8686 }
8787
88+ function copyRuntimeScriptDeps ( { targetRoot, shownRoot, force, dryRun, log, inlineLog = log } ) {
89+ const counts = { added : 0 , updated : 0 , skipped : 0 }
90+ for ( const relRaw of CLAUDE_MCP_RUNTIME_SCRIPT_DEPS ) {
91+ const rel = String ( relRaw || '' ) . replace ( / \\ / g, '/' )
92+ if ( ! rel ) continue
93+ const srcFile = path . join ( PKG_ROOT , ...rel . split ( '/' ) )
94+ if ( ! fs . existsSync ( srcFile ) ) {
95+ inlineLog ( c . yellow ( ` ⚠ missing project runtime dep source: ${ rel } ` ) )
96+ continue
97+ }
98+ const destFile = path . join ( targetRoot , ...rel . split ( '/' ) )
99+ const existed = fs . existsSync ( destFile )
100+ const shown = `${ shownRoot } /${ rel } `
101+ if ( existed && filesContentEqual ( srcFile , destFile ) ) {
102+ counts . skipped ++
103+ log ( c . dim ( ` ~ ${ shown } ` ) )
104+ continue
105+ }
106+ if ( existed && ! force ) {
107+ counts . skipped ++
108+ log ( c . dim ( ` ~ ${ shown } (outdated; use --force)` ) )
109+ continue
110+ }
111+ if ( ! dryRun ) {
112+ fs . mkdirSync ( path . dirname ( destFile ) , { recursive : true } )
113+ fs . copyFileSync ( srcFile , destFile )
114+ }
115+ if ( existed ) { counts . updated ++ ; log ( c . yellow ( ` ↺ ${ shown } ` ) ) }
116+ else { counts . added ++ ; log ( c . green ( ` ✓ ${ shown } ` ) ) }
117+ }
118+ return counts
119+ }
120+
88121 function cmdInitWorkspaceRuntime ( argv = [ ] , { refresh = false } = { } ) {
89122 const values = Array . isArray ( argv ) ? argv : [ ]
90123 const json = values . includes ( '--json' )
@@ -620,35 +653,10 @@ function buildCliInstallCommands(ctx) {
620653 }
621654 }
622655
623- // 2b. MCP runtime script deps: copy scripts/lib helpers for Claude MCP (mcp/*.js relative require path)
624- for ( const relRaw of CLAUDE_MCP_RUNTIME_SCRIPT_DEPS ) {
625- const rel = String ( relRaw || '' ) . replace ( / \\ / g, '/' )
626- if ( ! rel ) continue
627- const srcFile = path . join ( PKG_ROOT , ...rel . split ( '/' ) )
628- if ( ! fs . existsSync ( srcFile ) ) {
629- inlineLog ( c . yellow ( ` ⚠ missing MCP runtime dep source: ${ rel } ` ) )
630- continue
631- }
632- const destFile = path . join ( clDir , ...rel . split ( '/' ) )
633- const existed = fs . existsSync ( destFile )
634- const shown = `.claude/${ rel } `
635-
636- if ( existed && filesContentEqual ( srcFile , destFile ) ) {
637- skipped ++
638- log ( c . dim ( ` ~ ${ shown } ` ) )
639- continue
640- }
641- if ( existed && ! force ) {
642- skipped ++
643- log ( c . dim ( ` ~ ${ shown } (outdated; use --force)` ) )
644- continue
645- }
646- if ( ! dryRun ) {
647- fs . mkdirSync ( path . dirname ( destFile ) , { recursive : true } )
648- fs . copyFileSync ( srcFile , destFile )
649- }
650- if ( existed ) { updated ++ ; log ( c . yellow ( ` ↺ ${ shown } ` ) ) }
651- else { added ++ ; log ( c . green ( ` ✓ ${ shown } ` ) ) }
656+ // 2b. Project runtime script deps for Claude hooks and shared MCP.
657+ {
658+ const counts = copyRuntimeScriptDeps ( { targetRoot : clDir , shownRoot : '.claude' , force, dryRun, log, inlineLog } )
659+ added += counts . added ; updated += counts . updated ; skipped += counts . skipped
652660 }
653661
654662 // 3. Write / merge .claude/settings.json
@@ -832,6 +840,11 @@ function buildCliInstallCommands(ctx) {
832840 }
833841 }
834842
843+ {
844+ const counts = copyRuntimeScriptDeps ( { targetRoot : path . join ( cwd , '.codex' ) , shownRoot : '.codex' , force, dryRun, log, inlineLog } )
845+ added += counts . added ; updated += counts . updated ; skipped += counts . skipped
846+ }
847+
835848 // Deploy shared MCP runtime under .claude/mcp (reused by Claude + Codex)
836849 {
837850 const mcpSrc = path . join ( PKG_ROOT , 'mcp' )
@@ -860,31 +873,8 @@ function buildCliInstallCommands(ctx) {
860873 else { added ++ ; log ( c . green ( ` ✓ ${ shown } ` ) ) }
861874 }
862875 }
863- for ( const relRaw of CLAUDE_MCP_RUNTIME_SCRIPT_DEPS ) {
864- const rel = String ( relRaw || '' ) . replace ( / \\ / g, '/' )
865- if ( ! rel ) continue
866- const srcFile = path . join ( PKG_ROOT , ...rel . split ( '/' ) )
867- if ( ! fs . existsSync ( srcFile ) ) continue
868- const destFile = path . join ( cwd , '.claude' , ...rel . split ( '/' ) )
869- const existed = fs . existsSync ( destFile )
870- const shown = `.claude/${ rel } `
871- if ( existed && filesContentEqual ( srcFile , destFile ) ) {
872- skipped ++
873- log ( c . dim ( ` ~ ${ shown } ` ) )
874- continue
875- }
876- if ( existed && ! force ) {
877- skipped ++
878- log ( c . dim ( ` ~ ${ shown } (outdated; use --force)` ) )
879- continue
880- }
881- if ( ! dryRun ) {
882- fs . mkdirSync ( path . dirname ( destFile ) , { recursive : true } )
883- fs . copyFileSync ( srcFile , destFile )
884- }
885- if ( existed ) { updated ++ ; log ( c . yellow ( ` ↺ ${ shown } ` ) ) }
886- else { added ++ ; log ( c . green ( ` ✓ ${ shown } ` ) ) }
887- }
876+ const counts = copyRuntimeScriptDeps ( { targetRoot : path . join ( cwd , '.claude' ) , shownRoot : '.claude' , force, dryRun, log, inlineLog } )
877+ added += counts . added ; updated += counts . updated ; skipped += counts . skipped
888878 }
889879
890880 // Merge Codex config.toml MCP servers (managed block; fail-closed; does not wipe user keys)
0 commit comments