@echo off
title Monitor Node
cd /d "%~dp0"
for /f "usebackq delims=" %%V in ("bin\version.txt") do set "NODE_VERSION=%%V"
title AI-Network Monitor - %NODE_VERSION%

if not exist ".tmp\active_session.txt" (
    echo Error: No active session found. Please run "Start Node.bat" first!
    echo.
    pause
    exit /b
)

:: Read the active session name
set /p SESSION_NAME=<".tmp\active_session.txt"

:: Trim trailing spaces (standard DOS file read quirk)
set SESSION_NAME=%SESSION_NAME: =%

if not exist ".tmp\%SESSION_NAME%" (
    echo Error: Session folder .tmp\%SESSION_NAME% was deleted or is missing!
    echo.
    pause
    exit /b
)

:: Navigate to the active session folder and launch monitor
cd /d ".tmp\%SESSION_NAME%"
call monitor_all.bat
