def _build_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(prog="runeconomy")
    subparsers = parser.add_subparsers(dest="command", required=True)
    analyze = subparsers.add_parser("analyze", help="analyze a normalized trace")
    analyze.add_argument("trace", type=Path)
    analyze.add_argument("--format", choices=("human", "json"), default="human")
    analyze.add_argument("--output", type=Path)

    import_vllm = subparsers.add_parser(
        "import-vllm-jsonl",
        help="convert exact-token vLLM capture records into a normalized trace",
    )
    import_vllm.add_argument("captures", type=Path)
    import_vllm.add_argument("--output", type=Path, required=True)
    import_vllm.add_argument("--trace-id", required=True)
    import_vllm.add_argument("--workload", default="unknown")
    import_vllm.add_argument("--model", required=True)
    import_vllm.add_argument("--model-revision")
    import_vllm.add_argument("--tokenizer")
    import_vllm.add_argument("--tokenizer-revision")
    import_vllm.add_argument("--chat-template-digest")
    import_vllm.add_argument("--backend-version")
    import_vllm.add_argument("--block-size", type=int, default=16)
    success = import_vllm.add_mutually_exclusive_group()
    success.add_argument("--success", dest="success", action="store_true")
    success.add_argument("--failure", dest="success", action="store_false")
    import_vllm.set_defaults(success=None)

    capture = subparsers.add_parser(
        "capture-vllm", help="render and execute one vLLM Responses request"
    )
    capture.add_argument("request", type=Path)
    capture.add_argument("--base-url", required=True)
    capture.add_argument("--api-key-env")
    capture.add_argument("--timeout", type=float, default=300.0)
    capture.add_argument("--startup-timeout", type=float, default=600.0)
    capture.add_argument("--output", type=Path)
    capture.add_argument(
        "--append-trace-jsonl",
        type=Path,
        help="append an importable envelope containing the request and capture",
    )
    capture.add_argument("--request-id")
    capture.add_argument("--invoked-tool", action="append", default=[])

    demo = subparsers.add_parser(
        "demo", help="render the bundled CPU-only NegativeSplit demonstration"
    )
    demo.add_argument("--output", type=Path, default=Path("runeconomy-demo.html"))

    experiment = subparsers.add_parser(
        "negative-split",
        aliases=["experiment"],
        help="run a controlled baseline-versus-candidate comparison",
    )
    experiment_commands = experiment.add_subparsers(
        dest="experiment_command", required=True
    )
    validate = experiment_commands.add_parser("validate", help="validate a manifest")
    validate.add_argument("manifest", type=Path)
    validate.add_argument(
        "--allow-exec-evaluators",
        action="store_true",
        help="allow trusted python and command evaluators",
    )
    run = experiment_commands.add_parser("run", help="run a manifest against vLLM")
    run.add_argument("manifest", type=Path)
    run.add_argument("--output", type=Path, required=True)
    run.add_argument("--timeout", type=float, default=300.0)
    run.add_argument("--startup-timeout", type=float, default=600.0)
    run.add_argument(
        "--checkpoint",
        type=Path,
        help="JSONL recovery journal (defaults beside the output file)",
    )
    run.add_argument(
        "--resume",
        action="store_true",
        help="resume the deterministic schedule from an existing checkpoint",
    )
    run.add_argument(
        "--allow-exec-evaluators",
        action="store_true",
        help="allow trusted python and command evaluators",
    )
    run.add_argument(
        "--require-verified",
        action="store_true",
        help="return exit code 3 unless every configured acceptance gate passes",
    )
    report = experiment_commands.add_parser(
        "report", help="render a static NegativeSplit report"
    )
    report.add_argument("result", type=Path)
    report.add_argument("--output", type=Path, required=True)
    report.add_argument("--format", choices=("markdown", "html"))
    return parser
