free-claude-code/cli/entrypoints.py
Alishahryar1 f3a7528d49
Some checks are pending
CI / checks (push) Waiting to run
Major refactor: API, providers, messaging, and Anthropic protocol
Consolidates the incremental refactor work into a single change set: modular web tools (api/web_tools), native Anthropic request building and SSE block policy, OpenAI conversion and error handling, provider transports and rate limiting, messaging handler and tree queue, safe logging, smoke tests, and broad test coverage.
2026-04-26 03:01:14 -07:00

60 lines
1.8 KiB
Python

"""CLI entry points for the installed package."""
from __future__ import annotations
from pathlib import Path
def _load_env_template() -> str:
"""Load the canonical root env template from package resources or source."""
import importlib.resources
packaged = importlib.resources.files("cli").joinpath("env.example")
if packaged.is_file():
return packaged.read_text("utf-8")
source_template = Path(__file__).resolve().parents[1] / ".env.example"
if source_template.is_file():
return source_template.read_text(encoding="utf-8")
raise FileNotFoundError("Could not find bundled or source .env.example template.")
def serve() -> None:
"""Start the FastAPI server (registered as `free-claude-code` script)."""
import uvicorn
from cli.process_registry import kill_all_best_effort
from config.settings import get_settings
settings = get_settings()
try:
uvicorn.run(
"api.app:create_app",
factory=True,
host=settings.host,
port=settings.port,
log_level="debug",
timeout_graceful_shutdown=5,
)
finally:
kill_all_best_effort()
def init() -> None:
"""Scaffold config at ~/.config/free-claude-code/.env (registered as `fcc-init`)."""
config_dir = Path.home() / ".config" / "free-claude-code"
env_file = config_dir / ".env"
if env_file.exists():
print(f"Config already exists at {env_file}")
print("Delete it first if you want to reset to defaults.")
return
config_dir.mkdir(parents=True, exist_ok=True)
template = _load_env_template()
env_file.write_text(template, encoding="utf-8")
print(f"Config created at {env_file}")
print(
"Edit it to set your API keys and model preferences, then run: free-claude-code"
)