This guide explains how to build, hash, declare, and test a Language plugin and a Metric plugin for codeint. GLOSSARY.md defines every term on this page. ADR 0002 records why Plugins are WebAssembly components behind a WIT interface.
codeint defines its Plugin contract in package codeint:plugin@0.2.0.
Two WIT files hold the contract:
- wit/language.wit defines
codeint:plugin/language@0.2.0and thelanguage-pluginworld. - wit/metric.wit defines
codeint:plugin/metric@0.2.0and themetric-pluginworld.
The metric interface reuses file-model and resolution from language.
A Language plugin exports language and lowers source files into the Code model.
A Metric plugin exports metric and measures the Code model of one Source set without knowing the source language.
Both worlds import nothing:
world language-plugin {
export language;
}
world metric-plugin {
export metric;
}codeint instantiates every external Plugin with an empty wasmtime::component::Linker.
A Plugin receives no filesystem, network, environment variable, or clock imports.
Any component that imports a WASI host interface such as wasi:filesystem/*, wasi:sockets/*, or wasi:clocks/* fails to instantiate with exit code 2.
Because standard Rust wasm32-wasip2 builds pull in WASI imports, the sample plugins in this repository use #![no_std] with extern crate alloc, a small bump allocator, and an exported cabi_realloc.
Any language or toolchain that produces a WebAssembly component with zero host imports works with codeint.
Install the Rust toolchain listed in rust-toolchain.toml and add the wasm32-wasip2 target:
rustup target add wasm32-wasip2crates/plugin-host/tests/fixtures/sample-plugin/ is a complete Language plugin for a toy .mini language.
Configure the crate as a cdylib and depend on wit-bindgen without default features:
[lib]
crate-type = ["cdylib"]
[dependencies]
wit-bindgen = { version = "=0.63.0", default-features = false, features = ["macros", "realloc"] }Generate bindings for the language-plugin world and export your implementation:
wit_bindgen::generate!({
world: "language-plugin",
path: "../../../../../wit",
});
use exports::codeint::plugin::language::{
DeclaredDep, DepKind, FileModel, FlaggedLine, Function, Guest, ImportRequest, LowerError,
Manifest, ReferenceRange, Resolution, SourceSet, Token, TokenKind, WorkspaceError,
};
struct SampleMiniPlugin;
export!(SampleMiniPlugin);Implement all eight functions on Guest:
| Function | Responsibility |
|---|---|
extensions() -> list<string> |
Return file extensions without a leading dot, such as ["mini"]. |
lower(path, text) -> result<file-model, lower-error> |
Lower one file into its source-set, source-lines, functions (each with optional name and nesting-weighted cognitive-complexity), tokens, flagged-lines, and runtime-imports. Return declaration-only, unparsable, unsupported-file, or too-large on error. |
manifest-paths(repository-paths) -> list<string> |
Select manifest paths from repository-paths that the host reads once on the Plugin's behalf. |
workspace-packages(manifests) -> result<list<string>, workspace-error> |
Return relative Workspace package roots from the manifest contents, or an empty list for a single-package repository. |
resolve-imports(repository-paths, manifests, requests) -> list<resolution> |
Return one resolved(string), external(string) (carrying the canonical package name), builtin (for standard-library or runtime built-ins), or unresolved(string) entry per request, in request order. |
declared-dependencies(manifests) -> list<declared-dep> |
Extract manifest-declared external dependencies (package-root, normalized name, and kind of runtime, dev, or optional). |
entry-points(repository-paths, manifests) -> list<string> |
Discover standard entry-point source files from repository-paths and manifests, returning only paths from repository-paths. |
reference-ranges() -> list<reference-range> |
Return published Reference ranges for this language, at most one per Metric. |
Follow these invariants in lower:
- Keep
functionssorted by startline(line >= 1andline <= end-line), withnameset tononefor anonymous lambdas or closures. - Keep
tokenssorted by 1-basedline, with 64-bit FNV-1atext-hashvalues of each token's UTF-8 text. - Produce identical
source-linesandfunctionsfor LF and CRLF line endings. - Do not count nested functions' decision points, cognitive complexity, or source lines in their enclosing function.
Run this command from the repository root to build the sample Language plugin from scratch:
cargo build \
--manifest-path crates/plugin-host/tests/fixtures/sample-plugin/Cargo.toml \
--target wasm32-wasip2 \
--release \
--lockedCargo writes the WebAssembly component to crates/plugin-host/tests/fixtures/sample-plugin/target/wasm32-wasip2/release/sample_mini_plugin.wasm.
Pass --target-dir target/wasm-plugins to place build artifacts under the root target/ folder instead.
crates/plugin-host/tests/fixtures/sample-metric-plugin/ is a complete Metric plugin that measures long_functions, the share of functions with more than 10 source lines.
Use the same cdylib and wit-bindgen configuration, and generate bindings for the metric-plugin world:
wit_bindgen::generate!({
world: "metric-plugin",
path: "../../../../../wit",
});
use exports::codeint::plugin::metric::{CodeModel, Finding, Guest, Measurement};
struct SampleLongFunctionsPlugin;
export!(SampleLongFunctionsPlugin);Implement all four functions on Guest:
| Function | Responsibility |
|---|---|
key() -> string |
Return the Metric key used in reports, Budgets, and Regression limits, such as long_functions. |
name() -> string |
Return the display name shown in human-readable reports, such as Long functions. |
description() -> string |
Return a short description used in SARIF rule metadata. |
measure(model) -> measurement |
Compute ratio, numerator, denominator, and findings for one Source set's Code model. |
The Plugin host enforces these rules at load and measurement time:
keymust be non-empty, start with a lowercase ASCII letter, and contain only lowercase ASCII letters, digits,_, or-.keymust not collide with built-in Metric keys (erosion,duplication,verbosity,import_cycles), reserved report keys (files,source_lines,packages), or another external Metric plugin's key.ratiomust be finite and between0.0and1.0.numeratoranddenominatormust be finite and>= 0.0.- Each Finding must have a non-empty
id, a 1-basedline(>= 1), and a valid repository-relativepathusing/. - Compute each Finding
idfrom file path and content (never from line numbers) socodeint difftracks moved Findings as unchanged. - Order
findingsworst first.
Run this command from the repository root to build the sample Metric plugin from scratch:
cargo build \
--manifest-path crates/plugin-host/tests/fixtures/sample-metric-plugin/Cargo.toml \
--target wasm32-wasip2 \
--release \
--lockedCargo writes the WebAssembly component to crates/plugin-host/tests/fixtures/sample-metric-plugin/target/wasm32-wasip2/release/sample_long_functions_plugin.wasm.
Every external Plugin entry in codeint.json requires the 64-character hexadecimal SHA-256 digest of the .wasm file.
codeint verifies the digest in constant time before compiling or instantiating the component.
A missing digest, malformed digest, or hash mismatch stops the run with exit code 2.
Compute the digest for each built .wasm file:
On Linux:
sha256sum path/to/plugin.wasmOn macOS:
shasum -a 256 path/to/plugin.wasmOn Windows PowerShell:
Get-FileHash -Algorithm SHA256 path\to\plugin.wasmCopy the 64-character hexadecimal digest into plugins[].sha256 in codeint.json.
Recompute the digest whenever you rebuild the .wasm file.
Declare external Language plugins and Metric plugins under the top-level plugins array in codeint.json.
See docs/reference.md for the full codeint.json schema.
{
"plugins": [
{
"name": "sample-mini",
"kind": "language",
"path": "plugins/sample_mini_plugin.wasm",
"sha256": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
},
{
"name": "long-functions",
"kind": "metric",
"path": "plugins/sample_long_functions_plugin.wasm",
"sha256": "fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210"
}
],
"languages": [
{ "plugin": "typescript-javascript", "include": ["web"] },
{ "plugin": "sample-mini", "include": ["scripts"] }
],
"budgets": {
"production": {
"long_functions": 0.25
}
},
"regression_limits": {
"long_functions": {
"ratio_rise": 0.02,
"new_findings": "numerator_rise_with_new_findings"
}
}
}Key rules:
namemust be unique across Plugins and must not reuse a built-in Plugin name such astypescript-javascript.kindis"language"(the default when omitted) or"metric".pathresolves relative to the repository root, or uses an absolute path as given.- Use
languagesto scope Language plugins when two plugins claim the same file extension in the same repository. When two Language plugins claim the same extension in overlapping folders, codeint stops with exit code 2. - Use an external Metric plugin's
key(such aslong_functions) inbudgetsandregression_limitsthe same way you use built-in Metric keys.
Every Language plugin (built-in or external) must pass the shared Seam 2 conformance suite in crates/plugin-host/tests/conformance.rs. The suite verifies:
- Non-empty file extensions without leading dots.
UnsupportedFile, empty file,DeclarationOnly, andUnparsablehandling inlower.- Production and Test Source set classification.
- LF and CRLF equivalence for
source-linesandfunctions. - Ordered
functionsandtokens, valid 1-based line spans, and non-empty Flagged line rules. manifest-pathsreturning only paths fromrepository-paths.workspace-packagesparsing valid manifests and returningWorkspaceError::Manifeston invalid manifests.resolve-importsreturning oneResolved,External,Builtin, orUnresolvedresult per request in request order.declared-dependenciesreturning manifest-declared dependencies andentry-pointsreturning only paths fromrepository-paths.reference-rangesreturning valid ranges.- Safe concurrent
lowercalls across threads.
Run the conformance suite and the host sandbox tests:
cargo test --locked -p codeint-plugin-host --test conformance
cargo test --locked -p codeint-plugin-host --test loadCopy your built .wasm file into a Git repository, compute its SHA-256 digest, declare it in codeint.json, and run codeint check and codeint diff:
codeint check --format json
codeint check --format markdown
codeint check --format sarif
codeint diff main --format jsonVerify that:
- External Language plugins measure files matching their extensions and report
skippedanddeclaration_onlyfiles. - External Metric plugins appear alongside built-in Metrics in TOON, JSON, Markdown, and SARIF reports.
budgetsfail with exit code 1 when an external Metric exceeds its Budget.codeint diffclassifies new, resolved, and unchanged Findings using your Findingidvalues and enforcesregression_limits.
Run the CLI plugin integration tests in this repository to see end-to-end examples:
cargo test --locked -p codeint-cli --test pluginsThe WIT package declaration carries a Semantic Versioning number:
package codeint:plugin@0.2.0;This version identifies the exported interfaces codeint:plugin/language@0.2.0 and codeint:plugin/metric@0.2.0 in the compiled WebAssembly component.
- Pre-1.0 (
0.x.y): While the major version is0, a minor version bump (0.1.0to0.2.0) may introduce breaking changes. A patch version bump (0.1.0to0.1.1) contains only non-breaking fixes. - Stable (
1.x.yand later):- Additive, backward-compatible changes (such as adding a new optional interface or new world) bump the minor version (
1.0.0to1.1.0). - Breaking changes (removing or renaming a function, changing record fields, or changing variant or enum cases) bump the major version (
1.0.0to2.0.0).
- Additive, backward-compatible changes (such as adding a new optional interface or new world) bump the minor version (
wasmtime::component::bindgen! binds the codeint host to the exact WIT interface version compiled into the binary.
At load time, wasmtime checks that the component's exported interface name and version match what the host expects.
- A Plugin built against an incompatible WIT version (such as
codeint:plugin@0.1.0) fails at load time with exit code 2, naming the plugin, its found interface version, the required0.2.0interface version, and how to rebuild it. - Rebuild the Plugin against the updated
wit/files and update itssha256incodeint.jsonwhen upgrading to a breaking WIT version. - Never silently mutate an existing released WIT version in place; every breaking change gets a new version number.