Skip to content

The agent that grows with you

fix(tui): render the vault.save_login prompt so browser logins can be saved

liuhao1024a8d7bc3ea1c8
diff --git a/ui-tui/src/__tests__/createGatewayEventHandler.test.ts b/ui-tui/src/__tests__/createGatewayEventHandler.test.ts
index 47475f6e579..61712696664 100644
--- a/ui-tui/src/__tests__/createGatewayEventHandler.test.ts
+++ b/ui-tui/src/__tests__/createGatewayEventHandler.test.ts
@@ -2363,5 +2363,48 @@ describe('createGatewayEventHandler', () => {
expect(getUiState().busy).toBe(true)
expect(appended).toHaveLength(0)
})
+
+ describe('vault.save_login prompt (#109101)', () => {
+ it('opens the two-step save-login card for the server request', () => {
+ const { handled } = serverRequest(
+ 'vault.save_login',
+ {
+ origin: 'https://www.linkedin.com',
+ session_id: 'sess',
+ site: 'www.linkedin.com'
+ },
+ 'save-9'
+ )
+
+ expect(handled).toBe(true)
+ expect(getOverlayState().vaultSaveLogin).toEqual({
+ origin: 'https://www.linkedin.com',
+ requestId: 'save-9',
+ site: 'www.linkedin.com'
+ })
+ expect(getUiState().status).toBe('save login for www.linkedin.com')
+ })
+
+ it('tears the card down on request.cancel, but only for the matching request', () => {
+ const onEvent = createGatewayEventHandler(buildCtx([]))
+
+ serverRequest(
+ 'vault.save_login',
+ {
+ origin: 'https://a.example',
+ session_id: 'sess',
+ site: 'a.example'
+ },
+ 'save-1'
+ )
+ expect(getOverlayState().vaultSaveLogin).not.toBeNull()
+
+ onEvent({ payload: { id: 'save-2' }, type: 'request.cancel' } as any)
+ expect(getOverlayState().vaultSaveLogin).not.toBeNull()
+
+ onEvent({ payload: { id: 'save-1' }, type: 'request.cancel' } as any)
+ expect(getOverlayState().vaultSaveLogin).toBeNull()
+ })
+ })
})
})
diff --git a/ui-tui/src/__tests__/useInputHandlers.test.ts b/ui-tui/src/__tests__/useInputHandlers.test.ts
index ac1417aa77a..8f63408660a 100644
--- a/ui-tui/src/__tests__/useInputHandlers.test.ts
+++ b/ui-tui/src/__tests__/useInputHandlers.test.ts
@@ -212,4 +212,18 @@ describe('dismissSensitivePrompt', () => {
expect(getOverlayState().secret).toBeNull()
expect(sys).toHaveBeenCalled()
})
+
+ it('declines a vault save-login overlay with an empty value so the blocked wait resolves', () => {
+ resetOverlayState()
+ resetServerRequestsForTests()
+ patchOverlayState({ vaultSaveLogin: { origin: 'https://example.com', requestId: 'save-1', site: 'example.com' } })
+ const respond = openRequest('save-1', 'vault.save_login')
+ const sys = vi.fn()
+
+ dismissSensitivePrompt(getOverlayState(), vi.fn(), sys)
+
+ expect(getOverlayState().vaultSaveLogin).toBeNull()
+ expect(sys).toHaveBeenCalledWith('login for example.com not saved')
+ expect(respond).toHaveBeenCalledWith({ value: '' })
+ })
})
diff --git a/ui-tui/src/__tests__/vaultSaveLoginPrompt.test.tsx b/ui-tui/src/__tests__/vaultSaveLoginPrompt.test.tsx
new file mode 100644
index 00000000000..4f046ebb1a7
--- /dev/null
+++ b/ui-tui/src/__tests__/vaultSaveLoginPrompt.test.tsx
@@ -0,0 +1,114 @@
+import { EventEmitter } from 'node:events'
+import { PassThrough } from 'node:stream'
+
+import { renderSync } from '@hermes/ink'
+import React from 'react'
+import stripAnsi from 'strip-ansi'
+import { describe, expect, it, vi } from 'vitest'
+
+import { VaultSaveLoginPrompt } from '../components/vaultSaveLoginPrompt.js'
+import { DEFAULT_THEME } from '../theme.js'
+
+class FakeInput extends EventEmitter {
+ chunks: string[] = []
+ isRaw = false
+ isTTY = true
+ readableLength = 0
+
+ read() {
+ const next = this.chunks.shift() ?? null
+ this.readableLength = this.chunks.length
+
+ return next
+ }
+
+ ref = vi.fn()
+
+ send(...chunks: string[]) {
+ this.chunks.push(...chunks)
+ this.readableLength = this.chunks.length
+ this.emit('readable')
+ }
+
+ setEncoding = vi.fn()
+
+ setRawMode = vi.fn((enabled: boolean) => {
+ this.isRaw = enabled
+ })
+
+ unref = vi.fn()
+}
+
+const settle = (ms = 25) => new Promise(resolve => setTimeout(resolve, ms))
+
+function mount(onReady: (identifier: string, password: string) => void) {
+ const stdin = new FakeInput()
+ const stdout = Object.assign(new PassThrough(), { columns: 80, isTTY: false, rows: 24 })
+ const frames: string[] = []
+ stdout.on('data', chunk => frames.push(chunk.toString()))
+
+ const instance = renderSync(
+ <VaultSaveLoginPrompt cols={80} onReady={onReady} site="www.linkedin.com" t={DEFAULT_THEME} />,
+ {
+ patchConsole: false,
+ stdin: stdin as unknown as NodeJS.ReadStream,
+ stdout: stdout as unknown as NodeJS.WriteStream
+ }
+ )
+
+ return { frames, instance, stdin, stdout }
+}
+
+const screenText = (frames: string[]) => stripAnsi(frames.join(''))
+
+describe('VaultSaveLoginPrompt (#109101)', () => {
+ it('shows the identifier step first for the requesting site', async () => {
+ const onReady = vi.fn()
+ const { frames, instance } = mount(onReady)
+
+ await settle()
+ expect(screenText(frames)).toContain('Save a login for www.linkedin.com')
+ expect(onReady).not.toHaveBeenCalled()
+
+ instance.unmount()
+ instance.cleanup()
+ })
+
+ it('declines the whole save when the identifier step is submitted empty', async () => {
+ const onReady = vi.fn()
+ const { instance, stdin } = mount(onReady)
+
+ await settle()
+ stdin.send('\r')
+ await settle()
+
+ expect(onReady).toHaveBeenCalledWith('', '')
+
+ instance.unmount()
+ instance.cleanup()
+ })
+
+ it('moves to the masked password step after a non-empty identifier, then emits both values', async () => {
+ const onReady = vi.fn()
+ const { frames, instance, stdin } = mount(onReady)
+
+ await settle()
+ stdin.send('[email protected]')
+ await settle()
+ stdin.send('\r')
+ await settle()
+
+ expect(screenText(frames)).toContain('Password for [email protected]')
+ expect(onReady).not.toHaveBeenCalled()
+
+ stdin.send('s3cret')
+ await settle()
+ stdin.send('\r')
+ await settle()
+
+ expect(onReady).toHaveBeenCalledWith('[email protected]', 's3cret')
+
+ instance.unmount()
+ instance.cleanup()
+ })
+})
diff --git a/ui-tui/src/app/createGatewayEventHandler.ts b/ui-tui/src/app/createGatewayEventHandler.ts
index e0a76c19568..369737b057a 100644
--- a/ui-tui/src/app/createGatewayEventHandler.ts
+++ b/ui-tui/src/app/createGatewayEventHandler.ts
@@ -1353,7 +1353,7 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:
const next = { ...prev }
let changed = false
- for (const key of ['approval', 'clarify', 'secret', 'sudo', 'vaultUnlock'] as const) {
+ for (const key of ['approval', 'clarify', 'secret', 'sudo', 'vaultSaveLogin', 'vaultUnlock'] as const) {
if (prev[key]?.requestId === id) {
next[key] = null
changed = true
diff --git a/ui-tui/src/app/createServerRequestHandler.ts b/ui-tui/src/app/createServerRequestHandler.ts
index 2e4e8b84da3..0f59ad9c168 100644
--- a/ui-tui/src/app/createServerRequestHandler.ts
+++ b/ui-tui/src/app/createServerRequestHandler.ts
@@ -21,8 +21,8 @@ const strList = (v: unknown): null | string[] =>
* (`tui_gateway/server_requests.py`). Each method opens its overlay card;
* the card's answer path resolves the request through `serverRequestStore`.
* Methods the terminal cannot answer (desktop GUI bridges: `preview.*`,
- * `window.read`, `tour`, `mcp.setup`, `terminal.read`, the vault card
- * prompts) return `false` so the channel answers `-32601` and the tool
+ * `window.read`, `tour`, `mcp.setup`, `terminal.read`, the vault code
+ * prompt) return `false` so the channel answers `-32601` and the tool
* fails fast instead of waiting out its deadline.
*/
export function createServerRequestHandler(ctx: ServerRequestHandlerContext): (request: ServerRequest) => boolean {
@@ -110,6 +110,14 @@ export function createServerRequestHandler(ctx: ServerRequestHandlerContext): (r
return true
+ case 'vault.save_login':
+ patchOverlayState({
+ vaultSaveLogin: { origin: str(p.origin), requestId: request.id, site: str(p.site) }
+ })
+ open(request, `save login for ${str(p.site)}`)
+
+ return true
+
default:
return false
}
diff --git a/ui-tui/src/app/interfaces.ts b/ui-tui/src/app/interfaces.ts
index 6bea7c363f8..a6eee283aa0 100644
--- a/ui-tui/src/app/interfaces.ts
+++ b/ui-tui/src/app/interfaces.ts
@@ -30,6 +30,7 @@ import type {
SessionInfo,
SlashCatalog,
SudoReq,
+ VaultSaveLoginReq,
VaultUnlockReq
} from '../types.js'
@@ -303,6 +304,7 @@ export interface OverlayState {
petPicker: boolean
pluginsHub: boolean
secret: null | SecretReq
+ vaultSaveLogin: null | VaultSaveLoginReq
vaultUnlock: null | VaultUnlockReq
sessions: boolean
skillsHub: boolean
@@ -575,6 +577,7 @@ export interface AppLayoutActions {
answerClarifyQuestion: (qid: string, answer: string) => void
answerSecret: (value: string) => void
answerSudo: (pw: string) => void
+ answerVaultSaveLogin: (identifier: string, password: string) => void
answerVaultUnlock: (password: string) => void
cancelClarify: () => void
clearSelection: () => void
@@ -651,6 +654,7 @@ export interface AppOverlaysProps {
onResumeSelect: (sessionId: string) => void
onSecretSubmit: (value: string) => void
onSudoSubmit: (pw: string) => void
+ onVaultSaveLoginSubmit: (identifier: string, password: string) => void
onVaultUnlockSubmit: (password: string) => void
pagerPageSize: number
}
diff --git a/ui-tui/src/app/overlayStore.ts b/ui-tui/src/app/overlayStore.ts
index e5322213190..3ae624d72f4 100644
--- a/ui-tui/src/app/overlayStore.ts
+++ b/ui-tui/src/app/overlayStore.ts
@@ -20,6 +20,7 @@ const buildOverlayState = (): OverlayState => ({
pluginsHub: false,
secret: null,
vaultUnlock: null,
+ vaultSaveLogin: null,
sessions: false,
skillsHub: false,
subscription: null,
@@ -48,6 +49,7 @@ export const $isBlocked = computed(
subscription,
sudo,
vaultUnlock,
+ vaultSaveLogin,
widget
}) =>
Boolean(
@@ -68,6 +70,7 @@ export const $isBlocked = computed(
subscription ||
sudo ||
vaultUnlock ||
+ vaultSaveLogin ||
widget
)
)
diff --git a/ui-tui/src/app/useInputHandlers.ts b/ui-tui/src/app/useInputHandlers.ts
index 76febe62ca7..64ba1fd53a9 100644
--- a/ui-tui/src/app/useInputHandlers.ts
+++ b/ui-tui/src/app/useInputHandlers.ts
@@ -166,7 +166,7 @@ export function applyVoiceRecordResponse(
}
export function dismissSensitivePrompt(
- overlay: Pick<OverlayState, 'secret' | 'sudo' | 'vaultUnlock'>,
+ overlay: Pick<OverlayState, 'secret' | 'sudo' | 'vaultSaveLogin' | 'vaultUnlock'>,
rpc: GatewayRpc,
sys: (text: string) => void
) {
@@ -200,6 +200,17 @@ export function dismissSensitivePrompt(
respondToServerRequest(requestId, { value: '' })
}
+
+ if (overlay.vaultSaveLogin) {
+ const requestId = overlay.vaultSaveLogin.requestId
+
+ patchOverlayState({ vaultSaveLogin: null })
+ sys(`login for ${overlay.vaultSaveLogin.site} not saved`)
+
+ respondToServerRequest(requestId, { value: '' })
+
+ return
+ }
}
const clamp = (value: number, min: number, max: number) => Math.max(min, Math.min(max, value))
diff --git a/ui-tui/src/app/useMainApp.ts b/ui-tui/src/app/useMainApp.ts
index 46230d3e167..955e089a1f1 100644
--- a/ui-tui/src/app/useMainApp.ts
+++ b/ui-tui/src/app/useMainApp.ts
@@ -1192,6 +1192,36 @@ export function useMainApp(gw: GatewayClient) {
[overlay.vaultUnlock, respondWith]
)
+ const answerVaultSaveLogin = useCallback(
+ (identifier: string, password: string) => {
+ if (!overlay.vaultSaveLogin) {
+ return
+ }
+
+ const requestId = overlay.vaultSaveLogin.requestId
+
+ // Either step left empty = declined (CLI parity). The login pair travels
+ // as one JSON value string (ValueResult); an empty value means "not
+ // saving" — the backend treats a password-less login as declined — so
+ // the tool's blocked wait resolves immediately instead of burning its
+ // 180s timeout. Values go only to the encrypted vault, never to the
+ // transcript, logs, or model context.
+ if (!identifier || !password) {
+ patchOverlayState({ vaultSaveLogin: null })
+ }
+
+ return respondWith(
+ requestId,
+ { value: identifier && password ? JSON.stringify({ identifier, password }) : '' },
+ () => {
+ patchOverlayState({ vaultSaveLogin: null })
+ patchUiState({ status: 'running…' })
+ }
+ )
+ },
+ [overlay.vaultSaveLogin, respondWith]
+ )
+
const onModelSelect = useCallback((value: string) => {
patchOverlayState({ modelPicker: false })
slashRef.current(`/model ${value}`, false) // the typed /model that opened the picker already counted
@@ -1301,6 +1331,7 @@ export function useMainApp(gw: GatewayClient) {
answerClarifyQuestion,
answerSecret,
answerSudo,
+ answerVaultSaveLogin,
answerVaultUnlock,
cancelClarify,
clearSelection,
@@ -1325,6 +1356,7 @@ export function useMainApp(gw: GatewayClient) {
answerClarifyQuestion,
answerSecret,
answerSudo,
+ answerVaultSaveLogin,
answerVaultUnlock,
cancelClarify,
clearSelection,
diff --git a/ui-tui/src/components/appLayout.tsx b/ui-tui/src/components/appLayout.tsx
index ecba126148d..84d2d99b5fc 100644
--- a/ui-tui/src/components/appLayout.tsx
+++ b/ui-tui/src/components/appLayout.tsx
@@ -620,6 +620,7 @@ export const AppLayout = memo(function AppLayout({
onClarifyQuestionAnswer={actions.answerClarifyQuestion}
onSecretSubmit={actions.answerSecret}
onSudoSubmit={actions.answerSudo}
+ onVaultSaveLoginSubmit={actions.answerVaultSaveLogin}
onVaultUnlockSubmit={actions.answerVaultUnlock}
/>
</PerfPane>
diff --git a/ui-tui/src/components/appOverlays.tsx b/ui-tui/src/components/appOverlays.tsx
index d0ed5b7424b..d2a1bf42d10 100644
--- a/ui-tui/src/components/appOverlays.tsx
+++ b/ui-tui/src/components/appOverlays.tsx
@@ -20,6 +20,7 @@ import { PluginsHub } from './pluginsHub.js'
import { ApprovalPrompt, ClarifyPrompt, ConfirmPrompt } from './prompts.js'
import { SkillsHub } from './skillsHub.js'
import { SubscriptionOverlay } from './subscriptionOverlay.js'
+import { VaultSaveLoginPrompt } from './vaultSaveLoginPrompt.js'
import { WidgetGrid, type WidgetGridWidget } from './widgetGrid.js'
const COMPLETION_WINDOW = 16
@@ -63,6 +64,7 @@ export function PromptZone({
onClarifyQuestionAnswer,
onSecretSubmit,
onSudoSubmit,
+ onVaultSaveLoginSubmit,
onVaultUnlockSubmit
}: Pick<
AppOverlaysProps,
@@ -72,6 +74,7 @@ export function PromptZone({
| 'onClarifyQuestionAnswer'
| 'onSecretSubmit'
| 'onSudoSubmit'
+ | 'onVaultSaveLoginSubmit'
| 'onVaultUnlockSubmit'
>) {
const overlay = useStore($overlayState)
@@ -191,6 +194,19 @@ export function PromptZone({
)
}
+ if (overlay.vaultSaveLogin) {
+ return (
+ <PromptCell cols={cols} id="vault-save-login">
+ <VaultSaveLoginPrompt
+ cols={cols}
+ onReady={onVaultSaveLoginSubmit}
+ site={overlay.vaultSaveLogin.site}
+ t={theme}
+ />
+ </PromptCell>
+ )
+ }
+
return null
}
diff --git a/ui-tui/src/components/vaultSaveLoginPrompt.tsx b/ui-tui/src/components/vaultSaveLoginPrompt.tsx
new file mode 100644
index 00000000000..814dde70b46
--- /dev/null
+++ b/ui-tui/src/components/vaultSaveLoginPrompt.tsx
@@ -0,0 +1,59 @@
+import { Box, Text } from '@hermes/ink'
+import { useState } from 'react'
+
+import type { Theme } from '../theme.js'
+
+import { MaskedPrompt } from './maskedPrompt.js'
+import { TextInput } from './textInput.js'
+
+/**
+ * Two-step capture for the `vault.save_login` server→client request (CLI
+ * parity: identifier shown as typed, then a masked password). Either step
+ * submitted empty declines the whole save. The values travel only to the
+ * encrypted vault — never to the transcript, logs, or model context.
+ */
+export function VaultSaveLoginPrompt({ cols = 80, onReady, site, t }: VaultSaveLoginPromptProps) {
+ const [identifier, setIdentifier] = useState('')
+ const [masked, setMasked] = useState(false)
+
+ if (masked) {
+ return (
+ <MaskedPrompt
+ cols={cols}
+ icon="🔑"
+ label={`Password for ${identifier}`}
+ onSubmit={password => onReady(identifier, password)}
+ sub={`stored in the encrypted vault for ${site} · hidden · never shown to the model`}
+ t={t}
+ />
+ )
+ }
+
+ return (
+ <Box flexDirection="column">
+ <Text bold color={t.color.warn}>
+ 🔑 Save a login for {site}
+ </Text>
+
+ <Text color={t.color.muted}> identifier (shown as typed) · password comes next · empty declines</Text>
+
+ <Box>
+ <Text color={t.color.label}>{'> '}</Text>
+ <TextInput
+ color={t.color.text}
+ columns={Math.max(20, cols - 6)}
+ onChange={setIdentifier}
+ onSubmit={value => (value ? setMasked(true) : onReady('', ''))}
+ value={identifier}
+ />
+ </Box>
+ </Box>
+ )
+}
+
+interface VaultSaveLoginPromptProps {
+ cols?: number
+ onReady: (identifier: string, password: string) => void
+ site: string
+ t: Theme
+}
diff --git a/ui-tui/src/types.ts b/ui-tui/src/types.ts
index 8da8375ba14..821f34cfc0f 100644
--- a/ui-tui/src/types.ts
+++ b/ui-tui/src/types.ts
@@ -201,6 +201,17 @@ export interface VaultUnlockReq {
requestId: string
}
+/**
+ * `vault.save_login` server→client request — save a new website login from a
+ * browser sign-in page. Two-step capture (identifier shown, password masked);
+ * the answer goes only to the encrypted vault, never to the model.
+ */
+export interface VaultSaveLoginReq {
+ origin: string
+ requestId: string
+ site: string
+}
+
export interface PanelData {
sections: PanelSection[]
title: string