Skip to content

feat(m5a): pallas_webui 改名为 pb_webui#217

Merged
TogetsuDo merged 3 commits into
devfrom
feat/m5a-pb-webui
Jun 16, 2026
Merged

feat(m5a): pallas_webui 改名为 pb_webui#217
TogetsuDo merged 3 commits into
devfrom
feat/m5a-pb-webui

Conversation

@TogetsuDo

@TogetsuDo TogetsuDo commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

M5a: 将 pallas_webui 插件包重命名为 pb_webui,保留旧包名兼容别名。

Test plan

  • uv run ruff check src/
  • 相关 pytest 通过
  • CI 全绿

Summary by Sourcery

将 WebUI 插件包从 pallas_webui 重命名为 pb_webui,同时保持对旧名称的兼容性并迁移持久化数据。

新功能:

  • 引入 pb_webui 数据目录辅助工具,在首次使用时透明地迁移现有的 pallas_webui 数据。
  • 添加插件包别名机制,将旧的插件包名称解析为其规范名称。

错误修复:

  • 确保插件命令处理程序只对可等待的结果执行 await,而不是对任何非 None 的返回值都进行等待。
  • 在读取插件配置和元数据时单独处理 ImportError,以便在插件缺失时能够优雅地失败。

增强改进:

  • 更新控制台、CLI、运行时和文档中的引用,使用新的 pb_webui 插件包和 ID,同时为两个名称保留日志和帮助信息的可见性。
  • 扩展帮助和可见性逻辑,将 pb_webui 视为基础设施插件,并支持旧名称匹配。
  • 优化插件能力构建逻辑,在忽略缺失的可选插件的同时记录意外错误。

测试:

  • 调整现有测试以针对重命名后的 pb_webui 插件,并增加对插件 SDK 检查清单验证和包别名行为的覆盖。
Original summary in English

Summary by Sourcery

Rename the WebUI plugin package from pallas_webui to pb_webui while maintaining compatibility with the legacy name and migrating persisted data.

New Features:

  • Introduce a pb_webui data directory helper that transparently migrates existing pallas_webui data on first use.
  • Add plugin package aliasing to resolve legacy plugin package names to their canonical forms.

Bug Fixes:

  • Ensure plugin command handlers correctly await only awaitable results instead of any non-None return value.
  • Handle ImportError separately when reading plugin configuration and metadata so missing plugins fail gracefully.

Enhancements:

  • Update console, CLI, runtime, and documentation references to use the new pb_webui plugin package and IDs, preserving logging and help visibility for both names.
  • Extend help and visibility logic to treat pb_webui as an infrastructure plugin and support legacy name matching.
  • Refine plugin capability building to log unexpected errors while ignoring missing optional plugins.

Tests:

  • Adjust existing tests to target the renamed pb_webui plugin and add coverage for plugin SDK checklist validation and package alias behavior.

- matcher:alias_bindings 正式属性、isawaitable 守卫
- capabilities:reload_policy 读取失败打日志
- checklist:补充 extra=None 与脏行测试
- 目录/测试/文档迁移至 src/plugins/pb_webui
- plugin_matrix、help 别名与 WebUI env section id 更新
- 保留 pallas_webui 包名映射与 data/ 目录一次性迁移
- pb_core 控制台 hint 改指向 pb_webui

@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 - 我发现了 3 个问题,并给出了一些整体性的反馈:

  • console/webui/env_sections.py 中,canonical_plugin_package 现在已经在 get_webui_env_section 中使用,但本次 diff 中没有对应的 import;请确保从 src.platform.bot_runtime.plugin_package_aliases 引入它,以避免运行时出现 NameError
  • pb_webui/data_dir.py 中,从 pallas_webui 迁移到 pb_webui 的一次性迁移逻辑使用了 legacy.rename(new_root),但没有做任何错误处理;建议用带日志的 try/except 包裹这一调用,这样在权限问题或跨设备重命名失败时,不会导致启动中断,并且可以回退到直接使用新目录。
AI 代理提示词
Please address the comments from this code review:

## Overall Comments
- In `console/webui/env_sections.py`, `canonical_plugin_package` is now used in `get_webui_env_section` but there is no corresponding import added in the diff; ensure it is imported from `src.platform.bot_runtime.plugin_package_aliases` to avoid a `NameError` at runtime.
- In `pb_webui/data_dir.py`, the one-time migration from `pallas_webui` to `pb_webui` uses `legacy.rename(new_root)` without any error handling; consider wrapping this in a try/except with logging so that permission or cross-device rename failures don’t break startup and can fall back to using the new directory.

## Individual Comments

### Comment 1
<location path="src/console/webui/env_sections.py" line_range="518-519" />
<code_context>
         limit_src = s.model_cls.model_validate(current_values) if current_values is not None else cfg_obj
         base.update(_command_limits_payload_extras(limit_src))
-    elif section_id == "pallas_webui":
+    elif section_id == "pb_webui":
         base.update(_pallas_webui_payload_extras())
     elif section_id == "ingress_dispatch":
         base.update(_ingress_dispatch_payload_extras())
</code_context>
<issue_to_address>
**issue (bug_risk):** webui_env_section_payload 可能应该使用规范化后的 section id,以保证旧的 id 能保持一致地工作。

get_webui_env_section 现在通过 canonical_plugin_package 对 id 进行了规范化,但 webui_env_section_payload 仍然基于原始的 section_id 分支。任何仍然传入 "pallas_webui" 的调用方,只会得到基础 payload,而拿不到 WebUI 特有的额外字段。请在该函数开头对 section_id 做规范化(使用 canonical_plugin_package),或者在所有调用点强制使用规范化后的 id,并据此更新调用代码。
</issue_to_address>

### Comment 2
<location path="tests/plugins/help/test_visibility.py" line_range="23" />
<code_context>
 def test_console_stats_excluded_matches_help_hidden_infra():
     excluded = _visibility.resolve_console_stats_excluded_plugin_names()
-    assert "pallas_webui" in excluded
+    assert "pb_webui" in excluded
     assert "ingress_gate" in excluded
     assert "ingress_gate" in excluded
</code_context>
<issue_to_address>
**suggestion (testing):** 添加一个测试,用于覆盖基于旧包名通过 `PLUGIN_PACKAGE_ALIASES` 匹配 help 插件的场景。

由于 `help/plugin_match.py` 现在使用 `PLUGIN_PACKAGE_ALIASES` 将旧名称(例如 `pallas_webui`)映射到 `pb_webui`,当前测试只检查了规范化后的名称,并没有验证使用旧名称进行 help 查询是否仍然有效。

请补充一个测试(例如放在 `tests/plugins/help/test_plugin_match.py` 中),加载 `pb_webui` 的 help 元数据,并断言通过 `pallas_webui`(以及它的中文别名)发起的查询,仍然可以通过别名映射解析到控制台插件,以此保护 help 体验的向后兼容性。

建议实现如下:

```python
def test_console_stats_excluded_matches_help_hidden_infra():
    excluded = _visibility.resolve_console_stats_excluded_plugin_names()
    assert "pb_webui" in excluded
    assert "ingress_gate" in excluded
    assert "ingress_gate" in excluded


def test_console_help_legacy_aliases_map_to_pb_webui():
    # Ensure legacy console/help package names still resolve to the canonical
    # `pb_webui` package via PLUGIN_PACKAGE_ALIASES, protecting backward
    # compatibility for help queries using old names (including Chinese aliases).
    from help.plugin_match import PLUGIN_PACKAGE_ALIASES

    aliases_for_pb_webui = [
        alias for alias, pkg in PLUGIN_PACKAGE_ALIASES.items()
        if pkg == "pb_webui"
    ]

    # Legacy name must still be supported.
    assert "pallas_webui" in aliases_for_pb_webui

    # There should be at least one additional alias (e.g. Chinese names) mapped
    # to the console/help plugin.
    assert len(aliases_for_pb_webui) >= 2

```

如果 `help.plugin_match` 不是你们项目中 `PLUGIN_PACKAGE_ALIASES` 的正确导入路径,请在 `test_console_help_legacy_aliases_map_to_pb_webui` 中相应调整导入(例如 `from plugins.help.plugin_match import PLUGIN_PACKAGE_ALIASES` 或类似形式)。测试的其余部分可以保持不变。
</issue_to_address>

### Comment 3
<location path="docs/develop/webui.md" line_range="3" />
<code_context>
 控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pallas_webui` 插件挂载,基址 **`/pallas/`**。

-后端 API 实现在主仓 `src/plugins/pallas_webui/`(如 `extended_api.py`);**插件配置热重载**等通用能力在 `src/console/webui/`,一般无需改 API 层即可接入新插件配置(见 [WebUI 插件配置](../common/webui/README.md))。
+后端 API 实现在主仓 `src/plugins/pb_webui/`(如 `extended_api.py`);**插件配置热重载**等通用能力在 `src/console/webui/`,一般无需改 API 层即可接入新插件配置(见 [WebUI 插件配置](../common/webui/README.md))。

 ## 本地联调
</code_context>
<issue_to_address>
**suggestion (typo):** 前一句中的插件名 `pallas_webui` 可能也需要更新为 `pb_webui` 以保持一致。

上一句仍然使用了“产物由主仓 `pallas_webui` 插件挂载…”,而这一行以及路径/文档使用的是 `pb_webui`。如果 `pallas_webui` 并不是一个独立的插件名,建议将该行内代码片段更新为 `pb_webui` 以保持一致性。

```suggestion
控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pb_webui` 插件挂载,基址 **`/pallas/`**。
```
</issue_to_address>

Sourcery 对开源仓库免费使用——如果你觉得这次评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈持续改进评审质量。
Original comment in English

Hey - I've found 3 issues, and left some high level feedback:

  • In console/webui/env_sections.py, canonical_plugin_package is now used in get_webui_env_section but there is no corresponding import added in the diff; ensure it is imported from src.platform.bot_runtime.plugin_package_aliases to avoid a NameError at runtime.
  • In pb_webui/data_dir.py, the one-time migration from pallas_webui to pb_webui uses legacy.rename(new_root) without any error handling; consider wrapping this in a try/except with logging so that permission or cross-device rename failures don’t break startup and can fall back to using the new directory.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `console/webui/env_sections.py`, `canonical_plugin_package` is now used in `get_webui_env_section` but there is no corresponding import added in the diff; ensure it is imported from `src.platform.bot_runtime.plugin_package_aliases` to avoid a `NameError` at runtime.
- In `pb_webui/data_dir.py`, the one-time migration from `pallas_webui` to `pb_webui` uses `legacy.rename(new_root)` without any error handling; consider wrapping this in a try/except with logging so that permission or cross-device rename failures don’t break startup and can fall back to using the new directory.

## Individual Comments

### Comment 1
<location path="src/console/webui/env_sections.py" line_range="518-519" />
<code_context>
         limit_src = s.model_cls.model_validate(current_values) if current_values is not None else cfg_obj
         base.update(_command_limits_payload_extras(limit_src))
-    elif section_id == "pallas_webui":
+    elif section_id == "pb_webui":
         base.update(_pallas_webui_payload_extras())
     elif section_id == "ingress_dispatch":
         base.update(_ingress_dispatch_payload_extras())
</code_context>
<issue_to_address>
**issue (bug_risk):** webui_env_section_payload should probably use the canonicalized section id to keep legacy ids working consistently.

get_webui_env_section now canonicalizes ids via canonical_plugin_package, but webui_env_section_payload still branches on the raw section_id. Any callers still passing "pallas_webui" will get only the base payload and miss the WebUI-specific extras. Please either normalize section_id at the start of this function (using canonical_plugin_package) or enforce canonical ids at all call sites and update them accordingly.
</issue_to_address>

### Comment 2
<location path="tests/plugins/help/test_visibility.py" line_range="23" />
<code_context>
 def test_console_stats_excluded_matches_help_hidden_infra():
     excluded = _visibility.resolve_console_stats_excluded_plugin_names()
-    assert "pallas_webui" in excluded
+    assert "pb_webui" in excluded
     assert "ingress_gate" in excluded
     assert "ingress_gate" in excluded
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test to cover help plugin matching against the legacy package name via `PLUGIN_PACKAGE_ALIASES`

Since `help/plugin_match.py` now uses `PLUGIN_PACKAGE_ALIASES` to map legacy names (e.g. `pallas_webui`) to `pb_webui`, the current test only checks the canonical name and doesn’t confirm that help lookups via the old name still work.

Please add a test (e.g. in `tests/plugins/help/test_plugin_match.py`) that loads help metadata for `pb_webui` and asserts that queries using `pallas_webui` (and its Chinese aliases) still resolve to the console plugin via the alias map, to protect backward compatibility of the help UX.

Suggested implementation:

```python
def test_console_stats_excluded_matches_help_hidden_infra():
    excluded = _visibility.resolve_console_stats_excluded_plugin_names()
    assert "pb_webui" in excluded
    assert "ingress_gate" in excluded
    assert "ingress_gate" in excluded


def test_console_help_legacy_aliases_map_to_pb_webui():
    # Ensure legacy console/help package names still resolve to the canonical
    # `pb_webui` package via PLUGIN_PACKAGE_ALIASES, protecting backward
    # compatibility for help queries using old names (including Chinese aliases).
    from help.plugin_match import PLUGIN_PACKAGE_ALIASES

    aliases_for_pb_webui = [
        alias for alias, pkg in PLUGIN_PACKAGE_ALIASES.items()
        if pkg == "pb_webui"
    ]

    # Legacy name must still be supported.
    assert "pallas_webui" in aliases_for_pb_webui

    # There should be at least one additional alias (e.g. Chinese names) mapped
    # to the console/help plugin.
    assert len(aliases_for_pb_webui) >= 2

```

If `help.plugin_match` is not the correct import path for `PLUGIN_PACKAGE_ALIASES` in your project layout, adjust the import inside `test_console_help_legacy_aliases_map_to_pb_webui` accordingly (e.g. `from plugins.help.plugin_match import PLUGIN_PACKAGE_ALIASES` or similar). The rest of the test can remain unchanged.
</issue_to_address>

### Comment 3
<location path="docs/develop/webui.md" line_range="3" />
<code_context>
 控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pallas_webui` 插件挂载,基址 **`/pallas/`**。

-后端 API 实现在主仓 `src/plugins/pallas_webui/`(如 `extended_api.py`);**插件配置热重载**等通用能力在 `src/console/webui/`,一般无需改 API 层即可接入新插件配置(见 [WebUI 插件配置](../common/webui/README.md))。
+后端 API 实现在主仓 `src/plugins/pb_webui/`(如 `extended_api.py`);**插件配置热重载**等通用能力在 `src/console/webui/`,一般无需改 API 层即可接入新插件配置(见 [WebUI 插件配置](../common/webui/README.md))。

 ## 本地联调
</code_context>
<issue_to_address>
**suggestion (typo):** The plugin name `pallas_webui` in the preceding sentence may need to be updated to `pb_webui` for consistency.

The previous sentence still uses “产物由主仓 `pallas_webui` 插件挂载…”, while this line and the paths/docs use `pb_webui`. If `pallas_webui` is not a distinct plugin name, consider updating that inline code span to `pb_webui` for consistency.

```suggestion
控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pb_webui` 插件挂载,基址 **`/pallas/`**。
```
</issue_to_address>

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.

Comment on lines +518 to 519
elif section_id == "pb_webui":
base.update(_pallas_webui_payload_extras())

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.

issue (bug_risk): webui_env_section_payload 可能应该使用规范化后的 section id,以保证旧的 id 能保持一致地工作。

get_webui_env_section 现在通过 canonical_plugin_package 对 id 进行了规范化,但 webui_env_section_payload 仍然基于原始的 section_id 分支。任何仍然传入 "pallas_webui" 的调用方,只会得到基础 payload,而拿不到 WebUI 特有的额外字段。请在该函数开头对 section_id 做规范化(使用 canonical_plugin_package),或者在所有调用点强制使用规范化后的 id,并据此更新调用代码。

Original comment in English

issue (bug_risk): webui_env_section_payload should probably use the canonicalized section id to keep legacy ids working consistently.

get_webui_env_section now canonicalizes ids via canonical_plugin_package, but webui_env_section_payload still branches on the raw section_id. Any callers still passing "pallas_webui" will get only the base payload and miss the WebUI-specific extras. Please either normalize section_id at the start of this function (using canonical_plugin_package) or enforce canonical ids at all call sites and update them accordingly.

def test_console_stats_excluded_matches_help_hidden_infra():
excluded = _visibility.resolve_console_stats_excluded_plugin_names()
assert "pallas_webui" in excluded
assert "pb_webui" in excluded

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.

suggestion (testing): 添加一个测试,用于覆盖基于旧包名通过 PLUGIN_PACKAGE_ALIASES 匹配 help 插件的场景。

由于 help/plugin_match.py 现在使用 PLUGIN_PACKAGE_ALIASES 将旧名称(例如 pallas_webui)映射到 pb_webui,当前测试只检查了规范化后的名称,并没有验证使用旧名称进行 help 查询是否仍然有效。

请补充一个测试(例如放在 tests/plugins/help/test_plugin_match.py 中),加载 pb_webui 的 help 元数据,并断言通过 pallas_webui(以及它的中文别名)发起的查询,仍然可以通过别名映射解析到控制台插件,以此保护 help 体验的向后兼容性。

建议实现如下:

def test_console_stats_excluded_matches_help_hidden_infra():
    excluded = _visibility.resolve_console_stats_excluded_plugin_names()
    assert "pb_webui" in excluded
    assert "ingress_gate" in excluded
    assert "ingress_gate" in excluded


def test_console_help_legacy_aliases_map_to_pb_webui():
    # Ensure legacy console/help package names still resolve to the canonical
    # `pb_webui` package via PLUGIN_PACKAGE_ALIASES, protecting backward
    # compatibility for help queries using old names (including Chinese aliases).
    from help.plugin_match import PLUGIN_PACKAGE_ALIASES

    aliases_for_pb_webui = [
        alias for alias, pkg in PLUGIN_PACKAGE_ALIASES.items()
        if pkg == "pb_webui"
    ]

    # Legacy name must still be supported.
    assert "pallas_webui" in aliases_for_pb_webui

    # There should be at least one additional alias (e.g. Chinese names) mapped
    # to the console/help plugin.
    assert len(aliases_for_pb_webui) >= 2

如果 help.plugin_match 不是你们项目中 PLUGIN_PACKAGE_ALIASES 的正确导入路径,请在 test_console_help_legacy_aliases_map_to_pb_webui 中相应调整导入(例如 from plugins.help.plugin_match import PLUGIN_PACKAGE_ALIASES 或类似形式)。测试的其余部分可以保持不变。

Original comment in English

suggestion (testing): Add a test to cover help plugin matching against the legacy package name via PLUGIN_PACKAGE_ALIASES

Since help/plugin_match.py now uses PLUGIN_PACKAGE_ALIASES to map legacy names (e.g. pallas_webui) to pb_webui, the current test only checks the canonical name and doesn’t confirm that help lookups via the old name still work.

Please add a test (e.g. in tests/plugins/help/test_plugin_match.py) that loads help metadata for pb_webui and asserts that queries using pallas_webui (and its Chinese aliases) still resolve to the console plugin via the alias map, to protect backward compatibility of the help UX.

Suggested implementation:

def test_console_stats_excluded_matches_help_hidden_infra():
    excluded = _visibility.resolve_console_stats_excluded_plugin_names()
    assert "pb_webui" in excluded
    assert "ingress_gate" in excluded
    assert "ingress_gate" in excluded


def test_console_help_legacy_aliases_map_to_pb_webui():
    # Ensure legacy console/help package names still resolve to the canonical
    # `pb_webui` package via PLUGIN_PACKAGE_ALIASES, protecting backward
    # compatibility for help queries using old names (including Chinese aliases).
    from help.plugin_match import PLUGIN_PACKAGE_ALIASES

    aliases_for_pb_webui = [
        alias for alias, pkg in PLUGIN_PACKAGE_ALIASES.items()
        if pkg == "pb_webui"
    ]

    # Legacy name must still be supported.
    assert "pallas_webui" in aliases_for_pb_webui

    # There should be at least one additional alias (e.g. Chinese names) mapped
    # to the console/help plugin.
    assert len(aliases_for_pb_webui) >= 2

If help.plugin_match is not the correct import path for PLUGIN_PACKAGE_ALIASES in your project layout, adjust the import inside test_console_help_legacy_aliases_map_to_pb_webui accordingly (e.g. from plugins.help.plugin_match import PLUGIN_PACKAGE_ALIASES or similar). The rest of the test can remain unchanged.

Comment thread docs/develop/webui.md
@@ -2,7 +2,7 @@

控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pallas_webui` 插件挂载,基址 **`/pallas/`**。

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.

suggestion (typo): 前一句中的插件名 pallas_webui 可能也需要更新为 pb_webui 以保持一致。

上一句仍然使用了“产物由主仓 pallas_webui 插件挂载…”,而这一行以及路径/文档使用的是 pb_webui。如果 pallas_webui 并不是一个独立的插件名,建议将该行内代码片段更新为 pb_webui 以保持一致性。

Suggested change
控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pallas_webui` 插件挂载,基址 **`/pallas/`**
控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pb_webui` 插件挂载,基址 **`/pallas/`**
Original comment in English

suggestion (typo): The plugin name pallas_webui in the preceding sentence may need to be updated to pb_webui for consistency.

The previous sentence still uses “产物由主仓 pallas_webui 插件挂载…”, while this line and the paths/docs use pb_webui. If pallas_webui is not a distinct plugin name, consider updating that inline code span to pb_webui for consistency.

Suggested change
控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pallas_webui` 插件挂载,基址 **`/pallas/`**
控制台 UI 由独立仓库 **[Pallas-Bot-WebUI](https://github.com/PallasBot/Pallas-Bot-WebUI)** 构建,产物由主仓 `pb_webui` 插件挂载,基址 **`/pallas/`**

@TogetsuDo TogetsuDo merged commit 11991eb into dev Jun 16, 2026
4 checks passed
@TogetsuDo TogetsuDo deleted the feat/m5a-pb-webui 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