Skip to main content

Crate gatekpr_opencode

Crate gatekpr_opencode 

Source
Expand description

OpenCode CLI integration for RAG-powered validation enrichment

This crate provides a client that invokes the OpenCode CLI to enrich validation findings with context from the RAG system. It implements a two-stage validation flow:

  • Stage 1: Local pipeline produces RawFinding
  • Stage 2: OpenCode CLI enriches to EnrichedFinding with RAG context

§Architecture

The client executes opencode run with structured prompts, instructing the LLM to use MCP tools (search_docs_for_rule, get_fix_hint) to fetch relevant Shopify documentation and provide detailed analysis.

Each finding is processed in a fresh OpenCode session to avoid context window accumulation. This prioritizes accuracy over speed.

§Usage

use gatekpr_opencode::{OpenCodeClient, RawFinding, Severity};

// Create client (auto-detects CLI path)
let client = OpenCodeClient::auto()?;

// Enrich findings from local pipeline
let raw_findings = vec![
    RawFinding::new("WH001", Severity::Critical, "webhooks", "src/app.ts", "Missing GDPR webhook")
        .with_line(42)
];

let enriched = client.enrich_findings(raw_findings, Path::new("./my-app")).await?;

// Enriched findings include:
// - Detailed issue description and impact
// - Fix recommendations with code snippets
// - Documentation references from RAG

§Configuration

The client can be configured via environment variables:

  • OPENCODE_CLI_PATH: Path to opencode binary (default: auto-detect)
  • OPENCODE_MODEL: Model to use (default: zai-coding-plan/glm-4.7)
  • OPENCODE_TIMEOUT: Timeout in seconds (default: 120)
  • MCP_SERVER_PATH: Path to gatekpr-mcp-server binary

Re-exports§

pub use client::OpenCodeClient;
pub use config::OpenCodeConfig;
pub use error::OpenCodeError;
pub use error::Result;
pub use models::*;

Modules§

client
OpenCode CLI client for RAG-powered validation enrichment
config
Configuration for OpenCode CLI integration
error
Error types for OpenCode CLI integration
models
Data models for OpenCode validation enrichment