picogent-py/picogent/cli.py
Markov 5417980b76 Initial implementation of PicoGent - minimal AI coding agent
- Implemented ReAct loop in agent.py
- Added Anthropic provider using httpx (no SDK)
- Created tools: read, write, edit, bash
- Added session management with JSONL format
- Included configuration system with env var support
- Added CLI interface and example usage
- Minimal dependencies: only httpx
2026-02-22 23:18:02 +01:00

64 lines
1.8 KiB
Python

"""
Command line interface for PicoGent
"""
import asyncio
import argparse
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("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()
# 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())