Skip to content

fix: 修正了能力词条不出现在第三行识别失败的问题#1125

Merged
MistEO merged 4 commits intomainfrom
fix/essence
Mar 9, 2026
Merged

fix: 修正了能力词条不出现在第三行识别失败的问题#1125
MistEO merged 4 commits intomainfrom
fix/essence

Conversation

@Joe-Bao
Copy link
Contributor

@Joe-Bao Joe-Bao commented Mar 8, 2026

#1107

Summary by Sourcery

错误修复:

  • 确保在任意 OCR 行中出现 slot3 技能时,都能正确检测到 practical essence,而不是只在第三行时才生效。
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Ensure practical essence detection works when the slot3 skill appears in any OCR line rather than only the third line.

Copilot AI review requested due to automatic review settings March 8, 2026 16:52
@Joe-Bao Joe-Bao self-assigned this Mar 8, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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>

Sourcery 对开源项目免费 —— 如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
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>

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 +115 to +116
for i := 0; i < 3; i++ {
id, matched := matchSkillIDEnhanced(3, ocrSkills[i])
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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,并更新日志字段。

Comment on lines 571 to 575
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: 保留实用基质")
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

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

该日志的 Msg 仍包含 <EssenceFilter> 前缀和具体规则名,这与 go-service 的日志规范(上下文用结构化字段,Msg 保持简短)不符。建议增加如 component="EssenceFilter"rule="MatchSlot3Level3Practical" 等字段,并将 Msg 改为简短描述(例如 "keep practical essence"/"rule hit")。参考:.github/instructions/go-service.instructions.md:42-47。

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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>
@MaaEnd MaaEnd deleted a comment from Copilot AI Mar 8, 2026
Copy link
Contributor

Copilot AI commented Mar 8, 2026

@Joe-Bao I've opened a new pull request, #1127, to work on those changes. Once the pull request is ready, I'll request review from you.

)

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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +102 to +110
// 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 {
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

(可选)函数名 MatchSlot3Level3Practical 含 “Level3”,但实际按 minLevel 参数做阈值判断(且 options 里 Slot3MinLevel 可配置,并不固定为 3)。为避免后续误用/误解,建议将函数重命名为更贴合语义的名字(例如强调 minLevel/threshold),或若确实只支持等级 3 则固定阈值并去掉可变参数。

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +42 to 44
log.Error().Err(err).Str("component", "EssenceFilter").Str("step", "LoadDatabase").Msg("load DB failed")
return false
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

日志字段 step 这里用的是 LoadDatabase,但实际调用的是 LoadWeaponDatabase(且上一步已用 LoadMatcherConfig)。为便于按 step 检索和排查问题,建议把 step 名称与实际函数/阶段保持一致(例如 LoadWeaponDatabase / LoadWeaponDB),避免后续出现多个“LoadDatabase”含义不清的情况。

Suggested change
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")

Copilot uses AI. Check for mistakes.
@MistEO MistEO merged commit 4880898 into main Mar 9, 2026
20 checks passed
@MistEO MistEO deleted the fix/essence branch March 9, 2026 06:22
MistEO pushed a commit that referenced this pull request Mar 9, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
MistEO pushed a commit that referenced this pull request Mar 9, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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.

4 participants