fix: use desktop codex for dashboard runs

This commit is contained in:
daixiawu 2026-06-26 18:50:43 +08:00
parent bc302ba71b
commit 961b644aea

View File

@ -621,6 +621,29 @@ def _codex_job_snapshot(job):
def _codex_command_base():
override = os.environ.get('TH1_DASHBOARD_CODEX_EXE', '').strip()
if override and os.path.isfile(override):
return [override]
if sys.platform == 'win32':
local_appdata = os.environ.get('LOCALAPPDATA') or os.path.join(os.path.expanduser('~'), 'AppData', 'Local')
desktop_bin = os.path.join(local_appdata, 'OpenAI', 'Codex', 'bin')
candidates = []
try:
for name in os.listdir(desktop_bin):
exe_path = os.path.join(desktop_bin, name, 'codex.exe')
if os.path.isfile(exe_path):
try:
mtime = os.path.getmtime(exe_path)
except Exception:
mtime = 0
candidates.append((mtime, exe_path))
except Exception:
candidates = []
if candidates:
candidates.sort(reverse=True)
return [candidates[0][1]]
if sys.platform == 'win32':
for name in ('codex.cmd', 'codex.exe', 'codex.bat'):
found = shutil.which(name)
@ -4873,18 +4896,23 @@ def kill_stale_servers(port):
pass
os.chdir(SCRIPT_DIR)
def main():
os.chdir(SCRIPT_DIR)
print(f'Checking port {PORT} for stale processes...')
kill_stale_servers(PORT)
print(f'Checking port {PORT} for stale processes...')
kill_stale_servers(PORT)
with http.server.ThreadingHTTPServer(('', PORT), DashboardHandler) as httpd:
url = f'http://localhost:{PORT}'
print(f'TH1 Dashboard serving at {url}')
print('Press Ctrl+C to stop.')
if os.environ.get('TH1_DASHBOARD_NO_BROWSER') != '1':
webbrowser.open(url)
try:
httpd.serve_forever()
except KeyboardInterrupt:
print('\nStopped.')
with http.server.ThreadingHTTPServer(('', PORT), DashboardHandler) as httpd:
url = f'http://localhost:{PORT}'
print(f'TH1 Dashboard serving at {url}')
print('Press Ctrl+C to stop.')
if os.environ.get('TH1_DASHBOARD_NO_BROWSER') != '1':
webbrowser.open(url)
try:
httpd.serve_forever()
except KeyboardInterrupt:
print('\nStopped.')
if __name__ == '__main__':
main()