diff --git a/src/cli/artifact-format.ts b/src/cli/artifact-format.ts index 3e2dbcfbbdb..b33a74894c0 100644 --- a/src/cli/artifact-format.ts +++ b/src/cli/artifact-format.ts @@ -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') diff --git a/src/cli/handlers/artifacts.test.ts b/src/cli/handlers/artifacts.test.ts index 40dfbc89ac5..92e94e69c59 100644 --- a/src/cli/handlers/artifacts.test.ts +++ b/src/cli/handlers/artifacts.test.ts @@ -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'), '

Hi

', 'utf8')