Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

- **`build_companion_prompt()` 未标记已注入**:读取 uninjected ruminations 后调用 `mark_injected(ids)`,避免重复注入
- **`scheduler/tasks.py` 导入路径错误**:`from .engine.context_injection` → `from ..engine.context_injection`
- **SAN 白名单私聊 scope**:SAN 群分析会跳过 `private_` scope,避免将私聊 ID 当作群号解析

#### Changed

Expand Down
8 changes: 6 additions & 2 deletions cognition/san.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ async def _get_listened_groups(self):
# 方式1: 白名单配置
whitelist = self.plugin.cfg.target_scopes
if whitelist:
logger.debug(f"[SAN] 使用白名单群列表: {whitelist}")
return whitelist
groups = [g for g in whitelist if not str(g).startswith("private_")]
logger.debug(f"[SAN] 使用白名单群列表 (已过滤私聊): {groups}")
return groups
# 方式2: eavesdropping get_active_scopes()
eavesdropping = getattr(self.plugin, "eavesdropping", None)
if eavesdropping and hasattr(eavesdropping, "get_active_scopes"):
Expand Down Expand Up @@ -249,6 +250,9 @@ async def _analyze_group(self, group_id: str) -> dict | None:

async def _fetch_group_messages(self, group_id: str) -> list:
"""通过 NapCat API 获取群消息"""
if not group_id or str(group_id).startswith("private_"):
logger.debug(f"[SAN] 忽略私聊会话消息获取: {group_id}")
return []
try:
platform_insts = self.plugin.context.platform_manager.platform_insts
if not platform_insts:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_san.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@


class SANSystemTests(IsolatedAsyncioTestCase):
async def test_get_listened_groups_filters_private_scopes_from_whitelist(self):
plugin = SimpleNamespace(
cfg=SimpleNamespace(target_scopes=["7001", "private_1001", "7002"]),
)
san = SANSystem(plugin)

groups = await san._get_listened_groups()

self.assertEqual(groups, ["7001", "7002"])

async def test_fetch_group_messages_ignores_private_scope_without_bot_call(self):
bot = SimpleNamespace(call_action=AsyncMock())
plugin = SimpleNamespace(
cfg=SimpleNamespace(san_msg_count_per_group=50),
context=SimpleNamespace(platform_manager=SimpleNamespace(platform_insts=[SimpleNamespace(get_client=lambda: bot)])),
)
san = SANSystem(plugin)

messages = await san._fetch_group_messages("private_1001")

self.assertEqual(messages, [])
bot.call_action.assert_not_called()

async def test_llm_analyze_uses_group_umo_for_provider_lookup(self):
provider = SimpleNamespace(
text_chat=AsyncMock(
Expand Down