Skip to content

armgit / avibe

Public Imported from GitHub
0

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.

merge(org): reconcile dev memory MVP with organization ACL

Maxvint051d079ebbe0
diff --cc core/session_turns.py
index 2616d3946,c60c97325..f1191b69f
--- a/core/session_turns.py
+++ b/core/session_turns.py
@@@ -1006,31 -1012,24 +1020,41 @@@ class SessionTurnManager
and owner.strip()
)
)
- user_owner = user_owners[0] if len(user_owners) == 1 else None
- user_metadata = None
- if user_owner:
- user_metadata = {WEB_PUSH_USER_KEY_METADATA: user_owner}
- elif user_owners:
- user_metadata = {WEB_PUSH_USER_KEYS_METADATA: user_owners}
+ web_push_owner = web_push_owners[0] if len(web_push_owners) == 1 else None
+ memory_cli_admitted = all(
+ (row.get("metadata") or {}).get("_memory_cli_admitted") is True for row in segment
+ )
+ memory_ordinary_text = all(
+ (row.get("metadata") or {}).get(MEMORY_ORDINARY_TEXT_METADATA) is True
+ for row in segment
+ )
+ user_metadata = {
+ MEMORY_ORDINARY_TEXT_METADATA: memory_ordinary_text,
+ "_memory_cli_admitted": memory_cli_admitted,
+ }
+ if memory_user:
+ user_metadata[MEMORY_USER_ID_METADATA] = memory_user
+ if web_push_owner:
+ user_metadata[WEB_PUSH_USER_KEY_METADATA] = web_push_owner
+ elif web_push_owners:
+ user_metadata[WEB_PUSH_USER_KEYS_METADATA] = web_push_owners
+ authorization_contexts: dict[str, dict[str, Any]] = {}
+ for row in segment:
+ raw_contexts = (row.get("metadata") or {}).get(
+ WEB_PUSH_AUTHORIZATION_CONTEXTS_METADATA
+ )
+ if not isinstance(raw_contexts, list):
+ continue
+ for raw_context in raw_contexts:
+ if not isinstance(raw_context, dict):
+ continue
+ context_user_key = raw_context.get("user_key")
- if context_user_key in user_owners:
++ if context_user_key in web_push_owners:
+ authorization_contexts[str(context_user_key)] = raw_context
+ if authorization_contexts:
- if user_metadata is None:
- user_metadata = {}
+ user_metadata[WEB_PUSH_AUTHORIZATION_CONTEXTS_METADATA] = list(
+ authorization_contexts.values()
+ )
attachment_specs = resolve_attachment_specs(
conn, session_id=session_id, attachments=queued_attachments
)
diff --cc core/watches.py
index 72b22a91c,2f0fd5d9d..a7e3db1e8
--- a/core/watches.py
+++ b/core/watches.py
@@@ -296,13 -412,13 +417,18 @@@ class ManagedWatchStore
session_policy: Optional[str] = None,
message: Optional[str] = None,
metadata: Optional[dict[str, Any]] = None,
+ user_context: Any = None,
) -> ManagedWatch:
+ from core.vibe_agents import ensure_agent_name_access
+ from storage.resource_access_service import metadata_with_resource_user_context
+
+ ensure_agent_name_access(agent_name, user_context=user_context)
watch = self._watches[watch_id]
+ if mode != watch.mode:
+ # A mode change starts a new lifecycle. Completion and failure
+ # metadata from the old mode remains available in run history, but
+ # must not determine the definition state under the new mode.
+ self._clear_cycle_state(watch)
watch.name = name
watch.session_key = session_key
watch.session_id = session_id
diff --cc tests/test_internal_server.py
index 5e03e6b21,95dc20f98..6799e2363
--- a/tests/test_internal_server.py
+++ b/tests/test_internal_server.py
@@@ -807,9 -1436,12 +1436,25 @@@ def test_async_dispatch_flushes_queue_o
with engine.connect() as conn:
assert messages_service.list_queued(conn, session_id) == []
transcript = messages_service.list_session_messages(conn, session_id=session_id, types=("user",))
++ from storage.models import messages
++
++ metadata_json = conn.execute(
++ select(messages.c.metadata_json).where(
++ messages.c.id == transcript["messages"][0]["id"]
++ )
++ ).scalar_one()
assert [m["text"] for m in transcript["messages"]] == ["q1\nq2"], "the flush persisted one merged user row"
- assert transcript["messages"][0]["author_id"] == "remote:user-a"
- assert "_web_push_user_key" not in transcript["messages"][0]["metadata"]
+ assert transcript["messages"][0]["author_id"] is None
- assert transcript["messages"][0]["metadata"]["_web_push_user_keys"] == [
++ assert not any(
++ key.startswith("_web_push_")
++ for key in transcript["messages"][0]["metadata"]
++ )
++ assert transcript["messages"][0]["metadata"]["_memory_user_id"] == "remote:user-a"
++ persisted_metadata = json.loads(metadata_json)
++ assert persisted_metadata["_web_push_user_keys"] == [
+ "remote:user-a",
+ "push:loopback",
+ ]
def test_cancel_does_not_flush_queue(monkeypatch, tmp_path):
@@@ -2980,48 -3639,21 +3652,51 @@@ def test_flush_mixed_owner_user_rows_ne
message_type=messages_service.QUEUED_TYPE,
text=text,
author_id=owner,
- metadata={"_web_push_user_key": owner, "_memory_user_id": owner},
+ metadata={
+ "_web_push_user_key": owner,
++ "_memory_user_id": owner,
+ "_web_push_authorization_contexts": [
+ {
+ "user_key": owner,
+ "sub": owner.removeprefix("remote:"),
+ "email": f"{owner.removeprefix('remote:')}@example.com",
+ "vibe_instance_role": "editor",
+ "vibe_instance_access_source": "email",
+ "vibe_group_ids": [],
+ }
+ ],
+ },
)
mgr, runs = _manager_capturing_runs()
assert asyncio.run(mgr.flush_queue(session["id"])) is True
- assert [(t, s) for t, s, _ in runs] == [("u1\nu2", SOURCE_HUMAN)]
+ assert [(t, s) for t, s, _ in runs] == [("u1", SOURCE_HUMAN)]
+ assert runs[0][2].user_id == "remote:user-a"
+ with engine.connect() as conn:
+ queued = messages_service.list_queued(conn, session["id"])
+ assert [row["text"] for row in queued] == ["u2"]
with engine.connect() as conn:
transcript = messages_service.list_session_messages(conn, session_id=session["id"], types=("user",))
+ from storage.models import messages
+
+ metadata_json = conn.execute(
+ select(messages.c.metadata_json).where(
+ messages.c.id == transcript["messages"][0]["id"]
+ )
+ ).scalar_one()
- assert transcript["messages"][0]["author_id"] is None
+ assert transcript["messages"][0]["author_id"] == "remote:user-a"
- assert transcript["messages"][0]["metadata"]["_web_push_user_key"] == "remote:user-a"
+ assert not any(
+ key.startswith("_web_push_")
+ for key in transcript["messages"][0]["metadata"]
+ )
++ assert transcript["messages"][0]["metadata"]["_memory_user_id"] == "remote:user-a"
+ persisted_metadata = json.loads(metadata_json)
- assert persisted_metadata["_web_push_user_keys"] == [
- "remote:user-a",
- "remote:user-b",
- ]
++ assert persisted_metadata["_web_push_user_key"] == "remote:user-a"
+ assert [
+ record["user_key"]
+ for record in persisted_metadata["_web_push_authorization_contexts"]
- ] == ["remote:user-a", "remote:user-b"]
++ ] == ["remote:user-a"]
def test_capture_scheduled_provenance_keeps_delivery_drops_routing():
diff --cc tests/test_ui_remote_access_auth.py
index e6414c62a,51c980b13..ef2db3627
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@@ -752,6 -613,29 +752,29 @@@ def test_remote_host_allows_valid_remot
assert response.status_code != 302
+ def test_remote_generic_config_omits_memory_projection(monkeypatch, tmp_path):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ config.memory.processing.llm.base_url = "https://llm.example.test/v1"
+ config.memory.processing.llm.model = "private-model"
+ config.save()
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
- remote_access.make_session_cookie(config, "[email protected]", "user-1"),
++ remote_session_cookie(config, "[email protected]", "user-1"),
+ domain="alex.avibe.bot",
+ )
+
+ response = client.get(
+ "/api/config",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ assert response.status_code == 200
+ assert "memory" not in response.get_json()
+
+
def test_remote_session_info_includes_authenticated_subject(monkeypatch, tmp_path):
monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
config = _save_config(tmp_path)
diff --cc tests/test_ui_session_stream.py
index 571f12bac,a739dc1ba..dcbb666b9
--- a/tests/test_ui_session_stream.py
+++ b/tests/test_ui_session_stream.py
@@@ -126,7 -127,8 +127,8 @@@ def test_route_fire_and_forgets_dispatc
payload = response.get_json()
assert payload["author"] == "user"
assert payload["author_id"] == "remote:user-a"
- assert payload["metadata"]["_web_push_user_key"] == "remote:user-a"
+ assert "_web_push_user_key" not in payload["metadata"]
+ assert payload["metadata"]["_memory_cli_admitted"] is False
assert payload["text"] == "no stream"
# The turn was kicked off fire-and-forget with the session + text.
dispatch_mock.assert_awaited_once()
diff --cc ui/src/components/AppShell.tsx
index 62c7e6ff9,b76cdc8b1..8df242940
--- a/ui/src/components/AppShell.tsx
+++ b/ui/src/components/AppShell.tsx
@@@ -1,6 -1,6 +1,6 @@@
import React, { useEffect, useState } from 'react';
-import { Link, NavLink, Outlet, useLocation } from 'react-router-dom';
+import { Link, Navigate, NavLink, Outlet, useLocation } from 'react-router-dom';
- import { ArrowLeft, Bot, ChevronDown, Cpu, FolderTree, Globe, Grid2x2, Hash, Inbox, LayoutDashboard, LayoutGrid, Link as LinkIcon, Menu, MessageCircle, PlugZap, Plus, Settings, Sparkles, X } from 'lucide-react';
+ import { ArrowLeft, Bot, Brain, ChevronDown, Cpu, FolderTree, Globe, Grid2x2, Hash, Inbox, LayoutDashboard, LayoutGrid, Link as LinkIcon, Menu, MessageCircle, PlugZap, Plus, Settings, Sparkles, X } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import clsx from 'clsx';
@@@ -242,8 -241,19 +244,19 @@@ export const AppShell: React.FC = () =
setConfig(c);
setEnabledPlatforms(getEnabledPlatforms(c));
}).catch(() => {});
- }, [api]);
+ }, [api, capabilities.can_manage_instance]);
+ useEffect(() => {
+ const refreshMemoryNav = () => {
+ void api.getMemorySettings()
+ .then((memory) => setMemoryNavVisible(memoryNavShouldBeVisible(memory)))
+ .catch(() => setMemoryNavVisible(false));
+ };
+ refreshMemoryNav();
+ window.addEventListener('avibe:memory-settings-changed', refreshMemoryNav);
+ return () => window.removeEventListener('avibe:memory-settings-changed', refreshMemoryNav);
+ }, [api]);
+
// Global ⌘K / Ctrl+K toggles the message-search palette. Intercept the chord
// everywhere (it's a deliberate command, so it wins even from the composer);
// the palette's own input/Esc/arrow handling takes over once it is open.
diff --cc vibe/ui_server.py
index 82c1b583c,8614ca537..cff596372
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@@ -3322,31 -3031,8 +3337,31 @@@ def config_get()
# default is never mistaken for a completed setup. The write side
# (``save_config``) already creates the file on the first real save.
config = settings_service.load_config_or_default()
- payload = api.config_to_payload(config)
+ payload = api.client_config_payload(config)
- return jsonify(payload)
+ authorization_context = getattr(g, "authorization_context", None)
+ if authorization_context is not None and authorization_context.can_manage_instance:
+ return jsonify(payload)
+
+ ui_payload = payload.get("ui")
+ return jsonify(
+ {
+ "mode": payload.get("mode"),
+ "version": payload.get("version"),
+ "setup_state": payload.get("setup_state"),
+ "language": payload.get("language"),
+ "ui": {
+ key: ui_payload[key]
+ for key in (
+ "instance_name",
+ "default_instance_name",
+ "chat_message_font_size",
+ "show_agent_activity",
+ "show_tool_calls",
+ )
+ if isinstance(ui_payload, dict) and key in ui_payload
+ },
+ }
+ )
_MODEL_HUB_SERVICE = None
@@@ -7062,18 -6352,17 +7104,18 @@@ async def sessions_bootstrap(session_id
include_metadata_sources=("show_page",),
tail=True,
)
- queued = messages_service.list_queued(conn, session_id)
- draft = messages_service.get_draft(conn, session_id)
+ queued = messages_service.list_queued(conn, session_id) if can_chat else []
+ draft = messages_service.get_draft(conn, session_id) if can_chat else None
- try:
- agents_payload = vibe_api.get_vibe_agents(include_disabled=False)
- except Exception:
- logger.exception("sessions_bootstrap: failed to load Vibe Agents")
- agents_payload = {"agents": [], "default_agent_name": None}
+ agents_payload = {"agents": [], "default_agent_name": None}
+ if can_chat:
+ try:
+ agents_payload = vibe_api.get_vibe_agents(include_disabled=False)
+ except Exception:
+ logger.exception("sessions_bootstrap: failed to load Vibe Agents")
try:
- config_payload = vibe_api.config_to_payload(settings_service.load_config_or_default())
+ config_payload = vibe_api.client_config_payload(settings_service.load_config_or_default())
except Exception:
logger.exception("sessions_bootstrap: failed to load config")
config_payload = None
@@@ -8369,10 -7592,7 +8416,11 @@@ async def sessions_messages_create(sess
"""
from core.services import sessions as workbench_sessions_service
+ from core.web_push_notifications import (
+ WEB_PUSH_AUTHORIZATION_CONTEXTS_METADATA,
+ web_push_authorization_context_record,
+ )
+ from modules.im.message_facts import is_ordinary_workbench_text
from storage import messages_service
from vibe import internal_client
from vibe.sse_broker import broker
@@@ -8384,11 -7606,8 +8434,12 @@@
return jsonify({"error": "text or content is required"}), 400
# A quick-reply click tags the row with the agent message it answers.
quick_reply_for = (payload.get("metadata") or {}).get("quick_reply_for")
+ memory_ordinary_text = is_ordinary_workbench_text(payload, quick_reply_for)
web_push_user_key = _web_push_user_key()
+ web_push_authorization_context = web_push_authorization_context_record(
+ web_push_user_key,
+ getattr(g, "authorization_context", None),
+ )
engine = _projects_engine()
try:
@@@ -8448,15 -7662,6 +8499,18 @@@
# must stay terminal — no new row, no turn.
if workbench_sessions_service.is_session_archived(conn, session_id):
return None
+ message_metadata = {
+ **(payload.get("metadata") or {}),
+ "_web_push_user_key": web_push_user_key,
++ "_memory_user_id": memory_user_id,
++ "_memory_cli_admitted": memory_cli_admitted,
++ "_memory_ordinary_text": memory_ordinary_text,
+ }
+ message_metadata.pop(WEB_PUSH_AUTHORIZATION_CONTEXTS_METADATA, None)
+ if web_push_authorization_context is not None:
+ message_metadata[WEB_PUSH_AUTHORIZATION_CONTEXTS_METADATA] = [
+ web_push_authorization_context
+ ]
row = messages_service.append(
conn,
scope_id=session["scope_id"],