fix(native-chat): switch to Terminal when a chat command opens a TUI dialog (#43192)

OpenCode /models, /help and similar commands open a dialog the Chat
view cannot show, and later chat sends were typed into it. Flag the
commands that open a TUI screen (OpenCode, Codex pickers, OMP's
in-Terminal commands) and switch the terminal-backed chat to Terminal
once the command is submitted, on desktop and mobile.
This commit is contained in:
Kelvin Amoaba
2026-11-16 19:00:42 +00:00
committed by GitHub
parent d1ddc79c7f
commit f3869d5040
12 changed files with 298 additions and 40 deletions
@@ -217,4 +217,26 @@ describe('useMobileNativeChatSessionOptions', () => {
await expect(first).resolves.toBe(true)
await expect(queued).resolves.toBe(false)
})
it('switches to Terminal after a sent command that opens a TUI dialog', () => {
mount({ agent: 'opencode' })
act(() => {
api!.recordCommand('/clear')
})
expect(onAgentPicker).not.toHaveBeenCalled()
act(() => {
api!.recordCommand('/models')
})
expect(onAgentPicker).toHaveBeenCalledTimes(1)
})
it('does not switch another chat when a TUI dialog command lands after the phone moved on', () => {
mount({ agent: 'opencode', scopeKey: scopeKey('a') })
const recordFromA = api!.recordCommand
update({ scopeKey: scopeKey('b') })
act(() => {
recordFromA('/models')
})
expect(onAgentPicker).not.toHaveBeenCalled()
})
})
@@ -33,6 +33,7 @@ import {
matchNativeChatCatalogModelId
} from '../../../../../../src/shared/native-chat/input/session-options/native-chat-session-option-state'
import { setBoundedScopeCacheEntry } from '../../../../../../src/shared/native-chat/native-chat-scope-cache'
import { nativeChatCommandOpensTerminal } from '../../../../../../src/shared/native-chat/native-chat-agent-profiles'
import { sayMobileNativeChatSessionOption } from './native-chat-session-option-copy'
export type MobileNativeChatSessionOptionsController = {
@@ -273,8 +274,19 @@ export function useMobileNativeChatSessionOptions(
[track]
)
const recordCommand = useCallback(
(command: string) => surface?.recordOutgoingCommand(command),
[surface]
(command: string) => {
surface?.recordOutgoingCommand(command)
// Why: later chat sends would be typed into the TUI screen this command opened; a send that lands after the phone moved to another chat or agent must not switch that one.
if (
agent &&
latest.current.scopeKey === scopeKey &&
latest.current.agent === agent &&
nativeChatCommandOpensTerminal(agent, command)
) {
latest.current.onAgentPicker?.()
}
},
[agent, scopeKey, surface]
)
const pendingId = pending && pending.identity === identity ? pending.id : null
@@ -233,12 +233,11 @@ export const NativeChatComposerPane = forwardRef<ComposerHandle, C.NativeChatCom
const ptyCommandRouting = {
agent,
disabled,
isDispatchingSessionOption: sessionOptions.isDispatching,
...sessionOptions.ptyCommandRouting,
resolveTarget,
onSlashCommand,
onSubmitted,
answerCommandLocally,
sessionOptionsSurface: sessionOptions.pty.surface,
trackPendingSend,
setDraft,
setCaret,
@@ -1,6 +1,10 @@
import { useNativeChatSessionOptionCommand } from '../../session/options/terminal/use-native-chat-session-option-command'
import { useNativeChatSessionOptions } from '../../session/options/terminal/use-native-chat-session-options'
import type { NativeChatComposerProps } from '../native-chat-composer-types'
import type { NativeChatSendHandle } from '../../session/terminal/send/native-chat-runtime-send'
import type { NativeChatPtySessionOptionsSurface } from '../../../../../../shared/native-chat/input/session-options/native-chat-pty-session-options'
import { nativeChatCommandOpensTerminal } from '../../../../../../shared/native-chat/native-chat-agent-profiles'
import { useCallback } from 'react'
import type {
SessionOptionDescriptor,
SessionOptionsSurface
@@ -33,8 +37,13 @@ export function useNativeChatComposerSessionOptions({
paneKey,
structuredTransport
}: ComposerSessionOptionsArgs): {
isDispatching: boolean
pty: ReturnType<typeof useNativeChatSessionOptions>
/** What a PTY command send needs from the session options. */
ptyCommandRouting: {
isDispatchingSessionOption: boolean
sessionOptionsSurface: NativeChatPtySessionOptionsSurface | null
/** Switches to Terminal once a command that opens a TUI screen is in. */
onCommandSent: (command: string, delivery: NativeChatSendHandle) => void
}
surface: SessionOptionsSurface | null
snapshot: SessionOptionDescriptor[]
} {
@@ -54,9 +63,26 @@ export function useNativeChatComposerSessionOptions({
readTerminalScreen,
paneKey
})
const onCommandSent = useCallback(
(command: string, delivery: NativeChatSendHandle) => {
if (!onSwitchToTerminal || !nativeChatCommandOpensTerminal(agent, command)) {
return
}
// Why: leaving the chat cancels its pending writes, so switch only once the command is in.
void delivery.outcome?.then((outcome) => {
if (outcome === 'submitted') {
onSwitchToTerminal()
}
})
},
[agent, onSwitchToTerminal]
)
return {
isDispatching,
pty,
ptyCommandRouting: {
isDispatchingSessionOption: isDispatching,
sessionOptionsSurface: pty.surface,
onCommandSent
},
surface: structuredTransport?.optionsSurface ?? pty.surface,
snapshot: structuredTransport?.optionSnapshot ?? pty.snapshot
}
@@ -0,0 +1,117 @@
import { translate } from '@/i18n/i18n'
import type { SlashCommandDescriptionCopy } from './native-chat-slash-command-descriptions'
export const OPENCODE_SLASH_COMMAND_DESCRIPTIONS: SlashCommandDescriptionCopy = {
models: {
'Open the model selector in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.modelTerminal',
'Open the model selector in Terminal'
)
},
agents: {
'Choose the agent in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.agentsTerminal',
'Choose the agent in Terminal'
)
},
sessions: {
'Switch sessions in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.sessionsTerminal',
'Switch sessions in Terminal'
)
},
skills: {
'Browse skills in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.skillsTerminal',
'Browse skills in Terminal'
)
},
mcps: {
'Manage MCP servers in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.mcpsTerminal',
'Manage MCP servers in Terminal'
)
},
connect: {
'Connect a provider in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.connectTerminal',
'Connect a provider in Terminal'
)
},
status: {
'View status in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.statusTerminal',
'View status in Terminal'
)
},
themes: {
'Choose a theme in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.themesTerminal',
'Choose a theme in Terminal'
)
},
diff: {
'Open the diff viewer in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.diffTerminal',
'Open the diff viewer in Terminal'
)
},
editor: {
'Open your editor in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.editorTerminal',
'Open your editor in Terminal'
)
},
debug: {
'View debug info in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.debugTerminal',
'View debug info in Terminal'
)
},
help: {
'Show help in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.helpTerminal',
'Show help in Terminal'
)
},
fork: {
'Fork the session in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.forkSessionTerminal',
'Fork the session in Terminal'
)
},
rename: {
'Rename the session in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.renameSessionTerminal',
'Rename the session in Terminal'
)
},
timeline: {
'Browse the session timeline in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.timelineTerminal',
'Browse the session timeline in Terminal'
)
},
export: {
'Export the session in Terminal': () =>
translate(
'components.native-chat.slashCommandDescriptions.exportTerminal',
'Export the session in Terminal'
)
}
}
@@ -1,6 +1,7 @@
import { translate } from '@/i18n/i18n'
import { CODEX_SLASH_COMMAND_DESCRIPTIONS } from './native-chat-codex-slash-command-descriptions'
import { OMP_SLASH_COMMAND_DESCRIPTIONS } from './native-chat-omp-slash-command-descriptions'
import { OPENCODE_SLASH_COMMAND_DESCRIPTIONS } from './native-chat-opencode-slash-command-descriptions'
/** Command name -> curated English description -> localized copy. */
export type SlashCommandDescriptionCopy = Record<string, Record<string, () => string>>
@@ -74,7 +75,8 @@ const SHARED_SLASH_COMMAND_DESCRIPTIONS: SlashCommandDescriptionCopy = {
const SLASH_COMMAND_DESCRIPTION_TABLES = [
SHARED_SLASH_COMMAND_DESCRIPTIONS,
CODEX_SLASH_COMMAND_DESCRIPTIONS,
OMP_SLASH_COMMAND_DESCRIPTIONS
OMP_SLASH_COMMAND_DESCRIPTIONS,
OPENCODE_SLASH_COMMAND_DESCRIPTIONS
]
/** Localize curated descriptions by command name; agent-reported or older-host text passes through. */
@@ -7,7 +7,8 @@ import {
} from '@/components/native-chat/telemetry/native-chat-telemetry'
import {
sendNativeChatMessage,
sendNativeChatTypedCommand
sendNativeChatTypedCommand,
type NativeChatSendHandle
} from '../../session/terminal/send/native-chat-runtime-send'
import {
nativeChatComposerTargetIsRemote,
@@ -27,6 +28,7 @@ export function useNativeChatPickerCommandDispatch(args: {
isDispatchingSessionOption: boolean
resolveTarget: () => NativeChatResolvedTarget | null
onSlashCommand?: (command: string, output?: string) => void
onCommandSent?: (command: string, delivery: NativeChatSendHandle) => void
answerCommandLocally?: NativeChatLocalCommandAnswer
onSubmitted?: () => void
sessionOptionsSurface: NativeChatPtySessionOptionsSurface | null
@@ -44,6 +46,7 @@ export function useNativeChatPickerCommandDispatch(args: {
isDispatchingSessionOption,
resolveTarget,
onSlashCommand,
onCommandSent,
answerCommandLocally,
onSubmitted,
sessionOptionsSurface,
@@ -80,16 +83,17 @@ export function useNativeChatPickerCommandDispatch(args: {
setActiveSuggestion(0)
return
}
trackPendingSend(
const delivery =
agent === 'codex'
? sendNativeChatTypedCommand(target.ptyId, text)
: sendNativeChatMessage(target.ptyId, text)
)
trackPendingSend(delivery)
emitNativeChatPickerItemAccepted({ agent, itemKind: 'command' })
// Match typed-command telemetry and composer cleanup; stale attachments must not ride the next prompt.
emitNativeChatSendClassified({ agent, outcome: 'command' })
onSlashCommand?.(text)
sessionOptionsSurface?.recordOutgoingCommand(text)
onCommandSent?.(text, delivery)
emitNativeChatMessageSent({
agent,
runtime: nativeChatComposerTargetIsRemote(target.ptyId) ? 'remote' : 'local'
@@ -109,6 +113,7 @@ export function useNativeChatPickerCommandDispatch(args: {
clearSkillOrigin,
disabled,
isDispatchingSessionOption,
onCommandSent,
onSlashCommand,
onSubmitted,
resolveTarget,
@@ -47,6 +47,7 @@ export function useNativeChatPtyComposerSend(args: {
onOptimisticSend?: (text: string, imagePaths?: string[], recovery?: boolean) => string | undefined
optimisticSendOutcome?: NativeChatOptimisticSendOutcome
onSlashCommand?: (command: string, output?: string) => void
onCommandSent?: (command: string, delivery: NativeChatSendHandle) => void
answerCommandLocally?: NativeChatLocalCommandAnswer
onSubmitted?: () => void
sessionOptionsSurface: NativeChatPtySessionOptionsSurface | null
@@ -140,6 +141,9 @@ export function useNativeChatPtyComposerSend(args: {
if (classification === 'command') {
args.onSlashCommand?.(text.trim())
args.sessionOptionsSurface?.recordOutgoingCommand(text.trim())
if (pendingHandle) {
args.onCommandSent?.(text.trim(), pendingHandle)
}
}
} else {
pendingId = args.onOptimisticSend?.(text, imagePaths, retry !== undefined)
@@ -164,7 +164,13 @@ export function sendNativeChatTypedCommand(
if (!isCancelled() && outcome !== 'accepted') {
clearUnsubmittedAgentInput(ptyId)
}
markSubmitted()
markSubmitted(
outcome === 'accepted'
? 'submitted'
: outcome === 'unknown'
? 'uncertain'
: 'not-submitted'
)
}
const typeCommand = (): void => {
void typeAgentTuiCommand({
+16 -1
View File
@@ -21592,7 +21592,22 @@
"settings": "Open settings in Terminal",
"extensions": "Open the extension dashboard in Terminal",
"hotkeys": "Show keyboard shortcuts in Terminal",
"mcpManage": "Manage MCP servers"
"mcpManage": "Manage MCP servers",
"agentsTerminal": "Choose the agent in Terminal",
"sessionsTerminal": "Switch sessions in Terminal",
"skillsTerminal": "Browse skills in Terminal",
"mcpsTerminal": "Manage MCP servers in Terminal",
"connectTerminal": "Connect a provider in Terminal",
"statusTerminal": "View status in Terminal",
"themesTerminal": "Choose a theme in Terminal",
"diffTerminal": "Open the diff viewer in Terminal",
"editorTerminal": "Open your editor in Terminal",
"debugTerminal": "View debug info in Terminal",
"helpTerminal": "Show help in Terminal",
"forkSessionTerminal": "Fork the session in Terminal",
"renameSessionTerminal": "Rename the session in Terminal",
"timelineTerminal": "Browse the session timeline in Terminal",
"exportTerminal": "Export the session in Terminal"
},
"modelDescriptions": {
"grok_4_7": "xAI's latest frontier model",
@@ -19,6 +19,8 @@ export type SlashCommandSuggestion = {
reply?: NativeChatCommandReply
/** The desktop chat runs it itself: it hides an agent command of the same name, never a skill. */
orcaOwned?: true
/** Sent bare, it opens a TUI screen the chat cannot show, so a terminal-backed chat switches to Terminal. */
opensInTerminal?: true
}
// Curated stable commands: CLIs provide no machine-readable catalog.
@@ -45,21 +47,21 @@ const OPENCLAUDE_COMMANDS: readonly SlashCommandSuggestion[] = [
const CODEX_COMMANDS: readonly SlashCommandSuggestion[] = [
{ name: 'model', description: 'Choose the model and reasoning effort' },
{ name: 'ide', description: 'Include IDE context' },
{ name: 'permissions', description: 'Choose what Codex is allowed to do' },
{ name: 'keymap', description: 'Remap TUI shortcuts' },
{ name: 'permissions', description: 'Choose what Codex is allowed to do', opensInTerminal: true },
{ name: 'keymap', description: 'Remap TUI shortcuts', opensInTerminal: true },
{ name: 'vim', description: 'Toggle Vim mode' },
{ name: 'experimental', description: 'Toggle experimental features' },
{ name: 'experimental', description: 'Toggle experimental features', opensInTerminal: true },
{ name: 'approve', description: 'Approve one auto-review retry' },
{ name: 'memories', description: 'Configure memory use' },
{ name: 'skills', description: 'Manage and use skills' },
{ name: 'memories', description: 'Configure memory use', opensInTerminal: true },
{ name: 'skills', description: 'Manage and use skills', opensInTerminal: true },
{ name: 'import', description: 'Import setup from Claude Code' },
{ name: 'hooks', description: 'View lifecycle hooks' },
{ name: 'review', description: 'Review the current changes' },
{ name: 'rename', description: 'Rename the current thread' },
{ name: 'review', description: 'Review the current changes', opensInTerminal: true },
{ name: 'rename', description: 'Rename the current thread', opensInTerminal: true },
{ name: 'new', description: 'Start a new chat' },
{ name: 'archive', description: 'Archive this session and exit' },
{ name: 'delete', description: 'Delete this session and exit' },
{ name: 'resume', description: 'Resume a saved chat' },
{ name: 'resume', description: 'Resume a saved chat', opensInTerminal: true },
{ name: 'fork', description: 'Fork the current chat' },
{ name: 'app', description: 'Continue in Codex Desktop' },
{ name: 'init', description: 'Create an AGENTS.md file' },
@@ -74,37 +76,46 @@ const CODEX_COMMANDS: readonly SlashCommandSuggestion[] = [
{ name: 'mention', description: 'Mention a file' },
{ name: 'status', description: 'Show session configuration and usage' },
{ name: 'usage', description: 'View account usage' },
{ name: 'title', description: 'Configure the terminal title' },
{ name: 'statusline', description: 'Configure the status line' },
{ name: 'theme', description: 'Choose a syntax highlighting theme' },
{ name: 'pets', description: 'Choose or hide the terminal pet' },
{ name: 'title', description: 'Configure the terminal title', opensInTerminal: true },
{ name: 'statusline', description: 'Configure the status line', opensInTerminal: true },
{ name: 'theme', description: 'Choose a syntax highlighting theme', opensInTerminal: true },
{ name: 'pets', description: 'Choose or hide the terminal pet', opensInTerminal: true },
{ name: 'mcp', description: 'List configured MCP tools' },
{ name: 'plugins', description: 'Browse plugins' },
{ name: 'plugins', description: 'Browse plugins', opensInTerminal: true },
{ name: 'logout', description: 'Log out of Codex' },
{ name: 'exit', description: 'Exit Codex' },
{ name: 'feedback', description: 'Send logs to maintainers' },
{ name: 'feedback', description: 'Send logs to maintainers', opensInTerminal: true },
{ name: 'ps', description: 'List background terminals' },
{ name: 'stop', description: 'Stop all background terminals' },
{ name: 'clear', description: 'Clear the terminal and start a new chat' },
{ name: 'personality', description: 'Choose a communication style' },
{ name: 'subagents', description: 'Switch the active agent thread' }
{ name: 'subagents', description: 'Switch the active agent thread', opensInTerminal: true }
]
// OMP built-in registry; interactive commands still execute in its terminal.
const OMP_COMMANDS: readonly SlashCommandSuggestion[] = [
{ name: 'model', description: 'Open the model selector in Terminal' },
{ name: 'model', description: 'Open the model selector in Terminal', opensInTerminal: true },
{
name: 'switch',
description: 'Open the temporary model selector in Terminal'
description: 'Open the temporary model selector in Terminal',
opensInTerminal: true
},
{ name: 'plan', description: 'Toggle plan mode' },
{ name: 'compact', description: 'Compact conversation context' },
{ name: 'clear', description: 'Clear context while keeping the session' },
{ name: 'new', description: 'Start a new session' },
{ name: 'resume', description: 'Resume a session; without arguments, choose in Terminal' },
{ name: 'fork', description: 'Fork from a previous message in Terminal' },
{ name: 'branch', description: 'Rewind to a previous message in Terminal' },
{ name: 'tree', description: 'Browse the session tree in Terminal' },
{
name: 'resume',
description: 'Resume a session; without arguments, choose in Terminal',
opensInTerminal: true
},
{ name: 'fork', description: 'Fork from a previous message in Terminal', opensInTerminal: true },
{
name: 'branch',
description: 'Rewind to a previous message in Terminal',
opensInTerminal: true
},
{ name: 'tree', description: 'Browse the session tree in Terminal', opensInTerminal: true },
{ name: 'session', description: 'Show session information and controls' },
{ name: 'rename', description: 'Rename the session' },
// Why: OMP paints this in its TUI and records nothing the chat could show.
@@ -113,18 +124,49 @@ const OMP_COMMANDS: readonly SlashCommandSuggestion[] = [
{ name: 'fast', description: 'Toggle priority service tier' },
{ name: 'tools', description: 'Show tools visible to the agent' },
{ name: 'jobs', description: 'Show background jobs' },
{ name: 'git', description: 'Open the Git viewer in Terminal' },
{ name: 'git', description: 'Open the Git viewer in Terminal', opensInTerminal: true },
{ name: 'export', description: 'Export the session to HTML' },
{ name: 'settings', description: 'Open settings in Terminal' },
{ name: 'extensions', description: 'Open the extension dashboard in Terminal' },
{ name: 'hotkeys', description: 'Show keyboard shortcuts in Terminal' }
{ name: 'settings', description: 'Open settings in Terminal', opensInTerminal: true },
{
name: 'extensions',
description: 'Open the extension dashboard in Terminal',
opensInTerminal: true
},
{ name: 'hotkeys', description: 'Show keyboard shortcuts in Terminal', opensInTerminal: true }
]
// Flagged rows open a TUI dialog on OpenCode 1.19.0 or 2.3.0.
const OPENCODE_COMMANDS: readonly SlashCommandSuggestion[] = [
{ name: 'clear', description: 'Clear the conversation' },
{ name: 'models', description: 'Open the model selector in Terminal', opensInTerminal: true },
{ name: 'agents', description: 'Choose the agent in Terminal', opensInTerminal: true },
{ name: 'sessions', description: 'Switch sessions in Terminal', opensInTerminal: true },
{ name: 'skills', description: 'Browse skills in Terminal', opensInTerminal: true },
{ name: 'mcps', description: 'Manage MCP servers in Terminal', opensInTerminal: true },
{ name: 'connect', description: 'Connect a provider in Terminal', opensInTerminal: true },
{ name: 'status', description: 'View status in Terminal', opensInTerminal: true },
{ name: 'themes', description: 'Choose a theme in Terminal', opensInTerminal: true },
{ name: 'diff', description: 'Open the diff viewer in Terminal', opensInTerminal: true },
{ name: 'editor', description: 'Open your editor in Terminal', opensInTerminal: true },
{ name: 'debug', description: 'View debug info in Terminal', opensInTerminal: true },
{ name: 'help', description: 'Show help in Terminal', opensInTerminal: true },
{ name: 'fork', description: 'Fork the session in Terminal', opensInTerminal: true },
{ name: 'rename', description: 'Rename the session in Terminal', opensInTerminal: true },
{
name: 'timeline',
description: 'Browse the session timeline in Terminal',
opensInTerminal: true
},
{ name: 'export', description: 'Export the session in Terminal', opensInTerminal: true }
]
const COMMANDS_BY_AGENT: Partial<Record<AgentType, readonly SlashCommandSuggestion[]>> = {
claude: CLAUDE_COMMANDS,
openclaude: OPENCLAUDE_COMMANDS,
codex: CODEX_COMMANDS,
omp: OMP_COMMANDS
omp: OMP_COMMANDS,
opencode: OPENCODE_COMMANDS,
opencode2: OPENCODE_COMMANDS
}
/** Known slash commands for an agent, falling back to a small common set so the
@@ -109,6 +109,14 @@ export function getNativeChatCommandReply(
)
}
/** Whether a bare command sent over a terminal session opens a TUI screen the chat cannot show. */
export function nativeChatCommandOpensTerminal(agent: AgentType, command: string): boolean {
const text = command.trim()
return getVerifiedNativeChatCommands(agent).some(
(entry) => entry.opensInTerminal === true && text === `/${entry.name}`
)
}
/** Exclude desktop-only answers: mobile lacks composer answers/transcript reply rows and would offer commands with no visible result. */
export function getAgentAnsweredNativeChatCommands(
agent: AgentType