mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-03 02:11:48 +00:00
fix(tui): reset terminal modes on startup and exit
Reset sticky mouse/focus/paste terminal modes before the TUI starts and during graceful shutdown paths so stale tab state from prior crashes cannot poison the next session.
This commit is contained in:
parent
98a428fd61
commit
d05497f812
3 changed files with 87 additions and 2 deletions
|
|
@ -11,12 +11,17 @@ import { GatewayClient } from './gatewayClient.js'
|
|||
import { setupGracefulExit } from './lib/gracefulExit.js'
|
||||
import { formatBytes, type HeapDumpResult, performHeapDump } from './lib/memory.js'
|
||||
import { type MemorySnapshot, startMemoryMonitor } from './lib/memoryMonitor.js'
|
||||
import { resetTerminalModes } from './lib/terminalModes.js'
|
||||
|
||||
if (!process.stdin.isTTY) {
|
||||
console.log('hermes-tui: no TTY')
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
// Start from a clean slate. If a previous TUI crashed or was kill -9'd, the
|
||||
// terminal tab can still have mouse/focus/paste modes enabled.
|
||||
resetTerminalModes()
|
||||
|
||||
const gw = new GatewayClient()
|
||||
|
||||
gw.start()
|
||||
|
|
@ -25,17 +30,27 @@ const dumpNotice = (snap: MemorySnapshot, dump: HeapDumpResult | null) =>
|
|||
`hermes-tui: ${snap.level} memory (${formatBytes(snap.heapUsed)}) — auto heap dump → ${dump?.heapPath ?? '(failed)'}\n`
|
||||
|
||||
setupGracefulExit({
|
||||
cleanups: [() => gw.kill()],
|
||||
cleanups: [
|
||||
() => {
|
||||
resetTerminalModes()
|
||||
|
||||
return gw.kill()
|
||||
}
|
||||
],
|
||||
onError: (scope, err) => {
|
||||
const message = err instanceof Error ? `${err.name}: ${err.message}` : String(err)
|
||||
|
||||
process.stderr.write(`hermes-tui ${scope}: ${message.slice(0, 2000)}\n`)
|
||||
},
|
||||
onSignal: signal => process.stderr.write(`hermes-tui: received ${signal}\n`)
|
||||
onSignal: signal => {
|
||||
resetTerminalModes()
|
||||
process.stderr.write(`hermes-tui: received ${signal}\n`)
|
||||
}
|
||||
})
|
||||
|
||||
const stopMemoryMonitor = startMemoryMonitor({
|
||||
onCritical: (snap, dump) => {
|
||||
resetTerminalModes()
|
||||
process.stderr.write(dumpNotice(snap, dump))
|
||||
process.stderr.write('hermes-tui: exiting to avoid OOM; restart to recover\n')
|
||||
process.exit(137)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue