Skip to content

fix(auto_coffee): 修复了自动做咖啡无法选到正确关卡的问题#241

Merged
1bananachicken merged 5 commits into
devfrom
fix-coffee
May 29, 2026
Merged

fix(auto_coffee): 修复了自动做咖啡无法选到正确关卡的问题#241
1bananachicken merged 5 commits into
devfrom
fix-coffee

Conversation

@1bananachicken
Copy link
Copy Markdown
Owner

@1bananachicken 1bananachicken commented May 29, 2026

现在会拖到最上面选择1-1关卡了

Summary by Sourcery

确保自动咖啡动作在开始运行前,能够可靠地滚动到顶部并选择正确的目标等级。

Bug Fixes:

  • 修复自动咖啡等级选择问题:在开始前先滚动到顶部,并显式定位目标咖啡等级。
  • 调整自动咖啡点击辅助函数中的点击时序,以提升与游戏 UI 交互的可靠性。
Original summary in English

Summary by Sourcery

Ensure the auto coffee action reliably scrolls to the top and selects the correct target level before starting the run.

Bug Fixes:

  • Fix auto coffee level selection by scrolling to the top and explicitly locating the target coffee level before starting.
  • Adjust tap timing in the auto coffee click helper to improve interaction reliability with the game UI.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 29, 2026

Reviewer's Guide

调整自动咖啡动作,在开始前可靠地滚动到最顶端并选择正确的关卡(1-1 / Coffee Master),并移除未使用的时间工具模块。

更新后的自动咖啡等级选择顺序图

sequenceDiagram
    participant TaskRunner
    participant Context
    participant Controller

    TaskRunner->>Context: run
    Context->>Controller: get_image
    Context->>Context: run_recognition MakeCoffeeStart
    alt MakeCoffeeStart hit
        loop until MakeCoffeeTargetCoffeeMaster hit
            Context->>Context: run_action MakeCoffeeScrollToTop
            Context->>Controller: get_image
            Context->>Context: run_recognition MakeCoffeeTargetCoffeeMaster
        end
        Context->>Controller: click_rect target_result.box
        Context->>Controller: get_image
        Context->>Context: run_recognition MakeCoffeeStart
        alt MakeCoffeeStart hit
            Context->>Controller: click_rect start_roi
        end
    end
Loading

File-Level Changes

Change Details Files
在点击屏幕矩形区域时稳定点击交互。
  • click_rect 中增加 touch_downtouch_up 事件之间的休眠时间,以减少误触或漏触
agent/custom/action/auto_make_coffee.py
确保自动咖啡流程在按下开始之前始终滚动到顶部并选择目标 Coffee Master 关卡。
  • 添加 scroll_to_top_action 常量,并映射到 MakeCoffeeScrollToTop pipeline action
  • 在检测到开始界面后,反复执行“滚动到顶部”动作,直到检测到 Coffee Master 目标
  • 点击识别出的 Coffee Master 目标的边界框,以选择正确的关卡
  • 在选择关卡后,重新校验开始按钮是否存在;如果尚未就绪,则重试,然后再继续原有的开始点击流程
agent/custom/action/auto_make_coffee.py
assets/resource/base/pipeline/MakeCoffee.json
assets/resource/tasks/MakeCoffee.json
移除未使用的时间工具模块。
  • 删除 agent.utils.time 模块及其相关引用(如果有)
agent/utils/time.py
agent/utils/__init__.py

Possibly linked issues

  • 更新assets/interface.json #1:二者都通过滚动并重新选择正确关卡来修复自动咖啡未返回预期关卡的问题。
  • #(not specified):此 PR 让自动咖啡始终选择 1-1,从而支持请求的每周活力重复刷关。

Tips and commands

Interacting with Sourcery

  • 触发新的审核: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审核评论。
  • 从审核评论生成 GitHub issue: 通过回复某条审核评论请求 Sourcery 基于该评论创建 issue。你也可以回复审核评论 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题中的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文的任意位置写上 @sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 撤销所有 Sourcery 审核: 在 pull request 中评论 @sourcery-ai dismiss,即可撤销所有现有的 Sourcery 审核。特别适用于你想从头开始一次全新的审核时 —— 记得再评论 @sourcery-ai review 来触发新的审核!

Customizing Your Experience

访问你的 dashboard 以:

  • 启用或禁用诸如 Sourcery 生成的 pull request 摘要、审阅者指南等审核功能。
  • 更改审核语言。
  • 添加、移除或编辑自定义审核说明。
  • 调整其他审核设置。

Getting Help

Original review guide in English

Reviewer's Guide

Adjusts the auto coffee action to reliably scroll to the top and select the correct level (1-1 / Coffee Master) before starting, and removes an unused time utility module.

Sequence diagram for updated auto coffee level selection

sequenceDiagram
    participant TaskRunner
    participant Context
    participant Controller

    TaskRunner->>Context: run
    Context->>Controller: get_image
    Context->>Context: run_recognition MakeCoffeeStart
    alt MakeCoffeeStart hit
        loop until MakeCoffeeTargetCoffeeMaster hit
            Context->>Context: run_action MakeCoffeeScrollToTop
            Context->>Controller: get_image
            Context->>Context: run_recognition MakeCoffeeTargetCoffeeMaster
        end
        Context->>Controller: click_rect target_result.box
        Context->>Controller: get_image
        Context->>Context: run_recognition MakeCoffeeStart
        alt MakeCoffeeStart hit
            Context->>Controller: click_rect start_roi
        end
    end
Loading

File-Level Changes

Change Details Files
Stabilize tap interactions when clicking on-screen rectangles.
  • Increase sleep delay between touch_down and touch_up events in click_rect to reduce mis-taps or missed inputs
agent/custom/action/auto_make_coffee.py
Ensure auto coffee flow always scrolls to the top and selects the target Coffee Master level before pressing start.
  • Add scroll_to_top_action constant mapped to the MakeCoffeeScrollToTop pipeline action
  • After detecting the start screen, repeatedly perform the scroll-to-top action until the Coffee Master target is detected
  • Click on the recognized Coffee Master target bounding box to select the correct level
  • Re-validate that the start button is present after selecting the level, and retry if not ready before proceeding with the original start click sequence
agent/custom/action/auto_make_coffee.py
assets/resource/base/pipeline/MakeCoffee.json
assets/resource/tasks/MakeCoffee.json
Remove unused time utility module.
  • Delete agent.utils.time module and associated references if any
agent/utils/time.py
agent/utils/__init__.py

Possibly linked issues

  • 更新assets/interface.json #1: They both fix auto coffee not returning to the intended stage by scrolling and reselecting the correct level.
  • #(not specified): PR makes auto coffee always select 1-1, enabling the requested repeated farming for weekly vitality

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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 - 我发现了两个问题,并给出了一些整体建议:

  • 反复调用 scroll_to_top_actionwhile True 循环没有最大迭代次数或超时保护;建议添加重试次数限制或基于时间的退出条件,以避免在识别一直未命中时出现潜在的无限循环。
  • click_rect 中的点击延迟从 0.001 增加到 0.05 会减慢所有使用该辅助方法的调用;如果更长的延迟只在这一特定流程中需要,建议将该延迟做成可配置参数,或使用单独的点击辅助方法,以免影响其他调用方。
  • 新增的 scroll_to_top_action = "MakeCoffeeScrollToTop" 假设在 pipeline/tasks JSON 中存在对应的 action;为避免默默无效的情况,更安全的做法是处理 context.run_action(scroll_to_top_action) 失败或缺失的场景。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `while True` loop that repeatedly calls `scroll_to_top_action` has no max-iteration or timeout guard; consider adding a retry limit or time-based escape to avoid potential infinite loops if recognition never hits.
- Increasing the click delay from `0.001` to `0.05` in `click_rect` will slow down every use of this helper; if the longer delay is only needed for this specific flow, consider making the delay configurable or using a separate click helper so other callers are not penalized.
- The newly introduced `scroll_to_top_action = "MakeCoffeeScrollToTop"` assumes a corresponding action exists in the pipeline/tasks JSON; it would be safer to handle the case where `context.run_action(scroll_to_top_action)` fails or is missing to prevent silent no-ops.

## Individual Comments

### Comment 1
<location path="agent/custom/action/auto_make_coffee.py" line_range="76-85" />
<code_context>
                 img = get_image(controller)
                 start_result = context.run_recognition("MakeCoffeeStart", img)
                 if start_result and start_result.hit:
+                    while True:
+                        if context.tasker.stopping:
+                            return CustomAction.RunResult(success=False)
+                        context.run_action(scroll_to_top_action)
+                        time.sleep(1)
+                        img = get_image(controller)
+                        target_result = context.run_recognition(
+                            "MakeCoffeeTargetCoffeeMaster", img
+                        )
+                        if target_result and target_result.hit:
+                            break
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Add a timeout or max-iteration guard to avoid a potentially infinite search loop.

This `while True` loop will keep calling `scroll_to_top_action` and recognition until either the target is detected or `tasker.stopping` is set. If `MakeCoffeeTargetCoffeeMaster` is never matched (e.g., asset change or unexpected UI state), this loop can run indefinitely and block the pipeline. Please add a max-attempt or time-based limit and return a failure or safe fallback once that limit is reached.
</issue_to_address>

### Comment 2
<location path="agent/custom/action/auto_make_coffee.py" line_range="80" />
<code_context>
+                        if context.tasker.stopping:
+                            return CustomAction.RunResult(success=False)
+                        context.run_action(scroll_to_top_action)
+                        time.sleep(1)
+                        img = get_image(controller)
+                        target_result = context.run_recognition(
</code_context>
<issue_to_address>
**suggestion:** Consider using an existing cadence/constant instead of a hard-coded 1s sleep in the polling loop.

This fixed 1s sleep sets a separate cadence from `check_freq` and other timing settings in this action. To keep behavior consistent and easier to tune, either reuse `check_freq` (or another shared timing constant) or promote this to a named constant so it’s configurable without digging into the loop body.

Suggested implementation:

```python
                        time.sleep(check_freq)

```

This change assumes `check_freq` is already defined and in scope for this block (e.g., as a variable, attribute, or imported constant used by the rest of the action's timing logic). If it is not, you should:

1. Introduce a shared constant near the top of the file or in the existing configuration module, for example:
   - `AUTO_MAKE_COFFEE_CHECK_FREQ = 1.0`
2. Use that constant consistently:
   - Replace or define `check_freq = AUTO_MAKE_COFFEE_CHECK_FREQ` in the action setup.
   - Ensure any other sleeps or polling logic in this action also use `check_freq` (or the shared constant) instead of hard-coded literals.

This keeps all the action’s timing behavior controlled from one configuration value instead of scattering literal delays through the loop body.
</issue_to_address>

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

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

  • The while True loop that repeatedly calls scroll_to_top_action has no max-iteration or timeout guard; consider adding a retry limit or time-based escape to avoid potential infinite loops if recognition never hits.
  • Increasing the click delay from 0.001 to 0.05 in click_rect will slow down every use of this helper; if the longer delay is only needed for this specific flow, consider making the delay configurable or using a separate click helper so other callers are not penalized.
  • The newly introduced scroll_to_top_action = "MakeCoffeeScrollToTop" assumes a corresponding action exists in the pipeline/tasks JSON; it would be safer to handle the case where context.run_action(scroll_to_top_action) fails or is missing to prevent silent no-ops.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `while True` loop that repeatedly calls `scroll_to_top_action` has no max-iteration or timeout guard; consider adding a retry limit or time-based escape to avoid potential infinite loops if recognition never hits.
- Increasing the click delay from `0.001` to `0.05` in `click_rect` will slow down every use of this helper; if the longer delay is only needed for this specific flow, consider making the delay configurable or using a separate click helper so other callers are not penalized.
- The newly introduced `scroll_to_top_action = "MakeCoffeeScrollToTop"` assumes a corresponding action exists in the pipeline/tasks JSON; it would be safer to handle the case where `context.run_action(scroll_to_top_action)` fails or is missing to prevent silent no-ops.

## Individual Comments

### Comment 1
<location path="agent/custom/action/auto_make_coffee.py" line_range="76-85" />
<code_context>
                 img = get_image(controller)
                 start_result = context.run_recognition("MakeCoffeeStart", img)
                 if start_result and start_result.hit:
+                    while True:
+                        if context.tasker.stopping:
+                            return CustomAction.RunResult(success=False)
+                        context.run_action(scroll_to_top_action)
+                        time.sleep(1)
+                        img = get_image(controller)
+                        target_result = context.run_recognition(
+                            "MakeCoffeeTargetCoffeeMaster", img
+                        )
+                        if target_result and target_result.hit:
+                            break
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Add a timeout or max-iteration guard to avoid a potentially infinite search loop.

This `while True` loop will keep calling `scroll_to_top_action` and recognition until either the target is detected or `tasker.stopping` is set. If `MakeCoffeeTargetCoffeeMaster` is never matched (e.g., asset change or unexpected UI state), this loop can run indefinitely and block the pipeline. Please add a max-attempt or time-based limit and return a failure or safe fallback once that limit is reached.
</issue_to_address>

### Comment 2
<location path="agent/custom/action/auto_make_coffee.py" line_range="80" />
<code_context>
+                        if context.tasker.stopping:
+                            return CustomAction.RunResult(success=False)
+                        context.run_action(scroll_to_top_action)
+                        time.sleep(1)
+                        img = get_image(controller)
+                        target_result = context.run_recognition(
</code_context>
<issue_to_address>
**suggestion:** Consider using an existing cadence/constant instead of a hard-coded 1s sleep in the polling loop.

This fixed 1s sleep sets a separate cadence from `check_freq` and other timing settings in this action. To keep behavior consistent and easier to tune, either reuse `check_freq` (or another shared timing constant) or promote this to a named constant so it’s configurable without digging into the loop body.

Suggested implementation:

```python
                        time.sleep(check_freq)

```

This change assumes `check_freq` is already defined and in scope for this block (e.g., as a variable, attribute, or imported constant used by the rest of the action's timing logic). If it is not, you should:

1. Introduce a shared constant near the top of the file or in the existing configuration module, for example:
   - `AUTO_MAKE_COFFEE_CHECK_FREQ = 1.0`
2. Use that constant consistently:
   - Replace or define `check_freq = AUTO_MAKE_COFFEE_CHECK_FREQ` in the action setup.
   - Ensure any other sleeps or polling logic in this action also use `check_freq` (or the shared constant) instead of hard-coded literals.

This keeps all the action’s timing behavior controlled from one configuration value instead of scattering literal delays through the loop body.
</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.

Comment on lines +76 to +85
while True:
if context.tasker.stopping:
return CustomAction.RunResult(success=False)
context.run_action(scroll_to_top_action)
time.sleep(1)
img = get_image(controller)
target_result = context.run_recognition(
"MakeCoffeeTargetCoffeeMaster", img
)
if target_result and target_result.hit:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): 添加超时或最大迭代次数保护,以避免潜在的无限搜索循环。

这个 while True 循环会持续调用 scroll_to_top_action 并进行识别,直到检测到目标或设置了 tasker.stopping。如果始终无法匹配到 MakeCoffeeTargetCoffeeMaster(例如资源变更或出现了意外的 UI 状态),该循环可能会无限运行并阻塞整个 pipeline。请添加最大尝试次数或基于时间的限制,并在达到该限制时返回失败结果或安全的降级处理。

Original comment in English

issue (bug_risk): Add a timeout or max-iteration guard to avoid a potentially infinite search loop.

This while True loop will keep calling scroll_to_top_action and recognition until either the target is detected or tasker.stopping is set. If MakeCoffeeTargetCoffeeMaster is never matched (e.g., asset change or unexpected UI state), this loop can run indefinitely and block the pipeline. Please add a max-attempt or time-based limit and return a failure or safe fallback once that limit is reached.

if context.tasker.stopping:
return CustomAction.RunResult(success=False)
context.run_action(scroll_to_top_action)
time.sleep(1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: 建议在轮询循环中使用现有的频率/常量,而不是硬编码 1 秒的 sleep。

这个固定的 1 秒 sleep 引入了与本 action 中 check_freq 以及其他计时设置不同的一套节奏。为保持行为一致且便于调优,建议要么复用 check_freq(或其他共享的时间常量),要么将该值提升为具名常量,这样无需深入循环体就可以进行配置。

建议的实现方式:

                        time.sleep(check_freq)

此修改假设 check_freq 已经定义并在该代码块的作用域中可用(例如作为变量、属性或被其余计时逻辑使用的导入常量)。如果尚未定义,你可以:

  1. 在文件顶部或现有配置模块中引入一个共享常量,例如:
    • AUTO_MAKE_COFFEE_CHECK_FREQ = 1.0
  2. 在整个逻辑中统一使用该常量:
    • 在 action 初始化阶段替换或定义 check_freq = AUTO_MAKE_COFFEE_CHECK_FREQ
    • 确保该 action 中其他 sleep 或轮询逻辑也使用 check_freq(或该共享常量),而不是分散的硬编码字面量。

这样可以通过单一配置值统一控制整个 action 的计时行为,而不是在循环体中分散多个延迟常量。

Original comment in English

suggestion: Consider using an existing cadence/constant instead of a hard-coded 1s sleep in the polling loop.

This fixed 1s sleep sets a separate cadence from check_freq and other timing settings in this action. To keep behavior consistent and easier to tune, either reuse check_freq (or another shared timing constant) or promote this to a named constant so it’s configurable without digging into the loop body.

Suggested implementation:

                        time.sleep(check_freq)

This change assumes check_freq is already defined and in scope for this block (e.g., as a variable, attribute, or imported constant used by the rest of the action's timing logic). If it is not, you should:

  1. Introduce a shared constant near the top of the file or in the existing configuration module, for example:
    • AUTO_MAKE_COFFEE_CHECK_FREQ = 1.0
  2. Use that constant consistently:
    • Replace or define check_freq = AUTO_MAKE_COFFEE_CHECK_FREQ in the action setup.
    • Ensure any other sleeps or polling logic in this action also use check_freq (or the shared constant) instead of hard-coded literals.

This keeps all the action’s timing behavior controlled from one configuration value instead of scattering literal delays through the loop body.

@1bananachicken 1bananachicken merged commit d8922c1 into dev May 29, 2026
3 checks passed
@1bananachicken 1bananachicken deleted the fix-coffee branch June 2, 2026 07:00
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.

1 participant