74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
"""
|
|
Command line interface for PicoGent
|
|
"""
|
|
|
|
import asyncio
|
|
import argparse
|
|
import logging
|
|
import sys
|
|
import os
|
|
from .agent import Agent
|
|
from .config import Config
|
|
|
|
|
|
async def main():
|
|
"""Main CLI entry point"""
|
|
parser = argparse.ArgumentParser(description="PicoGent - Minimal AI Coding Agent")
|
|
parser.add_argument("--verbose", "-v", action="store_true", help="Enable debug logging")
|
|
parser.add_argument("message", nargs="*", help="Message to send to the agent")
|
|
parser.add_argument("--config", "-c", default="config.json", help="Config file path")
|
|
parser.add_argument("--session", "-s", help="Session file path (JSONL)")
|
|
parser.add_argument("--workspace", "-w", help="Workspace directory")
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Setup logging
|
|
log_level = logging.DEBUG if args.verbose else logging.INFO
|
|
logging.basicConfig(
|
|
level=log_level,
|
|
format="[%(name)s] %(message)s",
|
|
stream=sys.stderr
|
|
)
|
|
|
|
# Join message parts
|
|
message = " ".join(args.message) if args.message else None
|
|
|
|
# Read from stdin if no message provided
|
|
if not message:
|
|
if sys.stdin.isatty():
|
|
print("Enter your message (or pipe input):")
|
|
message = input()
|
|
else:
|
|
message = sys.stdin.read().strip()
|
|
|
|
if not message:
|
|
print("Error: No message provided")
|
|
sys.exit(1)
|
|
|
|
# Load config
|
|
try:
|
|
if os.path.exists(args.config):
|
|
config = Config.from_file(args.config)
|
|
else:
|
|
print(f"Warning: Config file '{args.config}' not found, using defaults")
|
|
config = Config()
|
|
except Exception as e:
|
|
print(f"Error loading config: {e}")
|
|
sys.exit(1)
|
|
|
|
# Override workspace if specified
|
|
if args.workspace:
|
|
config.workspace = args.workspace
|
|
|
|
# Create and run agent
|
|
try:
|
|
agent = Agent(config)
|
|
response = await agent.run(message, session_file=args.session)
|
|
print(response)
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |