mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 18:47:40 +00:00
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:
co-authored by
Paweł Kotowski
parent
be29644ec9
commit
ef950401d3
@@ -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()
|
||||
})
|
||||
})
|
||||
@@ -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 }
|
||||
}
|
||||
Reference in New Issue
Block a user