Conversation
There was a problem hiding this comment.
Hey - 我发现了 1 个问题
AI 代理提示词
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="agent/go-service/essencefilter/matcher.go" line_range="115-116" />
<code_context>
+ return nil, 0, false
+ }
+
+ for i := 0; i < 3; i++ {
+ id, matched := matchSkillIDEnhanced(3, ocrSkills[i])
+ if matched {
+ slot3Chinese := skillNameByID(id, pool)
</code_context>
<issue_to_address>
**suggestion (performance):** 将 `skillNameByID` 的查找推迟到等级检查之后再执行,以避免不必要的开销。
`skillNameByID` 会对每一个匹配到的 id 调用,即使在 `levels[i] < minLevel` 且候选项被丢弃的情况下也是如此。请只在 `if levels[i] >= minLevel` 代码块中解析 `slot3Chinese`,以避免对不符合条件的条目进行查找,从而减轻这一热点路径的负担。
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="agent/go-service/essencefilter/matcher.go" line_range="115-116" />
<code_context>
+ return nil, 0, false
+ }
+
+ for i := 0; i < 3; i++ {
+ id, matched := matchSkillIDEnhanced(3, ocrSkills[i])
+ if matched {
+ slot3Chinese := skillNameByID(id, pool)
</code_context>
<issue_to_address>
**suggestion (performance):** Defer `skillNameByID` lookup until after the level check to avoid unnecessary work.
`skillNameByID` is invoked for every `matched` id, even when `levels[i] < minLevel` and the candidate is discarded. Resolve `slot3Chinese` only inside the `if levels[i] >= minLevel` block to avoid lookups for non-qualifying entries and keep this hot path lighter.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| for i := 0; i < 3; i++ { | ||
| id, matched := matchSkillIDEnhanced(3, ocrSkills[i]) |
There was a problem hiding this comment.
suggestion (performance): 将 skillNameByID 的查找推迟到等级检查之后再执行,以避免不必要的开销。
skillNameByID 会对每一个匹配到的 id 调用,即使在 levels[i] < minLevel 且候选项被丢弃的情况下也是如此。请只在 if levels[i] >= minLevel 代码块中解析 slot3Chinese,以避免对不符合条件的条目进行查找,从而减轻这一热点路径的负担。
Original comment in English
suggestion (performance): Defer skillNameByID lookup until after the level check to avoid unnecessary work.
skillNameByID is invoked for every matched id, even when levels[i] < minLevel and the candidate is discarded. Resolve slot3Chinese only inside the if levels[i] >= minLevel block to avoid lookups for non-qualifying entries and keep this hot path lighter.
There was a problem hiding this comment.
Pull request overview
该 PR 针对 #1107 中“实用基质(例如医疗3)在第三词条不出现在第 3 行时被误判丢弃”的问题,修正了基于 OCR 顺序直接假定 slot3 位于第三行导致的匹配失败,使“保留实用基质”规则能够在任意 OCR 位置识别到 slot3 池技能时生效。
Changes:
- 调整
MatchSlot3Level3Practical:不再假定ocrSkills[2]就是 slot3,而是遍历 3 条 OCR 技能并用 slot3 技能池 ID 命中来判定。 MatchSlot3Level3Practical返回值扩展为(match, slot3Level, ok),调用方日志与原因说明使用实际命中的技能与等级。
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| agent/go-service/essencefilter/matcher.go | 遍历 OCR 三条技能,按 slot3 技能池命中来判定“实用基质”保留条件,并返回命中的等级用于上层展示/日志。 |
| agent/go-service/essencefilter/actions.go | 适配新的返回值,使用实际命中的 slot3 技能名与等级生成 extendedReason,并更新日志字段。 |
| log.Info(). | ||
| Str("slot3_skill", skills[2]). | ||
| Int("slot3_level", currentSkillLevels[2]). | ||
| Str("slot3_skill", matchResult.SkillsChinese[2]). | ||
| Int("slot3_level", slot3Lv). | ||
| Int("min_level", slot3MinLv). | ||
| Msg("<EssenceFilter> MatchSlot3Level3Practical: 保留实用基质") |
There was a problem hiding this comment.
该日志的 Msg 仍包含 <EssenceFilter> 前缀和具体规则名,这与 go-service 的日志规范(上下文用结构化字段,Msg 保持简短)不符。建议增加如 component="EssenceFilter"、rule="MatchSlot3Level3Practical" 等字段,并将 Msg 改为简短描述(例如 "keep practical essence"/"rule hit")。参考:.github/instructions/go-service.instructions.md:42-47。
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Thanks for the feedback on #1125. I've created this new PR, which merges into #1125, to address your comment. I will work on the changes and keep this PR's description up to date as I make progress. Original PR: #1125 Triggering review: #1125 (comment) > @copilot open a new pull request to apply changes based on [this feedback](#1125 (comment)) <!-- START COPILOT CODING AGENT TIPS --> --- 🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Joe Bao <114393786+Joe-Bao@users.noreply.github.com>
) All 45 log statements in `actions.go` used `<EssenceFilter>` prefixes and embedded context (rule names, step labels) directly in `Msg`, violating the go-service zerolog convention. ## Changes - **Removed `<EssenceFilter>` prefix** from every `Msg` string - **Added `Str("component", "EssenceFilter")`** to all log calls - **Moved contextual identifiers to typed fields**: - Rule names → `Str("rule", "MatchSlot3Level3Practical")` / `Str("rule", "MatchFuturePromising")` - Init steps → `Str("step", "LoadMatcherConfig")` / `"LoadDatabase"` / `"LoadOptions"` / `"ValidatePresets"` / `"FilterWeapons"` / `"BuildSkillCombinations"` (descriptive names instead of `Step2`–`Step7`) - Action scope → `Str("action", "CheckTotal")` / `"RowCollect"` / `"RowNextItem"` / `"CheckItem"` - **Msgs reduced to short English descriptions** Before / after example: ```go // Before log.Info(). Str("slot3_skill", matchResult.SkillsChinese[2]). Int("slot3_level", slot3Lv). Int("min_level", slot3MinLv). Msg("<EssenceFilter> MatchSlot3Level3Practical: 保留实用基质") // After log.Info(). Str("component", "EssenceFilter"). Str("rule", "MatchSlot3Level3Practical"). Str("slot3_skill", matchResult.SkillsChinese[2]). Int("slot3_level", slot3Lv). Int("min_level", slot3MinLv). Msg("keep practical essence") ``` <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/MaaEnd/MaaEnd/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Joe-Bao <114393786+Joe-Bao@users.noreply.github.com>
| // MatchSlot3Level3Practical - 保留实用基质:任一 OCR 技能命中 slot3 池且该技能等级 >= minLevel | ||
| // 注意:OCR 位置不固定对应 slot,需通过匹配 slot3 池的 ID 判定;slot3 技能可能出现在任意位置 | ||
| // 返回值: | ||
| // - match:命中的技能组合,仅包含匹配到的 slot3 技能(固定放在 SkillIDs[2]/SkillsChinese[2])及占位信息;未命中时为 nil | ||
| // - slot3Level:命中的那条 slot3 技能在其 OCR 原始位置上的等级;未命中时为 0 | ||
| // - ok:是否命中 slot3 池且该技能等级满足 minLevel 的布尔标记 | ||
| // 优先度低于 MatchEssenceSkills | ||
| func MatchSlot3Level3Practical(ocrSkills []string, levels [3]int, minLevel int) (*SkillCombinationMatch, bool) { | ||
| if len(ocrSkills) < 3 || minLevel <= 0 || levels[2] < minLevel { | ||
| return nil, false | ||
| func MatchSlot3Level3Practical(ocrSkills []string, levels [3]int, minLevel int) (match *SkillCombinationMatch, slot3Level int, ok bool) { | ||
| if len(ocrSkills) < 3 || minLevel <= 0 { |
There was a problem hiding this comment.
(可选)函数名 MatchSlot3Level3Practical 含 “Level3”,但实际按 minLevel 参数做阈值判断(且 options 里 Slot3MinLevel 可配置,并不固定为 3)。为避免后续误用/误解,建议将函数重命名为更贴合语义的名字(例如强调 minLevel/threshold),或若确实只支持等级 3 则固定阈值并去掉可变参数。
| log.Error().Err(err).Str("component", "EssenceFilter").Str("step", "LoadDatabase").Msg("load DB failed") | ||
| return false | ||
| } |
There was a problem hiding this comment.
日志字段 step 这里用的是 LoadDatabase,但实际调用的是 LoadWeaponDatabase(且上一步已用 LoadMatcherConfig)。为便于按 step 检索和排查问题,建议把 step 名称与实际函数/阶段保持一致(例如 LoadWeaponDatabase / LoadWeaponDB),避免后续出现多个“LoadDatabase”含义不清的情况。
| log.Error().Err(err).Str("component", "EssenceFilter").Str("step", "LoadDatabase").Msg("load DB failed") | |
| return false | |
| } | |
| log.Error().Err(err).Str("component", "EssenceFilter").Str("step", "LoadWeaponDatabase").Msg("load DB failed") | |
| return false | |
| } | |
| log.Info().Str("component", "EssenceFilter").Str("step", "LoadWeaponDatabase").Msg("weapon database loaded") |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
#1107
Summary by Sourcery
错误修复:
Original summary in English
Summary by Sourcery
Bug Fixes: