fix(sidebar): keep retained agent identity under a bare Terminal title

Hoisting titleShowsNoAgent also broadened it to treat any "Terminal N" as
evidence of exit, which dropped a pane's retained Codex identity
(use-tab-agent-retained-identity). A bare default-shaped title is only
exit evidence when it matches the tab's own defaultTitle.
This commit is contained in:
Brennan Benson
2026-08-20 20:12:24 -07:00
parent 3181e1e02a
commit 40c7c39e5e
2 changed files with 6 additions and 10 deletions
@@ -426,7 +426,10 @@ describe('titleShowsNoAgent', () => {
it('treats shell names and default Terminal titles as no agent', () => {
expect(titleShowsNoAgent('zsh')).toBe(true)
expect(titleShowsNoAgent('cmd.exe')).toBe(true)
expect(titleShowsNoAgent('Terminal 1')).toBe(true)
// A bare "Terminal N" is NOT evidence of exit on its own: a pane can carry a
// retained agent identity under that title (use-tab-agent-retained-identity).
// It only means "no agent" when it matches the tab's own default title.
expect(titleShowsNoAgent('Terminal 1')).toBe(false)
expect(titleShowsNoAgent('Terminal 1', 'Terminal 1')).toBe(true)
})
+2 -9
View File
@@ -22,17 +22,10 @@ export function isShellProcess(processName: string): boolean {
)
}
const DEFAULT_TERMINAL_TITLE_RE = /^terminal \d+$/i
/** A shell name or the tab's default Terminal title; blank titles are no evidence. */
/** A shell name or the tab's own neutral default title; blank titles are no evidence. */
export function titleShowsNoAgent(title: string, defaultTitle?: string): boolean {
const trimmed = title.trim()
return (
trimmed.length > 0 &&
(isShellProcess(trimmed) ||
trimmed === defaultTitle?.trim() ||
DEFAULT_TERMINAL_TITLE_RE.test(trimmed))
)
return trimmed.length > 0 && (isShellProcess(trimmed) || trimmed === defaultTitle?.trim())
}
// Why: a ConPTY-side buffer clear cannot reach PSReadLine's cached cursor