backend/memories/ (store + /api/memories, /api/memory), core/filecache.py
(its last caller) and the MemorySummary / MemoryDetail / MemoriesResponse
schemas are gone; Claude's memory folder is the `memories` plugin's
(ai-agent-plugins, plugins/memories).
- graph.read takes its memory nodes from memories_bridge only (no core fallback)
- ConversationDetail no longer carries memoriesRead / memoriesCreated; the
indexer still records the slugs a transcript read (parse/state.py) and the
plugin reads them through hub/conversations?memories=1
- `ai-agent memories [--show SLUG]` and MCP browse("memories") /
read_document("memory") call /api/plugins/memories/actions/{index,get}
(memories_call, the plans_call twin) and say so when the plugin is off
- frontend: business/memories/ removed; /memories and /memories/:slug
redirect to /plugins/memories/memories[/<slug>]; the Details drawer's
Memories card is the plugin's conversation.details slot (saved layouts map
`memories` → pluginSlots), a service page's memories its service.detail
slot; the Files/nav entries, useMemories / fetchMemories, the tags' memory
counts, mock handlers and stale French keys are gone
- authz: the two routes leave lab.read and matrix.golden.txt
- standalone-smoke.sh no longer probes /api/memories (nor /api/plans, gone
since the Plans extraction)
openapi.json / src/generated are left for the coordinator's one re-dump
after Batch 1 merges.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
3.3 KiB
Python
96 lines
3.3 KiB
Python
"""The hub's read of Claude memories once Memories is a live plugin.
|
|
|
|
The twin of :mod:`plugins.plans_bridge`: core code that needs the memory list
|
|
(the Graph plugin's ``graph.read`` bridge) asks the plugin declaring
|
|
``provides: {"memories.index": "<action>"}`` — and, for one memory, that
|
|
plugin's ``get`` action — as the owner.
|
|
|
|
Both degrade quietly: with no provider installed, disabled or failing,
|
|
:func:`list_memories` is ``[]`` and :func:`get_memory` is ``None``
|
|
(``backend/memories/`` left the core on 2026-11-26: the plugin is the only
|
|
reader).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from plugins.store import OWNER_UID
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
PROVIDES = "memories.index"
|
|
|
|
|
|
def _provider(deps) -> tuple[dict[str, Any], str] | None:
|
|
"""The owner's active plugin providing ``memories.index`` → (rec, action)."""
|
|
from plugins.waiting import _providers_for
|
|
|
|
try:
|
|
found = _providers_for(deps, OWNER_UID, PROVIDES)
|
|
except Exception: # noqa: BLE001 — no plugin store (tests, early boot)
|
|
return None
|
|
for rec, _grant in found:
|
|
mf = rec.get("manifest") or {}
|
|
act = (mf.get("provides") or {}).get(PROVIDES)
|
|
if act in (mf.get("actions") or {}):
|
|
return rec, act
|
|
return None
|
|
|
|
|
|
def _run(deps, rec: dict[str, Any], action: str, payload: dict[str, Any]) -> dict[str, Any]:
|
|
from plugins.runner import run_script
|
|
|
|
act = (rec.get("manifest") or {}).get("actions", {}).get(action)
|
|
if not act:
|
|
raise LookupError(action)
|
|
return run_script(deps, deps.plugin_store, OWNER_UID, rec, act["script"],
|
|
payload=payload, timeout_sec=int(act.get("timeoutSec") or 20))
|
|
|
|
|
|
def has_provider(deps) -> bool:
|
|
return _provider(deps) is not None
|
|
|
|
|
|
available = has_provider
|
|
|
|
|
|
def list_memories(deps) -> list[dict[str, Any]]:
|
|
"""Every memory summary (slug, name, description, type, links, projects,
|
|
services, originSessionId…); ``[]`` without the plugin."""
|
|
hit = _provider(deps)
|
|
if hit is None:
|
|
return []
|
|
rec, action = hit
|
|
try:
|
|
res = _run(deps, rec, action, {})
|
|
except Exception as e: # noqa: BLE001 — a broken plugin never breaks the hub
|
|
log.warning("memories.index via %s failed: %s", rec.get("id"), e)
|
|
return []
|
|
mems = res.get("memories") if isinstance(res, dict) else None
|
|
return [m for m in mems if isinstance(m, dict) and m.get("slug")] if isinstance(mems, list) else []
|
|
|
|
|
|
def get_memory(deps, slug: str) -> dict[str, Any] | None:
|
|
"""One memory (body, links…) through the providing plugin's ``get``
|
|
action; ``None`` when absent or without the plugin."""
|
|
hit = _provider(deps)
|
|
if hit is None or not slug:
|
|
return None
|
|
rec, _action = hit
|
|
from plugins.runner import ActionError
|
|
|
|
try:
|
|
res = _run(deps, rec, "get", {"slug": slug})
|
|
except LookupError:
|
|
return None
|
|
except ActionError as e:
|
|
if e.status != 404:
|
|
log.warning("memories get %s via %s failed: %s", slug, rec.get("id"), e.message)
|
|
return None
|
|
except Exception as e: # noqa: BLE001
|
|
log.warning("memories get %s via %s failed: %s", slug, rec.get("id"), e)
|
|
return None
|
|
return res if isinstance(res, dict) and res.get("slug") else None
|