diff --git a/agentrace/cli.py b/agentrace/cli.py index 476759c..2aef482 100644 --- a/agentrace/cli.py +++ b/agentrace/cli.py @@ -92,13 +92,13 @@ def cmd_check(args) -> int: flagged += 1 total_findings += len(findings) console.print( - f"\n[bold]{r.description or '(no description)'}[/] [dim]{r.tool_use_id[-8:]}[/]" + f"\n[bold]{escape(r.description or '(no description)')}[/] [dim]{r.tool_use_id[-8:]}[/]" ) for f in findings: colour = _SEV_COLOUR.get(f.severity, "white") - console.print(f" [{colour}]{f.severity:<6}[/] [bold]{f.check}[/] {f.message}") + console.print(f" [{colour}]{f.severity:<6}[/] [bold]{escape(f.check)}[/] {escape(f.message)}") if f.evidence: - console.print(f" [dim]{f.evidence}[/]") + console.print(f" [dim]{escape(f.evidence)}[/]") console.print( f"\n[bold]{flagged}/{len(runs)}[/] runs flagged, {total_findings} findings. " @@ -119,18 +119,18 @@ def cmd_show(args) -> int: console.print(f"[red]No run matching {args.id!r}[/]") return 1 r = match[0] - console.print(f"[bold]{r.description}[/] [dim]{r.tool_use_id}[/]") + console.print(f"[bold]{escape(r.description)}[/] [dim]{escape(r.tool_use_id)}[/]") console.print(f"[dim]duration: {r.duration_s}s | background: {r.background}[/]\n") console.print("[bold cyan]PROMPT[/]") - console.print(r.prompt[: args.max] or "[dim](empty)[/]") + console.print(escape(r.prompt[: args.max]) if r.prompt[: args.max] else "[dim](empty)[/]") console.print("\n[bold cyan]RESULT[/]") - console.print(r.result[: args.max] or "[dim](empty)[/]") + console.print(escape(r.result[: args.max]) if r.result[: args.max] else "[dim](empty)[/]") findings = analyse(r) if findings: console.print("\n[bold cyan]FINDINGS[/]") for f in findings: colour = _SEV_COLOUR.get(f.severity, "white") - console.print(f" [{colour}]{f.severity:<6}[/] {f.check}: {f.message}") + console.print(f" [{colour}]{f.severity:<6}[/] {escape(f.check)}: {escape(f.message)}") return 0 diff --git a/tests/test_cli.py b/tests/test_cli.py index 28b0de3..5d7241f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -136,3 +136,19 @@ def test_version(): result = run_cli("--version") assert result.returncode == 0 assert "0.1.0" in result.stdout + + +def test_check_prints_bracketed_description_literally(monkeypatch, capsys): + start = datetime(2026, 1, 1, tzinfo=UTC) + run = AgentRun( + tool_use_id="toolu_test123456", + description="run [bold]pwned[/bold] test", + prompt="x" * 500, + result="I could not complete the task because access was denied.", + started_at=start, + ended_at=start + timedelta(seconds=1), + ) + monkeypatch.setattr(cli, "_load", lambda args: [run]) + + assert cli.cmd_check(Namespace(severity=None, strict=False)) == 0 + assert "run [bold]pwned[/bold] test" in capsys.readouterr().out