mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
* fix(tabs): a session's own name replaces a quick-command tab name * fix(tabs): only a session's own name replaces a quick-command tab name Session titles now say whether they are the session's own name (a rename or a provider-generated name) or a stand-in such as the first prompt. A quick-command tab keeps its label until the session has a name; a name typed on the tab still wins. Titles from older hosts and saved tabs with no kind keep the label; old saved titles are asked for once. * fix(tabs): classify History-cached titles for session-id-only title requests * fix(tabs): keep a cached session title when its transcript cannot be reread * fix(tabs): keep a session title when its classification reread fails * fix(tabs): keep the transcript for an unclassified cached session title * test(tabs): keep the cached-title fixture's agent literal
84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
import type { AiVaultSessionTitle } from './ai-vault/contracts/ai-vault-session-title'
|
|
import type { Tab } from './tab-types'
|
|
import type { TerminalTab } from './workspace-layout/terminal-tab-types'
|
|
import { isMeaningfulOpenCodeTerminalTitle } from './agent-status/title/providers/opencode-terminal-title'
|
|
|
|
export type TabNameSources = {
|
|
/** A name the user typed into the tab. */
|
|
customTitle?: string | null
|
|
quickCommandLabel?: string | null
|
|
/** The program's own terminal title right now. */
|
|
liveTitle: string
|
|
/** The agent session's title, already checked to belong to this tab's session. */
|
|
sessionTitle?: Pick<AiVaultSessionTitle, 'title' | 'kind'> | null
|
|
generatedTitle?: string | null
|
|
}
|
|
|
|
/** The one name order every tab and agent-row surface uses; '' leaves the plain live title to the caller. */
|
|
export function resolveTabNameSource(
|
|
sources: TabNameSources,
|
|
generatedTitlesEnabled: boolean
|
|
): string {
|
|
const sessionTitle = sources.sessionTitle?.title.trim() ?? ''
|
|
// Why: a quick-command label only names the tab until the session has a name of its own (a rename or
|
|
// a provider-generated name); a first-prompt stand-in does not replace it. A typed tab name wins over both.
|
|
const sessionNamed = sources.sessionTitle?.kind === 'named'
|
|
return (
|
|
sources.customTitle?.trim() ||
|
|
(isMeaningfulOpenCodeTerminalTitle(sources.liveTitle) ? sources.liveTitle : '') ||
|
|
(sessionNamed ? sessionTitle : '') ||
|
|
sources.quickCommandLabel?.trim() ||
|
|
sessionTitle ||
|
|
(generatedTitlesEnabled ? sources.generatedTitle?.trim() : '') ||
|
|
''
|
|
)
|
|
}
|
|
|
|
export function resolveTerminalTabTitle(
|
|
tab: Pick<TerminalTab, 'quickCommandLabel' | 'aiVaultTitle' | 'generatedTitle' | 'title'> & {
|
|
customTitle?: string | null
|
|
},
|
|
generatedTitlesEnabled: boolean,
|
|
fallback = ''
|
|
): string {
|
|
const liveTitle = tab.title?.trim() ?? ''
|
|
return (
|
|
resolveTabNameSource(
|
|
{
|
|
customTitle: tab.customTitle,
|
|
quickCommandLabel: tab.quickCommandLabel,
|
|
liveTitle,
|
|
sessionTitle: tab.aiVaultTitle,
|
|
generatedTitle: tab.generatedTitle
|
|
},
|
|
generatedTitlesEnabled
|
|
) ||
|
|
liveTitle ||
|
|
fallback
|
|
)
|
|
}
|
|
|
|
export function resolveUnifiedTabLabel(
|
|
tab:
|
|
| Pick<Tab, 'customLabel' | 'quickCommandLabel' | 'aiVaultTitle' | 'generatedLabel' | 'label'>
|
|
| undefined,
|
|
generatedTitlesEnabled: boolean,
|
|
fallback = ''
|
|
): string {
|
|
const liveLabel = tab?.label?.trim() ?? ''
|
|
return (
|
|
resolveTabNameSource(
|
|
{
|
|
customTitle: tab?.customLabel,
|
|
quickCommandLabel: tab?.quickCommandLabel,
|
|
liveTitle: liveLabel,
|
|
sessionTitle: tab?.aiVaultTitle,
|
|
generatedTitle: tab?.generatedLabel
|
|
},
|
|
generatedTitlesEnabled
|
|
) ||
|
|
liveLabel ||
|
|
fallback
|
|
)
|
|
}
|