Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
path: |
target/wasm-fixtures/wasm32-wasip2/debug/*.wasm
target/wasm-fixtures/wasm32-wasip2/debug/.fixtures-stamp
key: v0-wasm-fixtures-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml', 'Cargo.toml', '.cargo/config.toml', 'wit/**', 'crates/plugin-sdk/**', 'crates/plugin-host/tests/fixtures/**') }}
key: v0-wasm-fixtures-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml', 'Cargo.toml', '.cargo/config.toml', 'wit/**', 'crates/plugin-sdk/**', 'crates/plugin-host/tests/fixtures/**', 'crates/plugin-host/wit-legacy/**') }}
- id: go
run: echo "version=$(go env GOVERSION)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9
Expand Down Expand Up @@ -346,7 +346,7 @@ jobs:
path: |
target/wasm-fixtures/wasm32-wasip2/debug/*.wasm
target/wasm-fixtures/wasm32-wasip2/debug/.fixtures-stamp
key: v0-wasm-fixtures-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml', 'Cargo.toml', '.cargo/config.toml', 'wit/**', 'crates/plugin-sdk/**', 'crates/plugin-host/tests/fixtures/**') }}
key: v0-wasm-fixtures-${{ runner.os }}-${{ hashFiles('rust-toolchain.toml', 'Cargo.toml', '.cargo/config.toml', 'wit/**', 'crates/plugin-sdk/**', 'crates/plugin-host/tests/fixtures/**', 'crates/plugin-host/wit-legacy/**') }}
- uses: ./.github/actions/gitleaks
- uses: ./.github/actions/lychee
- id: go
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ The planted-defect suite runs with the other tests: `cargo test --locked -p code

## Adding a Language or Metric plugin

Read [docs/plugins.md](./docs/plugins.md) to build an external WebAssembly Plugin against `codeint:plugin@0.5.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.
Inspect `plugins/languages/` for built-in implementations of the Code model contract.

## Code of Conduct

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Beyond static snapshots, codeint helps humans and coding agents understand how f

codeint is written in safe Rust (`#![forbid(unsafe_code)]` on every host, core, CLI, and built-in Plugin crate, [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.5.0` WIT contract with mandatory SHA-256 verification, zero host capabilities, and configurable memory and time caps, using `codeint-plugin-sdk` for safe Rust builds on `wasm32-wasip2` (`no_std`, zero extra tools) or `wasm32-unknown-unknown` (`std` plus `wasm-tools component new`) with zero WASI imports ([ADR 0027](./docs/adr/0027-plugin-sdk-guest-runtime-unsafe.md)).
External WebAssembly Plugins implement the versioned `codeint:plugin@0.6.0` WIT contract with mandatory SHA-256 verification, zero host capabilities, and configurable memory and time caps, using `codeint-plugin-sdk` for safe Rust builds on `wasm32-wasip2` (`no_std`, zero extra tools) or `wasm32-unknown-unknown` (`std` plus `wasm-tools component new`) with zero WASI imports ([ADR 0027](./docs/adr/0027-plugin-sdk-guest-runtime-unsafe.md)).

Read [docs/guide/philosophy-and-architecture.md](./docs/guide/philosophy-and-architecture.md) for the full architecture diagram and design rationale.

Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/check/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,9 @@ fn no_imports_language_plugin_never_has_import_manifest_or_entry_point_functions

guest_lower!(|_path, text| {
let mut model = lines_of(&text)?;
model.runtime_imports.push("./never-resolved".to_owned());
model
.runtime_imports
.push("./never-resolved".to_owned().into());
model.program_start = true;
Ok(model)
});
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,13 @@ fn plugin_component_error(
PluginHostError::Instantiate { reason, .. } => DoctorCheck::error(
id,
format!(
"External Wasm Plugin {name:?} at {label} is not loadable: component does not satisfy the codeint:plugin@{PLUGIN_INTERFACE_VERSION} sandbox contract"
"External Wasm Plugin {name:?} at {label} is not loadable: component does not satisfy the Plugin sandbox contract"
),
)
.with_detail(reason.clone())
.with_remedy(format!(
"Ensure the Plugin exports codeint:plugin/language@{PLUGIN_INTERFACE_VERSION} or codeint:plugin/metric@{PLUGIN_INTERFACE_VERSION} and imports no host capabilities."
)),
.with_remedy(
"Ensure the Plugin exports a supported Language or Metric interface and imports no host capabilities.",
),
_ => DoctorCheck::error(
id,
format!("External Wasm Plugin {name:?} at {label} is not loadable: {error}"),
Expand Down
12 changes: 6 additions & 6 deletions crates/cli/src/remedy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use codeint_config::{
use codeint_git::GitError;
use codeint_metrics::ImpactError;
use codeint_model::{LanguagePluginError, MetricPluginError, WorkspaceError};
use codeint_plugin_host::PluginHostError;
use codeint_plugin_host::{PLUGIN_INTERFACE_VERSION, PluginHostError};
use codeint_report::{SavedReportError, TraceError};

use crate::CliError;
Expand Down Expand Up @@ -851,14 +851,14 @@ fn plugin_load_remedy(error: &PluginHostError, file: ConfigFileKind) -> Option<C
"Verify the plugin file has not been modified, then update sha256 in {file} to match the trusted file."
))
}
PluginHostError::Compile { .. } => Cow::Borrowed(
"Build the plugin as a WebAssembly component targeting codeint:plugin@0.5.0.",
),
PluginHostError::Compile { .. } => Cow::Owned(format!(
"Build the plugin as a WebAssembly component targeting codeint:plugin@{PLUGIN_INTERFACE_VERSION}."
)),
PluginHostError::Instantiate { .. } => Cow::Borrowed(
"Ensure the plugin exports codeint:plugin/language@0.5.0 or codeint:plugin/metric@0.5.0 and imports no host capabilities.",
"Ensure the plugin exports a supported Language or Metric interface and imports no host capabilities.",
),
PluginHostError::IncompatibleContractVersion { .. } => Cow::Owned(format!(
"Rebuild the plugin against codeint:plugin@0.5.0 and update its sha256 in {file}."
"Rebuild the plugin against codeint:plugin@{PLUGIN_INTERFACE_VERSION} and update its sha256 in {file}."
)),
_ => return None,
})
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/tests/integration/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ fn a_result_cached_under_plugin_interface_0_2_0_or_cache_version_7_is_not_reused
assert_eq!(entries, 2);
}

assert_eq!(current_settings["plugin_interface_version"], json!("0.5.0"));
assert_eq!(current_settings["plugin_interface_version"], json!("0.6.0"));
assert_eq!(current_settings["cache_version"], json!(10));
}

Expand Down Expand Up @@ -1759,7 +1759,7 @@ fn a_result_cached_under_plugin_interface_0_5_0_is_reused_on_subsequent_runs() {
let fixture = Fixture::with_an_eroded_file_removed_since_main();
let first = fixture.diff_json("main");
let (settings, _) = read_cached_settings_and_result(fixture.result_cache.path());
assert_eq!(settings["plugin_interface_version"], json!("0.5.0"));
assert_eq!(settings["plugin_interface_version"], json!("0.6.0"));

fixture.forget_committed_file("main:src/removed.ts");
let second = fixture.diff_json("main");
Expand Down
18 changes: 9 additions & 9 deletions crates/cli/tests/integration/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,47 +528,47 @@ fn doctor_reports_v0_2_0_and_v0_3_0_language_and_metric_plugins_as_not_loadable(
"legacy_v0_2_0_language_plugin.wasm",
"codeint:plugin/language@0.2.0",
"0.2.0",
"codeint:plugin/language@0.5.0",
"codeint:plugin/language@0.6.0",
),
(
"legacy-v02-metric",
"metric",
"legacy_v0_2_0_metric_plugin.wasm",
"codeint:plugin/metric@0.2.0",
"0.2.0",
"codeint:plugin/metric@0.5.0",
"codeint:plugin/metric@0.6.0",
),
(
"legacy-v03-lang",
"language",
"legacy_v0_3_0_language_plugin.wasm",
"codeint:plugin/language@0.3.0",
"0.3.0",
"codeint:plugin/language@0.5.0",
"codeint:plugin/language@0.6.0",
),
(
"legacy-v03-metric",
"metric",
"legacy_v0_3_0_metric_plugin.wasm",
"codeint:plugin/metric@0.3.0",
"0.3.0",
"codeint:plugin/metric@0.5.0",
"codeint:plugin/metric@0.6.0",
),
(
"legacy-v04-lang",
"language",
"legacy_v0_4_0_language_plugin.wasm",
"codeint:plugin/language@0.4.0",
"0.4.0",
"codeint:plugin/language@0.5.0",
"codeint:plugin/language@0.6.0",
),
(
"legacy-v04-metric",
"metric",
"legacy_v0_4_0_metric_plugin.wasm",
"codeint:plugin/metric@0.4.0",
"0.4.0",
"codeint:plugin/metric@0.5.0",
"codeint:plugin/metric@0.6.0",
),
];

Expand Down Expand Up @@ -596,13 +596,13 @@ fn doctor_reports_v0_2_0_and_v0_3_0_language_and_metric_plugins_as_not_loadable(
&& summary.contains(found_interface)
&& summary.contains(found_version)
&& summary.contains(expected_interface)
&& summary.contains("0.5.0"),
&& summary.contains("0.6.0"),
"expected summary to report {name} not loadable with both versions, got: {summary:?}"
);
let remedy = check["remedy"].as_str().unwrap_or_default();
assert!(
remedy.to_ascii_lowercase().contains("rebuild") && remedy.contains("0.5.0"),
"expected remedy to instruct rebuilding against 0.5.0, got: {remedy:?}"
remedy.to_ascii_lowercase().contains("rebuild") && remedy.contains("0.6.0"),
"expected remedy to instruct rebuilding against 0.6.0, got: {remedy:?}"
);
}

Expand Down
18 changes: 9 additions & 9 deletions crates/cli/tests/integration/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,13 +1204,13 @@ fn assert_legacy_plugin_stops_check(
&& lines[0].contains(found_interface)
&& lines[0].contains(found_version)
&& lines[0].contains(expected_interface)
&& lines[0].contains("0.5.0"),
&& lines[0].contains("0.6.0"),
"expected stderr line 1 to name plugin and both versions, got: {}",
lines[0]
);
assert!(
lines[1].to_ascii_lowercase().contains("rebuild") && lines[1].contains("0.5.0"),
"expected stderr line 2 to instruct rebuilding against 0.5.0, got: {}",
lines[1].to_ascii_lowercase().contains("rebuild") && lines[1].contains("0.6.0"),
"expected stderr line 2 to instruct rebuilding against 0.6.0, got: {}",
lines[1]
);
}
Expand All @@ -1223,23 +1223,23 @@ fn v0_2_0_through_v0_4_0_language_plugins_stop_check_with_exit_2_and_rebuild_rem
"legacy_v0_2_0_language_plugin.wasm",
"codeint:plugin/language@0.2.0",
"0.2.0",
"codeint:plugin/language@0.5.0",
"codeint:plugin/language@0.6.0",
);
assert_legacy_plugin_stops_check(
"legacy-v03-lang",
"language",
"legacy_v0_3_0_language_plugin.wasm",
"codeint:plugin/language@0.3.0",
"0.3.0",
"codeint:plugin/language@0.5.0",
"codeint:plugin/language@0.6.0",
);
assert_legacy_plugin_stops_check(
"legacy-v04-lang",
"language",
"legacy_v0_4_0_language_plugin.wasm",
"codeint:plugin/language@0.4.0",
"0.4.0",
"codeint:plugin/language@0.5.0",
"codeint:plugin/language@0.6.0",
);
}

Expand All @@ -1251,23 +1251,23 @@ fn v0_2_0_through_v0_4_0_metric_plugins_stop_check_with_exit_2_and_rebuild_remed
"legacy_v0_2_0_metric_plugin.wasm",
"codeint:plugin/metric@0.2.0",
"0.2.0",
"codeint:plugin/metric@0.5.0",
"codeint:plugin/metric@0.6.0",
);
assert_legacy_plugin_stops_check(
"legacy-v03-metric",
"metric",
"legacy_v0_3_0_metric_plugin.wasm",
"codeint:plugin/metric@0.3.0",
"0.3.0",
"codeint:plugin/metric@0.5.0",
"codeint:plugin/metric@0.6.0",
);
assert_legacy_plugin_stops_check(
"legacy-v04-metric",
"metric",
"legacy_v0_4_0_metric_plugin.wasm",
"codeint:plugin/metric@0.4.0",
"0.4.0",
"codeint:plugin/metric@0.5.0",
"codeint:plugin/metric@0.6.0",
);
}

Expand Down
2 changes: 2 additions & 0 deletions crates/cli/tests/integration/trace.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod package_conditions;

use std::fs;
use std::path::Path;
use std::process::Output;
Expand Down
46 changes: 46 additions & 0 deletions crates/cli/tests/integration/trace/package_conditions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use serde_json::json;

use super::{init_git_repo, trace_json};

#[test]
fn trace_selects_package_exports_by_runtime_import_kind() {
let repo = init_git_repo(&[
(
"package.json",
r#"{"private":true,"workspaces":["packages/*"]}"#,
),
(
"packages/dual/package.json",
r#"{"name":"dual","exports":{
".":{"require":"./c.cjs","import":"./e.mjs"},
"./reverse":{"import":"./e.mjs","require":"./c.cjs"}
}}"#,
),
("packages/dual/e.mjs", "export default 'esm';"),
("packages/dual/c.cjs", "module.exports = 'cjs';"),
("main.mjs", "import 'dual';"),
("main.cjs", "require('dual/reverse');"),
(
"mixed.mjs",
"import { createRequire } from 'node:module';\n\
const require = createRequire(import.meta.url);\n\
import('dual');\n\
require('dual');",
),
]);

for (source, target, connected) in [
("main.mjs", "packages/dual/e.mjs", true),
("main.mjs", "packages/dual/c.cjs", false),
("main.cjs", "packages/dual/c.cjs", true),
("main.cjs", "packages/dual/e.mjs", false),
("mixed.mjs", "packages/dual/e.mjs", true),
("mixed.mjs", "packages/dual/c.cjs", true),
] {
let trace = trace_json(repo.path(), &[source, target]);
assert_eq!(trace["connected"], connected, "{source} to {target}");
if connected {
assert_eq!(trace["paths"], json!([[source, target]]));
}
}
}
5 changes: 3 additions & 2 deletions crates/model/HOW-TO.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl LanguagePlugin for Plain {
}
```

- The interface is defined once, in [wit/language.wit](../../wit/language.wit), as the versioned package `codeint:plugin@0.5.0`.
- The interface is defined once, in [wit/language.wit](../../wit/language.wit), as the versioned package `codeint:plugin@0.6.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 `LanguagePlugin` directly and borrows `&RepoPath`, `&str`, and `&[RepoPath]` to avoid per-file clones.
Expand Down Expand Up @@ -213,8 +213,9 @@ impl LanguagePlugin for Plain {
A `HazardLine` never holds source text.
A line that matches two rules appears once per rule.
Return an empty list when `has_hazard_rules` returns `false`; six of the eight built-in Language plugins always return an empty list (`sql` and `shell` declare Hazard line rules).
- `runtime_imports` lists the specifiers of imports that run when the file runs.
- `runtime_imports` lists the specifier and import kind of each runtime import.
Leave out type-only imports.
Use `ImportKind::Unknown` for languages without import and require forms.
The Language plugin can normalize specifiers and group imported names from the same module.
- `program_start` is `false` unless the source text marks the file as a program start, such as a Go `package main` file.
Seven of the eight built-in Language plugins always set `program_start` to `false` (`go` sets it for `package main` files).
Expand Down
27 changes: 27 additions & 0 deletions crates/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ mod tests;
mod tooling;
mod workspace;

impl FileModel {
pub fn runtime_import_specifiers(&self) -> impl Iterator<Item = &str> {
self.runtime_imports
.iter()
.map(|edge| edge.specifier.as_str())
}
}

impl language::ImportRequest {
pub fn new(importer: impl Into<String>, specifier: impl Into<String>) -> Self {
Self {
importer: importer.into(),
specifier: specifier.into(),
kind: language::ImportKind::Unknown,
}
}
}

impl From<String> for language::ImportEdge {
fn from(specifier: String) -> Self {
Self {
specifier,
kind: language::ImportKind::Unknown,
}
}
}

mod bindings {
wit_bindgen::generate!({
world: "language-plugin",
Expand Down
Loading
Loading