mirror of
https://github.com/stablyai/orca.git
synced 2026-10-22 08:03:37 +00:00
* fix(sidebar): show Cursor rows and stop a stray "claude" title hijacking OpenCode Two defects in the same title-resolution path. **#10258** — Cursor's only native OSC title is the literal `cursor agent`, which both title trackers dropped unconditionally. A hookless Cursor pane therefore had neither a status entry nor any title carrying Cursor identity, so the worktree card showed nothing at all. **#8940** — two owner-blind paths let an incidental `claude` token anywhere in an OpenCode session or task title outrank the pane's known owner, so the tab icon and sidebar row flipped to Claude Code. #10258: let the literal through exactly once as identity, so a restored or mobile tab keeps its Cursor row instead of vanishing. #8940: require an *identity frame* — after stripping status decoration the title must PRESENT Claude, not merely mention it — before a Claude title may reclaim a pane from its prior identity, and make the sidebar row builder owner-aware. > These two are in one PR because they share the `ownerAgentType` plumbing through `buildTitleDerivedAgentRow` — split apart, neither half compiles on its own. Fixes #10258 Fixes #8940 Co-authored-by: Orca <help@stably.ai> * test(e2e): add recordable proof for sidebar-agent-row-identity Fails on origin/main, passes on this branch. Test: sidebar keeps a Cursor pane visible and an OpenCode pane out of Claude Code hands Co-authored-by: Orca <help@stably.ai> * fix(terminal): preserve restored Cursor identity * test(terminal): cover restored Cursor redraw suppression * refactor(terminal): tighten Cursor identity handling and Claude frame matching Review follow-ups on the title-resolution path: - pty-transport dropped a native Cursor literal that main emits whenever a non-Cursor title preceded it, re-introducing the #10258 blank row in the renderer path. The pre-filter now projects the predecessor the drain will actually see, and defers to the drain gate while facts are still queued. - applyTrackedPtyTitle threaded the cursor flag through 12 sites, including ptyRecordChanged bookkeeping the sole caller ignores. Force the status null once, and the activity-gated effects fall out unchanged. - isClaudeIdentityFrameTitle missed a multiplexer-wrapped Claude title ("zsh | Claude Code"), costing a genuine Claude pane its identity. Reuse the ' | ' segment split that agent-title-owner already had inline. - Keep title normalization on launchAgent: it only rewrites within an identity group (OMP wraps Pi), so a split does not make it wrong, and the hook-row path normalizes the same way. - Drop the tab.ptyId tracker fallback, which read a pty that the pane identity check had just rejected. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
140 lines
4.9 KiB
TypeScript
140 lines
4.9 KiB
TypeScript
import {
|
|
AGY_AGENT_NAME_RE,
|
|
DROID_AGENT_NAME_RE,
|
|
HERMES_AGENT_NAME_RE,
|
|
titleHasAgentName,
|
|
titleHasAnyLegacyAgentName
|
|
} from './agent-name-token-match'
|
|
import { isLegacyPiCompatibleTitle } from './pi-compatible-synthetic-title'
|
|
|
|
export { AGY_AGENT_NAME_RE, DROID_AGENT_NAME_RE, HERMES_AGENT_NAME_RE, titleHasAgentName }
|
|
|
|
export type AgentStatus = 'working' | 'permission' | 'idle'
|
|
|
|
export const CLAUDE_IDLE = '\u2733' // ✳
|
|
const CLAUDE_COMMAND_RE = String.raw`(?:.*[\\/])?claude(?:\.(?:exe|cmd|bat|ps1))?`
|
|
export const CLAUDE_MANAGEMENT_TITLE_RE = new RegExp(
|
|
String.raw`^\s*(?:"${CLAUDE_COMMAND_RE}"|'${CLAUDE_COMMAND_RE}'|${CLAUDE_COMMAND_RE})\s+agents\s*$`,
|
|
'i'
|
|
)
|
|
|
|
export const GEMINI_WORKING = '\u2726' // ✦
|
|
export const GEMINI_SILENT_WORKING = '\u23f2' // ⏲
|
|
export const GEMINI_IDLE = '\u25c7' // ◇
|
|
export const GEMINI_PERMISSION = '\u270b' // ✋
|
|
|
|
const STRONG_IDLE_KEYWORDS = ['ready', 'idle', 'done'] as const
|
|
const STRONG_WORKING_KEYWORDS = ['working', 'thinking', 'running'] as const
|
|
|
|
// Why: plain `\b` matches inside hyphenated tokens and cwd paths such as
|
|
// "~/codex/ready"; the left side also blocks path separators for Windows/Unix.
|
|
export const STRONG_IDLE_KEYWORDS_RE = new RegExp(
|
|
`(?<![\\w./\\\\-])(${STRONG_IDLE_KEYWORDS.join('|')})(?![\\w\\-])`,
|
|
'i'
|
|
)
|
|
|
|
// Why: mirrors the idle matcher so titles like "reworking" or
|
|
// "is-thinking-cap" do not drive false active-agent UI.
|
|
export const STRONG_WORKING_KEYWORDS_RE = new RegExp(
|
|
`(?<![\\w./\\\\-])(${STRONG_WORKING_KEYWORDS.join('|')})(?![\\w\\-])`,
|
|
'i'
|
|
)
|
|
|
|
export const STRONG_WORKING_KEYWORDS_RE_GLOBAL = new RegExp(STRONG_WORKING_KEYWORDS_RE.source, 'gi')
|
|
|
|
export const CURSOR_NATIVE_TITLE_LOWER = 'cursor agent'
|
|
|
|
// eslint-disable-next-line no-control-regex -- intentional unicode range
|
|
export const BRAILLE_SPINNER_RE = /[\u2800-\u28ff]/g
|
|
|
|
export function isGeminiTerminalTitle(title: string): boolean {
|
|
// Why: Gemini OSC glyphs are stronger evidence than any cwd/session text.
|
|
if (
|
|
title.includes(GEMINI_PERMISSION) ||
|
|
title.includes(GEMINI_WORKING) ||
|
|
title.includes(GEMINI_SILENT_WORKING) ||
|
|
title.includes(GEMINI_IDLE)
|
|
) {
|
|
return true
|
|
}
|
|
// Why: Pi/OMP titles include cwd/session text; substring matching made
|
|
// paths like "gemini-project" masquerade as Gemini CLI.
|
|
if (isPiAgentTitle(title)) {
|
|
return false
|
|
}
|
|
return titleHasAgentName(title, 'gemini')
|
|
}
|
|
|
|
export function isPiTerminalTitle(title: string): boolean {
|
|
return isLegacyPiCompatibleTitle(title) && !containsBrailleSpinner(title)
|
|
}
|
|
|
|
export function isPiAgentTitle(title: string): boolean {
|
|
return isLegacyPiCompatibleTitle(title)
|
|
}
|
|
|
|
export function containsBrailleSpinner(title: string): boolean {
|
|
for (const char of title) {
|
|
const codePoint = char.codePointAt(0)
|
|
if (codePoint !== undefined && codePoint >= 0x2800 && codePoint <= 0x28ff) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
export function containsLegacyAgentName(title: string): boolean {
|
|
return titleHasAnyLegacyAgentName(title)
|
|
}
|
|
|
|
export function containsAgentName(title: string): boolean {
|
|
return (
|
|
containsLegacyAgentName(title) ||
|
|
AGY_AGENT_NAME_RE.test(title) ||
|
|
DROID_AGENT_NAME_RE.test(title) ||
|
|
HERMES_AGENT_NAME_RE.test(title)
|
|
)
|
|
}
|
|
|
|
export function containsAny(title: string, words: readonly string[]): boolean {
|
|
const lower = title.toLowerCase()
|
|
return words.some((word) => lower.includes(word))
|
|
}
|
|
|
|
export function isClaudeManagementTitle(title: string): boolean {
|
|
return CLAUDE_MANAGEMENT_TITLE_RE.test(title)
|
|
}
|
|
|
|
export function isCursorNativeAgentTitle(title: string): boolean {
|
|
return title.trim().toLowerCase() === CURSOR_NATIVE_TITLE_LOWER
|
|
}
|
|
|
|
// Why: `cursor` is also an ordinary editor noun that other agents type into their own
|
|
// task-summary titles, so a name token is not identity. Cursor's identifying titles are
|
|
// a closed set (the native literal plus the labels Orca synthesizes from Cursor hooks),
|
|
// so match that vocabulary instead.
|
|
export function isCursorAgentTitle(title: string | null | undefined): boolean {
|
|
if (typeof title !== 'string') {
|
|
return false
|
|
}
|
|
const trimmed = title.trim()
|
|
const lower = trimmed.toLowerCase()
|
|
if (
|
|
lower === CURSOR_NATIVE_TITLE_LOWER ||
|
|
lower === 'cursor ready' ||
|
|
lower === 'cursor - action required'
|
|
) {
|
|
return true
|
|
}
|
|
// Why: display labels can mention Cursor in another agent's task text. Only
|
|
// treat the controlled synthetic Cursor spinner title as Cursor identity.
|
|
return /^[\u2800-\u28ff] Cursor Agent$/u.test(trimmed)
|
|
}
|
|
|
|
// Why: cursor-agent re-emits its bare native title every redraw, which would stomp
|
|
// Orca's hook-synthesized spinner state, but only once a Cursor-owned title already
|
|
// owns the pane. A hookless Cursor pane still needs the literal once, for identity.
|
|
export function shouldSuppressCursorNativeTitle(lastEmittedTitle: string | null): boolean {
|
|
return lastEmittedTitle !== null && isCursorAgentTitle(lastEmittedTitle)
|
|
}
|