DD-338 Phase A.2 (narrowed) — syncthing list_folders + recent_changes cat-B scope= promotion
Wire the existing A.1 _resolve_scope_folders substrate into the two
remaining cat-B tools surfaced by the spec's Phase 0 audit:
* syncthing_list_folders — filter config.folders to the resolved
SYNCTHING_<SCOPE>_FOLDERS[_<INSTANCE>] set; honest matched_total /
returned / filtered_by counts via the existing append_meta envelope
(already shipped for domain_hints in A.2.dom.c).
* syncthing_recent_changes — filter the /rest/events stream to events
whose data.folderID is in the scoped set; gain _meta envelope via
append_meta. Events without a folderID (system-level events) drop out
under an active scope filter — system events do not partition by
folder scope.
OQ-4 resolution (Syncthing event key): events carry `data.folderID` not
`data.folder` (confirmed at branch checkout against the existing concise
projection at tools/system.py:158 + Syncthing 1.27.x REST schema). Filter
keys on `e.get("data", {}).get("folderID")`.
Reuses A.1 substrate verbatim — no greenfield scope mechanism.
Tests: +15 cases in tests/test_a2_catB.py (7 list_folders + 8
recent_changes), incl. determinism harnesses (N=5 byte-equal modulo
latency_ms). 1 modified existing recent_changes test in
test_tools_system.py to use split_meta after the envelope addition.
Suite: 133 → 151 (all green).
Per architect amendment 2026-05-23: spec narrowed from 34-tool sweep to
this 2-tool cat-B promotion. The 32 cat-A (honest scope_none) + cat-D
(write verb) tools in the original spec are already conformant via
pack-spec v4.4.0's honest-declaration path; no edits to those rows.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
4 files changed
+405
-14
No files matched your search
@@ -4,7 +4,7 @@ import time
|
||||
from typing import Any
|
||||
|
||||
from syncthing_mcp.formatters import append_meta, fmt, format_folder
|
||||
from syncthing_mcp.models import ReadParams
|
||||
from syncthing_mcp.models import ReadParams, _resolve_scope_folders
|
||||
from syncthing_mcp.registry import (
|
||||
get_all_instances,
|
||||
get_instance,
|
||||
@@ -66,15 +66,28 @@ async def syncthing_list_instances(params: ReadParams) -> str:
|
||||
async def syncthing_list_folders(params: ReadParams) -> str:
|
||||
"""All configured folders with labels, types, and device counts.
|
||||
|
||||
DD-338 A.2 — accepts ``scope=work|personal|family|home|infrastructure``
|
||||
mapped to ``SYNCTHING_<SCOPE>_FOLDERS[_<INSTANCE>]`` env var; filters
|
||||
``config.folders`` to the resolved folder-ID set via the A.1
|
||||
``_resolve_scope_folders`` substrate. ``scope=public`` raises.
|
||||
|
||||
DD-338 A.2.dom.c — emits per-record ``domain_hints`` in the ``_meta``
|
||||
envelope when the user has configured matching patterns via the
|
||||
BladeConfigStore.
|
||||
"""
|
||||
start = time.perf_counter()
|
||||
try:
|
||||
scope_set, redactions = _resolve_scope_folders(params.scope, params.instance)
|
||||
client = get_instance(params.instance)
|
||||
config = await client._get("/rest/config")
|
||||
folders = config.get("folders", [])
|
||||
all_folders = config.get("folders", [])
|
||||
matched_total = len(all_folders)
|
||||
filtered_by: list[str] = []
|
||||
if scope_set is not None:
|
||||
folders = [f for f in all_folders if f.get("id") in scope_set]
|
||||
filtered_by.append(f"scope={params.scope}")
|
||||
else:
|
||||
folders = all_folders
|
||||
if params.concise:
|
||||
result = [format_folder(f, concise=True) for f in folders]
|
||||
else:
|
||||
@@ -104,10 +117,10 @@ async def syncthing_list_folders(params: ReadParams) -> str:
|
||||
latency_ms = int((time.perf_counter() - start) * 1000)
|
||||
return append_meta(
|
||||
payload,
|
||||
matched_total=len(folders),
|
||||
matched_total=matched_total,
|
||||
returned=len(result),
|
||||
filtered_by=[],
|
||||
redactions=[],
|
||||
filtered_by=filtered_by,
|
||||
redactions=redactions,
|
||||
latency_ms=latency_ms,
|
||||
domain_hints=domain_hints,
|
||||
)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
"""System status, health, errors, log, restart, and upgrade tools."""
|
||||
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
from syncthing_mcp.formatters import fmt, format_bytes, truncate
|
||||
from syncthing_mcp.models import ReadParams, WriteParams
|
||||
from syncthing_mcp.formatters import append_meta, fmt, format_bytes, truncate
|
||||
from syncthing_mcp.models import ReadParams, WriteParams, _resolve_scope_folders
|
||||
from syncthing_mcp.registry import get_instance, handle_error_global
|
||||
from syncthing_mcp.server import mcp
|
||||
|
||||
@@ -138,10 +139,21 @@ async def syncthing_system_log(params: ReadParams) -> str:
|
||||
},
|
||||
)
|
||||
async def syncthing_recent_changes(params: ReadParams) -> str:
|
||||
"""Recent file change events (local and remote) across all folders."""
|
||||
"""Recent file change events (local and remote) across all folders.
|
||||
|
||||
DD-338 A.2 — accepts ``scope=work|personal|family|home|infrastructure``
|
||||
mapped to ``SYNCTHING_<SCOPE>_FOLDERS[_<INSTANCE>]`` env var; filters the
|
||||
event stream to events whose ``data.folderID`` is in the scoped folder
|
||||
set via the A.1 ``_resolve_scope_folders`` substrate. ``scope=public``
|
||||
raises. Events with missing/empty ``folderID`` are filtered out when
|
||||
a scope filter is active (system-level events do not partition by
|
||||
folder scope).
|
||||
"""
|
||||
start = time.perf_counter()
|
||||
try:
|
||||
scope_set, redactions = _resolve_scope_folders(params.scope, params.instance)
|
||||
client = get_instance(params.instance)
|
||||
events = await client._get(
|
||||
events_raw = await client._get(
|
||||
"/rest/events",
|
||||
params={
|
||||
"events": "LocalChangeDetected,RemoteChangeDetected",
|
||||
@@ -149,8 +161,16 @@ async def syncthing_recent_changes(params: ReadParams) -> str:
|
||||
"timeout": "0",
|
||||
},
|
||||
)
|
||||
if not isinstance(events, list):
|
||||
events = []
|
||||
if not isinstance(events_raw, list):
|
||||
events_raw = []
|
||||
matched_total = len(events_raw)
|
||||
filtered_by: list[str] = []
|
||||
if scope_set is not None:
|
||||
events_raw = [
|
||||
e for e in events_raw
|
||||
if (e.get("data", {}).get("folderID") or "") in scope_set
|
||||
]
|
||||
filtered_by.append(f"scope={params.scope}")
|
||||
if params.concise:
|
||||
events = [
|
||||
{
|
||||
@@ -159,14 +179,25 @@ async def syncthing_recent_changes(params: ReadParams) -> str:
|
||||
"path": e.get("data", {}).get("path", ""),
|
||||
"action": e.get("data", {}).get("action", ""),
|
||||
}
|
||||
for e in events
|
||||
for e in events_raw
|
||||
]
|
||||
else:
|
||||
events = events_raw
|
||||
data: dict[str, Any] = {
|
||||
"instance": client.name,
|
||||
"count": len(events),
|
||||
"events": events,
|
||||
}
|
||||
return truncate(fmt(data, concise=params.concise))
|
||||
payload = truncate(fmt(data, concise=params.concise))
|
||||
latency_ms = int((time.perf_counter() - start) * 1000)
|
||||
return append_meta(
|
||||
payload,
|
||||
matched_total=matched_total,
|
||||
returned=len(events),
|
||||
filtered_by=filtered_by,
|
||||
redactions=redactions,
|
||||
latency_ms=latency_ms,
|
||||
)
|
||||
except Exception as e:
|
||||
return handle_error_global(e)
|
||||
|
||||
|
||||
Reference in new issue
Block a user