|
| 1 | +import argparse |
| 2 | +import sys |
| 3 | +from pathlib import Path |
| 4 | +from importlib.metadata import version |
| 5 | + |
| 6 | +from agentci.client_config import discover_evaluations |
| 7 | + |
| 8 | +__version__ = version("agentci") |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +def validate_command(args): |
| 13 | + """Validate AgentCI configuration files in the current directory.""" |
| 14 | + # Use the provided path or current working directory |
| 15 | + repo_path = Path(args.path) if args.path else Path.cwd() |
| 16 | + |
| 17 | + if not repo_path.exists(): |
| 18 | + print(f"Error: Directory '{repo_path}' does not exist.", file=sys.stderr) |
| 19 | + return 1 |
| 20 | + |
| 21 | + if not repo_path.is_dir(): |
| 22 | + print(f"Error: '{repo_path}' is not a directory.", file=sys.stderr) |
| 23 | + return 1 |
| 24 | + |
| 25 | + print(f"Validating AgentCI configurations in: {repo_path}") |
| 26 | + |
| 27 | + try: |
| 28 | + evaluations = discover_evaluations(repo_path) |
| 29 | + |
| 30 | + if not evaluations: |
| 31 | + print("\nNo evaluation configurations found.") |
| 32 | + print(f"Place your .toml files in: {repo_path}/.agentci/evals/") |
| 33 | + return 0 |
| 34 | + |
| 35 | + print(f"\n✓ Found {len(evaluations)} valid evaluation configuration(s):") |
| 36 | + for eval_config in evaluations: |
| 37 | + print(f" - {eval_config.name} ({eval_config.type.value}): {eval_config.description}") |
| 38 | + print(f" File: {eval_config.file_path}") |
| 39 | + print(f" Targets: {len(eval_config.targets.agents)} agent(s), {len(eval_config.targets.tools)} tool(s)") |
| 40 | + print(f" Cases: {len(eval_config.cases)}") |
| 41 | + |
| 42 | + print(f"\n✓ All configurations are valid!") |
| 43 | + return 0 |
| 44 | + |
| 45 | + except ValueError as e: |
| 46 | + print(f"\n✗ Validation failed: {e}", file=sys.stderr) |
| 47 | + return 1 |
| 48 | + except Exception as e: |
| 49 | + print(f"\n✗ Unexpected error: {e}", file=sys.stderr) |
| 50 | + return 1 |
| 51 | + |
| 52 | + |
| 53 | +def main(): |
| 54 | + parser = argparse.ArgumentParser( |
| 55 | + description=f"Agent CI CLI v{__version__}", |
| 56 | + prog="agentci", |
| 57 | + ) |
| 58 | + parser.add_argument( |
| 59 | + "--version", |
| 60 | + action="version", |
| 61 | + version=f"%(prog)s {__version__}", |
| 62 | + ) |
| 63 | + |
| 64 | + subparsers = parser.add_subparsers(dest="command", help="Available commands") |
| 65 | + |
| 66 | + # Validate command |
| 67 | + validate_parser = subparsers.add_parser( |
| 68 | + "validate", |
| 69 | + help="Validate AgentCI configuration files", |
| 70 | + description="Discover and validate AgentCI evaluation configuration files in a directory", |
| 71 | + ) |
| 72 | + validate_parser.add_argument( |
| 73 | + "path", |
| 74 | + nargs="?", |
| 75 | + default=None, |
| 76 | + help="Path to the repository (defaults to current directory)", |
| 77 | + ) |
| 78 | + |
| 79 | + args = parser.parse_args() |
| 80 | + |
| 81 | + if args.command == "validate": |
| 82 | + return validate_command(args) |
| 83 | + else: |
| 84 | + # No command specified, show help |
| 85 | + parser.print_help() |
| 86 | + return 0 |
| 87 | + |
| 88 | + |
| 89 | +if __name__ == "__main__": |
| 90 | + sys.exit(main()) |
0 commit comments