|
import argparse
|
|
import sys
|
|
|
|
from rp import __version__
|
|
from rp.core import Assistant
|
|
|
|
|
|
def main_def():
|
|
import tracemalloc
|
|
|
|
tracemalloc.start()
|
|
parser = argparse.ArgumentParser(
|
|
description="RP Assistant - Professional CLI AI assistant with visual effects, cost tracking, and autonomous execution",
|
|
epilog="""
|
|
Examples:
|
|
rp "What is Python?" # Single query
|
|
rp -i # Interactive mode
|
|
rp -i --model gpt-4 # Use specific model
|
|
rp --save-session my-task -i # Save session
|
|
rp --load-session my-task # Load session
|
|
rp --list-sessions # List all sessions
|
|
rp --usage # Show token usage stats
|
|
|
|
Features:
|
|
• Visual progress indicators during AI calls
|
|
• Real-time cost tracking for each query
|
|
• Sophisticated CLI with colors and effects
|
|
• Tool execution with status updates
|
|
|
|
Commands in interactive mode:
|
|
/auto [task] - Enter autonomous mode
|
|
/reset - Clear message history
|
|
/verbose - Toggle verbose output
|
|
/models - List available models
|
|
/tools - List available tools
|
|
/usage - Show usage statistics
|
|
/save <name> - Save current session
|
|
exit, quit, q - Exit the program
|
|
""",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
)
|
|
parser.add_argument("message", nargs="?", help="Message to send to assistant")
|
|
parser.add_argument("--version", action="version", version=f"RP Assistant {__version__}")
|
|
parser.add_argument("-m", "--model", help="AI model to use")
|
|
parser.add_argument("-u", "--api-url", help="API endpoint URL")
|
|
parser.add_argument("--model-list-url", help="Model list endpoint URL")
|
|
parser.add_argument("-i", "--interactive", action="store_true", help="Interactive mode")
|
|
parser.add_argument("-a", "--autonomous", action="store_true", help="Autonomous mode")
|
|
parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output")
|
|
parser.add_argument(
|
|
"--debug", action="store_true", help="Enable debug mode with detailed logging"
|
|
)
|
|
parser.add_argument("--no-syntax", action="store_true", help="Disable syntax highlighting")
|
|
parser.add_argument(
|
|
"--include-env", action="store_true", help="Include environment variables in context"
|
|
)
|
|
parser.add_argument("-c", "--context", action="append", help="Additional context files")
|
|
parser.add_argument(
|
|
"--api-mode", action="store_true", help="API mode for specialized interaction"
|
|
)
|
|
parser.add_argument(
|
|
"--output", choices=["text", "json", "structured"], default="text", help="Output format"
|
|
)
|
|
parser.add_argument("--quiet", action="store_true", help="Minimal output")
|
|
parser.add_argument("--save-session", metavar="NAME", help="Save session with given name")
|
|
parser.add_argument("--load-session", metavar="NAME", help="Load session with given name")
|
|
parser.add_argument("--list-sessions", action="store_true", help="List all saved sessions")
|
|
parser.add_argument("--delete-session", metavar="NAME", help="Delete a saved session")
|
|
parser.add_argument(
|
|
"--export-session", nargs=2, metavar=("NAME", "FILE"), help="Export session to file"
|
|
)
|
|
parser.add_argument("--usage", action="store_true", help="Show token usage statistics")
|
|
parser.add_argument(
|
|
"--create-config", action="store_true", help="Create default configuration file"
|
|
)
|
|
parser.add_argument("--plugins", action="store_true", help="List loaded plugins")
|
|
args = parser.parse_args()
|
|
if args.create_config:
|
|
from rp.core.config_loader import create_default_config
|
|
|
|
if create_default_config():
|
|
print("Configuration file created at ~/.prrc")
|
|
else:
|
|
print("Error creating configuration file", file=sys.stderr)
|
|
return
|
|
if args.list_sessions:
|
|
from rp.core.session import SessionManager
|
|
|
|
sm = SessionManager()
|
|
sessions = sm.list_sessions()
|
|
if not sessions:
|
|
print("No saved sessions found")
|
|
else:
|
|
print(f"Found {len(sessions)} saved sessions:\n")
|
|
for sess in sessions:
|
|
print(f" {sess['name']}")
|
|
print(f" Created: {sess['created_at']}")
|
|
print(f" Messages: {sess['message_count']}")
|
|
print()
|
|
return
|
|
if args.delete_session:
|
|
from rp.core.session import SessionManager
|
|
|
|
sm = SessionManager()
|
|
if sm.delete_session(args.delete_session):
|
|
print(f"Session '{args.delete_session}' deleted")
|
|
else:
|
|
print(f"Error deleting session '{args.delete_session}'", file=sys.stderr)
|
|
return
|
|
if args.export_session:
|
|
from rp.core.session import SessionManager
|
|
|
|
sm = SessionManager()
|
|
name, output_file = args.export_session
|
|
format_type = "json"
|
|
if output_file.endswith(".md"):
|
|
format_type = "markdown"
|
|
elif output_file.endswith(".txt"):
|
|
format_type = "txt"
|
|
if sm.export_session(name, output_file, format_type):
|
|
print(f"Session exported to {output_file}")
|
|
else:
|
|
print(f"Error exporting session", file=sys.stderr)
|
|
return
|
|
if args.usage:
|
|
from rp.core.usage_tracker import UsageTracker
|
|
|
|
usage = UsageTracker.get_total_usage()
|
|
print(f"\nTotal Usage Statistics:")
|
|
print(f" Requests: {usage['total_requests']}")
|
|
print(f" Tokens: {usage['total_tokens']:,}")
|
|
print(f" Estimated Cost: ${usage['total_cost']:.4f}")
|
|
return
|
|
if args.plugins:
|
|
from rp.plugins.loader import PluginLoader
|
|
|
|
loader = PluginLoader()
|
|
loader.load_plugins()
|
|
plugins = loader.list_loaded_plugins()
|
|
if not plugins:
|
|
print("No plugins loaded")
|
|
else:
|
|
print(f"Loaded {len(plugins)} plugins:")
|
|
for plugin in plugins:
|
|
print(f" - {plugin}")
|
|
return
|
|
assistant = Assistant(args)
|
|
assistant.run()
|
|
|
|
|
|
def main():
|
|
return main_def()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|