Skip to content

fix(commands): propagate command-group renames and aliases to sub-commands - #9371

Open
he-yufeng wants to merge 1 commit into
AstrBotDevs:masterfrom
he-yufeng:fix/command-group-rename-propagate
Open

fix(commands): propagate command-group renames and aliases to sub-commands#9371
he-yufeng wants to merge 1 commit into
AstrBotDevs:masterfrom
he-yufeng:fix/command-group-rename-propagate

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

问题

#9366:WebUI 里重命名指令组(或给它加别名)后,子指令只认旧前缀,新前缀无响应。

根因是两处快照不同步:子指令注册时把指令组当时的 get_complete_command_names() 快照进 parent_command_names(star_handler.py),而重命名只更新了指令组自身的 group_name 并清了它自己的 _cmpl_cmd_names 缓存(command_management.py 的 _set_filter_fragment),子指令的快照和缓存都没动,于是 get_complete_command_names() 继续返回旧前缀组合。

修法

  • 新增 _refresh_sub_command_names:指令组的 fragment 或别名更新后,递归刷新子过滤器的 parent_command_names 快照并清掉 _cmpl_cmd_names 缓存,嵌套指令组同样处理。
  • _apply_config_to_runtime 里,只要 filter_refCommandGroupFilter 就在 fragment/别名应用后调用它,rename 和 alter alias 两条路都覆盖到。

测试

4 个新测试(tests/test_command_management.py):扁平组重命名、嵌套组重命名、经 _apply_config_to_runtime 的 rename 传播、别名传播。全部通过;tests/test_conversation_commands.py 回归也通过。

Fixes #9366

Summary by Sourcery

Ensure command group renames and aliases are propagated to sub-commands so they match updated prefixes.

New Features:

  • Add helper to refresh sub-command snapshots and caches when a command group’s name or aliases change.

Enhancements:

  • Invoke sub-command refresh during runtime config application for command group filters to keep naming consistent.

Tests:

  • Add tests covering direct and nested command group renames, propagation via runtime config application, and alias propagation to sub-commands.

…mands

Sub-filters snapshot parent_command_names at registration and cache their complete names, so renaming a group left children matching only the old prefix (and the same for alias changes). Refresh the snapshots and clear the caches recursively after the group fragment or aliases are updated.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Jul 24, 2026

@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 - I've reviewed your changes and they look great!


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 指令组重命名后子指令仍匹配旧前缀(parent_command_names 未同步更新)

1 participant