Skip to content

feat: 同步 next_monday、任务结束关机、单次领奖卡住与道馆建馆修复 (#2)#1613

Open
huiyuhang1 wants to merge 1 commit into
runhey:devfrom
huiyuhang1:cursor/squash-upstream-dev-pr-139b
Open

feat: 同步 next_monday、任务结束关机、单次领奖卡住与道馆建馆修复 (#2)#1613
huiyuhang1 wants to merge 1 commit into
runhey:devfrom
huiyuhang1:cursor/squash-upstream-dev-pr-139b

Conversation

@huiyuhang1
Copy link
Copy Markdown

@huiyuhang1 huiyuhang1 commented Jun 5, 2026

  • feat(Scheduler): 添加 next_monday 运行支持

  • feat(Wait): 添加任务完毕关闭电脑选项

  • fix(CollectiveMissions): 修复单次领奖时循环等待卡住

  • fix(Dokan): 优化道馆建立逻辑,移除周一限制


由 Sourcery 生成的摘要

新增可选的下周一调度功能、支持任务完成后关闭电脑、修复单次领取任务奖励导致卡住的问题,并放宽 Dokan 创建对工作日的限制。

新功能:

  • 引入调度器标志,用于将下次运行延迟到下一个周一。
  • 新增配置选项,当任务队列为空时关闭电脑。

错误修复:

  • 在集体任务的捐赠和喂食流程中,当只有一个奖励弹窗出现时,避免出现无限等待的情况。
  • 通过移除工作日限制,允许在非周一创建 Dokan。
Original summary in English

Summary by Sourcery

Add optional next-Monday scheduling, support shutting down the computer after tasks complete, prevent single-claim mission rewards from hanging, and relax Dokan creation weekday constraints.

New Features:

  • Introduce a scheduler flag to delay next runs until the next Monday.
  • Add a configuration option to shut down the computer when the task queue is empty.

Bug Fixes:

  • Avoid infinite waiting when only a single reward popup appears in Collective Missions donation and feeding flows.
  • Allow Dokan creation outside of Monday by removing the weekday restriction.

* feat(Scheduler): 添加 next_monday 运行支持

Co-authored-by: huiyuhang1 <huiyuhang1@users.noreply.github.com>

* feat(Wait): 添加任务完毕关闭电脑选项

Co-authored-by: huiyuhang1 <huiyuhang1@users.noreply.github.com>

* fix(CollectiveMissions): 修复单次领奖时循环等待卡住

Co-authored-by: huiyuhang1 <huiyuhang1@users.noreply.github.com>

* fix(Dokan): 优化道馆建立逻辑,移除周一限制

Co-authored-by: huiyuhang1 <huiyuhang1@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: huiyuhang1 <huiyuhang1@users.noreply.github.com>
Copy link
Copy Markdown

@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 个问题,并留下了一些高层次的反馈:

  • _wait_close_computer 中,调用 os.system('shutdown /s /t 1') 是特定于 Windows 的,而且在执行该命令后立刻等待到 next_run 很可能是多余的,或者在关机后根本不会被执行;建议让这一逻辑具备平台感知能力,并在安排关机后立刻返回。
  • task_delay 中关于 next_monday 的调度逻辑(通过计算 today = next_run - timedelta(days=1) 然后再计算 days_until_monday)有点晦涩,而且可能比较容易出错;建议将这段逻辑重构成一个语义更清晰的小工具函数(例如显式地从 next_run 计算下一个周一),以提升可读性和可维护性。
面向 AI 代理的提示
请根据这次代码审查中的评论进行修改:

## 总体评论
-`_wait_close_computer` 中,调用 `os.system('shutdown /s /t 1')` 是特定于 Windows 的,而且在执行该命令后立刻等待到 `next_run` 很可能是多余的,或者在关机后根本不会被执行;建议让这一逻辑具备平台感知能力,并在安排关机后立刻返回。
- `task_delay` 中关于 `next_monday` 的调度逻辑(通过计算 `today = next_run - timedelta(days=1)` 然后再计算 `days_until_monday`)有点晦涩,而且可能比较容易出错;建议将这段逻辑重构成一个语义更清晰的小工具函数(例如显式地从 `next_run` 计算下一个周一),以提升可读性和可维护性。

## 单独评论

### 评论 1
<location path="script.py" line_range="441-443" />
<code_context>
         self.device.release_during_wait()
         return self.wait_until(next_run)

+    def _wait_close_computer(self, next_run: datetime) -> bool:
+        logger.info("Close computer during wait")
+        os.system('shutdown /s /t 1')
+        return self.wait_until(next_run)
+
</code_context>
<issue_to_address>
**issue (bug_risk):** 直接调用 `os.system('shutdown /s /t 1')` 在不同环境和平台上存在风险。

这条命令会在所有运行该代码的平台上执行,包括本地开发环境、CI 或其他非 Windows / 配置错误的环境,并可能强制关闭这些系统。请至少通过平台检查(例如使用 `sys.platform`)对其进行保护,更理想的方式是通过配置或抽象进行控制,使其可以在非生产环境中被禁用或模拟。此外,如果关机命令执行成功,后续的 `wait_until` 调用将永远不会执行,因此在这里依赖它的返回值是有误导性的。
</issue_to_address>

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

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

  • In _wait_close_computer, calling os.system('shutdown /s /t 1') is Windows-specific and then immediately waiting until next_run is likely unnecessary or never reached after shutdown; consider making this platform-aware and returning immediately after scheduling shutdown.
  • The next_monday scheduling logic in task_delay (computing today = next_run - timedelta(days=1) and then days_until_monday) is a bit opaque and could be error-prone; refactoring this into a small helper with clearer semantics (e.g., explicitly computing the next Monday from next_run) would improve readability and maintainability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `_wait_close_computer`, calling `os.system('shutdown /s /t 1')` is Windows-specific and then immediately waiting until `next_run` is likely unnecessary or never reached after shutdown; consider making this platform-aware and returning immediately after scheduling shutdown.
- The `next_monday` scheduling logic in `task_delay` (computing `today = next_run - timedelta(days=1)` and then `days_until_monday`) is a bit opaque and could be error-prone; refactoring this into a small helper with clearer semantics (e.g., explicitly computing the next Monday from `next_run`) would improve readability and maintainability.

## Individual Comments

### Comment 1
<location path="script.py" line_range="441-443" />
<code_context>
         self.device.release_during_wait()
         return self.wait_until(next_run)

+    def _wait_close_computer(self, next_run: datetime) -> bool:
+        logger.info("Close computer during wait")
+        os.system('shutdown /s /t 1')
+        return self.wait_until(next_run)
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Calling `os.system('shutdown /s /t 1')` directly is risky across environments and platforms.

This command will run on any platform where this code executes, including local dev, CI, or other non-Windows/misconfigured environments, and may forcibly shut them down. Please at least guard it with a platform check (e.g. via `sys.platform`) and ideally gate it behind configuration/abstraction so it can be disabled or mocked outside production. Also, if the shutdown succeeds, the subsequent `wait_until` call will never execute, so relying on its return value here is misleading.
</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 thread script.py
Comment on lines +441 to +443
def _wait_close_computer(self, next_run: datetime) -> bool:
logger.info("Close computer during wait")
os.system('shutdown /s /t 1')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): 直接调用 os.system('shutdown /s /t 1') 在不同环境和平台上存在风险。

这条命令会在所有运行该代码的平台上执行,包括本地开发环境、CI 或其他非 Windows / 配置错误的环境,并可能强制关闭这些系统。请至少通过平台检查(例如使用 sys.platform)对其进行保护,更理想的方式是通过配置或抽象进行控制,使其可以在非生产环境中被禁用或模拟。此外,如果关机命令执行成功,后续的 wait_until 调用将永远不会执行,因此在这里依赖它的返回值是有误导性的。

Original comment in English

issue (bug_risk): Calling os.system('shutdown /s /t 1') directly is risky across environments and platforms.

This command will run on any platform where this code executes, including local dev, CI, or other non-Windows/misconfigured environments, and may forcibly shut them down. Please at least guard it with a platform check (e.g. via sys.platform) and ideally gate it behind configuration/abstraction so it can be disabled or mocked outside production. Also, if the shutdown succeeds, the subsequent wait_until call will never execute, so relying on its return value here is misleading.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Findings

  • C1 [风险]
    位置:PR 整体变更(module/config/config.pyscript.pytasks/CollectiveMissions/script_task.pytasks/Dokan/script_task.py)
    原因:这个 PR 同时引入 next_monday 调度、任务结束关机、集体任务领奖卡死修复、道馆建馆时机调整,属于多个独立功能/修复打包提交。
    修改:按目标拆分为独立 PR,至少把调度增强、空闲关机和两个任务修复分开。
  • C2 [风险]
    位置:script.py_wait_close_computer()
    原因:这里直接执行 os.system('shutdown /s /t 1') 后继续 wait_until(next_run),没有判断命令是否成功;在非 Windows 环境下会静默失败并进入普通等待,关机分支没有明确失败退出。
    修改:先按平台判断并校验关机命令返回值,失败时显式记录并回退到已有等待策略或抛出异常。
  • C6 [风险]
    位置:tasks/Component/config_scheduler.pytasks/Script/config_optimization.pyconfig/template.jsonassets/i18n/*.json
    原因:新增了 scheduler.next_mondaywhen_task_queue_empty=close_computer,但 config/template.json 没同步这些字段,assets/i18n 也没有新增对应文案,配置默认值和界面翻译会不同步。
    修改:把新字段补到实际生效的模板配置,并同步补齐中英文 i18n 文案。

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com

💡 Tip: api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"

See Network Configuration for more information.

Generated by PR Review Checklist for issue #1613 · gpt54 1.5M ·

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Change Summary

  • 调度层新增了 next_monday 开关,并把 task_delay(..., target=...)server=True 同时出现时的计算路径改成了“直接在目标时间上加随机浮动”。
  • 空闲策略新增 close_computer,当任务队列为空时会直接执行系统关机命令。
  • CollectiveMissions 的捐赠/喂食领奖循环不再默认无限等待第二个奖励弹窗,而是在领到第一个奖励后最多再等 10 秒。
  • Dokan 移除了“仅周一尝试建馆”的显式门槛,进入寻找道馆场景后只要配置允许就会尝试建馆。

Reconstructed Intent

点击此处展开 - 这次改动最可能是在补齐三类行为:一是让部分任务可以被同步到“下一个周一”再运行;二是让脚本在空闲期支持“任务跑完后直接关机”;三是修复集体任务在只出现单次领奖时的卡死。 - `Dokan` 这部分更像是在放宽既有流程约束:不再把“建馆”限定在周一,而是交给当前场景与权限判断决定是否尝试。

Observed Constraints

点击此处展开 - `next_monday` 依赖现有调度入口最终都会走 `Config.task_delay()`;同时它是在已有 `next_run` 计算完成后再二次改写日期,因此会继承原有 `success_interval` / `target` / `server_update` 的结果。 - 这次为了支持 `next_monday`,顺带把 `target is not None` 纳入了 `server=True` 的“直接追加随机浮动”分支;这会改变现有 `sync_next_run` 这类传入明确目标时间的调用语义,不再走 `parse_tomorrow_server(...)`。 - `close_computer` 当前直接执行 `shutdown /s /t 1`,实现上明显依赖宿主机接受这一命令格式;如果运行环境不是 Windows,行为是否失败、阻塞或静默无效,这里都没有额外兜底。 - 集体任务的领奖修复依赖一个隐含前提:正常双倍场景下第二个奖励弹窗会在 10 秒内出现,否则流程会按“只有一次奖励”提前结束。 - `Dokan` 放开周一限制后,是否应该建馆就完全依赖 `try_start_dokan`、当前场景识别以及 `creat_dokan()` 自身幂等性;外层不再提供日期边界保护。

Intent Alignment

  • 整体上与推断 intent 基本一致:单次领奖卡死修复和道馆建馆放宽都直接落在对应流程上。
  • 但调度部分不只是“增加 next_monday”,还引入了额外行为变化:传入明确 target 的延时逻辑现在也会被 server=True 分支附加随机浮动,这一点超出了“同步到下周一”的最小改动范围。

Release Risk

  • 风险等级:中
  • 调度语义有扩大:sync_next_run 一类调用现在会受随机浮动影响,维护者需要确认这是否符合“同步 next run”预期,否则可能出现前端/外部调用给定了精确时间但实际落点被偏移。
  • close_computer 是宿主机级副作用,且当前实现没有平台判断与失败处理;一旦配置误开,影响不是单个任务而是整个运行环境。
  • Dokan 去掉周一门槛后,建馆尝试频率会增加,若 creat_dokan() 或场景识别并非严格幂等,可能把原本由日期限制遮住的问题暴露出来。

Validation Gaps

点击此处展开 - 需要确认 `sync_next_run` / 手动同步下次运行时间时,带 `server=True` 的目标时间偏移是否是有意设计,而不是为了 `next_monday` 顺手改坏了既有语义。 - 需要至少覆盖一次非双倍与双倍两种 `CollectiveMissions` 场景,确认 10 秒窗口不会把慢弹出的第二个奖励误判为单次奖励。 - 需要验证 `close_computer` 在项目实际支持的宿主环境上的行为,尤其是非 Windows 或模拟器托管场景下的失败模式。 - 需要验证非周一进入 `Dokan` 时,`creat_dokan()` 在“已有馆 / 无权限 / 不可建馆”几类场景下是否会安全退出,而不是反复触发无效尝试。

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • api.github.com
  • github.com

💡 Tip: api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "api.github.com"
    - "github.com"

See Network Configuration for more information.

Generated by PR Review Intent for issue #1613 · gpt54 1.1M ·

@runhey
Copy link
Copy Markdown
Owner

runhey commented Jun 6, 2026

  1. 分多个pr而不是一个。
  2. next_monday 直接塞到Scheduler(ConfigBase)导致所有任务都有一个莫名其妙的字段,很多时候都用不到

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