mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
fix(terminal): keep remote-viewer clipboard env on command-less creates (#40550)
* fix(terminal): keep remote-viewer clipboard env on command-less creates (#39852) A paired viewer's plain terminal reaches the host renderer's tab-create bridge with spawn env (ORCA_REMOTE_VIEWER_CLIPBOARD, PI_CLIPBOARD_OSC52) but no startup command. The bridge queued pendingStartup only when a command existed, dropping the env, so the spawned shell never saw the remote-viewer clipboard marker and copied text stayed on the host clipboard (#39852). - Queue the startup whenever the request carries launch material (env/envToDelete/launchConfig/resume), not only a command. - PtyPaneStartup.command becomes optional for env-only startups; spawn options already tolerate a missing command. - Keep the plain-shell pre-bind input hold for startups that plan no post-bind work, so an env-only startup types as a plain shell does. Co-Authored-By: Claude Code <noreply@anthropic.com> * test(e2e): layout oracle marks only panes the user can see A hidden tab with a queued startup is laid out at opacity 0 so it spawns at real geometry. The marker check counted it as visible because it has a size, then waited for output that the hidden-delivery gate correctly withholds. Paired-client creates now queue spawn env, so their background tabs hit this. --------- Co-authored-by: Chen <zwq19980411@gmail.com> Co-authored-by: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import type { PtyPaneStartup } from '../../pty-connection/startup/pty-pane-startup'
|
||||
|
||||
export type SplitStartupPayload = { command: string; env?: Record<string, string> }
|
||||
|
||||
export function splitPaneWithOneShotStartup<TPane>(
|
||||
deps: { startup?: SplitStartupPayload | null },
|
||||
// Why the union: pane deps hold a full PtyPaneStartup, whose command is optional (#39852).
|
||||
deps: { startup?: SplitStartupPayload | PtyPaneStartup | null },
|
||||
startup: SplitStartupPayload,
|
||||
splitPane: () => TPane
|
||||
): TPane {
|
||||
|
||||
@@ -19,10 +19,23 @@ export function paneHasStartupWork(session: ConnectPanePtySession): boolean {
|
||||
return paneHasKnownStartupWork(session) || mainStartsPane(session)
|
||||
}
|
||||
|
||||
/** Spawn env alone is not post-bind work; a plain paired terminal types as a plain shell does (#39852). */
|
||||
function startupPlansPostBindWork(startup: ConnectPanePtySession['paneStartup']): boolean {
|
||||
return Boolean(
|
||||
startup &&
|
||||
(startup.command !== undefined ||
|
||||
startup.agentLaunch !== undefined ||
|
||||
startup.freshAgentLaunch !== undefined ||
|
||||
startup.resumeProviderSession !== undefined ||
|
||||
startup.launchConfig !== undefined ||
|
||||
startup.draftPrompt !== undefined)
|
||||
)
|
||||
}
|
||||
|
||||
function paneHasKnownStartupWork(session: ConnectPanePtySession): boolean {
|
||||
const state = useAppStore.getState()
|
||||
return Boolean(
|
||||
session.paneStartup ||
|
||||
startupPlansPostBindWork(session.paneStartup) ||
|
||||
session.getSleepingRecordForPane(state) ||
|
||||
findColdRestoreResumeSource(session, state)
|
||||
)
|
||||
|
||||
+2
-1
@@ -11,7 +11,8 @@ import type { SessionOptionValue } from '../../../../../../shared/native-chat/in
|
||||
import type { AgentPaneLaunchRequest } from '../../../../../../shared/agent-launch/contracts/agent-pane-launch-request'
|
||||
|
||||
export type PtyPaneStartup = {
|
||||
command: string
|
||||
/** Absent when the startup carries only spawn env, e.g. a paired viewer's plain terminal (#39852). */
|
||||
command?: string
|
||||
/** Renderer-delivered startup input for callers that need xterm paste
|
||||
* semantics before the submit Enter. */
|
||||
delivery?: 'terminal-paste'
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createTabsSliceMockApi } from '../../store/slices/tabs/tabs-slice-test-harness'
|
||||
import { createTestStore } from '../../store/testing/app-store-test-fixture'
|
||||
|
||||
vi.mock('sonner', () => ({ toast: { info: vi.fn(), success: vi.fn(), error: vi.fn() } }))
|
||||
const testStore = vi.hoisted(() => {
|
||||
const ref: { current: ReturnType<typeof createTestStore> | null } = { current: null }
|
||||
return ref
|
||||
})
|
||||
vi.mock('../../store', () => ({
|
||||
useAppStore: {
|
||||
getState: () => {
|
||||
if (!testStore.current) {
|
||||
throw new Error('no test store')
|
||||
}
|
||||
return testStore.current.getState()
|
||||
}
|
||||
}
|
||||
}))
|
||||
vi.mock('@/lib/terminal-worktree-route', () => ({
|
||||
resolveTerminalWorktreeRoute: () => ({ runtimeEnvironmentId: null })
|
||||
}))
|
||||
vi.mock('./terminal-command-state', async (importOriginal) => ({
|
||||
...(await importOriginal<object>()),
|
||||
focusTerminalInitiatedTab: vi.fn()
|
||||
}))
|
||||
|
||||
createTabsSliceMockApi()
|
||||
|
||||
const { registerTerminalRequestIpcBridge } = await import('./terminal-request-ipc-bridge')
|
||||
|
||||
const WT = 'repo1::/tmp/feature'
|
||||
|
||||
type CreateRequest = {
|
||||
requestId: string
|
||||
worktreeId: string
|
||||
presentation?: 'focused' | 'background'
|
||||
source?: 'runtime-session'
|
||||
env?: Record<string, string>
|
||||
}
|
||||
|
||||
let request!: (data: CreateRequest) => void
|
||||
const replyTerminalCreate = vi.fn()
|
||||
let store: ReturnType<typeof createTestStore>
|
||||
|
||||
beforeEach(() => {
|
||||
store = createTestStore()
|
||||
testStore.current = store
|
||||
replyTerminalCreate.mockClear()
|
||||
vi.stubGlobal('window', {
|
||||
...globalThis.window,
|
||||
api: {
|
||||
...globalThis.window?.api,
|
||||
ui: {
|
||||
...globalThis.window?.api?.ui,
|
||||
onRequestTerminalCreate: (callback: (data: CreateRequest) => void) => {
|
||||
request = callback
|
||||
return () => {}
|
||||
},
|
||||
replyTerminalCreate
|
||||
}
|
||||
}
|
||||
})
|
||||
registerTerminalRequestIpcBridge([])
|
||||
store.getState().setActiveWorktree(WT)
|
||||
})
|
||||
|
||||
describe("a paired viewer's command-less terminal create", () => {
|
||||
// Main sends only spawn env for a plain remote terminal; dropping it left the pane without the
|
||||
// remote-viewer clipboard marker, so copied text never reached the viewer (#39852).
|
||||
it('queues the env as startup so the spawned pane carries it', () => {
|
||||
request({
|
||||
requestId: 'request-1',
|
||||
worktreeId: WT,
|
||||
source: 'runtime-session',
|
||||
presentation: 'focused',
|
||||
env: { ORCA_REMOTE_VIEWER_CLIPBOARD: '1', PI_CLIPBOARD_OSC52: '1' }
|
||||
})
|
||||
|
||||
const tabId = replyTerminalCreate.mock.calls[0]?.[0]?.tabId
|
||||
expect(tabId).toBeDefined()
|
||||
expect(store.getState().pendingStartupByTabId[tabId!]).toEqual({
|
||||
env: { ORCA_REMOTE_VIEWER_CLIPBOARD: '1', PI_CLIPBOARD_OSC52: '1' }
|
||||
})
|
||||
})
|
||||
|
||||
it('still queues nothing for a bare create without command or env', () => {
|
||||
request({ requestId: 'request-2', worktreeId: WT, presentation: 'focused' })
|
||||
|
||||
const tabId = replyTerminalCreate.mock.calls[0]?.[0]?.tabId
|
||||
expect(tabId).toBeDefined()
|
||||
expect(store.getState().pendingStartupByTabId[tabId!]).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -62,23 +62,29 @@ export function registerTerminalRequestIpcBridge(unsubs: (() => void)[]): void {
|
||||
recordInteraction: false,
|
||||
...(data.cwd ? { startupCwd: data.cwd } : {})
|
||||
}
|
||||
const pendingStartup = data.command
|
||||
? {
|
||||
command: data.command,
|
||||
...(data.env ? { env: data.env } : {}),
|
||||
...(data.envToDelete ? { envToDelete: data.envToDelete } : {}),
|
||||
...(data.launchConfig ? { launchConfig: data.launchConfig } : {}),
|
||||
...(data.resumeProviderSession
|
||||
? { resumeProviderSession: data.resumeProviderSession }
|
||||
: {}),
|
||||
...(data.launchToken ? { launchToken: data.launchToken } : {}),
|
||||
...(data.launchAgent ? { launchAgent: data.launchAgent } : {}),
|
||||
...(data.trustWorktreeId ? { trustWorktreeId: data.trustWorktreeId } : {}),
|
||||
...(data.startupCommandDelivery
|
||||
? { startupCommandDelivery: data.startupCommandDelivery }
|
||||
: {})
|
||||
}
|
||||
: undefined
|
||||
// Why beyond command: a paired viewer's plain terminal carries only spawn env (#39852).
|
||||
const pendingStartup =
|
||||
data.command ||
|
||||
data.env ||
|
||||
data.envToDelete ||
|
||||
data.launchConfig ||
|
||||
data.resumeProviderSession
|
||||
? {
|
||||
...(data.command ? { command: data.command } : {}),
|
||||
...(data.env ? { env: data.env } : {}),
|
||||
...(data.envToDelete ? { envToDelete: data.envToDelete } : {}),
|
||||
...(data.launchConfig ? { launchConfig: data.launchConfig } : {}),
|
||||
...(data.resumeProviderSession
|
||||
? { resumeProviderSession: data.resumeProviderSession }
|
||||
: {}),
|
||||
...(data.launchToken ? { launchToken: data.launchToken } : {}),
|
||||
...(data.launchAgent ? { launchAgent: data.launchAgent } : {}),
|
||||
...(data.trustWorktreeId ? { trustWorktreeId: data.trustWorktreeId } : {}),
|
||||
...(data.startupCommandDelivery
|
||||
? { startupCommandDelivery: data.startupCommandDelivery }
|
||||
: {})
|
||||
}
|
||||
: undefined
|
||||
const tab = store.createTab(
|
||||
worktreeId,
|
||||
data.targetGroupId,
|
||||
|
||||
@@ -208,7 +208,7 @@ describe('launchAgentInNewTab', () => {
|
||||
}
|
||||
const startup = queuedStartups()[0]
|
||||
expect(startup).toBeDefined()
|
||||
expect(tokenizeStartupCommand(startup.command, 'posix')).toMatchObject({
|
||||
expect(tokenizeStartupCommand(startup.command ?? '', 'posix')).toMatchObject({
|
||||
ok: true,
|
||||
tokens: ['cx', '-c', 'model="true"', '-c', 'model_reasoning_effort=high']
|
||||
})
|
||||
|
||||
@@ -208,7 +208,7 @@ export type TerminalActions = {
|
||||
queueTabStartupCommand: (
|
||||
tabId: string,
|
||||
startup: {
|
||||
command: string
|
||||
command?: string
|
||||
delivery?: 'terminal-paste'
|
||||
startupCommandDelivery?: StartupCommandDelivery
|
||||
env?: Record<string, string>
|
||||
@@ -236,7 +236,7 @@ export type TerminalActions = {
|
||||
tabId: string,
|
||||
expected?: TerminalState['pendingStartupByTabId'][string]
|
||||
) => {
|
||||
command: string
|
||||
command?: string
|
||||
delivery?: 'terminal-paste'
|
||||
startupCommandDelivery?: StartupCommandDelivery
|
||||
env?: Record<string, string>
|
||||
|
||||
@@ -64,7 +64,8 @@ export type TerminalState = {
|
||||
pendingStartupByTabId: Record<
|
||||
string,
|
||||
{
|
||||
command: string
|
||||
/** Absent when the startup carries only spawn env, e.g. a paired viewer's plain terminal (#39852). */
|
||||
command?: string
|
||||
delivery?: 'terminal-paste'
|
||||
startupCommandDelivery?: StartupCommandDelivery
|
||||
env?: Record<string, string>
|
||||
|
||||
@@ -19,7 +19,12 @@ export async function checkPaneMarkers(
|
||||
const mounted = new Set(
|
||||
await page.evaluate(() =>
|
||||
Array.from(document.querySelectorAll<HTMLElement>('.pane[data-leaf-id][data-pty-id]'))
|
||||
.filter((pane) => pane.getBoundingClientRect().width > 0)
|
||||
// Why opacity: a hidden tab with a queued startup is laid out at opacity 0 so it spawns at real geometry; it has a size but is not shown.
|
||||
.filter(
|
||||
(pane) =>
|
||||
pane.getBoundingClientRect().width > 0 &&
|
||||
pane.checkVisibility({ opacityProperty: true, visibilityProperty: true })
|
||||
)
|
||||
.map((pane) => pane.dataset.leafId ?? '')
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user