11import { getSettingsManager } from "../utils/settings-manager" ;
22import { SuperAgent } from "../agent/super-agent" ;
3+ import { runSafeCommand } from "../utils/exec" ;
34import { SuperAgentPlugin } from "./types" ;
45import { SuperAgentTool } from "../types" ;
5- import { exec } from "child_process" ;
6- import { promisify } from "util" ;
6+ import execAsync from "node:process" ;
77import * as path from "path" ;
88import fs from "fs-extra" ;
99
10- const execAsync = promisify ( exec ) ;
11-
1210export class PluginManager {
1311 private static instance : PluginManager ;
1412 private plugins : Map < string , SuperAgentPlugin > = new Map ( ) ;
@@ -156,13 +154,15 @@ export class PluginManager {
156154 `Repository already cloned at ${ targetDir } . Pulling latest...` ,
157155 ) ;
158156 try {
159- await execAsync ( `cd "${ targetDir } " && git pull` ) ;
157+ await runSafeCommand ( "git" , [ "pull" ] , {
158+ cwd : targetDir ,
159+ } ) ;
160160 } catch ( error ) {
161161 console . warn ( `Failed to pull updates: ${ error } ` ) ;
162162 }
163163 } else {
164164 // Clone the repository
165- await execAsync ( ` git clone " ${ gitUrl } " " ${ targetDir } "` ) ;
165+ await runSafeCommand ( " git" , [ " clone" , gitUrl , targetDir ] ) ;
166166 }
167167
168168 // Try to build if package.json exists
@@ -174,20 +174,18 @@ export class PluginManager {
174174 const hasBun = await fs . pathExists ( path . join ( targetDir , "bun.lockb" ) ) ;
175175 const hasYarn = await fs . pathExists ( path . join ( targetDir , "yarn.lock" ) ) ;
176176
177- const installCmd = hasBun
178- ? "bun install"
179- : hasYarn
180- ? "yarn install"
181- : "npm install" ;
182- await execAsync ( `cd "${ targetDir } " && ${ installCmd } ` ) ;
177+ const installCmd = hasBun ? "bun" : hasYarn ? "yarn" : "npm" ;
178+ const installArgs = [ "install" ] ;
179+ await runSafeCommand ( installCmd , installArgs , {
180+ cwd : targetDir ,
181+ } ) ;
183182
184183 console . log ( "🔨 Building plugin..." ) ;
185- const buildCmd = hasBun
186- ? "bun run build"
187- : hasYarn
188- ? "yarn build"
189- : "npm run build" ;
190- await execAsync ( `cd "${ targetDir } " && ${ buildCmd } ` ) ;
184+ const buildCmd = hasBun ? "bun" : hasYarn ? "yarn" : "npm" ;
185+ const buildArgs = [ "run" , "build" ] ;
186+ await runSafeCommand ( buildCmd , buildArgs , {
187+ cwd : targetDir ,
188+ } ) ;
191189 } catch ( error : any ) {
192190 console . warn ( `Build failed: ${ error . message } ` ) ;
193191 }
@@ -222,20 +220,18 @@ export class PluginManager {
222220 path . join ( absolutePath , "yarn.lock" ) ,
223221 ) ;
224222
225- const installCmd = hasBun
226- ? "bun install"
227- : hasYarn
228- ? "yarn install"
229- : "npm install" ;
230- await execAsync ( `cd "${ absolutePath } " && ${ installCmd } ` ) ;
223+ const installCmd = hasBun ? "bun" : hasYarn ? "yarn" : "npm" ;
224+ const installArgs = [ "install" ] ;
225+ await runSafeCommand ( installCmd , installArgs , {
226+ cwd : absolutePath ,
227+ } ) ;
231228
232229 console . log ( "🔨 Building plugin..." ) ;
233- const buildCmd = hasBun
234- ? "bun run build"
235- : hasYarn
236- ? "yarn build"
237- : "npm run build" ;
238- await execAsync ( `cd "${ absolutePath } " && ${ buildCmd } ` ) ;
230+ const buildCmd = hasBun ? "bun" : hasYarn ? "yarn" : "npm" ;
231+ const buildArgs = [ "run" , "build" ] ;
232+ await runSafeCommand ( buildCmd , buildArgs , {
233+ cwd : absolutePath ,
234+ } ) ;
239235 } catch ( error : any ) {
240236 console . warn ( `Build failed: ${ error . message } ` ) ;
241237 }
0 commit comments