Prevent Command Code output from hijacking agent icons (#12573)

* fix terminal agent icon ownership

* fix terminal output ownership gaps
This commit is contained in:
Brennan Benson
2026-08-04 16:06:54 -07:00
committed by GitHub
parent 7948e46db8
commit a528b689a9
9 changed files with 354 additions and 11 deletions
+56 -3
View File
@@ -29,7 +29,7 @@ describe('createCommandCodeOutputStatusDetector', () => {
})
expect(detector.observe('Thinking about unrelated shell output')).toBe(false)
expect(detector.observe('# Command Code v0.27.2')).toBe(false)
expect(detector.observe('# Command Code v0.27.2\r\n')).toBe(false)
expect(detector.observe('⌘ Parsing...')).toBe(true)
expect(onWorking).toHaveBeenCalledWith('')
@@ -43,7 +43,7 @@ describe('createCommandCodeOutputStatusDetector', () => {
})
expect(detector.observe('# Command')).toBe(false)
expect(detector.observe(' Code v0.27.2')).toBe(false)
expect(detector.observe(' Code v0.27.2\r\n')).toBe(false)
expect(detector.observe('⌘ Parsing...')).toBe(true)
expect(onWorking).toHaveBeenCalledWith('')
@@ -56,7 +56,7 @@ describe('createCommandCodeOutputStatusDetector', () => {
onWorking
})
expect(detector.observe('# C\x1b[35mommand Co\x1b[0mde v0.27.2')).toBe(false)
expect(detector.observe('# C\x1b[35mommand Co\x1b[0mde v0.27.2\r\n')).toBe(false)
expect(detector.observe('⌘ Parsing...')).toBe(true)
expect(onWorking).toHaveBeenCalledWith('')
@@ -74,6 +74,59 @@ describe('createCommandCodeOutputStatusDetector', () => {
expect(onWorking).not.toHaveBeenCalled()
})
it('does not arm when another agent merely discusses Command Code', () => {
const onWorking = vi.fn()
const detector = createCommandCodeOutputStatusDetector({
startupCommand: null,
onWorking
})
expect(detector.observe('// Why: Command Code exposes transcript prompts')).toBe(false)
expect(detector.observe('\r\n✻ Thinking...')).toBe(false)
expect(onWorking).not.toHaveBeenCalled()
})
it.each([
'# Command Code v1.2\r\n',
'# Command Code v1.2.3.4\r\n',
'# Command Code v01.2.3\r\n',
'# Command Code v1.2.3suffix\r\n',
'#\nCommand Code v1.2.3\r\n'
])('does not arm for noncanonical banner %j', (banner) => {
const onWorking = vi.fn()
const detector = createCommandCodeOutputStatusDetector({ startupCommand: null, onWorking })
expect(detector.observe(banner)).toBe(false)
expect(detector.observe('✻ Thinking...')).toBe(false)
expect(onWorking).not.toHaveBeenCalled()
})
it('does not arm from a four-part version split at a PTY chunk boundary', () => {
const onWorking = vi.fn()
const detector = createCommandCodeOutputStatusDetector({ startupCommand: null, onWorking })
expect(detector.observe('# Command Code v1.2.3')).toBe(false)
expect(detector.observe('.4\r\n')).toBe(false)
expect(detector.observe('✻ Thinking...')).toBe(false)
expect(onWorking).not.toHaveBeenCalled()
})
it.each(['# Command Code v1.2.3\r\n', '# Command Code v1.2.3-beta.1+build.9\n'])(
'arms for canonical banner %j',
(banner) => {
const onWorking = vi.fn()
const detector = createCommandCodeOutputStatusDetector({ startupCommand: null, onWorking })
expect(detector.observe(banner)).toBe(false)
expect(detector.observe('✻ Thinking...')).toBe(true)
expect(onWorking).toHaveBeenCalledWith('')
}
)
it.each([
'Pondering',
'Contemplating',
+17 -6
View File
@@ -112,7 +112,16 @@ const ACTIVE_EXECUTION_STATUS_RE = new RegExp(
`(?:^|[\\r\\n])\\s*(?:${COMMAND_CODE_STATUS_GLYPH_RE_SOURCE}\\s*)?(?:Executing:\\s+\\S|Running\\s*\\()`
)
const IDLE_PROMPT_RE = /(?:^|[\r\n])\s*[❯>]\s+Ask your question\.\.\./
const COMMAND_CODE_BANNER_RE = /\bCommand Code\b/
const SEMVER_NUMBER_RE_SOURCE = '(?:0|[1-9]\\d*)'
const SEMVER_PRERELEASE_IDENTIFIER_RE_SOURCE = '(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)'
const SEMVER_BUILD_IDENTIFIER_RE_SOURCE = '[0-9A-Za-z-]+'
const COMMAND_CODE_BANNER_RE = new RegExp(
`(?:^|[\\r\\n])[ \\t]*#[ \\t]+Command Code[ \\t]+v` +
`${SEMVER_NUMBER_RE_SOURCE}\\.${SEMVER_NUMBER_RE_SOURCE}\\.${SEMVER_NUMBER_RE_SOURCE}` +
`(?:-${SEMVER_PRERELEASE_IDENTIFIER_RE_SOURCE}(?:\\.${SEMVER_PRERELEASE_IDENTIFIER_RE_SOURCE})*)?` +
`(?:\\+${SEMVER_BUILD_IDENTIFIER_RE_SOURCE}(?:\\.${SEMVER_BUILD_IDENTIFIER_RE_SOURCE})*)?` +
`(?=[ \\t]*[\\r\\n])`
)
function cleanPromptCandidate(value: string): string {
return cleanCommandCodePromptCandidate(stripTerminalControl(value))
@@ -233,17 +242,19 @@ export function createCommandCodeOutputStatusDetector(args: {
: scanRawText
if (!hasSeenCommandCodeUi) {
if (
!rawTextMayContainCommandCodeBanner(scanRawText) &&
!rawTextMayContainCommandCodeBanner(scanRawTextWithChunkBoundary)
) {
if (!rawTextMayContainCommandCodeBanner(scanRawText)) {
return false
}
const scanText = stripTerminalControl(scanRawText)
const scanTextWithChunkBoundary = stripTerminalControl(scanRawTextWithChunkBoundary)
const previousTextWithChunkBoundaryLength = previousRawText
? stripTerminalControl(`${previousRawText}\n`).length
: 0
if (
!COMMAND_CODE_BANNER_RE.test(scanText) &&
!COMMAND_CODE_BANNER_RE.test(scanTextWithChunkBoundary)
!COMMAND_CODE_BANNER_RE.test(
scanTextWithChunkBoundary.slice(previousTextWithChunkBoundaryLength)
)
) {
return false
}