Skip to content

refactor(repeater): P5 拆分 + M3 L2 元数据热重载#219

Merged
TogetsuDo merged 3 commits into
devfrom
feat/p5-repeater-m3-l2
Jun 16, 2026
Merged

refactor(repeater): P5 拆分 + M3 L2 元数据热重载#219
TogetsuDo merged 3 commits into
devfrom
feat/p5-repeater-m3-l2

Conversation

@TogetsuDo

@TogetsuDo TogetsuDo commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

  • P5repeater/__init__.py 拆至 handlers/(message / ban / scheduler / lifecycle / helpers),行为不变
  • M3 L2reload_plugin_metadata_l2() 重建 ingress / help / storage / cmd_perm 索引
  • WebUI 插件配置保存后,对 reload_policy: metadata|full 自动触发 L2
  • 修复 M5b 遗留:env_sections 延迟导入 plugin_package_aliases 避免循环依赖

Test plan

  • pytest tests/features/test_plugin_reload*.py tests/plugins/repeater/test_ban_target.py
  • ruff check 通过
  • CI

Summary by Sourcery

将 repeater 插件重构为独立的处理程序模块,并新增 L2 插件元数据热重载机制,在 WebUI 配置保存后重建运行时索引。

Enhancements(增强):

  • 将 repeater 插件逻辑拆分为单独的处理模块,用于消息、封禁、生命周期钩子、调度器以及共享助手,同时保持行为不变。
  • 引入 L2 元数据重载工具,在不卸载 matcher 的前提下重建入口、帮助、存储以及命令权限索引,并通过插件重载 API 对外提供。
  • 将 WebUI 插件配置保存与 L2 元数据重载打通,根据每个插件声明的 reload_policy 触发重载,支持 metadata / full 等策略。
  • 通过规范化插件包别名来统一 WebUI 环境配置区域(environment section)的 ID,避免与别名相关的不一致问题。

Documentation(文档):

  • 更新热重载层级文档,描述已实现的 L2 元数据重载行为以及由 WebUI 触发的工作流。

Tests(测试):

  • 新增测试用例,确保 L2 元数据重载会清空所有相关缓存,并且只会对具有合适重载策略的插件调用。
Original summary in English

Summary by Sourcery

Refactor the repeater plugin into dedicated handler modules and add L2 plugin metadata hot-reload that rebuilds runtime indices after WebUI config saves.

Enhancements:

  • Split repeater plugin logic into separate handler modules for messages, bans, lifecycle hooks, schedulers, and shared helpers while keeping behavior unchanged.
  • Introduce an L2 metadata reload utility that rebuilds ingress, help, storage, and command-permission indices without unloading matchers, and expose it via the plugin reload API.
  • Wire WebUI plugin config saves to trigger L2 metadata reload based on each plugin's declared reload_policy, including support for metadata/full policies.
  • Normalize WebUI environment section IDs through canonical plugin package aliases to avoid alias-related inconsistencies.

Documentation:

  • Update hot-reload tier documentation to describe the implemented L2 metadata reload behavior and WebUI-triggered workflows.

Tests:

  • Add tests ensuring L2 metadata reload clears all relevant caches and is only invoked for plugins with appropriate reload policies.

__init__ 仅保留元数据、生命周期绑定与对外 re-export;
matcher/调度逻辑迁至 handlers/{message,ban,scheduler,lifecycle,helpers}。
行为不变,fanout 仍 lazy import 避免循环依赖。
- reload_plugin_metadata_l2 重建 ingress/help/storage/cmd_perm 缓存
- WebUI 插件配置保存后对 reload_policy metadata/full 触发 L2
- env_sections 延迟导入 plugin_package_aliases 修复循环依赖

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我给出了一些整体性的反馈:

  • 当前针对封禁目标的 CQ 码规范化逻辑(用于消息中循环/try_convert_to_cqcode 的正则表达式和循环)在 extract_ban_reply_raw_from_messagehandlers/ban.py 中的召回处理器里各实现了一遍;建议抽取一个共享的辅助函数,把解析规则集中到一个地方维护。
  • reload_policy_for_plugin_name 中,查找逻辑是直接用 plugin.name 与 WebUI 的 plugin_name 做匹配;如果在其他地方使用了别名或带点号的包路径(例如规范化后的名称),为了避免策略不一致,可能更安全的做法是先进行统一规范化,或是改为与 PluginMetadata.name 对比。
给 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- The CQ-code normalization logic for ban targets (the regex and loop over message/`try_convert_to_cqcode`) is now duplicated between `extract_ban_reply_raw_from_message` and the recall handler in `handlers/ban.py`; consider extracting a shared helper to keep the parsing rules in one place.
- In `reload_policy_for_plugin_name`, the lookup matches `plugin.name` directly against the WebUI `plugin_name`; if aliases or dotted package paths are used elsewhere (e.g., canonicalized names), it may be safer to normalize or compare against `PluginMetadata.name` to avoid policy mismatches.

Sourcery 对开源项目是免费的——如果你觉得我们的 Review 有帮助,欢迎帮忙分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进以后的 Review。
Original comment in English

Hey - I've left some high level feedback:

  • The CQ-code normalization logic for ban targets (the regex and loop over message/try_convert_to_cqcode) is now duplicated between extract_ban_reply_raw_from_message and the recall handler in handlers/ban.py; consider extracting a shared helper to keep the parsing rules in one place.
  • In reload_policy_for_plugin_name, the lookup matches plugin.name directly against the WebUI plugin_name; if aliases or dotted package paths are used elsewhere (e.g., canonicalized names), it may be safer to normalize or compare against PluginMetadata.name to avoid policy mismatches.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The CQ-code normalization logic for ban targets (the regex and loop over message/`try_convert_to_cqcode`) is now duplicated between `extract_ban_reply_raw_from_message` and the recall handler in `handlers/ban.py`; consider extracting a shared helper to keep the parsing rules in one place.
- In `reload_policy_for_plugin_name`, the lookup matches `plugin.name` directly against the WebUI `plugin_name`; if aliases or dotted package paths are used elsewhere (e.g., canonicalized names), it may be safer to normalize or compare against `PluginMetadata.name` to avoid policy mismatches.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

- 抽取 normalize_cq_ban_token / ban_raw_from_recalled_api_payload
- reload_policy 查找经 canonical_plugin_package 对齐旧包名别名
@TogetsuDo TogetsuDo merged commit 282f563 into dev Jun 16, 2026
4 checks passed
@TogetsuDo TogetsuDo deleted the feat/p5-repeater-m3-l2 branch June 16, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant