1+ import { execSync } from 'child_process'
12import {
23 existsSync ,
34 mkdirSync ,
@@ -6,48 +7,22 @@ import {
67 readdirSync ,
78 readFileSync ,
89} from 'fs'
9- import path from 'path'
1010import os from 'os'
11- import { execSync } from 'child_process '
11+ import path from 'path '
1212
1313import { yellow , green , red , cyan , bold } from 'picocolors'
1414
1515import { CONFIG_DIR } from './credentials'
1616import { createAuthHeaders } from './utils/auth-headers'
1717import { logger } from './utils/logger'
1818
19- const SHIMS_DIR = path . join ( CONFIG_DIR , 'bin' )
20- const WINDOWS_SHIMS_DIR = path . join (
21- os . homedir ( ) ,
22- 'AppData' ,
23- 'Local' ,
24- 'Manicode' ,
25- 'bin' ,
26- )
19+ const SHIMS_DIR = path . join ( CONFIG_DIR , 'shims' )
2720
2821/**
2922 * Get the appropriate shims directory for the current platform
3023 */
3124export function getShimsDirectory ( ) : string {
32- return process . platform === 'win32' ? WINDOWS_SHIMS_DIR : SHIMS_DIR
33- }
34-
35- /**
36- * Get the absolute path to the codebuff executable
37- */
38- function getCodebuffPath ( ) : string {
39- try {
40- if ( process . platform === 'win32' ) {
41- return execSync ( 'where codebuff' , { encoding : 'utf8' } )
42- . trim ( )
43- . split ( '\n' ) [ 0 ]
44- } else {
45- return execSync ( 'which codebuff' , { encoding : 'utf8' } ) . trim ( )
46- }
47- } catch ( error ) {
48- // Fallback: assume codebuff is in PATH
49- return 'codebuff'
50- }
25+ return SHIMS_DIR
5126}
5227
5328/**
@@ -93,30 +68,22 @@ function validateCommandName(name: string): boolean {
9368/**
9469 * Generate shim content for Unix shells (bash/zsh)
9570 */
96- function generateUnixShim (
97- commandName : string ,
98- agentId : string ,
99- codebuffPath : string ,
100- ) : string {
71+ function generateUnixShim ( commandName : string , agentId : string ) : string {
10172 return `#!/bin/sh
10273# Auto-generated Codebuff shim for '${ commandName } ' → ${ agentId }
10374# Do not edit manually - use 'codebuff shims' commands
104- exec " ${ codebuffPath } " --agent "${ agentId } " "$@"
75+ exec codebuff --agent "${ agentId } " "$@"
10576`
10677}
10778
10879/**
10980 * Generate shim content for Windows CMD
11081 */
111- function generateWindowsShim (
112- commandName : string ,
113- agentId : string ,
114- codebuffPath : string ,
115- ) : string {
82+ function generateWindowsShim ( commandName : string , agentId : string ) : string {
11683 return `@echo off
11784REM Auto-generated Codebuff shim for '${ commandName } ' → ${ agentId }
11885REM Do not edit manually - use 'codebuff shims' commands
119- " ${ codebuffPath } " --agent "${ agentId } " %*
86+ codebuff --agent "${ agentId } " %*
12087`
12188}
12289
@@ -126,7 +93,6 @@ REM Do not edit manually - use 'codebuff shims' commands
12693function createShim (
12794 agentId : string ,
12895 commandName : string ,
129- codebuffPath : string ,
13096 force : boolean ,
13197) : void {
13298 if ( ! validateAgentId ( agentId ) ) {
@@ -163,11 +129,11 @@ function createShim(
163129
164130 if ( process . platform === 'win32' ) {
165131 const shimPath = path . join ( shimsDir , `${ commandName } .cmd` )
166- const content = generateWindowsShim ( commandName , agentId , codebuffPath )
132+ const content = generateWindowsShim ( commandName , agentId )
167133 writeFileSync ( shimPath , content , 'utf8' )
168134 } else {
169135 const shimPath = path . join ( shimsDir , commandName )
170- const content = generateUnixShim ( commandName , agentId , codebuffPath )
136+ const content = generateUnixShim ( commandName , agentId )
171137 writeFileSync ( shimPath , content , 'utf8' )
172138 // Make executable
173139 execSync ( `chmod +x "${ shimPath } "` )
@@ -213,7 +179,6 @@ export function installShims(
213179 agentSpecs : string [ ] ,
214180 options : { force ?: boolean } = { } ,
215181) : void {
216- const codebuffPath = getCodebuffPath ( )
217182 const { force = false } = options
218183
219184 if ( ! agentSpecs || agentSpecs . length === 0 ) {
@@ -243,7 +208,7 @@ export function installShims(
243208
244209 const commandName = customCommand || defaultCommandName
245210
246- createShim ( agentId , commandName , codebuffPath , force )
211+ createShim ( agentId , commandName , force )
247212 console . log ( green ( `✓ ${ commandName } → ${ agentId } ` ) )
248213 installed ++
249214 } catch ( error ) {
@@ -439,13 +404,12 @@ export function updateShims(commandNames?: string[]): void {
439404 return
440405 }
441406
442- const codebuffPath = getCodebuffPath ( )
443407 let updated = 0
444408 let errors = 0
445409
446410 for ( const { commandName, agentId } of targetShims ) {
447411 try {
448- createShim ( agentId , commandName , codebuffPath , true )
412+ createShim ( agentId , commandName , true )
449413 console . log ( green ( `✓ Updated ${ commandName } → ${ agentId } ` ) )
450414 updated ++
451415 } catch ( error ) {
@@ -867,7 +831,6 @@ export async function upgradeShims(): Promise<void> {
867831 ) ,
868832 )
869833
870- const codebuffPath = getCodebuffPath ( )
871834 let upgraded = 0
872835 let upToDate = 0
873836 let errors = 0
@@ -905,7 +868,7 @@ export async function upgradeShims(): Promise<void> {
905868
906869 // Upgrade the shim
907870 const newAgentId = `${ publisherId } /${ agentName } @${ latestVersion } `
908- createShim ( newAgentId , commandName , codebuffPath , true )
871+ createShim ( newAgentId , commandName , true )
909872 console . log (
910873 cyan ( `↗ ${ commandName } : ${ currentVersion } → ${ latestVersion } ` ) ,
911874 )
0 commit comments