Skip to content

feat: 特殊任务使用虚拟控制器#255

Open
zmdyy0318 wants to merge 4 commits into
MistEO:mainfrom
zmdyy0318:feat/2026062801
Open

feat: 特殊任务使用虚拟控制器#255
zmdyy0318 wants to merge 4 commits into
MistEO:mainfrom
zmdyy0318:feat/2026062801

Conversation

@zmdyy0318

@zmdyy0318 zmdyy0318 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

特殊任务都使用虚拟controller,避免游戏主进程退出后截图失败,导致无法执行特殊任务。

close MaaEnd/MaaEnd#1882
close MaaEnd/MaaEnd#2084
close MaaEnd/MaaEnd#2121
close MaaEnd/MaaEnd#2141
close MaaEnd/MaaEnd#2336
close MaaEnd/MaaEnd#2702
close MaaEnd/MaaEnd#2838
close MaaEnd/MaaEnd#3235

opus4.8
image
image

Summary by Sourcery

引入 Dummy 控制器支持和分段任务执行功能,使 MXU 的非可视特殊任务在没有实时游戏连接的情况下也能运行,同时在批次之间保持后端任务状态。

New Features:

  • 新增 Dummy 控制器类型,在没有真实游戏窗口的情况下运行 MXU 特殊任务时,返回固定的黑色截图并输出空操作输入。
  • 将 MXU 非可视特殊任务标记为可跳过截图/识别,并提供辅助方法用于检测此类任务以及将任务列表拆分为“特殊任务 / 游戏任务”两个分段。
  • 允许在启动任务时通过选项保留现有的后端任务运行状态,从而支持分段任务批次。
  • 新增工具方法,用于等待一批任务 ID 进入终止状态,优先使用回调机制,并在必要时回退到轮询。

Enhancements:

  • 更新工具栏和仪表盘中的任务启动逻辑,根据是否存在可视任务在真实设备和 Dummy 控制器之间进行选择,并允许在仅配置资源的情况下启动运行。
  • 调整控制器连接和短边显示处理逻辑,以支持新的 Dummy 控制器类型。
  • 优化后端任务状态管理,在 HTTP 和 Tauri 指令路径中依据新的 reset_state 标志选择重置或追加任务 ID。
Original summary in English

Summary by Sourcery

Introduce dummy controller support and segmented task execution so MXU non-visual special tasks can run without a live game connection while preserving backend task state across batches.

New Features:

  • Add a Dummy controller type that returns a constant black screenshot and no-op inputs for running MXU special tasks without a real game window.
  • Mark MXU non-visual special tasks as skippable for screenshot/recognition and provide helpers to detect such tasks and split task lists into special/game segments.
  • Allow starting tasks with an option to retain existing backend task run state, enabling segmented task batches.
  • Add a utility to wait for a batch of task IDs to reach a terminal state using callbacks with polling as a fallback.

Enhancements:

  • Update toolbar and dashboard task start logic to choose between real devices and the Dummy controller based on whether any visual tasks are present, and to allow starting runs with only resources configured.
  • Adjust controller connection and display-short-side handling to support the new Dummy controller type.
  • Refine backend task state management to either reset or append task IDs based on the new reset_state flag in both HTTP and Tauri command paths.

@zmdyy0318 zmdyy0318 marked this pull request as draft June 27, 2026 16:24

@sourcery-ai sourcery-ai Bot left a comment

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.

你好——我发现了 1 个问题,并且留下了一些整体性的反馈:

  • 在 src/utils/taskSegmentation.ts 中,needsSegmentedRun 目前只是简单地转发到 hasSpecialSegments,但 JSDoc 里写的是:只有在同时存在特殊段 并且 存在游戏段时才应该为 true;建议额外检查 segments.middle.length > 0,以避免把只有特殊任务的列表视为“分段运行”。
  • 在 DashboardView.tsx 中,needsDummyController 变量被计算出来但从未使用;建议要么像 Toolbar 里的 shouldUseDummyController 那样把它接入 start/run 逻辑,要么直接删掉,避免造成困惑和产生死代码。
提供给 AI Agents 的提示词
请处理这次代码评审中的评论:

## 整体评论
- 在 src/utils/taskSegmentation.ts 中,needsSegmentedRun 目前只是简单地转发到 hasSpecialSegments,但 JSDoc 里写的是:只有在同时存在特殊段 *并且* 存在游戏段时才应该为 true;建议额外检查 `segments.middle.length > 0`,以避免把只有特殊任务的列表视为“分段运行”。
- 在 DashboardView.tsx 中,needsDummyController 变量被计算出来但从未使用;建议要么像 Toolbar 里的 shouldUseDummyController 那样把它接入 start/run 逻辑,要么直接删掉,避免造成困惑和产生死代码。

## 具体评论

### 评论 1
<location path="src/utils/taskSegmentation.ts" line_range="49-50" />
<code_context>
+  return segments.leading.length > 0 || segments.trailing.length > 0;
+}
+
+/** 是否应走分段运行(存在特殊段且与游戏段组合) */
+export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {
+  return hasSpecialSegments(segments);
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** needsSegmentedRun 的实现没有体现注释里“与游戏段组合”的条件

当前实现只返回 `hasSpecialSegments(segments)`,与注释“存在特殊段且与游戏段组合”不符。如果所有任务都是特殊任务(`middle` 为空),按注释应不需要分段运行,但现在仍返回 true。建议同时判断 `middle` 非空,例如:

```ts
export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {
  return hasSpecialSegments(segments) && segments.middle.length > 0;
}
```
</issue_to_address>

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

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

  • In src/utils/taskSegmentation.ts, needsSegmentedRun currently just proxies to hasSpecialSegments, but the JSDoc says it should only be true when there are special segments and a game segment; consider also checking segments.middle.length > 0 to avoid treating a pure-special-task list as segmented.
  • In DashboardView.tsx, the needsDummyController variable is computed but never used; either wire this into the start/run logic (similar to Toolbar’s shouldUseDummyController) or remove it to avoid confusion and dead code.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In src/utils/taskSegmentation.ts, needsSegmentedRun currently just proxies to hasSpecialSegments, but the JSDoc says it should only be true when there are special segments *and* a game segment; consider also checking segments.middle.length > 0 to avoid treating a pure-special-task list as segmented.
- In DashboardView.tsx, the needsDummyController variable is computed but never used; either wire this into the start/run logic (similar to Toolbar’s shouldUseDummyController) or remove it to avoid confusion and dead code.

## Individual Comments

### Comment 1
<location path="src/utils/taskSegmentation.ts" line_range="49-50" />
<code_context>
+  return segments.leading.length > 0 || segments.trailing.length > 0;
+}
+
+/** 是否应走分段运行(存在特殊段且与游戏段组合) */
+export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {
+  return hasSpecialSegments(segments);
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** needsSegmentedRun 的实现没有体现注释里“与游戏段组合”的条件

当前实现只返回 `hasSpecialSegments(segments)`,与注释“存在特殊段且与游戏段组合”不符。如果所有任务都是特殊任务(`middle` 为空),按注释应不需要分段运行,但现在仍返回 true。建议同时判断 `middle` 非空,例如:

```ts
export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {
  return hasSpecialSegments(segments) && segments.middle.length > 0;
}
```
</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 +49 to +50
/** 是否应走分段运行(存在特殊段且与游戏段组合) */
export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {

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): needsSegmentedRun 的实现没有体现注释里“与游戏段组合”的条件

当前实现只返回 hasSpecialSegments(segments),与注释“存在特殊段且与游戏段组合”不符。如果所有任务都是特殊任务(middle 为空),按注释应不需要分段运行,但现在仍返回 true。建议同时判断 middle 非空,例如:

export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {
  return hasSpecialSegments(segments) && segments.middle.length > 0;
}
Original comment in English

issue (bug_risk): needsSegmentedRun 的实现没有体现注释里“与游戏段组合”的条件

当前实现只返回 hasSpecialSegments(segments),与注释“存在特殊段且与游戏段组合”不符。如果所有任务都是特殊任务(middle 为空),按注释应不需要分段运行,但现在仍返回 true。建议同时判断 middle 非空,例如:

export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {
  return hasSpecialSegments(segments) && segments.middle.length > 0;
}

@zmdyy0318 zmdyy0318 marked this pull request as ready for review June 28, 2026 16:00
@zmdyy0318 zmdyy0318 marked this pull request as draft June 28, 2026 16:01

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - 我发现了 1 个问题,并且给了一些整体性的反馈:

  • Toolbar 和 DashboardView 中的任务批处理逻辑(拆分为多个段、构建配置以及注册 task ID)现在有相当一部分是重复的;建议抽取一个共享的 helper,接受 runnableTasks 和段信息,从而减少重复代码并保持行为一致。
  • 新增的 needsSegmentedRun helper(位于 taskSegmentation.ts)目前只是代理了 hasSpecialSegments,并且与它的文档注释(“存在特殊段且与游戏段组合”)不符;建议要么调整实现以满足预期条件,要么在未使用时删除以避免混淆。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The task batching logic in Toolbar and DashboardView (splitting into segments, building configs, and registering task IDs) is now fairly duplicated; consider extracting a shared helper that takes runnableTasks and segment info to reduce repetition and keep the behavior consistent.
- The new `needsSegmentedRun` helper in `taskSegmentation.ts` currently just proxies `hasSpecialSegments` and doesn’t match its docstring (“存在特殊段且与游戏段组合”); either adjust the implementation to reflect the intended condition or remove it if unused to avoid confusion.

## Individual Comments

### Comment 1
<location path="src/utils/taskSegmentation.ts" line_range="49-50" />
<code_context>
+  return segments.leading.length > 0 || segments.trailing.length > 0;
+}
+
+/** 是否应走分段运行(存在特殊段且与游戏段组合) */
+export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {
+  return hasSpecialSegments(segments);
+}
</code_context>
<issue_to_address>
**suggestion (bug_risk):** `needsSegmentedRun` currently returns true whenever there is any leading/trailing segment, regardless of whether a middle/game segment exists.

The docstring says this should only be true when special segments are combined with a game segment, but the implementation is equivalent to `hasSpecialSegments`. For queues with only special tasks and no game tasks, `needsSegmentedRun` will still be true, which could trigger multi-batch execution when there is no middle segment. If this helper is used to decide multi-batch behavior, consider additionally checking that the `middle` segment is non-empty.
</issue_to_address>

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

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

  • The task batching logic in Toolbar and DashboardView (splitting into segments, building configs, and registering task IDs) is now fairly duplicated; consider extracting a shared helper that takes runnableTasks and segment info to reduce repetition and keep the behavior consistent.
  • The new needsSegmentedRun helper in taskSegmentation.ts currently just proxies hasSpecialSegments and doesn’t match its docstring (“存在特殊段且与游戏段组合”); either adjust the implementation to reflect the intended condition or remove it if unused to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The task batching logic in Toolbar and DashboardView (splitting into segments, building configs, and registering task IDs) is now fairly duplicated; consider extracting a shared helper that takes runnableTasks and segment info to reduce repetition and keep the behavior consistent.
- The new `needsSegmentedRun` helper in `taskSegmentation.ts` currently just proxies `hasSpecialSegments` and doesn’t match its docstring (“存在特殊段且与游戏段组合”); either adjust the implementation to reflect the intended condition or remove it if unused to avoid confusion.

## Individual Comments

### Comment 1
<location path="src/utils/taskSegmentation.ts" line_range="49-50" />
<code_context>
+  return segments.leading.length > 0 || segments.trailing.length > 0;
+}
+
+/** 是否应走分段运行(存在特殊段且与游戏段组合) */
+export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {
+  return hasSpecialSegments(segments);
+}
</code_context>
<issue_to_address>
**suggestion (bug_risk):** `needsSegmentedRun` currently returns true whenever there is any leading/trailing segment, regardless of whether a middle/game segment exists.

The docstring says this should only be true when special segments are combined with a game segment, but the implementation is equivalent to `hasSpecialSegments`. For queues with only special tasks and no game tasks, `needsSegmentedRun` will still be true, which could trigger multi-batch execution when there is no middle segment. If this helper is used to decide multi-batch behavior, consider additionally checking that the `middle` segment is non-empty.
</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 +49 to +50
/** 是否应走分段运行(存在特殊段且与游戏段组合) */
export function needsSegmentedRun(segments: ThreeSegmentSplit<unknown>): boolean {

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 (bug_risk): needsSegmentedRun 目前在存在任意前置 / 后置段时都会返回 true,而不管是否存在 middle/game 段。

文档注释说明它只应在“特殊段与游戏段组合”时返回 true,但当前实现等价于 hasSpecialSegments。对于只包含特殊任务而不包含游戏任务的队列,needsSegmentedRun 仍然会是 true,这可能会在没有 middle 段时触发多批次执行。如果这个 helper 用来决定是否进行多批次执行,建议额外检查 middle 段是否非空。

Original comment in English

suggestion (bug_risk): needsSegmentedRun currently returns true whenever there is any leading/trailing segment, regardless of whether a middle/game segment exists.

The docstring says this should only be true when special segments are combined with a game segment, but the implementation is equivalent to hasSpecialSegments. For queues with only special tasks and no game tasks, needsSegmentedRun will still be true, which could trigger multi-batch execution when there is no middle segment. If this helper is used to decide multi-batch behavior, consider additionally checking that the middle segment is non-empty.

@zmdyy0318 zmdyy0318 marked this pull request as ready for review June 28, 2026 16:07
@zmdyy0318

Copy link
Copy Markdown
Contributor Author

自测通过
单独执行游戏任务
单独执行特殊任务
先执行游戏任务,再执行特殊任务

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment