Skip to content

Commit 3bbd93d

Browse files
committed
Add agent run export command
1 parent 40881b7 commit 3bbd93d

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

dreadnode_cli/agent/cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,34 @@ def latest(
517517
print(format_run(run, verbose=verbose, include_logs=logs, server_url=server_config.url))
518518

519519

520+
@cli.command(help="Export all run information for the active agent")
521+
@pretty_cli
522+
def export(
523+
directory: t.Annotated[
524+
pathlib.Path,
525+
typer.Option("--dir", "-d", help="The export directory", file_okay=False, resolve_path=True),
526+
] = pathlib.Path("export"),
527+
strike: t.Annotated[str | None, typer.Option("--strike", "-s", help="Export runs for a specific strike")] = None,
528+
group: t.Annotated[str | None, typer.Option("--group", "-g", help="Export runs from a specific group")] = None,
529+
) -> None:
530+
agent_config = AgentConfig.read()
531+
ensure_profile(agent_config)
532+
533+
client = api.create_client()
534+
run_summaries = client.list_strike_runs(
535+
strike=strike or agent_config.strike, group=group, agent=agent_config.active_link.id
536+
)
537+
538+
print(f":package: Exporting {len(run_summaries)} runs to [b]{directory}[/] ...")
539+
540+
directory.mkdir(exist_ok=True)
541+
for summary in run_summaries:
542+
print(f" |- {summary.key} ({summary.id}) ...")
543+
run = client.get_strike_run(summary.id)
544+
with (directory / f"{run.key}_{run.id}.json").open("w") as f:
545+
f.write(run.model_dump_json())
546+
547+
520548
@cli.command(help="Show the status of the active agent")
521549
@pretty_cli
522550
def show(

dreadnode_cli/api.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,17 @@ def get_strike_run(self, run: UUID | str) -> StrikeRunResponse:
492492
response = self.request("GET", f"/api/strikes/runs/{run}")
493493
return self.StrikeRunResponse(**response.json())
494494

495-
def list_strike_runs(self, *, strike_id: UUID | str | None = None) -> list[StrikeRunSummaryResponse]:
495+
def list_strike_runs(
496+
self, *, strike: UUID | str | None = None, agent: UUID | str | None = None, group: UUID | str | None = None
497+
) -> list[StrikeRunSummaryResponse]:
496498
response = self.request(
497-
"GET", "/api/strikes/runs", query_params={"strike_id": str(strike_id)} if strike_id else None
499+
"GET",
500+
"/api/strikes/runs",
501+
query_params={
502+
**({"strike": str(strike)} if strike else {}),
503+
**({"agent": str(agent)} if agent else {}),
504+
**({"group": str(group)} if group else {}),
505+
},
498506
)
499507
return [self.StrikeRunSummaryResponse(**run) for run in response.json()]
500508

0 commit comments

Comments
 (0)