Grain CLI AI code provenance for the post-AI SDLC
grain-cli.getforge.io →
Lab Project

Grain CLI

Trace AI-generated code back to the prompt and conversation that created it. A local, privacy-first CLI tool that connects Cursor telemetry, agent transcripts, and Git to reconstruct the complete provenance chain from prompt to commit.

Grain CLI AI code provenance

Overview

"How can we trust AI-generated code?" This question comes up in every board meeting, every investor call, every CTO conversation where AI-assisted development is on the table. Git doesn't have the answer. Your SDLC doesn't account for it. Most compliance frameworks can't explain it.

Grain CLI is our answer, built for our own workflow first. It traces AI-generated code back to the prompt and conversation that created it, reads Cursor's local telemetry to reconstruct provenance, evaluates commits against configurable governance policies, and does all of this locally, with no data leaving the developer's machine.

Open source under the MIT licence. Available on npm. Built with Node.js and TypeScript.

The Trust Gap

In many engineering teams using AI coding assistants, AI contribution rates have climbed past 80%, sometimes 90%. Entire features are authored in a single conversation between a developer and an autonomous agent. A commit that was carefully hand-crafted line by line and a commit generated wholesale by an autonomous AI agent look identical in your commit history. They should not be treated identically.

The regulatory environment is making this concrete. The EU AI Act introduces transparency obligations for AI systems entering enforcement through 2025-2027. GDPR already requires organisations to explain automated decision-making. Code provenance is becoming non-optional.

The Insight: The Data Already Exists

Cursor maintains three rich local data sources on every developer's machine:

Together, these three sources reconstruct the complete chain from prompt to commit. Nobody was connecting them. That realisation became Grain CLI.

How It Works

Grain's core technical challenge was that Cursor has no direct foreign key between commits and conversations. We solved this with a heuristic join: match changed files from a commit against AI code hash records within a time window, rank conversations by number of matching entries, and surface the top candidates.

The result is the complete provenance chain:

The Policy Engine

Five policy types evaluate commits against configurable rules defined in a per-repository .grain/config.yaml:

Progressive Governance, Not Surveillance

The hardest design problem was not technical. Developers rightly resist surveillance of their work. If a tool exposes every experimental conversation to management, developers stop using AI assistants, which is a worse outcome than no governance at all.

Grain resolves this with progressive governance: four provenance levels that adapt disclosure to context.

A developer experimenting in a hackathon repo does not need the same oversight as a team shipping code to a regulated financial system. The tool adapts rather than imposing a single posture everywhere.

Privacy Engineering

Privacy is not a feature flag. A sanitisation pipeline runs on every output path, always active:

Architecture

Grain is a layered Node.js CLI application built with TypeScript, targeting Node.js 18+. The architecture separates data access, analysis, rendering, and privacy into independent layers. Key design decisions:

What We Still Need to Build

Grain CLI proves the concept as a local macOS tool. The path to enterprise-grade AI governance involves several dimensions of work we have scoped:

The Deeper Shift

The commit is no longer the atomic unit of authorship. For decades, the commit has been the fundamental record of software change. But when an AI agent generates 340 lines of code from a single prompt, the commit captures the output, not the process. The conversation is the new unit of authorship.

Grain is a step toward making that shift concrete. The provenance chain from prompt to commit is reconstructable today, on every developer's machine, using data that already exists.

Status

Active development. Open source under MIT licence.

grain-cli.getforge.io    github.com/beachio/grain-cli

Building governance for AI-assisted development?

We have deep experience with AI code provenance, developer tooling, and building the governance infrastructure that AI-native teams need.

Get in touch