coder - A CLI tool for interacting with coderai API
Connects to OpenAI-compatible API and executes tools automatically.
"""
importos
importsys
importjson
importargparse
importsubprocess
importreadline
importrandom
importstring
frompathlibimportPath
fromtypingimportOptional,Dict,Any,List,Callable
fromdataclassesimportdataclass,field
fromdatetimeimportdatetime
importrequests
# ANSI color codes
classColors:
"""ANSI color codes for terminal output."""
RESET="\033[0m"
BOLD="\033[1m"
DIM="\033[2m"
RED="\033[91m"
GREEN="\033[92m"
YELLOW="\033[93m"
BLUE="\033[94m"
MAGENTA="\033[95m"
CYAN="\033[96m"
WHITE="\033[97m"
# Default system prompt for normal models
DEFAULT_SYSTEM_PROMPT="""You are Coder, an AI coding assistant. You help users write, read, and modify code files. You have access to tools for file operations.
## CRITICAL: Response Format
1. ALWAYS maintain proper spacing between words and after punctuation.
2. Use complete sentences with normal spacing.
3. When showing code, use proper code blocks with language identifiers.
## Available Tools
You can invoke tools by outputting JSON inside <tool> tags: