v0.1.0 · Open Source

Know where your AI code comes from.

Grain traces every AI-generated line back to the conversation that created it. See your AI contribution, enforce policies, ship with confidence.

grain commit-trend --last 5
$ grain commit-trend --last 5

──── Commit Trend ──────────────────────────────────────────

SHA         AI%    Composer      Tab           Human         Message
────────────────────────────────────────────────────────────────────────────────
a3f1e29c  87%    +142/-38    +22/-4       +12/-8       feat: add policy engine
d90bc144  52%    +64/-12     +18/-6       +48/-21      refactor: sanitize paths
7e8f3a01  18%    +8/-2       +12/-0       +71/-34      fix: handle empty transcripts
c42b91e7  94%    +210/-0     +31/-0       +6/-2       feat: conversation ranker
1a0e8d33  41%    +29/-14     +0/-0        +55/-22      docs: update README

AI writes your code.
But who's keeping track?

AI coding tools generate hundreds of lines per session. Code flows from conversations into files into commits — with no audit trail. When something breaks in production, you can't trace it back. When compliance asks, you can't answer.

"How much of this codebase is AI-generated?"
"Which model wrote the authentication module?"
"Did an AI agent touch billing code without review?"
"Are we compliant with our AI usage policies?"

Trace. Analyze. Enforce.

Three steps from blind spot to full visibility.

Step 01

Trace

Grain reads Cursor's built-in tracking database and agent transcripts locally. No SDK, no wrapper, no instrumentation required.

Step 02

Analyze

Every commit is scored with an AI percentage. Conversations are ranked by relevance and linked to the files they changed.

Step 03

Enforce

Define policies: max AI%, restricted paths, allowed models. Run grain policy-check in CI. Violations return exit code 1.

Commands

grain commit-trend

Commit AI% at a glance

See recent commits with AI contribution percentage, broken down by composer, tab-complete, and human-written lines.

grain explain <commit>

Deep-dive any commit

Full provenance report: AI score, files changed, linked conversations, transcript excerpts, and model attribution.

grain convo <id>

Inspect conversations

See which models were used, which files were touched, time window, summary, and the full transcript of any AI conversation.

grain policy-check

CI-ready enforcement

Evaluate any commit against configured policies. Returns exit code 1 on violations — drop it into your CI pipeline.

grain policy-list

View active policies

List all configured policies and their thresholds. Know exactly what rules are enforced in your environment.

grain env

Environment-aware provenance

Four provenance levels — minimal, standard, enhanced, full — that control how much detail is disclosed based on your environment.

grain explain a3f1e29c
$ grain explain a3f1e29c

──── Environment ─────────────────────────────────────────
  Environment:      production
  Provenance Level: enhanced (level 2)

──── Commit ──────────────────────────────────────────────
  SHA:     a3f1e29c
  Message: feat: add policy engine
  Author:  jane@company.com
  Date:    2026-03-05 14:22:08

──── AI Attribution ──────────────────────────────────────
  AI%:       87%
  Composer:  +142/-38
  Tab:       +22/-4
  Human:     +12/-8
  Total:     +176/-50

──── Files Changed ───────────────────────────────────────
   src/analysis/policy.ts
   src/commands/policy-check.ts
   src/commands/policy-list.ts
   src/types.ts

──── Linked Conversations ────────────────────────────────
  #1 conv_8a3f21e9  matches: 4
     models: claude-4-sonnet  via: composer
     files:  src/analysis/policy.ts, src/commands/policy-check.ts
     query:  Build a policy engine that evaluates commits against configurable thresholds…
     summary: Implemented policy evaluation with five rule types and CI integration
grain policy-check a3f1e29c
$ grain policy-check a3f1e29c

──── Policy Check ────────────────────────────────────────
  Commit:      a3f1e29c
  Environment: production

  Rules Evaluated: 4

  PASS         allowed_models         Model claude-4-sonnet is allowed
  PASS         restricted_paths       No AI changes in restricted paths
  WARNING      ai_contribution        AI% 87 exceeds warn threshold 60
  VIOLATION    agent_mode             Agent-mode code requires review

  Result: 1 warning(s), 1 violation(s)

Configurable policy engine

Define guardrails. Enforce them in CI. Five rule types, zero ambiguity.

ai_contribution

Warn or block commits that exceed AI percentage thresholds. Set separate warn and max levels.

restricted_paths

Flag AI-generated code in sensitive directories like auth/, billing/, or security/.

agent_mode

Require human review for any code generated by an AI agent in autonomous mode.

allowed_models

Restrict which AI models are permitted to generate code in your repository.

ai_volume

Cap the number of AI code events per commit to prevent bulk AI-generated changes.

CI integration

grain policy-check returns exit code 1 on violations. Add it to your pipeline in one line.

.grain/config.yaml
# Policy configuration
policies:
  ai_contribution:
    warn_threshold: 60
    max_threshold:  90

  restricted_paths:
    - auth/
    - billing/
    - security/

  agent_mode:
    require_review: true

  allowed_models:
    - claude-4-sonnet
    - claude-4-opus

Privacy by default.
Local by design.

Grain runs entirely on your machine. No data leaves your environment. No telemetry, no cloud, no accounts.

  • Runs entirely locally — reads Cursor's existing database
  • Automatic secret redaction (API keys, tokens, connection strings)
  • Path sanitization (absolute paths → repo-relative)
  • Optional author stripping and conversation ID hashing
  • Provenance levels control disclosure depth per environment
Level 0
Minimal
AI%, model attribution, commit metadata only
Level 1
Standard
+ conversation summaries, file list, agent mode
Level 2
Enhanced
+ transcript excerpts, tool execution metadata
Level 3
Full
+ full transcripts, tool call details, reasoning traces

Get started in 30 seconds

Three commands. That's it.

01 · Install
npm install grain-cli
Install globally or as a dev dependency
02 · Initialize
grain init
Creates .grain/config.yaml in your repo
03 · Explore
grain commit-trend --last 10
See AI% for your recent commits

Prerequisites: Cursor with AI tracking enabled · Git repository