Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(acl): close review authorization gaps
Maxvint79391a74f98c
diff --git a/core/services/skills.py b/core/services/skills.pyindex 61d51f402..07e8480d6 100644--- a/core/services/skills.py+++ b/core/services/skills.py@@ -469,6 +469,21 @@ def _result_backends(result: dict[str, Any], fallback: Optional[list[str]]) -> lreturn _normalized_backends(fallback) or list(BACKEND_TO_AGENT)+def _removed_backends(result: dict[str, Any], fallback: Optional[list[str]]) -> list[str]:+ if "removedAgents" in result:+ raw_agents = result.get("removedAgents")+ if not isinstance(raw_agents, list):+ return []+ return list(+ dict.fromkeys(+ backend+ for agent in raw_agents+ if (backend := _backend_from_agent_ref(agent)) is not None+ )+ )+ return _normalized_backends(fallback) or list(BACKEND_TO_AGENT)++def _register_created_skill_policies(names: list[str],*,@@ -505,6 +520,20 @@ def _register_created_skill_policies()+def _delete_skill_policies(resource_ids: list[str]) -> None:+ if not resource_ids:+ return+ from storage import resource_access_service+ from storage.db import get_cached_sqlite_engine+ from storage.importer import ensure_sqlite_state++ ensure_sqlite_state()+ engine = get_cached_sqlite_engine()+ with engine.begin() as connection:+ for resource_id in resource_ids:+ resource_access_service.delete_resource_policy(connection, "skill", resource_id)++async def _installed_skill_resource_ids(askill_path: str,name: str,@@ -710,7 +739,18 @@ async def remove_skill(allow_missing_policy=False,)args = ["remove", name, *_target_scope_flag(scope), *_agent_flags(backends)]- return await _run_askill(askill_path, args, cwd=_cwd_for(scope, project_dir))+ result = await _run_askill(askill_path, args, cwd=_cwd_for(scope, project_dir))+ if result.get("ok"):+ removed_backends = _removed_backends(result, backends)+ _delete_skill_policies(+ _resource_ids_for_skill_name(+ name,+ scope=scope,+ project_dir=project_dir,+ backends=removed_backends,+ )+ )+ return resultasync def find_skills(askill_path: str, query: str = "") -> dict[str, Any]:diff --git a/core/vibe_agents.py b/core/vibe_agents.pyindex deae7cbfb..d110351d9 100644--- a/core/vibe_agents.py+++ b/core/vibe_agents.py@@ -167,6 +167,64 @@ class VibeAgent:return asdict(self)+def resolve_effective_default_agent(connection, *, enabled_only: bool = True) -> VibeAgent | None:+ """Resolve the same instance-wide default used by runtime dispatch."""++ raw_name = connection.execute(+ select(state_meta.c.value_json).where(state_meta.c.key == DEFAULT_AGENT_META_KEY).limit(1)+ ).scalar_one_or_none()+ configured_name = _json_loads(raw_name, None)+ candidates = [configured_name, DEFAULT_AGENT_NAME]+ seen: set[str] = set()+ for candidate in candidates:+ if not isinstance(candidate, str) or not candidate.strip():+ continue+ try:+ normalized = normalize_agent_name(candidate)+ except ValueError:+ continue+ if normalized in seen:+ continue+ seen.add(normalized)+ statement = select(agents).where(agents.c.normalized_name == normalized)+ if enabled_only:+ statement = statement.where(agents.c.enabled == 1)+ row = connection.execute(statement.limit(1)).mappings().first()+ if row is not None:+ return VibeAgentStore._from_row(row)++ if not enabled_only:+ return None+ row = connection.execute(select(agents).where(agents.c.enabled == 1).order_by(agents.c.name).limit(1)).mappings().first()+ return VibeAgentStore._from_row(row) if row is not None else None+++def ensure_default_agent_access(+ connection,+ *,+ user_context: Any = None,+ missing_is_error: bool = False,+) -> VibeAgent | None:+ """Resolve and authorize the effective default Agent for a remote caller."""++ from storage import resource_access_service++ context = resolve_resource_access_context(user_context)+ agent = resolve_effective_default_agent(connection)+ if agent is None:+ if context.is_remote or missing_is_error:+ raise LookupError("Default Agent not found")+ return None+ if not resource_access_service.can_use_resource(+ context,+ "agent",+ agent.id,+ connection=connection,+ ):+ raise VibeAgentAccessError("Agent access is not permitted.")+ return agent++@dataclass(frozen=True)class AgentImportCandidate:name: str@@ -575,25 +633,8 @@ class VibeAgentStore:)def get_default_agent(self, *, enabled_only: bool = True) -> Optional[VibeAgent]:- name = self.get_default_agent_name()- if name:- agent = self.get(name)- if agent is not None and (agent.enabled or not enabled_only):- return agent- fallback = self.get(DEFAULT_AGENT_NAME)- if fallback is not None and (fallback.enabled or not enabled_only):- return fallback- if enabled_only:- # This resolver maintains the instance-wide default. It must not let- # one remote caller's ACL-filtered catalog rewrite that global state.- from storage.resource_access_service import ResourceUserContext-- agents_list = self.list_agents(- include_disabled=False,- user_context=ResourceUserContext(is_trusted_local=True),- )- return agents_list[0] if agents_list else None- return None+ with self.engine.connect() as conn:+ return resolve_effective_default_agent(conn, enabled_only=enabled_only)@staticmethoddef _from_row(row: Any) -> VibeAgent:diff --git a/storage/resource_access_service.py b/storage/resource_access_service.pyindex 0a037612b..92d493610 100644--- a/storage/resource_access_service.py+++ b/storage/resource_access_service.py@@ -379,6 +379,24 @@ def ensure_resource_policy(return _serialize_policy(connection, policy)+def delete_resource_policy(connection: Connection, resource_kind: str, resource_id: str) -> bool:+ """Delete local policy state when its local resource is permanently removed."""++ kind = _validate_resource_kind(resource_kind)+ identifier = _required_identifier(resource_id, code="invalid_resource_id")+ connection.execute(+ resource_access_groups.delete()+ .where(resource_access_groups.c.resource_kind == kind)+ .where(resource_access_groups.c.resource_id == identifier)+ )+ result = connection.execute(+ resource_access_policies.delete()+ .where(resource_access_policies.c.resource_kind == kind)+ .where(resource_access_policies.c.resource_id == identifier)+ )+ return bool(result.rowcount)++def _replace_policy_groups(connection: Connection,resource_kind: str,diff --git a/storage/workbench_sessions_service.py b/storage/workbench_sessions_service.pyindex 789893f5c..7bebf221a 100644--- a/storage/workbench_sessions_service.py+++ b/storage/workbench_sessions_service.py@@ -335,14 +335,30 @@ def create_session(if reasoning_effort is None:reasoning_effort = scope_row.get("reasoning_effort")- if agent_name or agent_id:- from core.vibe_agents import ensure_agent_selection_access+ from core.vibe_agents import (+ ensure_agent_selection_access,+ ensure_default_agent_access,+ resolve_resource_access_context,+ )++ context = resolve_resource_access_context(user_context)+ if context.is_remote and not agent_name and not agent_id and not agent_backend:+ default_agent = ensure_default_agent_access(+ conn,+ user_context=context,+ missing_is_error=True,+ )+ assert default_agent is not None+ agent_id = default_agent.id+ agent_name = default_agent.name+ agent_backend = default_agent.backend+ if agent_name or agent_id:ensure_agent_selection_access(conn,agent_name=agent_name,agent_id=agent_id,- user_context=user_context,+ user_context=context,)now = _utc_now_iso()diff --git a/tests/test_resource_acl_agents.py b/tests/test_resource_acl_agents.pyindex 5eeb43e6a..263724e2a 100644--- a/tests/test_resource_acl_agents.py+++ b/tests/test_resource_acl_agents.py@@ -139,8 +139,10 @@ def test_remote_agent_request_and_selection_reject_inaccessible_agent(monkeypatcmonkeypatch.setenv("AVIBE_HOME", str(tmp_path))config = _save_config(tmp_path)store, agents = _seed_agents_with_policies()- store.close()private_agent = agents["private"]+ public_agent = agents["public"]+ store.set_default_agent_name(private_agent.name)+ store.close()context = _organization_context("member-1")client = app.test_client()@@ -192,6 +194,39 @@ def test_remote_agent_request_and_selection_reject_inaccessible_agent(monkeypatcagent_id=private_agent.id,user_context=context,)+ with pytest.raises(VibeAgentAccessError):+ workbench_sessions_service.create_session(+ connection,+ scope_id=scope_id,+ agent_backend="",+ user_context=context,+ )+ blocked_default = client.post(+ "/api/sessions",+ json={"project_id": "proj_acl_agents"},+ headers=csrf_headers(client, "https://alex.avibe.bot"),+ base_url="https://alex.avibe.bot",+ environ_base=_remote_peer(),+ )+ assert blocked_default.status_code == 403++ store = VibeAgentStore()+ try:+ store.set_default_agent_name(public_agent.name)+ finally:+ store.close()+ allowed_default = client.post(+ "/api/sessions",+ json={"project_id": "proj_acl_agents"},+ headers=csrf_headers(client, "https://alex.avibe.bot"),+ base_url="https://alex.avibe.bot",+ environ_base=_remote_peer(),+ )+ assert allowed_default.status_code == 201+ session = allowed_default.get_json()+ assert session["agent_id"] == public_agent.id+ assert session["agent_name"] == public_agent.name+ assert session["agent_backend"] == public_agent.backendwith pytest.raises(VibeAgentAccessError):ScheduledTaskStore(tmp_path / "tasks.json").add_task(diff --git a/tests/test_skills_service.py b/tests/test_skills_service.pyindex 8f6279198..b620d4c79 100644--- a/tests/test_skills_service.py+++ b/tests/test_skills_service.py@@ -80,8 +80,15 @@ def _skill_row(name: str) -> dict:}-def _seed_skill_policy(conn, name: str, *, access_level: str, group_ids: list[str] | None = None) -> str:- resource_id = skills.skill_resource_id("codex", scope="global", project_dir=None, name=name)+def _seed_skill_policy(+ conn,+ name: str,+ *,+ access_level: str,+ group_ids: list[str] | None = None,+ backend: str = "codex",+) -> str:+ resource_id = skills.skill_resource_id(backend, scope="global", project_dir=None, name=name)resource_access_service.ensure_resource_policy(conn,resource_kind="skill",@@ -303,6 +310,15 @@ def test_remote_skill_mutations_require_owner_or_organization_admin(monkeypatch,)) == {"ok": True}assert [call["args"] for call in owner_recorder.calls] == [["list", "-g"], ["remove", "private-skill", "-g"]]+ with engine.connect() as connection:+ assert resource_access_service.get_resource_policy(+ "skill",+ skills.skill_resource_id("codex", scope="global", project_dir=None, name="private-skill"),+ connection=connection,+ ) is None++ with engine.begin() as connection:+ _seed_skill_policy(connection, "private-skill", access_level="private")admin_recorder = _SequenceRecorder([listing, {"ok": True}])monkeypatch.setattr(skills, "_run_askill", admin_recorder)@@ -334,6 +350,61 @@ def test_remote_skill_mutations_require_owner_or_organization_admin(monkeypatch,engine.dispose()+def test_remove_skill_deletes_only_policies_for_removed_backends(monkeypatch, tmp_path) -> None:+ engine = _skills_engine(monkeypatch, tmp_path)+ listing = {+ "ok": True,+ "skills": [+ {+ **_skill_row("shared-skill"),+ "agents": [+ {"id": "codex", "name": "Codex"},+ {"id": "claude", "name": "Claude"},+ ],+ }+ ],+ }+ try:+ with engine.begin() as connection:+ codex_id = _seed_skill_policy(connection, "shared-skill", access_level="private")+ claude_id = _seed_skill_policy(+ connection,+ "shared-skill",+ access_level="private",+ backend="claude",+ )+ recorder = _SequenceRecorder(+ [+ listing,+ {+ "ok": True,+ "selectedAgents": ["codex", "claude"],+ "removedAgents": ["codex"],+ },+ ]+ )+ monkeypatch.setattr(skills, "_run_askill", recorder)++ result = _run(+ skills.remove_skill(+ "askill",+ "shared-skill",+ scope="global",+ backends=["codex", "claude"],+ user_context=_organization_context("owner-1"),+ )+ )+ with engine.connect() as connection:+ codex_policy = resource_access_service.get_resource_policy("skill", codex_id, connection=connection)+ claude_policy = resource_access_service.get_resource_policy("skill", claude_id, connection=connection)+ finally:+ engine.dispose()++ assert result["ok"] is True+ assert codex_policy is None+ assert claude_policy is not None++def test_remote_skill_add_registers_private_policy(monkeypatch, tmp_path) -> None:engine = _skills_engine(monkeypatch, tmp_path)try: