← Back to Pull requests

feat(sci): the CLI's SCI API access — proof of concept alongside foundry#171 #75

Open
unknown opened this pull request with 385 lines diff across 4 files
View on GitHub
unknown unknown commented on Dec 02, 2026 18:44 UTC
Author

Proof of concept alongside the architecture plan foundry#171 — implementation-to-plan pairing for user API access (Phase 2 of the plan). Not for merge until the foundry plan is approved.

Note: traust-cli has no \development\ branch (main is the trunk), so this branches off main. Sibling PR: source-code-intelligence#449 (Phase 1 — the API's session-registration endpoint this client calls).

What

\traust sci\ — the CLI talks to SCI's API as the user, with console-equivalent permissions (the token is the user; SCI's RBAC is transport-agnostic — no scoping in v1):

  • \traust sci login\ — authorization-code + PKCE loopback as the universal primary (works against the corporate Keycloak on stage/prod), RFC 8628 device code auto-selected when the issuer's discovery publishes \device_authorization_endpoint\ (e.g. integration Dex). \--flow=auto|device|pkce\, \--listen\ for the loopback port (default 127.0.0.1:8976), \--issuer\/\--client-id\ (default \sci-cli\).

  • \traust sci logout\ — revokes the server-side session (bearer hash) and deletes the local credential.

  • \traust sci status\ — stored credential, expiry, storage backend, who SCI sees (\/api/v1/me\).

  • \traust sci inventory list|get <id>\, \traust sci findings list <inventory-id>\ — the read-only v1 queries, tables by default, \--json\ for scripting.

  • On login the CLI exchanges the fresh ID token at SCI's \POST /api/v1/auth/session\ (foundry#171 Phase 1) so the bearer path admits it; on 401 it refreshes once, re-registers, and retries once before failing.
  • Credential storage (keychain-first, 0600 fallback)

    OS keychain via go-keyring (macOS Keychain / Secret Service / Credential Manager) with a 0600 file fallback under \<workspace>/cli/sci-credentials.json\ for headless hosts; the fallback refuses world-readable files. Never in \state.json\, never on argv, never logged. The SCI-side registration never receives the refresh token.

    Verified

  • \go test -race ./...\ green (including new \internal/sci\ and \cmd/sci_test.go\): PKCE flow against a mock issuer (loopback callback actually fires), device-code flow with \authorization_pending\ then success, auto-selection when the issuer advertises device code, refresh keeps the stored refresh token when the issuer doesn't rotate, file-store roundtrip + 0600/perm-refusal, 401→refresh→retry against a stub SCI, forbidden surfaces cleanly.

  • \go vet ./...\ clean, \gofmt\ clean, \make build\, \make check-version\ green.
  • Live testing still needed

  • The integration Dex device-code flow end-to-end (grant availability on the v2.41.1 deployment with the static-password dev connector).

  • The corporate Keycloak's real authorization-code+PKCE flow against a registered \sci-cli\ public client (stage/prod — platform team, foundry#171 Q11).

  • One full happy-path over SSH (headless host → device code or ported PKCE callback).
  • Cc @smith-xyz @chubirka

    Diff: 385 lines (+288 / -97) across 4 files Reviewer: smith-xyz Review duration: 3593m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 385 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.356
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #75"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43% (MEDIUM) · Higher = larger blast radius
    43%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.9% · Safe to merge
    22.9%