From 268a94b556cd1b93fb9a735d0e362925c4a6a5ec Mon Sep 17 00:00:00 2001 From: Prime Backup Bot Date: Wed, 11 Mar 2026 15:35:13 +0000 Subject: [PATCH] feat(policy): enforce oauth-only two-brain model routing --- config/model-router.yaml | 30 ++++++++++++++++++++++++++++++ docs/OAUTH_BOOTSTRAP.md | 15 +++++++++++++++ policies/MODEL_POLICY.md | 19 +++++++++++++++++++ scripts/preflight-auth.sh | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 config/model-router.yaml create mode 100644 docs/OAUTH_BOOTSTRAP.md create mode 100644 policies/MODEL_POLICY.md create mode 100755 scripts/preflight-auth.sh diff --git a/config/model-router.yaml b/config/model-router.yaml new file mode 100644 index 0000000..59c85eb --- /dev/null +++ b/config/model-router.yaml @@ -0,0 +1,30 @@ +version: 1 +policy: oauth-only +providers: + openai: + auth: oauth + role: planner + anthropic: + auth: oauth + role: coder +routing: + planning: + provider: openai + architecture: + provider: openai + risk_review: + provider: openai + coding: + provider: anthropic + refactor: + provider: anthropic + fix: + provider: anthropic +fallback: + mode: queue_and_alert + allow_degrade_single_brain: false +guards: + forbid_api_keys: true + required_oauth_providers: + - openai + - anthropic diff --git a/docs/OAUTH_BOOTSTRAP.md b/docs/OAUTH_BOOTSTRAP.md new file mode 100644 index 0000000..4056d89 --- /dev/null +++ b/docs/OAUTH_BOOTSTRAP.md @@ -0,0 +1,15 @@ +# OAuth Bootstrap (Prime) + +Prime requires OAuth sessions for: +- OpenAI (planner brain) +- Anthropic (coder brain) + +## Steps +1. Authenticate OpenAI OAuth in runtime (same pattern as OpenClaw). +2. Authenticate Anthropic OAuth in runtime. +3. Run `scripts/preflight-auth.sh`. +4. Confirm model routing with `config/model-router.yaml`. + +## Notes +- Do not set `OPENAI_API_KEY` / `ANTHROPIC_API_KEY`. +- If OAuth for Anthropic is not available in runtime, Prime must remain in queue+alert mode for coding tasks. diff --git a/policies/MODEL_POLICY.md b/policies/MODEL_POLICY.md new file mode 100644 index 0000000..06c5153 --- /dev/null +++ b/policies/MODEL_POLICY.md @@ -0,0 +1,19 @@ +# Prime Model Policy (v1) + +## Core Principles +- Prime uses **OAuth only** for model providers. +- **API keys are forbidden** for runtime model access. +- Two-brain model is mandatory for engineering workflows: + - **OpenAI brain**: planning, architecture, decomposition, risk analysis, review strategy. + - **Anthropic brain**: implementation/coding execution. + +## Routing Rules +1. Planning/design/review tasks route to OpenAI. +2. Coding/change-implementation tasks route to Anthropic. +3. If implementation fails validation, route back to OpenAI for revised plan. +4. If a provider is unavailable, Prime queues task + alerts operator unless degrade mode is explicitly enabled. + +## Security Rules +- No model API tokens in repository, env files, logs, or chat history. +- Startup preflight must fail if API-key env vars are detected. +- OAuth session state must be handled by provider/runtime auth storage only. diff --git a/scripts/preflight-auth.sh b/scripts/preflight-auth.sh new file mode 100755 index 0000000..6759392 --- /dev/null +++ b/scripts/preflight-auth.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -euo pipefail + +# 1) Block API-key based auth variables +blocked=( + OPENAI_API_KEY + ANTHROPIC_API_KEY + CLAUDE_API_KEY +) + +found=0 +for v in "${blocked[@]}"; do + if [[ -n "${!v:-}" ]]; then + echo "[FAIL] Forbidden env var set: $v" + found=1 + fi +done + +if [[ "$found" -ne 0 ]]; then + echo "[FAIL] OAuth-only policy violated (API key env var present)." + exit 1 +fi + +# 2) Best-effort OpenClaw auth visibility +if command -v openclaw >/dev/null 2>&1; then + status_out="$(openclaw status 2>/dev/null || true)" + if [[ -n "$status_out" ]]; then + echo "[INFO] openclaw status detected." + echo "$status_out" | sed -n '1,12p' + else + echo "[WARN] openclaw status unavailable; verify OAuth sessions manually." + fi +else + echo "[WARN] openclaw CLI not found; cannot verify OAuth session status here." +fi + +echo "[OK] Preflight passed: no API keys detected; OAuth-only policy enforced."