feat: devex help, add Makefile, ruff, pre-commit, and modernize CI

This commit is contained in:
Brooklyn Nicholson 2026-03-09 20:36:51 -05:00
parent 172a38c344
commit f4d7e6a29e
111 changed files with 11655 additions and 10200 deletions

View file

@ -4,14 +4,12 @@ from __future__ import annotations
import json
import logging
from pathlib import Path
from typing import List, Optional
import os
from pathlib import Path
logger = logging.getLogger(__name__)
DEFAULT_CODEX_MODELS: List[str] = [
DEFAULT_CODEX_MODELS: list[str] = [
"gpt-5.3-codex",
"gpt-5.2-codex",
"gpt-5.1-codex-max",
@ -19,10 +17,11 @@ DEFAULT_CODEX_MODELS: List[str] = [
]
def _fetch_models_from_api(access_token: str) -> List[str]:
def _fetch_models_from_api(access_token: str) -> list[str]:
"""Fetch available models from the Codex API. Returns visible models sorted by priority."""
try:
import httpx
resp = httpx.get(
"https://chatgpt.com/backend-api/codex/models?client_version=1.0.0",
headers={"Authorization": f"Bearer {access_token}"},
@ -57,7 +56,7 @@ def _fetch_models_from_api(access_token: str) -> List[str]:
return [slug for _, slug in sortable]
def _read_default_model(codex_home: Path) -> Optional[str]:
def _read_default_model(codex_home: Path) -> str | None:
config_path = codex_home / "config.toml"
if not config_path.exists():
return None
@ -75,7 +74,7 @@ def _read_default_model(codex_home: Path) -> Optional[str]:
return None
def _read_cache_models(codex_home: Path) -> List[str]:
def _read_cache_models(codex_home: Path) -> list[str]:
cache_path = codex_home / "models_cache.json"
if not cache_path.exists():
return []
@ -104,22 +103,22 @@ def _read_cache_models(codex_home: Path) -> List[str]:
sortable.append((rank, slug))
sortable.sort(key=lambda item: (item[0], item[1]))
deduped: List[str] = []
deduped: list[str] = []
for _, slug in sortable:
if slug not in deduped:
deduped.append(slug)
return deduped
def get_codex_model_ids(access_token: Optional[str] = None) -> List[str]:
def get_codex_model_ids(access_token: str | None = None) -> list[str]:
"""Return available Codex model IDs, trying API first, then local sources.
Resolution order: API (live, if token provided) > config.toml default >
local cache > hardcoded defaults.
"""
codex_home_str = os.getenv("CODEX_HOME", "").strip() or str(Path.home() / ".codex")
codex_home = Path(codex_home_str).expanduser()
ordered: List[str] = []
ordered: list[str] = []
# Try live API if we have a token
if access_token: