Skip to content

Split agent-detection into title status/display/identity domain modules (title evidence plan, PR 3) - #7612

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/terminal-title-evidence-phase3
Jul 8, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/terminal-title-evidence-phase3

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

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.ts was 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:

  • Every moved function body is byte-for-byte identical to what it replaced (verified mechanically by extracting each body from HEAD and comparing; the seven load-bearing ones — detectAgentStatusFromTitle, createAgentStatusTracker, clearWorkingIndicators, normalizeTerminalTitle, getAgentLabel, isGeminiTerminalTitle, isClaudeAgent — all matched exactly).
  • The only public-surface change is dropping the barrel's AGENT_NAMES re-export, which had zero importers (rg-verified).
  • The rest is import plumbing: which module imports which.

Module boundaries

  • terminal-title-status.ts (230 lines): AgentStatus, the strong keyword lists, STRONG_IDLE/WORKING_KEYWORDS_RE and 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 stateful createAgentStatusTracker (moved once, never duplicated).
  • terminal-title-display.ts (99 lines): normalizeTerminalTitle, clearWorkingIndicators, private containsAgentName.
  • terminal-title-agent-type.ts (73 → 249 lines): the existing identity module absorbs getAgentLabel, 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 dead AGENT_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 third containsBrailleSpinner copy in pi-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

  • Renderer: all consumers reach the same symbols through unchanged paths (@/lib/agent-status barrel or direct shared imports). Phase 2's evidence seam is untouched.
  • Main process (orca-runtime.ts, stats/agent-detector.ts, daemon adapters): unchanged imports through the barrel; covered by pnpm typecheck (node project).
  • Mobile (standalone package): imports only 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

  • The barrel is transitional: consumers can migrate to direct domain imports opportunistically; the barrel retires when the last importer moves (no deadline — it is a stable 34-line surface).
  • Main-process and mobile predicate call sites remain allowlisted (their migration to evidence-style reads is its own slice, unchanged from PR 2's body).
  • Phase 4 (persist only stable evidence across sleep/restore) is the remaining plan phase.

Made with Orca 🐋

…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]>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The shared agent-detection implementation is refactored into separate domain modules. src/shared/terminal-title-status.ts gains status detection (detectAgentStatusFromTitle) and a status tracker (createAgentStatusTracker). src/shared/terminal-title-agent-type.ts now contains agent classification logic (getAgentLabel, containsBrailleSpinner) plus new resolvers resolveTerminalTitleAgentType and resolveExplicitTerminalTitleAgentType. src/shared/terminal-title-display.ts adds clearWorkingIndicators and normalizeTerminalTitle. src/shared/agent-detection.ts becomes a re-export barrel over these modules, dropping its previous AGENT_NAMES export.

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
Loading

Related PRs: None specified.

Suggested labels: refactor, shared

Suggested reviewers: None specified.

Poem
A rabbit split one burrow wide,
Into status, type, and title-side.
Braille spinners twirl, keywords align,
Claude's quiet titles fall into line.
Barrel re-exports, tidy and neat—
Hop, hop, refactor complete!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, testing, and notes, but omits required screenshots, AI review report, and security audit sections. Add the missing template sections, including screenshots or 'No visual change', the testing checklist, AI review report, security audit, and any platform-specific notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed It clearly summarizes the main refactor: splitting agent-detection into domain modules.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8ffb2080-fc34-4e01-9b87-f98898375604

📥 Commits

Reviewing files that changed from the base of the PR and between 9a3bf12 and f02e5a8.

📒 Files selected for processing (4)
  • src/shared/agent-detection.ts
  • src/shared/terminal-title-agent-type.ts
  • src/shared/terminal-title-display.ts
  • src/shared/terminal-title-status.ts

Comment on lines +81 to +85
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')
}

@coderabbitai coderabbitai Bot Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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)
)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Comment on lines +88 to +95
if (isPiAgentTitle(title)) {
const status = detectAgentStatusFromTitle(title)
if (status === 'working') {
return '\u280b Pi'
}
if (status === 'idle') {
return 'Pi'
}

@coderabbitai coderabbitai Bot Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n "normalizeCompatibleAgentTitleForOwner" -C5 --type=ts
echo "---"
rg -n "resolvePaneDisplayTitle" -C5 --type=ts

Length 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" -C3

Length 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 -150

Length of output: 8471


🏁 Script executed:

#!/bin/bash
rg -n "getPiCompatibleSyntheticAgentLabel|getPiCompatibleSyntheticAgentStatus|isLegacyPiCompatibleTitle" -C4

Length 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" -i

Length 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.

@brennanb2025
brennanb2025 merged commit f311539 into main Jul 8, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant