fix(terminal): don't apply native-Windows ConPTY cursor stripping to remote serve PTYs
Closes #6008
This commit is contained in:
@@ -57,7 +57,7 @@ import {
|
||||
writeTerminalOutput
|
||||
} from '@/lib/pane-manager/pane-terminal-output-scheduler'
|
||||
import { recordAgentHibernationPaneOutput } from '@/lib/agent-hibernation-output-activity'
|
||||
import { isLocalNativeWindowsPty } from '@/lib/pane-manager/windows-pty-compatibility'
|
||||
import { isLocalNativeWindowsConpty } from '@/lib/pane-manager/windows-pty-compatibility'
|
||||
import { recordTerminalOutput, restoreScrollStateAfterLayout } from '@/lib/pane-manager/pane-scroll'
|
||||
import type { ScrollState } from '@/lib/pane-manager/pane-manager-types'
|
||||
import { createBrowserUuid } from '@/lib/browser-uuid'
|
||||
@@ -98,7 +98,10 @@ import {
|
||||
cancelScheduledHiddenOutputRestore,
|
||||
scheduleHiddenOutputRestore
|
||||
} from './hidden-output-restore-scheduler'
|
||||
import { getRuntimeEnvironmentIdForWorktree } from '@/lib/worktree-runtime-owner'
|
||||
import {
|
||||
getExecutionHostIdForWorktree,
|
||||
getRuntimeEnvironmentIdForWorktree
|
||||
} from '@/lib/worktree-runtime-owner'
|
||||
import { CLIENT_PLATFORM } from '@/lib/new-workspace'
|
||||
import { buildAgentResumeStartupPlan } from '@/lib/tui-agent-startup'
|
||||
import { resolveAgentStatusTerminalTitle } from '@/lib/agent-status-terminal-title'
|
||||
@@ -1736,11 +1739,18 @@ export function connectPanePty(
|
||||
const connectionId = getConnectionId(deps.worktreeId) ?? null
|
||||
const tab = (state.tabsByWorktree[deps.worktreeId] ?? []).find((t) => t.id === deps.tabId)
|
||||
const shellOverride = tab?.shellOverride
|
||||
const isNativeWindowsConpty = isLocalNativeWindowsPty({
|
||||
// Why: a serve/remote-runtime pane has no SSH connectionId and a Linux cwd, so
|
||||
// the native-Windows ConPTY heuristic misfires on a Windows client and wrongly
|
||||
// enables ConPTY synchronized-output protection, which strips an agent's
|
||||
// transient cursor-show (?25h) and leaves the cursor invisible. The execution
|
||||
// host is the authoritative signal: only a 'local' host is a local native PTY.
|
||||
const executionHostId = getExecutionHostIdForWorktree(state, deps.worktreeId)
|
||||
const isNativeWindowsConpty = isLocalNativeWindowsConpty({
|
||||
userAgent: navigator.userAgent,
|
||||
connectionId,
|
||||
cwd: deps.cwd,
|
||||
shellOverride
|
||||
shellOverride,
|
||||
executionHostId
|
||||
})
|
||||
const shouldApplyNativeWindowsRewriteRefresh = isNativeWindowsConpty
|
||||
const shouldProtectNativeWindowsSynchronizedOutput = isNativeWindowsConpty
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildWindowsPtyCompatibilityOptions,
|
||||
isLocalNativeWindowsConpty,
|
||||
isLocalNativeWindowsPty
|
||||
} from './windows-pty-compatibility'
|
||||
|
||||
@@ -107,3 +108,76 @@ describe('buildWindowsPtyCompatibilityOptions', () => {
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isLocalNativeWindowsConpty', () => {
|
||||
// A genuine local native Windows ConPTY (Windows UA, no SSH connectionId,
|
||||
// Windows cwd) on a 'local' execution host must keep the ConPTY workarounds.
|
||||
const localNativeWindowsContext = {
|
||||
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
||||
connectionId: null,
|
||||
cwd: 'C:\\repo',
|
||||
shellOverride: 'powershell.exe'
|
||||
} as const
|
||||
const remoteServePaneOnWindowsClientContext = {
|
||||
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
|
||||
connectionId: null,
|
||||
cwd: '/home/me/repo',
|
||||
shellOverride: null
|
||||
} as const
|
||||
|
||||
it('treats a local-execution-host Windows pane as a native ConPTY', () => {
|
||||
expect(
|
||||
isLocalNativeWindowsConpty({ ...localNativeWindowsContext, executionHostId: 'local' })
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('does NOT treat a remote-runtime (serve) pane as a native ConPTY even when the raw Windows heuristic matches', () => {
|
||||
// Regression: a serve-hosted pane on a Windows client has no SSH connectionId
|
||||
// and a Linux cwd, so isLocalNativeWindowsPty returns true. Without the
|
||||
// execution-host gate, ConPTY transient cursor-show (?25h) stripping is
|
||||
// wrongly applied and the agent cursor disappears.
|
||||
expect(isLocalNativeWindowsPty(remoteServePaneOnWindowsClientContext)).toBe(true)
|
||||
expect(
|
||||
isLocalNativeWindowsConpty({
|
||||
...remoteServePaneOnWindowsClientContext,
|
||||
executionHostId: 'runtime:my-serve'
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('does NOT treat an SSH-runtime pane as a native ConPTY', () => {
|
||||
expect(
|
||||
isLocalNativeWindowsConpty({
|
||||
...localNativeWindowsContext,
|
||||
executionHostId: 'ssh:my-host'
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('stays false on a local host when the pane is not a native Windows PTY', () => {
|
||||
// Non-Windows client: the raw heuristic is false, so the gate result is false
|
||||
// regardless of the local execution host.
|
||||
expect(
|
||||
isLocalNativeWindowsConpty({
|
||||
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0)',
|
||||
connectionId: null,
|
||||
cwd: '/repo',
|
||||
shellOverride: null,
|
||||
executionHostId: 'local'
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
|
||||
it('does not let a local execution host re-enable protection the raw heuristic already suppressed', () => {
|
||||
// Guards the AND: even on a 'local' host, a Windows pane excluded for a
|
||||
// non-execution-host reason (here an SSH connectionId) must stay false, so a
|
||||
// future refactor cannot make the local host bypass the raw checks.
|
||||
expect(
|
||||
isLocalNativeWindowsConpty({
|
||||
...localNativeWindowsContext,
|
||||
connectionId: 'ssh-1',
|
||||
executionHostId: 'local'
|
||||
})
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ITerminalOptions } from '@xterm/xterm'
|
||||
import { isWslUncPath } from '../../../../shared/wsl-paths'
|
||||
import { LOCAL_EXECUTION_HOST_ID, type ExecutionHostId } from '../../../../shared/execution-host'
|
||||
|
||||
export type WindowsPtyCompatibilityContext = {
|
||||
userAgent?: string
|
||||
@@ -57,3 +58,21 @@ export function isLocalNativeWindowsPty(context: WindowsPtyCompatibilityContext)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a pane is a genuine local native Windows ConPTY that needs the ConPTY
|
||||
* cursor/synchronized-output workarounds.
|
||||
*
|
||||
* Why this is gated on the execution host: a serve/remote-runtime pane on a
|
||||
* Windows client has no SSH `connectionId` and a Linux `cwd`, so
|
||||
* `isLocalNativeWindowsPty` misfires and classifies it as local. The execution
|
||||
* host is the authoritative signal: only a `'local'` host is a real local
|
||||
* native PTY. Remote panes resolve to `runtime:<env>` (or `ssh:<target>`) and
|
||||
* must be excluded, otherwise ConPTY transient cursor-show (`?25h`) stripping is
|
||||
* wrongly applied to them and a repainting agent's cursor disappears.
|
||||
*/
|
||||
export function isLocalNativeWindowsConpty(
|
||||
context: WindowsPtyCompatibilityContext & { executionHostId: ExecutionHostId }
|
||||
): boolean {
|
||||
return context.executionHostId === LOCAL_EXECUTION_HOST_ID && isLocalNativeWindowsPty(context)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user