fix(mobile): preserve leaf title projection

This commit is contained in:
Brennan Benson
2026-08-13 01:37:58 -07:00
parent 322d79e6e2
commit 1963ec767f
5 changed files with 51 additions and 16 deletions
@@ -549,7 +549,9 @@ function TerminalPane(
return leafIds.length === 1 ? leafIds[0] : null
}, [getNativeChatLeafIds, tabWideAgentHintLeafId])
const getTabWideAgentHintLeafIdRef = useRef(getTabWideAgentHintLeafId)
getTabWideAgentHintLeafIdRef.current = getTabWideAgentHintLeafId
useEffect(() => {
getTabWideAgentHintLeafIdRef.current = getTabWideAgentHintLeafId
}, [getTabWideAgentHintLeafId])
useEffect(() => {
if (tabWideAgentHintLeafId !== undefined) {
return
@@ -289,7 +289,8 @@ function makeLiveSurface(tabId: string): {
worktreeId: MOUNTED_WT,
getManager: () => manager,
getContainer: () => null,
getPtyIdForPane: (paneId: number) => ptyIdByPaneId.get(paneId) ?? null
getPtyIdForPane: (paneId: number) => ptyIdByPaneId.get(paneId) ?? null,
getTabWideAgentHintLeafId: () => MOUNTED_LEAF_ID
} as unknown as Parameters<typeof registerRuntimeTerminalTab>[0]
return {
registration,
@@ -553,4 +553,32 @@ describe('terminal mobile session layout publication', () => {
'parentLayout.titlesByLeafId'
)
})
it('keeps pane-owned titles across split parking', () => {
const firstLeaf = '11111111-1111-4111-8111-111111111111'
const secondLeaf = '22222222-2222-4222-8222-222222222222'
const splitState = makeState({
tabsByWorktree: {
'wt-1': [{ id: 'term-1', title: 'Leaked tab title', customTitle: null }]
} as unknown as AppState['tabsByWorktree'],
terminalLayoutsByTabId: {
'term-1': {
root: {
type: 'split',
direction: 'horizontal',
first: { type: 'leaf', leafId: firstLeaf },
second: { type: 'leaf', leafId: secondLeaf }
},
activeLeafId: firstLeaf,
expandedLeafId: null,
titlesByLeafId: { [firstLeaf]: 'agent pane', [secondLeaf]: 'shell pane' }
}
} as AppState['terminalLayoutsByTabId']
})
expect(buildMobileSessionTabSnapshots(splitState)[0]?.tabs).toMatchObject([
{ leafId: firstLeaf, title: 'agent pane' },
{ leafId: secondLeaf, title: 'shell pane' }
])
})
})
@@ -1038,7 +1038,8 @@ describe('buildMobileSessionTabSnapshots', () => {
text: 'inspect mobile routing',
createdAt: 2
}
}
},
runtimePaneTitlesByTabId: { 'term-collapse': { 1: 'Codex live title' } }
})
expect(buildMobileSessionTabSnapshots(state)[0]?.tabs).toEqual([
+16 -13
View File
@@ -1848,10 +1848,13 @@ function buildMobileLaunchDraftsByPaneKey(args: {
NonNullable<AppState['nativeChatLaunchDraftByTabId']>[string]
>
}): MobileSessionWorktreeInputs['launchDraftByPaneKey'] {
const draftsByPaneKey = new Map<
if (args.launchDraftByTabId.size === 0) {
return EMPTY_NARROWED_BY_KEY
}
let draftsByPaneKey: Map<
string,
NonNullable<AppState['nativeChatLaunchDraftByTabId']>[string]
>()
> | null = null
for (const terminal of args.terminalTabs) {
const draft = args.launchDraftByTabId.get(terminal.id)
if (!draft || draft.resolved) {
@@ -1870,9 +1873,10 @@ function buildMobileLaunchDraftsByPaneKey(args: {
if (!launchAgent || launchAgent !== draft.agent || !ownerLeafId) {
continue
}
draftsByPaneKey ??= new Map()
draftsByPaneKey.set(makePaneKey(terminal.id, ownerLeafId), draft)
}
return draftsByPaneKey
return draftsByPaneKey ?? EMPTY_NARROWED_BY_KEY
}
function buildMobileTerminalSurfaceTabs(
@@ -1929,19 +1933,18 @@ function buildMobileTerminalSurfaceTabs(
: legacyPaneId
? paneTitles[Number(legacyPaneId)]
: undefined
const leafTitle = paneTitle?.trim() || sanitizedSavedLayout?.titlesByLeafId?.[leafId]?.trim()
const paneKey = isTerminalLeafId(leafId) ? makePaneKey(terminal.id, leafId) : null
const tabWideFallbackSafe =
isNativeChatTabWideFallbackSafe(parentLayout) && launchAgentLeafId === leafId
const title =
paneTitle?.trim() ||
(tabWideFallbackSafe
? resolveRuntimeTerminalTitle(
terminal,
generatedTitlesEnabled,
terminal.title ?? 'Terminal'
)
: 'Terminal')
const agentStatusTitle = paneTitle ?? (tabWideFallbackSafe ? terminal.title : '') ?? ''
const title = tabWideFallbackSafe
? resolveRuntimeTerminalTitle(
terminal,
generatedTitlesEnabled,
leafTitle ?? terminal.title ?? 'Terminal'
)
: (leafTitle ?? 'Terminal')
const agentStatusTitle = leafTitle ?? (tabWideFallbackSafe ? terminal.title : '') ?? ''
const agentStatus =
paneKey && !isClaudeManagementTitle(agentStatusTitle)
? inputs.agentStatusByPaneKey.get(paneKey)