Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Issues and pull requests replace intents and attempts | 1 | //! Runs a coding agent on one pull request and reports back to g1t. |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 2 | //! |
| Issues and pull requests replace intents and attempts | 3 | //! This is the program a hosted sandbox starts. It clones the pull |
| 4 | //! request's fork, runs the agent harness headless, streams what the agent | |
| 5 | //! does into the pull request's session as it happens, pushes the result | |
| 6 | //! and marks the pull request ready for review. It talks to g1t only through the public API and git, exactly | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 7 | //! as an agent on someone's own machine would. |
| 8 | //! | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 9 | //! `MODE` selects another job instead: `checks` runs acceptance checks, |
| 10 | //! `update` brings a pull request up to date with its target branch, | |
| 11 | //! `review` has an agent review one, and `revise` sends the author back to | |
| 12 | //! address what the checks or a review found, `plan` turns an outcome | |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 13 | //! into issues, `queue` builds and checks a state of the merge queue, |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 14 | //! `mergecheck` finds out whether a pull request merges cleanly, |
| 15 | //! `actions` runs one job of a GitHub Actions workflow, and `bump` makes a | |
| 16 | //! security update: one package raised in its lockfiles, pushed as g1t. | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 17 | //! See the modules of those names. |
| Acceptance checks in sandboxes, line comments and review verdicts | 18 | //! |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 19 | //! Configuration comes from the environment: |
| 20 | //! | |
| 21 | //! - `G1T_API`, `G1T_TOKEN`, `G1T_USER`: where and who to report as. | |
| Issues and pull requests replace intents and attempts | 22 | //! - `G1T_REPO`, `PULL_NUMBER`, `GIT_REMOTE`: the pull request and its fork. |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 23 | //! - `PROMPT`: what the agent is asked to do. |
| 24 | //! - `COMMIT_MESSAGE`: used if the agent leaves changes uncommitted. | |
| 25 | //! - `ANTHROPIC_API_KEY`: read by the harness itself. | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 26 | //! |
| 27 | //! Every mode runs with the mining watch in `abuse`: a sandbox that looks | |
| 28 | //! like it is mining stops itself and exits with `abuse::EXIT_CODE`. | |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 29 | //! |
| 30 | //! Given a command instead (`register`, `run`, `service`, `remove`, | |
| 31 | //! `update`, `version`), it is a self-hosted runner on someone's own | |
| 32 | //! machine, which runs work in these modes: see `selfhosted`. | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 33 | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 34 | mod abuse; |
| GitHub Actions on g1t, part two: running workflows | 35 | mod actions; |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 36 | mod bump; |
| Acceptance checks in sandboxes, line comments and review verdicts | 37 | mod checks; |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 38 | mod clone; |
| Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step | 39 | mod confidence; |
| Deployments: a preview for every pull request, production on g1t.page | 40 | mod deploy; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 41 | mod guard; |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 42 | mod harness; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 43 | mod learned; |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 44 | mod mergecheck; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 45 | mod plan; |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 46 | mod progress; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 47 | mod queue; |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 48 | mod reply; |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 49 | mod report; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 50 | mod review; |
| 51 | mod revise; | |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 52 | mod selfhosted; |
| Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request | 53 | mod steer; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 54 | mod update; |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 55 | |
| 56 | use std::path::Path; | |
| 57 | use std::process::Command; | |
| 58 | ||
| 59 | use anyhow::{Context, Result, bail}; | |
| 60 | use base64::Engine; | |
| 61 | use base64::engine::general_purpose::STANDARD; | |
| 62 | ||
| 63 | use report::{Entry, Reporter}; | |
| 64 | ||
| Acceptance checks in sandboxes, line comments and review verdicts | 65 | pub(crate) const WORKDIR: &str = "/work/repo"; |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 66 | |
| Acceptance checks in sandboxes, line comments and review verdicts | 67 | pub(crate) fn env(name: &str) -> Result<String> { |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 68 | std::env::var(name).with_context(|| format!("{name} is not set")) |
| 69 | } | |
| 70 | ||
| 71 | /// Runs git and returns its trimmed output, failing on a non-zero exit. | |
| Acceptance checks in sandboxes, line comments and review verdicts | 72 | pub(crate) fn git(dir: &Path, args: &[&str]) -> Result<String> { |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 73 | let output = Command::new("git") |
| 74 | .current_dir(dir) | |
| 75 | .args(args) | |
| 76 | .output() | |
| 77 | .context("could not run git")?; | |
| 78 | if !output.status.success() { | |
| 79 | bail!( | |
| 80 | "git {} failed: {}", | |
| 81 | args.first().unwrap_or(&""), | |
| 82 | String::from_utf8_lossy(&output.stderr).trim() | |
| 83 | ); | |
| 84 | } | |
| 85 | Ok(String::from_utf8_lossy(&output.stdout).trim().to_owned()) | |
| 86 | } | |
| 87 | ||
| 88 | /// A git option that authenticates one command. The credential is passed | |
| 89 | /// per command and never written to the clone's config or its remote URL, | |
| 90 | /// where the agent would find it. | |
| Acceptance checks in sandboxes, line comments and review verdicts | 91 | pub(crate) fn auth_option(user: &str, token: &str) -> String { |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 92 | let credentials = STANDARD.encode(format!("{user}:{token}")); |
| 93 | format!("http.extraHeader=Authorization: Basic {credentials}") | |
| 94 | } | |
| 95 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 96 | /// Clones the fork, runs the agent on `PROMPT`, commits and pushes what it |
| 97 | /// did, and returns its closing summary. | |
| 98 | pub(crate) fn run(reporter: &mut Reporter) -> Result<String> { | |
| 99 | let mut prompt = env("PROMPT")?; | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 100 | let remote = env("GIT_REMOTE")?; |
| 101 | let auth = auth_option(&env("G1T_USER")?, &env("G1T_TOKEN")?); | |
| 102 | let workdir = Path::new(WORKDIR); | |
| 103 | ||
| Show the model behind each choice; toolchains in the sandbox | 104 | if let Ok(model) = std::env::var("AGENT_MODEL_NAME") { |
| 105 | reporter.record(Entry::new("note", &format!("Running on {model}."))); | |
| 106 | } | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 107 | reporter.record(Entry::new("prompt", &prompt)); |
| 108 | reporter.flush(); | |
| 109 | ||
| 110 | std::fs::create_dir_all("/work")?; | |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 111 | clone::clone(Path::new("/work"), &auth, &[], &remote, WORKDIR).context("could not clone the pull request's fork")?; |
| Diffs on attempts; hosted agent presented as the g1t agent | 112 | git(workdir, &["config", "user.name", "g1t agent"])?; |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 113 | git(workdir, &["config", "user.email", "agent@g1t.sh"])?; |
| 114 | let branch = git(workdir, &["rev-parse", "--abbrev-ref", "HEAD"])?; | |
| 115 | let start = git(workdir, &["rev-parse", "HEAD"]).unwrap_or_default(); | |
| 116 | ||
| Agents as a team: lifecycle, merge queue, billing and a new shell | 117 | // Sent back to work that is already open: start from where the branch it |
| 118 | // will land on is now, so what passes here passes there too. | |
| 119 | if let (Ok(upstream), Ok(upstream_branch)) = (env("UPSTREAM_REMOTE"), env("UPSTREAM_BRANCH")) { | |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 120 | clone::fetch(workdir, &auth, &upstream, &upstream_branch).context("could not fetch the branch this will land on")?; |
| 121 | // Shallow: deep enough to tell whether it is behind, and to merge. | |
| 122 | clone::share_history(workdir, &auth, &[("origin", branch.as_str()), (upstream.as_str(), upstream_branch.as_str())], "HEAD", "FETCH_HEAD")?; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 123 | let behind = Command::new("git") |
| 124 | .current_dir(workdir) | |
| 125 | .args(["merge-base", "--is-ancestor", "FETCH_HEAD", "HEAD"]) | |
| 126 | .status() | |
| 127 | .is_ok_and(|status| !status.success()); | |
| 128 | if behind { | |
| 129 | let message = format!("Catch up with {upstream_branch}"); | |
| 130 | let merged = Command::new("git") | |
| 131 | .current_dir(workdir) | |
| 132 | .args(["merge", "--quiet", "--no-edit", "-m", &message, "FETCH_HEAD"]) | |
| 133 | .status() | |
| 134 | .is_ok_and(|status| status.success()); | |
| 135 | if merged { | |
| 136 | reporter.record(Entry::new( | |
| 137 | "note", | |
| 138 | &format!("Merged in the latest {upstream_branch} before starting."), | |
| 139 | )); | |
| 140 | } else { | |
| 141 | let files = git(workdir, &["diff", "--name-only", "--diff-filter=U"])?; | |
| 142 | let files: Vec<&str> = files.lines().collect(); | |
| 143 | reporter.record(Entry::new( | |
| 144 | "note", | |
| 145 | &format!( | |
| 146 | "Merged in the latest {upstream_branch} before starting; {} conflict.", | |
| 147 | files.join(", ") | |
| 148 | ), | |
| 149 | )); | |
| 150 | prompt.push_str(&format!( | |
| 151 | "\n\nBefore you started, the latest {upstream_branch} was merged into this branch, and these files conflict: {}. Resolve the conflicts first, keeping what both sides meant, then address the points above. Leave no conflict markers.", | |
| 152 | files.join(", ") | |
| 153 | )); | |
| 154 | } | |
| 155 | reporter.flush(); | |
| 156 | } | |
| 157 | } | |
| 158 | ||
| Thirteen MCP tools and classic token scopes; agents rate their confidence and can be put on an issue in one step | 159 | // The agent is asked what it learned, which goes to memory, and how sure |
| 160 | // it is of its change, which g1t weighs with what it observes. Neither | |
| 161 | // stays in the summary. | |
| 162 | let asked = confidence::ask(&learned::ask(&prompt)); | |
| 163 | let summary = confidence::finish(learned::finish(harness::run_claude(workdir, &asked, reporter)?)); | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 164 | |
| 165 | // Commit whatever the agent left in the working tree. | |
| 166 | if !git(workdir, &["status", "--porcelain"])?.is_empty() { | |
| 167 | let message = std::env::var("COMMIT_MESSAGE").unwrap_or_else(|_| "Agent changes".into()); | |
| 168 | git(workdir, &["add", "--all"])?; | |
| 169 | git(workdir, &["commit", "--quiet", "--message", &message])?; | |
| 170 | } | |
| 171 | let head = git(workdir, &["rev-parse", "HEAD"])?; | |
| 172 | if head == start { | |
| Agents asked while not at work are woken to answer | 173 | // An agent woken to answer usually only answers. |
| 174 | if std::env::var("MODE").as_deref() == Ok("answer") { | |
| 175 | return Ok(summary); | |
| 176 | } | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 177 | bail!("the agent finished without changing anything"); |
| 178 | } | |
| 179 | git( | |
| 180 | workdir, | |
| 181 | &[ | |
| 182 | "-c", | |
| 183 | &auth, | |
| 184 | "push", | |
| 185 | "--quiet", | |
| 186 | "origin", | |
| 187 | &format!("HEAD:{branch}"), | |
| 188 | ], | |
| 189 | ) | |
| Issues and pull requests replace intents and attempts | 190 | .context("could not push the pull request's commits")?; |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 191 | reporter.record(Entry::new( |
| 192 | "note", | |
| Issues and pull requests replace intents and attempts | 193 | &format!("Pushed {}.", &head[..head.len().min(12)]), |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 194 | )); |
| 195 | Ok(summary) | |
| 196 | } | |
| 197 | ||
| 198 | fn main() { | |
| Fast pages, required checks on the branch, self-hosted runners, honest incidents | 199 | // A self-hosted runner's commands; the modes below are what it, and |
| 200 | // g1t's sandboxes, run work with. | |
| 201 | let args: Vec<String> = std::env::args().skip(1).collect(); | |
| 202 | if selfhosted::is_command(&args) { | |
| 203 | std::process::exit(selfhosted::main(args)); | |
| 204 | } | |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 205 | // A guarded sandbox's HTTPS is re-signed on its way out: trust that |
| 206 | // before anything is fetched. The guard hook runs before every tool | |
| 207 | // call, so it skips this. | |
| 208 | if std::env::var("MODE").as_deref() == Ok("guard") { | |
| 209 | std::process::exit(guard::hook_main()); | |
| 210 | } | |
| 211 | guard::trust_egress_ca(); | |
| Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look | 212 | // Watches for mining for as long as the sandbox runs (abuse.rs). Not in |
| 213 | // the hooks the harness runs after every tool call. | |
| 214 | if std::env::var("MODE").as_deref() != Ok("steer") { | |
| 215 | abuse::watch(); | |
| 216 | } | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 217 | // The same image does the other jobs a sandbox is started for. |
| 218 | match std::env::var("MODE").as_deref() { | |
| GitHub Actions on g1t, part two: running workflows | 219 | Ok("actions") => std::process::exit(actions::main()), |
| Git storage hardened, pages in tens of milliseconds, honest security alerts, and costs reconciled daily | 220 | Ok("bump") => std::process::exit(bump::main()), |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 221 | Ok("checks") => std::process::exit(checks::main()), |
| Deployments: a preview for every pull request, production on g1t.page | 222 | Ok("deploy") => std::process::exit(deploy::main()), |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 223 | Ok("update") => std::process::exit(update::main()), |
| 224 | Ok("review") => std::process::exit(review::main()), | |
| 225 | Ok("revise") => std::process::exit(revise::main()), | |
| Agents asked while not at work are woken to answer | 226 | Ok("answer") => std::process::exit(revise::answer()), |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 227 | Ok("plan") => std::process::exit(plan::main()), |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 228 | Ok("reply") => std::process::exit(reply::main()), |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 229 | Ok("queue") => std::process::exit(queue::main()), |
| Agents and memory, checks and conflicts, profiles, slug renames, custom domains | 230 | Ok("mergecheck") => std::process::exit(mergecheck::main()), |
| Usage, like a hosting provider's: what agents cost, per day, task, repository and pull request | 231 | Ok("steer") => std::process::exit(steer::main()), |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 232 | _ => {} |
| Acceptance checks in sandboxes, line comments and review verdicts | 233 | } |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 234 | let mut reporter = match Reporter::from_env() { |
| 235 | Ok(reporter) => reporter, | |
| 236 | Err(error) => { | |
| 237 | eprintln!("g1t-runner: {error:#}"); | |
| 238 | std::process::exit(2); | |
| 239 | } | |
| 240 | }; | |
| 241 | match run(&mut reporter) { | |
| 242 | Ok(summary) => { | |
| 243 | reporter.flush(); | |
| Issues and pull requests replace intents and attempts | 244 | if let Err(error) = reporter.ready(&summary) { |
| 245 | eprintln!("g1t-runner: could not mark the pull request ready: {error:#}"); | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 246 | std::process::exit(1); |
| 247 | } | |
| 248 | } | |
| 249 | Err(error) => { | |
| 250 | eprintln!("g1t-runner: {error:#}"); | |
| Agents get guardrails, run credentials, an audit log, a context hub, repository instructions and mentions; security upkeep; snake_case API | 251 | // Stopped at a cap: like a person's stop, the pull request is |
| 252 | // left open for a person, not closed. | |
| 253 | if guard::is_halt(&error) { | |
| 254 | reporter.record(Entry::new("note", &format!("g1t stopped the agent: {error:#}."))); | |
| 255 | reporter.flush(); | |
| 256 | std::process::exit(1); | |
| 257 | } | |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 258 | reporter.record(Entry::new("note", &format!("The run failed: {error:#}"))); |
| 259 | reporter.flush(); | |
| Issues and pull requests replace intents and attempts | 260 | let _ = reporter.close(); |
| Account dropdown, llms.txt onboarding, hosted agent runner (not yet deployed) | 261 | std::process::exit(1); |
| 262 | } | |
| 263 | } | |
| 264 | } |