// cli/commands/handoff.ts — planu handoff <specId> (SPEC-124)
import { parseArgs } from 'node:util';
import { handleGenerateTeammatePrompt } from '../../tools/generate-teammate-prompt.js';
import { formatToolResult } from '../formatter.js';
import { detectProjectId } from '../project-detector.js';
import { red } from '../colors.js';
export const handoffCommand = {
    name: 'handoff',
    description: 'Generate a teammate handoff prompt for a spec',
    usage: 'planu handoff <specId> [--name Agent-1] [--role implementer] [--files src/a.ts,src/b.ts]',
    async run(args, flags) {
        const { values, positionals } = parseArgs({
            args,
            options: {
                'project-id': { type: 'string' },
                name: { type: 'string', short: 'n' },
                role: { type: 'string', short: 'r' },
                files: { type: 'string', short: 'f' },
            },
            strict: false,
            allowPositionals: true,
        });
        const specId = positionals[0];
        if (!specId) {
            process.stderr.write(`${red('Error:')} Spec ID is required.\nUsage: ${handoffCommand.usage}\n`);
            process.exitCode = 1;
            return;
        }
        const projectId = values['project-id'] ?? detectProjectId();
        const teammateName = values.name ?? 'Agent-1';
        const role = values.role ?? 'implementer';
        const filesStr = values.files ?? '';
        const assignedFiles = filesStr ? filesStr.split(',').map((f) => f.trim()) : [];
        const result = await handleGenerateTeammatePrompt({
            projectId,
            specId,
            teammateName,
            assignedFiles,
            role: role,
        });
        if (result.isError) {
            process.stderr.write(`${red(formatToolResult(result, flags))}\n`);
            process.exitCode = 1;
            return;
        }
        const output = formatToolResult(result, flags);
        if (output) {
            process.stdout.write(output + '\n');
        }
    },
};
//# sourceMappingURL=handoff.js.map