Skip to content

Commit 66d566e

Browse files
committed
fix(agents): show all agents in /agents submenu
1 parent dd835d6 commit 66d566e

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

npm-app/src/cli-handlers/agents.ts

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
getLoadedAgentNames,
1414
loadedAgents,
1515
} from '../agents/load-agents'
16-
import { CLI } from '../cli'
16+
import { getAllTsFiles } from '../agents/agent-utils'
17+
import { CLI, getLocalAgentInfo } from '../cli'
1718
import { createExampleAgentFiles } from './init-agents'
1819
import { getProjectRoot } from '../project-files'
1920
import { Spinner } from '../utils/spinner'
@@ -54,8 +55,8 @@ export async function enterAgentsBuffer(rl: any, onExit: () => void) {
5455
return
5556
}
5657

57-
// Load local agents
58-
await loadLocalAgents({ verbose: false })
58+
// Load local agents using the same logic as CLI startup
59+
await getLocalAgentInfo() // This updates the cache properly
5960
const localAgents = getLoadedAgentNames()
6061

6162
// Build management actions section with header
@@ -76,29 +77,51 @@ export async function enterAgentsBuffer(rl: any, onExit: () => void) {
7677
},
7778
]
7879

79-
// Get custom agent files for display purposes
80-
const agentsDir = path.join(getProjectRoot(), AGENT_TEMPLATES_DIR)
81-
let customAgentFiles: string[] = []
82-
if (fs.existsSync(agentsDir)) {
83-
const files = fs.readdirSync(agentsDir)
84-
customAgentFiles = filterCustomAgentFiles(files)
85-
}
86-
8780
// Build agent list starting with management actions
8881
agentList = [...actions]
8982

90-
// Collect custom agents from .agents/templates
91-
const agentEntries = customAgentFiles.map((file) => {
92-
const agentId = extractAgentIdFromFileName(file)
93-
const filePath = path.join(agentsDir, file)
83+
const agentsDir = path.join(getProjectRoot(), AGENT_TEMPLATES_DIR)
84+
85+
const allAgentFiles = fs.existsSync(agentsDir) ? getAllTsFiles(agentsDir) : []
86+
87+
const agentEntries = Object.entries(loadedAgents).map(([agentId, def]) => {
88+
// Find the file path for this agent by looking for files that match the agent ID
89+
const matchingPath = allAgentFiles.find((filePath) => {
90+
const relativePath = path.relative(agentsDir, filePath).replace('.ts', '')
91+
92+
return (
93+
relativePath === agentId ||
94+
path.basename(filePath, '.ts').endsWith(agentId)
95+
)
96+
})
97+
9498
let mtime = 0
95-
try {
96-
mtime = fs.statSync(filePath).mtimeMs
97-
} catch {}
98-
const def = (loadedAgents as any)[agentId]
99-
return { file, agentId, filePath, mtime, def }
99+
let filePath = ''
100+
if (matchingPath) {
101+
filePath = matchingPath
102+
try {
103+
mtime = fs.statSync(matchingPath).mtimeMs
104+
} catch {}
105+
}
106+
107+
return {
108+
file: matchingPath
109+
? path.relative(agentsDir, matchingPath)
110+
: `${agentId}.ts`,
111+
agentId,
112+
filePath,
113+
mtime,
114+
def,
115+
}
100116
})
101117

118+
// Create agent description with file location
119+
const createAgentDescription = (entry: any) => {
120+
return entry.def?.description
121+
? `${entry.def.description}`
122+
: `Custom user-defined agent`
123+
}
124+
102125
const validAgents = agentEntries
103126
.filter((e) => e.def && e.def.id && e.def.model)
104127
.sort((a, b) => b.mtime - a.mtime)
@@ -121,10 +144,12 @@ export async function enterAgentsBuffer(rl: any, onExit: () => void) {
121144
for (const entry of recentAgents) {
122145
const agentName =
123146
localAgents[entry.agentId] || entry.def?.displayName || entry.agentId
147+
const description = createAgentDescription(entry)
148+
124149
agentList.push({
125150
id: entry.agentId,
126151
name: agentName,
127-
description: entry.def?.description || 'Custom user-defined agent',
152+
description,
128153
isBuiltIn: false,
129154
filePath: entry.filePath,
130155
})
@@ -145,10 +170,12 @@ export async function enterAgentsBuffer(rl: any, onExit: () => void) {
145170
for (const entry of otherAgents) {
146171
const agentName =
147172
localAgents[entry.agentId] || entry.def?.displayName || entry.agentId
173+
const description = createAgentDescription(entry)
174+
148175
agentList.push({
149176
id: entry.agentId,
150177
name: agentName,
151-
description: entry.def?.description || 'Custom user-defined agent',
178+
description,
152179
isBuiltIn: false,
153180
filePath: entry.filePath,
154181
})
@@ -160,7 +187,7 @@ export async function enterAgentsBuffer(rl: any, onExit: () => void) {
160187
id: '__agents_header__',
161188
name:
162189
bold(cyan('Custom Agents')) +
163-
gray(` • ${customAgentFiles.length} in ${AGENT_TEMPLATES_DIR}`),
190+
gray(` • ${allAgentFiles.length} in ${AGENT_TEMPLATES_DIR}`),
164191
description: '',
165192
isBuiltIn: false,
166193
isSectionHeader: true,
@@ -506,7 +533,7 @@ function setupAgentsKeyHandler(rl: any, onExit: () => void) {
506533
.then(() => {
507534
cliInstance.freshPrompt()
508535
})
509-
.catch((error) => {
536+
.catch((error: any) => {
510537
Spinner.get().stop()
511538
console.error(red('Error switching to agent:'), error)
512539
onExit()

npm-app/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let cachedLocalAgentInfo: Record<
122122
* Get local agent names using the proper agent loading logic
123123
* @returns Record of agent type to agent info
124124
*/
125-
async function getLocalAgentInfo(): Promise<
125+
export async function getLocalAgentInfo(): Promise<
126126
Record<string, { displayName: string; purpose?: string }>
127127
> {
128128
try {

0 commit comments

Comments
 (0)