Skip to content

feat: 信用点商店适配ADB和智能刷新模式#1568

Merged
MistEO merged 8 commits intov2from
fix/CreditShoppingADB
Mar 24, 2026
Merged

feat: 信用点商店适配ADB和智能刷新模式#1568
MistEO merged 8 commits intov2from
fix/CreditShoppingADB

Conversation

@overflow65537
Copy link
Copy Markdown
Member

@overflow65537 overflow65537 commented Mar 24, 2026

Summary by Sourcery

支持基于阈值和基于表达式的预留额度识别,并为 ADB 和智能刷新模式适配信用商城相关工作流。

New Features:

  • 允许通过布尔表达式配置预留额度检查,可组合来自多个节点的 OCR 识别结果。
  • 引入一个可复用的数值型 OCR 识别辅助工具,用于额度及相关数值的识别。
  • 扩展信用购物(credit shopping)流水线和任务,以支持基于 ADB 的运行方式和智能刷新行为。

Enhancements:

  • 优化预留额度识别配置的解析逻辑,以处理包含阈值和表达式在内的结构化参数。
  • 改进对 OCR 数值结果和表达式的求值过程,提升错误处理与日志记录能力。
Original summary in English

Summary by Sourcery

Support both threshold-based and expression-based reserve credit recognition and adapt credit shop workflows for ADB and smart refresh modes.

New Features:

  • Allow reserve credit checks to be configured via boolean expressions that combine OCR results from multiple nodes.
  • Introduce a reusable numeric OCR recognition helper for credit and related values.
  • Extend credit shopping pipelines and tasks to support ADB-based operation and smart refresh behavior.

Enhancements:

  • Refine parsing of reserve recognition configuration to handle structured parameters including thresholds and expressions.
  • Improve evaluation of OCR-derived numeric values and expression evaluation with better error handling and logging.
Original summary in English

Summary by Sourcery

支持基于阈值和基于表达式的预留额度识别,并为 ADB 和智能刷新模式适配信用商城相关工作流。

New Features:

  • 允许通过布尔表达式配置预留额度检查,可组合来自多个节点的 OCR 识别结果。
  • 引入一个可复用的数值型 OCR 识别辅助工具,用于额度及相关数值的识别。
  • 扩展信用购物(credit shopping)流水线和任务,以支持基于 ADB 的运行方式和智能刷新行为。

Enhancements:

  • 优化预留额度识别配置的解析逻辑,以处理包含阈值和表达式在内的结构化参数。
  • 改进对 OCR 数值结果和表达式的求值过程,提升错误处理与日志记录能力。
Original summary in English

Summary by Sourcery

Support both threshold-based and expression-based reserve credit recognition and adapt credit shop workflows for ADB and smart refresh modes.

New Features:

  • Allow reserve credit checks to be configured via boolean expressions that combine OCR results from multiple nodes.
  • Introduce a reusable numeric OCR recognition helper for credit and related values.
  • Extend credit shopping pipelines and tasks to support ADB-based operation and smart refresh behavior.

Enhancements:

  • Refine parsing of reserve recognition configuration to handle structured parameters including thresholds and expressions.
  • Improve evaluation of OCR-derived numeric values and expression evaluation with better error handling and logging.

Copilot AI review requested due to automatic review settings March 24, 2026 05:41
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 - 我已经审查了你的修改,看起来很棒!


Sourcery 对开源项目是免费的——如果你喜欢我们的审查,请考虑分享它们 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进代码审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


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.

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 旨在让“信用点商店(CreditShopping)”流程更好地适配 ADB 资源,并补充“折扣筛选”中的“包含无折扣”选项,从而提升在不同环境下的识别与购买逻辑一致性。

Changes:

  • 在任务配置中为折扣筛选新增 Ignore 案例(包含“无折扣”),并补齐多语言文案。
  • 调整 CreditShopping 主 pipeline 中“保留信用点”相关 OCR:扩大 ROI,并新增/接入颜色过滤节点以提升 OCR 稳定性。
  • 更新 ADB pipeline 覆写的 ROI(但目前对 color_filter 对应节点的 ROI 覆写路径存在问题)。

Reviewed changes

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

Show a summary per file
File Description
assets/tasks/CreditShopping.json 为折扣筛选新增 Ignore 选项,并通过 pipeline_override 覆写 IsDiscount 识别参数。
assets/resource_adb/pipeline/CreditShopping/Shopping.json ADB 环境下对“保留信用点”相关 ROI 做覆写,并启用 ADBSpecial 流程。
assets/resource/pipeline/CreditShopping/Shopping.json 调整保留信用点 OCR ROI、引入颜色过滤节点;修改“购买黑名单”节点的识别条件与描述。
assets/misc/locales/zh_tw.json 新增 Ignore 文案并调整 Any 文案表达。
assets/misc/locales/zh_cn.json 新增 Ignore 文案并调整 Any 文案表达。
assets/misc/locales/ko_kr.json 新增 Ignore 文案并调整 Any 文案表达。
assets/misc/locales/ja_jp.json 新增 Ignore 文案并调整 Any 文案表达。
assets/misc/locales/en_us.json 新增 Ignore 文案并调整 Any 文案表达。

@overflow65537 overflow65537 marked this pull request as draft March 24, 2026 10:17
@overflow65537 overflow65537 changed the title fix: 信用点商店适配ADB feat: 信用点商店适配ADB和智能刷新模式 Mar 24, 2026
@overflow65537 overflow65537 linked an issue Mar 24, 2026 that may be closed by this pull request
@overflow65537 overflow65537 marked this pull request as ready for review March 24, 2026 10:36
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 个问题,并给出了一些整体性的反馈:

  • evaluateBinaryExpression 中,逻辑运算符(&&||)总是会计算两边的表达式,因为在检查运算符之前就对 XY 调用了 evaluateASTExpression;如果在表达式中嵌入了 OCR 调用,建议增加显式的短路求值,以避免不必要的识别开销以及潜在的副作用。
  • resolveExpressionValues 中,expressionNodePattern.ReplaceAllStringFunc 对每个匹配都调用了一次 FindStringSubmatch,即使完整匹配字符串已经可用;你可以直接从 match 字符串中截取占位符内容(例如去掉外围的大括号),从而简化逻辑并避免多余的正则开销。
面向 AI Agent 的提示词
Please address the comments from this code review:

## Overall Comments
- In `evaluateBinaryExpression`, logical operators (`&&`, `||`) always evaluate both sides because `evaluateASTExpression` is called on `X` and `Y` before checking the operator; if OCR calls are embedded in expressions, consider adding explicit short-circuit evaluation to avoid unnecessary recognitions and potential side effects.
- In `resolveExpressionValues`, `expressionNodePattern.ReplaceAllStringFunc` calls `FindStringSubmatch` for each match even though the full match is already provided; you can simplify and avoid the extra regex work by capturing the placeholder content directly from the `match` string (e.g., by trimming the surrounding braces).

## Individual Comments

### Comment 1
<location path="agent/go-service/creditshopping/reserve_recognition.go" line_range="109-118" />
<code_context>
+		return reserveRecognitionConfig{}, err
+	}
+
+	if expressionRaw, ok := params["expression"]; ok {
+		expression, ok := expressionRaw.(string)
+		if !ok {
+			return reserveRecognitionConfig{}, fmt.Errorf("expression: unsupported type %T", expressionRaw)
+		}
+		expression = strings.TrimSpace(expression)
+		if expression == "" {
+			return reserveRecognitionConfig{}, fmt.Errorf("expression: must not be empty")
+		}
+		return reserveRecognitionConfig{
+			Expression: expression,
+		}, nil
</code_context>
<issue_to_address>
**suggestion:** Threshold is silently ignored when an expression is provided

When `expression` is present, the function returns a config with only `Expression`, silently discarding any `threshold` value. To avoid confusing mixed configs, either validate and reject cases where both are provided, or clearly log/document that `threshold` is ignored when `expression` is set.

Suggested implementation:

```golang
	if expressionRaw, ok := params["expression"]; ok {
		if _, hasThreshold := params["threshold"]; hasThreshold {
			return reserveRecognitionConfig{}, fmt.Errorf("expression: must not be provided together with threshold")
		}

		expression, ok := expressionRaw.(string)
		if !ok {
			return reserveRecognitionConfig{}, fmt.Errorf("expression: unsupported type %T", expressionRaw)
		}
		expression = strings.TrimSpace(expression)
		if expression == "" {
			return reserveRecognitionConfig{}, fmt.Errorf("expression: must not be empty")
		}
		return reserveRecognitionConfig{
			Expression: expression,
		}, nil
	}

```

None required based on the provided snippet. This change ensures that when both `expression` and `threshold` are present, the function fails fast with a clear validation error instead of silently ignoring `threshold`.
</issue_to_address>

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

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

  • In evaluateBinaryExpression, logical operators (&&, ||) always evaluate both sides because evaluateASTExpression is called on X and Y before checking the operator; if OCR calls are embedded in expressions, consider adding explicit short-circuit evaluation to avoid unnecessary recognitions and potential side effects.
  • In resolveExpressionValues, expressionNodePattern.ReplaceAllStringFunc calls FindStringSubmatch for each match even though the full match is already provided; you can simplify and avoid the extra regex work by capturing the placeholder content directly from the match string (e.g., by trimming the surrounding braces).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `evaluateBinaryExpression`, logical operators (`&&`, `||`) always evaluate both sides because `evaluateASTExpression` is called on `X` and `Y` before checking the operator; if OCR calls are embedded in expressions, consider adding explicit short-circuit evaluation to avoid unnecessary recognitions and potential side effects.
- In `resolveExpressionValues`, `expressionNodePattern.ReplaceAllStringFunc` calls `FindStringSubmatch` for each match even though the full match is already provided; you can simplify and avoid the extra regex work by capturing the placeholder content directly from the `match` string (e.g., by trimming the surrounding braces).

## Individual Comments

### Comment 1
<location path="agent/go-service/creditshopping/reserve_recognition.go" line_range="109-118" />
<code_context>
+		return reserveRecognitionConfig{}, err
+	}
+
+	if expressionRaw, ok := params["expression"]; ok {
+		expression, ok := expressionRaw.(string)
+		if !ok {
+			return reserveRecognitionConfig{}, fmt.Errorf("expression: unsupported type %T", expressionRaw)
+		}
+		expression = strings.TrimSpace(expression)
+		if expression == "" {
+			return reserveRecognitionConfig{}, fmt.Errorf("expression: must not be empty")
+		}
+		return reserveRecognitionConfig{
+			Expression: expression,
+		}, nil
</code_context>
<issue_to_address>
**suggestion:** Threshold is silently ignored when an expression is provided

When `expression` is present, the function returns a config with only `Expression`, silently discarding any `threshold` value. To avoid confusing mixed configs, either validate and reject cases where both are provided, or clearly log/document that `threshold` is ignored when `expression` is set.

Suggested implementation:

```golang
	if expressionRaw, ok := params["expression"]; ok {
		if _, hasThreshold := params["threshold"]; hasThreshold {
			return reserveRecognitionConfig{}, fmt.Errorf("expression: must not be provided together with threshold")
		}

		expression, ok := expressionRaw.(string)
		if !ok {
			return reserveRecognitionConfig{}, fmt.Errorf("expression: unsupported type %T", expressionRaw)
		}
		expression = strings.TrimSpace(expression)
		if expression == "" {
			return reserveRecognitionConfig{}, fmt.Errorf("expression: must not be empty")
		}
		return reserveRecognitionConfig{
			Expression: expression,
		}, nil
	}

```

None required based on the provided snippet. This change ensures that when both `expression` and `threshold` are present, the function fails fast with a clear validation error instead of silently ignoring `threshold`.
</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.

@overflow65537
Copy link
Copy Markdown
Member Author

ExpressionRecognition 是一个通用的 Custom Recognition,用于对由识别节点结果组成的表达式进行求值。它支持通过 {节点名} 引用其他 OCR 数字识别节点,执行后将识别结果代入表达式,并以布尔结果决定是否命中
大概类似于

{节点A}<400

节点A必须识别数字,且不能有任何其他字符串(^d+$)

@MistEO
Copy link
Copy Markdown
Contributor

MistEO commented Mar 24, 2026

locales 换位置了,冲突了

@MistEO MistEO merged commit 0394c35 into v2 Mar 24, 2026
18 checks passed
@MistEO MistEO deleted the fix/CreditShoppingADB branch March 24, 2026 12:55
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.

更细致的信用点购物策略

3 participants