#!/usr/bin/env python3"""Command-line interface for the agent-logic package.This module provides a command-line interface for interacting with the agent-logic package,including tools for validating proofs and other logical operations.Usage: python -m agent_logic.cli --help python -m agent_logic.cli validate path/to/proof.json python -m agent_logic.cli --log-level DEBUG validate path/to/proof.json"""importargparseimportjsonimportloggingimportsysfromagent_logic.proofs.proof_systemimportProoffromagent_logic.utils.loggerimportset_global_log_level
[docs]defparse_args():""" Parse command-line arguments. Returns: Parsed command-line arguments as an argparse.Namespace object. """parser=argparse.ArgumentParser(description="Logic system command-line interface")# Global argumentsparser.add_argument("--log-level",choices=["DEBUG","INFO","WARNING","ERROR","CRITICAL"],default="INFO",help="Set logging level",)parser.add_argument("--debug",action="store_true",help="Enable debug mode (sets log level to DEBUG)",)# Main command subparserssubparsers=parser.add_subparsers(dest="command",help="Command to execute")# Validate proof commandvalidate_parser=subparsers.add_parser("validate",help="Validate a proof")validate_parser.add_argument("proof_file",type=str,help="Path to proof JSON file")returnparser.parse_args()
[docs]defvalidate_proof(proof_file,debug=False):""" Validate a proof from a JSON file. Loads a proof from a JSON file and checks if it is valid according to the specified inference rules. Args: proof_file: Path to the JSON file containing the proof. debug: Whether to enable debug mode in the proof validation. Returns: Exit code (0 for success, 1 for invalid proof, 2 for errors). Raises: FileNotFoundError: If the proof file doesn't exist. json.JSONDecodeError: If the file contains invalid JSON. """try:withopen(proof_file,"r")asf:data=json.load(f)# Create proof objectproof=Proof.from_dict(data)# Set debug modeproof.debug=debug# Validate proofis_valid=proof.is_valid()ifis_valid:print("✅ Proof is valid")return0else:print("❌ Proof is invalid")return1exceptExceptionase:print(f"Error validating proof: {e}")return2
[docs]defmain():""" Main entry point for the CLI. Parses command-line arguments, sets up logging, and executes the appropriate command. Returns: Exit code (0 for success, non-zero for errors). """args=parse_args()# Set log levellog_level=logging.DEBUGifargs.debugelsegetattr(logging,args.log_level)set_global_log_level(log_level)ifargs.command=="validate":returnvalidate_proof(args.proof_file,debug=args.debug)else:print("Please specify a command. Use --help for more information.")return1