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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Native knowledge, plan, fix and configuration commands send the selected organiz

`proofline review --path src/main.rs` reviews only that file's local changes against the normal merge-base. The path is literal and repository-relative; the command refuses directories, globs, and `..`. Combine it with `--staged` to read the index, or `--include-untracked` to select a new, non-ignored file. The command preserves the real index and applies the usual secret preflight. You cannot combine `--path` with pushed-commit, range, or pull-request review.

`proofline reviews --repository-id UUID --cursor CURSOR` returns one page with its continuation metadata, and all flags are optional. `proofline routing REVIEW_ID` reads recorded routing. `proofline run --repo owner/name --pr 7 --run 2` reads one retained run, and `proofline history --repo owner/name --pr 7` reads all recorded runs. Both commands send the API the name without its owner, and use the response only when its repository choices list `owner/name`, or the Git remote's owner and name, among the organization's reviewed repositories. A repository with no reviews in the organization exits nonzero. `proofline findings --pr 7` finds the pull request's newest review through the same route and counts only runs of the repository whose full name matches. None of these commands reads the organization's review list.
`proofline reviews --repository-id UUID --cursor CURSOR` returns one page with its continuation metadata, and all flags are optional. `proofline routing REVIEW_ID` reads recorded routing. `proofline run --repo owner/name --pr 7 --run 2` reads one retained run, and `proofline history --repo owner/name --pr 7` reads all recorded runs. Both commands send the API the name without its owner, and use the response only when its repository choices list `owner/name`, or the Git remote's owner and name, among the organization's reviewed repositories. A repository with no reviews in the organization exits nonzero. `proofline findings --pr 7` finds the pull request's newest review through the same route and counts only runs of the repository whose full name matches, while `proofline walkthrough --pr 7` renders its reading-order file groups, per-file notes, and skipped-file reasons. None of these commands reads the organization's review list.

`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.

Expand Down
198 changes: 184 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
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),
/// Show the reading-order file walkthrough of a pull request, commit, or review.
Walkthrough(WalkthroughArgs),
/// Forward a coding agent's stdio messages to this console's MCP server.
Mcp,
/// Commands for a CI job.
Expand Down Expand Up @@ -399,6 +401,19 @@ struct FindingsArgs {
output: OutputArgs,
}

#[derive(Debug, Args)]
struct WalkthroughArgs {
#[command(flatten)]
selector: Selector,
/// Wait for the review's walkthrough to be stored.
#[arg(long)]
wait: bool,
#[command(flatten)]
repository: RepositoryArgs,
#[command(flatten)]
output: OutputArgs,
}

#[derive(Debug, Clone, Copy)]
enum OutputFormat {
Text,
Expand Down Expand Up @@ -607,6 +622,13 @@ 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::Walkthrough(args) => {
if let Some(head) = &args.selector.head {
git::commit_sha(head)?;
}
let api = connect(Http::new(origin)?, token, cli.org).await?;
walkthrough(&api, &args).await
}
Command::Mcp => {
let http = Http::new(origin)?;
let credential = credentials::load(http.origin(), token, cli.org).await?;
Expand Down Expand Up @@ -1206,25 +1228,33 @@ async fn finish(api: &Api, review_id: Uuid, args: &ReviewArgs) -> anyhow::Result
.await
}

async fn findings(api: &Api, args: &FindingsArgs) -> anyhow::Result<Verdict> {
let review_id = match (&args.selector.review, args.selector.pr) {
(Some(id), _) => *id,
(None, Some(number)) => pull_request_review(api, &args.repository, number).await?,
async fn resolve_review_id(
api: &Api,
selector: &Selector,
repository: &RepositoryArgs,
) -> anyhow::Result<Uuid> {
match (&selector.review, selector.pr) {
(Some(id), _) => Ok(*id),
(None, Some(number)) => pull_request_review(api, repository, number).await,
(None, None) => {
let sha = match &args.selector.head {
let sha = match &selector.head {
Some(raw) => git::commit_sha(raw)?,
None => git::head().await?,
};
let (name, repository_id) = reviewed_repository(api, &args.repository).await?;
let (name, repository_id) = reviewed_repository(api, repository).await?;
// An audit is a revision scan of this commit too, but its
// findings are in its report, so it never answers for the head.
latest(api, repository_id, &sha, |item| {
item.audit_mode.is_none() && item.head_commit_sha.as_deref() == Some(sha.as_str())
})
.await?
.with_context(|| format!("no review of {name} has head commit {sha}; push it and open a pull request, or name one with --pr"))?
.await?
.with_context(|| format!("no review of {name} has head commit {sha}; push it and open a pull request, or name one with --pr"))
}
};
}
}

async fn findings(api: &Api, args: &FindingsArgs) -> anyhow::Result<Verdict> {
let review_id = resolve_review_id(api, &args.selector, &args.repository).await?;
let format = if args.sarif {
OutputFormat::Sarif
} else {
Expand All @@ -1233,6 +1263,54 @@ async fn findings(api: &Api, args: &FindingsArgs) -> anyhow::Result<Verdict> {
show(api, review_id, args.wait, &args.output, format, None).await
}

async fn walkthrough(api: &Api, args: &WalkthroughArgs) -> anyhow::Result<Verdict> {
let review_id = resolve_review_id(api, &args.selector, &args.repository).await?;
let deadline = if args.wait {
Some(poll_deadline(args.output.timeout)?)
} else {
None
};
let Some((raw, detail, state)) =
read_review_until(api, review_id, deadline, false, |detail, terminal| {
terminal.is_some() || detail.walkthrough.is_some()
})
.await?
else {
say_not_established(api, review_id, args.output.timeout);
return Ok(Verdict::Unavailable);
};
let Some(walkthrough) = &detail.walkthrough else {
let url = api.review_url(review_id);
match state {
None => say(&format!(
"No walkthrough is stored for this review yet (status: {}); pass --wait or check {url}.",
text::one_line(&detail.status)
)),
Some(_) => say(&format!(
"No walkthrough was recorded for this review ({}); see {url}.",
text::one_line(&detail.status)
)),
}
return Ok(Verdict::NotComplete);
};
let url = api.review_url(review_id);
if args.output.json {
let document = serde_json::json!({
"review_id": detail.id,
"review_url": url.as_str(),
"diff_stats": raw.get("diff_stats").unwrap_or(&serde_json::Value::Null),
"walkthrough": raw.get("walkthrough").unwrap_or(&serde_json::Value::Null),
});
return tools::json(&document);
}
write!(
std::io::stdout().lock(),
"{}",
render::walkthrough(&detail, walkthrough, &url)
)?;
Ok(Verdict::Done)
}

#[derive(Debug, thiserror::Error)]
#[error("--timeout {minutes} minutes is too large to wait; choose a shorter timeout")]
struct PollTimeoutTooLarge {
Expand Down Expand Up @@ -1264,6 +1342,16 @@ async fn read_review(
review_id: Uuid,
deadline: Option<tokio::time::Instant>,
sarif: bool,
) -> anyhow::Result<Option<ReviewRead>> {
read_review_until(api, review_id, deadline, sarif, |_, state| state.is_some()).await
}

async fn read_review_until(
api: &Api,
review_id: Uuid,
deadline: Option<tokio::time::Instant>,
sarif: bool,
ready: impl Fn(&ReviewDetail, Option<Outcome>) -> bool,
) -> anyhow::Result<Option<ReviewRead>> {
let deadline = match deadline {
Some(deadline) if tokio::time::Instant::now() < deadline => deadline,
Expand All @@ -1278,13 +1366,10 @@ async fn read_review(
};
let read = read?;
let now = tokio::time::Instant::now();
if read.2.is_some() || now >= deadline {
if ready(&read.1, read.2) || now >= deadline {
return Ok(Some(read));
}
say(&format!(
"Review is {}; checking again in {delay} seconds.",
text::one_line(&read.1.status)
));
say(&poll_status(&read.1, delay));
tokio::time::sleep_until(deadline.min(now + Duration::from_secs(delay))).await;
if tokio::time::Instant::now() >= deadline {
return Ok(Some(read));
Expand All @@ -1293,6 +1378,48 @@ async fn read_review(
}
}

/// Formats a live polling progress line, surfacing `provider_wait` and
/// `run_progress` when the server reports them.
fn poll_status(detail: &ReviewDetail, delay: u64) -> String {
let status = text::one_line(&detail.status);
let context = match (&detail.provider_wait, &detail.run_progress) {
(Some(wait), _) => {
let reason = match wait.reason.as_str() {
"GITHUB_RATE_LIMIT" => "GitHub rate limit".to_owned(),
other => text::one_line(other),
};
format!(
" (waiting on {reason} until {})",
text::one_line(&wait.until)
)
}
(None, Some(progress)) => {
let step = match progress.state.as_str() {
"RETRY_SCHEDULED" => progress.due_at.as_deref().map_or_else(
|| "retry scheduled".to_owned(),
|due| format!("retry scheduled for {}", text::one_line(due)),
),
"QUEUED" => progress.due_at.as_deref().map_or_else(
|| "queued".to_owned(),
|due| format!("queued since {}", text::one_line(due)),
),
"WAITING" => progress.due_at.as_deref().map_or_else(
|| "waiting".to_owned(),
|due| format!("waiting until {}", text::one_line(due)),
),
other => text::one_line(&other.to_ascii_lowercase()),
};
if progress.attempts > 1 {
format!(" ({step}, attempt {})", progress.attempts)
} else {
format!(" ({step})")
}
}
(None, None) => String::new(),
};
format!("Review is {status}{context}; checking again in {delay} seconds.")
}

async fn read_review_once(api: &Api, review_id: Uuid, sarif: bool) -> anyhow::Result<ReviewRead> {
let (raw, detail) = api.review(review_id).await?;
outcome::same_review(&detail, review_id)?;
Expand Down Expand Up @@ -2373,4 +2500,47 @@ mod tests {
Verdict::NotComplete
);
}

#[test]
fn poll_status_surfaces_provider_wait_and_run_progress() {
let mut detail: ReviewDetail = serde_json::from_value(json!({
"id": REQUESTED,
"kind": "PULL_REQUEST",
"status": "PENDING",
"assessment_count": 1,
"assessments": [],
"code_assessment": null,
"base_commit_sha": null,
"head_commit_sha": HEAD,
"open_items": null,
"pull_request_number": 12,
"repository_full_name": "acme/app",
"run_number": 1,
}))
.unwrap();
assert_eq!(
poll_status(&detail, 10),
"Review is PENDING; checking again in 10 seconds."
);

detail.run_progress = Some(model::RunProgress {
state: "RETRY_SCHEDULED".to_owned(),
attempts: 2,
due_at: Some("2026-11-28T12:05:00Z".to_owned()),
last_progress_at: None,
});
assert_eq!(
poll_status(&detail, 20),
"Review is PENDING (retry scheduled for 2026-11-28T12:05:00Z, attempt 2); checking again in 20 seconds."
);

detail.provider_wait = Some(model::ProviderWait {
reason: "GITHUB_RATE_LIMIT".to_owned(),
until: "2026-11-28T12:15:00Z".to_owned(),
});
assert_eq!(
poll_status(&detail, 60),
"Review is PENDING (waiting on GitHub rate limit until 2026-11-28T12:15:00Z); checking again in 60 seconds."
);
}
}
110 changes: 110 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,116 @@ pub struct ReviewDetail {
/// every other review.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub local_reverifications: Vec<LocalReverification>,
/// Where an unfinished review's runs currently stand.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub run_progress: Option<RunProgress>,
/// Provider wait holding this review, such as a GitHub rate limit.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub provider_wait: Option<ProviderWait>,
/// Line totals across changed files in the pinned comparison.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub diff_stats: Option<ReviewDiffStats>,
/// Deterministic pull-request merge gate captured for this head.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub merge_gate: Option<PullRequestMergeGate>,
/// Automatic Deep Review escalation outcome for this comparison.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deep_review_escalation: Option<DeepReviewEscalation>,
/// Public incompleteness causes recorded by incomplete assessments.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub incomplete_causes: Option<Vec<String>>,
/// Reading-order walkthrough of the reviewed head's changed files.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub walkthrough: Option<Walkthrough>,
}

/// Where an unfinished review's runs stand.
#[derive(Debug, Deserialize, Serialize)]
pub struct RunProgress {
pub state: String,
pub attempts: i32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub due_at: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub last_progress_at: Option<String>,
}

/// A provider wait currently holding a review.
#[derive(Debug, Deserialize, Serialize)]
pub struct ProviderWait {
pub reason: String,
pub until: String,
}

/// Line totals across changed files in a review's pinned comparison.
#[derive(Debug, Deserialize, Serialize)]
pub struct ReviewDiffStats {
pub additions: i64,
pub deletions: i64,
}

/// Deterministic pull-request merge gate state for a reviewed head.
#[derive(Debug, Deserialize, Serialize)]
pub struct PullRequestMergeGate {
pub id: Uuid,
pub pull_request_number: i64,
pub head_sha: String,
pub status: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub decision: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub reason_code: Option<String>,
pub policy_version: String,
pub blocking_severity: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub finding_count: Option<i32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub assessment_count: Option<i32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bypassed_at: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub merged_by_login: Option<String>,
}

/// Automatic Deep Review escalation status for a comparison.
#[derive(Debug, Deserialize, Serialize)]
pub struct DeepReviewEscalation {
pub status: String,
pub reason: String,
}

/// Reading-order walkthrough of a review's pinned head.
#[derive(Debug, Deserialize, Serialize)]
pub struct Walkthrough {
pub head_sha: String,
pub groups: Vec<WalkthroughGroup>,
}

/// One logical group of changed files in a walkthrough.
#[derive(Debug, Deserialize, Serialize)]
pub struct WalkthroughGroup {
pub title: String,
pub kind: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub files: Vec<WalkthroughFile>,
}

/// One changed file entry in a walkthrough group.
#[derive(Debug, Deserialize, Serialize)]
pub struct WalkthroughFile {
pub path: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub previous_path: Option<String>,
pub change: String,
pub additions: i64,
pub deletions: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub depth: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub skip_class: Option<String>,
pub line: String,
pub generated: bool,
}

/// One finding a patch review re-verified against the local changes. The
Expand Down
Loading