From f71c86edbaea4fc52a6997bb18aef2f12876dd50 Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:36:12 +0000 Subject: [PATCH] fix(jcode): keep the turn tail out of title-only readers Title-only readers (completion tracking) saw a turn from Jcode's identity title and then idle when Jcode switched to a conversation title naming another agent. Read the tail only through the pane-scoped reader, check it before generic title status in the sidebar row, and stop treating a bare jcode/ as Jcode. --- .../worktree-title-derived-agent-rows.ts | 3 +- .../worktree-title-derived-jcode-rows.test.ts | 46 +++++++++++++++++++ .../agent-status/title/agent-title-status.ts | 8 ++-- .../title/providers/jcode-terminal-title.ts | 23 ++++------ src/shared/jcode-agent-identity.test.ts | 26 +++++------ 5 files changed, 74 insertions(+), 32 deletions(-) create mode 100644 src/renderer/src/components/sidebar/workspace-card/activity/worktree-title-derived-jcode-rows.test.ts diff --git a/src/renderer/src/components/sidebar/workspace-card/activity/worktree-title-derived-agent-rows.ts b/src/renderer/src/components/sidebar/workspace-card/activity/worktree-title-derived-agent-rows.ts index 21572a2c9d2..97db8a57b2a 100644 --- a/src/renderer/src/components/sidebar/workspace-card/activity/worktree-title-derived-agent-rows.ts +++ b/src/renderer/src/components/sidebar/workspace-card/activity/worktree-title-derived-agent-rows.ts @@ -183,7 +183,8 @@ function buildTitleDerivedAgentRow(args: { return null } // Why: the title sets activity only; a plain title on a process-identified pane is idle. - const status = titleStatus ?? jcodePaneTitleStatus(title, agentType) ?? 'idle' + // Jcode's own tail outranks agent names its conversation title happens to mention. + const status = jcodePaneTitleStatus(title, agentType) ?? titleStatus ?? 'idle' const rowLabel = agentType === titleAgentType && label && diff --git a/src/renderer/src/components/sidebar/workspace-card/activity/worktree-title-derived-jcode-rows.test.ts b/src/renderer/src/components/sidebar/workspace-card/activity/worktree-title-derived-jcode-rows.test.ts new file mode 100644 index 00000000000..854f0eac2c0 --- /dev/null +++ b/src/renderer/src/components/sidebar/workspace-card/activity/worktree-title-derived-jcode-rows.test.ts @@ -0,0 +1,46 @@ +import { describe, expect, it } from 'vitest' +import type { TerminalTab } from '../../../../../../shared/workspace-layout/terminal-tab-types' +import { makePaneKey } from '../../../../../../shared/workspace-layout/stable-pane-id' +import { buildTitleDerivedAgentRows } from './worktree-title-derived-agent-rows' + +const LEAF_ID = '11111111-1111-4111-8111-111111111111' +const PANE_KEY = makePaneKey('tab-1', LEAF_ID) + +function jcodeRow(title: string) { + const tab: TerminalTab = { + id: 'tab-1', + ptyId: 'pty-1', + worktreeId: 'wt-1', + title, + customTitle: null, + color: null, + sortOrder: 0, + createdAt: 0 + } + const rows = buildTitleDerivedAgentRows({ + tabs: [tab], + ptyIdsByTabId: { 'tab-1': ['pty-1'] }, + terminalLayoutsByTabId: { + 'tab-1': { root: null, activeLeafId: LEAF_ID, expandedLeafId: null } + }, + // Linux reads jcode-linux-x86_64.bin; the foreground tracker publishes it as jcode. + paneForegroundAgentByPaneKey: { + [PANE_KEY]: { agent: 'jcode', agentEvidence: 'process-read', shellForeground: false } + }, + seenPaneKeys: new Set(), + now: 0 + }) + return rows.map((row) => ({ agentType: row.agentType, state: row.state })) +} + +describe('title-derived Jcode rows', () => { + it('keeps the row through Jcode titles and follows its turn tail', () => { + expect(jcodeRow('🐩 jcode/marsh Poodle')).toEqual([{ agentType: 'jcode', state: 'idle' }]) + expect(jcodeRow('🦊 Fix codex hooks · +3 -1 · work ~12s')).toEqual([ + { agentType: 'jcode', state: 'working' } + ]) + expect(jcodeRow('🦊 Fix codex hooks · last ~2m05s')).toEqual([ + { agentType: 'jcode', state: 'idle' } + ]) + }) +}) diff --git a/src/shared/agent-status/title/agent-title-status.ts b/src/shared/agent-status/title/agent-title-status.ts index 3e6c362b1fd..16a93a7c99e 100644 --- a/src/shared/agent-status/title/agent-title-status.ts +++ b/src/shared/agent-status/title/agent-title-status.ts @@ -1,6 +1,6 @@ import { getDeepSeekBuildTitleStatus } from './providers/dsb-terminal-title' import { qoderTitleStatus } from './providers/qoder-terminal-title' -import { jcodeIdentityTitleStatus } from './providers/jcode-terminal-title' +import { isJcodeIdentityTerminalTitle } from './providers/jcode-terminal-title' import { cursorTitleStatus } from './providers/cursor-terminal-title' import { AGY_AGENT_NAME_RE, @@ -280,9 +280,9 @@ function computeAgentStatusFromTitle(title: string): AgentStatus | null { if (title.startsWith(`${CLAUDE_IDLE} `) || title === CLAUDE_IDLE) { return 'idle' } - const jcodeStatus = jcodeIdentityTitleStatus(title) - if (jcodeStatus) { - return jcodeStatus + // Activity comes from jcodePaneTitleStatus; the identity alone says Jcode is at rest. + if (isJcodeIdentityTerminalTitle(title)) { + return 'idle' } // Read π ! as blocked before generic idle or OMP user waits disappear. const piCompatibleSeparatorStatus = getPiCompatibleTitleSeparatorStatus(title) diff --git a/src/shared/agent-status/title/providers/jcode-terminal-title.ts b/src/shared/agent-status/title/providers/jcode-terminal-title.ts index 23bda185bb5..f3094197222 100644 --- a/src/shared/agent-status/title/providers/jcode-terminal-title.ts +++ b/src/shared/agent-status/title/providers/jcode-terminal-title.ts @@ -11,8 +11,8 @@ export function stripJcodeTitleStatus(title: string): string { return title.replace(JCODE_TITLE_STATUS_RE, '').trim() } -// jcode, jcode Puppy and jcode/marsh Puppy (server name) are identity; user work labels contain more. -const JCODE_IDENTITY_TITLE_RE = /^jcode(?:\/[\w-]+)?(?:\s+[^\s·]+)?$/iu +// jcode, jcode Puppy and jcode/marsh Puppy (server name) are identity; a bare jcode/ is a shell path. +const JCODE_IDENTITY_TITLE_RE = /^jcode(?:(?:\/[\w-]+)?\s+[^\s·]+)?$/iu /** True when a jcode title says only which jcode session this is, not what it is doing. */ export function isJcodeIdentityTerminalTitle(title: string | null | undefined): boolean { @@ -28,20 +28,15 @@ export function isJcodeIdentityTerminalTitle(title: string | null | undefined): // title_with_metrics: `· work ~2m05s` (or `· working`) mid-turn, `· last ~2m05s` after it. const JCODE_ACTIVITY_TAIL_RE = /\s·\s(?:(work|last)\s~(?:\d+h\d{2}m|\d+m\d{2}s|\d+s)|working)$/u -function jcodeTitleActivity(title: string): 'working' | 'idle' | null { - const tail = JCODE_ACTIVITY_TAIL_RE.exec(title) - return tail ? (tail[1] === 'last' ? 'idle' : 'working') : null -} - -/** A jcode identity title carries its own activity; without a tail it is at rest. */ -export function jcodeIdentityTitleStatus(title: string): 'working' | 'idle' | null { - return isJcodeIdentityTerminalTitle(title) ? (jcodeTitleActivity(title) ?? 'idle') : null -} - -/** Conversation and SSH titles carry only the tail, which is too generic to identify Jcode, so it counts only in a Jcode pane. */ +/** The tail is too generic to identify Jcode, and title-only readers must not see a turn that a + * later conversation title drops, so it counts only in a pane already known to run Jcode. */ export function jcodePaneTitleStatus( title: string, agent: string | null | undefined ): 'working' | 'idle' | null { - return agent === 'jcode' ? jcodeTitleActivity(title) : null + if (agent !== 'jcode') { + return null + } + const tail = JCODE_ACTIVITY_TAIL_RE.exec(title) + return tail ? (tail[1] === 'last' ? 'idle' : 'working') : null } diff --git a/src/shared/jcode-agent-identity.test.ts b/src/shared/jcode-agent-identity.test.ts index e5bf2aa0053..6352d1c9348 100644 --- a/src/shared/jcode-agent-identity.test.ts +++ b/src/shared/jcode-agent-identity.test.ts @@ -19,24 +19,24 @@ describe('Jcode pane identity and title status', () => { expect(recognizeAgentProcessFromCommandLine('jcode-helper')).toBeNull() }) - it('reads working and idle from the tail of its identity title', () => { - expect(detectAgentStatusFromTitle('🌐 jcode/fountain Duck · work ~2s')).toBe('working') - expect(detectAgentStatusFromTitle('🐩 jcode Poodle · +3 -1 · working')).toBe('working') - expect(detectAgentStatusFromTitle('🌐 jcode/fountain Duck · last ~1m05s')).toBe('idle') - expect(detectAgentStatusFromTitle('🐩 jcode/marsh Poodle')).toBe('idle') - }) - - it('reads the tail of conversation and SSH titles only in a Jcode pane', () => { - const conversation = '🦊 Improve session tabs · +12 -3 · work ~2m05s' - expect(detectAgentStatusFromTitle(conversation)).toBeNull() - expect(jcodePaneTitleStatus(conversation, 'jcode')).toBe('working') - expect(jcodePaneTitleStatus(conversation, 'claude')).toBeNull() + it('reads the turn tail only in a Jcode pane', () => { + for (const title of [ + '🌐 jcode/fountain Duck · work ~2s', + '🦊 Fix codex hooks · +12 -3 · work ~2m05s', + '🐩 jcode Poodle · working' + ]) { + expect(jcodePaneTitleStatus(title, 'jcode')).toBe('working') + expect(jcodePaneTitleStatus(title, 'claude')).toBeNull() + } expect(jcodePaneTitleStatus('jcode SSH devbox fox · last ~1h05m', 'jcode')).toBe('idle') + // Title-only readers see the identity at rest, never a turn a later title would drop. + expect(detectAgentStatusFromTitle('🌐 jcode/fountain Duck · work ~2s')).toBe('idle') + expect(detectAgentStatusFromTitle('🦊 Improve session tabs · work ~2m05s')).toBeNull() }) it('identifies Jcode from its server-qualified session title', () => { expect(resolveExplicitTerminalTitleAgentType('🌐 jcode/fountain Duck · work ~2s')).toBe('jcode') expect(resolveExplicitTerminalTitleAgentType('✳ Jcode hooks')).not.toBe('jcode') - expect(resolveExplicitTerminalTitleAgentType('jcode/scripts/build.sh')).not.toBe('jcode') + expect(resolveExplicitTerminalTitleAgentType('jcode/scripts')).not.toBe('jcode') }) })