Fix Grok and Pi terminal title normalization and status detection (#7880)

* fix(mobile): normalize Grok rotating OSC titles at the main observation boundary

Desktop already collapses Grok Build's rotating working frames via the
renderer's normalizeTerminalTitle, but the main process stored raw OSC
titles, so mobile session tabs (fed from pty.lastOscTitle) still saw a
distinct title every spinner frame and re-touched snapshots each time.

Apply normalizeTerminalTitle once where main records an observed OSC
title, before the prevTitle comparison that gates session-tab and
mobile-snapshot touches, and normalize hydration-seeded titles the same
way so the first live frame after a seed compares equal. Agent status
stays detected from the raw title, mirroring the renderer tracker.

Covers remoted/SSH PTYs too since they surface through the same main
observation path.

Co-authored-by: Orca <help@stably.ai>

* Fix Grok and Pi terminal title normalization and status detection

- Require a strict "spinner - phrase - grok" pattern for Grok working
  titles to prevent false positives on other agent tasks ending in
  "- grok" (such as Claude or Codex).
- Treat collapsed "Pi" and "OMP" synthetic titles as idle by default
  to prevent them from reverting to neutral status after normalization.
- Prevent duplicate mobile session tab updates during Grok status
  frame rotations by ensuring they normalize to a stable title.

---------

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Jinjing
2026-07-08 21:22:06 -07:00
committed by GitHub
co-authored by Orca
parent 7f3e851696
commit 6b4831d5ef
7 changed files with 174 additions and 25 deletions
+14 -1
View File
@@ -5,7 +5,8 @@ import {
extractAllOscTitles,
extractLastOscTitle,
getAgentLabel,
MAX_OSC_TITLE_CHARS
MAX_OSC_TITLE_CHARS,
normalizeTerminalTitle
} from './agent-detection'
import {
hasCompatibleAgentTitleIdentity,
@@ -88,15 +89,27 @@ describe('Pi-compatible title detection', () => {
it.each([
['\u280b OMP', 'OMP', 'working'],
['OMP ready', 'OMP', 'idle'],
['OMP', 'OMP', 'idle'],
['OMP - action required', 'OMP', 'permission'],
['\u280b Pi', 'Pi', 'working'],
['Pi ready', 'Pi', 'idle'],
// Why: normalizeTerminalTitle collapses idle π frames to bare "Pi"; re-detection
// from stored lastOscTitle must still classify idle, not neutral.
['Pi', 'Pi', 'idle'],
['Pi - action required', 'Pi', 'permission']
] as const)('classifies synthesized %s', (title, expectedLabel, expectedStatus) => {
expect(getAgentLabel(title)).toBe(expectedLabel)
expect(detectAgentStatusFromTitle(title)).toBe(expectedStatus)
})
it('re-detects status after display-title normalization for Pi idle frames', () => {
expect(normalizeTerminalTitle('π - my-project')).toBe('Pi')
expect(detectAgentStatusFromTitle(normalizeTerminalTitle('π - my-project'))).toBe('idle')
expect(detectAgentStatusFromTitle(normalizeTerminalTitle('\u280b π - my-project'))).toBe(
'working'
)
})
it.each([
['\u280b Pi', 'omp', '\u280b OMP'],
['Pi ready', 'omp', 'OMP ready'],
+5 -5
View File
@@ -3,7 +3,6 @@ export type PiCompatibleSyntheticAgentStatus = 'working' | 'permission' | 'idle'
const PI_COMPATIBLE_SYNTHETIC_TITLE_RE =
/^\s*(?:[\u2800-\u28ff]\s+)?(pi|omp)(?:\s+-\s+action required|\s+(?:ready|idle|done))?\s*$/i
const PI_COMPATIBLE_IDLE_RE = /(?<![\w./\\-])(?:ready|idle|done)(?![\w-])/i
// Why: legacy Pi/OMP-compatible shells can emit the delimiter before cwd text exists.
const LEGACY_PI_COMPATIBLE_TITLE_RE = /^\s*(?:[\u2800-\u28ff]\s+)?π(?:\s*[-:]|\s)\s*.*$/u
@@ -44,10 +43,11 @@ export function getPiCompatibleSyntheticAgentStatus(
) {
return 'permission'
}
if (PI_COMPATIBLE_IDLE_RE.test(title)) {
return 'idle'
}
return null
// Why: bare "Pi"/"OMP" and ready/idle/done labels are all idle. Bare labels
// come from normalizeTerminalTitle collapsing π frames; they must re-detect
// as idle or stored lastOscTitle values classify as neutral after main-side
// normalization.
return 'idle'
}
export function isLegacyPiCompatibleTitle(title: string): boolean {
+5 -1
View File
@@ -21,10 +21,14 @@ describe('isGrokRotatingWorkingTitle', () => {
expect(isGrokRotatingWorkingTitle('⠋ ~/grok-scratch/ready')).toBe(false) // path fragment, not a trailing token
expect(isGrokRotatingWorkingTitle('⠋ grokking the plan')).toBe(false) // "grok" not a whole trailing token
expect(isGrokRotatingWorkingTitle('⠋ Codex')).toBe(false)
// Task text ending in "grok" is not the Grok Build identity suffix " - grok".
// Task text ending in "grok" is not the Grok frame shape "spinner - phrase - grok".
expect(isGrokRotatingWorkingTitle('⠋ wire up grok')).toBe(false)
expect(isGrokRotatingWorkingTitle('⠋ Codex is thinking about grok')).toBe(false)
expect(isGrokRotatingWorkingTitle('⠋ support for Grok')).toBe(false)
// Why: Claude/Codex braille + task can end with " - grok" without the
// post-spinner delimiter that marks a real Grok Build frame.
expect(isGrokRotatingWorkingTitle('⠋ fix the flaky suite - grok')).toBe(false)
expect(isGrokRotatingWorkingTitle('⠋ review grok integration - claude')).toBe(false)
})
})
+10 -10
View File
@@ -51,22 +51,22 @@ export function isPiTerminalTitle(title: string): boolean {
return isLegacyPiCompatibleTitle(title) && !containsBrailleSpinner(title)
}
// Why: Grok Build's working OSC titles interpolate a rotating status/tool phrase
// between the spinner and its name — "⠋ - Waiting for response… - grok",
// "⠴ - Thinking - grok", "⠦ - Sleep 2s… - grok" — so every frame is a distinct
// title that flips the tab and sidebar labels. Require the identity suffix
// " - grok" (not arbitrary task text ending in "grok") so Claude/Codex titles
// like "⠋ wire up grok" stay intact. Spinner marks working; no-spinner session
// titles ("Fix the auth bug - grok") pass through. The bare "spinner + grok"
// branch keeps our own collapsed label idempotent under re-normalization.
const GROK_FRAME_IDENTITY_SUFFIX_RE = / - grok\s*$/i
// Why: Grok Build's working OSC titles use a fixed frame shape —
// "spinner - <rotating phrase> - grok" — so every frame is a distinct title
// that flips tab and sidebar labels. Require BOTH the post-spinner " - "
// delimiter and the trailing identity " - grok" so Claude/Codex task text
// like "⠋ fix the flaky suite - grok" or "⠋ wire up grok" is not mislabeled.
// Spinner marks working; no-spinner session titles ("Fix the auth bug - grok")
// pass through. The bare "spinner + grok" branch keeps our own collapsed
// label idempotent under re-normalization.
const GROK_ROTATING_FRAME_RE = /^[\u2800-\u28FF]+\s+-\s+[\s\S]+?\s-\s+grok\s*$/i
const GROK_COLLAPSED_WORKING_TITLE_RE = /^[\u2800-\u28FF]+\s+grok\s*$/i
export function isGrokRotatingWorkingTitle(title: string): boolean {
if (!containsBrailleSpinner(title)) {
return false
}
return GROK_FRAME_IDENTITY_SUFFIX_RE.test(title) || GROK_COLLAPSED_WORKING_TITLE_RE.test(title)
return GROK_ROTATING_FRAME_RE.test(title) || GROK_COLLAPSED_WORKING_TITLE_RE.test(title)
}
export function isPiAgentTitle(title: string): boolean {