@sigit / si Mirror · read-only / commits / 558150c
Fork 0

Mirror of github.com/getsigit/si.

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

Synced Nov 24, 08:15 UTC

Add si run to start and follow Cloud Agent runs

si run list and view show your agent runs, with the end of the transcript on view. si run start --repo OWNER/NAME starts one, and the server explains when the GitHub app or your GitHub connection is missing. si run cancel asks a run to stop, and si run handoff prints the branch, prompt and command for continuing it locally. The client crate gets the matching endpoints and the AgentRun type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Seto Elkahfi committed Oct 28, 2026 at 10:13 UTC 558150c7a21019ae4658a425e2f316949c245d99
8 files changed +291 -2
crates/cli/src/cli.rs
+26
@@ -42,6 +42,10 @@ pub enum Command {
42 #[command(subcommand)]
43 Code(CodeCommand),
44
45 + /// Start and follow siGit Code Cloud Agent runs.
46 + #[command(subcommand)]
47 + Run(RunCommand),
48 +
49 /// Report and read commit statuses, the checks CI shows on a commit.
50 #[command(subcommand)]
51 Status(StatusCommand),
@@ -222,6 +226,28 @@ pub enum CodeCommand {
226 },
227 }
228
229 +#[derive(clap::Subcommand)]
230 +pub enum RunCommand {
231 + /// List your agent runs, newest first.
232 + List,
233 + /// Show a run's status and the end of its transcript.
234 + View { id: i64 },
235 + /// Start a run on a GitHub repository where the siGit Code app is
236 + /// installed and your connected GitHub account can write.
237 + Start {
238 + /// OWNER/NAME of the GitHub repository.
239 + #[arg(long)]
240 + repo: String,
241 + /// What the agent should do.
242 + prompt: String,
243 + },
244 + /// Ask a running agent to stop.
245 + Cancel { id: i64 },
246 + /// Print the branch, prompt and command for continuing a run on your own
247 + /// machine.
248 + Handoff { id: i64 },
249 +}
250 +
251 #[derive(clap::Subcommand)]
252 pub enum StatusCommand {
253 /// Report a status on a commit.
crates/cli/src/commands/mod.rs
+1
@@ -8,5 +8,6 @@ pub mod issue;
8 pub mod me;
9 pub mod pr;
10 pub mod repo;
11 +pub mod run;
12 pub mod session;
13 pub mod status;
crates/cli/src/commands/run.rs new
+57
@@ -0,0 +1,57 @@
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 +}
crates/cli/src/main.rs
+1
@@ -46,6 +46,7 @@ async fn run() -> Result<()> {
46 Command::Pr(command) => commands::pr::run(&ctx, command).await,
47 Command::Issue(command) => commands::issue::run(&ctx, command).await,
48 Command::Code(command) => commands::code::run(&ctx, command).await,
49 + Command::Run(command) => commands::run::run(&ctx, command).await,
50 Command::Status(command) => commands::status::run(&ctx, command).await,
51 Command::Hook(command) => commands::hook::run(&ctx, command).await,
52 Command::Session(command) => commands::session::run(&ctx, command).await,
crates/cli/src/ui/render.rs
+69 -2
@@ -5,8 +5,8 @@ use {
5 super::{bold, dim, highlight, relative_time, state_badge},
6 console::style,
7 sigit_si_api::models::{
8 - Billing, CloudSession, CodeHit, CombinedStatus, Comment, Hook, Issue, IssueSummary,
9 - PullRequest, PullRequestSummary, Repository, RepositorySummary, User,
8 + AgentRun, Billing, CloudSession, CodeHit, CombinedStatus, Comment, Hook, Issue,
9 + IssueSummary, PullRequest, PullRequestSummary, Repository, RepositorySummary, User,
10 },
11 tabled::{builder::Builder, settings::Style},
12 };
@@ -401,6 +401,73 @@ pub fn combined_status(combined: &CombinedStatus) {
401 );
402 }
403
404 +// ── Agent runs ──────────────────────────────────────────────────────────────
405 +
406 +fn run_badge(status: &str) -> String {
407 + match status {
408 + "succeeded" | "completed" => style(status).green().to_string(),
409 + "failed" | "errored" | "timed_out" => style(status).red().to_string(),
410 + "running" | "queued" | "pending" => style(status).yellow().to_string(),
411 + other => style(other).dim().to_string(),
412 + }
413 +}
414 +
415 +pub fn agent_runs(runs: &[AgentRun]) {
416 + let rows = runs
417 + .iter()
418 + .map(|run| {
419 + vec![
420 + run.id.to_string(),
421 + truncate(run.title.as_deref().unwrap_or("(untitled)"), 40),
422 + run.repo_full_name.clone(),
423 + run_badge(&run.status),
424 + relative_time(run.created_at),
425 + ]
426 + })
427 + .collect();
428 +
429 + table(
430 + &["ID", "Title", "Repository", "Status", "Started"],
431 + rows,
432 + "You have no agent runs yet. Start one with `si run start`.",
433 + );
434 +}
435 +
436 +pub fn agent_run_detail(run: &AgentRun) {
437 + println!();
438 + println!(
439 + " {} {}",
440 + highlight(run.title.as_deref().unwrap_or("(untitled run)")),
441 + run_badge(&run.status)
442 + );
443 + field("ID", Some(&run.id.to_string()));
444 + field("Repository", Some(&run.repo_full_name));
445 + field("Triggered by", Some(&run.trigger_kind));
446 + field("Base", run.base_branch.as_deref());
447 + field("Branch", run.head_branch.as_deref());
448 + field("Pull request", run.pull_request_url.as_deref());
449 + field("Exit reason", run.exit_reason.as_deref());
450 + field("Requests", Some(&run.inference_requests_used.to_string()));
451 + if run.cancel_requested {
452 + field("Cancel", Some("requested"));
453 + }
454 + field("Created", Some(&relative_time(run.created_at)));
455 + field("Finished", run.finished_at.map(relative_time).as_deref());
456 + println!();
457 +
458 + if let Some(tail) = run
459 + .transcript_tail
460 + .as_deref()
461 + .filter(|t| !t.trim().is_empty())
462 + {
463 + println!(" {}", dim("Transcript (end)"));
464 + for line in tail.lines() {
465 + println!(" {line}");
466 + }
467 + println!();
468 + }
469 +}
470 +
471 // ── Billing ─────────────────────────────────────────────────────────────────
472
473 pub fn billing(billing: &Billing) {
crates/sigit-si-api/src/agent_runs.rs new
+107
@@ -0,0 +1,107 @@
1 +//! siGit Code Cloud Agent runs.
2 +
3 +use {
4 + crate::{client::Client, error::Result, models::AgentRun},
5 + reqwest::{Method, RequestBuilder},
6 + serde::Deserialize,
7 +};
8 +
9 +#[derive(Deserialize)]
10 +struct AgentRuns {
11 + agent_runs: Vec<AgentRun>,
12 +}
13 +
14 +impl Client {
15 + /// `GET /api/v1/agent/runs` — your runs, newest first.
16 + pub async fn agent_runs(&self) -> Result<Vec<AgentRun>> {
17 + let runs: AgentRuns = self.get("agent/runs").await?;
18 + Ok(runs.agent_runs)
19 + }
20 +
21 + /// `GET /api/v1/agent/runs/:id` — one run, with the tail of its
22 + /// transcript in `transcript_tail`.
23 + pub async fn agent_run(&self, id: i64) -> Result<AgentRun> {
24 + self.get(&format!("agent/runs/{id}")).await
25 + }
26 +
27 + /// `POST /api/v1/agent/runs` — start a run on a GitHub repository that has
28 + /// the siGit Code GitHub App installed and that your connected GitHub
29 + /// account can write to.
30 + pub async fn create_agent_run(&self, repo_full_name: &str, prompt: &str) -> Result<AgentRun> {
31 + self.send(self.create_agent_run_request(repo_full_name, prompt))
32 + .await
33 + }
34 +
35 + /// `POST /api/v1/agent/runs/:id/cancel`
36 + pub async fn cancel_agent_run(&self, id: i64) -> Result<AgentRun> {
37 + self.send(self.request(Method::POST, &format!("agent/runs/{id}/cancel")))
38 + .await
39 + }
40 +
41 + /// `GET /api/v1/agent/runs/:id/handoff` — the branch, prompt and command to
42 + /// carry on with a run on your own machine. Returned as the server sent it.
43 + pub async fn agent_run_handoff(&self, id: i64) -> Result<serde_json::Value> {
44 + self.get(&format!("agent/runs/{id}/handoff")).await
45 + }
46 +
47 + fn create_agent_run_request(&self, repo_full_name: &str, prompt: &str) -> RequestBuilder {
48 + self.request(Method::POST, "agent/runs")
49 + .json(&serde_json::json!({
50 + "repo_full_name": repo_full_name,
51 + "prompt": prompt,
52 + }))
53 + }
54 +}
55 +
56 +#[cfg(test)]
57 +mod tests {
58 + use {super::*, crate::Environment};
59 +
60 + fn client() -> Client {
61 + Client::builder(Environment::Production)
62 + .base_url("https://sigit.si")
63 + .token("tok")
64 + .build()
65 + .unwrap()
66 + }
67 +
68 + #[test]
69 + fn a_run_is_started_with_the_repo_and_prompt() {
70 + let request = client()
71 + .create_agent_run_request("seto/demo", "Fix the build")
72 + .build()
73 + .unwrap();
74 +
75 + assert_eq!(request.method(), Method::POST);
76 + assert_eq!(request.url().as_str(), "https://sigit.si/api/v1/agent/runs");
77 + let body = request.body().and_then(|b| b.as_bytes()).unwrap();
78 + let body: serde_json::Value = serde_json::from_slice(body).unwrap();
79 + assert_eq!(body["repo_full_name"], "seto/demo");
80 + assert_eq!(body["prompt"], "Fix the build");
81 + }
82 +
83 + #[test]
84 + fn the_list_is_unwrapped() {
85 + let body = r#"{"agent_runs":[{"id":7,"title":null,"repo_full_name":"seto/demo",
86 + "trigger_kind":"api","status":"running","cancel_requested":false,
87 + "exit_reason":null,"base_branch":"main","head_branch":"sigit/x",
88 + "pull_request_url":null,"issue_number":null,"pr_number":null,
89 + "inference_requests_used":3,"created_at":"2026-10-01T10:00:00Z",
90 + "started_at":null,"finished_at":null}]}"#;
91 + let runs: AgentRuns = serde_json::from_str(body).unwrap();
92 + assert_eq!(runs.agent_runs[0].id, 7);
93 + assert!(runs.agent_runs[0].transcript_tail.is_none());
94 + }
95 +
96 + #[test]
97 + fn a_single_run_carries_its_transcript_tail() {
98 + let body = r#"{"id":7,"title":"t","repo_full_name":"seto/demo","trigger_kind":"api",
99 + "status":"succeeded","cancel_requested":false,"exit_reason":null,
100 + "base_branch":null,"head_branch":null,"pull_request_url":null,
101 + "issue_number":null,"pr_number":null,"inference_requests_used":0,
102 + "created_at":"2026-10-01T10:00:00Z","started_at":null,"finished_at":null,
103 + "transcript_tail":"line 1\nline 2\n"}"#;
104 + let run: AgentRun = serde_json::from_str(body).unwrap();
105 + assert_eq!(run.transcript_tail.as_deref(), Some("line 1\nline 2\n"));
106 + }
107 +}
crates/sigit-si-api/src/lib.rs
+2
@@ -35,6 +35,8 @@
35 #[cfg(feature = "client")]
36 pub mod account;
37 #[cfg(feature = "client")]
38 +pub mod agent_runs;
39 +#[cfg(feature = "client")]
40 pub mod billing;
41 #[cfg(feature = "client")]
42 pub mod client;
crates/sigit-si-api/src/models.rs
+28
@@ -166,6 +166,34 @@ pub struct CombinedStatus {
166 pub statuses: Vec<CommitStatus>,
167 }
168
169 +// ── Agent runs ──────────────────────────────────────────────────────────────
170 +
171 +/// A siGit Code Cloud Agent run. `transcript_tail` is only present on the
172 +/// single-run read.
173 +#[derive(Debug, Clone, Deserialize, Serialize)]
174 +pub struct AgentRun {
175 + pub id: i64,
176 + pub title: Option<String>,
177 + pub repo_full_name: String,
178 + pub trigger_kind: String,
179 + pub status: String,
180 + #[serde(default)]
181 + pub cancel_requested: bool,
182 + pub exit_reason: Option<String>,
183 + pub base_branch: Option<String>,
184 + pub head_branch: Option<String>,
185 + pub pull_request_url: Option<String>,
186 + pub issue_number: Option<i64>,
187 + pub pr_number: Option<i64>,
188 + #[serde(default)]
189 + pub inference_requests_used: i64,
190 + pub created_at: DateTime<Utc>,
191 + pub started_at: Option<DateTime<Utc>>,
192 + pub finished_at: Option<DateTime<Utc>>,
193 + #[serde(default, skip_serializing_if = "Option::is_none")]
194 + pub transcript_tail: Option<String>,
195 +}
196 +
197 // ── MCP-backed resources ────────────────────────────────────────────────────
198 //
199 // Issues, pull requests, and code search have no REST surface; they are served