#!/usr/bin/env -S uv run
# /// script
# dependencies = ["pydantic", "python-dotenv", "pyyaml", "rich"]
# ///
"""Test fixture ADW: open a traced session and finish without agent work."""

import argparse
import sys

from adw_modules import agents, session
from adw_modules.data_types import PhaseParams


def main(config: str, adw_id: str | None = None, hold: bool = False) -> int:
    cfg = agents.load_config(config)
    run = session.ensure(cfg, adw_id=adw_id)
    with run.phase(
        PhaseParams(
            name="probe",
            kind="engineer",
            owner=run.engineer,
            description="Record the target repo without agent work",
        ),
    ) as ph:
        ph.log(input="factory cli probe")
    if hold:
        try:
            sys.stdin.read(1)
        except OSError:
            pass
    return run.finish()


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--config", required=True)
    parser.add_argument("--adw-id", default="probe-session")
    parser.add_argument(
        "--hold",
        action="store_true",
        help="Block on stdin after recording so /proc argv can be verified",
    )
    args = parser.parse_args()
    sys.exit(main(args.config, args.adw_id, hold=args.hold))
