Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e9cb969
refactor(agents): extract the title name-anchoring vocabulary
Sep 7, 2026
af3f9d9
fix(agents): stop a foreign agent name in task text from taking a pane
Sep 7, 2026
ad8f437
Merge remote-tracking branch 'origin/main' into brennanb2025/sta4554-…
Sep 7, 2026
5fad753
fix(agents): let the title label map admit a missing label
Sep 7, 2026
fa42ea4
fix(agents): let an agent's own sigil still present it against an owner
Sep 7, 2026
f4a8a04
Merge remote-tracking branch 'origin/main' into brennanb2025/sta4554-…
Sep 7, 2026
48eea76
fix(agents): gate on one identity-frame grammar, ratcheted against th…
Sep 7, 2026
2cc0151
Merge remote-tracking branch 'origin/main' into brennanb2025/sta4554-…
Sep 7, 2026
8b65244
fix(agents): stop reading a wrapper prefix as an identity frame
Sep 7, 2026
9055ab2
Merge main before completing title identity admission
brennanb2025 Oct 28, 2026
5f66731
fix(agents): admit identity frames before trusting terminal titles
brennanb2025 Oct 28, 2026
8f52bd5
fix(agents): separate title identity from readiness policy
brennanb2025 Oct 28, 2026
ea30590
Preserve title frame boundaries and normalization identity
brennanb2025 Oct 28, 2026
89597b9
Preserve activity token whitespace at title wrapper boundaries
brennanb2025 Oct 28, 2026
7480c27
Merge main before final PR #19309 QA
brennanb2025 Oct 28, 2026
c99ccd6
test: expose typed mailbox idle evidence source
brennanb2025 Oct 28, 2026
5f080dc
test: scope title projection work contract to renderer
brennanb2025 Oct 28, 2026
7193757
test: distinguish task activity from agent identity
brennanb2025 Oct 28, 2026
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 @@ -4,6 +4,11 @@ import type { TerminalLayoutSnapshot, TerminalTab } from '../../../../shared/ter
import type { TuiAgent } from '../../../../shared/tui-agent'
import { makePaneKey } from '../../../../shared/stable-pane-id'
import { buildWorktreeAgentRows } from './worktree-agent-rows'
import {
resolveAgentTypeFromTerminalTitle,
resolveTitleDerivedAgentType
} from './worktree-title-derived-agent-rows'
import { resolveRowAgentType } from './worktree-agent-row-type'

const LEAF_ID_1 = '77777777-7777-4777-8777-777777777777'
const LEAF_ID_2 = '88888888-8888-4888-8888-888888888888'
Expand Down Expand Up @@ -382,3 +387,125 @@ describe('buildTitleDerivedAgentRows', () => {
expect(rows).toHaveLength(0)
})
})

/**
* #14938: the owner guard below `resolveTitleDerivedAgentType`'s early return was only ever
* reached for the Claude label, so a Claude pane working on a task whose text names another agent
* was listed as that agent's row — label, icon and agentType.
*/
describe('a foreign name in a Claude pane task title', () => {
const FOREIGN_NAME_TASK_TITLES = [
'⠋ Fix the codex plugin launcher',
'⠋ add grok support to the tab bar',
'⠋ port the gemini status parser'
]

it('does not hand the row to the named agent', () => {
for (const title of FOREIGN_NAME_TASK_TITLES) {
const rows = buildWorktreeAgentRows({
tabs: [makeTab('tab-1', { launchAgent: 'claude' })],
entries: [],
retained: [],
runtimePaneTitlesByTabId: { 'tab-1': { 1: title } },
ptyIdsByTabId: { 'tab-1': ['pty-claude'] },
terminalLayoutsByTabId: { 'tab-1': makeSingleLayout(LEAF_ID_1) },
now: 2000
})
expect(rows.map((row) => row.agentType)).toEqual(['claude'])
}
})

it('declines at both title resolvers so the caller can fall back to the owner', () => {
expect(
resolveTitleDerivedAgentType('⠋ Fix the codex plugin launcher', 'Codex', 'claude')
).toBeNull()
expect(
resolveAgentTypeFromTerminalTitle('⠋ Fix the codex plugin launcher', 'claude')
).toBeNull()
})

// #14938 named this consumer specifically: it passes tab.launchAgent as the owner the guard used
// to discard, so a hook row with a missing or 'unknown' agentType flipped to the named agent too.
it('keeps resolveRowAgentType on the launch owner for an unknown-typed hook row', () => {
const entry = {
paneKey: makePaneKey('tab-1', LEAF_ID_1),
state: 'working',
prompt: 'x',
updatedAt: 0,
stateStartedAt: 0,
stateHistory: [],
agentType: 'unknown',
terminalTitle: '⠋ Fix the codex plugin launcher'
} as unknown as Parameters<typeof resolveRowAgentType>[0]
expect(resolveRowAgentType(entry, makeTab('tab-1', { launchAgent: 'claude' }))).toBe('claude')
})

// The reverse direction, which #8940 already guarded. Both directions are now one rule; this is
// the assertion that fails if the guard is ever made one-way again.
it('is symmetric with the Claude-token-in-foreign-task-text direction', () => {
expect(
resolveTitleDerivedAgentType('⠋ port the claude hook installer', 'Claude Code', 'codex')
).toBeNull()
expect(
resolveTitleDerivedAgentType('⠋ Fix the codex plugin launcher', 'Codex', 'claude')
).toBeNull()
})

it('still accepts a genuine identity frame on a reused pane', () => {
expect(resolveTitleDerivedAgentType('⠋ Codex', 'Codex', 'claude')).toBe('codex')
expect(resolveTitleDerivedAgentType('⠋ Codex: fix cursor offsets', 'Codex', 'claude')).toBe(
'codex'
)
expect(resolveTitleDerivedAgentType('⠋ Claude Code', 'Claude Code', 'codex')).toBe('claude')
})

// Non-discriminating: an unowned pane has nothing to protect, so the title answers either way.
it('still answers from the title when the pane has no known owner', () => {
expect(resolveTitleDerivedAgentType('⠋ Fix the codex plugin launcher', 'Codex', null)).toBe(
'codex'
)
})

// A vendor marker is the agent's own sigil, so it must still take the row from a prior owner.
// Reading only anchoredNames printed a Claude row, with a Claude label, for a live Gemini pane.
it('lets a vendor-marker title take the row from a prior owner', () => {
expect(
resolveTitleDerivedAgentType('\u2726 Analyzing the repository', 'Gemini CLI', 'claude')
).toBe('gemini')
expect(resolveTitleDerivedAgentType('\u25c7 waiting', 'Gemini CLI', 'claude')).toBe('gemini')
const rows = buildWorktreeAgentRows({
tabs: [makeTab('tab-1', { launchAgent: 'claude' })],
entries: [],
retained: [],
runtimePaneTitlesByTabId: { 'tab-1': { 1: '\u2726 Analyzing the repository' } },
ptyIdsByTabId: { 'tab-1': ['pty-gemini'] },
terminalLayoutsByTabId: { 'tab-1': makeSingleLayout(LEAF_ID_1) },
now: 2000
})
expect(rows.map((row) => [row.agentType, row.entry.prompt])).toEqual([['gemini', 'Gemini CLI']])
})

// #10258: Cursor's status-less native literal still identifies the pane, even against an owner.
it('lets the native cursor literal take the row from a prior owner', () => {
const rows = buildWorktreeAgentRows({
tabs: [makeTab('tab-1', { launchAgent: 'claude' })],
entries: [],
retained: [],
runtimePaneTitlesByTabId: { 'tab-1': { 1: 'Cursor Agent' } },
ptyIdsByTabId: { 'tab-1': ['pty-cursor'] },
terminalLayoutsByTabId: { 'tab-1': makeSingleLayout(LEAF_ID_1) },
now: 2000
})
expect(rows.map((row) => row.agentType)).toEqual(['cursor'])
})

// The label map is missing every label outside its fixed set, so the unknown-label branch is
// live at runtime. Nothing said so in the types until the value type was narrowed to TuiAgent,
// and deleting the branch on the compiler's advice would return undefined here instead.
it('returns unknown for a label the map does not carry', () => {
expect(resolveTitleDerivedAgentType('⠋ Something Else', 'Something Else', null)).toBe('unknown')
expect(resolveTitleDerivedAgentType('⠋ Something Else', 'Something Else', 'claude')).toBe(
'unknown'
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
type CompatibleAgentOwnerOptions
} from '../../../../shared/agent-title-owner'
import { resolvePaneAgentOwner } from '../../../../shared/pane-agent-owner'
import { isClaudeIdentityFrameTitle } from '../../../../shared/terminal-title-agent-type'
import { titlePresentsAgent } from '../../../../shared/agent-title-evidence'
import type { TuiAgent } from '../../../../shared/tui-agent'

/** Fixed, not per-process: title rows are a pure projection of the current title, so they are
* comparable across restarts in a way a sequenced authority's rows are not. Ordering against
Expand All @@ -32,7 +33,10 @@ const EMPTY_RUNTIME_TITLES: Record<string, Record<number, string>> = {}
const EMPTY_LIVE_PTY_IDS: Record<string, string[]> = {}
const EMPTY_TERMINAL_LAYOUTS: Record<string, TerminalLayoutSnapshot | undefined> = {}

const TITLE_AGENT_LABEL_TO_TYPE: Record<string, AgentType> = {
// Partial, not Record: `label` is arbitrary text parsed off a terminal title, so a lookup misses
// for anything outside this fixed set and the `?? 'unknown'` below is live. Without `Partial` the
// index type promises a hit that the runtime does not, and the unknown-label guard reads as dead.
const TITLE_AGENT_LABEL_TO_TYPE: Partial<Record<string, TuiAgent>> = {
'Claude Code': 'claude',
OpenClaude: 'openclaude',
Codex: 'codex',
Expand Down Expand Up @@ -231,19 +235,21 @@ export function resolveTitleDerivedAgentType(
ownerAgentType?: AgentType | null
): AgentType | null {
const agentType = TITLE_AGENT_LABEL_TO_TYPE[label] ?? 'unknown'
if (agentType !== 'claude') {
if (agentType === 'unknown') {
return agentType
}
// Why: Claude's task-title spinner heuristic has no provider identity. In
// split panes it can match arbitrary terminal spinners, so sidebar rows only
// accept Claude when the title itself names Claude.
if (!CLAUDE_AGENT_TOKEN_RE.test(title)) {
if (agentType === 'claude' && !CLAUDE_AGENT_TOKEN_RE.test(title)) {
return null
}
// Why: a "claude" word inside another agent's task text is a mention, not identity.
// Only a title that PRESENTS Claude may take a pane away from its known owner (#8940).
// Why: a name inside another agent's task text is a mention, not identity. Only a title that
// PRESENTS that agent may take a pane away from its known owner (#8940). Agent-neutral on
// purpose: while this was scoped to Claude, every other name in a Claude pane's task text
// short-circuited above the guard and took the row.
const owner = ownerAgentType && ownerAgentType !== 'unknown' ? ownerAgentType : null
if (owner && owner !== 'claude' && !isClaudeIdentityFrameTitle(title)) {
if (owner && owner !== agentType && !titlePresentsAgent(title, agentType)) {
return null
}
return agentType
Expand Down
209 changes: 209 additions & 0 deletions src/renderer/src/lib/tab-agent-foreign-name-title-guard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import { describe, expect, it } from 'vitest'
import { resolveTabAgentFromSignals as resolveFromSignalsModule } from './tab-agent-from-signals'
import { resolveTabAgentFromSignals as resolveFromHookModule } from './use-tab-agent'

/**
* #14937: a Claude pane's WORKING title is a bare braille spinner plus task text, so any agent
* name in that text used to resolve the title to a committed foreign identity and take the pane
* from its Claude owner. The guard that fixed the mirror-image bug (#8940) was written for the
* Claude label only, so every other name short-circuited above it.
*
* Both copies are exercised on purpose: `useTabAgent` (the tab-bar icon) calls the copy in
* use-tab-agent.ts, while open-tab-occupant-agent.ts and the rest of these suites call the copy in
* tab-agent-from-signals.ts. They are separate implementations of the same contract.
*/
const RESOLVERS = [
['tab-agent-from-signals', resolveFromSignalsModule],
['use-tab-agent', resolveFromHookModule]
] as const

const FOREIGN_NAME_TASK_TITLES = [
'⠋ Fix the codex plugin launcher',
'⠙ Investigate why codex hangs on Windows',
'⠹ compare codex and claude output',
'⠋ add grok support to the tab bar',
'⠋ port the gemini status parser',
'⠋ review copilot suggestions'
]

describe.each(RESOLVERS)('%s: a foreign name in task text is a mention', (_name, resolve) => {
it('keeps a Claude-owned pane Claude with no live hook', () => {
for (const title of FOREIGN_NAME_TASK_TITLES) {
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title,
hookAgent: null,
launchAgent: 'claude'
})
).toBe('claude')
}
})

it('keeps a Claude-owned pane Claude with a completed hook, and on a remote pane', () => {
const title = '⠋ Fix the codex plugin launcher'
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title,
hookAgent: null,
focusedCompletedHookAgent: 'claude',
launchAgent: 'claude'
})
).toBe('claude')
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: true,
title,
hookAgent: null,
launchAgent: 'claude'
})
).toBe('claude')
})

// Non-discriminating on its own — it passes before the fix too. Kept as the control that shows
// why users experienced this as random: a live hook always outranked the title.
it('was already correct while a live hook existed', () => {
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title: '⠋ Fix the codex plugin launcher',
hookAgent: 'claude',
launchAgent: 'claude'
})
).toBe('claude')
})

// The guard must stay agent-neutral in BOTH directions. This is the assertion that fails if
// someone reintroduces a one-way guard: #8940's direction and #14937's direction are one rule.
it('still lets a genuine identity frame reclaim a reused pane, both directions', () => {
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title: '✳ Claude Code',
hookAgent: null,
launchAgent: 'opencode'
})
).toBe('claude')
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title: '⠋ Codex',
hookAgent: null,
launchAgent: 'claude'
})
).toBe('codex')
})

// The mirror of this PR's own bug, and the regression the first cut of it shipped: a vendor
// marker is the agent's OWN sigil, which task text cannot forge, so it must still reclaim a
// pane from a prior owner. Gemini's four glyphs and Cursor's native literal are markers, not
// anchored names, so a predicate reading only anchoredNames strands a real Gemini pane on its
// previous Claude owner.
it('lets a vendor-marker title reclaim a pane from a prior owner', () => {
for (const title of [
'\u2726 Analyzing the repository',
'\u23f2 thinking',
'\u25c7 waiting',
'\u270b approve this edit'
]) {
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title,
hookAgent: null,
launchAgent: 'claude'
})
).toBe('gemini')
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title,
hookAgent: null,
focusedCompletedHookAgent: 'claude',
launchAgent: 'claude'
})
).toBe('gemini')
}
// #10258: the native literal is deliberately status-less but still identifies a live pane.
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title: 'cursor agent',
hookAgent: null,
launchAgent: 'claude'
})
).toBe('cursor')
})

// Claude's decorations are the exception, and the reason the vendor class cannot be admitted
// wholesale: OpenCode emits '. ' and '* ' too, so they prove activity, not identity.
it('does not let a generic Claude status prefix reclaim a pane', () => {
for (const title of [
'. port the claude prompt',
'. ship it with claude',
'. Compare Opencode Vs Orca'
]) {
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title,
hookAgent: null,
launchAgent: 'opencode'
})
).toBe('opencode')
}
})

// The four routes `getAgentLabel` mints identity from that a predicate built on the evidence
// parser alone cannot see. Each is the agent naming itself, so each must still take the pane.
it.each([
['pi native', '\u03c0 > session - ~/orca', 'pi'],
['pi native, blocked', '\u03c0 ! blocked-session', 'pi'],
['name plus status', 'codex working', 'codex'],
['name plus status, spinner', '\u2838 aider running', 'aider'],
['name plus status, grok', 'grok done', 'grok'],
['em-dash frame', '\u2849 Codex \u2014 refactoring', 'codex'],
['pipe-headed', 'ssh host | opencode ready', 'opencode'],
['windows launcher', 'aider.ps1 ready', 'aider'],
['windows launcher, action', 'copilot.exe - action required', 'copilot']
])('reclaims a foreign-owned pane for a %s title', (_label, title, expected) => {
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title,
hookAgent: null,
launchAgent: 'claude'
})
).toBe(expected)
})

it('keeps an OpenCode pane OpenCode when its task text mentions Claude (#8940)', () => {
for (const title of [
'OC | ⠋ ask claude about this',
'⠋ use Claude Sonnet',
'⠋ port the claude prompt'
]) {
expect(
resolve({
hasObservedAgentSignal: true,
isRemote: false,
title,
hookAgent: null,
launchAgent: 'opencode'
})
).toBe('opencode')
}
})
})
Loading
Loading