@sigit / si Mirror · read-only
Fork 0

Mirror of github.com/getsigit/si.

Mirrored from https://github.com/getsigit/si.git

Synced Nov 24, 09:30 UTC

1 use {
2 crate::{cli::RunCommand, context::Ctx, ui},
3 anyhow::Result,
4 };
5
6 pub async fn run(ctx: &Ctx, command: RunCommand) -> Result<()> {
7 ctx.require_token()?;
8
9 match command {
10 RunCommand::List => list(ctx).await,
11 RunCommand::View { id } => view(ctx, id).await,
12 RunCommand::Start { repo, prompt } => start(ctx, &repo, &prompt).await,
13 RunCommand::Cancel { id } => cancel(ctx, id).await,
14 RunCommand::Handoff { id } => handoff(ctx, id).await,
15 }
16 }
17
18 async fn list(ctx: &Ctx) -> Result<()> {
19 let runs = ctx.client.agent_runs().await?;
20 ui::emit(ctx.json, &runs, |runs| ui::render::agent_runs(runs))
21 }
22
23 async fn view(ctx: &Ctx, id: i64) -> Result<()> {
24 let run = ctx.client.agent_run(id).await?;
25 ui::emit(ctx.json, &run, ui::render::agent_run_detail)
26 }
27
28 async fn start(ctx: &Ctx, repo: &str, prompt: &str) -> Result<()> {
29 let slug = crate::git::RepoSlug::parse(repo)?;
30 let run = ctx
31 .client
32 .create_agent_run(&slug.to_string(), prompt)
33 .await?;
34 ui::emit(ctx.json, &run, |run| {
35 ui::success(format!(
36 "Started run #{} on {}.",
37 run.id,
38 ui::highlight(&run.repo_full_name)
39 ));
40 ui::note(format!("Follow it with `si run view {}`.", run.id));
41 })
42 }
43
44 async fn cancel(ctx: &Ctx, id: i64) -> Result<()> {
45 let run = ctx.client.cancel_agent_run(id).await?;
46 ui::emit(ctx.json, &run, |run| {
47 ui::success(format!("Asked run #{} to stop.", run.id));
48 })
49 }
50
51 /// The context is already JSON, so it prints the same with or without
52 /// `--json`.
53 async fn handoff(ctx: &Ctx, id: i64) -> Result<()> {
54 let context = ctx.client.agent_run_handoff(id).await?;
55 println!("{}", serde_json::to_string_pretty(&context)?);
56 Ok(())
57 }