feat: add /research command with sub-agent delegation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
|
||||
import { createContextCommand, createElevateCommand, createModelCommand, createQueueCommand } from './index.js';
|
||||
import { createContextCommand, createElevateCommand, createModelCommand, createQueueCommand, createResearchCommand } from './index.js';
|
||||
|
||||
describe('builtin /model command', () => {
|
||||
it('passes through the full argument string', async () => {
|
||||
@@ -36,6 +36,36 @@ describe('builtin /model command', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('builtin /research command', () => {
|
||||
it('delegates to the research agent with the full task string', async () => {
|
||||
const cmd = createResearchCommand();
|
||||
const delegateAgent = vi.fn(() => 'research output');
|
||||
|
||||
const result = await cmd.execute(['compare', 'k0s', 'vs', 'k3s'], {
|
||||
channel: 'test',
|
||||
senderId: 'user',
|
||||
sessionId: 's1',
|
||||
rawInput: '/research compare k0s vs k3s',
|
||||
services: { delegateAgent },
|
||||
});
|
||||
|
||||
expect(delegateAgent).toHaveBeenCalledWith('research', 'compare k0s vs k3s');
|
||||
expect(result).toEqual({ handled: true, text: 'research output' });
|
||||
});
|
||||
|
||||
it('returns usage when no task is provided', async () => {
|
||||
const cmd = createResearchCommand();
|
||||
const result = await cmd.execute([], {
|
||||
channel: 'test',
|
||||
senderId: 'user',
|
||||
sessionId: 's1',
|
||||
rawInput: '/research',
|
||||
services: {},
|
||||
});
|
||||
expect(result).toEqual({ handled: true, text: 'Usage: /research <question or task>' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('builtin /elevate command', () => {
|
||||
it('passes through the full argument string', async () => {
|
||||
const cmd = createElevateCommand();
|
||||
|
||||
@@ -195,11 +195,35 @@ export function createQueueCommand(): CommandDefinition {
|
||||
};
|
||||
}
|
||||
|
||||
export function createResearchCommand(): CommandDefinition {
|
||||
return {
|
||||
name: 'research',
|
||||
description: 'Delegate a task to the configured research sub-agent',
|
||||
execute: async (args, ctx) => {
|
||||
const task = args.join(' ').trim();
|
||||
if (!task) {
|
||||
return {
|
||||
handled: true,
|
||||
text: 'Usage: /research <question or task>',
|
||||
};
|
||||
}
|
||||
if (!ctx.services?.delegateAgent) {
|
||||
return notAvailable('Research command');
|
||||
}
|
||||
return {
|
||||
handled: true,
|
||||
text: await ctx.services.delegateAgent('research', task),
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function registerBuiltinCommands(registry: CommandRegistry): void {
|
||||
registry.register(createHelpCommand(registry));
|
||||
registry.register(createStatusCommand());
|
||||
registry.register(createUsageCommand());
|
||||
registry.register(createContextCommand());
|
||||
registry.register(createResearchCommand());
|
||||
registry.register(createModelCommand());
|
||||
registry.register(createCompactCommand());
|
||||
registry.register(createResetCommand());
|
||||
|
||||
Reference in New Issue
Block a user