Merged
Conversation
- Add CombatStopRequested exception for graceful combat stop - Add stop_event (threading.Event) to GameContext - Check stop signal in CombatRecognizer.wait_for_phase() - Handle CombatStopRequested in CombatEngine.fight() loop - Use Pydantic Discriminator for multi-type task endpoint - Change task type fields from TaskType enum to Literal strings - Bind task_manager._stop_event to ctx.stop_event on task start
NodeConfig.enemy_rules and enemy_formation_rules now accept list[str | list] to support mixed formats found in YAML combat plans.
for more information, see https://pre-commit.ci
huan-yp
approved these changes
Mar 5, 2026
There was a problem hiding this comment.
Pull request overview
该 PR 旨在修复“按类型枚举/分发”的请求解析问题,并补齐任务停止信号在战斗循环中的传播与响应。
Changes:
- 将各任务请求的
type字段改为Literal[...],以支持基于type的判别联合(discriminated union) - 在 FastAPI 入口使用
Discriminator('type')统一解析任务请求,并将 TaskManager 的停止事件绑定到GameContext - 在战斗识别/引擎循环中新增对停止信号的检查与退出流程,同时扩展配置规则类型
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| autowsgr/server/schemas.py | 用 Literal[TaskType.X] 固化判别字段以支持按类型解析 |
| autowsgr/server/main.py | 引入判别联合请求类型,并将停止事件绑定到上下文 |
| autowsgr/infra/config.py | 放宽规则列表元素类型以支持更复杂结构 |
| autowsgr/context/game_context.py | 在上下文中新增 stop_event 以传递停止信号 |
| autowsgr/combat/recognizer.py | 在轮询识别中检查 stop_event 并抛出停止异常 |
| autowsgr/combat/engine.py | 捕获取消异常并优雅退出战斗循环 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
198
to
199
| if isinstance(request, NormalFightRequest): | ||
| return await _start_normal_fight(ctx, request) |
There was a problem hiding this comment.
这里直接访问并暴露 task_manager._stop_event(私有属性)会造成较强的实现耦合,也让后续替换 TaskManager 实现或事件类型变得困难。建议在 TaskManager 上提供公开的 stop_event 属性/方法(返回与 GameContext.stop_event 兼容的事件对象),并在此处改用公开接口进行绑定。
Suggested change
| if isinstance(request, NormalFightRequest): | |
| return await _start_normal_fight(ctx, request) | |
| # 将任务管理器的停止事件绑定到游戏上下文,优先使用 TaskManager 的公开接口 | |
| stop_event = getattr(task_manager, "stop_event", None) | |
| if stop_event is None: | |
| # 兼容旧实现,退回到私有属性;后续可在 TaskManager 中提供正式接口后移除 | |
| stop_event = getattr(task_manager, "_stop_event") | |
| ctx.stop_event = stop_event |
Comment on lines
+370
to
+372
| enemy_rules: list[str | list] = Field(default_factory=list) | ||
| """索敌规则列表""" | ||
| enemy_formation_rules: list[str] = Field(default_factory=list) | ||
| enemy_formation_rules: list[str | list] = Field(default_factory=list) |
There was a problem hiding this comment.
类型 list[str | list] 中的 list 未参数化,导致元素类型变得过于宽泛(等价于 list[Any]),会削弱静态检查与 IDE 提示,也不利于后续维护。建议为嵌套列表明确元素类型(例如元素允许 str 或 list[str]),或定义一个清晰的类型别名(如 Rule = str | list[str])后复用到两个字段上。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.