from pathlib import Path

from mixersystem.data.repository import context_scope, get_context, update_frontmatter
from mixersystem.workflows.upgrade import builder


async def run(work_folder: str, size: str = "M",
              depth: int | None = None) -> None:
    """Analyze agent logs and suggest rule upgrades."""
    with context_scope(
        work_folder=str(Path(work_folder).resolve()),
        size=size,
        depth=depth,
    ):
        await builder.run()

        ctx = get_context()
        update_frontmatter(ctx.paths["upgrade_path"], size=ctx.size)


if __name__ == "__main__":
    from mixersystem.data.repository import run_cli
    run_cli(run)
