@@ -2,7 +2,11 @@ import * as fs from 'fs'
22
33import { cyan , green } from 'picocolors'
44
5- import { getAllTsFiles , getAgentsDirectory } from './agent-utils'
5+ import {
6+ getAllTsFiles ,
7+ getAgentsDirectory ,
8+ getUserAgentsDirectory ,
9+ } from './agent-utils'
610
711import type { CodebuffConfig } from '@codebuff/common/json-config/constants'
812
@@ -16,16 +20,24 @@ export async function loadLocalAgents({
1620} ) : Promise < typeof loadedAgents > {
1721 loadedAgents = { }
1822
19- const agentsDir = agentsPath ?? getAgentsDirectory ( )
23+ // Collect agents from both directories
24+ const agentsDirs = agentsPath
25+ ? [ agentsPath ]
26+ : [ getAgentsDirectory ( ) , getUserAgentsDirectory ( ) ]
2027
21- if ( ! fs . existsSync ( agentsDir ) ) {
28+ const allTsFiles : string [ ] = [ ]
29+ for ( const dir of agentsDirs ) {
30+ if ( fs . existsSync ( dir ) ) {
31+ allTsFiles . push ( ...getAllTsFiles ( dir ) )
32+ }
33+ }
34+
35+ if ( allTsFiles . length === 0 ) {
2236 return loadedAgents
2337 }
2438
2539 try {
26- const tsFiles = getAllTsFiles ( agentsDir )
27-
28- for ( const fullPath of tsFiles ) {
40+ for ( const fullPath of allTsFiles ) {
2941 let agentDefinition : any
3042 let agentModule : any
3143 try {
@@ -111,14 +123,15 @@ export function displayLoadedAgents(codebuffConfig: CodebuffConfig) {
111123 const loadedAgentNames = Object . values ( getLoadedAgentNames ( ) )
112124 // Calculate terminal width and format agents in columns
113125 const terminalWidth = process . stdout . columns || 80
114- const columnWidth = Math . max ( ...loadedAgentNames . map ( name => name . length ) ) + 2 // Column width based on longest name + padding
126+ const columnWidth =
127+ Math . max ( ...loadedAgentNames . map ( ( name ) => name . length ) ) + 2 // Column width based on longest name + padding
115128 const columnsPerRow = Math . max ( 1 , Math . floor ( terminalWidth / columnWidth ) )
116-
129+
117130 const formattedLines : string [ ] = [ ]
118131 for ( let i = 0 ; i < loadedAgentNames . length ; i += columnsPerRow ) {
119132 const rowAgents = loadedAgentNames . slice ( i , i + columnsPerRow )
120133 const formattedRow = rowAgents
121- . map ( name => cyan ( name . padEnd ( columnWidth ) ) )
134+ . map ( ( name ) => cyan ( name . padEnd ( columnWidth ) ) )
122135 . join ( '' )
123136 formattedLines . push ( formattedRow )
124137 }
0 commit comments