mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 08:03:15 +00:00
* feat(dashboard): restructure Open SWE Review tab + wire create_prs Restructures the dashboard around two related changes the reviewer settings have been asking for: - Wire profile.create_prs. Defaults to true (opt-out); when off the system prompt gets a `Pull Request Policy Override` section telling the agent to push the branch and notify with the branch URL instead of opening a PR. Removes the noop Slack Notifications / Allow Artifacts / First Name / Last Name controls and their schema fields. - Repositories opt-in for Open SWE Review. New per-team enabled list stored in the LangGraph Store (`["enabled_review_repos"]`). Every reviewer webhook chokepoint now goes through `_is_repo_enabled_for_review` which AND-combines the existing env allowlist with the dashboard list. Default is empty (opt-in) — admins enable repos per-installation from the new Repositories page nested under Open SWE Review. - Open SWE Review tab now mirrors the Cursor "rules" pattern: main page shows installation rows + a Rules entry; both drill into nested pages (/review/repositories/$owner and /review/styles) with a back link. - Adds the new logo/favicon assets shipped from sidebar + html head. Tests pass with a new autouse fixture (`tests/conftest.py`) that defaults `is_review_repo_enabled` to True for existing allowlist tests. * fix(dashboard): make main content scroll independently of the sidebar Outer flex container was min-h-svh, so it grew with main's content and the whole page scrolled — sidebar moved with it. Pin to h-svh + overflow-hidden so the sidebar stays put and only <main> scrolls. * fix(dashboard): make disabled repo toggles obviously disabled Switch's disabled state used opacity-50 against a muted background, so the not-admin state looked nearly identical to the off state. Bump to opacity-40 + grayscale, and wrap each repo toggle in a span carrying a native hover tooltip explaining why it's disabled. * fix(switch): handle base-ui's data-disabled state base-ui's Switch.Root sets data-disabled (not the HTML disabled attribute) when disabled, so Tailwind's disabled: variant never matches and the button keeps its cursor-pointer + clickable look. Mirror the styling under the data-[disabled] variant and add pointer-events-none so the disabled state is both visible and actually unclickable. * feat(dashboard): paginate per-installation repository list 20 repos per page with Prev / page X of Y / Next controls at the bottom. Pager only renders when there are more than 20 repos. Page resets to 0 when navigating between installations. * feat(dashboard): global default model selectors for Agent + Reviewer Adds team-wide default model + reasoning effort for both agents in the Admin tab so operators can switch models without redeploying. Resolution chain: Agent: hardcoded -> LLM_MODEL_ID env -> team default -> user profile Reviewer: hardcoded -> LLM_MODEL_ID env -> team default -> per-call configurable Team defaults live in team_settings and are validated against the SUPPORTED_MODELS allowlist + the model's supported reasoning efforts. 'Inherit from env' clears the override and falls back to LLM_MODEL_ID. * refactor(models): drop LLM_MODEL_ID env in favour of the team default The team default is now the single source of truth for the runtime model choice; per-user (agent) and per-call configurable (reviewer) selections still win on top. When no admin has touched the team default, it surfaces the hardcoded fallback (DEFAULT_MODEL_ID + its default effort), so the admin UI's dropdown is always pre-populated with a sensible value. The Admin UI loses the 'Inherit from env' option since there is no longer an env layer to inherit from. * chore(models): set hardcoded fallback to gpt-5.5 medium Decouple the team-default boot value (gpt-5.5 / medium) from each model's ProfileForm-suggested default_effort so we can change one without nudging the other. The Opus xhigh default for new user profiles is unchanged. * feat(dashboard): trigger-mode copy, Coming Soon badges, logout in My Settings - Rename trigger mode 'ready_for_review' -> 'once_per_pr' with new description copy that matches the screenshot. Legacy stored values fall back to 'every_push' on read so the UI never shows an unknown selection. - Add a 'Coming soon' badge + greyed-out + disabled state on the controls that don't have runtime consumers yet: Trigger Mode, Autofix Mode, Autofix Severity Threshold, and Automatically fix CI failures. SettingsRow grew a comingSoon prop to keep this consistent. - My Settings drops the noop PR Preferences section and adds a Sign Out button. preferred_pr_destination is removed from the profile schema; old records get the field popped on next write. --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
144 lines
4.7 KiB
Python
144 lines
4.7 KiB
Python
"""User profile schema and LangGraph Store CRUD.
|
|
|
|
Storage is split into two namespaces to avoid the read-modify-write race
|
|
between profile-edit writes and OAuth-callback token refreshes:
|
|
|
|
* ``["profiles"]`` — user-editable settings (model, effort, default_repo).
|
|
* ``["oauth_tokens"]`` — encrypted GitHub OAuth access token + email.
|
|
|
|
Each upsert only touches its own namespace, so the two flows can't clobber
|
|
each other's fields even when they interleave.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from datetime import UTC, datetime
|
|
from typing import Any
|
|
|
|
import httpx
|
|
from langgraph_sdk import get_client
|
|
from pydantic import BaseModel, field_validator
|
|
|
|
from ..encryption import decrypt_token, encrypt_token
|
|
from .options import SUPPORTED_MODEL_IDS, model_supports_effort
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
PROFILES_NAMESPACE: list[str] = ["profiles"]
|
|
OAUTH_TOKENS_NAMESPACE: list[str] = ["oauth_tokens"]
|
|
|
|
|
|
class ProfileUpdate(BaseModel):
|
|
default_model: str
|
|
reasoning_effort: str
|
|
default_repo: str | None = None
|
|
base_branch: str | None = None
|
|
branch_prefix: str | None = None
|
|
auto_fix_ci: bool = True
|
|
create_prs: bool = True
|
|
|
|
@field_validator("default_model")
|
|
@classmethod
|
|
def _model_supported(cls, v: str) -> str:
|
|
if v not in SUPPORTED_MODEL_IDS:
|
|
raise ValueError(f"unsupported model: {v}")
|
|
return v
|
|
|
|
def validate_pairing(self) -> None:
|
|
if not model_supports_effort(self.default_model, self.reasoning_effort):
|
|
raise ValueError(
|
|
f"effort {self.reasoning_effort!r} not supported by {self.default_model!r}"
|
|
)
|
|
|
|
|
|
def _client():
|
|
return get_client()
|
|
|
|
|
|
async def _get_value(namespace: list[str], key: str) -> dict[str, Any] | None:
|
|
try:
|
|
item = await _client().store.get_item(namespace, key)
|
|
except httpx.HTTPStatusError as e:
|
|
if e.response.status_code == 404:
|
|
return None
|
|
raise
|
|
if item is None:
|
|
return None
|
|
value = item.get("value") if isinstance(item, dict) else getattr(item, "value", None)
|
|
return value if isinstance(value, dict) else None
|
|
|
|
|
|
async def get_profile(login: str) -> dict[str, Any] | None:
|
|
return await _get_value(PROFILES_NAMESPACE, login)
|
|
|
|
|
|
async def upsert_profile(login: str, email: str, update: ProfileUpdate) -> dict[str, Any]:
|
|
"""Write the user's editable settings.
|
|
|
|
Only touches ``["profiles"]`` — the OAuth token in ``["oauth_tokens"]``
|
|
is untouched, so a concurrent re-login can't be clobbered by this write
|
|
and vice versa.
|
|
"""
|
|
existing = await get_profile(login) or {}
|
|
value: dict[str, Any] = {
|
|
**existing,
|
|
"login": login,
|
|
"email": email or existing.get("email", ""),
|
|
"default_model": update.default_model,
|
|
"reasoning_effort": update.reasoning_effort,
|
|
"default_repo": update.default_repo,
|
|
"base_branch": update.base_branch,
|
|
"branch_prefix": update.branch_prefix,
|
|
"auto_fix_ci": update.auto_fix_ci,
|
|
"create_prs": update.create_prs,
|
|
"updated_at": datetime.now(UTC).isoformat(),
|
|
}
|
|
for stale_field in (
|
|
"first_name",
|
|
"last_name",
|
|
"allow_artifacts",
|
|
"slack_notifications",
|
|
"preferred_pr_destination",
|
|
):
|
|
value.pop(stale_field, None)
|
|
await _client().store.put_item(PROFILES_NAMESPACE, login, value)
|
|
return value
|
|
|
|
|
|
async def upsert_access_token(login: str, email: str, access_token: str) -> None:
|
|
"""Persist (or refresh) the user's encrypted GitHub OAuth token.
|
|
|
|
Only touches ``["oauth_tokens"]`` — the user-editable profile is left
|
|
intact even if a save is in flight in another request.
|
|
"""
|
|
if not access_token:
|
|
return
|
|
value: dict[str, Any] = {
|
|
"login": login,
|
|
"email": email,
|
|
"encrypted_gh_token": encrypt_token(access_token),
|
|
"updated_at": datetime.now(UTC).isoformat(),
|
|
}
|
|
await _client().store.put_item(OAUTH_TOKENS_NAMESPACE, login, value)
|
|
|
|
|
|
async def get_access_token(login: str) -> str | None:
|
|
record = await _get_value(OAUTH_TOKENS_NAMESPACE, login)
|
|
if not record:
|
|
return None
|
|
encrypted = record.get("encrypted_gh_token")
|
|
if not encrypted:
|
|
return None
|
|
return decrypt_token(encrypted) or None
|
|
|
|
|
|
async def list_profiles() -> list[dict[str, Any]]:
|
|
result = await _client().store.search_items(PROFILES_NAMESPACE, limit=1000)
|
|
items = result.get("items") if isinstance(result, dict) else getattr(result, "items", [])
|
|
out: list[dict[str, Any]] = []
|
|
for item in items or []:
|
|
value = item.get("value") if isinstance(item, dict) else getattr(item, "value", None)
|
|
if isinstance(value, dict):
|
|
out.append(value)
|
|
return out
|