/**
 * List all persistent specialist definitions.
 */
import { listSpecialists, removeSpecialist } from '../utils/specialist-utils.js';
import { AgentRegistryManager } from '../core/agent-registry.js';
export const agentSpecialistListTool = {
    name: 'agent_specialist_list',
    label: 'List Specialists',
    description: 'List all persistent specialist definitions. Specialists auto-spawn on agent_serve and survive cleanup.',
    parameters: {
        type: 'object',
        properties: {
            remove: {
                type: 'string',
                description: 'Remove a specialist by name',
            },
        },
        required: [],
    },
    async execute(_toolCallId, params) {
        if (params.remove) {
            const removed = removeSpecialist(params.remove);
            if (removed) {
                // Also unmark persistent in registry
                const registry = new AgentRegistryManager();
                const agent = registry.getAgentByName(params.remove);
                if (agent) {
                    agent.persistent = false;
                    registry.upsertAgent(agent);
                    registry.save();
                }
                return {
                    content: [{ type: 'text', text: `✅ Specialist "${params.remove}" removed` }],
                };
            }
            return {
                content: [{ type: 'text', text: `❌ Specialist "${params.remove}" not found` }],
                isError: true,
            };
        }
        const specialists = listSpecialists();
        if (specialists.length === 0) {
            return {
                content: [{ type: 'text', text: 'No persistent specialists defined.\n\nUse `agent_specialist_save` to save a worker as a specialist, or define a new one.' }],
                details: { count: 0 },
            };
        }
        // Check which are currently running
        const registry = new AgentRegistryManager();
        const lines = [`# Persistent Specialists (${specialists.length})`, ''];
        for (const spec of specialists) {
            const agent = registry.getAgentByName(spec.name);
            const status = agent
                ? (agent.status === 'idle' || agent.status === 'working' ? '🟢 running' : '🔴 offline')
                : '⚪ not spawned';
            lines.push(`### ${spec.name} — ${status}`);
            lines.push(`**Role**: ${spec.persona.role}`);
            if (spec.persona.strengths && spec.persona.strengths.length > 0) {
                lines.push(`**Strengths**: ${spec.persona.strengths.join(', ')}`);
            }
            if (spec.allowedTools.length > 0) {
                lines.push(`**Tools**: ${spec.allowedTools.join(', ')}`);
            }
            else {
                lines.push(`**Tools**: all`);
            }
            if (spec.setup) {
                lines.push(`**Setup**: \`${spec.setup}\``);
            }
            lines.push('');
        }
        return {
            content: [{ type: 'text', text: lines.join('\n') }],
            details: { count: specialists.length, specialists },
        };
    },
};
//# sourceMappingURL=agentSpecialistList.js.map