[STAGE5] Migrate DigestBot to gateway read tools
lint / hygiene (pull_request) Failing after 30s
standard / check (pull_request) Successful in 12s
lint / hygiene (push) Failing after 24s
standard / check (push) Successful in 11s

This commit is contained in:
architect committed 2026-11-29 22:15:23 +03:00
1 parent 7e30c8df13
commit 235e7b829c
5 files changed
+69 -7

No files matched your search

+3
View File
@@ -31,6 +31,9 @@ direct 127.0.0.1:9120 → blocked
- `HomeBot` мигрирован на gateway (`home.stats`, `home.status`);
- feature flag `HUB_GATEWAY_HOME=1` включён;
- `home.stats` 646 сущностей, `home.status` 77 states;
- `DigestBot` мигрирован на gateway (`catalog.content`, `digest.index`, `prometheus.*`, `seerr.counts`);
- feature flag `HUB_GATEWAY_DIGEST=1` включён;
- digest: индекс 93, targets 35, тревоги 2; Seerr 401 — отдельная auth-проблема;
- hub-bots active, 9 ботов на связи.
## Порядок миграции
@@ -53,6 +53,26 @@ tools:
mode: read
local: home_status
approval: false
- name: catalog.content
mode: read
local: catalog_content
approval: false
- name: digest.index
mode: read
local: digest_index
approval: false
- name: prometheus.targets
mode: read
local: prom_targets
approval: false
- name: prometheus.alerts
mode: read
local: prom_alerts
approval: false
- name: seerr.counts
mode: read
local: seerr_counts
approval: false
- name: audit.write
gateway: http://127.0.0.1:9160/api/sprint/status
mode: write
+1 -1
View File
@@ -27,7 +27,7 @@ GET /v1/models
| S5-04 | Memory | done: SQLite namespaced memory + TTL/search, tests 3/3 |
| S5-05 | Night Shift | done: timers 00:00/07:30, llm-night-start/stop |
| S5-06 | Tool Gateway / agent approvals | done: agent-gw enforced + approval queue; legacy migration = G5 |
| S5-07 | Gate G5 | in_progress: Photo+Book+Home migrated; остальные direct |
| S5-07 | Gate G5 | in_progress: Photo+Book+Home+Digest migrated; остальные direct |
## Tool Gateway runtime
+22
View File
@@ -35,6 +35,12 @@ def _photo_local():
return local
def _hub_module(name):
sys.path.insert(0, "/opt/hub-bots")
import importlib
return importlib.import_module("hub." + name)
def local_call(handler, q=""):
if handler == "photo_stats":
c, err = _photo_local().ImmichDb().counts()
@@ -58,6 +64,22 @@ def local_call(handler, q=""):
if handler == "home_status":
data, err = _photo_local().HomeDb().states()
return {"ok": not bool(err), "data": data, "error": err}
if handler == "catalog_content":
return {"ok": True, "data": _hub_module("catalog").content_state(), "error": None}
if handler == "digest_index":
try:
return {"ok": True, "data": _hub_module("index").stats(), "error": None}
except Exception as e:
return {"ok": False, "data": None, "error": str(e)[:200]}
if handler == "seerr_counts":
data, err = _hub_module("sources").Seerr().counts()
return {"ok": not bool(err), "data": data, "error": err}
if handler == "prom_targets":
data, err = _hub_module("sources").Prom().targets()
return {"ok": not bool(err), "data": data, "error": err}
if handler == "prom_alerts":
data, err = _hub_module("sources").Prom().alerts()
return {"ok": not bool(err), "data": data, "error": err}
raise ValueError("unknown local handler")
+23 -6
View File
@@ -1426,7 +1426,11 @@ class DigestBot(Bot):
def build(self):
parts = [f"**Сводка · {datetime.date.today().strftime('%d.%m.%Y')}**", ""]
c = catalog.content_state()
if os.environ.get("HUB_GATEWAY_DIGEST") == "1":
from .gateway import call
c = call("catalog.content").get("data") or {}
else:
c = catalog.content_state()
jf = c.get("jellyfin") or {}
parts.append(f"**Медиа**: {jf.get('Movie', 0)} фильмов, {jf.get('Series', 0)} сериалов, "
@@ -1444,17 +1448,26 @@ class DigestBot(Bot):
ha = c.get("home") or {}
parts.append(f"**Дом**: {ha.get('total', 0)} сущностей")
prom = Prom()
targets, err = prom.targets()
if os.environ.get("HUB_GATEWAY_DIGEST") == "1":
from .gateway import call
targets = call("prometheus.targets").get("data") or []
alerts = call("prometheus.alerts").get("data") or []
else:
prom = Prom()
targets, err = prom.targets()
alerts, _ = prom.alerts()
if targets:
down = sum(1 for t in targets if t.get("health") != "up")
parts.append(f"**Службы**: {len(targets) - down} в норме, {down} проблемных")
alerts, _ = prom.alerts()
parts.append(f"**Тревоги**: {len(alerts)} активных")
# заявки в Seerr и состояние индекса
try:
counts, _ = Seerr().counts()
if os.environ.get("HUB_GATEWAY_DIGEST") == "1":
from .gateway import call
counts = call("seerr.counts").get("data")
else:
counts, _ = Seerr().counts()
if counts:
parts.append(f"**Заявки**: {counts.get('pending', 0)} в ожидании, "
f"{counts.get('approved', 0)} одобрено, "
@@ -1462,7 +1475,11 @@ class DigestBot(Bot):
except Exception:
pass
try:
s = index.stats()
if os.environ.get("HUB_GATEWAY_DIGEST") == "1":
from .gateway import call
s = call("digest.index").get("data") or {}
else:
s = index.stats()
parts.append(f"**Индекс**: {s['total']} записей "
f"(обновлён {(s['built_at'] or '—')[11:16]})")
except Exception: