155 lines
5.3 KiB
Python
155 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Clover - A CLI tool for working with AI models to build and manage projects.
|
|
Interactive mode where you can run commands without prefixing 'clover'.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
# Add the current directory to Python path
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from cli.commands import handle_command
|
|
from cli.parser import parse_args, print_help
|
|
|
|
|
|
def interactive_mode():
|
|
"""Run Clover in interactive mode"""
|
|
print("Clover Interactive Mode")
|
|
print("=" * 40)
|
|
print("Welcome to Clover! You are now in interactive mode.")
|
|
print("Commands without 'clover' prefix:")
|
|
print("- /init : Initialize project summary file")
|
|
print("- /list : List available models")
|
|
print("- /timeout SECS : Set timeout duration")
|
|
print("- /threads N : Set thread limit")
|
|
print("- /git_status : Check Git repository status")
|
|
print("- /lint_file FILE : Lint a specific file")
|
|
print("- /help : Show this help")
|
|
print("- /quit or /exit: Exit interactive mode")
|
|
print("\nEnter commands below (type /help for usage):")
|
|
print("-" * 40)
|
|
|
|
while True:
|
|
try:
|
|
# Get user input
|
|
user_input = input("\n> ").strip()
|
|
|
|
# Handle exit commands
|
|
if user_input.lower() in ["/quit", "/exit", "exit", "quit"]:
|
|
print("Goodbye!")
|
|
break
|
|
|
|
# Handle help command
|
|
if user_input.lower() == "/help":
|
|
print_help()
|
|
continue
|
|
|
|
# If input is empty, continue
|
|
if not user_input:
|
|
continue
|
|
|
|
# Parse and handle the command (prefix with clover for parsing)
|
|
# We'll create a fake args object for command handling in interactive mode
|
|
if user_input.startswith("/"):
|
|
# This is already a special command - no prefix needed
|
|
args = argparse.Namespace()
|
|
if user_input == "/init":
|
|
args.init = True
|
|
args.list = False
|
|
args.timeout = None
|
|
args.threads = None
|
|
args.prompt = None
|
|
elif user_input == "/list":
|
|
args.init = False
|
|
args.list = True
|
|
args.timeout = None
|
|
args.threads = None
|
|
args.prompt = None
|
|
elif user_input.startswith("/timeout "):
|
|
try:
|
|
seconds = int(user_input.split()[1])
|
|
args.init = False
|
|
args.list = False
|
|
args.timeout = seconds
|
|
args.threads = None
|
|
args.prompt = None
|
|
except (ValueError, IndexError):
|
|
print("Usage: /timeout <seconds>")
|
|
continue
|
|
elif user_input.startswith("/threads "):
|
|
try:
|
|
count = int(user_input.split()[1])
|
|
args.init = False
|
|
args.list = False
|
|
args.timeout = None
|
|
args.threads = count
|
|
args.prompt = None
|
|
except (ValueError, IndexError):
|
|
print("Usage: /threads <count>")
|
|
continue
|
|
elif user_input == "/git_status":
|
|
# For git commands we might need to handle differently
|
|
args.init = False
|
|
args.list = False
|
|
args.timeout = None
|
|
args.threads = None
|
|
args.prompt = "/git_status"
|
|
elif user_input.startswith("/lint_file "):
|
|
args.init = False
|
|
args.list = False
|
|
args.timeout = None
|
|
args.threads = None
|
|
args.prompt = user_input
|
|
else:
|
|
# Treat as regular command for now
|
|
args = argparse.Namespace()
|
|
args.init = False
|
|
args.list = False
|
|
args.timeout = None
|
|
args.threads = None
|
|
args.prompt = user_input
|
|
|
|
try:
|
|
handle_command(args)
|
|
except Exception as e:
|
|
print(f"Error executing command: {e}")
|
|
else:
|
|
# Treat as regular query
|
|
args = argparse.Namespace()
|
|
args.init = False
|
|
args.list = False
|
|
args.timeout = None
|
|
args.threads = None
|
|
args.prompt = user_input
|
|
try:
|
|
handle_command(args)
|
|
except Exception as e:
|
|
print(f"Error executing command: {e}")
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n\nGoodbye!")
|
|
break
|
|
except EOFError:
|
|
print("\nGoodbye!")
|
|
break
|
|
|
|
|
|
def main():
|
|
"""Main entry point"""
|
|
# Parse arguments
|
|
args = parse_args()
|
|
|
|
# Check if running in interactive mode (no arguments provided)
|
|
if len(sys.argv) == 1:
|
|
interactive_mode()
|
|
else:
|
|
# Run single command mode
|
|
handle_command(args)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|