Skip to content

refactor: resell#1213

Merged
MistEO merged 9 commits intov2from
refactor/resell
Mar 25, 2026
Merged

refactor: resell#1213
MistEO merged 9 commits intov2from
refactor/resell

Conversation

@dongwlin
Copy link
Copy Markdown
Contributor

@dongwlin dongwlin commented Mar 12, 2026

改改代码喵

Summary by Sourcery

优化转售相关的 OCR 解析与工具方法,以更好地提取数值,并改进配额相关的识别,同时新增专门的完成动作。

New Features:

  • 为 OCR 增加辅助方法,用于解析转售配额信息,包括当前与最大配额以及下一次增量时间。
  • 引入转售完成动作,用于记录转售流程结束的时间点。
  • 提供一个实用工具,用于安全地将鼠标光标移动到 OCR 关键区域之外。

Bug Fixes:

  • 收紧数值解析逻辑,将之前的数字提取器替换为以整数为主的解析器,用于处理成本和好友价格的 OCR 结果。

Enhancements:

  • 新增工具函数,用于从识别详情中一致性地提取 OCR 文本,优先使用最佳和过滤后的结果,并支持处理合并节点。
  • 调整利润记录的后处理逻辑,对最大利润记录的行索引进行归一化。
Original summary in English

Summary by Sourcery

Refine resell OCR parsing and utilities to better extract numeric values and handle quota-related recognition while adding a dedicated finish action.

New Features:

  • Add helpers to OCR and parse resell quota information, including current and maximum quota and next increment timing.
  • Introduce a resell finish action that logs when the resell workflow completes.
  • Provide a utility to safely move the mouse cursor away from critical OCR regions.

Bug Fixes:

  • Tighten numeric parsing by replacing the previous number extractor with an integer-focused parser for cost and friend price OCR results.

Enhancements:

  • Add utilities to consistently extract OCR text from recognition details, prioritizing best and filtered results and handling combined nodes.
  • Adjust profit record post-processing to normalize the row index for maximum-profit records.

dongwlin and others added 6 commits March 12, 2026 14:29
Extract OCR text from RecognitionDetail using the Results field
  (which is already parsed by maa-framework-go) instead of manually
  parsing DetailJson. Add tryGetOCRText and tryGetOCRTexts helper
  functions for better readability.
@dongwlin
Copy link
Copy Markdown
Contributor Author

摆了一段时间,忘记后面要改啥了,先这样吧(投降喵

@dongwlin dongwlin marked this pull request as ready for review March 25, 2026 02:24
Copy link
Copy Markdown
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 个问题,并留下了一些整体性的反馈:

  • 新增的 helper MoveMouseSafe 在这个 diff 中被定义但没有在任何地方使用,建议要么把它集成进相关流程中,要么移除它以避免产生死代码。
  • processMaxRecord 只有在 Row >= 2 时才会对 Row 减 1;如果你的意图是总是把最大记录归一到前一行,建议通过注释或对 Row == 1 做显式处理来澄清边界条件,从而让行为更容易理解。
  • recognizeText 函数在每次 OCR 成功时都会用 Info 级别打日志;如果在正常流程中调用频繁,建议将其降级为 Debug,或者加上一定的控制(例如采样或开关),以避免线上日志过于嘈杂。
给 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- The new helper `MoveMouseSafe` is defined but not used anywhere in this diff, consider either integrating it into the relevant flow or removing it to avoid dead code.
- `processMaxRecord` subtracts 1 from `Row` only when `Row >= 2`; if the intent is to always normalize max records to the previous row, consider clarifying the boundary condition (e.g., with a comment or by handling `Row == 1` explicitly) to make the behavior easier to reason about.
- The `recognizeText` function logs at `Info` level on every successful OCR; if this runs frequently in normal flows, consider downgrading to `Debug` or gating the log to avoid noisy logs in production.

## Individual Comments

### Comment 1
<location path="agent/go-service/resell/quota_ocr.go" line_range="111-115" />
<code_context>
+		return ""
+	}
+
+	log.Info().
+		Str("node", nodeName).
+		Str("text", text).
+		Msg("recognition OCR text")
+	return text
+}
</code_context>
<issue_to_address>
**suggestion (performance):** Using Info-level logging for every successful OCR result may generate excessive log volume.

Since `recognizeText` may run frequently, logging every non-empty result at Info can create noisy, high-volume logs and make operational issues harder to detect. Consider lowering this to Debug or guarding it with sampling/feature flags unless Info-level visibility is explicitly required in production.

```suggestion
	log.Debug().
		Str("node", nodeName).
		Str("text", text).
		Msg("recognition OCR text")
	return text
```
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得我们的 Review 有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的 Review。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • The new helper MoveMouseSafe is defined but not used anywhere in this diff, consider either integrating it into the relevant flow or removing it to avoid dead code.
  • processMaxRecord subtracts 1 from Row only when Row >= 2; if the intent is to always normalize max records to the previous row, consider clarifying the boundary condition (e.g., with a comment or by handling Row == 1 explicitly) to make the behavior easier to reason about.
  • The recognizeText function logs at Info level on every successful OCR; if this runs frequently in normal flows, consider downgrading to Debug or gating the log to avoid noisy logs in production.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new helper `MoveMouseSafe` is defined but not used anywhere in this diff, consider either integrating it into the relevant flow or removing it to avoid dead code.
- `processMaxRecord` subtracts 1 from `Row` only when `Row >= 2`; if the intent is to always normalize max records to the previous row, consider clarifying the boundary condition (e.g., with a comment or by handling `Row == 1` explicitly) to make the behavior easier to reason about.
- The `recognizeText` function logs at `Info` level on every successful OCR; if this runs frequently in normal flows, consider downgrading to `Debug` or gating the log to avoid noisy logs in production.

## Individual Comments

### Comment 1
<location path="agent/go-service/resell/quota_ocr.go" line_range="111-115" />
<code_context>
+		return ""
+	}
+
+	log.Info().
+		Str("node", nodeName).
+		Str("text", text).
+		Msg("recognition OCR text")
+	return text
+}
</code_context>
<issue_to_address>
**suggestion (performance):** Using Info-level logging for every successful OCR result may generate excessive log volume.

Since `recognizeText` may run frequently, logging every non-empty result at Info can create noisy, high-volume logs and make operational issues harder to detect. Consider lowering this to Debug or guarding it with sampling/feature flags unless Info-level visibility is explicitly required in production.

```suggestion
	log.Debug().
		Str("node", nodeName).
		Str("text", text).
		Msg("recognition OCR text")
	return text
```
</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.

@dongwlin
Copy link
Copy Markdown
Contributor Author

@copilot

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

@copilot

请问有什么需要我帮忙的吗?目前 PR 中已完成了 resell 相关的 OCR 解析重构、配额识别辅助方法提取、完成动作新增等工作。如果你想继续某个方向(比如 Pipeline 补充、测试、文档等),可以告诉我具体需求,我来接着做。

Copy link
Copy Markdown
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 对 go-service 的 resell 模块做重构,拆分并优化 OCR 文本/数值解析与配额识别相关工具,提升识别结果提取的一致性,并补充流程结束动作的实现落点。

Changes:

  • 将原 utils.go 中的多类工具方法拆分为更聚焦的文件(OCR detail 提取、配额 OCR、文本整数解析、finish action 等)。
  • 将成本价/好友出售价的数字提取替换为新的整数解析方法 extractIntegerFromText
  • 将“最高利润记录行索引归一化”的后处理逻辑移至 decide.go

Reviewed changes

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

Show a summary per file
File Description
agent/go-service/resell/utils.go 删除原聚合工具文件(相关逻辑迁移到多个新文件)
agent/go-service/resell/text_parse.go 新增整数解析工具 extractIntegerFromText
agent/go-service/resell/scan_product.go 成本/好友价格解析改用新整数解析;新增 MoveMouseSafe
agent/go-service/resell/quota_ocr.go 新增配额 OCR + 解析流程与 recognizeText 封装
agent/go-service/resell/ocr_detail.go 新增统一的 OCR 文本提取工具 extractOCRText
agent/go-service/resell/finish.go 抽出 ResellFinishAction 到独立文件
agent/go-service/resell/decide.go 增加 processMaxRecord 后处理函数

Comment on lines +14 to +36
// 优先从 Results 中查找
if detail.Results != nil {
// 按优先级顺序尝试获取 OCR 文本
if text := tryGetOCRText(detail.Results.Best); text != "" {
return text
}
if text := tryGetOCRTexts(detail.Results.Filtered); text != "" {
return text
}
if text := tryGetOCRTexts(detail.Results.All); text != "" {
return text
}
}

// 递归查找 CombinedResult(Or/And 节点)
for _, child := range detail.CombinedResult {
if text := extractOCRText(child); text != "" {
return text
}
}

return ""
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

extractOCRText 目前只从 Results/CombinedResult 提取文本,未再从 detail.DetailJson 做兜底解析;但同仓库中(如 quantizedsliding/ocr.go)存在必须从 DetailJson 提取 OCR text 的情况,且 resell 旧实现也包含该兜底。建议补回对 DetailJson 的解析(至少支持 Maa wrap 的 best.text / best.detail 结构),否则在某些 Or/OCR 返回仅含 DetailJson 时会取不到 OCR 文本。

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

Choose a reason for hiding this comment

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

此处无需对DetailJson再进行解析,本质和go binding解析一样

Copy link
Copy Markdown
Contributor

@MistEO MistEO left a comment

Choose a reason for hiding this comment

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

看看 AI 建议有要改的不

@dongwlin dongwlin requested a review from HYY1116 March 25, 2026 10:05
@MistEO MistEO merged commit a802e7c into v2 Mar 25, 2026
16 checks passed
@MistEO MistEO deleted the refactor/resell branch March 25, 2026 15:45
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