From 54cec6bf0c7a8042fecbe055a4cda2bc6a918548 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Thu, 20 Aug 2026 11:26:03 +0700 Subject: [PATCH] improve: add README, .editorconfig, fix fallback models in setup_all.py, update .gitignore --- .editorconfig | 26 ++++++++++++++++++++++++ .gitignore | 5 +++++ README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ setup_all.py | 4 ++-- 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 .editorconfig create mode 100644 README.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0cc0244 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +# EditorConfig helps maintain consistent coding styles across editors and IDEs +# https://editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +max_line_length = 100 + +[*.{py,pyi}] +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab + +[*.{nix}] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false +max_line_length = 0 diff --git a/.gitignore b/.gitignore index 626ac14..6530e8c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,8 @@ whsec*.txt __pycache__/ *.pyc result +*.egg-info/ +.eggs/ +dist/ +build/ +.venv/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..85132f6 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# PR-Agent Server + +Nix-deployed GitHub App server for automated PR review + auto-merge, using a custom LLM endpoint (9router/Omniroute). + +## Architecture + +``` +GitHub webhook → Cloudflare DNS → Caddy (reverse proxy, :4002) + → pr-agent-server (Nix profile, uvicorn) + → PR-Agent github_app.py (FastAPI) + → 9router API (custom OpenAI-compatible endpoint) +``` + +## Components + +| File | Purpose | +|------|---------| +| `run_server.py` | Main FastAPI server — GitHub App webhook handler + analytics/metrics + Discord notifications | +| `auto_merge_bot.py` | Periodic bot that finds reviewed PRs and merges them | +| `trivial_merge.py` | Trivial PR fast-path (docs-only, dependabot, <100 lines) | +| `health-check.py` | Model health watchdog — tests primary + fallback models against 9router | +| `sync-key.py` | Auto-syncs the BWS router key to disk on every service start | +| `generate_manifest.py` | Creates GitHub App manifest URL | +| `callback_server.py` | Dev callback server for receiving GitHub App credentials | +| `flake.nix` | Nix build definition — produces the deployable package | + +## Development + +```bash +# Syntax check all Python files +python3 -m py_compile run_server.py auto_merge_bot.py health-check.py sync-key.py trivial_merge.py callback_server.py generate_manifest.py setup_all.py setup_app.py start_server.py + +# Build with Nix +nix build .#default + +# Deploy (CI does this automatically on push to main) +nix copy --to ssh://user@vps $STORE_PATH +ssh user@vps "sudo /nix/var/nix/profiles/default/bin/nix-env --profile /nix/var/nix/profiles/pr-agent-server --set '$STORE_PATH'" +ssh user@vps "sudo systemctl restart pr-agent-server" +``` + +## Ops + +- **Health watchdog**: cron `pr-agent-health-watchdog` (every 10m) → `~/.hermes/scripts/pr-agent-health-check.sh` +- **Key sync**: systemd `ExecStartPre` → `pr-agent-sync-key` (BWS → disk) +- **Prometheus**: `GET /api/metrics` → `pr_agent_requests_total`, `pr_agent_requests_by_command`, `pr_agent_model_failures` +- **Analytics**: `GET /api/analytics` → JSON summary of recent events + failures +- **Discord**: `POST /api/v1/notify_review` → webhook delivery for review complete/failed + +## Nix Profile Integrity + +After deploy, run `nix-gc-vps.sh` to clean up old generations. The GC script now includes +a repair step that fixes broken profile symlinks before running `nix store gc`, preventing +the issue where profile `-link` dirs get deleted and store paths become unreferenced (see +`devops/pr-agent-deployment` skill for full troubleshooting). diff --git a/setup_all.py b/setup_all.py index b987cce..f2f32c3 100644 --- a/setup_all.py +++ b/setup_all.py @@ -78,8 +78,8 @@ with open(BASE_DIR / ".secrets.toml", "w") as f: # ── 4. Create PR-Agent config ── config_toml = """[config] -model = "claude-opus-4-8" -fallback_models = ["auto/best-coding", "auto/claude-sonnet"] +model = "openai/claude-opus-4-8" +fallback_models = ["openai/ATLAS", "openai/gemini", "openai/text", "openai/deepseek-v4-free"] custom_model_max_tokens = 128000 git_provider = "github" publish_output = true