Cai
2026-08-10 da3591d542aa4d2753ac5e1ad61021a3feff6d1f
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 non-destructive managed open helper.
REM role: case_analysis.report_collector
REM managed_session_key: project-info.yanbao-collector
REM Use this first when the recorded PID is stale/missing or when you only want safe open/reuse.
REM It resumes the existing provider_session_id/thread_id and never terminates an alive remote TUI.
REM If a PID is alive but the visible window is missing, use restore-*.bat instead.
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] Target status before open for case_analysis.report_collector
python -m mbx.cli session status --project project-info --role case_analysis.report_collector
echo.
echo [MB-X] Read-only terminal crash diagnostics before open:
python -m mbx.cli session terminal-diagnose --project project-info --role case_analysis.report_collector
echo.
echo [MB-X] Opening/reusing visible session for case_analysis.report_collector
echo [MB-X] Use this script for stale/missing PID. Use restore-*.bat only when an alive recorded PID has no visible window.
echo [MB-X] Command: python -m mbx.cli session open --project project-info --role case_analysis.report_collector
python -m mbx.cli session open --project project-info --role case_analysis.report_collector
set "MBX_EXIT=%ERRORLEVEL%"
if not "%MBX_EXIT%"=="0" (
  echo [MB-X][ERROR] session open failed with exit code %MBX_EXIT%.
  echo [MB-X][NEXT] Read the error details above. If app-server is alive but remote_tui_start_failed reports missing executable, fix Codex CLI PATH/codex.cmd first. If a PID is alive but no window is visible, use restore-*.bat only with recorded approval.
  pause
  exit /b %MBX_EXIT%
)
echo.
echo [MB-X] Target status after open for case_analysis.report_collector
python -m mbx.cli session status --project project-info --role case_analysis.report_collector
echo.
echo [MB-X] Verify the visible Codex window shows old chat history. If it disappears after Enter, run the terminal-diagnose command above and consider terminal-rendering apply only with recorded approval.
pause