From 7d4fedb1fe45346fd6eedfe1a1d8a350d6727517 Mon Sep 17 00:00:00 2001 From: John Michael Manlupig Date: Tue, 24 Nov 2026 13:10:06 +0800 Subject: [PATCH 01/25] feat(plugins): move Plugin interface to version 0.3.0 Move the Language plugin and Metric plugin WIT contracts, Plugin host, CLI remedies, test fixtures, and documentation to codeint:plugin@0.3.0 without adding new records, functions, or variants. Export PLUGIN_INTERFACE_VERSION from codeint-plugin-host as the single source of truth for the active Plugin interface version. Closes #245 --- CONTRIBUTING.md | 2 +- README.md | 2 +- crates/cli/src/remedy.rs | 8 +-- crates/model/HOW-TO.md | 2 +- crates/plugin-host/HOW-TO.md | 2 +- crates/plugin-host/src/lib.rs | 2 + crates/plugin-host/src/wasm.rs | 2 +- crates/plugin-host/src/wasm_metric.rs | 2 +- .../dual-version-language/src/lib.rs | 67 ++++++++++++------- crates/plugin-host/tests/load.rs | 20 +++--- docs/guide/philosophy-and-architecture.md | 2 +- docs/plugins.md | 28 +++++--- docs/reference.md | 4 +- llms.txt | 2 +- wit/language.wit | 2 +- wit/metric.wit | 2 +- 16 files changed, 92 insertions(+), 57 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a3e226a1..6bcbe6e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,7 +47,7 @@ People and coding agents follow the same rules in this repository: read [.rules] ## Adding a Language or Metric plugin -Read [docs/plugins.md](./docs/plugins.md) to build an external WebAssembly Plugin against `codeint:plugin@0.2.0`, or inspect `plugins/languages/` to see how built-in Language plugins implement the Code model contract. +Read [docs/plugins.md](./docs/plugins.md) to build an external WebAssembly Plugin against `codeint:plugin@0.3.0`, or inspect `plugins/languages/` to see how built-in Language plugins implement the Code model contract. ## Code of Conduct diff --git a/README.md b/README.md index cc4ef115..5ae2dd92 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Beyond static snapshots, codeint helps humans and coding agents understand how f 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. -External WebAssembly Plugins implement the versioned `codeint:plugin@0.2.0` WIT contract with mandatory SHA-256 verification, zero host capabilities, and configurable memory and time caps. +External WebAssembly Plugins implement the versioned `codeint:plugin@0.3.0` WIT contract 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. diff --git a/crates/cli/src/remedy.rs b/crates/cli/src/remedy.rs index 8e715297..23e58a6f 100644 --- a/crates/cli/src/remedy.rs +++ b/crates/cli/src/remedy.rs @@ -446,15 +446,15 @@ fn plugin_load_remedy(error: &PluginHostError, file: ConfigFileKind) -> Option<& ) } PluginHostError::Compile { .. } => { - "Build the plugin as a WebAssembly component targeting codeint:plugin@0.2.0." + "Build the plugin as a WebAssembly component targeting codeint:plugin@0.3.0." } PluginHostError::Instantiate { .. } => { - "Ensure the plugin exports codeint:plugin/language@0.2.0 or codeint:plugin/metric@0.2.0 and imports no host capabilities." + "Ensure the plugin exports codeint:plugin/language@0.3.0 or codeint:plugin/metric@0.3.0 and imports no host capabilities." } PluginHostError::IncompatibleContractVersion { .. } => choose_file_remedy( file, - "Rebuild the plugin against codeint:plugin@0.2.0 and update its sha256 in codeint.json.", - "Rebuild the plugin against codeint:plugin@0.2.0 and update its sha256 in codeint.jsonc.", + "Rebuild the plugin against codeint:plugin@0.3.0 and update its sha256 in codeint.json.", + "Rebuild the plugin against codeint:plugin@0.3.0 and update its sha256 in codeint.jsonc.", ), PluginHostError::NonHttpsUrl { .. } => choose_file_remedy( file, diff --git a/crates/model/HOW-TO.md b/crates/model/HOW-TO.md index 091aa0fb..a8745749 100644 --- a/crates/model/HOW-TO.md +++ b/crates/model/HOW-TO.md @@ -85,7 +85,7 @@ impl Guest for Plain { } ``` -- The interface is defined once, in [wit/language.wit](../../wit/language.wit), as the versioned package `codeint:plugin@0.2.0`. +- The interface is defined once, in [wit/language.wit](../../wit/language.wit), as the versioned package `codeint:plugin@0.3.0`. - `codeint_model::language` holds the Rust types that wit-bindgen generates from that file. Never write a second Rust copy of a WIT type. - A built-in Language plugin implements the generated `Guest` trait, so it compiles against the same interface as an external WebAssembly Plugin. diff --git a/crates/plugin-host/HOW-TO.md b/crates/plugin-host/HOW-TO.md index 7f89ea94..81d995ac 100644 --- a/crates/plugin-host/HOW-TO.md +++ b/crates/plugin-host/HOW-TO.md @@ -15,7 +15,7 @@ let external = load_language_plugins(repository.root(), &configuration.plugins, - Relative paths in `PluginSource::Path` resolve against `repository_root`; absolute paths are used as given. - `PluginSource::HttpsUrl` downloads through `curl` with `--proto =https --tlsv1.2 --proto-redir =https`, verifies the SHA-256 digest of the downloaded bytes before atomically renaming into `/.wasm`, and reuses a valid cached entry without network I/O. - Every `WasmLanguagePlugin` is instantiated with an empty `wasmtime::component::Linker` with zero host capabilities (no WASI, no filesystem, no network, no environment variables, no clocks). A component that imports any host interface fails to instantiate with `PluginHostError::Instantiate`. -- Every `WasmLanguagePlugin` and `WasmMetricPlugin` validates its exported WIT interface version against `codeint:plugin@0.2.0` before instantiation; an incompatible version (such as `codeint:plugin@0.1.0`) fails with `PluginHostError::IncompatibleContractVersion`. +- Every `WasmLanguagePlugin` and `WasmMetricPlugin` validates its exported WIT interface version against `codeint:plugin@0.3.0` before instantiation; an incompatible version (such as `codeint:plugin@0.2.0`) fails with `PluginHostError::IncompatibleContractVersion`. - Every `WasmLanguagePlugin` and `WasmMetricPlugin` enforces `codeint_config::PluginLimits` (linear memory cap via `wasmtime::ResourceLimiter` and wall-clock time limit via `wasmtime` epoch interruption). Use `load_language_plugins_with_limits` and `load_metric_plugins_with_limits` to pass configured limits from `codeint.json`. - `WasmLanguagePlugin` implements `codeint_model::LanguagePlugin: Sync` using an internal pool of pre-instantiated component instances, so callers can invoke `lower` concurrently across threads. diff --git a/crates/plugin-host/src/lib.rs b/crates/plugin-host/src/lib.rs index 3d9895ab..72167072 100644 --- a/crates/plugin-host/src/lib.rs +++ b/crates/plugin-host/src/lib.rs @@ -20,6 +20,8 @@ pub use sha256::{format_hex as sha256_hex, sha256}; pub use wasm::WasmLanguagePlugin; pub use wasm_metric::WasmMetricPlugin; +pub const PLUGIN_INTERFACE_VERSION: &str = "0.3.0"; + #[derive(Debug, thiserror::Error)] pub enum PluginHostError { #[error("cannot read Plugin {name:?} at {}", path.display())] diff --git a/crates/plugin-host/src/wasm.rs b/crates/plugin-host/src/wasm.rs index 0e75a6d3..5b1a828f 100644 --- a/crates/plugin-host/src/wasm.rs +++ b/crates/plugin-host/src/wasm.rs @@ -33,7 +33,7 @@ pub(crate) struct ContractSpec { const LANGUAGE_CONTRACT: ContractSpec = ContractSpec { interface_prefix: "codeint:plugin/language@", - expected_interface: "codeint:plugin/language@0.2.0", + expected_interface: "codeint:plugin/language@0.3.0", }; pub(crate) fn check_contract_version( diff --git a/crates/plugin-host/src/wasm_metric.rs b/crates/plugin-host/src/wasm_metric.rs index 78e346d5..4a9c8264 100644 --- a/crates/plugin-host/src/wasm_metric.rs +++ b/crates/plugin-host/src/wasm_metric.rs @@ -13,7 +13,7 @@ use crate::wasm::{ContractSpec, InstancePool, instantiate_sandboxed_component, m const METRIC_CONTRACT: ContractSpec = ContractSpec { interface_prefix: "codeint:plugin/metric@", - expected_interface: "codeint:plugin/metric@0.2.0", + expected_interface: "codeint:plugin/metric@0.3.0", }; mod bindings { diff --git a/crates/plugin-host/tests/fixtures/sandbox-probes/dual-version-language/src/lib.rs b/crates/plugin-host/tests/fixtures/sandbox-probes/dual-version-language/src/lib.rs index bfcf5cfc..6f0fb0d3 100644 --- a/crates/plugin-host/tests/fixtures/sandbox-probes/dual-version-language/src/lib.rs +++ b/crates/plugin-host/tests/fixtures/sandbox-probes/dual-version-language/src/lib.rs @@ -10,20 +10,22 @@ use alloc::vec::Vec; wit_bindgen::generate!({ world: "dual-language-plugin", inline: " - package codeint:dual@0.2.0; + package codeint:dual@0.3.0; world dual-language-plugin { - export codeint:plugin/language@0.1.0; export codeint:plugin/language@0.2.0; + export codeint:plugin/language@0.3.0; } - package codeint:plugin@0.1.0 { + package codeint:plugin@0.2.0 { interface language { record function { line: u32, end-line: u32, decision-points: u32, source-lines: u32, + name: option, + cognitive-complexity: u32, } enum token-kind { @@ -67,10 +69,23 @@ wit_bindgen::generate!({ variant resolution { resolved(string), - external, + external(string), + builtin, unresolved(string), } + enum dep-kind { + runtime, + dev, + optional, + } + + record declared-dep { + package-root: string, + name: string, + kind: dep-kind, + } + variant lower-error { unparsable(string), unsupported-file(string), @@ -100,11 +115,13 @@ wit_bindgen::generate!({ manifest-paths: func(repository-paths: list) -> list; workspace-packages: func(manifests: list) -> result, workspace-error>; resolve-imports: func(repository-paths: list, manifests: list, requests: list) -> list; + declared-dependencies: func(manifests: list) -> list; + entry-points: func(repository-paths: list, manifests: list) -> list; reference-ranges: func() -> list; } } - package codeint:plugin@0.2.0 { + package codeint:plugin@0.3.0 { interface language { record function { line: u32, @@ -255,33 +272,33 @@ macro_rules! impl_common_guest { vec![] } + fn declared_dependencies( + _manifests: Vec, + ) -> Vec { + vec![exports::codeint::$pkg::language::DeclaredDep { + package_root: String::new(), + name: "dual-dep".to_string(), + kind: exports::codeint::$pkg::language::DepKind::Runtime, + }] + } + + fn entry_points( + repository_paths: Vec, + _manifests: Vec, + ) -> Vec { + repository_paths.into_iter().take(1).collect() + } + fn reference_ranges() -> Vec { vec![] } }; } -impl exports::codeint::plugin0_1_0::language::Guest for DualVersionLanguagePlugin { - impl_common_guest!(plugin0_1_0); -} - impl exports::codeint::plugin0_2_0::language::Guest for DualVersionLanguagePlugin { impl_common_guest!(plugin0_2_0); +} - fn declared_dependencies( - _manifests: Vec, - ) -> Vec { - vec![exports::codeint::plugin0_2_0::language::DeclaredDep { - package_root: String::new(), - name: "dual-dep".to_string(), - kind: exports::codeint::plugin0_2_0::language::DepKind::Runtime, - }] - } - - fn entry_points( - repository_paths: Vec, - _manifests: Vec, - ) -> Vec { - repository_paths.into_iter().take(1).collect() - } +impl exports::codeint::plugin0_3_0::language::Guest for DualVersionLanguagePlugin { + impl_common_guest!(plugin0_3_0); } diff --git a/crates/plugin-host/tests/load.rs b/crates/plugin-host/tests/load.rs index 16361588..5da3dcd3 100644 --- a/crates/plugin-host/tests/load.rs +++ b/crates/plugin-host/tests/load.rs @@ -12,8 +12,9 @@ use codeint_model::{ MetricPluginError, RepoPath, SourceFile, SourceSet, Token, TokenKind, token_text_hash, }; use codeint_plugin_host::{ - PluginHostError, WasmLanguagePlugin, load_language_plugin, load_language_plugin_with_limits, - load_language_plugins, load_metric_plugin, load_metric_plugin_with_limits, load_metric_plugins, + PLUGIN_INTERFACE_VERSION, PluginHostError, WasmLanguagePlugin, load_language_plugin, + load_language_plugin_with_limits, load_language_plugins, load_metric_plugin, + load_metric_plugin_with_limits, load_metric_plugins, }; use common::{build_fixture_workspace, declaration_for, declaration_with_kind, sample_plugin_wasm}; @@ -572,11 +573,12 @@ fn built_in_and_sample_plugins_fit_comfortably_within_default_limits() { } #[test] -fn verifies_0_2_0_contract_fields_and_methods_across_wasm_boundary() { +fn verifies_0_3_0_contract_fields_and_methods_across_wasm_boundary() { + assert_eq!(PLUGIN_INTERFACE_VERSION, "0.3.0"); let wasm_path = sample_plugin_wasm(); let declaration = declaration_for("sample-mini", wasm_path); let plugin = load_language_plugin(Path::new("."), &declaration, &PluginHostConfig::default()) - .expect("0.2.0 sample plugin loads"); + .expect("0.3.0 sample plugin loads"); let lowered = plugin .lower( @@ -698,12 +700,12 @@ fn rejects_v0_1_0_language_plugin_with_actionable_version_mismatch_error() { let error = load_language_plugin(Path::new("."), &declaration, &PluginHostConfig::default()) .err() - .expect("0.1.0 Language plugin must be rejected by 0.2.0 host"); + .expect("0.1.0 Language plugin must be rejected by 0.3.0 host"); assert_incompatible_contract_error( error, "legacy-lang", - "codeint:plugin/language@0.2.0", + "codeint:plugin/language@0.3.0", "codeint:plugin/language@0.1.0", ); } @@ -715,12 +717,12 @@ fn rejects_v0_1_0_metric_plugin_with_actionable_version_mismatch_error() { let error = load_metric_plugin(Path::new("."), &declaration, &PluginHostConfig::default()) .err() - .expect("0.1.0 Metric plugin must be rejected by 0.2.0 host"); + .expect("0.1.0 Metric plugin must be rejected by 0.3.0 host"); assert_incompatible_contract_error( error, "legacy-metric", - "codeint:plugin/metric@0.2.0", + "codeint:plugin/metric@0.3.0", "codeint:plugin/metric@0.1.0", ); } @@ -918,7 +920,7 @@ fn rejects_invalid_entry_points_and_declared_dependencies_from_wasm_plugin() { } #[test] -fn loads_dual_version_language_plugin_exporting_0_1_0_and_0_2_0() { +fn loads_dual_version_language_plugin_exporting_0_2_0_and_0_3_0() { let plugin = load_probe( "dual-lang", "dual_version_language_plugin.wasm", diff --git a/docs/guide/philosophy-and-architecture.md b/docs/guide/philosophy-and-architecture.md index eddf67e3..24b44376 100644 --- a/docs/guide/philosophy-and-architecture.md +++ b/docs/guide/philosophy-and-architecture.md @@ -75,5 +75,5 @@ CLI + MCP + Rust SDK (crates/cli) & JS/TS SDK (npm/codeint) - **Git-native measurement (`crates/git`)**: reads tracked working-tree files and historical commits directly from Git objects via `gix`, never modifying the working tree during `diff`, `trend`, `churn`, or `coupling`, with a content-addressed result cache for fast repeated runs. - **Language plugins (`plugins/languages/*`)**: own every language-specific rule (parsing, named functions, decision points, cognitive complexity, tokens, Flagged lines, imports, workspaces, entry points, declared dependencies, Source-set defaults) and lower files into the language-neutral **Code model** (`crates/model`). TypeScript/JavaScript (including `.vue` and `.svelte` `