普通镜牢转交 AALC,核对镜牢实际完成局数,合成与任务互斥
转交与互斥(原未提交改动,合入选队分支后提交): - MCP 初始化说明和工具描述引导常规日常/领奖/普通镜牢走 task_status -> run_task -> 轮询;jev_mirror_agent 默认转交 AALC, 明确的速通配置、决策模型或未完成速通局仍走逐步模式。 - 新增 ~/lc_mcp/game.lock:run_task 子进程与模块合成脚本互斥, 合成脚本另查 task_status,状态不明时不接管游戏。 - all 任务的 HDR 提示无 GUI 时直接确认并记录;预检按窗口位置 决定是否计标题栏,set_windows=false 跳过;levelup card/weakest 同步失败返回非零。急停提示改为 End 键。 镜牢结果(对接文档指出的缺口): - 预检拒绝空队列和没有适用当前难度队伍的配置:AALC 会一局不打 就以 0 退出。可用判定与 Mirror_task 的固定用途规则一致。 - 监听 mirror_signal 统计实际完成局数;少于应打局数记 [ERROR] 并以退出码 4 结束,task_status 为 failed。 - mirror 指定 count 时临时关闭 infinite_dungeons(否则次数变成 9999),原值写入恢复文件,结束或强杀后写回。 验证:Linux / Python 3.12 全套 507 项通过;git diff --check 通过。 用上游真实 Mirror_task 回放了无可用队伍和正常完成两种情况; Windows 实机仍需回归。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,10 @@ from lc_ui import HERE, click, items, keypress, probe, screen_text
|
|||||||
GAME_EXE = r'D:\SteamLibrary\steamapps\common\Limbus Company\LimbusCompany.exe'
|
GAME_EXE = r'D:\SteamLibrary\steamapps\common\Limbus Company\LimbusCompany.exe'
|
||||||
GAME_PROC = 'LimbusCompany'
|
GAME_PROC = 'LimbusCompany'
|
||||||
REPO = os.path.dirname(HERE) if os.path.basename(HERE) == 'scripts' else HERE
|
REPO = os.path.dirname(HERE) if os.path.basename(HERE) == 'scripts' else HERE
|
||||||
|
if REPO not in sys.path:
|
||||||
|
sys.path.insert(0, REPO)
|
||||||
|
from lc_mcp.game_lock import exclusive_game
|
||||||
|
|
||||||
PYW = os.path.join(REPO, 'vendor', 'aalc', '.venv', 'Scripts', 'pythonw.exe')
|
PYW = os.path.join(REPO, 'vendor', 'aalc', '.venv', 'Scripts', 'pythonw.exe')
|
||||||
SERVER_PORT = 8765
|
SERVER_PORT = 8765
|
||||||
|
|
||||||
@@ -760,8 +764,20 @@ def main(argv=None):
|
|||||||
|
|
||||||
log('=== 开始: 体力换模块 ===')
|
log('=== 开始: 体力换模块 ===')
|
||||||
|
|
||||||
|
try:
|
||||||
|
with exclusive_game():
|
||||||
|
return run_conversion(args, done)
|
||||||
|
except (OSError, RuntimeError, subprocess.SubprocessError) as e:
|
||||||
|
return done(1, '%s: %s' % (type(e).__name__, e))
|
||||||
|
|
||||||
|
|
||||||
|
def run_conversion(args, done):
|
||||||
if not ensure_server():
|
if not ensure_server():
|
||||||
return done(1, 'MCP 服务连不上, 也没能拉起来')
|
return done(1, 'MCP 服务连不上, 也没能拉起来')
|
||||||
|
# Also refuse older task processes started before the shared lock was added.
|
||||||
|
status = probe('task_status', {'lines': 1})
|
||||||
|
if not status.get('ok') or status.get('state') not in ('idle', 'succeeded', 'failed', 'stopped'):
|
||||||
|
return done(1, 'AALC 任务仍在运行或状态无法确认,本轮不接管游戏')
|
||||||
# 断线会让截图全黑, 那之后什么都做不了 —— 先确认桌面在出图再动游戏
|
# 断线会让截图全黑, 那之后什么都做不了 —— 先确认桌面在出图再动游戏
|
||||||
if not ensure_display():
|
if not ensure_display():
|
||||||
return done(1, '桌面不在出图(会话被断开), 本轮跳过')
|
return done(1, '桌面不在出图(会话被断开), 本轮跳过')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""Validated scene actions for Jev decisions and fixed speedrun macros."""
|
"""Delegate ordinary mirror runs to AALC; retain Jev control for special speedruns."""
|
||||||
import argparse
|
import argparse
|
||||||
import functools
|
import functools
|
||||||
import json
|
import json
|
||||||
@@ -9,7 +9,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
from mcp_session import Session as Bridge, SessionCancelled, SessionTimeout
|
from mcp_session import Session as Bridge, SessionCancelled, SessionTimeout
|
||||||
from game_scenes import battle_is_terminal, battle_is_visible, death_retry_screen
|
from game_scenes import battle_is_terminal, battle_is_visible, death_retry_screen
|
||||||
from run_state import prepare_run, save_json, record_claim, claim_is_current, complete_run
|
from run_state import (RESUMABLE, load_json, prepare_run, save_json, record_claim,
|
||||||
|
claim_is_current, complete_run)
|
||||||
from decision_router import DecisionRouter, DecisionRequired
|
from decision_router import DecisionRouter, DecisionRequired
|
||||||
from jev_client import request_answer
|
from jev_client import request_answer
|
||||||
from lc_scene_aliases import normalize
|
from lc_scene_aliases import normalize
|
||||||
@@ -797,22 +798,104 @@ def acquire_single_instance():
|
|||||||
return lambda: kernel.CloseHandle(lease)
|
return lambda: kernel.CloseHandle(lease)
|
||||||
|
|
||||||
|
|
||||||
|
def execution_workflow(args, executor_decider=None):
|
||||||
|
"""Keep explicit speedrun requirements and unfinished runs on their old path."""
|
||||||
|
if args.workflow != 'auto':
|
||||||
|
return args.workflow
|
||||||
|
if (args.config or args.decision_engine or executor_decider is not None
|
||||||
|
or os.environ.get('LC_FIXED_FALLBACK') == '1'):
|
||||||
|
return 'speedrun'
|
||||||
|
previous = None if args.new_run else load_json(RUNTIME_HOME / 'mirror_current_run.json')
|
||||||
|
if previous and previous.get('workflow') == 'aalc':
|
||||||
|
return 'aalc'
|
||||||
|
if args.resume or previous and previous.get('status') in RESUMABLE:
|
||||||
|
return 'speedrun'
|
||||||
|
return 'aalc'
|
||||||
|
|
||||||
|
|
||||||
|
def delegate_mirror(new_run=False, resume=False):
|
||||||
|
"""Start or inspect AALC once; the calling agent monitors task_status afterward."""
|
||||||
|
record = {'workflow': 'aalc', 'next_call': {'tool': 'task_status', 'args': {'lines': 30}},
|
||||||
|
'note': '启动或接管监控不代表通关。继续轮询 task_status,检查 errors 和 pending_restore;'
|
||||||
|
'停止用 stop_task 或急停键(默认 End)。调用超时或用户停止后不自动重试或转为逐步输入。'}
|
||||||
|
bridge = None
|
||||||
|
try:
|
||||||
|
if STOP_FILE.exists():
|
||||||
|
return dict(record, state='stopped', reason='stop_requested')
|
||||||
|
# An explicit workflow switch must not silently discard a special route.
|
||||||
|
previous = None if new_run else load_json(RUNTIME_HOME / 'mirror_current_run.json')
|
||||||
|
if previous and previous.get('status') in RESUMABLE:
|
||||||
|
return dict(record, state='requires_analysis', reason='unfinished_speedrun',
|
||||||
|
error='存在未完成的速通局;使用 --workflow speedrun --resume,明确新开任务时用 --new-run')
|
||||||
|
bridge = Bridge(cancelled=STOP_FILE.exists, raise_on_error=False)
|
||||||
|
current = bridge.call('task_status', {'lines': 30})
|
||||||
|
state = current.get('state')
|
||||||
|
if not current.get('ok') or state not in ('idle', 'running', 'succeeded', 'failed', 'stopped'):
|
||||||
|
return dict(record, state='requires_analysis', task_status=current)
|
||||||
|
if (resume and previous and previous.get('workflow') == 'aalc' and previous.get('task_log')
|
||||||
|
and current.get('log') != previous['task_log']):
|
||||||
|
return dict(record, state='requires_analysis', reason='task_changed', task_status=current)
|
||||||
|
if state == 'running':
|
||||||
|
return dict(record, state='monitoring' if current.get('task') == 'mirror' else 'busy',
|
||||||
|
task_status=current)
|
||||||
|
if state == 'stopped' or current.get('exit_code') == 130:
|
||||||
|
if not new_run:
|
||||||
|
return dict(record, state='stopped', task_status=current, reason='user_stopped')
|
||||||
|
if resume:
|
||||||
|
return dict(record, state='requires_analysis' if current.get('errors') or current.get('pending_restore')
|
||||||
|
or current.get('task') != 'mirror' else state, task_status=current)
|
||||||
|
if state == 'failed' or current.get('errors') or current.get('pending_restore'):
|
||||||
|
if not new_run or current.get('pending_restore'):
|
||||||
|
return dict(record, state='requires_analysis', task_status=current)
|
||||||
|
started = bridge.call('run_task', {'task': 'mirror', 'count': 1})
|
||||||
|
if not started.get('ok'):
|
||||||
|
return dict(record, state='requires_analysis', result=started)
|
||||||
|
record['result'] = started
|
||||||
|
run, _ = prepare_run(RUNTIME_HOME, new_run=True)
|
||||||
|
run.update(status='delegated', workflow='aalc', task_log=started.get('log'))
|
||||||
|
save_json(RUNTIME_HOME / 'mirror_current_run.json', run)
|
||||||
|
return dict(record, state='delegated')
|
||||||
|
except Exception as error:
|
||||||
|
record.update(state='stopped' if isinstance(error, SessionCancelled) else 'requires_analysis',
|
||||||
|
error='%s: %s' % (type(error).__name__, error))
|
||||||
|
if isinstance(error, (SessionCancelled, SessionTimeout)):
|
||||||
|
record.update(outcome_unknown=error.outcome_unknown, pending_tool=getattr(error, 'tool', None))
|
||||||
|
return record
|
||||||
|
finally:
|
||||||
|
if bridge is not None:
|
||||||
|
bridge.close()
|
||||||
|
|
||||||
|
|
||||||
def main(executor_decider=None):
|
def main(executor_decider=None):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('config', nargs='?', help='Optional Jev JSON config; omit for execution-model handoff')
|
parser.add_argument('config', nargs='?', help='Optional Jev JSON config for stepwise speedrun control')
|
||||||
|
parser.add_argument('--workflow', choices=('auto', 'aalc', 'speedrun'), default='auto',
|
||||||
|
help='Default: AALC for ordinary mirror runs; explicit model/config or unfinished speedrun keeps stepwise control')
|
||||||
parser.add_argument('--decision-engine', choices=('auto', 'jev', 'executor', 'fixed'))
|
parser.add_argument('--decision-engine', choices=('auto', 'jev', 'executor', 'fixed'))
|
||||||
parser.add_argument('--steps', type=int, default=250)
|
parser.add_argument('--steps', type=int, default=250, help='Stepwise speedrun action budget')
|
||||||
parser.add_argument('--seconds', type=int, default=1200)
|
parser.add_argument('--seconds', type=int, default=1200, help='Stepwise speedrun time budget')
|
||||||
mode = parser.add_mutually_exclusive_group()
|
mode = parser.add_mutually_exclusive_group()
|
||||||
mode.add_argument('--new-run', action='store_true', help='Start fresh state for a new dungeon')
|
mode.add_argument('--new-run', action='store_true', help='Start fresh state for a new dungeon')
|
||||||
mode.add_argument('--resume', action='store_true', help='Require an unfinished run with matching state')
|
mode.add_argument('--resume', action='store_true', help='Require an unfinished run with matching state')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.steps <= 0 or args.seconds <= 0:
|
if args.steps <= 0 or args.seconds <= 0:
|
||||||
parser.error('--steps and --seconds must be positive')
|
parser.error('--steps and --seconds must be positive')
|
||||||
|
try:
|
||||||
|
workflow = execution_workflow(args, executor_decider)
|
||||||
|
except (OSError, ValueError) as error:
|
||||||
|
parser.error(str(error))
|
||||||
release = acquire_single_instance()
|
release = acquire_single_instance()
|
||||||
if release is None:
|
if release is None:
|
||||||
print(json.dumps({'state':'already_running'}), flush=True)
|
print(json.dumps({'state':'already_running'}), flush=True)
|
||||||
return
|
return
|
||||||
|
if workflow == 'aalc':
|
||||||
|
try:
|
||||||
|
record = delegate_mirror(new_run=args.new_run, resume=args.resume)
|
||||||
|
save_json(RUNTIME_HOME / 'aalc_mirror_status.json', record)
|
||||||
|
print(json.dumps(record, ensure_ascii=False), flush=True)
|
||||||
|
finally:
|
||||||
|
release()
|
||||||
|
return
|
||||||
log = RUNTIME_HOME / 'jev_mirror_log.jsonl'
|
log = RUNTIME_HOME / 'jev_mirror_log.jsonl'
|
||||||
status = RUNTIME_HOME / 'jev_mirror_status.json'
|
status = RUNTIME_HOME / 'jev_mirror_status.json'
|
||||||
deadline = time.monotonic() + args.seconds
|
deadline = time.monotonic() + args.seconds
|
||||||
|
|||||||
+2
-1
@@ -297,6 +297,7 @@ def cmd_card(ci, ri, uptie=False):
|
|||||||
print('详情页已打开')
|
print('详情页已打开')
|
||||||
ok, desc = do_level_up()
|
ok, desc = do_level_up()
|
||||||
print('升级: %s (%s)' % ('OK' if ok else 'FAIL', desc))
|
print('升级: %s (%s)' % ('OK' if ok else 'FAIL', desc))
|
||||||
|
ok2 = True
|
||||||
if uptie:
|
if uptie:
|
||||||
ok2, desc2 = do_uptie()
|
ok2, desc2 = do_uptie()
|
||||||
print('同步: %s (%s)' % ('OK' if ok2 else 'FAIL', desc2))
|
print('同步: %s (%s)' % ('OK' if ok2 else 'FAIL', desc2))
|
||||||
@@ -318,7 +319,7 @@ def cmd_card(ci, ri, uptie=False):
|
|||||||
txt = screen_text(items)
|
txt = screen_text(items)
|
||||||
if not ('IDENTITIES' in txt and 'Facades' in txt):
|
if not ('IDENTITIES' in txt and 'Facades' in txt):
|
||||||
print('[warn] 未能回到 Identities 网格, 当前: ' + txt[:160])
|
print('[warn] 未能回到 Identities 网格, 当前: ' + txt[:160])
|
||||||
return 0 if ok else 1
|
return 0 if ok and ok2 else 1
|
||||||
|
|
||||||
|
|
||||||
# 每级升级所需经验(来源 wiki "EXP per Level" 表)。
|
# 每级升级所需经验(来源 wiki "EXP per Level" 表)。
|
||||||
|
|||||||
Reference in New Issue
Block a user