fix(cli): preserve text between terminal sequences

This commit is contained in:
Jinwoo-H
2026-08-31 19:35:05 -04:00
parent 3e90b79cfc
commit 54f15ca5ca
2 changed files with 12 additions and 1 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ export function formatArtifactRead(result: ArtifactReadResult): string {
export function sanitizeArtifactTerminalContent(content: string): string {
const escape = String.fromCharCode(27)
const osc = new RegExp(
`${escape}\\][^${String.fromCharCode(7)}]*(?:${String.fromCharCode(7)}|${escape}\\\\)`,
`${escape}\\][^${String.fromCharCode(7)}]*?(?:${String.fromCharCode(7)}|${escape}\\\\)`,
'g'
)
const csi = new RegExp(`${escape}(?:\\[[0-9;?]*[ -/]*[@-~])`, 'g')
+11
View File
@@ -5,6 +5,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import type { ArtifactListItem } from '../../shared/artifacts'
import { ARTIFACT_HANDLERS } from './artifacts'
import { ARTIFACT_CLI_MAX_RPC_BYTES } from '../../shared/artifacts'
import { sanitizeArtifactTerminalContent } from '../artifact-format'
import {
ARTIFACT_SHARING_DISABLED_CODE,
ARTIFACT_SHARING_DISABLED_MESSAGE,
@@ -99,6 +100,16 @@ describe('artifact CLI handlers', () => {
expect(log).toHaveBeenCalledWith(`Artifact written to ${JSON.stringify(resolve(cwd, output))}`)
expect(String(log.mock.calls[0]?.[0])).not.toContain('\u001b]52;')
})
it('preserves text between separate OSC terminal sequences', () => {
const escape = String.fromCharCode(27)
const bell = String.fromCharCode(7)
expect(
sanitizeArtifactTerminalContent(
`${escape}]8;;https://example.com${bell}visible${escape}]0;title${bell}`
)
).toBe('visible')
})
it('reads a relative HTML file and sends sanitized content to the runtime', async () => {
const cwd = await mkdtemp(join(tmpdir(), 'orca-artifact-cli-'))
await writeFile(join(cwd, 'report.html'), '<h1>Hi</h1>', 'utf8')