From cb840fbce2b75512ef3b72ba0873ef1bce8cb6dd Mon Sep 17 00:00:00 2001 From: William Loo Date: Fri, 4 Dec 2026 10:24:30 -0800 Subject: [PATCH] As an env author, I want agent-env task get --summary to print one lin From Ask AgentEnv (localdev MVP, FD-7169). --- src/agent_env/cli/task/get.py | 9 +++++++-- tst/unit/cli/task_get_summary_test.py | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tst/unit/cli/task_get_summary_test.py diff --git a/src/agent_env/cli/task/get.py b/src/agent_env/cli/task/get.py index 1a896fbad..4110516a8 100644 --- a/src/agent_env/cli/task/get.py +++ b/src/agent_env/cli/task/get.py @@ -8,11 +8,16 @@ @click.command() @click.option("--id", "task_id", required=True, help="Task id") @click.option("--version", "task_version", default=None, type=int, help="Task version (defaults to latest)") -def get(task_id: str, task_version: int | None): +@click.option("--summary", is_flag=True, help="Print one line per step (index, type, id) instead of JSON") +def get(task_id: str, task_version: int | None, summary: bool): """Get a task and output its step definitions as JSON, as task create takes them: an object with its steps and - headline_verifiers when it has them.""" + headline_verifiers when it has them; with --summary, one tab-separated line per step to skim instead.""" from agent_env.bundle.parse import task_file_body from agent_env.task import Task task = Task.get(task_id, task_version) + if summary: + for index, step in enumerate(task.steps): + click.echo(f"{index}\t{step.type}\t{step.id}") + return click.echo(json.dumps(task_file_body(task.to_dict()["steps"], task.headline_verifiers), indent=2)) diff --git a/tst/unit/cli/task_get_summary_test.py b/tst/unit/cli/task_get_summary_test.py new file mode 100644 index 000000000..77518881b --- /dev/null +++ b/tst/unit/cli/task_get_summary_test.py @@ -0,0 +1,25 @@ +"""`agent-env task get --summary` prints a line per step rather than the task's JSON.""" + +import json + +import pytest +from click.testing import CliRunner + +from agent_env.cli.task.get import get +from agent_env.task import Task + +STEPS = [{"id": "box", "type": "deploy_sandbox", "sandbox_name": "box", "sandbox_mode": "vm"}, + {"id": "tests", "type": "verify_sandbox", "sandbox_name": "box", "verifier_id": "tests", "criteria": []}] + + +@pytest.mark.parametrize("headlines", [None, ["tests"]], ids=["bare", "headlines"]) +def test_summary_prints_each_steps_index_type_and_id(monkeypatch, headlines): + task = Task.from_dict({"id": "t", "version": 1, "steps": STEPS, "headline_verifiers": headlines}) + monkeypatch.setattr(Task, "get", classmethod(lambda cls, task_id, version=None: task)) + + result = CliRunner().invoke(get, ["--id", "t", "--summary"]) + + assert result.exit_code == 0, result.output + assert result.output.splitlines() == ["0\tdeploy_sandbox\tbox", "1\tverify_sandbox\ttests"] + with pytest.raises(json.JSONDecodeError): + json.loads(result.output)