feat(cli): attach terminal clients to the selected Desktop [skip ci]
NAN-104 requires terminal chat and browser attachment without granting a client ownership of Desktop's gateway. Resolve bounded short-lived credentials over authenticated current-user IPC, pin both Desktop and gateway identities, and reject replacement instances or incompatible clients before any mutation. Reuse the existing TUI artifact resolver behind a narrow Desktop-only entrypoint, keep credentials out of argv/environment/files, and preserve Python-mode reconnect and gateway leases. Add protocol, real-gateway, and anonymous IPC regression coverage; matching native-host and Windows acceptance remain release gates.
This commit is contained in:
1 parent
b373a95f5c
commit
48e7c4f697
20 files changed
+797
-52
No files matched your search
+14
-7
@@ -1,4 +1,11 @@
|
||||
import { NanobotTui, sessionExitMessage, type AppOptions } from "./app"
|
||||
import { desktopConnectionSource } from "./desktop"
|
||||
|
||||
if (process.argv.slice(2).join(" ") === "--desktop-protocol") {
|
||||
process.stdout.write("1\n")
|
||||
process.exit(0)
|
||||
}
|
||||
const desktop = desktopConnectionSource()
|
||||
|
||||
// Keep in sync with _TUI_DETACH_EXIT_CODE in nanobot/cli/tui_launcher.py.
|
||||
const TUI_DETACH_EXIT_CODE = 90
|
||||
@@ -15,11 +22,11 @@ const wsUrl = process.env.NANOBOT_TUI_WS_URL?.trim() || ""
|
||||
const healthUrl = process.env.NANOBOT_TUI_HEALTH_URL?.trim() || ""
|
||||
const gatewayStopCommand = process.env.NANOBOT_TUI_GATEWAY_STOP_COMMAND?.trim()
|
||||
|| "nanobot gateway stop"
|
||||
if (!bootstrapUrl && !wsUrl) {
|
||||
if (!desktop && !bootstrapUrl && !wsUrl) {
|
||||
throw new Error("NANOBOT_TUI_BOOTSTRAP_URL or NANOBOT_TUI_WS_URL is required")
|
||||
}
|
||||
const options: AppOptions = {
|
||||
...(bootstrapUrl
|
||||
...(desktop ? { resolveConnection: desktop.resolve, desktopGatewayId: desktop.gatewayId } : bootstrapUrl
|
||||
? {
|
||||
bootstrapUrl,
|
||||
bootstrapSecret: process.env.NANOBOT_TUI_BOOTSTRAP_SECRET?.trim() || "",
|
||||
@@ -38,11 +45,11 @@ const options: AppOptions = {
|
||||
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`)
|
||||
if (!desktop && chatId) process.stdout.write(sessionExitMessage(chatId))
|
||||
process.stdout.write(desktop ? "Desktop remains running. Reconnect with nanobot.\n" : `Stop it with: ${gatewayStopCommand}\n`)
|
||||
},
|
||||
onExit: (chatId) => {
|
||||
process.stdout.write(sessionExitMessage(chatId))
|
||||
process.stdout.write(desktop ? "Disconnected from Desktop; its backend remains running.\n" : sessionExitMessage(chatId))
|
||||
},
|
||||
}
|
||||
|
||||
@@ -62,11 +69,11 @@ for (const signal of ["SIGHUP", "SIGINT", "SIGTERM"] as const) {
|
||||
process.once("exit", () => app?.stop())
|
||||
process.once("uncaughtException", (error) => {
|
||||
shutdown(1)
|
||||
process.stderr.write(`${error instanceof Error ? error.stack || error.message : String(error)}\n`)
|
||||
process.stderr.write(desktop ? "Desktop terminal connection failed. No backend was started.\n" : `${error instanceof Error ? error.stack || error.message : String(error)}\n`)
|
||||
})
|
||||
process.once("unhandledRejection", (error) => {
|
||||
shutdown(1)
|
||||
process.stderr.write(`${error instanceof Error ? error.stack || error.message : String(error)}\n`)
|
||||
process.stderr.write(desktop ? "Desktop terminal connection failed. No backend was started.\n" : `${error instanceof Error ? error.stack || error.message : String(error)}\n`)
|
||||
})
|
||||
|
||||
app = await NanobotTui.create(options)
|
||||
|
||||
Reference in new issue
Block a user