Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ describe('resolveTerminalShortcutAction', () => {
).toEqual({ type: 'sendInput', data: '\x1b[13;2u' })
})

it('sends a literal LF for Windows panes whose agent binds the Ctrl+J newline alias (#10203)', () => {
// Why: Pi binds 0x0A as a newline; a 1-byte LF is a fast newline that avoids the
// CSI-u decode freeze vs Alt+J and stays distinct from Enter's CR (no submit).
expect(
resolveTerminalShortcutAction(
event({ key: 'Enter', code: 'Enter', shiftKey: true }),
false,
'false',
0,
true,
undefined,
undefined,
undefined,
undefined,
() => 'lf'
)
).toEqual({ type: 'sendInput', data: '\n' })
})

it('uses CSI-u for a non-Windows PTY reached from Windows only while Kitty is active', () => {
const getWindowsShiftEnterEncoding = vi.fn(() => 'csi-u' as const)
const resolve = (kittyActive: boolean) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ export function resolveTerminalShortcutAction(
) {
// Why: negotiated KKP is authoritative everywhere; trusted pane evidence also preserves Droid's Windows encoding without KKP.
const windowsHost = isWindowsTerminalHost()
const hasTrustedWindowsCsiU = windowsHost && getWindowsShiftEnterEncoding?.() === 'csi-u'
const windowsEncoding = windowsHost ? getWindowsShiftEnterEncoding?.() : undefined
// Why: agents that bind a literal LF newline (e.g. Pi's Ctrl+J/0x0A alias) send a fast 1-byte LF instead of CSI-u - avoids the CSI-u decode freeze vs Alt+J (#10203) while staying distinct from Enter's CR (no submit, #9703).
if (windowsEncoding === 'lf') {
return { type: 'sendInput', data: '\n' }
}
const hasTrustedWindowsCsiU = windowsEncoding === 'csi-u'
// Why: CSI-u is application input, not universal; without trusted Windows evidence, require active KKP negotiation.
const canSendCsiU = hasTrustedWindowsCsiU || isKittyKeyboardActivePane?.() === true
return { type: 'sendInput', data: canSendCsiU ? '\x1b[13;2u' : '\x1b\r' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import {
} from './terminal-windows-shift-enter'

describe('resolveWindowsShiftEnterEncoding', () => {
it('uses CSI-u only for trusted Droid process evidence', () => {
it('uses CSI-u for trusted Droid evidence and for a Droid-launched pane when live trust is missing (#9703 reliability)', () => {
expect(
resolveWindowsShiftEnterEncoding({
foreground: { agent: 'droid', routingTrusted: true, shellForeground: false }
})
).toBe('csi-u')
expect(resolveWindowsShiftEnterEncoding({ launchAgentType: 'droid' })).toBe('alt-enter')
// Why: launch ownership keeps the encoding applied across a transient foreground-scan miss.
expect(resolveWindowsShiftEnterEncoding({ launchAgentType: 'droid' })).toBe('csi-u')
})

it('uses CSI-u only for trusted Pi process evidence', () => {
it('uses LF for trusted Pi evidence and for a Pi-launched pane when live trust is missing (fast newline, no CSI-u decode freeze) (#9703 #10203)', () => {
expect(
resolveWindowsShiftEnterEncoding({
foreground: { agent: 'pi', routingTrusted: true, shellForeground: false }
})
).toBe('csi-u')
expect(resolveWindowsShiftEnterEncoding({ launchAgentType: 'pi' })).toBe('alt-enter')
).toBe('lf')
expect(resolveWindowsShiftEnterEncoding({ launchAgentType: 'pi' })).toBe('lf')
})

it('does not let hook or OSC-derived status forge Droid input routing', () => {
Expand Down Expand Up @@ -55,19 +56,19 @@ describe('resolveWindowsShiftEnterEncoding', () => {
).toBe('alt-enter')
})

it('fails closed while a newer command generation awaits trusted evidence', () => {
it('keeps the launch-agent encoding while a newer command generation awaits trusted evidence (#9703 reliability)', () => {
expect(
resolveWindowsShiftEnterEncoding({
foreground: { agent: 'droid', shellForeground: false },
launchAgentType: 'droid'
})
).toBe('alt-enter')
).toBe('csi-u')
expect(
resolveWindowsShiftEnterEncoding({
foreground: { agent: null, shellForeground: false },
launchAgentType: 'droid'
})
).toBe('alt-enter')
).toBe('csi-u')
})

it('keeps launch ownership on its original leaf after a split sibling survives', () => {
Expand All @@ -78,9 +79,10 @@ describe('resolveWindowsShiftEnterEncoding', () => {
}
}

expect(resolveWindowsShiftEnterEncodingForPane(state, 'tab:launched-droid')).toBe('alt-enter')
// Why: launch ownership keeps the encoding applied on the launched leaf across a transient foreground-scan miss.
expect(resolveWindowsShiftEnterEncodingForPane(state, 'tab:launched-droid')).toBe('csi-u')
// Why: after split→close leaves only the sibling, pane count is no longer
// ownership evidence; the surviving leaf must keep the legacy fallback.
// ownership evidence; the surviving leaf with no launch config keeps the legacy fallback.
expect(resolveWindowsShiftEnterEncodingForPane(state, 'tab:surviving-sibling')).toBe(
'alt-enter'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AgentType } from '../../../../shared/agent-status-types'
import { TUI_AGENT_CONFIG } from '../../../../shared/tui-agent-config'
import type { PaneForegroundAgentEntry } from '@/store/slices/pane-foreground-agent'

export type WindowsShiftEnterEncoding = 'alt-enter' | 'csi-u'
export type WindowsShiftEnterEncoding = 'alt-enter' | 'csi-u' | 'lf'

type WindowsShiftEnterAgentSignals = {
foreground?: PaneForegroundAgentEntry
Expand All @@ -22,12 +22,11 @@ export function resolveWindowsShiftEnterEncoding(
if (signals.foreground?.shellForeground) {
return 'alt-enter'
}
// Why: an entry marks a newer command/process generation. Until fresh
// confirmation trusts it, stale launch ownership must not route input.
// Launch metadata is only an expectation used to start confirmation; it is
// never byte-routing authority because warm/stale daemon state can outlive
// the process that originally launched the agent.
const agent = signals.foreground?.routingTrusted === true ? signals.foreground.agent : null
// Why: trust the live foreground when fresh confirmation is available; otherwise fall back to the pane's launch agent so a single Shift+Enter newline is not lost to a transient foreground-scan miss during agent tool-subprocess churn (#9703, #10203). shellForeground above still fails closed when the agent has exited to a shell.
const agent =
signals.foreground?.routingTrusted === true
? signals.foreground.agent
: (signals.launchAgentType ?? null)
return agent ? (TUI_AGENT_CONFIG[agent].windowsShiftEnterEncoding ?? 'alt-enter') : 'alt-enter'
}

Expand Down
6 changes: 3 additions & 3 deletions src/shared/tui-agent-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type TuiAgentConfig = {
/** Renderer-specific signal that the composer is ready for paste, stronger than the default quiet-render window. */
draftPasteReadySignal?: DraftPasteReadySignal
/** Windows Shift+Enter encoding override; omitted agents keep the legacy Esc+CR path. */
windowsShiftEnterEncoding?: 'csi-u'
windowsShiftEnterEncoding?: 'csi-u' | 'lf'
}

export const TUI_AGENT_CONFIG: Record<TuiAgent, TuiAgentConfig> = {
Expand Down Expand Up @@ -131,8 +131,8 @@ export const TUI_AGENT_CONFIG: Record<TuiAgent, TuiAgentConfig> = {
promptInjectionMode: 'argv',
// Why: pi has no `--prefill` and paste-after-ready races its long startup; the orca-prefill extension seeds this env var instead.
draftPromptEnvVar: 'ORCA_PI_PREFILL',
// Why: Pi decodes CSI-u; Esc+CR submits after tool subprocesses reset live KKP state (#9703).
windowsShiftEnterEncoding: 'csi-u'
// Why: Pi binds Ctrl+J (0x0A) as a newline alias by default, so sending LF for Shift+Enter is a fast 1-byte newline that avoids both the Esc+CR submit (#9703) and the CSI-u decode freeze vs Alt+J (#10203).
windowsShiftEnterEncoding: 'lf'
},
omp: {
detectCmd: 'omp',
Expand Down