feat(cli): add /agents config command and improve agent discovery (#17342)

This commit is contained in:
Sandy Tao
2026-01-22 15:22:56 -08:00
committed by GitHub
parent 11e48e2dd1
commit 35feea8868
3 changed files with 223 additions and 2 deletions
+80 -2
View File
@@ -62,7 +62,13 @@ async function enableAction(
args: string,
): Promise<SlashCommandActionReturn | void> {
const { config, settings } = context.services;
if (!config) return;
if (!config) {
return {
type: 'message',
messageType: 'error',
content: 'Config not loaded.',
};
}
const agentName = args.trim();
if (!agentName) {
@@ -132,7 +138,13 @@ async function disableAction(
args: string,
): Promise<SlashCommandActionReturn | void> {
const { config, settings } = context.services;
if (!config) return;
if (!config) {
return {
type: 'message',
messageType: 'error',
content: 'Config not loaded.',
};
}
const agentName = args.trim();
if (!agentName) {
@@ -200,6 +212,53 @@ async function disableAction(
};
}
async function configAction(
context: CommandContext,
args: string,
): Promise<SlashCommandActionReturn | void> {
const { config } = context.services;
if (!config) {
return {
type: 'message',
messageType: 'error',
content: 'Config not loaded.',
};
}
const agentName = args.trim();
if (!agentName) {
return {
type: 'message',
messageType: 'error',
content: 'Usage: /agents config <agent-name>',
};
}
const agentRegistry = config.getAgentRegistry();
if (!agentRegistry) {
return {
type: 'message',
messageType: 'error',
content: 'Agent registry not found.',
};
}
const definition = agentRegistry.getDiscoveredDefinition(agentName);
if (!definition) {
return {
type: 'message',
messageType: 'error',
content: `Agent '${agentName}' not found.`,
};
}
return {
type: 'message',
messageType: 'info',
content: `Configuration for '${agentName}' will be available in the next update.`,
};
}
function completeAgentsToEnable(context: CommandContext, partialArg: string) {
const { config, settings } = context.services;
if (!config) return [];
@@ -221,6 +280,15 @@ function completeAgentsToDisable(context: CommandContext, partialArg: string) {
return allAgents.filter((name: string) => name.startsWith(partialArg));
}
function completeAllAgents(context: CommandContext, partialArg: string) {
const { config } = context.services;
if (!config) return [];
const agentRegistry = config.getAgentRegistry();
const allAgents = agentRegistry?.getAllDiscoveredAgentNames() ?? [];
return allAgents.filter((name: string) => name.startsWith(partialArg));
}
const enableCommand: SlashCommand = {
name: 'enable',
description: 'Enable a disabled agent',
@@ -239,6 +307,15 @@ const disableCommand: SlashCommand = {
completion: completeAgentsToDisable,
};
const configCommand: SlashCommand = {
name: 'config',
description: 'Configure an agent',
kind: CommandKind.BUILT_IN,
autoExecute: false,
action: configAction,
completion: completeAllAgents,
};
const agentsRefreshCommand: SlashCommand = {
name: 'refresh',
description: 'Reload the agent registry',
@@ -278,6 +355,7 @@ export const agentsCommand: SlashCommand = {
agentsRefreshCommand,
enableCommand,
disableCommand,
configCommand,
],
action: async (context: CommandContext, args) =>
// Default to list if no subcommand is provided