feat(tui): add /detach command (#5461)

* feat(tui): add detach command

* fix(tui): print exact detached gateway stop command
This commit is contained in:
chengyongru authored and GitHub committed 2026-08-21 15:50:07 +08:00
1 parent 5b44ebdfd7
commit 26764f2423
9 files changed
+163 -9

No files matched your search

+11
View File
@@ -1,6 +1,9 @@
import { NanobotTui, sessionExitMessage, type AppOptions } from "./app"
import { currentGitBranch } from "./host"
// Keep in sync with _TUI_DETACH_EXIT_CODE in nanobot/cli/tui_launcher.py.
const TUI_DETACH_EXIT_CODE = 90
function themePreference(): AppOptions["theme"] {
const value = process.env.NANOBOT_TUI_THEME?.trim() || "auto"
if (value === "auto" || value === "dark" || value === "light") return value
@@ -11,6 +14,8 @@ const workspace = process.env.NANOBOT_TUI_WORKSPACE?.trim() || ""
const hostWorkspace = process.cwd()
const bootstrapUrl = process.env.NANOBOT_TUI_BOOTSTRAP_URL?.trim() || ""
const wsUrl = process.env.NANOBOT_TUI_WS_URL?.trim() || ""
const gatewayStopCommand = process.env.NANOBOT_TUI_GATEWAY_STOP_COMMAND?.trim()
|| "nanobot gateway stop"
if (!bootstrapUrl && !wsUrl) {
throw new Error("NANOBOT_TUI_BOOTSTRAP_URL or NANOBOT_TUI_WS_URL is required")
}
@@ -32,6 +37,12 @@ const options: AppOptions = {
version: process.env.NANOBOT_TUI_VERSION?.trim() || "dev",
access: process.env.NANOBOT_TUI_ACCESS?.trim() || "workspace access",
theme: themePreference(),
onDetach: (chatId) => {
process.exitCode = TUI_DETACH_EXIT_CODE
process.stdout.write("Detached; the agent continues in the background.\n")
if (chatId) process.stdout.write(sessionExitMessage(chatId))
process.stdout.write(`Stop it with: ${gatewayStopCommand}\n`)
},
onExit: (chatId) => {
process.stdout.write(sessionExitMessage(chatId))
},