import {
  init_dist
} from "./chunk-MI6MA6OP.js";
import {
  Err,
  Ok
} from "./chunk-RL4VMEXL.js";

// src/persona/generators/agents-md.ts
init_dist();
function formatPrTrigger(trigger) {
  const paths = trigger.conditions?.paths?.join(", ") ?? "all files";
  return `On PR (${paths})`;
}
function formatCommitTrigger(trigger) {
  const branches = trigger.conditions?.branches?.join(", ") ?? "all branches";
  return `On commit (${branches})`;
}
function formatTrigger(trigger) {
  switch (trigger.event) {
    case "on_pr":
      return formatPrTrigger(trigger);
    case "on_commit":
      return formatCommitTrigger(trigger);
    case "scheduled":
      return `Scheduled (cron: ${trigger.cron})`;
    case "manual":
      return "Manual";
  }
}
function buildCommandList(persona) {
  const commands = persona.steps.filter((s) => "command" in s).map((s) => `\`harness ${s.command}\``);
  const stepSkills = persona.steps.filter((s) => "skill" in s).map((s) => `\`harness skill run ${s.skill}\``);
  return [...commands, ...stepSkills].join(", ");
}
function generateAgentsMd(persona) {
  try {
    const triggers = persona.triggers.map(formatTrigger).join(", ");
    const skills = persona.skills.join(", ");
    const allCommands = buildCommandList(persona);
    const fragment = `## ${persona.name} Agent

**Role:** ${persona.role}

**Triggers:** ${triggers}

**Skills:** ${skills}

**When this agent flags an issue:** Fix violations before merging. Run ${allCommands} locally to validate.
`;
    return Ok(fragment);
  } catch (error) {
    return Err(
      new Error(
        `Failed to generate AGENTS.md fragment: ${error instanceof Error ? error.message : String(error)}`
      )
    );
  }
}

export {
  generateAgentsMd
};
