Skip to content

refactor(autostockpile): 拆分 Pipeline 和 Go Service 职责边界#1635

Merged
MistEO merged 6 commits intov2from
refactor/auto-stockpile
Mar 28, 2026
Merged

refactor(autostockpile): 拆分 Pipeline 和 Go Service 职责边界#1635
MistEO merged 6 commits intov2from
refactor/auto-stockpile

Conversation

@single-ptilopsis
Copy link
Copy Markdown
Contributor

@single-ptilopsis single-ptilopsis commented Mar 27, 2026

summary:

  • 拆分 AutoStockpile Pipeline:将单体 Task.json 拆为 Entry、DecisionLoop、Purchase 三个子流程,保持决策锚点与连通关系不变
  • 拆分 Go Service 职责:从 recognition.go 中抽出 goods_scan、recognition_results、quota、params、overrides、nodes 等模块,收窄各模块职责边界
  • 收窄识别来源:模板匹配和 OCR 候选均限制为 Best 结果,减少误识别
  • 更新中英文维护文档,同步到当前 Pipeline 拆分结构并补充 attach、阈值回退、运行时覆盖说明

Summary by Sourcery

通过拆分流水线职责与 Go 服务逻辑为更聚焦的组件,对 AutoStockpile 模块进行重构,同时收紧识别行为并更新维护文档。

增强内容:

  • 将货物扫描、配额处理、识别结果工具、参数解析、节点常量以及流水线覆盖(override)辅助函数从单一的大文件中抽取出来,拆分为独立的 Go 模块,以实现更清晰的职责划分。
  • 调整模板匹配和 OCR 流程,仅依赖最佳或经筛选的识别候选结果,从而降低物品、价格和配额解析中的歧义。
  • 优化运行时流水线覆盖行为,使选择、跳过分支以及决策就绪逻辑与新的 Entry、DecisionLoop 和 Purchase 流水线拆分方案保持一致。

文档:

  • 更新中英文的 AutoStockpile 和 quantized-sliding 开发文档,描述新的 Entry/DecisionLoop/Purchase 流水线拆分方式、attach/threshold/reserve-stock-bill 行为,以及扩展后的运行时覆盖语义。
Original summary in English

Summary by Sourcery

Refactor the AutoStockpile module by splitting pipeline responsibilities and Go service logic into focused components while tightening recognition behavior and updating maintenance documentation.

Enhancements:

  • Extract goods scanning, quota handling, recognition result utilities, parameter parsing, node constants, and pipeline override helpers from monolithic files into dedicated Go modules for clearer responsibilities.
  • Adjust template matching and OCR flows to rely on best or filtered recognition candidates only, reducing ambiguity in item, price, and quota parsing.
  • Refine runtime pipeline override behavior for selection, skip branches, and decision readiness to align with the new split Entry, DecisionLoop, and Purchase pipelines.

Documentation:

  • Update Chinese and English AutoStockpile and quantized-sliding developer docs to describe the new Entry/DecisionLoop/Purchase pipeline split, attach/threshold/reserve-stock-bill behavior, and the expanded runtime override semantics.
Original summary in English

Summary by Sourcery

通过拆分流水线职责与 Go 服务逻辑为更聚焦的组件,对 AutoStockpile 模块进行重构,同时收紧识别行为并更新维护文档。

增强内容:

  • 将货物扫描、配额处理、识别结果工具、参数解析、节点常量以及流水线覆盖(override)辅助函数从单一的大文件中抽取出来,拆分为独立的 Go 模块,以实现更清晰的职责划分。
  • 调整模板匹配和 OCR 流程,仅依赖最佳或经筛选的识别候选结果,从而降低物品、价格和配额解析中的歧义。
  • 优化运行时流水线覆盖行为,使选择、跳过分支以及决策就绪逻辑与新的 Entry、DecisionLoop 和 Purchase 流水线拆分方案保持一致。

文档:

  • 更新中英文的 AutoStockpile 和 quantized-sliding 开发文档,描述新的 Entry/DecisionLoop/Purchase 流水线拆分方式、attach/threshold/reserve-stock-bill 行为,以及扩展后的运行时覆盖语义。
Original summary in English

Summary by Sourcery

Refactor the AutoStockpile module by splitting pipeline responsibilities and Go service logic into focused components while tightening recognition behavior and updating maintenance documentation.

Enhancements:

  • Extract goods scanning, quota handling, recognition result utilities, parameter parsing, node constants, and pipeline override helpers from monolithic files into dedicated Go modules for clearer responsibilities.
  • Adjust template matching and OCR flows to rely on best or filtered recognition candidates only, reducing ambiguity in item, price, and quota parsing.
  • Refine runtime pipeline override behavior for selection, skip branches, and decision readiness to align with the new split Entry, DecisionLoop, and Purchase pipelines.

Documentation:

  • Update Chinese and English AutoStockpile and quantized-sliding developer docs to describe the new Entry/DecisionLoop/Purchase pipeline split, attach/threshold/reserve-stock-bill behavior, and the expanded runtime override semantics.

Copilot AI review requested due to automatic review settings March 27, 2026 03:09
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 代理的提示
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="docs/en_us/developers/auto-stockpile-maintain.md" line_range="105" />
<code_context>
 > [!TIP]
 >
-> Threshold-related task inputs and attach values must be **positive integers**. Empty strings, `0`, and negative values do not trigger fallback; they are rejected by task input validation or by the Go-side config parser.
+> Threshold-related task inputs and attach values must be **positive integers**. Empty strings, `0`, and negative values do not trigger fallback; they are rejected by task input validation or the Go-side config parser.

 ## Reserve Stock Bill
</code_context>
<issue_to_address>
**issue (typo):** 为了语法正确,请在这个句子中补上缺失的 "by"。

可以考虑将句子的结尾部分改写为:

`...they are rejected by task input validation or by the Go-side config parser.`

```suggestion
> Threshold-related task inputs and attach values must be **positive integers**. Empty strings, `0`, and negative values do not trigger fallback; they are rejected by task input validation or by the Go-side config parser.
```
</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="docs/en_us/developers/auto-stockpile-maintain.md" line_range="105" />
<code_context>
 > [!TIP]
 >
-> Threshold-related task inputs and attach values must be **positive integers**. Empty strings, `0`, and negative values do not trigger fallback; they are rejected by task input validation or by the Go-side config parser.
+> Threshold-related task inputs and attach values must be **positive integers**. Empty strings, `0`, and negative values do not trigger fallback; they are rejected by task input validation or the Go-side config parser.

 ## Reserve Stock Bill
</code_context>
<issue_to_address>
**issue (typo):** Add a missing "by" for correct grammar in this sentence.

Consider rewriting the end of the sentence as:

`...they are rejected by task input validation or by the Go-side config parser.`

```suggestion
> Threshold-related task inputs and attach values must be **positive integers**. Empty strings, `0`, and negative values do not trigger fallback; they are rejected by task input validation or by the Go-side config parser.
```
</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.

- 抽出节点常量、地区参数解析和 pipeline override 构造
- 分离额度解析、商品扫描与 RecognitionDetail 读取 helper
- 收窄 recognition、quantity 和 types 的职责边界
- 将 Task.json 拆为 Entry、DecisionLoop 和 Purchase
- 保留决策锚点、attach 合同节点和地区节点命名
- 维持购买链与统一退出链的原有连通关系
- 同步中英文维护文档到当前 Pipeline 拆分结构
- 补充 attach、阈值回退、保留调度券与运行时覆盖说明
- 修正 QuantizedSliding 文档中的 AutoStockpile 示例路径
@single-ptilopsis single-ptilopsis force-pushed the refactor/auto-stockpile branch from 8be6e2e to cc852ab Compare March 27, 2026 06:12
@MistEO MistEO requested review from Copilot and removed request for Copilot March 28, 2026 14:48
@MistEO
Copy link
Copy Markdown
Contributor

MistEO commented Mar 28, 2026

@sourcery-ai review

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 对 AutoStockpile 进行结构性重构:将原先单体 Pipeline 拆分为更清晰的 Entry / DecisionLoop / Purchase 三段,并将 go-service 的 autostockpile 识别与决策逻辑按职责拆分到多个文件中,同时收紧识别来源到 Best/Filtered 结果以降低误识别;相应维护文档与 QuantizedSliding 接入示例也同步更新到新的 Pipeline 结构。

Changes:

  • 拆分 AutoStockpile Pipeline:移除 Task.json,新增 Entry.json / DecisionLoop.json / Purchase.json 并保持锚点/连通关系。
  • 重构 go-service/autostockpile:抽离商品扫描、识别结果、配额、参数解析、override、节点常量等模块,缩小文件职责边界。
  • 更新中英文开发/维护文档:修正文档引用路径与运行时覆盖/阈值回退/attach 说明。

Reviewed changes

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

Show a summary per file
File Description
docs/zh_cn/developers/quantized-sliding.md 更新 QuantizedSliding 在 AutoStockpile 中的接入示例位置引用到 Purchase.json 节点。
docs/zh_cn/developers/auto-stockpile-maintain.md 同步 AutoStockpile Pipeline 拆分后的维护说明,并补充 attach/阈值回退/override 行为描述。
docs/en_us/developers/quantized-sliding.md 英文版同步更新 QuantizedSliding 接入示例引用到 Purchase.json 节点。
docs/en_us/developers/auto-stockpile-maintain.md 英文版同步更新 Pipeline 拆分与运行时行为说明。
assets/resource/pipeline/AutoStockpile/Task.json 删除旧的单体流程定义,为拆分后的三段流程让路。
assets/resource/pipeline/AutoStockpile/Entry.json 新增“进入与滚动到底部”等入口阶段节点。
assets/resource/pipeline/AutoStockpile/DecisionLoop.json 新增“识别-决策-复核-跳过”等核心决策循环节点与 attach 合同节点。
assets/resource/pipeline/AutoStockpile/Purchase.json 新增“调整数量-购买-取消-返回”等购买分支节点,并承接 QuantizedSliding 节点示例。
agent/go-service/autostockpile/types.go 精简类型文件:移除与阈值解析/runner 声明等无关内容,使其聚焦数据契约与配置类型。
agent/go-service/autostockpile/stockbill.go OCR 文本来源收敛为 Best-only,并复用统一的 OCR 文本候选提取逻辑。
agent/go-service/autostockpile/selector.go SelectItem 自定义动作逻辑保留,改用新的识别详情 JSON 提取函数,并移动接口断言到类型附近。
agent/go-service/autostockpile/register.go 使用集中定义的 action/recognition 名称常量注册 runner。
agent/go-service/autostockpile/reconcile.go 复核阶段 OCR 文本来源收敛为 Best-only,日志字段改进(Strs)。
agent/go-service/autostockpile/recognition_results.go 新增识别结果/候选提取工具:Best-only/Filtered-only OCR 文本与模板命中提取、detail JSON 解包等。
agent/go-service/autostockpile/recognition.go 识别主流程瘦身:将商品扫描/配额/参数/override 等拆出,模板命中取 Best 结果。
agent/go-service/autostockpile/quota.go 抽离配额 OCR 与解析逻辑,且 OCR 文本来源改为 Filtered-only。
agent/go-service/autostockpile/quantity.go 移除与 override/param 解析相关的杂项实现(迁移到专用文件),保留数量决策与展示文本格式化。
agent/go-service/autostockpile/params.go 新增参数解析/归一化:Region 解析与 custom_action_param 兼容 map/JSON string。
agent/go-service/autostockpile/overrides.go 新增集中 override 构造与跳过分支重置/重定向逻辑。
agent/go-service/autostockpile/options.go 阈值/输入解析错误模型与数值解析函数迁移至此,使 options 聚焦配置解析与校验。
agent/go-service/autostockpile/nodes.go 新增节点名/动作名/识别名常量集中管理,减少散落字符串。
agent/go-service/autostockpile/itemmap.go 增补 item_map 校验与 region/未绑定条目收集等辅助逻辑(从识别文件迁移)。
agent/go-service/autostockpile/goods_scan.go 抽离商品扫描:模板匹配、OCR 绑定、ROI 调整、测试价注入等逻辑独立成模块。
Comments suppressed due to low confidence (2)

agent/go-service/autostockpile/selector.go:37

  • 这里的日志字段 component 仍在使用字符串字面量 "autostockpile"。当前包已在 nodes.go 定义了 autoStockpileComponent 常量,建议统一改用该常量,避免后续改名/拼写不一致导致日志聚合维度分裂。
	detailJSON := extractCustomRecognitionDetailJSON(arg.RecognitionDetail)
	if detailJSON == "" {
		log.Error().
			Str("component", "autostockpile").
			Msg("recognition detail json is empty")

agent/go-service/autostockpile/reconcile.go:44

  • 这里的日志字段 component 仍在使用字符串字面量 "autostockpile"。当前包已提供 autoStockpileComponent 常量(见 nodes.go),建议统一改用常量,减少重复字面量并避免未来出现不一致。
	ocrTexts := ocrTextCandidates(arg.RecognitionDetail, ocrTextPolicyBestOnly)
	if len(ocrTexts) == 0 {
		log.Error().
			Str("component", "autostockpile").
			Msg("reconcile recognition detail contains no ocr text")

@MistEO MistEO merged commit 53f935f into v2 Mar 28, 2026
22 checks passed
@MistEO MistEO deleted the refactor/auto-stockpile branch March 28, 2026 16:36
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