def main() -> int:
"""Main CLI entrypoint."""
initialize_user_config()
parser = argparse.ArgumentParser(
prog="abc-runner",
description="ABC Runner: Autonomous benchmark suite for scientific computing",
)
subparsers = parser.add_subparsers(dest="command", help="Command to run")
parser_list_tasks = subparsers.add_parser("list-tasks", help="List available tasks")
parser_list_tasks.add_argument("task_group", nargs="?", help="Optional task group filter")
parser_list_tasks.add_argument(
"--task-dir",
type=Path,
default=None,
help="Directory containing task groups (highest resolution priority)",
)
parser_list_tasks.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_list_tasks.set_defaults(func=cmd_list_tasks)
parser_list_task_groups = subparsers.add_parser("list-task-groups", help="List all available task groups")
parser_list_task_groups.add_argument(
"--task-dir",
type=Path,
default=None,
help="Directory containing task groups (highest resolution priority)",
)
parser_list_task_groups.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_list_task_groups.set_defaults(func=cmd_list_task_groups)
parser_install = subparsers.add_parser(
"install", help="Install task group(s) into ~/.abc-runner/tasks"
)
parser_install.add_argument(
"sources",
nargs="*",
help="Task-group source(s): a directory, .sqfs image, or .tar.gz archive. "
"With no source, seeds the bundled smoke_test if nothing is installed.",
)
parser_install.add_argument(
"--force", "-f", action="store_true", help="Overwrite already-installed groups"
)
parser_install.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_install.set_defaults(func=cmd_install)
parser_list_containers = subparsers.add_parser("list-containers", help="List containers or show container details")
parser_list_containers.add_argument("container", nargs="?", help="Container ref or glob pattern")
parser_list_containers.add_argument(
"--built-only",
action="store_true",
help="Show only built containers",
)
parser_list_containers.add_argument(
"--task-dir",
type=Path,
default=None,
help="Directory containing task groups (highest resolution priority)",
)
parser_list_containers.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_list_containers.set_defaults(func=cmd_list_containers)
parser_list_models = subparsers.add_parser("list-models", help="List configured models")
parser_list_models.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_list_models.set_defaults(func=cmd_list_models)
parser_list_agents = subparsers.add_parser("list-agents", help="List configured agents")
parser_list_agents.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_list_agents.set_defaults(func=cmd_list_agents)
parser_build_container = subparsers.add_parser("build-container", help="Build a container artifact")
parser_build_container.add_argument("container", nargs="?", help="Container ref to build")
parser_build_container.add_argument("--all", action="store_true", help="Build all containers")
parser_build_container.add_argument("--rebuild", action="store_true", help="Force rebuild even if already built")
parser_build_container.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
parser_build_container.add_argument(
"--task-dir",
type=Path,
default=None,
help="Directory containing task groups (highest resolution priority)",
)
parser_build_container.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_build_container.set_defaults(func=cmd_build_container)
parser_delete_container = subparsers.add_parser("delete-container", help="Delete a built container artifact")
parser_delete_container.add_argument("container", nargs="?", help="Container ref to delete")
parser_delete_container.add_argument("--all", action="store_true", help="Delete all built containers")
parser_delete_container.add_argument("--force", "-f", action="store_true", help="Skip confirmation prompt")
parser_delete_container.add_argument(
"--task-dir",
type=Path,
default=None,
help="Directory containing task groups (highest resolution priority)",
)
parser_delete_container.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_delete_container.set_defaults(func=cmd_delete_container)
parser_clear_cache = subparsers.add_parser("clear-cache", help="Clear built containers and temporary build cache")
parser_clear_cache.add_argument("--force", "-f", action="store_true", help="Skip confirmation prompt")
parser_clear_cache.add_argument(
"--task-dir",
type=Path,
default=None,
help="Directory containing task groups (highest resolution priority)",
)
parser_clear_cache.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_clear_cache.set_defaults(func=cmd_clear_cache)
parser_run = subparsers.add_parser("run", help="Run a benchmark")
parser_run.add_argument("--task", required=True, help="Task ID to run")
parser_run.add_argument("--agent", required=True, help="Agent ID to use")
parser_run.add_argument("--task-group", default=None, help="Explicit task group when --task is not canonical")
parser_run.add_argument(
"--task-dir",
type=Path,
default=None,
help="Directory containing task groups (highest resolution priority)",
)
parser_run.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_run.add_argument("--timeout", type=int, default=None, help="Timeout in seconds (default: from config)")
parser_run.add_argument(
"--results-dir",
type=Path,
default=None,
help="Organized archive root for many benchmark results (or ABC_RUNNER_RESULTS_DIR)",
)
parser_run.add_argument(
"--output-dir",
type=Path,
default=None,
help="Standalone directory for this single benchmark result (or ABC_RUNNER_OUTPUT_DIR)",
)
parser_run.add_argument("--dry-run", action="store_true", help="Print commands without executing")
parser_run.add_argument("--no-stream-output", action="store_true", help="Write container output only to log files")
parser_run.add_argument(
"--harness-memory-limit",
type=parse_memory_limit,
default=None,
metavar="SIZE",
help="Fixed memory cap for the harness process tree, e.g. 8G or 4096M (default: 90%% of available memory)",
)
parser_run.add_argument(
"--harness-memory-limit-fraction",
type=float,
default=0.9,
help="Fraction of available memory to use as harness cap when --harness-memory-limit is not set (default: 0.9)",
)
parser_run.add_argument("--no-harness-memory-limit", action="store_true", help="Disable the harness memory cap")
parser_run.add_argument(
"--no-clean-env",
action="store_true",
help="Do not remove task environment after verification (useful for debugging)",
)
parser_run.add_argument(
"--no-sandbox-network",
action="store_true",
help="Run harness and verification with host networking instead of loopback-only sandboxing",
)
parser_run.add_argument(
"--keep-workspace",
action="store_true",
help="Keep the full final workspace (expanded result format) instead of a delta against the task",
)
parser_run.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
parser_run.set_defaults(func=cmd_run)
parser_run_tasks = subparsers.add_parser("run-tasks", help="Run multiple benchmarks from canonical task-ref globs")
parser_run_tasks.add_argument("patterns", nargs="+", help="Canonical task-ref glob pattern(s), e.g. 'smoke_test/*'")
parser_run_tasks.add_argument("--agent", required=True, help="Agent ID to use")
parser_run_tasks.add_argument(
"--task-dir",
type=Path,
default=None,
help="Directory containing task groups (highest resolution priority)",
)
parser_run_tasks.add_argument(
"--config",
type=Path,
default=None,
help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})",
)
parser_run_tasks.add_argument("--timeout", type=int, default=None, help="Timeout in seconds (default: from config)")
parser_run_tasks.add_argument(
"--results-dir",
type=Path,
default=None,
help="Organized archive root for many benchmark results (or ABC_RUNNER_RESULTS_DIR)",
)
parser_run_tasks.add_argument("--dry-run", action="store_true", help="Print commands without executing")
parser_run_tasks.add_argument(
"--no-stream-output", action="store_true", help="Write container output only to log files"
)
parser_run_tasks.add_argument(
"--attempts",
type=int,
default=1,
help="Number of attempts to run per task (default: 1). Already-completed "
"attempts are kept; a batch never exceeds this many attempts per task.",
)
parser_run_tasks.add_argument(
"--mpi",
action="store_true",
help="Distribute the batch across MPI ranks (requires launching under "
"an MPI launcher, e.g. srun/mpiexec, and the automaton[mpi] extra). "
"Rank 0 both dispatches and runs jobs.",
)
parser_run_tasks.add_argument(
"--harness-memory-limit",
type=parse_memory_limit,
default=None,
metavar="SIZE",
help="Fixed memory cap for the harness process tree, e.g. 8G or 4096M (default: 90%% of available memory)",
)
parser_run_tasks.add_argument(
"--harness-memory-limit-fraction",
type=float,
default=0.9,
help="Fraction of available memory to use as harness cap when --harness-memory-limit is not set (default: 0.9)",
)
parser_run_tasks.add_argument(
"--no-harness-memory-limit", action="store_true", help="Disable the harness memory cap"
)
parser_run_tasks.add_argument(
"--no-clean-env",
action="store_true",
help="Do not remove task environment after verification (useful for debugging)",
)
parser_run_tasks.add_argument(
"--no-sandbox-network",
action="store_true",
help="Run harness and verification with host networking instead of loopback-only sandboxing",
)
parser_run_tasks.add_argument(
"--keep-workspace",
action="store_true",
help="Keep the full final workspace (expanded result format) instead of a delta against the task",
)
parser_run_tasks.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
parser_run_tasks.set_defaults(func=cmd_run_tasks)
group_map_help = (
"Resolve a recorded task group under a different installed name, e.g. "
"truchas=truchas-old (repeatable)"
)
parser_compress = subparsers.add_parser(
"compress-results",
help="Compress expanded runs (full workspace copies) to workspace deltas, in place",
)
parser_compress.add_argument("paths", nargs="+", help="Run directories or archive roots to scan")
parser_compress.add_argument("--group-map", action="append", metavar="OLD=NEW", help=group_map_help)
parser_compress.add_argument("--dry-run", action="store_true", help="List runs that would be compressed")
parser_compress.add_argument(
"--jobs",
"-j",
type=int,
default=1,
help="Number of runs to compress in parallel; 0 uses all CPUs available to this process (default: 1)",
)
parser_compress.add_argument(
"--task-dir", type=Path, default=None, help="Directory containing task groups (highest resolution priority)"
)
parser_compress.add_argument("--config", type=Path, default=None, help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})")
parser_compress.set_defaults(func=cmd_compress_results)
parser_restore = subparsers.add_parser(
"restore-workspace",
help="Rebuild a compressed run's final workspace from its task and stored delta",
)
parser_restore.add_argument("run_dir", help="Run directory containing workspace_delta.json")
parser_restore.add_argument("--dest", required=True, help="Directory to create")
parser_restore.add_argument("--group-map", action="append", metavar="OLD=NEW", help=group_map_help)
parser_restore.add_argument(
"--task-dir", type=Path, default=None, help="Directory containing task groups (highest resolution priority)"
)
parser_restore.add_argument("--config", type=Path, default=None, help=f"Path to config file (default: {DEFAULT_CONFIG_PATH})")
parser_restore.set_defaults(func=cmd_restore_workspace)
args = parser.parse_args()
if not args.command:
parser.print_help()
return 1
return args.func(args)