Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,26 @@
# Default: 8086
# CODEX_OAUTH_PORT=8086


# --- GitHub Copilot ---
# GitHub Copilot provider uses Device Flow OAuth.
# The GitHub OAuth token (long-lived) is used to derive short-lived
# Copilot API tokens (~30 min expiry, refreshed automatically).
#
# Numbered credential format (recommended for multiple accounts):
# COPILOT_1_GITHUB_TOKEN=gho_xxxxx (first GitHub account)
# COPILOT_2_GITHUB_TOKEN=gho_yyyyy (second GitHub account)
#
# Legacy single-credential format:
# COPILOT_GITHUB_TOKEN=gho_xxxxx
#
# Optional: override the default model list
# COPILOT_MODELS=gpt-4o,claude-sonnet-4,gemini-2.5-pro
#
# To obtain a GitHub OAuth token, run the proxy with --add-credential
# and select the Copilot provider, or use the interactive Device Flow
# by starting the proxy without any COPILOT env vars.

# ------------------------------------------------------------------------------
# | [ADVANCED] Debugging / Logging |
# ------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ cache/antigravity/thought_signatures.json

/usage/
.env
.agent/
156 changes: 156 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# LLM-API-Key-Proxy — Agent Instructions

## ⚠️ MANDATORY: Read Before Any Code Change

This repository is a **fork** maintained as a linear commit stack on top of `upstream/dev`.
**You MUST follow the workflow below for every change you make, no exceptions.**

---

## How the Fork Works

```
upstream/dev
├── feat(anthropic): ... ← one clean commit per feature area
├── feat(chutes): ...
├── feat(codex): ...
├── ... (15 more) ...
└── feat: add health endpoints ← HEAD (dev)
```

- `dev` is a **linear stack** of squashed, self-contained commits on `upstream/dev`
- Each commit has a **topic prefix**: `feat(codex):`, `fix(core):`, `feat(tui):`, etc.
- There are **no merge commits** — the history is always flat and linear

---

## Making a Change

### Step 1: Identify which commit owns the files you're changing

```bash
git log --oneline upstream/dev..HEAD
```

Match files to commits:

| File Pattern | Owning Commit Prefix |
|-------------|---------------------|
| `providers/<name>_provider.py` | `feat(<name>):` |
| `providers/utilities/<name>_*` | `feat(<name>):` |
| `providers/copilot_*` | `feat(copilot):` |
| `client/rotating_client.py` | `feat(core):` |
| `client/executor.py`, `streaming.py`, `errors.py` | `feat(core):` |
| `client/transforms.py` | `feat(core):` |
| `proxy_app/main.py` | `feat(core):` |
| `proxy_app/quota_viewer.py` | `feat(tui):` |
| `proxy_app/log_viewer.py` | `feat(tui):` |
| `model_alias_registry.py`, `cross_provider_executor.py` | `feat(model-routing):` |
| `error_handler.py`, `error_tracker.py` | `feat(core):` |
| `credential_manager.py`, `credential_tool.py` | `feat(core):` |
| `tests/*` | `feat: add local test suite` |

### Step 2: Make the change and commit with the `fixup!` prefix

```bash
# Edit files...
git add -A
git commit -m "fixup! feat(codex): Responses API rewrite, dynamic model discovery, and OAuth exports"
```

> **CRITICAL:** The text after `fixup!` must **exactly match** the first line of the
> target commit. Copy it from `git log --oneline`.

### Step 3: Fold it into the correct commit

```bash
GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash upstream/dev
```

This automatically moves your fixup commit next to its target and squashes them.

### Step 4: Push

```bash
git push origin dev --force-with-lease
```

---

## Adding an Entirely New Feature

```bash
# Just commit at the tip with a new prefix:
git add -A
git commit -m "feat(newprovider): add SomeProvider with quota tracking"

# Push
git push origin dev --force-with-lease
```

No fixup needed — new features go at the end of the stack naturally.

---

## Upstream Sync

When the upstream repository updates:

```bash
git fetch upstream
git rebase upstream/dev
# Resolve any conflicts in the specific commit that breaks
git push origin dev --force-with-lease
```

Each commit is replayed one at a time. Conflicts are localized to the specific
commit that touched the affected lines — resolve it there and continue.

---

## Rules

1. **NEVER add raw commits** without a topic prefix. Every commit must be
`feat(<area>):`, `fix(<area>):`, or `fixup! <exact target commit message>`.

2. **NEVER merge branches into dev.** Dev is a linear rebase-only branch.

3. **Always use `--force-with-lease`** when pushing dev (it's a rewritten branch).

4. **One commit per feature area.** If you're fixing something in an existing
area, use `fixup!` + autosquash to fold it back in.

5. **Keep the stack ordered.** Independent providers come first, shared
infrastructure (`core`) in the middle, cross-cutting features (`tui`,
`model-routing`, `copilot`) at the end.

6. **When a rebase conflict occurs during autosquash**, stop and resolve it
carefully. You can always compare with the current file content using
`git stash` to save your work and inspect.

---

## Quick Reference

```bash
# See the full fork stack
git log --oneline upstream/dev..HEAD

# Find which commit owns a file
git log --oneline upstream/dev..HEAD -- path/to/file.py

# Make a fix and fold it in
git commit -m "fixup! <exact commit message from git log>"
GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash upstream/dev

# Sync with upstream
git fetch upstream && git rebase upstream/dev

# Push
git push origin dev --force-with-lease
```

## Additional References

- **Deployment & hot-patching**: `.agent/rules/llm-proxy.md`
- **Development environment**: `.agent/rules/claude.md`
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ COPY src/ ./src/
# Create directories for logs and oauth credentials
RUN mkdir -p logs oauth_creds

# Configure interactive shell: auto-launch TUI + alias
RUN printf '\n# TUI shortcut\nalias tui="python src/proxy_app/main.py"\n\n# Auto-launch TUI on interactive terminal (skip with SKIP_TUI=1)\nif [ -z "$SKIP_TUI" ] && [[ $- == *i* ]] && [ -t 0 ]; then\n exec python src/proxy_app/main.py\nfi\n' >> /root/.bashrc

# Expose the default port
EXPOSE 8000

Expand Down
Loading