Exit the process when stdin reaches EOF (parent TUI went away). The Ink TUI spawns this server with stdin wired to a pipe it holds open. If the TUI exits — even a hard crash that skips its cleanup — the OS closes that pipe, stdin EOFs here, and we exit. Mirrors hermes's gateway, which
()
| 35 | |
| 36 | |
| 37 | def _exit_when_stdin_closes() -> None: |
| 38 | """Exit the process when stdin reaches EOF (parent TUI went away). |
| 39 | |
| 40 | The Ink TUI spawns this server with stdin wired to a pipe it holds open. |
| 41 | If the TUI exits — even a hard crash that skips its cleanup — the OS closes |
| 42 | that pipe, stdin EOFs here, and we exit. Mirrors hermes's gateway, which |
| 43 | exits on stdin EOF when its Node parent goes away. Daemon thread so it never |
| 44 | blocks normal shutdown. |
| 45 | """ |
| 46 | import os as _os |
| 47 | import threading as _threading |
| 48 | |
| 49 | def _watch() -> None: |
| 50 | try: |
| 51 | sys.stdin.buffer.read() # blocks until the parent closes the pipe |
| 52 | except Exception: # noqa: BLE001 |
| 53 | pass |
| 54 | _os._exit(0) |
| 55 | |
| 56 | _threading.Thread(target=_watch, name="agent-server-parent-watch", daemon=True).start() |
| 57 | |
| 58 | |
| 59 | def run_agent_server_subcommand(argv: list[str]) -> int: |
no test coverage detected