fix(native-chat): show prompts sent mid-turn and ! commands where Claude read them (#31204)

Co-authored-by: Paweł Kotowski <p.kotowski89@gmail.com>
This commit is contained in:
Kelvin Amoaba
2026-10-20 23:13:32 +00:00
committed by GitHub
co-authored by Paweł Kotowski
parent be29644ec9
commit ef950401d3
12 changed files with 382 additions and 8 deletions
+19
View File
@@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest'
import { claudeBashInputAsTypedCommand } from './claude-bash-input'
describe('claudeBashInputAsTypedCommand', () => {
it('restores the line as typed, keeping the space after `!`', () => {
expect(claudeBashInputAsTypedCommand('<bash-input> gcloud auth login</bash-input>')).toBe(
'! gcloud auth login'
)
expect(claudeBashInputAsTypedCommand('<bash-input>ls -la</bash-input>')).toBe('!ls -la')
})
it.each([
'run <bash-input>ls</bash-input>',
'<bash-input>ls</bash-input> and more',
'<bash-stdout>ok</bash-stdout>',
'<bash-input>a</bash-input><bash-input>b</bash-input>'
])('leaves anything else alone (%s)', (text) => {
expect(claudeBashInputAsTypedCommand(text)).toBeNull()
})
})
+18
View File
@@ -0,0 +1,18 @@
import type { NativeChatBlock } from './native-chat-types'
const BASH_INPUT = /^\s*<bash-input>([\s\S]*)<\/bash-input>\s*$/
/** Claude records a `!` shell command as `<bash-input>cmd</bash-input>`, with the `!`
* stripped. Returns the line as typed, or null when the text is anything else. */
export function claudeBashInputAsTypedCommand(text: string): string | null {
const command = BASH_INPUT.exec(text)?.[1]
return command === undefined || command.includes('<bash-input>') ? null : `!${command}`
}
export function unwrapClaudeBashInputBlock(block: NativeChatBlock): NativeChatBlock {
if (block.type !== 'text') {
return block
}
const typed = claudeBashInputAsTypedCommand(block.text)
return typed === null ? block : { ...block, text: typed }
}