Track terminal titles in headless snapshots (#4780)

This commit is contained in:
Neil
2026-06-07 04:47:10 -07:00
committed by GitHub
parent e5f09ceacc
commit 733f77d522
6 changed files with 46 additions and 1 deletions
+18
View File
@@ -111,6 +111,24 @@ describe('HeadlessEmulator', () => {
})
})
describe('OSC title tracking', () => {
it('captures the latest OSC window title in snapshots', async () => {
emulator = new HeadlessEmulator({ cols: 80, rows: 24 })
await emulator.write('\x1b]0;Codex working\x07hello')
expect(emulator.getSnapshot().lastTitle).toBe('Codex working')
})
it('uses the last OSC title when a chunk contains multiple title updates', async () => {
emulator = new HeadlessEmulator({ cols: 80, rows: 24 })
await emulator.write('\x1b]0;Codex working\x07output\x1b]2;Codex idle\x1b\\')
expect(emulator.getSnapshot().lastTitle).toBe('Codex idle')
})
})
describe('resize', () => {
it('updates dimensions', () => {
emulator = new HeadlessEmulator({ cols: 80, rows: 24 })
+8 -1
View File
@@ -1,6 +1,7 @@
import './xterm-env-polyfill'
import { Terminal } from '@xterm/headless'
import { SerializeAddon } from '@xterm/addon-serialize'
import { extractLastOscTitle } from '../../shared/agent-detection'
import type { TerminalSnapshot, TerminalModes } from './types'
export type HeadlessEmulatorOptions = {
@@ -51,6 +52,7 @@ export class HeadlessEmulator {
private terminal: Terminal
private serializer: SerializeAddon
private cwd: string | null = null
private lastTitle: string | null = null
private privateModeScanTail = ''
private mouseTrackingMode: MouseTrackingMode = 'none'
private sgrMouseMode = false
@@ -87,6 +89,10 @@ export class HeadlessEmulator {
}
this.scanOsc7(data)
const lastTitle = extractLastOscTitle(data)
if (lastTitle !== null) {
this.lastTitle = lastTitle
}
return new Promise<void>((resolve) => {
this.terminal.write(data, () => {
// Why: snapshots combine serialized xterm state with mirrored mouse
@@ -118,7 +124,8 @@ export class HeadlessEmulator {
modes,
cols: this.terminal.cols,
rows: this.terminal.rows,
scrollbackLines: this.terminal.buffer.normal.length - this.terminal.rows
scrollbackLines: this.terminal.buffer.normal.length - this.terminal.rows,
lastTitle: this.lastTitle ?? undefined
}
}
+1
View File
@@ -23,6 +23,7 @@ export type TerminalSnapshot = {
cols: number
rows: number
scrollbackLines: number
lastTitle?: string
}
export type TerminalModes = {
+1
View File
@@ -1766,6 +1766,7 @@ export function registerPtyHandlers(
data: string
cols: number
rows: number
lastTitle?: string
seq?: number
source?: 'headless' | 'renderer'
} | null> => {
+13
View File
@@ -3434,6 +3434,19 @@ describe('OrcaRuntimeService', () => {
})
})
it('returns OSC titles from headless main terminal snapshots', async () => {
const runtime = createRuntime()
syncSinglePty(runtime, 'pty-1')
runtime.onPtyData('pty-1', '\x1b]0;Codex working\x07hello\n', 100)
const snapshot = await runtime.serializeMainTerminalBuffer('pty-1', { scrollbackRows: 1000 })
expect(snapshot).toMatchObject({
source: 'headless',
lastTitle: 'Codex working'
})
})
it('emits explicit OSC 9999 agent status from runtime PTY data', () => {
const statuses: RuntimeTerminalAgentStatusEvent[] = []
const runtime = new OrcaRuntimeService(store, undefined, {
+5
View File
@@ -3291,6 +3291,7 @@ export class OrcaRuntimeService {
data: string
cols: number
rows: number
lastTitle?: string
seq?: number
source?: 'headless' | 'renderer'
} | null> {
@@ -3304,6 +3305,7 @@ export class OrcaRuntimeService {
data: string
cols: number
rows: number
lastTitle?: string
seq?: number
source?: 'headless' | 'renderer'
} | null> {
@@ -3505,6 +3507,7 @@ export class OrcaRuntimeService {
data: string
cols: number
rows: number
lastTitle?: string
seq?: number
source?: 'headless' | 'renderer'
} | null> {
@@ -3546,6 +3549,7 @@ export class OrcaRuntimeService {
data: string
cols: number
rows: number
lastTitle?: string
seq?: number
source?: 'headless'
} | null> {
@@ -3570,6 +3574,7 @@ export class OrcaRuntimeService {
data,
cols: snapshot.cols,
rows: snapshot.rows,
lastTitle: snapshot.lastTitle,
seq: state.outputSequence,
source: 'headless'
}