@@ -264,25 +264,47 @@ export const loadLocalAgents = (currentAgentMode?: AgentMode): LocalAgentInfo[]
264264 * Bundled agents are compiled into the CLI binary at build time.
265265 * User agents from .agents/ are loaded via SDK at startup and cached.
266266 * User agents can override bundled agents with the same ID.
267+ *
268+ * Additionally, all user agent IDs are automatically added to the spawnableAgents
269+ * of any base agent (agents with IDs starting with 'base'), so users can spawn
270+ * their custom agents without needing to modify the base agent definition.
267271 */
268272export const loadAgentDefinitions = ( ) : AgentDefinition [ ] => {
269273 // Start with bundled agents - these are the default Codebuff agents
270274 const bundledAgents = getBundledAgents ( )
271- const definitions : AgentDefinition [ ] = Object . values ( bundledAgents )
275+ const definitions : AgentDefinition [ ] = Object . values ( bundledAgents ) . map ( def => ( { ... def } ) )
272276 const bundledIds = new Set ( Object . keys ( bundledAgents ) )
273277
274278 // Get user agents from the SDK-loaded cache
275279 const userAgentDefs = getUserAgentDefinitions ( )
280+ const userAgentIds = userAgentDefs . map ( def => def . id )
276281
277282 for ( const agentDef of userAgentDefs ) {
278283 // User agents override bundled agents with the same ID
279284 if ( bundledIds . has ( agentDef . id ) ) {
280285 const idx = definitions . findIndex ( d => d . id === agentDef . id )
281286 if ( idx !== - 1 ) {
282- definitions [ idx ] = agentDef
287+ definitions [ idx ] = { ... agentDef }
283288 }
284289 } else {
285- definitions . push ( agentDef )
290+ definitions . push ( { ...agentDef } )
291+ }
292+ }
293+
294+ // Auto-add user agent IDs to spawnableAgents of base agents
295+ // This allows users to spawn their custom agents without needing to
296+ // explicitly add them to the base agent's spawnableAgents list
297+ if ( userAgentIds . length > 0 ) {
298+ for ( const def of definitions ) {
299+ // Consider any agent with an ID starting with 'base' as a base agent
300+ if ( def . id . startsWith ( 'base' ) && def . spawnableAgents ) {
301+ const existingSpawnable = new Set ( def . spawnableAgents )
302+ for ( const userAgentId of userAgentIds ) {
303+ if ( ! existingSpawnable . has ( userAgentId ) ) {
304+ def . spawnableAgents = [ ...def . spawnableAgents , userAgentId ]
305+ }
306+ }
307+ }
286308 }
287309 }
288310
0 commit comments