diff --git a/src/cli/commands/delegate.ts b/src/cli/commands/delegate.ts new file mode 100644 index 0000000..e3e0e98 --- /dev/null +++ b/src/cli/commands/delegate.ts @@ -0,0 +1,39 @@ +import { loadConfig } from '../../core/config.js'; +import { Index } from '../../core/index.js'; +import { handoffCreate } from './handoff.js'; + +export async function delegate(cwd: string, options: { auto?: boolean } = {}): Promise { + const config = loadConfig(cwd); + const index = new Index(cwd); + const openTasks = index.list('task', { status: 'open' }); + index.close(); + + if (openTasks.length === 0) { + console.log('No open tasks to delegate.'); + return; + } + + const task = openTasks[0]; + const role = task.role ?? 'implementer'; + const preferredAgent = config.roles[role]?.preferredAgent ?? 'codex'; + + console.log('Suggested delegation:'); + console.log(` Task: ${task.id} — ${task.title}`); + console.log(` Role: ${role}`); + console.log(` Preferred agent: ${preferredAgent}`); + + if (config.delegationMode === 'auto' || options.auto) { + await handoffCreate(cwd, { + fromRole: 'user', + toRole: role, + toAgent: preferredAgent, + taskId: task.id, + summary: `Delegate ${task.id} to ${role}`, + context: `Task "${task.title}" should be handled by ${preferredAgent} in ${role} role.`, + }); + console.log('Handoff created automatically.'); + } else { + console.log('Run with --auto to create the handoff, or run:'); + console.log(` agenthub handoff create --taskId ${task.id}`); + } +}