Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

python -m backend.cli accounts
python -m backend.cli stages TL-
python -m backend.cli ops TL-5 --account 小卡.json
python -m backend.cli ops TL-5 --account 主号.json
python -m backend.cli progress
python -m backend.cli status
python -m backend.cli runs
Expand Down Expand Up @@ -74,7 +74,7 @@ def _flag(argv, name):


# 带取值的选项。算「位置参数」时必须跳过它们的值,否则
# ``ops --account 小卡.json TL-5`` 会把账号名当成关卡关键词。
# ``ops --account 主号.json TL-5`` 会把账号名当成关卡关键词。
_VALUE_OPTS = ('--account', '--accounts', '--kind', '--limit', '--maa-dir',
'--mode', '--names', '--stages')

Expand Down
3 changes: 3 additions & 0 deletions backend/core/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def list_accounts():
# (读那份档案 StartUp 的 AccountName)。规则在 acctbind.py。
'maaAccountNameFrom': _dict(snap.get('maa')).get('accountNameFrom') or '',
'maaDir': _dict(snap.get('maa')).get('dir') or '',
# 这个号钉在哪台模拟器(emulator-5556):多开时靠它分流,不靠
# 聊天里临时点名——助手忘一次就会串到隔壁那台(2026-11-23 用户报)
'maaAdbAddress': _dict(snap.get('maa')).get('adbAddress') or '',
'syncedAt': _dict(snap.get('sync')).get('syncedAt'),
# 关卡进度摘要(主线还差几关、活动几个区、剿灭几张没满);
# 明细在 account_detail 里,列表页只放这几个数字
Expand Down
34 changes: 34 additions & 0 deletions backend/core/acctbind.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,40 @@ def channel_of(snap) -> str:
return str((a.get('channelName') if isinstance(a, dict) else '') or '')


def addr_of(file='', snap=None) -> str:
"""这个账号钉在哪台模拟器上(``emulator-5556`` / ``127.0.0.1:16384``)

为什么要有这一格(2026-11-23 用户报的「又忘了实例控制」):
以前「哪个号用哪台」只能靠聊天里临时说一句,助手忘一次就串到另一台,
而 MAA 里八份档案又全写着 ``emulator-5554``——档案本身分不出来。绑到
账号上以后,跑机路径每次都读它,不依赖谁记得传参。
"""
return str(_maa_of(_snap(file, snap)).get('adbAddress') or '').strip()


_ADDR_RE = None


def check_addr(raw) -> tuple:
"""模拟器地址 → ``(规范值, 原因)``

只认 MAA / adb 的两种写法:``emulator-5554`` 与 ``ip:port``。填错的代价
很实在——地址写歪了 MaaCore 直接连不上,或者按前缀匹配到另一台实例。
留空是合法的(表示「不指定,按档案」)。
"""
global _ADDR_RE
s = str(raw or '').strip()
if not s:
return '', ''
import re
if _ADDR_RE is None:
_ADDR_RE = re.compile(r'^(emulator-\d{1,5}|[A-Za-z0-9_.\-]+:\d{2,5})$')
if not _ADDR_RE.match(s):
return '', ('模拟器地址要写成 emulator-5554 或 127.0.0.1:16384 这种,'
'收到的是「%s」' % s)
return s, ''


def profile_name(profile, maa_dir=None) -> str:
"""档案里的 AccountName(读不到就给空串,绝不抛)"""
try:
Expand Down
4 changes: 2 additions & 2 deletions backend/core/acctname.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def normalize(v) -> str:
if not digits:
return body
if not re.fullmatch(r'[\d*]+', body):
# 数字和字母混着 → B 服用户名(灰bao#7986),不碰
# 数字和字母混着 → B 服用户名(abc示例#7986),不碰
return body
if len(digits) == 11 and digits.startswith('1'):
return _mask(digits, 3, 4) # 完整手机号
Expand All @@ -127,7 +127,7 @@ def looks_official(nm) -> bool:
"""长得像不像官服的切号名:只有数字和星号,且至少 3 位数字

这样 ``5505`` / ``136`` / ``23****45`` / ``181****5505`` 都算,昵称
「小卡拉帕鲁灰」不算——官服拿昵称去匹配就是死循环几十次然后切号失败。
「示例昵称」不算——官服拿昵称去匹配就是死循环几十次然后切号失败。

3 位也放行的依据:本机 MAA 里用户自己那几份档案写的就是 ``136`` /
``165``(纯数字片段,AccountSwitchEnabled=true),一直能切。
Expand Down
438 changes: 372 additions & 66 deletions backend/core/agent.py

Large diffs are not rendered by default.

84 changes: 82 additions & 2 deletions backend/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ def api_account_maa(_q, body):
if 'accountNameFrom' in patch:
v = str(patch.get('accountNameFrom') or '').strip().lower()
patch['accountNameFrom'] = v if v in ('manual', 'profile') else ''
if 'adbAddress' in patch:
# 这个号钉在哪台模拟器上。写歪了会连到另一台实例,所以在这里就拦。
from . import acctbind
addr, why = acctbind.check_addr(patch.get('adbAddress'))
if why:
raise ValueError('模拟器地址不对:%s' % why)
patch['adbAddress'] = addr
if 'accountName' in patch:
# 切号名统一走 acctname:用户给「5505」「181 5505」「181****5505」
# 「157****3635」都能吃下,官服填了昵称则当场拦下——这一格填错的
Expand All @@ -186,6 +193,44 @@ def api_account_maa(_q, body):
return {'maa': accounts.save_maa_meta(body['file'], patch)}


def api_account_devices(q, _body):
"""某个账号能选哪些模拟器:在线设备 + 本机有哪些实例 + 现在钉的那台

设置里「模拟器」下拉用它。多开时地址必须是明示的(见 skills.device_of
的规则),所以这里把 adb 现在看到的都列出来,用户点一下就行,不用手抄。

``instances`` 是**没开着的实例也列**(雷电用 ``ldconsole list2`` 问出来):
用户想把号钉到第二台时,那台常常正好没开,只列在线设备他就选不到
(2026-11-23「只能启动 5554,启动不了 5556」的一半原因在前端这边)。
"""
file = ''
try:
file = _account_for(q.get('file'))
except Exception:
file = ''
from . import acctbind, envcheck
d = acctbind.dir_of(file) if file else None
prof = (acctbind.profile_of(file) or None) if file else None
try:
cfg = envcheck.read_config(d, prof)
except Exception: # noqa: BLE001
cfg = {}
devs = envcheck._devices(cfg.get('adb') or 'adb') or {}
insts = []
try:
for idx, up in envcheck.ld_instances(cfg.get('emu_dir') or ''):
ser = envcheck.ld_serial(cfg.get('emu_dir') or '', idx)
if ser and ser not in [x['address'] for x in insts]:
insts.append({'address': ser, 'index': idx, 'running': bool(up)})
except Exception: # noqa: BLE001
insts = []
return {'adb': cfg.get('adb') or '',
'bound': acctbind.addr_of(file) if file else '',
'devices': [{'address': a, 'state': s}
for a, s in sorted(devs.items())],
'instances': insts}


def api_account_token(_q, body):
"""设置 → 账号管理:读某个账号的 token(明文,仅在本地窗口里展示)

Expand Down Expand Up @@ -454,8 +499,8 @@ def api_maa_probe(q, _body):
"""检测一个目录是不是 MAA / MAAEND 根目录(首次引导 / 设置里用)

kind=endfield 时按 MAAEND 的主程序名去找:终末地那套是另一个程序,
主程序可能叫 MaaEnd.exe 或 mxu.exe(三月七脚本里两种都出现过)。这一步
只是把路径先管起来,MAAEND 的任务链还没接。
主程序不同版本分别叫 MaaEnd.exe 和 mxu.exe。这一步只是把路径先管起来,
MAAEND 的任务链还没接。
"""
d = (q.get('dir') or '').strip()
if not d:
Expand Down Expand Up @@ -836,6 +881,25 @@ def api_skill_run(_q, body):
return {'taskId': tid}


def api_run_stop(q, body):
"""停挂机:带 file 就只停那一个号,不带才全停

界面右栏那个「停止」按钮走这里(只停当前这个账号)。用户 2026-11-23
报的是「停止不能指定,会一起停其他任务」——以前只有 agent 的全停接口,
两台模拟器一起断,另一台正在打的关就白烧了。
"""
body = body or {}
f = str(body.get('file') or q.get('file') or '').strip()
all_ = bool(body.get('all') or q.get('all'))
if not f and not all_:
# 没点名就全停太危险:右栏那个按钮传的是「当前账号」,万一没选中
# 就会把两台一起砍掉——正是用户报过的「停止会一起停其他任务」。
return {'accounts': [], 'engines': 0, 'processes': 0, 'stopped': 0,
'error': '要停哪一路?传 file=账号文件名;全停请显式传 all=true'}
files = [] if all_ else [f]
return skills.stop_accounts(files)


def api_skill_list(_q, _body):
return {'skills': [{'name': k, 'desc': v[0]} for k, v in sorted(skills.SKILLS.items())]}

Expand Down Expand Up @@ -896,12 +960,25 @@ def api_schedule_stop(_q, _body):
return scheduler.stop_current()


def api_schedule_presets(_q, _body):
"""预设表(不含探测):界面下拉用,纯数据,快"""
return {'ok': True, 'presets': scheduler.presets()}


def api_schedule_detect(q, _body):
"""选预设时回填 program / args / cwd;refresh=1 强制重新找"""
pid = q.get('id') or ''
refresh = str(q.get('refresh') or '') in ('1', 'true', 'yes')
return dict(scheduler.fill(pid, refresh=refresh), ok=True)


ROUTES = {
'/api/bootstrap': bootstrap,
'/api/settings': api_settings,
'/api/accounts': api_accounts,
'/api/account': api_account,
'/api/account/maa': api_account_maa,
'/api/account/devices': api_account_devices,
'/api/account/token': api_account_token,
'/api/account/token/check': api_account_token_check,
'/api/account/token/set': api_account_token_set,
Expand Down Expand Up @@ -958,6 +1035,7 @@ def api_schedule_stop(_q, _body):
'/api/watch/start': api_watch_start,
'/api/watch/stop': api_watch_stop,
'/api/runs': api_runs,
'/api/run/stop': api_run_stop,
'/api/maa/profiles': api_profiles,
# 多账号
'/api/multi/candidates': api_multi_candidates,
Expand All @@ -972,6 +1050,8 @@ def api_schedule_stop(_q, _body):
'/api/schedule/save': api_schedule_save,
'/api/schedule/run': api_schedule_run,
'/api/schedule/stop': api_schedule_stop,
'/api/schedule/presets': api_schedule_presets,
'/api/schedule/detect': api_schedule_detect,
# 内置助手(M4)
'/api/agent/status': api_agent_status,
'/api/agent/config': api_agent_config,
Expand Down
5 changes: 3 additions & 2 deletions backend/core/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,11 +1121,12 @@ def _fix_oper(op, idx, notes):
need = max(2, need) # 带模组要求精二

if need > 0:
# 练度下限是**顺手补齐**的,不写进修正说明:一场作业集有 5~10 个干员,
# 每个都来一行「芬 精英要求 None → 1」,用户看到的就是一屏噪音
# (2026-11-22 明确说「修正练度就不要显示了」)。补照样补,只是不出声。
if not isinstance(req, dict):
op['requirements'] = {'elite': need}
notes.append('%s 缺练度字段,补上精英 %d' % (name, need))
elif int(req.get('elite') or 0) < need:
notes.append('%s 精英要求 %s → %d' % (name, req.get('elite'), need))
req['elite'] = need
return True

Expand Down
Loading