Cai
2026-08-14 783dbe9738755902e1b86d99f14ddf698f1a0033
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@echo off
setlocal
chcp 65001 >nul
 
REM MB-X destructive visible reopen helper.
REM role: case_analysis.report_collector
REM managed_session_key: project-info.yanbao-collector
REM It terminates only the recorded remote_tui_pid if alive, then resumes the existing thread through app-server.
REM It does not delete runtime queues and does not create a new provider session/thread.
set "WORKDIR=E:\mb-ms-doc\project-info"
set "MBX_SRC=E:\mb-ms-doc\project-mbx-core\src"
set "PYTHONPATH=%MBX_SRC%;%PYTHONPATH%"
 
echo [MB-X] Preflight: checking python and Codex CLI in this cmd/BAT environment.
echo [MB-X] PATH=%PATH%
where python >nul 2>nul
if errorlevel 1 (
  echo [MB-X][ERROR] python not found in PATH.
  echo [MB-X][NEXT] Add Python to PATH or run this script from a Python-enabled shell.
  pause
  exit /b 1
)
for /f "delims=" %%I in ('where python 2^>nul') do if not defined MBX_PYTHON_EXE set "MBX_PYTHON_EXE=%%I"
echo [MB-X] python=%MBX_PYTHON_EXE%
set "MBX_CODEX_EXE="
for /f "delims=" %%I in ('where codex.cmd 2^>nul') do if not defined MBX_CODEX_EXE set "MBX_CODEX_EXE=%%I"
if not defined MBX_CODEX_EXE for /f "delims=" %%I in ('where codex.exe 2^>nul') do if not defined MBX_CODEX_EXE set "MBX_CODEX_EXE=%%I"
if not defined MBX_CODEX_EXE for /f "delims=" %%I in ('where codex 2^>nul') do if not defined MBX_CODEX_EXE set "MBX_CODEX_EXE=%%I"
if not defined MBX_CODEX_EXE (
  echo [MB-X][ERROR] Codex CLI not found in this cmd/BAT PATH. remote TUI cannot start.
  echo [MB-X][NEXT] Confirm `codex.cmd --version` works in the same shell, add the npm/Codex bin directory to PATH, or update the workspace mbx.yaml provider command to an absolute codex.cmd/codex.exe path.
  echo [MB-X][DIAG] where codex:
  where codex
  echo [MB-X][DIAG] where codex.cmd:
  where codex.cmd
  pause
  exit /b 5
)
echo [MB-X] codex=%MBX_CODEX_EXE%
echo [MB-X] where codex.cmd:
where codex.cmd
echo [MB-X] where codex:
where codex
 
cd /d "%WORKDIR%"
echo [MB-X] Read-only terminal crash diagnostics before restore:
python -m mbx.cli session terminal-diagnose --project project-info --role case_analysis.report_collector
echo.
echo [MB-X] Restoring visible session for case_analysis.report_collector
echo [MB-X][RISK] This may terminate the recorded old remote TUI PID if it is still alive.
echo [MB-X][RISK] For management roles, record this as a high-risk management action if used for real validation.
set /p MBX_CONFIRM=Type REOPEN to continue:
if /I not "%MBX_CONFIRM%"=="REOPEN" (
  echo [MB-X] Cancelled.
  exit /b 2
)
echo [MB-X] Command: python -m mbx.cli session reopen --project project-info --role case_analysis.report_collector --terminate-existing
python -m mbx.cli session reopen --project project-info --role case_analysis.report_collector --terminate-existing
set "MBX_EXIT=%ERRORLEVEL%"
if not "%MBX_EXIT%"=="0" (
  echo [MB-X][ERROR] session reopen failed with exit code %MBX_EXIT%.
  pause
  exit /b %MBX_EXIT%
)
echo.
python -m mbx.cli session status --project project-info --role case_analysis.report_collector
echo.
echo [MB-X] Verify the visible window shows the old chat history; do not use history/read alone as window proof.
pause