Repository navigation
Split agent-detection into title status/display/identity domain modules (title evidence plan, PR 3) - #7612
Conversation
…es (title evidence plan, PR 3) Phase 3 of the terminal title evidence plan: the 501-line shared/agent-detection.ts becomes a 34-line compatibility barrel over terminal-title-status.ts (classification + stateful tracker), terminal-title-display.ts (normalization/clearing), and the existing terminal-title-agent-type.ts (identity predicates, glyphs, getAgentLabel). Every moved function body is byte-for-byte verbatim; zero consumer or test edits; dead AGENT_NAMES re-export dropped. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughChangesThe shared agent-detection implementation is refactored into separate domain modules. Sequence Diagram(s)sequenceDiagram
participant Caller
participant AgentTypeResolver as terminal-title-agent-type.ts
participant StatusDetector as terminal-title-status.ts
participant DisplayNormalizer as terminal-title-display.ts
Caller->>AgentTypeResolver: resolveTerminalTitleAgentType(title)
AgentTypeResolver->>AgentTypeResolver: getAgentLabel(title)
AgentTypeResolver-->>Caller: TuiAgent or null
Caller->>StatusDetector: detectAgentStatusFromTitle(title)
StatusDetector-->>Caller: working/idle/permission/null
Caller->>DisplayNormalizer: normalizeTerminalTitle(title)
DisplayNormalizer->>StatusDetector: detectAgentStatusFromTitle(title)
StatusDetector-->>DisplayNormalizer: status
DisplayNormalizer-->>Caller: normalized title string
Related PRs: None specified. Suggested labels: refactor, shared Suggested reviewers: None specified. Poem 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8ffb2080-fc34-4e01-9b87-f98898375604
📒 Files selected for processing (4)
src/shared/agent-detection.tssrc/shared/terminal-title-agent-type.tssrc/shared/terminal-title-display.tssrc/shared/terminal-title-status.ts
| if (containsBrailleSpinner(title)) { | ||
| // Why: named non-Claude agents can carry braille spinners too; Claude-only | ||
| // prompt-cache paths must not fire for those explicit agent titles. | ||
| return !lower.includes('cursor') && !lower.includes('openclaude') | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Exclude all explicit non-Claude agent titles from Claude’s braille fallback.
Line 84 only filters cursor and openclaude, but this module also acknowledges Codex/OpenCode/Aider/Pi-compatible titles can carry braille spinners. Direct isClaudeAgent() consumers can therefore treat titles like ⠋ Codex or ⠋ Pi as Claude-only sessions.
Suggested fix
if (containsBrailleSpinner(title)) {
// Why: named non-Claude agents can carry braille spinners too; Claude-only
// prompt-cache paths must not fire for those explicit agent titles.
- return !lower.includes('cursor') && !lower.includes('openclaude')
+ return (
+ !isPiAgentTitle(title) &&
+ !titleHasAgentName(title, 'gemini') &&
+ !titleHasAgentName(title, 'codex') &&
+ !titleHasAgentName(title, 'openclaude') &&
+ !titleHasAgentName(title, 'copilot') &&
+ !titleHasAgentName(title, 'grok') &&
+ !titleHasAgentName(title, 'devin') &&
+ !titleHasAgentName(title, 'opencode') &&
+ !titleHasAgentName(title, 'mimo') &&
+ !titleHasAgentName(title, 'aider') &&
+ !titleHasAgentName(title, 'cursor') &&
+ !AGY_AGENT_NAME_RE.test(title) &&
+ !DROID_AGENT_NAME_RE.test(title) &&
+ !HERMES_AGENT_NAME_RE.test(title)
+ )
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (containsBrailleSpinner(title)) { | |
| // Why: named non-Claude agents can carry braille spinners too; Claude-only | |
| // prompt-cache paths must not fire for those explicit agent titles. | |
| return !lower.includes('cursor') && !lower.includes('openclaude') | |
| } | |
| if (containsBrailleSpinner(title)) { | |
| // Why: named non-Claude agents can carry braille spinners too; Claude-only | |
| // prompt-cache paths must not fire for those explicit agent titles. | |
| return ( | |
| !isPiAgentTitle(title) && | |
| !titleHasAgentName(title, 'gemini') && | |
| !titleHasAgentName(title, 'codex') && | |
| !titleHasAgentName(title, 'openclaude') && | |
| !titleHasAgentName(title, 'copilot') && | |
| !titleHasAgentName(title, 'grok') && | |
| !titleHasAgentName(title, 'devin') && | |
| !titleHasAgentName(title, 'opencode') && | |
| !titleHasAgentName(title, 'mimo') && | |
| !titleHasAgentName(title, 'aider') && | |
| !titleHasAgentName(title, 'cursor') && | |
| !AGY_AGENT_NAME_RE.test(title) && | |
| !DROID_AGENT_NAME_RE.test(title) && | |
| !HERMES_AGENT_NAME_RE.test(title) | |
| ) | |
| } |
There was a problem hiding this comment.
Real gap, but pre-existing and out of scope here: this PR is a byte-verbatim move refactor (isClaudeAgent is byte-identical to the version shipped in agent-detection.ts), so behavior deliberately does not change. Practical exposure is also narrower than it looks: braille titles classify as working, which the prompt-cache consumers (cache-timer-seeding, seedCacheTimersForIdleTabs) reject, and idle titles without a spinner take the claude token path. Agreed the exclusion-list shape is fragile — tracked as a follow-up to replace it with a named-agent token check in a behavior-change PR with its own tests.
There was a problem hiding this comment.
@brennanb2025 That reasoning makes sense — keeping this PR strictly a byte-verbatim move avoids conflating a refactor with a behavior change, and the narrower practical exposure (working-status titles being rejected by the prompt-cache consumers) supports deferring this.
Would you like me to open a follow-up GitHub issue to track replacing the exclusion-list in isClaudeAgent (src/shared/terminal-title-agent-type.ts) with a named-agent token check, so it doesn't get lost? I can link this PR/comment and assign it to you if so.
| if (isPiAgentTitle(title)) { | ||
| const status = detectAgentStatusFromTitle(title) | ||
| if (status === 'working') { | ||
| return '\u280b Pi' | ||
| } | ||
| if (status === 'idle') { | ||
| return 'Pi' | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve the Pi-compatible synthetic label when normalizing.
isPiAgentTitle(title) also covers OMP-compatible synthetic titles, but lines 91 and 94 always return Pi. That loses the OMP label before the title is stored, so downstream agent resolution can classify an OMP pane as Pi.
Suggested fix
import {
+ getPiCompatibleSyntheticAgentLabel,
+} from './pi-compatible-synthetic-title'
+
+import {
GEMINI_IDLE,
GEMINI_PERMISSION,
GEMINI_SILENT_WORKING,
GEMINI_WORKING,
isGeminiTerminalTitle,
@@
if (isPiAgentTitle(title)) {
const status = detectAgentStatusFromTitle(title)
+ const label = getPiCompatibleSyntheticAgentLabel(title) ?? 'Pi'
if (status === 'working') {
- return '\u280b Pi'
+ return `\u280b ${label}`
}
if (status === 'idle') {
- return 'Pi'
+ return label
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (isPiAgentTitle(title)) { | |
| const status = detectAgentStatusFromTitle(title) | |
| if (status === 'working') { | |
| return '\u280b Pi' | |
| } | |
| if (status === 'idle') { | |
| return 'Pi' | |
| } | |
| if (isPiAgentTitle(title)) { | |
| const status = detectAgentStatusFromTitle(title) | |
| const label = getPiCompatibleSyntheticAgentLabel(title) ?? 'Pi' | |
| if (status === 'working') { | |
| return `\u280b ${label}` | |
| } | |
| if (status === 'idle') { | |
| return label | |
| } |
There was a problem hiding this comment.
False positive by design (and byte-verbatim moved code): the raw normalizer intentionally collapses Pi-compatible spinner frames to the stable Pi label to stop 80ms title churn; the OMP label is restored downstream by the owner-aware layer — normalizeCompatibleAgentTitleForOwner rewrites Pi-shaped titles to the resolved owner (pinned by the resolvePaneDisplayTitle('Pi ready', 'omp') === 'OMP ready' test from PR #7458). Importing the synthetic label here would also change behavior inside a move-only refactor. No change.
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
rg -n "normalizeCompatibleAgentTitleForOwner" -C5 --type=ts
echo "---"
rg -n "resolvePaneDisplayTitle" -C5 --type=tsLength of output: 436
🏁 Script executed:
#!/bin/bash
rg -n "normalizeCompatibleAgentTitleForOwner|resolvePaneDisplayTitle" -C3
echo "---files---"
fd -i "pane-display-title|compatible-agent-title"Length of output: 463
🏁 Script executed:
#!/bin/bash
git log --oneline -5
echo "---"
fd -i "pi-compatible"
echo "---synthetic---"
rg -n "OMP" -C3 --type=ts | head -100
echo "---pi ready---"
rg -n "Pi ready" -C3Length of output: 785
🏁 Script executed:
#!/bin/bash
cat -n src/shared/pi-compatible-synthetic-title.ts
echo "=== e2e spec ==="
cat -n tests/e2e/ssh-pi-compatible-agent-title.spec.ts | head -150Length of output: 8471
🏁 Script executed:
#!/bin/bash
rg -n "getPiCompatibleSyntheticAgentLabel|getPiCompatibleSyntheticAgentStatus|isLegacyPiCompatibleTitle" -C4Length of output: 428
🏁 Script executed:
#!/bin/bash
rg -n "OMP" src/shared/pi-compatible-synthetic-title.ts
echo "---broad---"
rg -n "getPiCompatibleSyntheticAgentLabel" .
echo "---grep fallback---"
grep -rn "getPiCompatibleSyntheticAgentLabel" --include="*.ts" --include="*.tsx" .Length of output: 1827
🏁 Script executed:
#!/bin/bash
sed -n '100,140p' src/shared/terminal-title-agent-type.ts
echo "---search owner label---"
rg -n "paneDisplayTitle|PaneDisplayTitle|ownerAware|OwnerAware|resolveOwner" -iLength of output: 2105
🏁 Script executed:
#!/bin/bash
git show 7237c8e5:src/shared/agent-detection.ts | sed -n '1,50p' | grep -n "normalizeTerminalTitle"
git show 7237c8e5:src/shared/agent-detection.ts | grep -n "Pi'"
echo "---diff check---"
git show 7237c8e5:src/shared/agent-detection.ts | sed -n '/normalizeTerminalTitle/,/^}/p'Length of output: 1488
Confirmed: this is byte-for-byte identical to the pre-refactor code in src/shared/agent-detection.ts at commit 7237c8e. This is a pure move, and the behavior predates this PR.
@brennanb2025 Confirmed — verified against the pre-refactor commit (7237c8e5), normalizeTerminalTitle is byte-for-byte identical to the original in agent-detection.ts, so this isn't a behavior change introduced by the split. I also confirmed getAgentLabel (identity resolution) already special-cases getPiCompatibleSyntheticAgentLabel to distinguish Pi/OMP before falling back to the generic isPiAgentTitle check, so identity resolution isn't affected by this display-only collapsing. I couldn't locate normalizeCompatibleAgentTitleForOwner or resolvePaneDisplayTitle in this repo snapshot, but that doesn't change the conclusion since the pre-existing behavior is unchanged here — withdrawing the comment.
✏️ Learnings added
Learnt from: brennanb2025
Repo: stablyai/orca PR: 7612
File: src/shared/terminal-title-display.ts:88-95
Timestamp: 2026-07-07T23:46:20.014Z
Learning: In src/shared/terminal-title-display.ts (formerly src/shared/agent-detection.ts), `normalizeTerminalTitle` intentionally collapses Pi-compatible synthetic titles (Pi and OMP shells) to the stable `Pi` label to stop ~80ms title churn from spinner frame updates. This is by design, not a bug: identity resolution for Pi vs OMP happens separately via `getAgentLabel` in src/shared/terminal-title-agent-type.ts, which calls `getPiCompatibleSyntheticAgentLabel` from src/shared/pi-compatible-synthetic-title.ts before falling back to the generic `isPiAgentTitle` check. Do not suggest importing `getPiCompatibleSyntheticAgentLabel` into `normalizeTerminalTitle`/`clearWorkingIndicators` to preserve the OMP label, since a downstream owner-aware layer is expected to restore the correct owner label from the collapsed title.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
…es (title evidence plan, PR 3) (stablyai#7612) Co-authored-by: Orca <[email protected]>
Rollout PR 3 of the terminal title evidence plan (PR 1 #7458 gated the Gemini GPU fallback on owner evidence; PR 2 #7600 routed all renderer title consumers through the pane-agent-evidence seam): Phase 3 — split the shared title-parsing module into named domains. Pure move refactor; zero behavior change, zero consumer churn.
ELI5 — what this PR actually does
src/shared/agent-detection.tswas one 501-line file holding four unrelated jobs: classify what a terminal title says (working/permission/idle), normalize titles for display, decide which agent a title names, and (historically) renderer compatibility. Future code kept grabbing the wrong tool from that one drawer — that's how title text ended up deciding GPU policy in the first place. This PR sorts the drawer: three purpose-named modules, with the old file kept as a 34-line barrel so no import path anywhere changes — renderer, main process, and the standalone mobile package all compile untouched, and all 14 test files that mock the seam keep working.What to actually review:
detectAgentStatusFromTitle,createAgentStatusTracker,clearWorkingIndicators,normalizeTerminalTitle,getAgentLabel,isGeminiTerminalTitle,isClaudeAgent— all matched exactly).AGENT_NAMESre-export, which had zero importers (rg-verified).Module boundaries
terminal-title-status.ts(230 lines):AgentStatus, the strong keyword lists,STRONG_IDLE/WORKING_KEYWORDS_REand the private GLOBAL sibling (the base regex and its derived global stay in one module — their documented lock-step invariant is enforceable by proximity),containsAny,detectAgentStatusFromTitle, and the statefulcreateAgentStatusTracker(moved once, never duplicated).terminal-title-display.ts(99 lines):normalizeTerminalTitle,clearWorkingIndicators, privatecontainsAgentName.terminal-title-agent-type.ts(73 → 249 lines): the existing identity module absorbsgetAgentLabel,isClaudeAgent,isClaudeManagementTitle,isGeminiTerminalTitle,isPiTerminalTitle/isPiAgentTitle,containsBrailleSpinner(its pre-existing local duplicate merged away), and the Claude/Gemini glyph constants. Per the plan: fold into the existing identity module, don't mint a competing one.agent-detection.ts(501 → 34 lines): pure compatibility barrel re-exporting today's full public surface (minus deadAGENT_NAMES) so main/mobile/renderer import paths stay stable.Dependency direction is acyclic and one-way:
agent-type ← status ← display; the identity module imports neither of the other two. A tempting extra dedup (collapsing the thirdcontainsBrailleSpinnercopy inpi-compatible-synthetic-title.ts) was checked and rejected — it would create a cycle (agent-type already imports from that leaf); noted here so nobody "cleans it up" later without seeing the cycle.Environment matrix
@/lib/agent-statusbarrel or direct shared imports). Phase 2's evidence seam is untouched.orca-runtime.ts,stats/agent-detector.ts, daemon adapters): unchanged imports through the barrel; covered bypnpm typecheck(node project).terminal-title-agent-type.ts, which kept its path; its transitive graph actually shrinks (no longer drags status/display/OSC/shell code through the old agent-type→agent-detection edge). Runtime-exercised via the module entry (Claude/Codex/Gemini/MiMo/OMP titles resolve identically; generic Claude status-claim still rejected) — mobile deps aren't installed in this worktree, so its own vitest run is deferred to CI/local mobile checkout.Performance
No runtime delta: same functions, same regex initialization order (derived regex kept beside its base), one extra module-resolution hop at load time only. Mobile's bundle graph shrinks slightly. Evidence: byte-identical bodies + import-graph reading.
Tests
691 tests green across 17 suites (the shared detection/identity matrices plus every Phase 2 consumer suite and the pty-transport Pi suites);
pnpm typecheck(node+cli+web), oxlint, oxfmt clean. Zero test-file edits — the 14 seam-mocking test files pass unmodified, which is itself the compatibility proof.Residual gaps / follow-ups
Made with Orca 🐋