"""krim - thin CLI agent entrypoint."""

from __future__ import annotations

import argparse

from krim import __version__
from krim.app import KrimCliApp


def parse_args():
    p = argparse.ArgumentParser(
        prog="krim",
        description="Thin CLI agent. Trust the model, keep the harness light.",
    )
    p.add_argument("prompt", nargs="?", help="task to perform (omit for interactive mode)")
    p.add_argument(
        "--provider",
        "-p",
        default=None,
        choices=["claude", "openai", "openrouter"],
        help="model provider (default: prompt to select)",
    )
    p.add_argument("--model", "-m", default=None, help="model name (default: provider's default)")
    p.add_argument(
        "--max-turns",
        "-t",
        type=int,
        default=None,
        help="max agent turns (default: from config or 10)",
    )
    p.add_argument("--skill", "-s", default=None, help="activate a skill by name")
    p.add_argument("--list-skills", action="store_true", help="list available skills")
    p.add_argument("--no-mcp", action="store_true", help="disable MCP servers")
    p.add_argument(
        "--auto-commit",
        action="store_true",
        default=None,
        help="auto-commit after agent edits",
    )
    p.add_argument(
        "--no-safety",
        action="store_true",
        help="disable bash safety prompts (auto-allow all)",
    )
    p.add_argument(
        "--quiet",
        "-q",
        action="store_true",
        help="hide turn logs, show only final response",
    )
    p.add_argument("--log-dir", default=None, help="save conversation logs to directory")
    p.add_argument("--resume", default=None, help="resume a prior session from a log directory")
    p.add_argument("--version", "-v", action="version", version=f"krim {__version__}")

    p.add_argument("--loop", action="store_true", help="run in loop mode")
    p.add_argument(
        "--max-iterations",
        type=int,
        default=20,
        help="max loop iterations before stopping (default: 20)",
    )
    p.add_argument(
        "--exit-on",
        default=None,
        help="shell command that must exit 0 to stop the loop (e.g. 'pytest')",
    )

    p.add_argument(
        "--parallel",
        nargs="+",
        metavar="TASK",
        help="run multiple tasks in parallel via git worktrees",
    )
    p.add_argument(
        "--no-merge",
        action="store_true",
        help="keep parallel branches separate (don't auto-merge)",
    )

    return p.parse_args()


def main():
    KrimCliApp().run(parse_args())


if __name__ == "__main__":
    main()
