Compare commits
2
Commits
2131f89e62
...
e490a29ceb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e490a29ceb | ||
|
|
66418dce22 |
@@ -85,6 +85,22 @@ codex mcp add limbus --env PYTHONUTF8=1 -- D:\lc-mcp\vendor\aalc\.venv\Scripts\p
|
|||||||
所以任务启动时先把原值写到 `~/lc_mcp/runs/*.restore.json`;`stop_task` 强停或任务进程异常退出后,
|
所以任务启动时先把原值写到 `~/lc_mcp/runs/*.restore.json`;`stop_task` 强停或任务进程异常退出后,
|
||||||
服务会据此写回。写回失败时 `task_status` 显示 `pending_restore`,并在写回成功前拒绝启动新任务。
|
服务会据此写回。写回失败时 `task_status` 显示 `pending_restore`,并在写回成功前拒绝启动新任务。
|
||||||
|
|
||||||
|
`state` 只反映任务子进程的退出码。AALC 在单次战斗失败(例如日志里的
|
||||||
|
`超出最大尝试次数,未能进入战斗`)后仍会继续跑完并正常退出,所以 `task_status`
|
||||||
|
会把日志尾部的 `[ERROR]`/异常行放进 `errors` 字段:**看到 `succeeded` 也要先看 `errors`。**
|
||||||
|
|
||||||
|
### 与上游 AALC 的差异(不改其源码)
|
||||||
|
|
||||||
|
`lc_mcp/aalc_input_patch.py` 在 `bootstrap()` 时给 Windows 输入适配器打补丁,只补上游缺的东西:
|
||||||
|
|
||||||
|
- **编队列表滑动**:AALC 基类要求适配器覆盖 `mouse_swipe_for_team_scroll` 以"规避队伍拖拽判定",
|
||||||
|
但上游只有 MuMu 模拟器适配器覆盖了它(见 `input_handlers/__init__.py` 注释)。Windows 前台/后台适配器
|
||||||
|
仍用普通列表手势 `build_windows_scroll_swipe_plan`(escape 30px/0.01s),在游戏的编队列表里不足以脱离
|
||||||
|
"按住罪人卡"判定,滑动会被当成拖动卡片:队伍顺序被拖乱,缺人时后续还会"未能进入战斗"。
|
||||||
|
补丁按 MuMu 的参数(按 `set_win_size` 缩放 60px escape、保持 0.1s、分段走完、松手前停稳 0.5s)
|
||||||
|
在 `Input`(前台)和 `BackgroundInput`(后台)上补上等价实现;`WindowMoveInput` 没有
|
||||||
|
`set_mouse_pos`,保持原样。
|
||||||
|
|
||||||
## 环境变量
|
## 环境变量
|
||||||
|
|
||||||
| 变量 | 默认 | 说明 |
|
| 变量 | 默认 | 说明 |
|
||||||
|
|||||||
@@ -56,3 +56,20 @@ Windows / Python 3.12.14;基础提交 `030527f5de5c83dd8ea6e53288c1c52f3b4a85b
|
|||||||
## 导出边界
|
## 导出边界
|
||||||
|
|
||||||
仅包含本次报告、人工时间线、清理后的三条 Jev 日志、本次时段的服务日志片段、四张游戏截图及测试输出。未包含 API key、MCP token、私有配置、Codex 聊天文件或其他桌面应用截图。代码修复随本反馈分支提供,未推送到默认分支。
|
仅包含本次报告、人工时间线、清理后的三条 Jev 日志、本次时段的服务日志片段、四张游戏截图及测试输出。未包含 API key、MCP token、私有配置、Codex 聊天文件或其他桌面应用截图。代码修复随本反馈分支提供,未推送到默认分支。
|
||||||
|
|
||||||
|
## 追加:内置经验本流程的编队拖拽缺陷(同分支后续提交)
|
||||||
|
|
||||||
|
原记录把"3 次经验本"当成成功,**这个结论是错的**:只有 2 次真正打完,另一次没进战斗。
|
||||||
|
|
||||||
|
- `~/lc_mcp/runs/task_20261003_105743_daily.log`:`11:05:55 [ERROR] tasks\battle\battle.py:83: 超出最大尝试次数,未能进入战斗`。任务子进程仍 exit 0,所以 `task_status` 当时报 `succeeded`——只看退出码会把这次失败算成成功。
|
||||||
|
- 同日志 `team_formation.py`:`对于配队人数OCR得到:7/5` → `6/5` → `5/5`。AALC 为了进入 5 人副本**点击移除了 TEAMS#1 的两名成员**(实测是六协会以实玛利与 G 公司格里高尔)。这是对用户预设队伍的实际改动,不是只读操作。
|
||||||
|
|
||||||
|
根因(按 submodule 约定不改 AALC 源码,从 lc-mcp 侧打补丁):
|
||||||
|
|
||||||
|
- AALC 基类要求适配器覆盖 `mouse_swipe_for_team_scroll` 以"规避队伍拖拽判定"(`module/automation/input_handlers/__init__.py` 注释),但上游只有 MuMu 模拟器适配器覆盖了它。Windows 前台(本机 `win_input_type=foreground`,日志确认 `使用前台点击模块`)与后台适配器仍用普通列表手势 `build_windows_scroll_swipe_plan`:escape 仅 30px / 0.01s,在编队列表里不足以脱离"按住罪人卡"判定,滑动被当成拖动卡片。
|
||||||
|
- 新增 `lc_mcp/aalc_input_patch.py`:按 MuMu 的参数(按 `set_win_size` 缩放 60px escape、保持 0.1s、分段走完、松手前停稳 0.5s)给 `Input`(前台)与 `BackgroundInput`(后台)补等价实现,在 `bootstrap()` 时安装;`WindowMoveInput` 没有 `set_mouse_pos`,保持原样。
|
||||||
|
- `lc_mcp/tasks.py`:退出码为 0 但日志尾部含 `[ERROR]`/异常行时,`task_status` 增加 `errors` 字段,避免只凭 `succeeded` 判断。
|
||||||
|
|
||||||
|
**验证范围**:滑动的几何与补丁安装有单元测试,101 项回归通过(见 [test-results.txt](test-results.txt),已更新为本次 101 项输出)。**真实编队界面上的滑动没有复测**——当时体力 6/120,不足以进入任何副本。下一次有体力跑经验本时应同时核对编队人数与 `errors`。
|
||||||
|
|
||||||
|
同一时段另有一项与 AALC 流程无关的养成操作:W Corp L3 堂吉诃德人格等级 35 → 37(HP 161→166、防御等级 34→36),消耗 12 张 III 级经验票,剩余 II 级经验票 19 张;升级时游戏服务器报错一次,点 Retry 后成功。
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"exported_at_utc": "2026-10-03T02:55:31.845399+00:00",
|
"exported_at_utc": "2026-10-03T02:55:31.845399+00:00",
|
||||||
"base_commit": "030527f5de5c83dd8ea6e53288c1c52f3b4a85bb",
|
"base_commit": "030527f5de5c83dd8ea6e53288c1c52f3b4a85bb",
|
||||||
"test_exit_code": 0,
|
"test_exit_code": 0,
|
||||||
"tests_passed": 94,
|
"tests_passed": 101,
|
||||||
"main_story_cleared": false,
|
"main_story_cleared": false,
|
||||||
"jev_calls_logged": 3,
|
"jev_calls_logged": 3,
|
||||||
"simultaneous_human_input_confirmed": true,
|
"simultaneous_human_input_confirmed": true,
|
||||||
@@ -49,18 +49,24 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "README.md",
|
"path": "README.md",
|
||||||
"bytes": 7606,
|
"bytes": 10061,
|
||||||
"sha256": "518dea5f19e2dd3beec627a173e86337f2a31e4e8020dab523cd407cf1bb33cc"
|
"sha256": "304d6a53972561e3638d16e5f76f71d738070646375f1439810c013a873d61de"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "test-results.txt",
|
"path": "test-results.txt",
|
||||||
"bytes": 14030,
|
"bytes": 14939,
|
||||||
"sha256": "0e1fd946db3376cd7b727b2f28edfd8955c2e6427895f5a339593589f3c262a0"
|
"sha256": "c6e6d0fccddfd05ba67ef618fd449561543135f570357e9a2b1d2e796d8b385b"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "timeline.jsonl",
|
"path": "timeline.jsonl",
|
||||||
"bytes": 3103,
|
"bytes": 3103,
|
||||||
"sha256": "965f2195f3af3e554b89089cc4735ee3cfcc656f31065a72e7ce59027e58fc83"
|
"sha256": "965f2195f3af3e554b89089cc4735ee3cfcc656f31065a72e7ce59027e58fc83"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"followup": {
|
||||||
|
"date": "2026-10-03",
|
||||||
|
"summary": "内置经验本流程的编队滑动补丁 + task_status errors 字段; 真实编队界面滑动未复测",
|
||||||
|
"third_exp_run_battle_error": true,
|
||||||
|
"teams_1_members_removed_by_aalc": 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
{"step": 0, "choice": "run_complete", "action": {"tool": "run_complete", "args": {}}, "jev_ms": 0, "ocr_ms": 0, "screen": null, "at": "2026-10-03T10:55:22", "state": "completed"}
|
|
||||||
{"step": 0, "choice": "wait", "action": {"tool": "wait", "args": {"seconds": 0.7}}, "jev_ms": 0, "ocr_ms": 0, "screen": null, "at": "2026-10-03T10:55:22", "action_ms": 0, "finished_at": "2026-10-03T10:55:22", "result": {"ok": true, "waited": 0.7}, "state": "running", "battle_context": false}
|
|
||||||
{"step": 1, "choice": "wait", "action": {"tool": "wait", "args": {"seconds": 0.7}}, "jev_ms": 0, "ocr_ms": 0, "screen": null, "at": "2026-10-03T10:55:22", "action_ms": 0, "finished_at": "2026-10-03T10:55:22", "result": {"ok": true, "waited": 0.7}, "state": "running", "battle_context": false}
|
|
||||||
|
|
||||||
test_choice_outside_permitted_actions_is_rejected (test_jev_client.JevClientTest.test_choice_outside_permitted_actions_is_rejected) ... ok
|
test_choice_outside_permitted_actions_is_rejected (test_jev_client.JevClientTest.test_choice_outside_permitted_actions_is_rejected) ... ok
|
||||||
test_configured_model_endpoint_session_and_instructions_reach_api (test_jev_client.JevClientTest.test_configured_model_endpoint_session_and_instructions_reach_api) ... ok
|
test_configured_model_endpoint_session_and_instructions_reach_api (test_jev_client.JevClientTest.test_configured_model_endpoint_session_and_instructions_reach_api) ... ok
|
||||||
test_curl_credentials_only_on_stdin_and_http_errors_not_retried (test_jev_client.JevClientTest.test_curl_credentials_only_on_stdin_and_http_errors_not_retried) ... ok
|
test_curl_credentials_only_on_stdin_and_http_errors_not_retried (test_jev_client.JevClientTest.test_curl_credentials_only_on_stdin_and_http_errors_not_retried) ... ok
|
||||||
test_session_id_stays_stable_across_decisions (test_jev_client.JevClientTest.test_session_id_stays_stable_across_decisions) ... ok
|
test_session_id_stays_stable_across_decisions (test_jev_client.JevClientTest.test_session_id_stays_stable_across_decisions) ... ok
|
||||||
|
{"step": 0, "choice": "run_complete", "action": {"tool": "run_complete", "args": {}}, "jev_ms": 0, "ocr_ms": 0, "screen": null, "at": "2026-10-03T11:25:38", "state": "completed"}
|
||||||
test_completed_run_archives_context_for_next_run (test_jev_mirror_agent.MainLoopTest.test_completed_run_archives_context_for_next_run) ... ok
|
test_completed_run_archives_context_for_next_run (test_jev_mirror_agent.MainLoopTest.test_completed_run_archives_context_for_next_run) ... ok
|
||||||
|
{"step": 0, "choice": "wait", "action": {"tool": "wait", "args": {"seconds": 0.7}}, "jev_ms": 0, "ocr_ms": 0, "screen": null, "at": "2026-10-03T11:25:38", "action_ms": 0, "finished_at": "2026-10-03T11:25:38", "result": {"ok": true, "waited": 0.7}, "state": "running", "battle_context": false}
|
||||||
|
{"step": 1, "choice": "wait", "action": {"tool": "wait", "args": {"seconds": 0.7}}, "jev_ms": 0, "ocr_ms": 0, "screen": null, "at": "2026-10-03T11:25:38", "action_ms": 0, "finished_at": "2026-10-03T11:25:38", "result": {"ok": true, "waited": 0.7}, "state": "running", "battle_context": false}
|
||||||
test_tool_errors_are_observed_instead_of_aborting (test_jev_mirror_agent.MainLoopTest.test_tool_errors_are_observed_instead_of_aborting) ... ok
|
test_tool_errors_are_observed_instead_of_aborting (test_jev_mirror_agent.MainLoopTest.test_tool_errors_are_observed_instead_of_aborting) ... ok
|
||||||
test_ambiguous_event_is_not_assumed_free (test_jev_mirror_agent.SceneRegressionTest.test_ambiguous_event_is_not_assumed_free) ... ok
|
test_ambiguous_event_is_not_assumed_free (test_jev_mirror_agent.SceneRegressionTest.test_ambiguous_event_is_not_assumed_free) ... ok
|
||||||
test_battle_cinematic_keeps_macro_available (test_jev_mirror_agent.SceneRegressionTest.test_battle_cinematic_keeps_macro_available) ... ok
|
test_battle_cinematic_keeps_macro_available (test_jev_mirror_agent.SceneRegressionTest.test_battle_cinematic_keeps_macro_available) ... ok
|
||||||
@@ -90,18 +89,25 @@ test_pythonw_streams_are_redirected_to_log (test_lc_mcp.RuntimeTest.test_pythonw
|
|||||||
test_stdio_isolates_bootstrap_output_and_uses_utf8 (test_lc_mcp.RuntimeTest.test_stdio_isolates_bootstrap_output_and_uses_utf8) ... ok
|
test_stdio_isolates_bootstrap_output_and_uses_utf8 (test_lc_mcp.RuntimeTest.test_stdio_isolates_bootstrap_output_and_uses_utf8) ... ok
|
||||||
test_template_list_is_scanned_once (test_lc_mcp.RuntimeTest.test_template_list_is_scanned_once) ... ok
|
test_template_list_is_scanned_once (test_lc_mcp.RuntimeTest.test_template_list_is_scanned_once) ... ok
|
||||||
test_template_scale_tracks_client_and_restores_config_on_error (test_lc_mcp.RuntimeTest.test_template_scale_tracks_client_and_restores_config_on_error) ... ok
|
test_template_scale_tracks_client_and_restores_config_on_error (test_lc_mcp.RuntimeTest.test_template_scale_tracks_client_and_restores_config_on_error) ... ok
|
||||||
|
test_clean_log_has_no_errors_field (test_lc_mcp.TaskErrorSurfaceTest.test_clean_log_has_no_errors_field) ... ok
|
||||||
|
test_exit_zero_with_battle_error_is_reported (test_lc_mcp.TaskErrorSurfaceTest.test_exit_zero_with_battle_error_is_reported) ... ok
|
||||||
test_leftover_restored_before_next_start_or_start_refused (test_lc_mcp.TaskRestoreTest.test_leftover_restored_before_next_start_or_start_refused) ... ok
|
test_leftover_restored_before_next_start_or_start_refused (test_lc_mcp.TaskRestoreTest.test_leftover_restored_before_next_start_or_start_refused) ... ok
|
||||||
test_stop_restores_overridden_config (test_lc_mcp.TaskRestoreTest.test_stop_restores_overridden_config) ... ok
|
test_stop_restores_overridden_config (test_lc_mcp.TaskRestoreTest.test_stop_restores_overridden_config) ... ok
|
||||||
|
test_downward_swipe_shifts_start_into_visible_rows (test_lc_mcp.TeamScrollPatchTest.test_downward_swipe_shifts_start_into_visible_rows) ... ok
|
||||||
|
test_escape_leg_has_requested_length (test_lc_mcp.TeamScrollPatchTest.test_escape_leg_has_requested_length) ... ok
|
||||||
|
test_install_patches_team_scroll_on_windows_adapters (test_lc_mcp.TeamScrollPatchTest.test_install_patches_team_scroll_on_windows_adapters) ... ok
|
||||||
|
test_upward_swipe_escapes_first_then_travels_nominal_delta (test_lc_mcp.TeamScrollPatchTest.test_upward_swipe_escapes_first_then_travels_nominal_delta) ... ok
|
||||||
|
test_zero_distance_is_noop (test_lc_mcp.TeamScrollPatchTest.test_zero_distance_is_noop) ... ok
|
||||||
test_bridge_end_to_end (test_lc_mcp.TransportTest.test_bridge_end_to_end) ... ok
|
test_bridge_end_to_end (test_lc_mcp.TransportTest.test_bridge_end_to_end) ... ok
|
||||||
test_bridge_offline (test_lc_mcp.TransportTest.test_bridge_offline) ... ok
|
test_bridge_offline (test_lc_mcp.TransportTest.test_bridge_offline) ... ok
|
||||||
test_client_disconnect_is_not_a_server_error (test_lc_mcp.TransportTest.test_client_disconnect_is_not_a_server_error) ... ok
|
test_client_disconnect_is_not_a_server_error (test_lc_mcp.TransportTest.test_client_disconnect_is_not_a_server_error) ... ok
|
||||||
test_non_ascii_token_is_denied_not_crashed (test_lc_mcp.TransportTest.test_non_ascii_token_is_denied_not_crashed) ... [lc_mcp] rejected connection from ('127.0.0.1', 56231)
|
test_non_ascii_token_is_denied_not_crashed (test_lc_mcp.TransportTest.test_non_ascii_token_is_denied_not_crashed) ... [lc_mcp] rejected connection from ('127.0.0.1', 51723)
|
||||||
ok
|
ok
|
||||||
test_stdio_server (test_lc_mcp.TransportTest.test_stdio_server) ... ok
|
test_stdio_server (test_lc_mcp.TransportTest.test_stdio_server) ... ok
|
||||||
test_wrong_token_rejected (test_lc_mcp.TransportTest.test_wrong_token_rejected) ... [lc_mcp] rejected connection from ('127.0.0.1', 56234)
|
test_wrong_token_rejected (test_lc_mcp.TransportTest.test_wrong_token_rejected) ... [lc_mcp] rejected connection from ('127.0.0.1', 51726)
|
||||||
ok
|
ok
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Ran 94 tests in 8.693s
|
Ran 101 tests in 8.912s
|
||||||
|
|
||||||
OK
|
OK
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ def bootstrap():
|
|||||||
from module.logger.my_log import Logger
|
from module.logger.my_log import Logger
|
||||||
Logger()
|
Logger()
|
||||||
_booted = d
|
_booted = d
|
||||||
|
# 编队列表滑动: Windows 输入适配器缺队伍拖拽规避, 上游只有模拟器适配器有。
|
||||||
|
# 在导入 AALC 之后立即打补丁, 服务的 MCP 输入与 run_task 子进程都会生效。
|
||||||
|
from . import aalc_input_patch
|
||||||
|
aalc_input_patch.install()
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""编队列表滑动补丁: 给 Windows 输入适配器补上队伍拖拽规避。
|
||||||
|
|
||||||
|
AALC 基类注释说明 ``mouse_swipe_for_team_scroll`` 需要适配器覆盖以"规避队伍
|
||||||
|
拖拽判定", 但上游只有 MuMu 模拟器适配器覆盖了它; Windows 的前台(Input)与后台
|
||||||
|
(BackgroundInput)适配器仍在用普通列表滚动手势 ``build_windows_scroll_swipe_plan``:
|
||||||
|
按下后只 escape 30px / 0.01s。在游戏的编队列表里这不足以脱离"按住罪人卡"的
|
||||||
|
判定, 滑动会被当成拖动卡片 —— 队伍顺序被拖乱, 编队人数不足时还会让后续的
|
||||||
|
"进入战斗"失败(battle.py 报"未能进入战斗")。
|
||||||
|
|
||||||
|
这里按 MuMu 的参数(按 set_win_size 缩放的 60px escape、保持 0.1s、分段走完、
|
||||||
|
松手前停稳 0.5s)在 Windows 适配器上补一份等价实现, 不改 AALC 源码。
|
||||||
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
|
from math import hypot
|
||||||
|
|
||||||
|
# 与 MuMu 覆盖实现保持一致的量级
|
||||||
|
ESCAPE_AT_1080P = 60
|
||||||
|
ESCAPE_HOLD_SECONDS = 0.1
|
||||||
|
SETTLE_SECONDS = 0.5
|
||||||
|
POINT_SPACING_AT_1080P = 8
|
||||||
|
MIN_SEGMENT_DURATION = 0.05
|
||||||
|
|
||||||
|
|
||||||
|
def team_scroll_plan(x, y, dx, dy, duration, escape_distance):
|
||||||
|
"""编队列表滑动的几何路径(纯函数, 便于单测)。
|
||||||
|
|
||||||
|
返回 ``(start, escape, end, duration)``; ``distance == 0`` 时返回 None。
|
||||||
|
向下滑动(dy > 0)时把起点沿反向偏移 escape, 终点沿正向多走 escape,
|
||||||
|
这样手指/指针能落在可见行内, 同时保持总位移不变。
|
||||||
|
"""
|
||||||
|
distance = hypot(dx, dy)
|
||||||
|
if distance == 0:
|
||||||
|
return None
|
||||||
|
unit_x, unit_y = dx / distance, dy / distance
|
||||||
|
if dy > 0:
|
||||||
|
start = (x - unit_x * escape_distance, y - unit_y * escape_distance)
|
||||||
|
else:
|
||||||
|
start = (float(x), float(y))
|
||||||
|
end = (start[0] + dx + unit_x * escape_distance,
|
||||||
|
start[1] + dy + unit_y * escape_distance)
|
||||||
|
escape = (start[0] + unit_x * escape_distance,
|
||||||
|
start[1] + unit_y * escape_distance)
|
||||||
|
return start, escape, end, max(0.0, float(duration))
|
||||||
|
|
||||||
|
|
||||||
|
def _scaled_escape():
|
||||||
|
from module.config import cfg
|
||||||
|
return ESCAPE_AT_1080P * cfg.set_win_size / 1080
|
||||||
|
|
||||||
|
|
||||||
|
def _segment_steps(escape_point, end):
|
||||||
|
"""把 escape 之后的剩余位移切成小段, 返回 (段数, 位移x, 位移y)。"""
|
||||||
|
from module.config import cfg
|
||||||
|
|
||||||
|
move_x = end[0] - escape_point[0]
|
||||||
|
move_y = end[1] - escape_point[1]
|
||||||
|
distance = hypot(move_x, move_y)
|
||||||
|
if distance == 0:
|
||||||
|
return 0, 0.0, 0.0
|
||||||
|
spacing = POINT_SPACING_AT_1080P * cfg.set_win_size / 1080
|
||||||
|
steps = max(int(distance / max(spacing, 1.0)), 1)
|
||||||
|
return steps, move_x, move_y
|
||||||
|
|
||||||
|
|
||||||
|
def _foreground_team_scroll(self, x, y, duration=0.3, dx=0, dy=0, move_back=True):
|
||||||
|
"""前台输入(pyautogui)下的编队列表滑动。"""
|
||||||
|
import pyautogui
|
||||||
|
|
||||||
|
plan = team_scroll_plan(x, y, dx, dy, duration, _scaled_escape())
|
||||||
|
if plan is None:
|
||||||
|
return
|
||||||
|
start, escape, end, total_duration = plan
|
||||||
|
restore = self.get_mouse_position() if move_back else None
|
||||||
|
|
||||||
|
sx, sy = self.pos_offset(*start)
|
||||||
|
ex, ey = self.pos_offset(*escape)
|
||||||
|
fx, fy = self.pos_offset(*end)
|
||||||
|
|
||||||
|
pyautogui.moveTo(sx, sy)
|
||||||
|
pyautogui.mouseDown(sx, sy)
|
||||||
|
try:
|
||||||
|
pyautogui.moveTo(ex, ey, duration=MIN_SEGMENT_DURATION)
|
||||||
|
# 让游戏渲染一帧, 确认这是滚动而不是按住卡片。
|
||||||
|
time.sleep(ESCAPE_HOLD_SECONDS)
|
||||||
|
steps, move_x, move_y = _segment_steps(escape, end)
|
||||||
|
if steps:
|
||||||
|
step_duration = max(total_duration, MIN_SEGMENT_DURATION) / steps
|
||||||
|
for index in range(1, steps + 1):
|
||||||
|
ratio = index / steps
|
||||||
|
pyautogui.moveTo(ex + move_x * ratio, ey + move_y * ratio,
|
||||||
|
duration=step_duration)
|
||||||
|
time.sleep(SETTLE_SECONDS)
|
||||||
|
finally:
|
||||||
|
pyautogui.mouseUp(fx, fy)
|
||||||
|
|
||||||
|
if restore:
|
||||||
|
self.mouse_move(restore)
|
||||||
|
|
||||||
|
|
||||||
|
def _adapter_team_scroll(self, x, y, duration=0.3, dx=0, dy=0, move_back=True):
|
||||||
|
"""后台/其它 Windows 适配器下的编队列表滑动(走适配器自身的原语)。"""
|
||||||
|
plan = team_scroll_plan(x, y, dx, dy, duration, _scaled_escape())
|
||||||
|
if plan is None:
|
||||||
|
return
|
||||||
|
start, escape, end, total_duration = plan
|
||||||
|
restore = self.get_mouse_position() if move_back else None
|
||||||
|
|
||||||
|
self.set_active()
|
||||||
|
self.set_mouse_pos(*start)
|
||||||
|
self.mouse_down(*start)
|
||||||
|
try:
|
||||||
|
self.set_mouse_pos(*escape, duration=MIN_SEGMENT_DURATION)
|
||||||
|
time.sleep(ESCAPE_HOLD_SECONDS)
|
||||||
|
steps, move_x, move_y = _segment_steps(escape, end)
|
||||||
|
if steps:
|
||||||
|
step_duration = max(total_duration, MIN_SEGMENT_DURATION) / steps
|
||||||
|
for index in range(1, steps + 1):
|
||||||
|
ratio = index / steps
|
||||||
|
self.set_mouse_pos(escape[0] + move_x * ratio,
|
||||||
|
escape[1] + move_y * ratio,
|
||||||
|
duration=step_duration)
|
||||||
|
time.sleep(SETTLE_SECONDS)
|
||||||
|
finally:
|
||||||
|
self.mouse_up(*end)
|
||||||
|
|
||||||
|
if restore:
|
||||||
|
self.mouse_move(restore)
|
||||||
|
|
||||||
|
|
||||||
|
def install():
|
||||||
|
"""给 AALC 的 Windows 输入适配器装上队伍安全滑动。幂等。"""
|
||||||
|
from module.automation.input_handlers import input as input_module
|
||||||
|
|
||||||
|
patched = []
|
||||||
|
cls = getattr(input_module, 'Input', None)
|
||||||
|
if cls is not None and getattr(cls, 'mouse_swipe_for_team_scroll', None) \
|
||||||
|
is not _foreground_team_scroll:
|
||||||
|
cls.mouse_swipe_for_team_scroll = _foreground_team_scroll
|
||||||
|
patched.append('Input')
|
||||||
|
|
||||||
|
for name in ('BackgroundInput', 'WindowMoveInput'):
|
||||||
|
cls = getattr(input_module, name, None)
|
||||||
|
if cls is None or not hasattr(cls, 'set_mouse_pos'):
|
||||||
|
continue
|
||||||
|
if getattr(cls, 'mouse_swipe_for_team_scroll', None) is _adapter_team_scroll:
|
||||||
|
continue
|
||||||
|
cls.mouse_swipe_for_team_scroll = _adapter_team_scroll
|
||||||
|
patched.append(name)
|
||||||
|
return patched
|
||||||
@@ -35,6 +35,22 @@ def tail(path, n):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
ERROR_MARKERS = ('[ERROR]', 'Traceback (most recent call last)')
|
||||||
|
ERROR_SCAN_LINES = 400
|
||||||
|
|
||||||
|
|
||||||
|
def log_errors(path, limit=3):
|
||||||
|
"""挑出日志尾部的报错行。
|
||||||
|
|
||||||
|
AALC 的每日流程在单次战斗失败后会继续跑完并正常退出(exit 0), 只看退出码
|
||||||
|
会把"超出最大尝试次数,未能进入战斗"这类失败当成成功, 所以状态里额外附上
|
||||||
|
日志里的报错行。
|
||||||
|
"""
|
||||||
|
hits = [line for line in tail(path, ERROR_SCAN_LINES)
|
||||||
|
if any(marker in line for marker in ERROR_MARKERS)]
|
||||||
|
return hits[-limit:]
|
||||||
|
|
||||||
|
|
||||||
class TaskRunner:
|
class TaskRunner:
|
||||||
|
|
||||||
def __init__(self, run_dir, argv_factory=default_argv, keep_logs=20, restore_argv=default_restore_argv):
|
def __init__(self, run_dir, argv_factory=default_argv, keep_logs=20, restore_argv=default_restore_argv):
|
||||||
@@ -112,6 +128,9 @@ class TaskRunner:
|
|||||||
'log': self.info['log'], 'log_tail': tail(self.info['log'], max(1, min(int(lines), 200)))}
|
'log': self.info['log'], 'log_tail': tail(self.info['log'], max(1, min(int(lines), 200)))}
|
||||||
if code is not None:
|
if code is not None:
|
||||||
r['exit_code'] = code
|
r['exit_code'] = code
|
||||||
|
errors = log_errors(self.info['log'])
|
||||||
|
if errors:
|
||||||
|
r['errors'] = errors
|
||||||
pending = self._pending_restores()
|
pending = self._pending_restores()
|
||||||
if pending:
|
if pending:
|
||||||
r['pending_restore'] = [os.path.basename(p) for p in pending]
|
r['pending_restore'] = [os.path.basename(p) for p in pending]
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||||||
sys.path.insert(0, REPO)
|
sys.path.insert(0, REPO)
|
||||||
|
|
||||||
from lc_mcp import server as srv_mod # noqa: E402
|
from lc_mcp import server as srv_mod # noqa: E402
|
||||||
|
from lc_mcp import aalc_input_patch # noqa: E402
|
||||||
from lc_mcp.engine import find_hits # noqa: E402
|
from lc_mcp.engine import find_hits # noqa: E402
|
||||||
from lc_mcp.fake_engine import FakeEngine # noqa: E402
|
from lc_mcp.fake_engine import FakeEngine # noqa: E402
|
||||||
from lc_mcp.protocol import Server, TOOLS # noqa: E402
|
from lc_mcp.protocol import Server, TOOLS # noqa: E402
|
||||||
@@ -580,5 +581,110 @@ class TransportTest(unittest.TestCase):
|
|||||||
self.assertEqual((state['ok'], state['items']), (True, []))
|
self.assertEqual((state['ok'], state['items']), (True, []))
|
||||||
|
|
||||||
|
|
||||||
|
class TaskErrorSurfaceTest(unittest.TestCase):
|
||||||
|
"""AALC 每日流程单次战斗失败后仍 exit 0; 状态里必须带出日志报错。"""
|
||||||
|
|
||||||
|
CHILD = ('import sys; '
|
||||||
|
'sys.stdout.write("[ERROR] [AALC] tasks\\\\battle\\\\battle.py:83: '
|
||||||
|
'超出最大尝试次数,未能进入战斗\\n"); '
|
||||||
|
'sys.stdout.write("[lc_mcp] task daily done\\n"); '
|
||||||
|
'sys.stdout.flush()')
|
||||||
|
|
||||||
|
def test_exit_zero_with_battle_error_is_reported(self):
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
runner = TaskRunner(d, argv_factory=lambda t, p: [sys.executable, '-c', self.CHILD])
|
||||||
|
self.assertTrue(runner.start('daily', {'exp': 1})['ok'])
|
||||||
|
deadline = time.time() + 15
|
||||||
|
while time.time() < deadline and runner.running():
|
||||||
|
time.sleep(0.05)
|
||||||
|
status = runner.status()
|
||||||
|
self.assertEqual((status['state'], status['exit_code']), ('succeeded', 0), status)
|
||||||
|
self.assertIn('未能进入战斗', status['errors'][-1])
|
||||||
|
|
||||||
|
def test_clean_log_has_no_errors_field(self):
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
runner = TaskRunner(d, argv_factory=lambda t, p: [sys.executable, '-c', 'print("[lc_mcp] ok")'])
|
||||||
|
self.assertTrue(runner.start('daily', {})['ok'])
|
||||||
|
deadline = time.time() + 15
|
||||||
|
while time.time() < deadline and runner.running():
|
||||||
|
time.sleep(0.05)
|
||||||
|
status = runner.status()
|
||||||
|
self.assertEqual(status['state'], 'succeeded')
|
||||||
|
self.assertNotIn('errors', status)
|
||||||
|
|
||||||
|
|
||||||
|
class TeamScrollPatchTest(unittest.TestCase):
|
||||||
|
"""编队列表滑动: Windows 适配器缺少队伍拖拽规避, 补丁的几何必须是
|
||||||
|
"先 escape 脱离按住判定, 再按名义位移走完"。
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_zero_distance_is_noop(self):
|
||||||
|
self.assertIsNone(aalc_input_patch.team_scroll_plan(10, 20, 0, 0, 0.3, 60))
|
||||||
|
|
||||||
|
def test_upward_swipe_escapes_first_then_travels_nominal_delta(self):
|
||||||
|
start, escape, end, duration = aalc_input_patch.team_scroll_plan(100, 200, 0, -200, 0.4, 60)
|
||||||
|
self.assertEqual(start, (100.0, 200.0))
|
||||||
|
self.assertEqual(escape, (100.0, 140.0))
|
||||||
|
self.assertEqual(end, (100.0, -60.0))
|
||||||
|
self.assertAlmostEqual(end[1] - escape[1], -200.0)
|
||||||
|
self.assertEqual(duration, 0.4)
|
||||||
|
|
||||||
|
def test_downward_swipe_shifts_start_into_visible_rows(self):
|
||||||
|
start, escape, end, _ = aalc_input_patch.team_scroll_plan(100, 200, 0, 200, 0.4, 60)
|
||||||
|
self.assertEqual(start, (100.0, 140.0))
|
||||||
|
self.assertEqual(escape, (100.0, 200.0))
|
||||||
|
self.assertEqual(end, (100.0, 400.0))
|
||||||
|
self.assertAlmostEqual(end[1] - escape[1], 200.0)
|
||||||
|
|
||||||
|
def test_escape_leg_has_requested_length(self):
|
||||||
|
start, escape, end, _ = aalc_input_patch.team_scroll_plan(0, 0, 300, -400, 0.5, 50)
|
||||||
|
leg = (escape[0] - start[0], escape[1] - start[1])
|
||||||
|
self.assertAlmostEqual((leg[0] ** 2 + leg[1] ** 2) ** 0.5, 50.0)
|
||||||
|
self.assertAlmostEqual(end[0] - escape[0], 300.0)
|
||||||
|
self.assertAlmostEqual(end[1] - escape[1], -400.0)
|
||||||
|
|
||||||
|
def test_install_patches_team_scroll_on_windows_adapters(self):
|
||||||
|
import types
|
||||||
|
|
||||||
|
class FakeInput:
|
||||||
|
def mouse_swipe_for_team_scroll(self, *args, **kwargs):
|
||||||
|
raise AssertionError('未打补丁')
|
||||||
|
|
||||||
|
class FakeBackground:
|
||||||
|
def set_mouse_pos(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def mouse_swipe_for_team_scroll(self, *args, **kwargs):
|
||||||
|
raise AssertionError('未打补丁')
|
||||||
|
|
||||||
|
class FakeWindowMove:
|
||||||
|
"""没有 set_mouse_pos 的适配器保持原样。"""
|
||||||
|
|
||||||
|
def mouse_swipe_for_team_scroll(self, *args, **kwargs):
|
||||||
|
raise AssertionError('未打补丁')
|
||||||
|
|
||||||
|
leaf = types.ModuleType('module.automation.input_handlers.input')
|
||||||
|
leaf.Input = FakeInput
|
||||||
|
leaf.BackgroundInput = FakeBackground
|
||||||
|
leaf.WindowMoveInput = FakeWindowMove
|
||||||
|
parents = {}
|
||||||
|
for name in ('module', 'module.automation', 'module.automation.input_handlers'):
|
||||||
|
parents[name] = types.ModuleType(name)
|
||||||
|
parents[name].__path__ = []
|
||||||
|
parents['module.automation.input_handlers'].input = leaf
|
||||||
|
parents['module.automation'].input_handlers = parents['module.automation.input_handlers']
|
||||||
|
parents['module'].automation = parents['module.automation']
|
||||||
|
|
||||||
|
with mock.patch.dict(sys.modules, parents):
|
||||||
|
patched = aalc_input_patch.install()
|
||||||
|
self.assertEqual(patched, ['Input', 'BackgroundInput'])
|
||||||
|
self.assertIs(FakeInput.mouse_swipe_for_team_scroll,
|
||||||
|
aalc_input_patch._foreground_team_scroll)
|
||||||
|
self.assertIs(FakeBackground.mouse_swipe_for_team_scroll,
|
||||||
|
aalc_input_patch._adapter_team_scroll)
|
||||||
|
# 幂等: 再装一次不再重复补
|
||||||
|
self.assertEqual(aalc_input_patch.install(), [])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user