Merge:'fix/RedDot-Log&v2'| 二值化红点v2识别 & 补全maa回调。#299
Conversation
📝 WalkthroughWalkthroughRedDotDetector 从绝对阈值迁移为分项归一化置信度加权(min_confidence),重写预设/独立执行路径、异常返回为结构化 AnalyzeResult、新增置信度/诊断计算与按 key 节流的调试落盘功能。 ChangesRedDotDetector 置信度加权模型重设计
🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
审查者指南重构 RedDotDetector 识别流水线,改为使用带置信度评分的感叹号检测器,并增加更丰富的日志/遥测与自动调试图像导出,同时增强预设/独立模式的交互和错误处理。 文件级变更
提示与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's GuideRefactors the RedDotDetector recognition pipeline to use a confidence-scored exclamation detector with richer logging/telemetry and automatic debug image dumping, and enhances preset/standalone interaction and error handling. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
assets/resource/base/pipeline/Test.json (1)
668-714:⚠️ Potential issue | 🟠 Major | ⚡ Quick win清理仍在使用的 RedDotDetector 旧参数:
Agt_RedDot_Preset仍包含inner_v_min/inner_s_max
在assets/resource/base/pipeline/Dummy.json里,Agt_RedDot_Preset的custom_recognition_param仍使用了inner_v_min/inner_s_max(位于预设参数中)。而Test.json的RedDot_Preset已按 v2 模型迁移到min_confidence,文档明确该模式“不再依赖 removed inner_v_min / inner_s_max thresholds”。当前多处节点仍引用{"preset":"Agt_RedDot_Preset"}(如QuestList.json、Pass.json、Mail.json、GACHA.json、GACHA_ADV.json等),因此这些节点的红点检测很可能不会按 v2 期望的门限生效;需要把Agt_RedDot_Preset也迁移到min_confidence模型并统一参数集。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@assets/resource/base/pipeline/Test.json` around lines 668 - 714, The Agt_RedDot_Preset still uses removed thresholds inner_v_min/inner_s_max while RedDot_Preset has been migrated to the v2 style (min_confidence, gap_ratio, red_area, hsv_ranges, debug); update the Agt_RedDot_Preset definition to the same v2 parameter set (replace inner_v_min/inner_s_max with min_confidence and include gap_ratio, red_area, hsv_ranges, debug as in RedDot_Preset) and then verify/adjust every node that references {"preset":"Agt_RedDot_Preset"} (e.g., nodes similar to CheckPanel_A) to either point to the updated Agt_RedDot_Preset or to RedDot_Preset so all red-dot detections use the unified min_confidence-based thresholds.
🧹 Nitpick comments (1)
agent/recognition/binarymatch.py (1)
398-403: ⚡ Quick win示例里的
CheckPanel_A.roi还是旧值。这里的示例 B 仍然写着
[640, 616, 17, 16],但这次 PR 引用的配置说明已经把CheckPanel_A的 ROI 更新成[723, 616, 18, 18]。这段注释本身就是调参文档,继续保留旧坐标会把后续对照示例的人直接带偏。建议同步成当前示例值,或至少明确标注这是占位示例。As per coding guidelines, "CheckPanel_A: roi changed to [723, 616, 18, 18]; ensure this ROI matches the expected red-dot search region since the detector now crops ROI and applies the new internal blob/confidence logic."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@agent/recognition/binarymatch.py` around lines 398 - 403, The example comment contains an outdated ROI for CheckPanel_A (still [640, 616, 17, 16]); update the example to the new value [723, 616, 18, 18] (or explicitly mark it as a placeholder) so the inline documentation matches the current detector behavior; specifically edit the commented example for "CheckPanel_A" in binarymatch.py to set CheckPanel_A.roi to [723, 616, 18, 18] and, if helpful, add a short note that RedDotDetector now crops the ROI and uses the new internal blob/confidence logic to avoid confusion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agent/recognition/binarymatch.py`:
- Around line 633-650: The code currently conflates reco is None (recognition
not started) with reco.hit == False (recognition ran but missed); update the
logic around Context.run_recognition/preset handling so you first check if reco
is None and return a distinct AnalyzeResult indicating the recognition did not
start (include context like preset_node and any available status), and only if
reco is non-None then branch on reco.hit; when reco.hit is False, return
CustomRecognition.AnalyzeResult(box=None, detail=...) but propagate the preset
node's raw_detail (e.g., reco.raw_detail) into the returned detail along with
result:"miss" and existing roi/hint fields so upstream can see stage/hint/stat
from the preset node rather than masking configuration errors as ordinary
misses.
- Around line 553-555: The module currently parses RDD_DUMP_INTERVAL at import
time into _DUMP_MIN_INTERVAL which can raise ValueError and abort import
(preventing RedDotDetector registration); change this to parse/validate with a
safe fallback at runtime (e.g., in the RedDotDetector initializer or before
first use) or wrap the environment parsing in a try/except that falls back to a
sane default and logs the parse error; ensure the symbol _DUMP_MIN_INTERVAL is
assigned only after validation so imports never raise, and reference
RDD_DUMP_INTERVAL, _DUMP_MIN_INTERVAL, and RedDotDetector (and analyze() if
relevant) when updating the code paths.
---
Outside diff comments:
In `@assets/resource/base/pipeline/Test.json`:
- Around line 668-714: The Agt_RedDot_Preset still uses removed thresholds
inner_v_min/inner_s_max while RedDot_Preset has been migrated to the v2 style
(min_confidence, gap_ratio, red_area, hsv_ranges, debug); update the
Agt_RedDot_Preset definition to the same v2 parameter set (replace
inner_v_min/inner_s_max with min_confidence and include gap_ratio, red_area,
hsv_ranges, debug as in RedDot_Preset) and then verify/adjust every node that
references {"preset":"Agt_RedDot_Preset"} (e.g., nodes similar to CheckPanel_A)
to either point to the updated Agt_RedDot_Preset or to RedDot_Preset so all
red-dot detections use the unified min_confidence-based thresholds.
---
Nitpick comments:
In `@agent/recognition/binarymatch.py`:
- Around line 398-403: The example comment contains an outdated ROI for
CheckPanel_A (still [640, 616, 17, 16]); update the example to the new value
[723, 616, 18, 18] (or explicitly mark it as a placeholder) so the inline
documentation matches the current detector behavior; specifically edit the
commented example for "CheckPanel_A" in binarymatch.py to set CheckPanel_A.roi
to [723, 616, 18, 18] and, if helpful, add a short note that RedDotDetector now
crops the ROI and uses the new internal blob/confidence logic to avoid
confusion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3929bcfa-538f-4d64-8f5a-0d607d67042c
📒 Files selected for processing (2)
agent/recognition/binarymatch.pyassets/resource/base/pipeline/Test.json
🤖 DeepSeek 自动评审报告模型: 概览PR #299 将红点检测器( 阻塞性问题(必须修改)1. 未命中时返回
|
具体在pr中标注.
否决,与事实不符. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agent/recognition/binarymatch.py`:
- Around line 650-665: The preset-mode AnalyzeResult detail is inconsistent: the
hit branch (CustomRecognition.AnalyzeResult in this file around the preset
handling for variable preset_node) only returns {"result","preset"} while the
miss branch embeds the preset node's stage/stat/conf/parts under "preset_detail"
using reco.raw_detail; unify both branches to the same detail schema promised by
the file-level docs by extracting the preset node's stage/stat/conf/parts (from
getattr(reco, "raw_detail", None) or reco.raw_detail) into the same top-level
detail fields (e.g., stage, stat, conf, parts or a single "preset" object) for
both hit and miss, preserve existing keys like
"result","mode","preset","roi","hint", and ensure the hit branch includes the
same preset-related fields so downstream code (MaaLogs/tuning scripts) can rely
on one schema.
- Around line 554-557: The environment parsing for _DUMP_MIN_INTERVAL should
treat NaN, Infinity, and non-positive values as invalid; when reading
RDD_DUMP_INTERVAL (currently via os.environ.get in the module scope), parse with
float inside the existing try/except, then validate with math.isfinite(value)
and value > 0 and fallback to 2.0 if validation fails; keep the existing
exception handling (TypeError, ValueError) and ensure the final assigned symbol
is _DUMP_MIN_INTERVAL with the safe default.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5a72b615-c5cd-483a-ae86-78d5db084686
📒 Files selected for processing (1)
agent/recognition/binarymatch.py
| try: | ||
| _DUMP_MIN_INTERVAL = float(os.environ.get("RDD_DUMP_INTERVAL", "2.0")) | ||
| except (TypeError, ValueError): | ||
| _DUMP_MIN_INTERVAL = 2.0 # 环境变量非法时兜底,避免 import 阶段崩溃中断 Agent 启动 |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
python - <<'PY'
import math
for raw in ("2.0", "nan", "inf", "-1", "oops"):
try:
value = float(raw)
print(raw, "->", value, "isfinite=", math.isfinite(value), "negative=", value < 0)
except Exception as exc:
print(raw, "->", type(exc).__name__)
PYRepository: sunyink/MFABD2
Length of output: 246
[minor] 让 RDD_DUMP_INTERVAL 对 nan/inf/负数 也视为非法并兜底(避免节流失效)
当前 float() 对 RDD_DUMP_INTERVAL=nan/inf 会解析成功而不会触发 try/except(math.isfinite 为 False),后续节流比较可能失效;同时负数也会通过解析并反向影响节流语义。
🩹 建议补丁
+import math
import json
import re
import time
import os
import traceback
@@
try:
- _DUMP_MIN_INTERVAL = float(os.environ.get("RDD_DUMP_INTERVAL", "2.0"))
+ _dump_min_interval = float(os.environ.get("RDD_DUMP_INTERVAL", "2.0"))
+ if not math.isfinite(_dump_min_interval) or _dump_min_interval < 0:
+ raise ValueError
+ _DUMP_MIN_INTERVAL = _dump_min_interval
except (TypeError, ValueError):
_DUMP_MIN_INTERVAL = 2.0 # 环境变量非法时兜底,避免 import 阶段崩溃中断 Agent 启动📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| try: | |
| _DUMP_MIN_INTERVAL = float(os.environ.get("RDD_DUMP_INTERVAL", "2.0")) | |
| except (TypeError, ValueError): | |
| _DUMP_MIN_INTERVAL = 2.0 # 环境变量非法时兜底,避免 import 阶段崩溃中断 Agent 启动 | |
| try: | |
| _dump_min_interval = float(os.environ.get("RDD_DUMP_INTERVAL", "2.0")) | |
| if not math.isfinite(_dump_min_interval) or _dump_min_interval < 0: | |
| raise ValueError | |
| _DUMP_MIN_INTERVAL = _dump_min_interval | |
| except (TypeError, ValueError): | |
| _DUMP_MIN_INTERVAL = 2.0 # 环境变量非法时兜底,避免 import 阶段崩溃中断 Agent 启动 |
🧰 Tools
🪛 Ruff (0.15.15)
[warning] 557-557: Comment contains ambiguous , (FULLWIDTH COMMA). Did you mean , (COMMA)?
(RUF003)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@agent/recognition/binarymatch.py` around lines 554 - 557, The environment
parsing for _DUMP_MIN_INTERVAL should treat NaN, Infinity, and non-positive
values as invalid; when reading RDD_DUMP_INTERVAL (currently via os.environ.get
in the module scope), parse with float inside the existing try/except, then
validate with math.isfinite(value) and value > 0 and fallback to 2.0 if
validation fails; keep the existing exception handling (TypeError, ValueError)
and ensure the final assigned symbol is _DUMP_MIN_INTERVAL with the safe
default.
| if reco.hit: | ||
| bx, by, bw, bh = reco.box | ||
| adjusted = (bx + rx, by + ry, bw, bh) | ||
| print(f"[RedDotDetector] [preset:{preset_node}] 命中 → {adjusted}") | ||
| return CustomRecognition.AnalyzeResult(box=adjusted, detail={"preset": preset_node}) | ||
| return None | ||
| mfaalog.info(f"[RedDotDetector] [preset:{preset_node}] hit -> {adjusted}") | ||
| return CustomRecognition.AnalyzeResult( | ||
| box=adjusted, detail={"result": "hit", "preset": preset_node}) | ||
|
|
||
| # 真未命中:阶段原因已由预设节点(独立模式)记进嵌套识别记录;这里附带透传其 raw_detail | ||
| raw = getattr(reco, "raw_detail", None) | ||
| mfaalog.warning(f"[RedDotDetector] miss@preset | {argv.node_name} via {preset_node}") | ||
| return CustomRecognition.AnalyzeResult(box=None, detail={ | ||
| "result": "miss", "mode": "preset", "preset": preset_node, | ||
| "roi": [rx, ry, rw, rh], | ||
| "preset_detail": raw, | ||
| "hint": "阶段原因见预设节点(独立模式)的 detail;失败截图见 debug/RedDotDetector/ 下以本节点名命名的 rdd_* 文件", | ||
| }) |
There was a problem hiding this comment.
预设模式的 detail 还没有真正统一。
Line 654 只返回了 {"result", "preset"},Line 663 又把预设节点的 stage/stat/conf/parts 包进了 preset_detail。这样预设模式命中/未命中的 detail 结构都和本文件上方文档承诺的统一 detail.* schema 不一致,接入 MaaLogs 或调参脚本时还得额外分支判断,等于把这次 PR 想统一的 preset/standalone 契约又拆开了。
♻️ 建议补丁
if reco.hit:
+ raw = getattr(reco, "raw_detail", None)
bx, by, bw, bh = reco.box
adjusted = (bx + rx, by + ry, bw, bh)
+ detail = raw.copy() if isinstance(raw, dict) else (
+ {"raw_detail": raw} if raw is not None else {}
+ )
+ detail.update({
+ "result": "hit",
+ "mode": "preset",
+ "preset": preset_node,
+ "roi": [rx, ry, rw, rh],
+ "box": list(adjusted),
+ })
mfaalog.info(f"[RedDotDetector] [preset:{preset_node}] hit -> {adjusted}")
- return CustomRecognition.AnalyzeResult(
- box=adjusted, detail={"result": "hit", "preset": preset_node})
+ return CustomRecognition.AnalyzeResult(box=adjusted, detail=detail)
# 真未命中:阶段原因已由预设节点(独立模式)记进嵌套识别记录;这里附带透传其 raw_detail
raw = getattr(reco, "raw_detail", None)
+ detail = raw.copy() if isinstance(raw, dict) else (
+ {"raw_detail": raw} if raw is not None else {}
+ )
+ detail.update({
+ "result": "miss",
+ "mode": "preset",
+ "preset": preset_node,
+ "roi": [rx, ry, rw, rh],
+ "hint": "阶段原因见预设节点(独立模式)的 detail;失败截图见 debug/RedDotDetector/ 下以本节点名命名的 rdd_* 文件",
+ })
mfaalog.warning(f"[RedDotDetector] miss@preset | {argv.node_name} via {preset_node}")
- return CustomRecognition.AnalyzeResult(box=None, detail={
- "result": "miss", "mode": "preset", "preset": preset_node,
- "roi": [rx, ry, rw, rh],
- "preset_detail": raw,
- "hint": "阶段原因见预设节点(独立模式)的 detail;失败截图见 debug/RedDotDetector/ 下以本节点名命名的 rdd_* 文件",
- })
+ return CustomRecognition.AnalyzeResult(box=None, detail=detail)🧰 Tools
🪛 Ruff (0.15.15)
[warning] 657-657: Comment contains ambiguous : (FULLWIDTH COLON). Did you mean : (COLON)?
(RUF003)
[warning] 657-657: Comment contains ambiguous ; (FULLWIDTH SEMICOLON). Did you mean ; (SEMICOLON)?
(RUF003)
[warning] 664-664: String contains ambiguous ; (FULLWIDTH SEMICOLON). Did you mean ; (SEMICOLON)?
(RUF001)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@agent/recognition/binarymatch.py` around lines 650 - 665, The preset-mode
AnalyzeResult detail is inconsistent: the hit branch
(CustomRecognition.AnalyzeResult in this file around the preset handling for
variable preset_node) only returns {"result","preset"} while the miss branch
embeds the preset node's stage/stat/conf/parts under "preset_detail" using
reco.raw_detail; unify both branches to the same detail schema promised by the
file-level docs by extracting the preset node's stage/stat/conf/parts (from
getattr(reco, "raw_detail", None) or reco.raw_detail) into the same top-level
detail fields (e.g., stage, stat, conf, parts or a single "preset" object) for
both hit and miss, preserve existing keys like
"result","mode","preset","roi","hint", and ensure the hit branch includes the
same preset-related fields so downstream code (MaaLogs/tuning scripts) can rely
on one schema.
Summary by Sourcery
优化红点(通知)检测器,引入基于置信度的评分模型,提供更丰富的诊断信息和常驻的调试产物,并改进预设/独立模式下的行为以及错误报告。
Enhancements:
Original summary in English
Summary by Sourcery
Refine the red-dot (notification) detector to use a confidence-based scoring model with richer diagnostics and always-on debug artifacts, and improve preset/standalone behavior and error reporting.
Enhancements:
Summary by CodeRabbit
发布说明
新功能
Bug 修复
Chores