import fs from "node:fs";
import path from "node:path";
/**
 * Execute one `org` tool action for the LLM. Kept as a pure function so
 * Agent + ChatEngine + future workers share the same dispatch surface
 * without each owning a copy.
 */
export function executeOrgAction(orgManager, orgConfig, action, args) {
    if (!orgManager)
        return "Error: Organization management is not configured.";
    switch (action) {
        case "list_team": {
            const team = orgManager.listTeam();
            if (team.length === 0)
                return "No team members found in your department.";
            return team
                .map((m) => `- ${m.name} (${m.role}): ${m.status} (Last seen: ${m.lastSeen})`)
                .join("\n");
        }
        case "assign": {
            const target = args.target;
            const instruction = args.instruction;
            if (!target || !instruction) {
                return "Error: 'target' and 'instruction' are required.";
            }
            try {
                const assignments = orgManager.assignTask(target, instruction);
                return `✓ Task assigned to ${target}: ${assignments.length} assignments created.`;
            }
            catch (err) {
                return `Error: ${err instanceof Error ? err.message : String(err)}`;
            }
        }
        case "list_departments": {
            const root = orgConfig?.root;
            if (!root)
                return "Error: Org root not found.";
            const registryDir = path.join(root, "registry");
            if (!fs.existsSync(registryDir))
                return "No departments found.";
            return fs.readdirSync(registryDir).join(", ");
        }
        default:
            return `Unknown org action: ${action}`;
    }
}
//# sourceMappingURL=org-executor.js.map