diff --git a/README.md b/README.md index ed2bf83..6742041 100644 --- a/README.md +++ b/README.md @@ -9,29 +9,69 @@ License: MIT

-codeint measures the Software entropy of a codebase: duplication, needless verbosity, and complexity concentrated in a few large functions. -It is for developers whose code is increasingly written by coding agents, so they see Software entropy grow before it compounds. - -codeint reports each Metric on its own, with the Findings behind it, and never blends them into one score. -It gates CI on per-Metric Budgets and on Regressions against a base Git ref. -Languages and Metrics are Plugins: TypeScript/JavaScript, Rust, PHP, and Dart ship as built-in Language plugins, and third-party languages and Metrics load as WebAssembly Plugins. -

+ Why codeint · + How it works · + Quick start · Guide · - Philosophy · - Install · - Configure · Reference · Programmatic API · Plugins · llms.txt

-[GLOSSARY.md](./GLOSSARY.md) defines every term on this page. +## Why codeint + +Coding agents write locally valid code very quickly. +Each pull request can pass tests and linters while quietly adding copied blocks, redundant branches, deeper functions, and tangled imports. +Over dozens of changes, that structural drag compounds until both humans and agents slow down. + +codeint measures **Software entropy** directly from the shape of source code so you see it grow before it compounds. +It ships with built-in Language plugins for TypeScript/JavaScript, Rust, PHP, and Dart, plus sandboxed WebAssembly Plugins for other languages and custom Metrics. + +## How it works + +### Four independent Metrics, never one blended score + +codeint reports four Metrics side by side and never collapses them into one grade or index ([ADR 0003](./docs/adr/0003-no-combined-score.md)). +A single score hides regressions when one Metric improves while another worsens. + +- **Erosion**: share of Function mass (`cyclomatic_complexity * sqrt(source_lines)`) in functions with cyclomatic complexity over 10. +- **Duplication**: share of source lines in Clone groups (at least 75 normalized tokens and 14 distinct normalized tokens, catching renamed copy-paste while ignoring import lists and data tables). +- **Verbosity**: share of source lines in zero-false-positive Flagged lines or Clone groups. +- **Import cycles**: share of modules in at least one runtime Import cycle. -## Install +### Grounded, ratchet-based enforcement -Install the standalone binary (macOS, Linux, Windows) or run directly with `npx`: +- **Pre-2023 Reference ranges**: every built-in language is calibrated against 20 public repositories pinned before `2023-01-01` (10th to 90th percentile), so raw numbers have grounded context. +- **Strict Source-set separation**: every file belongs to `production`, `test`, `generated`, or `vendored`, so fixtures and generated code never distort Production ratios. +- **Budgets and Regressions**: Budgets cap absolute entropy in `codeint check`, while `codeint diff ` ratchets every pull request against its Git merge-base. +- **Version-free parsing**: built-in Language plugins parse the modern superset of each language family, with no language-version pins needed in `codeint.json`. + +### Built for speed and safety + +codeint is written in safe Rust (`#![forbid(unsafe_code)]`, [ADR 0004](./docs/adr/0004-forbid-unsafe-code.md)) around two clean seams: Language plugins lower source files into a language-neutral Code model, and Metric plugins compute Metrics and Findings over that model. +It reads tracked files and commit history directly from Git objects without modifying your working tree, scanning `laravel/framework` (132k Production lines) in `0.47s` and `flutter/packages` (434k Production lines) in `3.68s` on Apple Silicon. +Third-party WebAssembly Plugins run with mandatory SHA-256 verification, zero host capabilities, and configurable memory and time caps. + +Read [docs/guide/philosophy-and-architecture.md](./docs/guide/philosophy-and-architecture.md) for the full architecture diagram and design rationale. + +## Calibrated Reference ranges + +10th to 90th percentile across 20 pre-2023 open-source repositories per language ([ADR 0008](./docs/adr/0008-typescript-reference-ranges.md), [ADR 0010](./docs/adr/0010-rust-reference-ranges.md), [ADR 0011](./docs/adr/0011-php-reference-ranges.md), [ADR 0012](./docs/adr/0012-dart-reference-ranges.md)): + +| Language | Erosion | Duplication | Verbosity | Import cycles | +| -------- | ------- | ----------- | --------- | ------------- | +| TypeScript / JavaScript | 35.2% to 60.0% | 1.7% to 34.6% | 1.8% to 34.7% | 0.0% to 30.8% | +| Rust | 38.0% to 64.2% | 5.0% to 32.5% | 6.0% to 32.9% | 2.1% to 50.6% | +| PHP | 5.5% to 67.7% | 4.1% to 29.0% | 4.2% to 29.2% | 0.0% to 10.7% | +| Dart | 4.7% to 41.9% | 7.3% to 25.6% | 8.0% to 25.9% | 7.3% to 52.4% | + +See [docs/guide/languages.md](./docs/guide/languages.md) for per-language rules and sample repository timings. + +## Quick start + +Install the standalone binary on macOS or Linux, on Windows, or run directly with `npx`: ```sh curl -fsSL https://github.com/avidianity/codeint/releases/latest/download/install.sh | bash @@ -45,168 +85,41 @@ irm https://github.com/avidianity/codeint/releases/latest/download/install.ps1 | npx codeint check ``` -## Use - -Run codeint inside a Git repository: +Run codeint inside any Git repository: ```sh codeint init codeint check codeint diff main codeint trend -codeint update ``` -`codeint init` writes a starter `codeint.json`. -`codeint check` measures the working tree and prints each Metric with its Findings. -`codeint diff main` compares the working tree with the merge-base of `main`, and fails on a Regression. -`codeint trend` prints each Metric for each commit of the main line. -`codeint update` verifies SHA-256 checksums and updates a standalone binary in place from GitHub Releases. - -[docs/reference.md](./docs/reference.md) documents every command, option, exit code, report format, and `codeint.json` key, with an example for each. -[docs/programmatic.md](./docs/programmatic.md) documents the JavaScript/TypeScript SDK (`import { check, diff, trend, init } from "codeint"`) and the Rust library API. -[docs/plugins.md](./docs/plugins.md) explains how to build, hash, declare, and test Language plugins and Metric plugins against the versioned WIT contract. - -## Configure - -Run `codeint init` at the root of your Git repository to create a starter `codeint.json` pinned to your installed version's `$schema` for editor autocomplete. -`codeint update` keeps that versioned `$schema` URL in sync when you upgrade. -Without `codeint.json`, codeint measures every supported language with default settings and no hard Budgets. - -```json -{ - "$schema": "https://raw.githubusercontent.com/avidianity/codeint/v0.1.0/schema/codeint.schema.json", - "source_sets": { - "generated": ["src/**/*.generated.ts"], - "vendored": ["vendor/**"] - }, - "budgets": { - "production": { - "erosion": 0.35, - "duplication": 0.08, - "verbosity": 0.08, - "import_cycles": 0.05 - } - }, - "regression_limits": { - "generated": { - "duplication": { "ratio_rise": 1, "new_findings": "never" } - } - }, - "languages": [ - { "plugin": "typescript-javascript", "include": ["web"], "exclude": ["web/dist"] }, - { "plugin": "rust", "include": ["crates"], "exclude": [] }, - { "plugin": "php", "include": ["app", "src"], "exclude": [] }, - { "plugin": "dart", "include": ["lib"], "exclude": [] } - ] -} -``` - -- **`source_sets`**: classify paths into `production`, `test`, `generated`, or `vendored` using globs (overrides built-in rules). -- **`budgets`**: hard maximum ratios (`0` to `1`) per Source set and Metric; `codeint check` and `codeint diff` exit `1` when exceeded. -- **`regression_limits`**: per-Metric or per-Source-set limits for `codeint diff` (`ratio_rise` defaults to `0.01`; `new_findings` accepts `any_new_finding`, `numerator_rise_with_new_findings`, or `never`). -- **`languages`**: scope built-in Language plugins (`typescript-javascript`, `rust`, `php`, `dart`) or external plugins to specific folders and exclusions. -- **`plugins`** and **`plugin_limits`**: load external WebAssembly Language or Metric plugins with SHA-256 verification and memory/time caps. - -See [docs/reference.md#codeintjson](./docs/reference.md#codeintjson) for every key, default value, and tested example. - -## What to expect +- `codeint init` writes a starter `codeint.json` with a versioned `$schema`. +- `codeint check` measures the working tree and prints each Metric with its Findings. +- `codeint diff main` compares the working tree against the merge-base of `main` and fails on a Regression. +- `codeint trend` prints each Metric across the latest main-line commits. -codeint measures four independent Production Metrics without blending them into one score: +Or call codeint programmatically from JavaScript/TypeScript (`npm install codeint`) or Rust (`codeint-cli`): -- **Erosion**: share of Function mass in functions with cyclomatic complexity over 10 -- **Duplication**: share of source lines in Clone groups -- **Verbosity**: share of source lines in Flagged lines or Clone groups -- **Import cycles**: share of modules in an Import cycle +```ts +import { check, diff } from "codeint"; -### Calibrated Reference ranges - -Measured across 20 pre-2023 open-source repositories per language (10th–90th percentile; [ADR 0008](./docs/adr/0008-typescript-reference-ranges.md), [ADR 0010](./docs/adr/0010-rust-reference-ranges.md), [ADR 0011](./docs/adr/0011-php-reference-ranges.md), [ADR 0012](./docs/adr/0012-dart-reference-ranges.md)): - -| Language | Erosion | Duplication | Verbosity | Import cycles | -| -------- | ------- | ----------- | --------- | ------------- | -| TypeScript / JavaScript | 35.2%–60.0% | 1.7%–34.6% | 1.8%–34.7% | 0.0%–30.8% | -| Rust | 38.0%–64.2% | 5.0%–32.5% | 6.0%–32.9% | 2.1%–50.6% | -| PHP | 5.5%–67.7% | 4.1%–29.0% | 4.2%–29.2% | 0.0%–10.7% | -| Dart | 4.7%–41.9% | 7.3%–25.6% | 8.0%–25.9% | 7.3%–52.4% | - -### Rust measurements and speed - -Sample Production measurements from `codeint check` (release build, Apple Silicon): - -| Repository | Files | Prod lines | Erosion | Duplication | Verbosity | Import cycles | Time | -| ---------- | ----- | ---------- | ------- | ----------- | --------- | ------------- | ---- | -| `avidianity/codeint` | 154 | 16,400 | 31.0% | 5.2% | 5.3% | 2.3% | 0.06s | -| `BurntSushi/ripgrep` | 105 | 24,961 | 36.4% | 31.1% | 31.3% | 29.3% | 0.07s | -| `sharkdp/fd` | 25 | 3,423 | 44.6% | 0.0% | 0.1% | 56.5% | 0.02s | -| `dtolnay/serde` | 189 | 19,425 | 45.7% | 40.2% | 40.2% | 0.0% | 0.06s | - -### PHP measurements and speed - -Sample Production measurements from `codeint check` (release build, Apple Silicon): - -| Repository | Files | Prod lines | Erosion | Duplication | Verbosity | Import cycles | Time | -| ---------- | ----- | ---------- | ------- | ----------- | --------- | ------------- | ---- | -| `laravel/laravel` | 29 | 762 | 0.0% | 0.0% | 0.0% | 8.0% | 0.03s | -| `laravel/framework` | 3,208 | 132,791 | 16.9% | 8.1% | 8.2% | 4.4% | 0.47s | - -### Dart measurements and speed - -Sample Production measurements from `codeint check` (release build, Apple Silicon): - -| Repository | Files | Prod lines | Erosion | Duplication | Verbosity | Import cycles | Time | -| ---------- | ----- | ---------- | ------- | ----------- | --------- | ------------- | ---- | -| `dart-lang/pub` | 547 | 26,170 | 44.4% | 0.5% | 1.7% | 78.6% | 0.88s | -| `flutter/packages` | 4,137 | 434,407 | 45.9% | 23.1% | 23.3% | 18.5% | 3.68s | - -## GitHub Actions - -Add `.github/workflows/codeint.yml` to run `codeint diff` on each pull request and upload its SARIF report to GitHub code scanning: - -```yaml -name: codeint - -on: - pull_request: - -permissions: - contents: read - security-events: write - -jobs: - codeint: - runs-on: ubuntu-24.04 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 - with: - fetch-depth: 0 - - name: Install codeint - run: | - curl -fsSL https://github.com/avidianity/codeint/releases/latest/download/install.sh | bash - echo "$HOME/.local/bin" >> "$GITHUB_PATH" - - name: Diff against pull request base - env: - BASE_REF: ${{ github.base_ref }} - run: codeint diff "origin/$BASE_REF" --format sarif --output codeint.sarif - - name: Upload SARIF - if: always() && hashFiles('codeint.sarif') != '' - uses: github/codeql-action/upload-sarif@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea - with: - sarif_file: codeint.sarif +const report = await check(); +const prDiff = await diff({ base: "main" }); ``` -`fetch-depth: 0` fetches the base branch history so `codeint diff` can find the merge-base. -`if: always() && hashFiles('codeint.sarif') != ''` uploads annotations even when a Budget or a Regression fails. +## Documentation -## Development - -You need: +- [Guide](./docs/guide/README.md): modular walkthroughs for [Philosophy and Architecture](./docs/guide/philosophy-and-architecture.md), [Getting Started](./docs/guide/getting-started.md), [Configuration (`codeint.json`)](./docs/guide/configuration.md), [Built-in Languages](./docs/guide/languages.md), and [CI and GitHub Actions](./docs/guide/ci-and-github-actions.md). +- [Reference](./docs/reference.md): tested reference for every command, flag, exit code, report format (`toon`, `json`, `sarif`, `markdown`), and `codeint.json` key. +- [Programmatic API](./docs/programmatic.md): JavaScript/TypeScript SDK and Rust library API. +- [Plugins](./docs/plugins.md): build, hash, declare, and test external WebAssembly Language and Metric plugins. +- [Glossary](./GLOSSARY.md): canonical definitions of every domain term on this page. +- [llms.txt](./llms.txt): compact documentation index for coding agents and LLM tools. -- Rust through rustup; [rust-toolchain.toml](./rust-toolchain.toml) selects the version. -- Node.js 24 and npm, for the development tools in [package.json](./package.json). -- gitleaks and lychee on your `PATH`, for the Git hook. +## Development -Set up a checkout: +You need Rust through rustup ([rust-toolchain.toml](./rust-toolchain.toml)), Node.js 24 and npm ([package.json](./package.json)), and `gitleaks` plus `lychee` on your `PATH`. ```sh npm ci @@ -215,7 +128,7 @@ cargo test --workspace --locked ``` Agents and people follow the same rules: start with [.rules](./.rules). -The checks that guard the repository are listed in [docs/checks](./docs/checks/README.md). +The repository checks are listed in [docs/checks/README.md](./docs/checks/README.md). ## License diff --git a/docs/guide/languages.md b/docs/guide/languages.md index d4b868b..55659c1 100644 --- a/docs/guide/languages.md +++ b/docs/guide/languages.md @@ -26,3 +26,18 @@ Measured across 20 pre-2023 public repositories per language (10th to 90th perce | Dart | 4.7% to 41.9% | 7.3% to 25.6% | 8.0% to 25.9% | 7.3% to 52.4% | [ADR 0012](../adr/0012-dart-reference-ranges.md) | To add another language as an external WebAssembly plugin, see [docs/plugins.md](../plugins.md). + +## Sample repository measurements and speed + +Sample Production measurements from `codeint check` (release build, Apple Silicon): + +| Language | Repository | Files | Prod lines | Erosion | Duplication | Verbosity | Import cycles | Time | +| -------- | ---------- | ----- | ---------- | ------- | ----------- | --------- | ------------- | ---- | +| Rust | `avidianity/codeint` | 154 | 16,400 | 31.0% | 5.2% | 5.3% | 2.3% | 0.06s | +| Rust | `BurntSushi/ripgrep` | 105 | 24,961 | 36.4% | 31.1% | 31.3% | 29.3% | 0.07s | +| Rust | `sharkdp/fd` | 25 | 3,423 | 44.6% | 0.0% | 0.1% | 56.5% | 0.02s | +| Rust | `dtolnay/serde` | 189 | 19,425 | 45.7% | 40.2% | 40.2% | 0.0% | 0.06s | +| PHP | `laravel/laravel` | 29 | 762 | 0.0% | 0.0% | 0.0% | 8.0% | 0.03s | +| PHP | `laravel/framework` | 3,208 | 132,791 | 16.9% | 8.1% | 8.2% | 4.4% | 0.47s | +| Dart | `dart-lang/pub` | 547 | 26,170 | 44.4% | 0.5% | 1.7% | 78.6% | 0.88s | +| Dart | `flutter/packages` | 4,137 | 434,407 | 45.9% | 23.1% | 23.3% | 18.5% | 3.68s |