feat(policy): enforce oauth-only two-brain model routing

This commit is contained in:
Prime Backup Bot
2026-03-11 15:35:13 +00:00
parent dd57bfcc88
commit 268a94b556
4 changed files with 101 additions and 0 deletions
+30
View File
@@ -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
+15
View File
@@ -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.
+19
View File
@@ -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.
+37
View File
@@ -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."