codefit

module
v0.1.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2026 License: Apache-2.0

README

codefit

ci license

The MCP-first auditor for AI-generated code — codefit maps, the agent reasons.

codefit is an open-source tool, written in Go, that audits software written (partly or fully) by AI. It detects what a developer never sees during normal development: security vulnerabilities, algorithmic complexity that scales badly, structural database problems, regression risk, and quality issues that only surface under deep review. Its guiding principle: codefit audits what the developer is never going to see — if a dimension is visible during normal development, it is out of scope.

⚠️ Project status: in active development (Phase 1)

codefit runs over the MCP stdio transport today: codefit mcp serve exposes the audit tools and an agent can call them. What is in main now:

  • TypeScript provider (gotreesitter, pure Go, no CGO).
  • Deterministic security rules for TypeScript — five categories (see below).
  • Surface mapping — three categories (IDOR, broken authorization, over-fetching) for Next.js / Prisma, validated against a real backend.
  • scan-all synthesis — the per-endpoint aggregation with three certainty levels, returned as a three-bucket summary: actionable (resolved locally with a gap — full detail), resolved_clean (resolved locally, controls present, no gap — named with a verification fact), and frontier_pending (the data left the handler body — named). Full detail of any named endpoint is one scan-endpoint call away. Keeps the response small enough not to truncate (ADR 0008).
  • MCP stdio servercodefit mcp serve exposes the tools over the protocol (built on the official MCP Go SDK; verified by a client↔server integration test). The Go provider and the self-audit (codefit scans its own code in CI) round it out.

Still in active development (Phase 1): the HTTP/SSE transport (--port) is not wired yet — use stdio. The plumbing commands init / update are scaffolding (the tools work without them — config is optional). Phases 2–4 (DB, complexity, code review, knowledge packs) are on the roadmap.

MCP-first, pure

codefit runs exclusively as an MCP server that AI agents (Claude Code, OpenCode, Cursor, …) consume as a set of tools. There is no audit CLI, and codefit never calls an LLM or manages any credentials.

It runs the deterministic layers (patterns + AST), maps the structural surface of the vulnerability classes that require reasoning, and returns findings + surface to the agent, which reasons over the surface with its own LLM. The intelligence is the agent's. That is what democratizes auditing: anyone already coding with AI can audit without extra API keys or infrastructure.

agent generates code
  └─► codefit (MCP tool): deterministic findings + mapped surface (JSON)
        └─► agent reasons the surface with its own LLM → fixes or proceeds

Connect it to your agent (stdio):

{
  "mcpServers": {
    "codefit": { "command": "codefit", "args": ["mcp", "serve"], "cwd": "/path/to/project" }
  }
}

The differentiator: surface mapping

Deterministic rules are what any linter does. The honest surface mapping that the agent reasons over is what makes codefit different.

Classes like IDOR, broken authorization, and over-fetching cannot be caught by a fixed pattern — they need semantic understanding. So codefit does not mark candidates surgically (inheriting the AST's blind spot). It enumerates the complete structural surface of each class — every endpoint that reaches a resource by an id, every sensitive handler, every serialization of a domain object — and hands all of it to the agent, with structural signals that are facts ("reads params.id", "no known authz helper detected in the body") and a reason-to-review that is a question ("does this verify ownership before access?"). codefit never judges; the agent reasons each item.

What codefit can confirm from structure it enumerates (FINITE); what requires following the data out of the handler it hands to the agent (the frontier); what it does not cover it declares in the coverage manifest (COVERAGE.md). The principle is recorded in ADR 0005; the per-endpoint synthesis with its three certainty levels in ADR 0006.

Deterministic security rules (TypeScript)

Five categories, each a fact codefit asserts with certainty 1.0: hardcoded secrets, weak cryptography (MD5/SHA-1, insecure Math.random for tokens), dangerous eval/new Function, inline SQL injection, and inline XSS via dangerouslySetInnerHTML. Rules are declarative YAML in a Semgrep-format subset, matched by codefit's own pure-Go engine (no OCaml/OpenGrep embedded) — see rules/. Their exact scope and known limits are in COVERAGE.md.

What codefit does NOT do (and why)

codefit complements linters and type-checkers; it does not replace them. An unused any, a style nit, an obvious type error — those are visible during normal development, so a linter already catches them and they are out of scope. codefit spends its effort on the invisible: a missing ownership check on an endpoint, a model serialized with every column to the client, a hash that is weak for security. It is the independent audit layer that validates AI-generated code is secure and correct before it merges — not another linter.

Supported languages

Language / Ecosystem Status
Go Provider + static security/best-practice detectors. codefit audits itself in CI.
TypeScript / Next.js / Prisma Deterministic security rules (5 categories) + surface mapping (IDOR, authz, over-fetching), validated against a real backend.
Java / Spring Roadmap
Python / FastAPI / Django Roadmap

Adding a language means implementing one LanguageProvider — it never touches the core, the sensors, the MCP server, or the reporting (see CONTRIBUTING.md and docs/decisions/).

Building from source

go install github.com/codefit-cli/codefit/cmd/codefit@latest   # Go 1.25+

codefit is a single static binary with no runtime dependencies (CGO_ENABLED=0), cross-compiling to linux/amd64, linux/arm64, windows/amd64, and darwin/arm64. There is no LLM or auth configuration — codefit manages no models and no credentials. Run codefit mcp serve and point your agent at it (see above).

Contributing

Contributions are welcome — new rules, surface categories, language providers, and false-positive reports especially. See CONTRIBUTING.md and rules/README.md. Please follow our Code of Conduct, and report security issues per our Security Policy.

License

Apache 2.0.

Directories

Path Synopsis
cmd
codefit command
Command codefit is the CLI and MCP entry point for the codefit auditor.
Command codefit is the CLI and MCP entry point for the codefit auditor.
internal
cli
Package cli wires the codefit command tree with cobra: the root command and its global flags, plus every subcommand (init, scan, bench, review, run, baseline, report, mcp serve, auth, set, status).
Package cli wires the codefit command tree with cobra: the root command and its global flags, plus every subcommand (init, scan, bench, review, run, baseline, report, mcp serve, auth, set, status).
config
Package config models and loads .codefit.yaml, the per-project configuration committed to the repository.
Package config models and loads .codefit.yaml, the per-project configuration committed to the repository.
core/baseline
Package baseline implements the adoption baseline (PRD RF-08): a committed snapshot of a project's findings so that, with baseline enabled, codefit reports only new findings while pre-existing debt is recorded (baselined: true) and does not block.
Package baseline implements the adoption baseline (PRD RF-08): a committed snapshot of a project's findings so that, with baseline enabled, codefit reports only new findings while pre-existing debt is recorded (baselined: true) and does not block.
core/cache
Package cache defines the content-hash finding cache (PRD section 15, optimization 2).
Package cache defines the content-hash finding cache (PRD section 15, optimization 2).
core/context
Package context defines AuditContext, the immutable struct that carries everything a sensor needs about the project under audit: where it lives, its language and framework, the parsed config, and the run modifiers (incremental ref, no-LLM mode).
Package context defines AuditContext, the immutable struct that carries everything a sensor needs about the project under audit: where it lives, its language and framework, the parsed config, and the run modifiers (incremental ref, no-LLM mode).
core/coverage
Package coverage models codefit's coverage manifest (PRD section 10, RF-07): the explicit, per-language declaration of what codefit detects and what it does not.
Package coverage models codefit's coverage manifest (PRD section 10, RF-07): the explicit, per-language declaration of what codefit detects and what it does not.
core/cve
Package cve checks project dependencies against known vulnerabilities via OSV.dev (PRD section 18, RF-09).
Package cve checks project dependencies against known vulnerabilities via OSV.dev (PRD section 18, RF-09).
core/findings
Package findings defines the universal, language-agnostic vocabulary of an audit: the Finding hallazgo, its Severity and Dimension, the ConsentRecord that authorizes suppressing a critical security finding, and the SensorResult every sensor returns.
Package findings defines the universal, language-agnostic vocabulary of an audit: the Finding hallazgo, its Severity and Dimension, the ConsentRecord that authorizes suppressing a critical security finding, and the SensorResult every sensor returns.
core/pipeline
Package pipeline defines the filtering pyramid (PRD section 15): cheap layers run first and only what they cannot conclude is escalated to the next, more expensive layer.
Package pipeline defines the filtering pyramid (PRD section 15): cheap layers run first and only what they cannot conclude is escalated to the next, more expensive layer.
core/report
Package report defines the canonical audit report and the renderers that present it.
Package report defines the canonical audit report and the renderers that present it.
core/ruleengine
Package ruleengine is codefit's own matcher for a subset of the Semgrep rule format (PRD section 17).
Package ruleengine is codefit's own matcher for a subset of the Semgrep rule format (PRD section 17).
core/scoring
Package scoring computes the per-dimension scores (0-100) and the weighted global score from a set of findings, using the configurable weights from .codefit.yaml (PRD RF-07).
Package scoring computes the per-dimension scores (0-100) and the weighted global score from a set of findings, using the configurable weights from .codefit.yaml (PRD RF-07).
core/surface
Package surface is the core framework for surface mapping (PRD section 10): the language-agnostic home for surface categories and, in Fase 1, the SurfaceQuery format (codefit's own declarative format for enumerating auditable structural surface, distinct from the Semgrep-format rules used for deterministic findings — PRD section 17).
Package surface is the core framework for surface mapping (PRD section 10): the language-agnostic home for surface categories and, in Fase 1, the SurfaceQuery format (codefit's own declarative format for enumerating auditable structural surface, distinct from the Semgrep-format rules used for deterministic findings — PRD section 17).
core/syntax
Package syntax is codefit's parser-agnostic AST boundary.
Package syntax is codefit's parser-agnostic AST boundary.
mcp
Package mcp implements the MCP server mode: a thin, stateless adapter that exposes the same core sensors as MCP tools (PRD section 10).
Package mcp implements the MCP server mode: a thin, stateless adapter that exposes the same core sensors as MCP tools (PRD section 10).
providers
Package providers defines the LanguageProvider contract — the extensibility seam (PRD section 14).
Package providers defines the LanguageProvider contract — the extensibility seam (PRD section 14).
providers/golang
Package golang is the Go LanguageProvider.
Package golang is the Go LanguageProvider.
providers/typescript
Package typescript is the TypeScript/TSX LanguageProvider.
Package typescript is the TypeScript/TSX LanguageProvider.
sensors
Package sensors defines the Sensor contract: a module that audits one findings.Dimension and returns a findings.SensorResult.
Package sensors defines the Sensor contract: a module that audits one findings.Dimension and returns a findings.SensorResult.
sensors/security
Package security is the universal security sensor.
Package security is the universal security sensor.
version
Package version holds the build-time identity of the codefit binary.
Package version holds the build-time identity of the codefit binary.
Package rules embeds codefit's declarative detection rules so they ship inside the single binary, versioned with it.
Package rules embeds codefit's declarative detection rules so they ship inside the single binary, versioned with it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL