Files
gabrielvidalandClaude Opus 5.5 4d0dcfa3ff refactor(toolproxy): the tools are plugins — retire the core brokers, the guests' tool groups and the hub editions
Since 2026-11-25 nanobanana, video-extract, 3d-gen, 3d-render, matomo,
movies and meta are live plugins with their own proxies and managed grants,
but the core still served the old path next to them — and its hub editions
won over the plugin skills on workers. This finishes the move (form
ai-agent-moves-to-ai-agent-plugins_o2qxmd, move A). Rebased on 41665fa2,
which had already removed the core's Meta Business.

- gone: toolproxy/{matomo,media,webroutes,owned,catalog}.py, the nanobanana /
  3d-gen / 3d-render / video-extract / matomo / movies routes and the movies
  webhook, cli/skills/{nanobanana,3d-gen,3d-render,video-extract,matomo,
  movies}, the guests' `tools` groups (users store, Caller.tool_groups,
  Me/GuestUser.tools, tools.matomoSites), the User page's Paid tools and
  Tools budget panels
- kept: the /proxy/tools door (tokens, whoami — now the caller's plugins and
  spend — and the shared client), the tool ledger, the tools chip, a guest
  job's tool token (c6e15991: tool_scope still gives one with plugin skills)
- labsync: a plugin skill wins over a lab skill of the same name; plugin
  skills with a proxy keep their hub.json
- guest runs get their plugins' skills on spawn, resume, reply, fork and No
  project runs alike (deps passed to scope_for / scratch_scope everywhere)
- Movies brings Jellyfin when the movies grant comes on (new guest, or the
  owner's switch)
- plugins/carryover_tools.py: tool groups → grants / installs (never over an
  explicit grant), Meta keys + saved days (only where the plugin has none),
  Matomo viewers, Seerr users and pending requests, 3d-gen ownership → the
  plugins' data, once
- matomo_sites: users.json tools.matomoSites → the matomo grant's
  `extraSites` (list grantField, sibling ai-agent-plugins PR), and the grant
  on for an `analytics` guest — once per guest, so Cel (analytics + site 11
  after the groups moved) gets it; an explicit grant only gets extraSites
  when it has none; waits for a matomo manifest with the field
- Me → Budget's Tools card reads the guest's managed plugins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:44:24 +01:00

82 lines
3.1 KiB
Python

"""App-initiated turns into an existing conversation, always preserving guest
scope and active-user checks.
Shared by child-conversation reports (``runs/children.py``), the new-project
flow, and the ``conversations.reply`` plugin hub capability.
"""
from __future__ import annotations
import logging
from users.caller import OWNER, OWNER_ID, OWNER_NAME, guest_from_record
log = logging.getLogger("ai-agent.runs.reply")
APP_TAG = '<ai-agent-from user="ai-agent" name="ai-agent" role="app"/>'
def requester_of(deps, sid: str) -> str:
"""Whose conversation ``sid`` is: its guest owner, else the owner."""
return (deps.meta_store.peek(sid) or {}).get("owner") or OWNER_ID
def caller_of(deps, uid: str):
if uid == OWNER_ID:
return OWNER
u = deps.users.active(uid)
return guest_from_record(u) if u else None
def display_name(deps, uid: str) -> str:
if uid == OWNER_ID:
return OWNER_NAME
return (deps.users.get(uid) or {}).get("name") or uid
def session_cwd(deps, sid: str) -> str | None:
"""Where a session last ran: the cwd of its newest transcript."""
from conversations import ids
from conversations.catalog import _conv_ids_by_session
conv = _conv_ids_by_session(deps).get(sid)
if not conv:
return None
summ = deps.store.get_summary(ids.path_of(conv)) or {}
return summ.get("cwd") or None
def say(deps, sid: str, text: str, tag: str = APP_TAG, *, harness: str | None = "claude",
inbox_only: bool = False) -> dict | None:
"""An app turn in the conversation, run where it already is — with its
guest's scope when a guest owns it.
``harness=None`` keeps the session's own (runs/children.py's report back);
``inbox_only`` only rides a live run (``_send_message``). Returns the
send's answer, or None when it was not sent (a guest no longer enabled)."""
from runs.service import _send_message
from users import runs as guest_runs
requester = requester_of(deps, sid)
scope = None
if requester != OWNER_ID:
caller = caller_of(deps, requester)
if caller is None:
# A guest disabled or deleted since: never their session on the
# owner's permissions (no scope = the owner's run).
log.warning("not resuming %s: its guest %s is not enabled", sid, requester)
return None
slug = ((deps.meta_store.peek(sid) or {}).get("projects") or [None])[0]
if slug and caller.can(slug, "chat"):
scope = guest_runs.scope_for(caller, slug, caller.level(slug),
guest_runs.shared_skills(deps), deps=deps)
else:
scope = {**guest_runs.scope_for(caller, slug or "-", None,
guest_runs.shared_skills(deps), deps=deps),
"writeDirs": ["/tmp"]}
return _send_message(deps, f"{tag}\n{text}", session_id=sid, harness=harness,
cwd=session_cwd(deps, sid), scope=scope, inbox_only=inbox_only)
# Backwards-compatible aliases
_say = say
_caller = caller_of
_name = display_name