Skip to content

refactor(quantizedsliding): 重构数量配置与按钮识别流程#1812

Merged
single-ptilopsis merged 7 commits intov2from
fix/quantized-sliding
Apr 1, 2026
Merged

refactor(quantizedsliding): 重构数量配置与按钮识别流程#1812
single-ptilopsis merged 7 commits intov2from
fix/quantized-sliding

Conversation

@single-ptilopsis
Copy link
Copy Markdown
Contributor

@single-ptilopsis single-ptilopsis commented Apr 1, 2026

summary:

  • 重构 QuantizedSliding 参数结构,将数量相关配置收敛为 Quantity.Target、Quantity.Box 与 Quantity.OnlyRec,并同步调整 AutoStockpile 的覆写逻辑
  • 为滑块与加减按钮识别补充 GreenMask 与辅助按钮节点,改造运行时 Pipeline 覆写方式,提升模板匹配分支的可配置性
  • 简化数量 OCR 读取链路,统一改为基于 Results.Best.AsOCR().Text 解析,并同步更新中英文开发文档与示例配置

Summary by Sourcery

重构 QuantizedSliding 的数量配置和按钮识别逻辑,改为使用嵌套的 Quantity 对象以及标准化的 OCR 与模板匹配路径,并相应更新 AutoStockpile 集成逻辑和开发文档。

增强内容:

  • 重构 QuantizedSliding 参数结构,将与数量相关的配置嵌套到一个 Quantity 对象下,包括 target、ROI box 和 OnlyRec 标记,并为模板匹配新增 GreenMask 开关。
  • 简化数量 OCR 流程,改为统一从 Results.Best.AsOCR().Text 读取结果,移除原有的字符串拼接和基于 JSON 的回退解析路径。
  • 调整运行时 Pipeline 覆盖行为,使数量 OCR 节点仅遵循 only_rec,按钮点击使用专用的辅助节点,并支持可配置的 green_mask 用于模板匹配。
  • 更新 AutoStockpile 对 QuantizedSliding 的集成方式,改为覆写 Quantity.Target,而不是之前的扁平 Target 字段。

文档:

  • 更新英文和中文的 QuantizedSliding 与 AutoStockpile 开发者文档及示例,以反映新的 Quantity.* 结构、GreenMask 选项以及简化后的 OCR 策略。
Original summary in English

Summary by Sourcery

Refactor QuantizedSliding quantity configuration and button recognition to use a nested Quantity object and standardized OCR and template-matching paths, and update AutoStockpile integration and developer docs accordingly.

Enhancements:

  • Restructure QuantizedSliding parameters to nest quantity-related settings under a Quantity object, including target, ROI box, and OnlyRec flag, plus a GreenMask switch for template matching.
  • Simplify quantity OCR by always reading from Results.Best.AsOCR().Text and removing concatenation and JSON fallback parsing paths.
  • Refine runtime Pipeline overrides so quantity OCR nodes honor only_rec and button clicks use dedicated helper nodes with configurable green_mask for template matching.
  • Adjust AutoStockpile’s QuantizedSliding integration to override Quantity.Target instead of the previous flat Target field.

Documentation:

  • Update English and Chinese QuantizedSliding and AutoStockpile developer documentation and examples to reflect the new Quantity.* schema, GreenMask option, and simplified OCR strategy.

- 为 QuantizedSlidingAction 新增 GreenMask 参数
- 将滑块按钮识别和数量分支识别统一映射到 green_mask
- 同步更新 Helper 管线与中英文开发文档
- 改为使用 Quantity.Target、Quantity.Box、Quantity.OnlyRec
- 数量识别统一读取 Results.Best.AsOCR().Text
- 同步更新 AutoStockpile 覆盖逻辑与中英文文档
- nodes.go 新增 IncreaseButton / DecreaseButton 节点常量
- overrides.go 将 green_mask 识别抽离至辅助节点,主节点改用 And 识别引用
- Helper.json 注册 QuantizedSlidingIncreaseButton 与 QuantizedSlidingDecreaseButton 节点
Copilot AI review requested due to automatic review settings April 1, 2026 08:40
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 个问题

给 AI 代理的提示
请根据这次代码评审中的评论进行修改:

## 单条评论

### 评论 1
<location path="agent/go-service/quantizedsliding/overrides.go" line_range="27-36" />
<code_context>
 }

-func buildMainInitializationOverride(end []int, quantityBox []int, quantityFilter *quantityFilterParam) map[string]any {
+func buildMainInitializationOverride(end []int, quantityBox []int, quantityFilter *quantityFilterParam, quantityOnlyRec bool, greenMask bool) map[string]any {
 	quantityParam := map[string]any{
-		"roi": append([]int(nil), quantityBox...),
</code_context>
<issue_to_address>
**建议:** `buildMainInitializationOverride` 中已经不再使用 `quantityFilter` 参数。

该函数仍然接收 `quantityFilter *quantityFilterParam`,但并未使用。如果这里已经不再需要它,请移除该参数,以简化 API 并避免让调用方困惑。如果它仍然应该影响行为(例如在流水线层面),请在构建 override 时使用它,而不是让它处于未使用状态。

建议实现:

```golang
func buildMainInitializationOverride(end []int, quantityBox []int, quantityOnlyRec bool, greenMask bool) map[string]any {

```

你还需要:
1. 查找所有 `buildMainInitializationOverride` 的使用位置,并从每个调用中移除 `quantityFilter` 参数(它之前很可能是第三个参数)。
2. 删除所有仅为满足该调用而存在、现已未使用的 `quantityFilter` 变量。
3. 如果 `quantityFilter` 仍然*应该*影响行为,那么与其完全移除它,不如在该函数中将其字段合并进 `quantityParam` / `override` 映射中;这需要基于 `quantityFilter` 的结构添加相应的条目。
</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/quantizedsliding/overrides.go" line_range="27-36" />
<code_context>
 }

-func buildMainInitializationOverride(end []int, quantityBox []int, quantityFilter *quantityFilterParam) map[string]any {
+func buildMainInitializationOverride(end []int, quantityBox []int, quantityFilter *quantityFilterParam, quantityOnlyRec bool, greenMask bool) map[string]any {
 	quantityParam := map[string]any{
-		"roi": append([]int(nil), quantityBox...),
</code_context>
<issue_to_address>
**suggestion:** The `quantityFilter` parameter is no longer used in `buildMainInitializationOverride`.

The function still takes `quantityFilter *quantityFilterParam`, but it’s not used. If it’s no longer needed here, remove the parameter to simplify the API and avoid confusing callers. If it should still affect behavior (e.g., at the pipeline level), please apply it when building the override rather than leaving it unused.

Suggested implementation:

```golang
func buildMainInitializationOverride(end []int, quantityBox []int, quantityOnlyRec bool, greenMask bool) map[string]any {

```

You’ll also need to:
1. Find all usages of `buildMainInitializationOverride` and remove the `quantityFilter` argument from each call (it will likely be the third argument previously).
2. Remove any now-unused `quantityFilter` variables that existed only to satisfy this call.
3. If `quantityFilter` *should* still influence behavior, instead of removing it entirely, you should incorporate its fields into the `quantityParam` / `override` maps in this function; that would require adding corresponding entries based on `quantityFilter`'s structure.
</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.

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 重构了 QuantizedSliding 的数量配置结构与按钮识别覆盖流程,将数量相关参数收敛到 Quantity.*,并引入 GreenMask 与辅助按钮节点以提升模板匹配分支的可配置性;同时简化数量 OCR 读取链路并同步更新中英文开发文档与示例配置。

Changes:

  • 将数量参数从 Target/QuantityBox/ConcatAllFilteredDigits 调整为 Quantity.Target/Quantity.Box/Quantity.OnlyRec,并同步 AutoStockpile 的运行时覆写逻辑与示例配置
  • 为加减按钮引入 Helper 节点(TemplateMatch),运行时通过覆写 helper + click 节点来实现“模板识别后点击”的分支
  • 数量 OCR 读取统一改为 Results.Best.AsOCR().Text 路径,并更新中英文文档说明

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/zh_cn/developers/quantized-sliding.md 同步参数结构、GreenMask/only_rec 与 OCR 读取口径的中文文档说明与示例
docs/zh_cn/developers/auto-stockpile-maintain.md 更新 AutoStockpile 运行时覆写字段为 Quantity.Target(中文)
docs/en_us/developers/quantized-sliding.md 同步参数结构、GreenMask/only_rec 与 OCR 读取口径的英文文档说明与示例
docs/en_us/developers/auto-stockpile-maintain.md 更新 AutoStockpile 运行时覆写字段为 Quantity.Target(英文)
assets/resource/pipeline/QuantizedSliding/Helper.json 新增滑块/按钮辅助识别节点与 OCR only_rec 字段,补齐 TemplateMatch 常用参数
assets/resource/pipeline/AutoStockpile/Purchase.json 更新 QuantizedSliding 调用参数为 Quantity{Target,Box,OnlyRec}
agent/go-service/quantizedsliding/types.go 重构 custom_action_param 类型定义,引入 QuantityGreenMask 等字段
agent/go-service/quantizedsliding/params.go 解析/归一化新参数结构,落地到 action 字段(含 OnlyRec/GreenMask)
agent/go-service/quantizedsliding/overrides.go 调整运行时覆写:支持 quantity OCR only_rec、slider green_mask、按钮 helper 覆写与 And 识别
agent/go-service/quantizedsliding/ocr.go 简化数量 OCR 文本读取逻辑,固定使用 Best OCR 文本解析数字
agent/go-service/quantizedsliding/nodes.go 增加按钮 helper 节点常量
agent/go-service/quantizedsliding/handlers.go 适配新 OCR 读取与分支覆写接口(传入 GreenMask 等)
agent/go-service/autostockpile/overrides.go AutoStockpile 覆写目标数量时改写 Quantity.Target

@single-ptilopsis single-ptilopsis marked this pull request as draft April 1, 2026 08:50
@single-ptilopsis single-ptilopsis marked this pull request as ready for review April 1, 2026 10:06
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 - 我在这里给出了一些高层次的反馈:

  • buildTemplateMatchButtonHelperOverride / buildTemplateMatchButtonOverride 中,显式设置的 threshold: 0.8 被去掉了,但文档中仍然描述的是固定的 0.8 阈值;建议重新显式设置该阈值,以避免依赖引擎默认值,并保持行为与文档一致。
  • resolveButtonHelperNode 在遇到意料之外的 nextNode 值时,可能会返回空的 helper node 字符串,而这个值会被传入 all_of 列表;为了更安全,建议在映射时进行校验,当没有适用的 helper node 时,要么记录日志,要么跳过 template-match override。
  • buildSwipeSpecificQuantityOverride 中,类型断言 clonedParam["Quantity"].(map[string]any) 会在传入参数结构错误或缺失时触发 panic;建议使用类型 switch / ok-check 进行检查,在结构不符合预期时优雅失败,而不是直接假定结构正确。
给 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- In `buildTemplateMatchButtonHelperOverride` / `buildTemplateMatchButtonOverride` the explicit `threshold: 0.8` was dropped, but the docs still describe a fixed 0.8 threshold; consider setting it explicitly again to avoid relying on engine defaults and to keep behavior aligned with the documentation.
- `resolveButtonHelperNode` can return an empty helper node string for unexpected `nextNode` values, which will then be passed into the `all_of` list; it may be safer to validate the mapping and either log or skip the template-match override when no helper node applies.
- In `buildSwipeSpecificQuantityOverride` the type assertion `clonedParam["Quantity"].(map[string]any)` will panic if the incoming param shape is wrong or missing; consider using a type switch / ok-check and failing gracefully instead of assuming the structure.

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

Hey - I've left some high level feedback:

  • In buildTemplateMatchButtonHelperOverride / buildTemplateMatchButtonOverride the explicit threshold: 0.8 was dropped, but the docs still describe a fixed 0.8 threshold; consider setting it explicitly again to avoid relying on engine defaults and to keep behavior aligned with the documentation.
  • resolveButtonHelperNode can return an empty helper node string for unexpected nextNode values, which will then be passed into the all_of list; it may be safer to validate the mapping and either log or skip the template-match override when no helper node applies.
  • In buildSwipeSpecificQuantityOverride the type assertion clonedParam["Quantity"].(map[string]any) will panic if the incoming param shape is wrong or missing; consider using a type switch / ok-check and failing gracefully instead of assuming the structure.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `buildTemplateMatchButtonHelperOverride` / `buildTemplateMatchButtonOverride` the explicit `threshold: 0.8` was dropped, but the docs still describe a fixed 0.8 threshold; consider setting it explicitly again to avoid relying on engine defaults and to keep behavior aligned with the documentation.
- `resolveButtonHelperNode` can return an empty helper node string for unexpected `nextNode` values, which will then be passed into the `all_of` list; it may be safer to validate the mapping and either log or skip the template-match override when no helper node applies.
- In `buildSwipeSpecificQuantityOverride` the type assertion `clonedParam["Quantity"].(map[string]any)` will panic if the incoming param shape is wrong or missing; consider using a type switch / ok-check and failing gracefully instead of assuming the structure.

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.

@single-ptilopsis single-ptilopsis marked this pull request as draft April 1, 2026 11:20
@single-ptilopsis single-ptilopsis marked this pull request as ready for review April 1, 2026 11:55
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 - 我发现了 2 个问题,并给出了一些高层次的反馈:

  • buildMainInitializationOverride 中,greenMask 参数被接收但从未使用;要么把它传递到相关的 TemplateMatch 参数中,要么从函数签名中移除它以避免混淆。
  • 新的 buildTemplateMatchButtonHelperOverride 去掉了之前硬编码的 TemplateMatch threshold 为 0.8;如果仍然希望保留这种行为,请显式设置 threshold 以维持之前的匹配敏感度。
  • 对于 Quantity.OnlyRec,当前归一化逻辑在字段被省略时会将 override 默认为 false,这会在流水线中强制关闭 only_rec;可以考虑只在用户显式提供 Quantity.OnlyRec 时注入 only_rec override,从而保持流水线默认值可用。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `buildMainInitializationOverride`, the `greenMask` parameter is accepted but never used; either wire it through to the relevant TemplateMatch parameters or remove it from the signature to avoid confusion.
- The new `buildTemplateMatchButtonHelperOverride` drops the previously hardcoded TemplateMatch `threshold` of 0.8; if that behavior is still desired, explicitly set `threshold` to maintain the prior matching sensitivity.
- For `Quantity.OnlyRec`, the normalization currently defaults the override to `false` when the field is omitted, which forces `only_rec` off in the pipeline; consider only injecting the `only_rec` override when the user explicitly provides `Quantity.OnlyRec` so that pipeline defaults remain usable.

## Individual Comments

### Comment 1
<location path="agent/go-service/quantizedsliding/overrides.go" line_range="27-33" />
<code_context>
 }

-func buildMainInitializationOverride(end []int, quantityBox []int, quantityFilter *quantityFilterParam) map[string]any {
+func buildMainInitializationOverride(end []int, quantityBox []int, quantityFilter *quantityFilterParam, quantityOnlyRec bool, greenMask bool) map[string]any {
 	quantityParam := map[string]any{
-		"roi": append([]int(nil), quantityBox...),
+		"roi":      append([]int(nil), quantityBox...),
+		"only_rec": quantityOnlyRec,
 	}

 	override := map[string]any{
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider either wiring `greenMask` into this override or removing it from the signature.

`greenMask` is passed from `handleMain` but never used when building this override. If it’s meant to affect template matching (like the button helper nodes), it should be included in the recognition params here; if not, the parameter should be removed from the function to avoid a no-op configuration option.
</issue_to_address>

### Comment 2
<location path="agent/go-service/quantizedsliding/overrides.go" line_range="124-130" />
<code_context>
 }

-func buildTemplateMatchButtonOverride(template string, repeat int) map[string]any {
+func resolveButtonHelperNode(nextNode string) string {
+	switch nextNode {
+	case nodeQuantizedSlidingIncreaseQuantity:
+		return nodeQuantizedSlidingIncreaseButton
+	case nodeQuantizedSlidingDecreaseQuantity:
+		return nodeQuantizedSlidingDecreaseButton
+	default:
+		return ""
+	}
</code_context>
<issue_to_address>
**issue:** Handle or guard against unknown `nextNode` values when resolving the button helper node.

If `nextNode` is anything else, this returns an empty string, which in `buildCheckQuantityBranchOverride` produces a helper keyed by `""` and an `And` node with `all_of: [""]`. That’s probably unintended and fragile. If `nextNode` should always be one of the known constants, consider panicking/returning an error, or at least skipping helper/And creation in this case to avoid malformed pipeline entries.
</issue_to_address>

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

Hey - I've found 2 issues, and left some high level feedback:

  • In buildMainInitializationOverride, the greenMask parameter is accepted but never used; either wire it through to the relevant TemplateMatch parameters or remove it from the signature to avoid confusion.
  • The new buildTemplateMatchButtonHelperOverride drops the previously hardcoded TemplateMatch threshold of 0.8; if that behavior is still desired, explicitly set threshold to maintain the prior matching sensitivity.
  • For Quantity.OnlyRec, the normalization currently defaults the override to false when the field is omitted, which forces only_rec off in the pipeline; consider only injecting the only_rec override when the user explicitly provides Quantity.OnlyRec so that pipeline defaults remain usable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `buildMainInitializationOverride`, the `greenMask` parameter is accepted but never used; either wire it through to the relevant TemplateMatch parameters or remove it from the signature to avoid confusion.
- The new `buildTemplateMatchButtonHelperOverride` drops the previously hardcoded TemplateMatch `threshold` of 0.8; if that behavior is still desired, explicitly set `threshold` to maintain the prior matching sensitivity.
- For `Quantity.OnlyRec`, the normalization currently defaults the override to `false` when the field is omitted, which forces `only_rec` off in the pipeline; consider only injecting the `only_rec` override when the user explicitly provides `Quantity.OnlyRec` so that pipeline defaults remain usable.

## Individual Comments

### Comment 1
<location path="agent/go-service/quantizedsliding/overrides.go" line_range="27-33" />
<code_context>
 }

-func buildMainInitializationOverride(end []int, quantityBox []int, quantityFilter *quantityFilterParam) map[string]any {
+func buildMainInitializationOverride(end []int, quantityBox []int, quantityFilter *quantityFilterParam, quantityOnlyRec bool, greenMask bool) map[string]any {
 	quantityParam := map[string]any{
-		"roi": append([]int(nil), quantityBox...),
+		"roi":      append([]int(nil), quantityBox...),
+		"only_rec": quantityOnlyRec,
 	}

 	override := map[string]any{
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider either wiring `greenMask` into this override or removing it from the signature.

`greenMask` is passed from `handleMain` but never used when building this override. If it’s meant to affect template matching (like the button helper nodes), it should be included in the recognition params here; if not, the parameter should be removed from the function to avoid a no-op configuration option.
</issue_to_address>

### Comment 2
<location path="agent/go-service/quantizedsliding/overrides.go" line_range="124-130" />
<code_context>
 }

-func buildTemplateMatchButtonOverride(template string, repeat int) map[string]any {
+func resolveButtonHelperNode(nextNode string) string {
+	switch nextNode {
+	case nodeQuantizedSlidingIncreaseQuantity:
+		return nodeQuantizedSlidingIncreaseButton
+	case nodeQuantizedSlidingDecreaseQuantity:
+		return nodeQuantizedSlidingDecreaseButton
+	default:
+		return ""
+	}
</code_context>
<issue_to_address>
**issue:** Handle or guard against unknown `nextNode` values when resolving the button helper node.

If `nextNode` is anything else, this returns an empty string, which in `buildCheckQuantityBranchOverride` produces a helper keyed by `""` and an `And` node with `all_of: [""]`. That’s probably unintended and fragile. If `nextNode` should always be one of the known constants, consider panicking/returning an error, or at least skipping helper/And creation in this case to avoid malformed pipeline entries.
</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.

@single-ptilopsis single-ptilopsis merged commit ad9dd57 into v2 Apr 1, 2026
18 checks passed
@single-ptilopsis single-ptilopsis deleted the fix/quantized-sliding branch April 1, 2026 13:52
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.

2 participants