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
+17
-5
@@ -34,6 +34,7 @@ import {
|
||||
type ConnectionStatusInfo,
|
||||
type FileEditEvent,
|
||||
type GatewayApiConnection,
|
||||
type GatewayConnection,
|
||||
type HistoryMessage,
|
||||
type InboundEvent,
|
||||
type MentionCandidate,
|
||||
@@ -98,6 +99,8 @@ import {
|
||||
import { configureOpenTuiEnvironment, createTuiHost, type TuiHost } from "./host"
|
||||
|
||||
interface AppOptions {
|
||||
resolveConnection?: () => Promise<GatewayConnection>
|
||||
desktopGatewayId?: string
|
||||
wsUrl?: string
|
||||
bootstrapUrl?: string
|
||||
bootstrapSecret?: string
|
||||
@@ -573,7 +576,7 @@ export class NanobotTui {
|
||||
this.defaultModelPreset = options.modelPreset
|
||||
this.modelName = options.model
|
||||
this.modelPreset = options.modelPreset
|
||||
this.apiReauthenticator = options.bootstrapUrl
|
||||
this.apiReauthenticator = options.bootstrapUrl || options.resolveConnection
|
||||
? (rejectedApiToken) => this.refreshApiConnection(rejectedApiToken)
|
||||
: undefined
|
||||
this.sessionModelPreset = options.chatId ? undefined : null
|
||||
@@ -615,7 +618,13 @@ export class NanobotTui {
|
||||
},
|
||||
)
|
||||
this.client = client || new NanobotClient({
|
||||
...(options.bootstrapUrl
|
||||
...(options.resolveConnection ? {
|
||||
resolveConnection: options.resolveConnection,
|
||||
onConnection: (connection: GatewayConnection) => this.useGatewayConnection(connection.apiUrl, connection.apiToken),
|
||||
expectedGatewayId: options.desktopGatewayId,
|
||||
reconnect: false,
|
||||
targetEndpoint: "Nanobot Desktop",
|
||||
} : options.bootstrapUrl
|
||||
? {
|
||||
resolveConnection: () => fetchGatewayConnection(
|
||||
options.bootstrapUrl || "",
|
||||
@@ -636,7 +645,7 @@ export class NanobotTui {
|
||||
}
|
||||
: { url: options.wsUrl }),
|
||||
chatId: options.chatId,
|
||||
initialWorkspaceScope: {
|
||||
initialWorkspaceScope: options.desktopGatewayId ? undefined : {
|
||||
project_path: options.workspace,
|
||||
access_mode: options.access.toLocaleLowerCase().includes("full") ? "full" : "restricted",
|
||||
},
|
||||
@@ -1442,12 +1451,12 @@ export class NanobotTui {
|
||||
return { apiUrl: this.options.apiUrl, apiToken: this.options.apiToken }
|
||||
}
|
||||
if (this.apiRefreshPromise) return this.apiRefreshPromise
|
||||
const refresh = fetchGatewayConnection(
|
||||
const refresh = (this.options.resolveConnection ? this.options.resolveConnection() : fetchGatewayConnection(
|
||||
this.options.bootstrapUrl || "",
|
||||
this.options.bootstrapSecret || "",
|
||||
this.options.apiUrl,
|
||||
`tui-${process.pid}`,
|
||||
).then((connection) => {
|
||||
)).then((connection) => {
|
||||
this.updateGatewayApiConnection(connection.apiUrl, connection.apiToken)
|
||||
return connection
|
||||
})
|
||||
@@ -1468,6 +1477,9 @@ export class NanobotTui {
|
||||
// accurate user-facing state unless the protocol supplied connection diagnostics.
|
||||
if (status === "error" && !info) return
|
||||
this.connectionMessage = connectionStatusText(status, info)
|
||||
if (this.options.desktopGatewayId && status === "error") {
|
||||
this.connectionMessage = "Desktop disconnected or incompatible · exit and run nanobot to reconnect"
|
||||
}
|
||||
if (status === "connected") {
|
||||
this.ready = false
|
||||
this.renderConnectionMessage()
|
||||
|
||||
Reference in new issue
Block a user