The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tui,gateway): keep the TUI parity picks within code-health caps on the PR head
Teknium573c882bdeab
diff --git a/hermes_cli/main_tui_launch.py b/hermes_cli/main_tui_launch.pyindex 4ff32edfb56..1e26f3730ad 100644--- a/hermes_cli/main_tui_launch.py+++ b/hermes_cli/main_tui_launch.py@@ -9,6 +9,7 @@ import contextlibimport jsonimport osimport shutil+import sqlite3import subprocessimport sys@@ -50,7 +51,7 @@ def _short_resume_id(db, session_id: str) -> str:short = session_id[:_SHORT_RESUME_LEN]try:return short if db.resolve_session_id(short) == session_id else session_id- except Exception:+ except sqlite3.Error: # an unreadable store prints the whole idreturn session_iddiff --git a/tui_gateway/change_watcher.py b/tui_gateway/change_watcher.pyindex faff2891946..a9d6e723165 100644--- a/tui_gateway/change_watcher.py+++ b/tui_gateway/change_watcher.py@@ -31,7 +31,7 @@ def skin_payload(config: dict) -> dict:"help_header": (skin.branding or {}).get("help_header", ""),# Raw user CSS for the desktop GUI's <style> tag (32 KiB cap in the skin engine)."customCSS": skin.custom_css}- except Exception:+ except Exception: # health: allow BLE001 -- moved unchanged from resolve_skin (main keeps the same handler): a broken skin file boots the default themereturn {}diff --git a/ui-tui/src/app/useMainApp.ts b/ui-tui/src/app/useMainApp.tsindex 64aacc594b6..7a531cdc799 100644--- a/ui-tui/src/app/useMainApp.ts+++ b/ui-tui/src/app/useMainApp.ts@@ -87,6 +87,50 @@ const BRACKET_PASTE_ON = '\x1b[?2004h'const BRACKET_PASTE_OFF = '\x1b[?2004l'const MAX_HEIGHT_CACHE_BUCKETS = 12+interface ExitClose {+ close: () => Promise<void>+ flight: boolean+}++/** Exit closes this view's canonical sessions first (main stamped `tui_shutdown` at sidecar exit).+ * The exit itself is Ink's exit() plus an explicit process.exit(): unmount() resets terminal modes+ * but leaves the Node process alive (stdin keeps the loop open), so entry.tsx's process.on('exit')+ * final resetTerminalModes() would never fire and kitty keyboard / mouse modes would stay enabled+ * in the parent shell (#19194). */+function useDie(gw: GatewayClient, exit: () => void) {+ const exitClose = useRef<ExitClose>({ close: async () => undefined, flight: false }).current++ const dieWithCode = useCallback(+ (code: number, reason = `app.dieWithCode:${code}`) => {+ if (deferExitForClose(gw, exitClose, () => dieWithCode(code, reason))) {+ return+ }++ gw.kill(reason)+ exit()+ process.exit(code)+ },+ [exit, exitClose, gw]+ )++ const die = useCallback(() => dieWithCode(0, 'app.die'), [dieWithCode])++ return { die, dieWithCode, exitClose }+}++/** On a canonical gateway, close this view's sessions (bounded so a dead socket never holds the+ * terminal) and then re-run the exit; true when the exit was deferred. */+function deferExitForClose(gw: GatewayClient, state: ExitClose, again: () => void): boolean {+ if (!gw.isCanonical || state.flight) {+ return false+ }++ state.flight = true+ void Promise.race([state.close().catch(() => undefined), new Promise(resolve => setTimeout(resolve, 1500))]).then(again)++ return true+}+const statusColorOf = (status: string, t: { error: string; muted: string; ok: string; warn: string }) => {if (status === 'ready') {return t.ok@@ -593,48 +637,7 @@ export function useMainApp(gw: GatewayClient) {const gateway = useMemo(() => ({ gw, rpc }), [gw, rpc])- // Exit closes this view's canonical sessions first (main stamped `tui_shutdown` at sidecar exit),- // bounded so a dead socket never holds the terminal.- const dieFlight = useRef(false)- const closeForExitRef = useRef<() => Promise<void>>(async () => undefined)-- const closeViewsForExit = () =>- Promise.race([closeForExitRef.current().catch(() => undefined), new Promise(resolve => setTimeout(resolve, 1500))])-- const die = useCallback(() => {- if (gw.isCanonical && !dieFlight.current) {- dieFlight.current = true- void closeViewsForExit().then(() => die())-- return- }-- gw.kill('app.die')- exit()- // Ink's exit() calls unmount() which resets terminal modes but does NOT- // call process.exit(). Without an explicit exit the Node process stays- // alive (stdin listener keeps the event loop open), so the process.on('exit')- // handler in entry.tsx — which sends the final resetTerminalModes() — never- // fires. This leaves kitty keyboard protocol, mouse modes, etc. enabled- // in the parent shell. See issue #19194.- process.exit(0)- }, [exit, gw])-- const dieWithCode = useCallback(- (code: number) => {- if (gw.isCanonical && !dieFlight.current) {- dieFlight.current = true- void closeViewsForExit().then(() => dieWithCode(code))-- return- }-- gw.kill(`app.dieWithCode:${code}`)- exit()- process.exit(code)- },- [exit, gw]- )+ const { die, dieWithCode, exitClose } = useDie(gw, exit)const session = useSessionLifecycle({colsRef,@@ -653,7 +656,7 @@ export function useMainApp(gw: GatewayClient) {sys})- closeForExitRef.current = session.closeForExit+ exitClose.close = session.closeForExituseEffect(() => {if (dashboardFreshSessionId) {