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 assessment REVIEW_ID [ASSESSMENT_ID]` (or `--environment NAME`) reads one environment assessment's evaluated risk domains, authorized subjects, checks, and findings (`findings:read`). `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 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
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const OPERATIONS: &[(&str, &str, &[&str])] = &[
("get", "export_reviews", &["dataset"]),
("get", "get_agent_session", &["session_id"]),
("get", "get_agent_session_prompt", &["finding_id"]),
("get", "get_assessment", &["review_id", "assessment_id"]),
(
"get",
"get_commit_deploy_verifications",
Expand Down
25 changes: 21 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use uuid::Uuid;

use crate::github_actions::Renewal;
use crate::model::{
CommitDeployVerifications, CommitReviewRequest, CommitReviewResponse, CoverageUploadRequest,
CoverageUploadResponse, FileReviewRequest, FileReviewResponse, PatchReviewRequest,
PatchReviewResponse, RepositoryNames, ReviewDetail, ReviewFilters, ReviewPage, RunNowMode,
RunNowRequest, RunNowResponse, ScanRequest, ScanResponse, StopResponse,
AssessmentDetail, CommitDeployVerifications, CommitReviewRequest, CommitReviewResponse,
CoverageUploadRequest, CoverageUploadResponse, FileReviewRequest, FileReviewResponse,
PatchReviewRequest, PatchReviewResponse, RepositoryNames, ReviewDetail, ReviewFilters,
ReviewPage, RunNowMode, RunNowRequest, RunNowResponse, ScanRequest, ScanResponse, StopResponse,
};
use crate::origin::Origin;
use crate::text::terminal_safe;
Expand Down Expand Up @@ -602,6 +602,23 @@ impl Api {
Ok((raw, typed))
}

/// Fetches one environment assessment of `review_id` as the raw document
/// and its typed reading.
pub async fn assessment(
&self,
review_id: Uuid,
assessment_id: Uuid,
) -> Result<(serde_json::Value, AssessmentDetail), ApiError> {
let review = review_id.to_string();
let assessment = assessment_id.to_string();
let raw = self
.get(self.url_get_assessment(&review, &assessment))
.await?;
let typed = serde_json::from_value(raw.clone())
.map_err(|error| self.http.protocol(error.to_string()))?;
Ok((raw, typed))
}

/// One page of the review collection, newest first.
pub async fn reviews(
&self,
Expand Down
134 changes: 134 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ enum Command {
Reviews(tools::ListArgs),
/// Read the routing decisions of a review as JSON.
Routing { review_id: Uuid },
/// Inspect one environment assessment of a review, including evaluated risk domains.
Assessment(AssessmentArgs),
/// Read a specific recorded pull-request run.
Run(tools::RunArgs),
/// Preview, start or inspect a vendor coding-agent session.
Expand Down Expand Up @@ -292,6 +294,27 @@ struct StopArgs {
json: bool,
}

#[derive(Debug, Args)]
struct AssessmentArgs {
/// Review ID returned by `review`, `reviews` or `findings`.
review_id: Uuid,
/// Assessment ID shown under the environment in `review` or `findings`.
/// Omit when the review has one environment assessment or when selecting
/// with `--environment`.
assessment_id: Option<Uuid>,
/// Environment display name, such as `production`, when `ASSESSMENT_ID`
/// is omitted.
#[arg(long, value_name = "NAME", conflicts_with = "assessment_id")]
environment: Option<String>,
/// Print the server's assessment document as JSON instead of text.
#[arg(long)]
json: bool,
/// Exit 3 when the completed assessment has an unresolved finding at or
/// above this severity.
#[arg(long, value_enum, value_name = "SEVERITY")]
fail_on: Option<Severity>,
}

#[derive(Debug, Args)]
struct LocalSelectionArgs {
/// Review the original index against the base, excluding unstaged changes.
Expand Down Expand Up @@ -526,6 +549,10 @@ pub async fn run(cli: Cli, token: Option<SecretString>) -> anyhow::Result<Verdic
.await?,
)
}
Command::Assessment(args) => {
let api = connect(Http::new(origin)?, token, cli.org).await?;
assessment(&api, &args).await
}
Command::Run(args) => {
let api = connect(Http::new(origin)?, token, cli.org).await?;
let runs = pull_request_runs(&api, &args.repository, args.pr).await?;
Expand Down Expand Up @@ -1206,6 +1233,113 @@ async fn finish(api: &Api, review_id: Uuid, args: &ReviewArgs) -> anyhow::Result
.await
}

async fn assessment(api: &Api, args: &AssessmentArgs) -> anyhow::Result<Verdict> {
let assessment_id = resolve_assessment_id(api, args).await?;
let (raw, detail) = match api.assessment(args.review_id, assessment_id).await {
Ok(result) => result,
Err(error) if error.status() == Some(403) => {
return Err(anyhow::Error::new(error).context(
"this sign-in cannot read assessment details; run `proofline login` and keep the findings:read permission",
));
}
Err(error) => return Err(error.into()),
};
outcome::same_assessment(&detail, args.review_id, assessment_id)?;
let state = outcome::assessment_terminal(&detail);
if args.json {
tools::json(&raw)?;
} else {
write!(
std::io::stdout().lock(),
"{}",
render::assessment_detail(&detail, state, &api.review_url(args.review_id))
)?;
}
match state {
Some(Outcome::Completed) => {
if args
.fail_on
.is_some_and(|threshold| outcome::assessment_findings_reach(&detail, threshold))
{
say("The assessment has an open finding at or above the --fail-on severity.");
return Ok(Verdict::ThresholdReached);
}
Ok(Verdict::Done)
}
Some(ended) => {
say_not_complete(ended);
Ok(Verdict::NotComplete)
}
None => {
say("The assessment has not finished, so it has no complete result.");
Ok(Verdict::NotComplete)
}
}
}

async fn resolve_assessment_id(api: &Api, args: &AssessmentArgs) -> anyhow::Result<Uuid> {
if let Some(id) = args.assessment_id {
return Ok(id);
}
let (_, review) = match api.review(args.review_id).await {
Ok(result) => result,
Err(error) if error.status() == Some(403) => {
return Err(anyhow::Error::new(error).context(
"this sign-in cannot read the review to resolve an environment assessment; pass ASSESSMENT_ID directly or sign in with reviews:read",
));
}
Err(error) => return Err(error.into()),
};
outcome::same_review(&review, args.review_id)?;
if review.assessments.is_empty() {
bail!("review {} has no environment assessments", args.review_id);
}
if let Some(environment) = &args.environment {
let mut matches = review.assessments.iter().filter(|item| {
item.environment_display_name
.eq_ignore_ascii_case(environment)
});
return match (matches.next(), matches.next()) {
(Some(found), None) => Ok(found.id),
(None, _) => bail!(
"review {} has no assessment for environment {:?}; available: {}",
args.review_id,
text::one_line(environment),
available_assessments(&review.assessments)
),
(Some(_), Some(_)) => bail!(
"review {} has more than one assessment named {:?}; pass ASSESSMENT_ID directly: {}",
args.review_id,
text::one_line(environment),
available_assessments(&review.assessments)
),
};
}
if let [only] = review.assessments.as_slice() {
return Ok(only.id);
}
bail!(
"review {} has {} environment assessments; pass ASSESSMENT_ID or --environment NAME: {}",
args.review_id,
review.assessments.len(),
available_assessments(&review.assessments)
)
}

fn available_assessments(assessments: &[model::Assessment]) -> String {
assessments
.iter()
.map(|item| {
format!(
"{} ({})",
text::one_line(&item.environment_display_name),
item.id
)
})
.collect::<Vec<_>>()
.join(", ")
}

async fn findings(api: &Api, args: &FindingsArgs) -> anyhow::Result<Verdict> {
let review_id = match (&args.selector.review, args.selector.pr) {
(Some(id), _) => *id,
Expand Down
45 changes: 45 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,26 @@ pub struct StoredCheckResult {

#[derive(Debug, Deserialize, Serialize)]
pub struct ReviewSubject {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub id: Option<Uuid>,
pub kind: String,
pub role: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub repository_full_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub commit_sha: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub artifact_digest: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub workflow_run_id: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub workflow_attempt: Option<i32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deployment_external_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub patch_digest: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
pub file_scope: Option<FileScope>,
}

Expand Down Expand Up @@ -230,6 +248,33 @@ pub struct Assessment {
pub release_evidence_gap: Option<String>,
}

/// One risk domain evaluated (or skipped) for an environment assessment.
#[derive(Debug, Deserialize, Serialize)]
pub struct AssessmentDomain {
pub domain: String,
pub status: String,
pub reason: String,
}

/// Detailed view of one environment assessment, including evaluated risk domains
/// and authorized review subjects.
#[derive(Debug, Deserialize, Serialize)]
pub struct AssessmentDetail {
pub review_id: Uuid,
pub id: Uuid,
pub environment_display_name: String,
pub status: String,
pub started_at: Option<String>,
pub completed_at: Option<String>,
pub domains: Vec<AssessmentDomain>,
pub findings: Vec<Finding>,
pub checks: Checks,
pub subjects: Vec<ReviewSubject>,
pub incompleteness_kind: Option<String>,
pub reason_codes: Option<Vec<String>>,
pub release_evidence_gap: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Checks {
pub receipt_recorded: bool,
Expand Down
Loading