diff --git a/llm/cli.py b/llm/cli.py index d3a755fc..9561f312 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -990,15 +990,16 @@ def logs_list( for attachment in attachments_by_id.get(row["id"], []) ] output = json.dumps(list(rows), indent=2) - elif response: - # Just output the last response - if rows: - output = rows[-1]["response"] elif extract: + # Extract and return first code block for row in rows: output = extract_first_fenced_code_block(row["response"]) if output is not None: break + elif response: + # Just output the last response + if rows: + output = rows[-1]["response"] if output is not None: click.echo(output) diff --git a/tests/test_llm.py b/tests/test_llm.py index 462b1a82..01f3bb5d 100644 --- a/tests/test_llm.py +++ b/tests/test_llm.py @@ -125,7 +125,17 @@ def test_logs_response_only(args, log_path): @pytest.mark.parametrize( - "args", (["-x"], ["--extract"], ["list", "-x"], ["list", "--extract"]) + "args", + ( + ["-x"], + ["--extract"], + ["list", "-x"], + ["list", "--extract"], + # Using -xr together should have same effect as just -x + ["-xr"], + ["-x", "-r"], + ["--extract", "--response"], + ), ) def test_logs_extract_first_code(args, log_path): "Test that logs -x/--extract returns the first code block"