← Back to Pull requests

feat: add Grok CLI provider for cli/grok models #498

Open
unknown opened this pull request with 348 lines diff across 4 files
View on GitHub
unknown unknown commented on Sep 29, 2026 01:27 UTC
Author

Summary

  • Adds Grok CLI as a CLI model backend: --cli grok, --model cli/grok, --model cli/grok/<model>, and cli.grok.{binary,model,extraArgs,isolated} config, plus GROK_PATH / SUMMARIZE_CLI_GROK binary overrides and CLI_GROK availability handling across the daemon model picker and the Chrome extension.

  • New runner (src/llm/cli-runners/grok.ts) invokes grok --prompt-file <file> --output-format json so untrusted page content never touches argv. Text summaries run in an isolated temp cwd with a read-only list_dir toolset, MCPTool() denied, --sandbox strict, and plan/subagent/web-search off; GROK_HOME is redirected to a temp dir carrying only auth.json so sessions/hooks/user config do not load. Attachment runs keep the caller cwd with --always-approve --sandbox off.

  • New parser (src/llm/cli-provider-output/grok.ts) maps additive cache usage fields (input + cache_creation + cache_read) and total_cost_usd, tolerates brace-containing diagnostic preludes, and surfaces {type:"error"} payloads — including stdout errors on non-zero exits (execCliWithInput now attaches buffered stdout to rejected errors).

  • Opt-in like agy/pi: excluded from the default auto-fallback order.

  • Drive-by fixes: pi no longer leaks its isolated temp cwd if the prompt mkdtemp fails; PI_PATH, GROK_HOME, and CODEX_HOME added to the daemon env snapshot whitelist (they were missing).
  • Test plan

  • pnpm run check — 3,688 tests green, lint/typecheck/format/localization all pass

  • Verified against the real grok v1.0.41 binary — transcripts below

  • Confirmed no ~/.grok/sessions residue and no temp-dir leaks on isolated runs

  • Confirmed grok hard-errors on duplicate singleton flags, so extraArgs overrides are handled via hasAnyFlag-style guards
  • Real-run transcript (grok v1.0.41, macOS)

    $ summarize --cli grok --plain --no-cache --timeout 3m /tmp/summarize-cli-smoke.txt
    The file is a short note on CLI smoke input and terminal tools.
    via model cli/grok
    31s · $0.0063 · cli/grok · ↑4.9k ↓2.1k Δ7.0k
    
    $ summarize --model cli/grok/totally-bogus-model --plain --no-cache --timeout 2m -
    Couldn't set model 'totally-bogus-model': Invalid params: "unknown model id". Run 'grok models' to see available models.
    
    $ summarize status
      Grok CLI: available
    

    Raw grok output shape (verified): {"text": "...", "usage": {"input_tokens": N, "cache_read_input_tokens": N, "cache_creation_input_tokens": N, "output_tokens": N, "total_tokens": N}, "total_cost_usd": N}; errors: {"type":"error","message":"..."} on stdout with exit 1. Session residue check: ~/.grok/sessions count unchanged after isolated runs; all summarize-grok- temp dirs removed in finally.

    Generated with Devin

    Diff: 348 lines (+261 / -87) across 4 files Reviewer: steipete Review duration: 2716m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.47) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 348 lines diff across 4 files
    0.47
    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%
    42%
    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.350
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #498"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 27.1% · Safe to merge
    27.1%