krit

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT

README

Krit

Go-first static analysis for Kotlin, Java, and Android. Krit uses tree-sitter for fast source analysis and can call JVM-backed Kotlin Analysis API/FIR helper tools for type-aware checks when a project needs them.

curl -fsSL https://raw.githubusercontent.com/kaeawc/krit/main/install.sh | sh
krit .

That's it. Run it in any Kotlin, Java, or Android project and get findings in seconds.

What it does

  • Broad rule coverage — detekt-compatible, Android Lint-compatible, plus extras for resources, icons, and Gradle
  • Auto-fixes at three safety levels — cosmetic, idiomatic, semantic
  • SARIF / JSON / Checkstyle / plain output
  • LSP + MCP servers — editor diagnostics and AI agent integration
  • Cross-file dead code via bloom-filtered indexing across Kotlin, Java, and XML
  • Optional JVM analysis through krit-types/KAA and FIR helper processes for checks that need compiler-grade facts

Install

# Recommended (macOS / Linux): verifies SHA256 and installs to ~/.local/bin
curl -fsSL https://raw.githubusercontent.com/kaeawc/krit/main/install.sh | sh

# Homebrew (macOS / Linux)
brew install --cask kaeawc/tap/krit

# Scoop (Windows)
scoop bucket add krit https://github.com/kaeawc/scoop-krit
scoop install krit

# Go (any platform; needs Go 1.25+ and a C compiler)
go install github.com/kaeawc/krit/cmd/krit@latest

See docs/install.md for the full set of install options and companion tools (krit-lsp, krit-mcp, krit-types, and krit-fir).

First run

krit --init     # write starter krit.yml
krit .          # analyze current directory
krit --fix .    # apply safe fixes

Docs

Contributing

git clone https://github.com/kaeawc/krit.git && cd krit
go build -o krit ./cmd/krit/
go test ./... -count=1

Rules live in internal/rules/. Fixtures live in tests/fixtures/. New rules embed the appropriate rule base and register v2 metadata. See CONTRIBUTING.md.

License

See LICENSE.

Directories

Path Synopsis
cmd
krit command
krit-lsp command
krit-mcp command
lint-catalog command
internal
analyzers/astflat
Package astflat provides flat-AST navigation primitives that are general across rule and analyzer packages: call/navigation/argument decomposition, scope-walk helpers, condition-operand iteration.
Package astflat provides flat-AST navigation primitives that are general across rule and analyzer packages: call/navigation/argument decomposition, scope-walk helpers, condition-operand iteration.
analyzers/nullflow
Package nullflow provides flow-sensitive nullability analysis primitives over a parsed scanner.File.
Package nullflow provides flow-sensitive nullability analysis primitives over a parsed scanner.File.
android
Package android provides parsers for Android project files.
Package android provides parsers for Android project files.
binsymbols
Package binsymbols defines the seam through which Krit consumes class metadata that lives outside the source workspace — JARs, AARs, stdlib stubs, or KAA-backed oracle responses.
Package binsymbols defines the seam through which Krit consumes class metadata that lives outside the source workspace — JARs, AARs, stdlib stubs, or KAA-backed oracle responses.
cacheutil
Package cacheutil is the shared infrastructure layer for every on-disk cache in krit.
Package cacheutil is the shared infrastructure layer for every on-disk cache in krit.
cli/clishared
Package clishared holds helpers shared across krit's verb-specific CLI packages (internal/cli/<verb>/).
Package clishared holds helpers shared across krit's verb-specific CLI packages (internal/cli/<verb>/).
cli/daemonclient
Package daemonclient lets short-lived CLI verbs call a long-lived krit daemon when one is reachable, and fall back to in-process execution otherwise.
Package daemonclient lets short-lived CLI verbs call a long-lived krit daemon when one is reachable, and fall back to in-process execution otherwise.
cli/precommit
Package precommit runs single-buffer rule analysis on every Kotlin file currently staged for a git commit, routing the work through a running krit daemon when one is available.
Package precommit runs single-buffer rule analysis on every Kotlin file currently staged for a git commit, routing the work through a running krit daemon when one is available.
cli/snapshot
Package snapshot implements the `krit snapshot` CLI verb.
Package snapshot implements the `krit snapshot` CLI verb.
cli/suggestreviewers
Package suggestreviewers implements the `krit suggest-reviewers` subcommand: parse CODEOWNERS, follow the cross-file reference index from the symbols changed in a PR, and propose reviewer teams that own callers of those symbols (in addition to teams that own the changed files directly).
Package suggestreviewers implements the `krit suggest-reviewers` subcommand: parse CODEOWNERS, follow the cross-file reference index from the symbols changed in a PR, and propose reviewer teams that own callers of those symbols (in addition to teams that own the changed files directly).
daemon
Package daemon implements a long-lived krit process that keeps parse trees, the cross-file index, oracle state, and typeinfer caches resident in memory.
Package daemon implements a long-lived krit process that keeps parse trees, the cross-file index, oracle state, and typeinfer caches resident in memory.
di
diag
Package diag provides a Reporter type for analyzer libraries to emit verbose progress and warning messages without coupling to os.Stderr.
Package diag provides a Reporter type for analyzer libraries to emit verbose progress and warning messages without coupling to os.Stderr.
env
Package env provides a small Reader abstraction over process environment access.
Package env provides a small Reader abstraction over process environment access.
filefacts
Package filefacts is the shared per-run memoization layer for per-file derived facts (imports, references, declaration summaries, and arbitrary rule-local computations).
Package filefacts is the shared per-run memoization layer for per-file derived facts (imports, references, declaration summaries, and arbitrary rule-local computations).
iterutil
Package iterutil contains determinism-safe iteration helpers.
Package iterutil contains determinism-safe iteration helpers.
jsonrpc
Package jsonrpc implements JSON-RPC 2.0 message transport shared by the LSP and MCP servers.
Package jsonrpc implements JSON-RPC 2.0 message transport shared by the LSP and MCP servers.
jsonschema
Package jsonschema provides a typed builder for JSON Schema documents.
Package jsonschema provides a typed builder for JSON Schema documents.
logger
Package logger provides a small Logger interface over log/slog so production code logs to stderr/JSON while tests substitute Capture to assert on emitted records.
Package logger provides a small Logger interface over log/slog so production code logs to stderr/JSON while tests substitute Capture to assert on emitted records.
lsp
manifest
Package manifest carries the rule-facing data model for parsed AndroidManifest.xml files.
Package manifest carries the rule-facing data model for parsed AndroidManifest.xml files.
mcp
onboarding
Package onboarding implements the shared logic for the krit init onboarding flow.
Package onboarding implements the shared logic for the krit init onboarding flow.
oracle/oracletest
Package oracletest provides a shared contract test that every implementation of oracle.Lookup must satisfy.
Package oracletest provides a shared contract test that every implementation of oracle.Lookup must satisfy.
pipeline
Package pipeline composes the Krit analysis workflow into a sequence of named, independently testable phases.
Package pipeline composes the Krit analysis workflow into a sequence of named, independently testable phases.
proc
Package proc provides a small abstraction over os/exec so production code can take a dependency on Runner instead of calling exec.Command directly.
Package proc provides a small abstraction over os/exec so production code can take a dependency on Runner instead of calling exec.Command directly.
rules/api
Package api defines the krit rule contract: a single Rule struct that declares its dependencies via a Capabilities bitfield and provides a single Check function which receives a Context carrying everything the rule needs.
Package api defines the krit rule contract: a single Rule struct that declares its dependencies via a Capabilities bitfield and provides a single Check function which receives a Context carrying everything the rule needs.
rules/api/evidence
Package evidence is a thin facade over scanner.File + the wired type resolvers, exposing only the structured questions a rule should ask.
Package evidence is a thin facade over scanner.File + the wired type resolvers, exposing only the structured questions a rule should ask.
rules/base
Package base holds the rule scaffolding types embedded by every rule implementation: BaseRule (name/ruleset/severity/description metadata and the Finding emit-helper), FlatDispatchBase (marker for flat-dispatch rules), and LineBase (marker for line-pass rules).
Package base holds the rule scaffolding types embedded by every rule implementation: BaseRule (name/ruleset/severity/description metadata and the Finding emit-helper), FlatDispatchBase (marker for flat-dispatch rules), and LineBase (marker for line-pass rules).
rules/coroutines
Package coroutines is a rules subpackage demonstrating the per-domain topology described in the architecture diagnosis.
Package coroutines is a rules subpackage demonstrating the per-domain topology described in the architecture diagnosis.
rules/ruletest
Package ruletest is the canonical entry point for unit-testing rules.
Package ruletest is the canonical entry point for unit-testing rules.
ruleslinter
Package ruleslinter statically verifies that each rule which calls ctx.Resolver or (*oracle.CompositeResolver).Oracle() declares a matching capability in its api.Rule registration.
Package ruleslinter statically verifies that each rule which calls ctx.Resolver or (*oracle.CompositeResolver).Oracle() declares a matching capability in its api.Rule registration.
snapshot
Package snapshot captures per-commit structural state (modules, files, symbols, scalar metrics) and persists it under `.krit/snapshots/` for later timeline and diff queries.
Package snapshot captures per-commit structural state (modules, files, symbols, scalar metrics) and persists it under `.krit/snapshots/` for later timeline and diff queries.
sourceheader
Package sourceheader extracts package and import header text from tree-sitter node strings.
Package sourceheader extracts package and import header text from tree-sitter node strings.
typeinfer
Package typeinfer provides lightweight type inference for Kotlin source code.
Package typeinfer provides lightweight type inference for Kotlin source code.
usedsymbols
Package usedsymbols extracts the set of external (out-of-module) fully-qualified symbols a Kotlin compilation unit references.
Package usedsymbols extracts the set of external (out-of-module) fully-qualified symbols a Kotlin compilation unit references.
pkg
extension
Package extension is the stable, public surface that downstream projects use to register additional rules with Krit's analyzer.
Package extension is the stable, public surface that downstream projects use to register additional rules with Krit's analyzer.

Jump to

Keyboard shortcuts

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