Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Native knowledge, plan, fix and configuration commands send the selected organiz

`proofline rerun REVIEW_ID` requests the original immutable subject and waits, while `--no-wait` returns its link. Reruns require `reviews:rerun`. `proofline guidance --repo owner/name` requires `guidance:read`, and `proofline fix-prompt FINDING_ID` requires `findings:read`. History, guidance, and fix prompts print JSON; prompt text remains untrusted.

`proofline diff --pr 7` compares findings across the newest recorded review run of a pull request and the run before it, categorizing findings into `resolved` (open previously, now cleared), `persistent` (still open), and `regressions` (newly introduced or reintroduced). Findings are correlated by their semantic fingerprint across runs, falling back to risk domain, claim, and primary location when fingerprints are absent. Pass `--base-run` and `--target-run` to pick specific runs, or `--base-review` and `--target-review` to compare any two reviews. In a Git checkout on a PR branch with a recorded review for the checked-out HEAD commit, `proofline diff` resolves the PR automatically (pass `--pr` explicitly if HEAD has no recorded review). `--fail-on-regression` exits 3 when any new or reintroduced regression is detected against a completed baseline, and returns exit 2 (`Verdict::NotComplete`) if either the target or baseline review is incomplete or unfinished, ensuring CI jobs gate strictly on completed review comparisons. `--json` prints machine-readable output.

`proofline review --range BASE..HEAD --fail-on serious` exits 3 when a complete review has an unresolved finding at or above the threshold. PR reviews use the server’s effective open-item counts; other reviews count unresolved findings. Incomplete and unavailable results retain their nonzero exits. `--fail-on` cannot be combined with `--no-wait`.

In GitHub Actions, `proofline ci review --annotations` prints unresolved findings as workflow annotations at verified cited lines. Findings without a verified head location appear on the job. The review link contains the full result.
Expand Down
16 changes: 14 additions & 2 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,25 @@ impl Api {
self.get(url).await
}

pub(crate) async fn history_page(
&self,
repository: &str,
number: u64,
cursor: Option<&str>,
) -> Result<serde_json::Value, ApiError> {
let mut url = self.url_list_pull_request_reviews(repository, &number.to_string());
if let Some(cursor) = cursor {
url.query_pairs_mut().append_pair("cursor", cursor);
}
self.get(url).await
}

pub(crate) async fn history(
&self,
repository: &str,
number: u64,
) -> Result<serde_json::Value, ApiError> {
self.get(self.url_list_pull_request_reviews(repository, &number.to_string()))
.await
self.history_page(repository, number, None).await
}

/// One pull request's review runs as received, with the review
Expand Down
210 changes: 208 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod tools;

use crate::model::{
CommitReviewRequest, FileReviewRequest, OpenItems, PatchReviewRequest, RepositoryNames,
ReviewDetail, ReviewFilters, ReviewSummary,
ReviewDetail, ReviewFilters, ReviewPage, ReviewSummary,
};
use crate::origin::{DEFAULT_ORIGIN, Origin};
use crate::outcome::Outcome;
Expand Down Expand Up @@ -169,6 +169,8 @@ enum Command {
Stop(StopArgs),
/// Show the findings of the latest review of a commit or pull request.
Findings(FindingsArgs),
/// Compare findings across review runs, identifying resolved, persistent, and new regressions.
Diff(DiffArgs),
/// Forward a coding agent's stdio messages to this console's MCP server.
Mcp,
/// Commands for a CI job.
Expand Down Expand Up @@ -395,6 +397,43 @@ struct FindingsArgs {
output: OutputArgs,
}

#[derive(Debug, Args)]
struct DiffArgs {
/// Pull request number to compare recorded runs for.
#[arg(long, value_name = "NUMBER")]
pr: Option<u64>,
/// Specific review ID for the base (previous) run.
#[arg(
long,
value_name = "ID",
requires = "target_review",
conflicts_with = "pr"
)]
base_review: Option<Uuid>,
/// Specific review ID for the target (current) run.
#[arg(
long,
value_name = "ID",
requires = "base_review",
conflicts_with = "pr"
)]
target_review: Option<Uuid>,
/// Run number for the base review. Defaults to the run before target.
#[arg(long, requires = "pr")]
base_run: Option<u64>,
/// Run number for the target review. Defaults to the latest recorded run.
#[arg(long, requires = "pr")]
target_run: Option<u64>,
/// Exit with code 3 if any new or reintroduced regressions are detected.
#[arg(long)]
fail_on_regression: bool,
#[command(flatten)]
repository: RepositoryArgs,
/// Print machine-readable JSON diff instead of text.
#[arg(long)]
json: bool,
}

#[derive(Debug, Clone, Copy)]
enum OutputFormat {
Text,
Expand Down Expand Up @@ -603,6 +642,10 @@ pub async fn run(cli: Cli, token: Option<SecretString>) -> anyhow::Result<Verdic
let api = connect(Http::new(origin)?, token, cli.org).await?;
findings(&api, &args).await
}
Command::Diff(args) => {
let api = connect(Http::new(origin)?, token, cli.org).await?;
diff(&api, &args).await
}
Command::Mcp => {
let http = Http::new(origin)?;
let credential = credentials::load(http.origin(), token, cli.org).await?;
Expand Down Expand Up @@ -964,7 +1007,7 @@ async fn pull_request_review(
number: u64,
) -> anyhow::Result<Uuid> {
let runs = pull_request_runs(api, args, number).await?;
let page = serde_json::from_value::<model::ReviewPage>(runs.raw)
let page = serde_json::from_value::<ReviewPage>(runs.raw)
.with_context(|| format!("{} returned an unreadable review list", api.origin()))?;
page.items
.iter()
Expand Down Expand Up @@ -1218,6 +1261,169 @@ async fn findings(api: &Api, args: &FindingsArgs) -> anyhow::Result<Verdict> {
show(api, review_id, args.wait, &args.output, format, None).await
}

async fn diff(api: &Api, args: &DiffArgs) -> anyhow::Result<Verdict> {
let (base_detail, target_detail, base_label, target_label) = match (
args.base_review,
args.target_review,
args.pr,
) {
(Some(base_id), Some(target_id), _) => {
let (_, base_detail) = api.review(base_id).await?;
let (_, target_detail) = api.review(target_id).await?;
let base_label = format!("review {}", base_detail.id);
let target_label = format!("review {}", target_detail.id);
(Some(base_detail), target_detail, base_label, target_label)
}
(None, None, pr_opt) => {
let (full_name, repository_id) = reviewed_repository(api, &args.repository).await?;
let pr = if let Some(pr) = pr_opt {
pr
} else {
let sha = git::head().await?;
let review_id = latest(api, repository_id, &sha, |item| {
item.audit_mode.is_none()
&& item.pull_request_number.is_some()
&& item.head_commit_sha.as_deref() == Some(sha.as_str())
})
.await?
.with_context(|| {
format!(
"no pull request review of {full_name} has head commit {sha}; push it and open a pull request, or name one with --pr"
)
})?;
let (_, detail) = api.review(review_id).await?;
let pr_num = detail.pull_request_number.with_context(|| {
format!(
"review {review_id} for {sha} is not associated with a pull request; pass --pr or --base-review and --target-review"
)
})?;
u64::try_from(pr_num).context("invalid pull request number")?
};

let mut runs: Vec<(i64, Uuid)> = Vec::new();
let mut cursor: Option<String> = None;
let mut page_count = 0;
loop {
let history_raw = api
.history_page(route_name(&full_name), pr, cursor.as_deref())
.await?;
let history_page: ReviewPage = serde_json::from_value(history_raw)
.context("could not parse pull request history")?;
for item in history_page.items {
if item.kind == "PULL_REQUEST"
&& item.repository_id == Some(repository_id)
&& item.pull_request_number == i64::try_from(pr).ok()
&& let Some(num) = item.run_number
{
runs.push((num, item.id));
}
}
page_count += 1;
let found_requested = match (args.base_run, args.target_run) {
(Some(b), Some(t)) => {
let (b_i, t_i) = (b as i64, t as i64);
runs.iter().any(|&(n, _)| n == b_i) && runs.iter().any(|&(n, _)| n == t_i)
}
(Some(b), None) => runs.iter().any(|&(n, _)| n == b as i64),
(None, Some(t)) => {
let t_i = t as i64;
runs.iter().any(|&(n, _)| n == t_i) && runs.iter().any(|&(n, _)| n < t_i)
}
(None, None) => page_count >= SEARCH_PAGES && runs.len() >= 2,
};
if found_requested {
break;
}
match history_page.next_cursor {
Some(next) if cursor.as_ref() != Some(&next) => cursor = Some(next),
_ => break,
}
}
runs.sort_by_key(|&(num, _)| num);
runs.dedup_by_key(|&mut (num, _)| num);

if runs.is_empty() {
bail!("{full_name} #{pr} has no recorded runs");
}

let target_run = if let Some(r) = args.target_run {
r
} else {
let max_run = runs.last().unwrap().0;
u64::try_from(max_run).context("invalid target run number")?
};
let target_run_i64 = i64::try_from(target_run).context("target run out of range")?;
let target_item = runs
.iter()
.find(|&&(num, _)| num == target_run_i64)
.with_context(|| format!("{full_name} #{pr} has no run {target_run}"))?;
let (_, target_detail) = api.review(target_item.1).await?;

let base_run_opt: Option<u64> = args.base_run.or_else(|| {
runs.iter()
.filter(|&&(num, _)| num < target_run_i64)
.map(|&(num, _)| num)
.next_back()
.and_then(|num| u64::try_from(num).ok())
});

let base_detail = match base_run_opt {
Some(base_run) => {
let base_run_i64 = i64::try_from(base_run).context("base run out of range")?;
let base_item = runs
.iter()
.find(|&&(num, _)| num == base_run_i64)
.with_context(|| format!("{full_name} #{pr} has no run {base_run}"))?;
let (_, detail) = api.review(base_item.1).await?;
Some(detail)
}
None => None,
};

let base_label = base_run_opt.map_or_else(
|| format!("{full_name} #{pr} initial baseline"),
|r| format!("{full_name} #{pr} run {r}"),
);
let target_label = format!("{full_name} #{pr} run {target_run}");

(base_detail, target_detail, base_label, target_label)
}
_ => bail!("specify either --pr, or both --base-review and --target-review"),
};

let prev_findings = base_detail
.as_ref()
.map(outcome::all_findings)
.unwrap_or_default();
let curr_findings = outcome::all_findings(&target_detail);
let diff_result = outcome::diff_findings(&prev_findings, &curr_findings);

let mut stdout = std::io::stdout().lock();
if args.json {
writeln!(stdout, "{}", serde_json::to_string_pretty(&diff_result)?)?;
} else {
writeln!(
stdout,
"{}",
render::diff(&diff_result, &base_label, &target_label)
)?;
}

if args.fail_on_regression {
if target_detail.status != "COMPLETED"
|| base_detail
.as_ref()
.is_some_and(|b| b.status != "COMPLETED")
{
return Ok(Verdict::NotComplete);
}
if !diff_result.regressions.is_empty() {
return Ok(Verdict::Regressed);
}
}
Ok(Verdict::Done)
}

#[derive(Debug, thiserror::Error)]
#[error("--timeout {minutes} minutes is too large to wait; choose a shorter timeout")]
struct PollTimeoutTooLarge {
Expand Down
4 changes: 2 additions & 2 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ pub struct Check {
pub unresolved_reason: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Finding {
pub id: Uuid,
/// The retained semantic identity that correlates this finding's
Expand All @@ -262,7 +262,7 @@ pub struct Finding {
pub evidence_refs: Vec<EvidenceRef>,
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct EvidenceRef {
pub kind: String,
pub label: String,
Expand Down
Loading