MCPcopy
hub / github.com/davepoon/buildwithclaude / addSubagent

Function addSubagent

packages/bwc-cli/src/commands/add.ts:126–188  ·  view source on GitHub ↗
(
  name: string, 
  configManager: ConfigManager, 
  registryClient: RegistryClient,
  forceUserLevel: boolean = false,
  forceProjectLevel: boolean = false
)

Source from the content-addressed store, hash-verified

124}
125
126async function addSubagent(
127 name: string,
128 configManager: ConfigManager,
129 registryClient: RegistryClient,
130 forceUserLevel: boolean = false,
131 forceProjectLevel: boolean = false
132): Promise<void> {
133 const spinner = logger.spinner(`Fetching subagent: ${name}`)
134
135 try {
136 const subagent = await registryClient.findSubagent(name)
137
138 if (!subagent) {
139 spinner.fail(`Subagent "${name}" not found`)
140 return
141 }
142
143 spinner.text = `Downloading ${subagent.name}...`
144
145 const content = await registryClient.fetchFileContent(subagent.file)
146 const subagentsPath = await configManager.getSubagentsPath()
147 const filePath = path.join(subagentsPath, `${subagent.name}.md`)
148
149 // Check if file already exists
150 const { fileExists } = await import('../utils/files.js')
151 if (await fileExists(filePath)) {
152 spinner.stop()
153
154 const { action } = await inquirer.prompt([
155 {
156 type: 'list',
157 name: 'action',
158 message: `Subagent "${subagent.name}" already exists. What would you like to do?`,
159 choices: [
160 { name: 'Overwrite - Replace the existing file with the new one', value: 'overwrite' },
161 { name: 'Skip - Skip this item and continue with other installations', value: 'skip' },
162 { name: 'Abort - Stop the entire installation process', value: 'abort' }
163 ]
164 }
165 ])
166
167 if (action === 'skip') {
168 logger.info(`Skipped subagent: ${subagent.name}`)
169 return
170 } else if (action === 'abort') {
171 logger.info('Installation aborted')
172 process.exit(0)
173 }
174
175 spinner.start(`Installing ${subagent.name}...`)
176 }
177
178 await writeFile(filePath, content)
179 await configManager.addInstalledSubagent(subagent.name)
180
181 spinner.succeed(`Successfully installed subagent: ${subagent.name}`)
182 logger.info(`Location: ${filePath}`)
183 logger.info(`Tools: ${subagent.tools.join(', ')}`)

Callers 2

createAddCommandFunction · 0.85
interactiveAddSubagentFunction · 0.85

Calls 6

writeFileFunction · 0.85
findSubagentMethod · 0.80
fetchFileContentMethod · 0.80
getSubagentsPathMethod · 0.80
addInstalledSubagentMethod · 0.80
fileExistsFunction · 0.50

Tested by

no test coverage detected