Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/agent_env/cli/task/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
25 changes: 25 additions & 0 deletions tst/unit/cli/task_get_summary_test.py
Original file line number Diff line number Diff line change
@@ -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)
Loading