Skip to content

Add proofline scan for whole-repository scans - #67

Merged
mohsen1 merged 1 commit into
prooflinedev:mainfrom
khanzzirfan:feat/scan
Nov 17, 2026
Merged

mohsen1 merged 1 commit into
prooflinedev:mainfrom
khanzzirfan:feat/scan

Conversation

@khanzzirfan

@khanzzirfan khanzzirfan commented Nov 17, 2026 •

Copy link
Copy Markdown

Who this helps

Teams that want a scan of a whole repository at a known point (a nightly scan of main, a pre-release scan of a tag, or a scan of the exact commit a deploy is about to ship) from cron or CI, without opening the console.

The public contract already describes this (request_scan, POST /repositories/{repo_id}/scans, scope scans:request), but no CLI command used it. This adds the command:

proofline scan --ref main --budget 200              # waits and prints the result like `proofline review`
proofline scan --commit <full SHA> --budget 50 --no-wait --json

Decisions

A scan spends credits, so the command is built around never spending money the caller did not choose and never paying twice.

  • --budget is required and has no default. It must be 1 or more. The organization's on-demand limit still caps it on the server.
  • One POST, never repeated. The CLI generates the request_id (UUID v7) unless --request-id is given, and prints it before sending. The client already never replays a POST; this command keeps that.
  • An unknown outcome exits 4 and names the safe retry. If the connection fails, the server returns 5xx, or the answer can't be read, the scan may have started. The command exits 4 (the code ci review already uses when Proofline gives no answer) and prints the --request-id that reads the first resolution instead of starting a second scan. A definite refusal (400, 403, 404) created nothing, so it shows only the server's reason, with no retry hint.
  • Every outcome is explicit. CREATED and EXISTING follow the scan review. REPOSITORY_UNAVAILABLE exits 1, says nothing was spent, and says to omit --request-id to ask again, because repeating the same ID returns the same answer. With --json that resolution still goes to stdout for scripts. An unknown outcome is not followed and asks the user to update the CLI.
  • A missing scope says which login to run. The default sign-in does not request scans:request, and --scope replaces the defaults, so a 403 prints the full proofline login command with the default scopes plus scans:request.
  • Input is checked before any network call. --ref and --commit are mutually exclusive and one is required. --commit must be a full SHA (40 or 64 hex, normalized to lowercase); --ref must not be blank.
  • Terminal output is sanitized. The repository name, the ref and the server's outcome pass through terminal_safe/one_line, like the rest of the CLI's output.
  • It reuses the existing pieces. The route builder comes from build.rs (request_scan declared beside its siblings), repository lookup from connected_repository, and waiting and printing from show, so --timeout, --json and exit codes 0/2 behave as in proofline review.

Left out on purpose: no --ref HEAD resolution on the client (GitHub resolves the ref on the server, once, as the contract says), and no MCP or SDK changes.

Outcomes at a glance

flowchart TD
    A["proofline scan --ref REF | --commit SHA --budget N"] --> V{"Input valid?"}
    V -- no --> X["Refused before any request<br/>exit 1"]
    V -- yes --> R["Print the request ID, then send one POST"]
    R --> S{"Server answer"}
    S -- "CREATED or EXISTING" --> W["Wait for the scan review and print it<br/>exit 0 complete, 2 incomplete or unfinished"]
    S -- "REPOSITORY_UNAVAILABLE" --> U["Nothing started, nothing spent<br/>exit 1; omit --request-id to ask again"]
    S -- "400 or 404" --> F["The server's reason, no retry hint<br/>exit 1"]
    S -- "403" --> L["The proofline login command to run<br/>exit 1"]
    S -- "5xx, dropped connection or unreadable answer" --> Q["Outcome unknown<br/>exit 4; rerun with --request-id"]
    S -- "unknown outcome" --> K["Not followed; update the CLI<br/>exit 1"]
    Q -. "same request ID returns the first resolution" .-> R
Loading

Demo

proofline scan against a local stand-in for the API

Recorded against a local stand-in for the three endpoints the command uses (mock_console.py), not against production, and the review content is made up. It shows the required budget, a scan waiting for its result, a 502 after the server accepted the request (exit 4 with the request ID), and the rerun with that ID returning the existing scan instead of starting a second one.

How I verified it

  • cargo fmt --check and cargo clippy --locked --all-targets -- -D warnings are clean.
  • cargo test --locked: all targets pass, including 9 new integration tests in tests/scan.rs. They run the real binary against a loopback stand-in for the console and check:
    • the exact JSON body for --ref and --commit (fields named, nothing extra, SHA lowercased);
    • exactly one POST on a 500 and on an unreadable 200, with exit 4 and the safe --request-id printed;
    • REPOSITORY_UNAVAILABLE exits 1, prints the resolution with --json, and explains how to ask again;
    • a 400 shows the server's reason without suggesting a retry; a 403 prints the login command;
    • an unknown outcome containing terminal escape codes is refused and the escape never reaches stderr;
    • nine malformed invocations are refused before any network call.
  • On macOS, tests/agent_install.rs fails on unmodified main too (/var vs /private/var), unrelated to this change; it passes on Linux CI.
  • Not verified against production: I have no organization with scan credits, so the 400 refusal body is modelled on the RunNowRefused schema in openapi.public.json.

Request a scan of one ref or exact commit through the public
request_scan operation, within a required credit budget.

- --budget has no default, so a scan never spends an unchosen amount.
- The request ID is printed before sending and the POST is never
  repeated; an unknown outcome exits 4 and names the --request-id that
  reads the first resolution instead of starting a second scan.
- REPOSITORY_UNAVAILABLE, definite refusals, a missing scans:request
  scope and unknown outcomes each get a distinct message.
- Malformed input is refused before any network call.

@mohsen1 mohsen1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex

Reviewed the scan operation, explicit budget, exact commit/ref selection and request identity handling. Required check and windows jobs passed on this head.

@mohsen1
mohsen1 merged commit 9a20b64 into prooflinedev:main Nov 17, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants