fix(agents): recognize OpenCode native OC | tab titles (#9102)

* fix(agents): recognize OpenCode native OC | tab titles

OpenCode's native OSC titles use `OC | <task>` without an `opencode`
token, so title classifiers left tabs as Claude/unknown. Map the native
marker (optional mux prefix) to OpenCode identity in both title
classifiers, exclude it from isClaudeAgent, and cover lookalikes plus
stale Claude launch reclaim.

Builds on and supersedes #8590 (credit @gatsby74). Fixes #8478.

* fix(agents): drop renderer import from #8478 shared repro

tsconfig.node includes src/shared tests; importing agent-status pulled
renderer modules outside the node project and failed typecheck. Assert
opencode identity via shared title classifiers only (OpenCode TUI sets
"OpenCode" and `OC | ${title}`).

* fix(runtime): fill browser cert failure map in mobile snapshot fixtures

Main's #9104 reads browserCertificateFailuresByPageId in buildMobileBrowserTab
but left partial AppState test helpers without the field, breaking PR Checks
merge commits. Default the map in fixtures and use optional chaining so partial
state cannot throw.
This commit is contained in:
Neil 2026-07-16 19:53:18 -07:00 committed by GitHub
parent e01f3f474c
commit 5ee90c8d59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 139 additions and 8 deletions

View File

@ -258,6 +258,20 @@ describe('resolveTabAgentFromSignals', () => {
).toBe('claude')
})
// Why: #8478 — OpenCode native `OC | …` titles must reclaim a stale Claude
// launch identity so the tab icon is OpenCode, not Claude.
it('uses OpenCode native session titles to replace stale Claude launch identity', () => {
expect(
resolveTabAgentFromSignals({
hasObservedAgentSignal: true,
isRemote: false,
title: 'OC | Understand about the plugin',
hookAgent: null,
launchAgent: 'claude'
})
).toBe('opencode')
})
it('does not let an explicit title override launch identity before any activity is observed', () => {
expect(
resolveTabAgentFromSignals({

View File

@ -16,6 +16,7 @@ function makeState(overrides: Partial<AppState> = {}): AppState {
activeBrowserTabIdByWorktree: {},
browserTabsByWorktree: {},
browserPagesByWorkspace: {},
browserCertificateFailuresByPageId: {},
openFiles: [],
editorDrafts: {},
activeTabId: null,

View File

@ -26,6 +26,7 @@ function makeState(overrides: Partial<AppState> = {}): AppState {
activeBrowserTabIdByWorktree: {},
browserTabsByWorktree: {},
browserPagesByWorkspace: {},
browserCertificateFailuresByPageId: {},
openFiles: [],
editorDrafts: {},
activeTabId: null,
@ -60,6 +61,7 @@ function makeSharedOverrides(): Partial<AppState> {
activeBrowserTabIdByWorktree: {},
browserTabsByWorktree: {},
browserPagesByWorkspace: {},
browserCertificateFailuresByPageId: {},
openFiles: [],
editorDrafts: {},
agentStatusByPaneKey: {},

View File

@ -1496,7 +1496,7 @@ function buildMobileBrowserTab(
// back through ?? would resurrect a stale workspace-level error.
loadError: activePage ? activePage.loadError : workspace.loadError,
certificateFailure: activePage
? (state.browserCertificateFailuresByPageId[activePage.id] ?? null)
? (state.browserCertificateFailuresByPageId?.[activePage.id] ?? null)
: null,
color: unifiedTab?.color ?? null,
isPinned: unifiedTab?.isPinned === true,

View File

@ -18,6 +18,7 @@ export {
STRONG_IDLE_KEYWORDS_RE,
STRONG_WORKING_KEYWORDS_RE
} from './agent-title-core'
export { isOpenCodeNativeTitle, isMeaningfulOpenCodeTerminalTitle } from './opencode-terminal-title'
export { getAgentLabel, isClaudeAgent } from './agent-title-identity'
export {
clearWorkingIndicators,

View File

@ -10,6 +10,7 @@ import {
isPiAgentTitle,
titleHasAgentName
} from './agent-title-core'
import { isOpenCodeNativeTitle } from './opencode-terminal-title'
import { getPiCompatibleSyntheticAgentLabel } from './pi-compatible-synthetic-title'
/**
@ -17,7 +18,7 @@ import { getPiCompatibleSyntheticAgentLabel } from './pi-compatible-synthetic-ti
* Used to scope prompt-cache-timer behavior to Claude sessions only.
*/
export function isClaudeAgent(title: string): boolean {
if (!title || isClaudeManagementTitle(title)) {
if (!title || isClaudeManagementTitle(title) || isOpenCodeNativeTitle(title)) {
return false
}
const lower = title.toLowerCase()
@ -46,6 +47,11 @@ export function getAgentLabel(title: string): string | null {
if (isClaudeManagementTitle(title)) {
return null
}
// Why: the native marker owns the whole title; its session text may name or
// include status glyphs from other agents without changing OpenCode identity.
if (isOpenCodeNativeTitle(title)) {
return 'OpenCode'
}
// Why: Claude task titles can mention another CLI; the prefix is the identity
// signal, not arbitrary task text.
if (

View File

@ -1,16 +1,23 @@
import { describe, expect, it } from 'vitest'
import { isMeaningfulOpenCodeTerminalTitle } from './opencode-terminal-title'
import { isMeaningfulOpenCodeTerminalTitle, isOpenCodeNativeTitle } from './opencode-terminal-title'
describe('OpenCode terminal titles', () => {
it('recognizes native session titles', () => {
expect(isMeaningfulOpenCodeTerminalTitle('OC | Native Stable Session')).toBe(true)
expect(isMeaningfulOpenCodeTerminalTitle(' OC|Session ')).toBe(true)
expect(isOpenCodeNativeTitle('OC | Understand about the plugin')).toBe(true)
expect(isOpenCodeNativeTitle('tmux | OC | ses_123')).toBe(true)
})
it('rejects generic or incomplete OpenCode titles', () => {
it('rejects generic, incomplete, embedded, and lookalike titles', () => {
expect(isMeaningfulOpenCodeTerminalTitle('OpenCode')).toBe(false)
expect(isMeaningfulOpenCodeTerminalTitle('OpenCode ready')).toBe(false)
expect(isMeaningfulOpenCodeTerminalTitle('OC |')).toBe(false)
expect(isMeaningfulOpenCodeTerminalTitle(undefined)).toBe(false)
// Why: lowercase is not OpenCode's native marker; avoid "oc |" cwd/task noise.
expect(isOpenCodeNativeTitle('oc | Understand about the plugin')).toBe(false)
// Why: mid-title OC must not steal another agent's braille/task frame.
expect(isOpenCodeNativeTitle('⠋ Fix foo | OC | bar')).toBe(false)
expect(isOpenCodeNativeTitle('my session | OC | task')).toBe(false)
})
})

View File

@ -1,4 +1,14 @@
export function isMeaningfulOpenCodeTerminalTitle(title: string | null | undefined): boolean {
// Why: bare OpenCode labels are status/identity; `OC | …` carries native session identity.
return /^OC\s*\|\s*\S/u.test(title?.trim() ?? '')
// Why: OpenCode abbreviates native OSC session titles as `OC | <task>` (no
// agent-name token). Optional single-token multiplexer prefix covers SSH/tmux
// frames like `tmux | OC | …`. Case-sensitive `OC` avoids ordinary lowercase
// "oc" lookalikes; require non-whitespace after the marker so bare `OC |` is not
// identity. Used for both display-title preservation and tab-agent identity.
const OPENCODE_NATIVE_TITLE_RE = /^(?:[^|\s]+ \| )?OC\s*\|\s*\S/u
export function isOpenCodeNativeTitle(title: string | null | undefined): boolean {
return OPENCODE_NATIVE_TITLE_RE.test(title?.trim() ?? '')
}
export function isMeaningfulOpenCodeTerminalTitle(title: string | null | undefined): boolean {
return isOpenCodeNativeTitle(title)
}

View File

@ -0,0 +1,49 @@
/**
* Issue #8478 OpenCode logo / icon not coming up well (Claude glyph on
* OpenCode tabs).
*
* Root cause (pre-fix): OpenCode's native OSC tab title format is `OC | <task>`.
* Title classifiers only recognized OpenCode when the token "opencode" appeared.
* Native `OC | …` titles fell through, so AgentIcon rendered Claude/"?".
*
* OpenCode source (packages/tui/src/app.tsx) sets titles as:
* - "OpenCode" on home / default session titles
* - `OC | ${title}` for named sessions (title truncated at 40 chars)
* - `OC | ${pluginId}` on plugin routes
*
* Related: #8940 (OpenCode activity frames mislabeled Claude Code separate
* braille-without-token path; not fully solved here).
*
* Re-run:
* pnpm exec vitest run --config config/vitest.config.ts \
* src/shared/repro-8478-opencode-native-title-icon.test.ts
*/
import { describe, expect, it } from 'vitest'
import { getAgentLabel, isClaudeAgent } from './agent-detection'
import {
resolveExplicitTerminalTitleAgentType,
resolveTerminalTitleAgentType
} from './terminal-title-agent-type'
describe('#8478 OpenCode native OC | titles map to OpenCode icon', () => {
it('recognizes OpenCode native "OC | …" title format as opencode identity', () => {
const native = 'OC | Understand about the plugin'
expect(getAgentLabel(native)).toBe('OpenCode')
expect(resolveTerminalTitleAgentType(native)).toBe('opencode')
expect(resolveExplicitTerminalTitleAgentType(native)).toBe('opencode')
expect(isClaudeAgent(native)).toBe(false)
})
// Why: bare "OpenCode" is what the TUI sets on home/default sessions; keep it
// classified so the icon path stays OpenCode without the OC | abbreviation.
it('keeps bare OpenCode home titles and Claude-style frames classified correctly', () => {
expect(getAgentLabel('OpenCode')).toBe('OpenCode')
expect(resolveTerminalTitleAgentType('OpenCode')).toBe('opencode')
expect(getAgentLabel('OpenCode ready')).toBe('OpenCode')
expect(resolveTerminalTitleAgentType('OpenCode ready')).toBe('opencode')
// Same family as #8940: braille/task frames without "opencode" still become Claude
// when they lack the native OC marker — documented, out of scope for this fix.
expect(isClaudeAgent('⠋ implementing the feature')).toBe(true)
expect(getAgentLabel('⠋ implementing the feature')).toBe('Claude Code')
})
})

View File

@ -1,4 +1,6 @@
import { describe, expect, it } from 'vitest'
import { getAgentLabel as getSharedAgentLabel } from './agent-title-identity'
import { isOpenCodeNativeTitle } from './opencode-terminal-title'
import {
isClaudeAgent,
isGrokRotatingWorkingTitle,
@ -51,6 +53,39 @@ describe('resolveExplicitTerminalTitleAgentType', () => {
expect(resolveExplicitTerminalTitleAgentType('* Review Codex behavior')).toBeNull()
})
it('resolves OpenCode native abbreviated session titles before task-text identities', () => {
expect(resolveExplicitTerminalTitleAgentType('OC | Understand about the plugin')).toBe(
'opencode'
)
expect(resolveExplicitTerminalTitleAgentType('OC | Compare Codex and Claude')).toBe('opencode')
// Why: Gemini glyphs inside OpenCode session text must not rebrand the tab.
expect(resolveExplicitTerminalTitleAgentType('OC | ✦ Gemini CLI')).toBe('opencode')
expect(getSharedAgentLabel('OC | Compare Codex and Claude')).toBe('OpenCode')
expect(getSharedAgentLabel('OC | ✦ Gemini CLI')).toBe('OpenCode')
expect(resolveExplicitTerminalTitleAgentType('tmux | OC | ses_123')).toBe('opencode')
expect(resolveExplicitTerminalTitleAgentType('OC|compact-session')).toBe('opencode')
expect(resolveExplicitTerminalTitleAgentType('oc | Understand about the plugin')).toBeNull()
})
it('does not find an OpenCode marker inside another agent task title', () => {
expect(isOpenCodeNativeTitle('⠋ Fix foo | OC | bar')).toBe(false)
expect(resolveExplicitTerminalTitleAgentType('⠋ Fix foo | OC | bar')).toBeNull()
})
// Why: adversarial coverage — native OC must not steal Claude/Codex/Cursor/
// Gemini/Pi identity, and those agents must keep resolving when titled normally.
it('keeps other agents classified correctly alongside OpenCode native titles', () => {
expect(resolveExplicitTerminalTitleAgentType('✳ Claude Code')).toBe('claude')
expect(resolveExplicitTerminalTitleAgentType('⠋ Codex')).toBe('codex')
expect(resolveExplicitTerminalTitleAgentType('✦ Gemini CLI')).toBe('gemini')
expect(resolveExplicitTerminalTitleAgentType('Cursor Agent')).toBe('cursor')
expect(resolveExplicitTerminalTitleAgentType('Pi ready')).toBe('pi')
expect(resolveExplicitTerminalTitleAgentType('OpenCode ready')).toBe('opencode')
expect(resolveTerminalTitleAgentType('OC | ⠋ implementing the feature')).toBe('opencode')
expect(isClaudeAgent('OC | ⠋ implementing the feature')).toBe(false)
expect(isClaudeAgent('OC | Understand about the plugin')).toBe(false)
})
it('still resolves Claude when the title explicitly names Claude', () => {
expect(resolveExplicitTerminalTitleAgentType('. Claude Code compare Opencode')).toBe('claude')
})

View File

@ -5,6 +5,7 @@ import {
titleHasAgentName
} from './agent-name-token-match'
import { isCursorAgentTitle } from './agent-title-core'
import { isOpenCodeNativeTitle } from './opencode-terminal-title'
import {
getPiCompatibleSyntheticAgentLabel,
isLegacyPiCompatibleTitle
@ -80,7 +81,7 @@ export function isPiAgentTitle(title: string): boolean {
* agents have different (or no) caching semantics.
*/
export function isClaudeAgent(title: string): boolean {
if (!title || isClaudeManagementTitle(title)) {
if (!title || isClaudeManagementTitle(title) || isOpenCodeNativeTitle(title)) {
return false
}
const lower = title.toLowerCase()
@ -124,6 +125,11 @@ export function getAgentLabel(title: string): string | null {
if (isClaudeManagementTitle(title)) {
return null
}
// Why: the native marker owns the whole title; its session text may name or
// include status glyphs from other agents without changing OpenCode identity.
if (isOpenCodeNativeTitle(title)) {
return 'OpenCode'
}
// Why: Claude Code title text is often the task title. If that task mentions
// another CLI, the Claude-specific prefix is the identity signal, not the words.
if (