g1t/crates/runner/src/revise.rs

43 lines1,586 bytesCodeBlame

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.

Agents as a team: lifecycle, merge queue, billing and a new shell1//! Sends the author back to a pull request that is already ready for
Fast pages, required checks on the branch, self-hosted runners, honest incidents2//! review, to address a check that failed on it (the repository's
3//! workflows), the merge queue taking it out, or a review.
Agents as a team: lifecycle, merge queue, billing and a new shell4//!
5//! The work is the same as making the change in the first place (see
6//! `main`): clone the fork, run the agent on `PROMPT`, commit and push.
7//! What differs is the ending. The pull request stays as it is, with the
8//! agent's account of what it changed added to its session, and a failure
9//! leaves it open for a person to look at.
10
11use crate::report::{Entry, Reporter};
12
Agents asked while not at work are woken to answer13/// The author woken to answer what other agents asked it while it was not
14/// at work: the same run, which pushes only if it took on handed-over work.
15pub fn answer() -> i32 {
16 finish(crate::run, "Answering failed")
17}
18
Agents as a team: lifecycle, merge queue, billing and a new shell19pub fn main() -> i32 {
Agents asked while not at work are woken to answer20 finish(crate::run, "The revision failed")
21}
22
23fn finish(run: fn(&mut Reporter) -> anyhow::Result<String>, failed: &str) -> i32 {
Agents as a team: lifecycle, merge queue, billing and a new shell24 let mut reporter = match Reporter::from_env() {
25 Ok(reporter) => reporter,
26 Err(error) => {
27 eprintln!("g1t-runner: {error:#}");
28 return 2;
29 }
30 };
Agents asked while not at work are woken to answer31 let outcome = run(&mut reporter);
Agents as a team: lifecycle, merge queue, billing and a new shell32 // On success the agent's account is already in the session: the harness
33 // records its messages as they arrive.
34 if let Err(error) = &outcome {
35 eprintln!("g1t-runner: {error:#}");
36 reporter.record(Entry::new(
37 "note",
Agents asked while not at work are woken to answer38 &format!("{failed}: {error:#}. Nothing was pushed."),
Agents as a team: lifecycle, merge queue, billing and a new shell39 ));
40 }
41 reporter.flush();
42 i32::from(outcome.is_err())
43}