Compare commits

...

4 Commits

Author SHA1 Message Date
Dandaedre 215a164a04
chore: release milestone 24
Rust CI JohnSlop failed CI.
Gitea/john_slop/pipeline/head There was a failure building this commit Details
2026-09-30 01:13:26 +02:00
Dandaedre 501328d05f
feat: add runtime diagnostic catalog workflow 2026-09-30 01:06:42 +02:00
Dandaedre 70ad6e5cf8
feat: load runtime diagnostic catalogs 2026-09-30 00:59:26 +02:00
Dandaedre 62a64ad816
docs: plan runtime diagnostic catalogs 2026-09-30 00:57:48 +02:00
31 changed files with 761 additions and 51 deletions

View File

@ -1,11 +1,11 @@
[last_run_clean]
run_status = "Success"
lines_parsed = 408
coverage = 93.09
lines_parsed = 418
coverage = 92.83
[last_run_clean.run_duration]
secs = 52
nanos = 332052570
secs = 53
nanos = 964406972
[last_run_incremental]
run_status = "Success"

View File

@ -146,12 +146,20 @@ The precedence from lowest to highest is:
1. embedded `crates/john-slop-core/assets/config.toml` and
`crates/john-slop-core/assets/heuristics.toml`;
2. user base config at `$XDG_CONFIG_HOME/john_slop/config.toml`, conventionally
2. runtime diagnostic catalogs: the optional user-wide `diagnostics.toml`, then
explicitly selected catalogs in command-line order;
3. user base config at `$XDG_CONFIG_HOME/john_slop/config.toml`, conventionally
`~/.config/john_slop/config.toml` on Linux;
3. named user config at `$XDG_CONFIG_HOME/john_slop/<config_name>.toml` when a
4. named user config at `$XDG_CONFIG_HOME/john_slop/<config_name>.toml` when a
validated config name is selected;
4. an explicit `--config <path>` file;
5. explicit CLI flags for the current invocation.
5. an explicit `--config <path>` file;
6. explicit CLI flags for the current invocation.
Diagnostic catalog files may contain only `schema_version` and `[[rules]]`.
They can add or patch data-driven rules but cannot define executable matcher
algorithms, categories, replacements, thresholds, or input policy. Normal
configuration layers intentionally load afterward so they can disable or tune
catalog rules by stable ID.
Missing optional files are allowed; malformed files are fatal and identify their
origin. A config name accepts only ASCII letters, digits, `_`, and `-`; it cannot

View File

@ -6,6 +6,25 @@ All notable changes to John Slop are recorded here. The format follows
## [Unreleased]
## [0.1.24] - 2026-09-30
### Added
- Added restricted runtime `diagnostics.toml` catalogs for defining
exact-phrase, regex, and repeated-regex rules without recompilation.
- Added repeatable `--diagnostics <FILE>` support across the detector,
formatter, and LSP, including LSP configuration reloads.
- Added `john-slop config init-diagnostics`, a commented starter catalog, and a
complete project example.
### Changed
- User and explicit diagnostic catalogs load before normal configuration so
later base, named, and explicit layers can tune or disable their stable IDs.
- Runtime catalogs reject code-backed matcher engines and unrelated settings;
executable plugin behavior remains outside the declarative configuration
boundary.
## [0.1.23] - 2026-09-30
### Added
@ -92,7 +111,8 @@ All notable changes to John Slop are recorded here. The format follows
- Stdio LSP replacement diagnostics and versioned quick fixes.
- Runnable examples, reviewed fixtures, fuzz targets, benchmarks, and CI gates.
[Unreleased]: https://git.dandaedre.com/idle-org/john_slop/compare/v0.1.23...HEAD
[Unreleased]: https://git.dandaedre.com/idle-org/john_slop/compare/v0.1.24...HEAD
[0.1.24]: https://git.dandaedre.com/idle-org/john_slop/compare/v0.1.23...v0.1.24
[0.1.23]: https://git.dandaedre.com/idle-org/john_slop/compare/v0.1.22...v0.1.23
[0.1.22]: https://git.dandaedre.com/idle-org/john_slop/compare/v0.1.21...v0.1.22
[0.1.21]: https://git.dandaedre.com/idle-org/john_slop/compare/v0.1.20...v0.1.21

6
Cargo.lock generated
View File

@ -699,7 +699,7 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]
name = "john-slop-core"
version = "0.1.23"
version = "0.1.24"
dependencies = [
"directories",
"figment",
@ -717,7 +717,7 @@ dependencies = [
[[package]]
name = "john-slop-lsp"
version = "0.1.23"
version = "0.1.24"
dependencies = [
"john-slop-core",
"serde_json",
@ -728,7 +728,7 @@ dependencies = [
[[package]]
name = "john_slop"
version = "0.1.23"
version = "0.1.24"
dependencies = [
"clap",
"criterion",

View File

@ -4,7 +4,7 @@ default-members = [".", "crates/john-slop-core", "crates/john-slop-lsp"]
resolver = "3"
[workspace.package]
version = "0.1.23"
version = "0.1.24"
edition = "2024"
rust-version = "1.98.1"
license = "MIT"
@ -18,8 +18,8 @@ figment = { version = "0.10.19", default-features = false, features = ["toml"] }
futures = { version = "0.3.34", default-features = false, features = ["std"] }
globset = { version = "0.4.20", default-features = false }
insta = { version = "1.48.0", default-features = false }
john-slop-core = { version = "0.1.23", path = "crates/john-slop-core" }
john-slop-lsp-engine = { package = "john-slop-lsp", version = "0.1.23", path = "crates/john-slop-lsp" }
john-slop-core = { version = "0.1.24", path = "crates/john-slop-core" }
john-slop-lsp-engine = { package = "john-slop-lsp", version = "0.1.24", path = "crates/john-slop-lsp" }
miette = { version = "7.6.0", default-features = false, features = ["derive"] }
regex = "1.13.1"
serde = { version = "1.0.229", features = ["derive"] }

View File

@ -34,8 +34,12 @@ or individual-rule switches as needed:
```sh
john-slop config init
john-slop config init-diagnostics
```
The second command creates a runtime rule catalog: exact-phrase and regex
diagnostics can then be added without changing or recompiling the program.
Diagnostics are colored Miette reports by default. Make the command fail when a
document reaches a chosen low-care evidence score with `--fail-score 0..100`:

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="version: 0.1.23"><title>version: 0.1.23</title><linearGradient id="bms-57a874b394dd235d" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-57a874b394dd235d"><rect width="96" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-57a874b394dd235d)"><rect width="51" height="18" fill="#555"/><rect x="51" width="45" height="18" fill="#fe7d37"/><rect width="96" height="18" fill="url(#bms-57a874b394dd235d)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="265" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">version</text><text x="265" y="130" transform="scale(.1)" fill="#fff" textLength="410">version</text><text aria-hidden="true" x="725" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="350">0.1.23</text><text x="725" y="130" transform="scale(.1)" fill="#fff" textLength="350">0.1.23</text></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="18" role="img" aria-label="version: 0.1.24"><title>version: 0.1.24</title><linearGradient id="bms-92b6d7b702266c6a" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-92b6d7b702266c6a"><rect width="96" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-92b6d7b702266c6a)"><rect width="51" height="18" fill="#555"/><rect x="51" width="45" height="18" fill="#fe7d37"/><rect width="96" height="18" fill="url(#bms-92b6d7b702266c6a)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="265" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">version</text><text x="265" y="130" transform="scale(.1)" fill="#fff" textLength="410">version</text><text aria-hidden="true" x="725" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="350">0.1.24</text><text x="725" y="130" transform="scale(.1)" fill="#fff" textLength="350">0.1.24</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,27 @@
# Runtime diagnostic catalog. Copy or generate this as `diagnostics.toml` and
# add data-driven rules without rebuilding John Slop.
schema_version = 1
# This starter rule is disabled until its phrase and metadata fit your policy.
# Duplicate this complete table for additional diagnostics; every ID must be
# unique lowercase kebab-case.
[[rules]]
id = "custom-review-marker"
category = "style"
severity = "warning"
matcher = "exact-phrase"
pattern = "REVIEW BEFORE PUBLISHING"
weight = 8.0
message = "a project review marker remains in the source"
help = "Resolve or remove the marker before publishing."
occurrence_cap = 1
enabled = false
[rules.scope]
content = ["prose", "source-code"]
extensions = []
include = []
exclude = []
skip_generated = true
skip_vendor = true
skip_minified = true

View File

@ -16,12 +16,18 @@ use crate::{Category, FindingSeverity};
const EMBEDDED_CONFIG: &str = include_str!("../assets/config.toml");
const EMBEDDED_HEURISTICS: &str = include_str!("../assets/heuristics.toml");
const EMBEDDED_UNICODE: &str = include_str!("../assets/unicode.toml");
const DIAGNOSTICS_TEMPLATE: &str = include_str!("../assets/diagnostics-template.toml");
/// Return the commented base configuration suitable for a user or project layer.
pub const fn default_config_template() -> &'static str {
EMBEDDED_CONFIG
}
/// Return a commented, valid starter catalog for runtime diagnostics.
pub const fn default_diagnostics_template() -> &'static str {
DIAGNOSTICS_TEMPLATE
}
/// A validated named configuration without path syntax or a file extension.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ConfigName(String);
@ -149,6 +155,7 @@ impl ThresholdOverrides {
#[derive(Debug, Clone)]
pub struct ConfigLoader {
paths: ConfigPaths,
diagnostic_files: Vec<PathBuf>,
overrides: ConfigOverrides,
}
@ -166,10 +173,17 @@ impl ConfigLoader {
pub fn from_paths(paths: ConfigPaths) -> Self {
Self {
paths,
diagnostic_files: Vec::new(),
overrides: ConfigOverrides::default(),
}
}
/// Add required runtime diagnostic catalogs in declaration order.
pub fn with_diagnostic_files(mut self, paths: impl IntoIterator<Item = PathBuf>) -> Self {
self.diagnostic_files.extend(paths);
self
}
/// Add highest-precedence scalar overrides from the current invocation.
pub fn with_overrides(mut self, overrides: ConfigOverrides) -> Self {
self.overrides = overrides;
@ -181,9 +195,21 @@ impl ConfigLoader {
&self.paths
}
/// Return explicitly selected runtime diagnostic catalogs in load order.
pub fn diagnostic_files(&self) -> &[PathBuf] {
&self.diagnostic_files
}
/// Load embedded, user, named, explicit, and command-line layers in order.
pub fn load(&self) -> Result<Config, ConfigError> {
let mut config = Config::embedded();
apply_optional_diagnostic_file(&mut config, &self.paths.diagnostics())?;
for path in &self.diagnostic_files {
if !path.exists() {
return Err(ConfigError::ExplicitDiagnosticFileMissing { path: path.clone() });
}
apply_diagnostic_file(&mut config, path)?;
}
apply_optional_file(&mut config, &self.paths.base)?;
if let Some(path) = &self.paths.named {
apply_optional_file(&mut config, path)?;
@ -214,6 +240,34 @@ pub enum ConfigError {
/// Requested explicit path.
path: PathBuf,
},
/// A deliberately selected runtime diagnostic catalog does not exist.
#[error("explicit diagnostic catalog `{path}` does not exist")]
#[diagnostic(code(john_slop::config::diagnostics_missing))]
ExplicitDiagnosticFileMissing {
/// Requested diagnostic catalog path.
path: PathBuf,
},
/// A runtime diagnostic catalog uses an unsupported schema.
#[error("diagnostic catalog `{path}` has schema_version {actual}; expected 1")]
#[diagnostic(code(john_slop::config::diagnostics_schema))]
UnsupportedDiagnosticSchema {
/// Diagnostic catalog path.
path: PathBuf,
/// Unsupported schema version.
actual: u32,
},
/// A runtime catalog attempted to introduce a rule backed by internal code.
#[error("runtime diagnostic `{id}` cannot introduce the code-backed `{matcher}` matcher")]
#[diagnostic(
code(john_slop::config::diagnostics_matcher),
help("Use exact-phrase, regex, or repeated-regex for runtime rules.")
)]
UnsupportedDiagnosticMatcher {
/// New rule ID.
id: String,
/// Rejected matcher name.
matcher: &'static str,
},
/// Figment could not read, parse, merge, or deserialize a source.
#[error("failed to load embedded configuration")]
#[diagnostic(code(john_slop::config::embedded_invalid))]
@ -430,6 +484,49 @@ fn apply_optional_file(config: &mut Config, path: &std::path::Path) -> Result<()
}
}
fn apply_optional_diagnostic_file(
config: &mut Config,
path: &std::path::Path,
) -> Result<(), ConfigError> {
if path.exists() {
apply_diagnostic_file(config, path)
} else {
Ok(())
}
}
fn apply_diagnostic_file(config: &mut Config, path: &std::path::Path) -> Result<(), ConfigError> {
let source_text = std::fs::read_to_string(path).map_err(|source| ConfigError::Read {
path: path.to_owned(),
source,
})?;
let catalog = Figment::from(Toml::string(&source_text))
.extract::<DiagnosticCatalogLayer>()
.map_err(|source| layer_error(path, source_text, source))?;
if catalog.schema_version != 1 {
return Err(ConfigError::UnsupportedDiagnosticSchema {
path: path.to_owned(),
actual: catalog.schema_version,
});
}
for rule in &catalog.rules {
if config.rules.iter().all(|existing| existing.id != rule.id) {
let matcher = match rule.matcher {
Some(MatcherType::Replacement) => Some("replacement"),
Some(MatcherType::Invisible) => Some("invisible"),
_ => None,
};
if let Some(matcher) = matcher {
return Err(ConfigError::UnsupportedDiagnosticMatcher {
id: rule.id.clone(),
matcher,
});
}
}
}
merge_rules(&mut config.rules, catalog.rules, path)
}
fn apply_file(config: &mut Config, path: &std::path::Path) -> Result<(), ConfigError> {
let source_text = std::fs::read_to_string(path).map_err(|source| ConfigError::Read {
path: path.to_owned(),
@ -508,6 +605,14 @@ struct ConfigLayer {
rules: Vec<RulePatch>,
}
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
struct DiagnosticCatalogLayer {
schema_version: u32,
#[serde(default)]
rules: Vec<RulePatch>,
}
#[derive(Debug, Default, Deserialize)]
#[serde(default, deny_unknown_fields)]
struct DiagnosticLayer {
@ -781,6 +886,11 @@ impl ConfigPaths {
Some(Self::in_directory(directory, name, explicit))
}
/// Return the optional user-wide runtime diagnostic catalog path.
pub fn diagnostics(&self) -> PathBuf {
self.directory.join("diagnostics.toml")
}
/// Resolve paths under a known directory, primarily for deterministic tests.
pub fn in_directory(
directory: PathBuf,
@ -1378,10 +1488,129 @@ mod tests {
);
assert_eq!(paths.base, directory.join("config.toml"));
assert_eq!(paths.diagnostics(), directory.join("diagnostics.toml"));
assert_eq!(paths.named, Some(directory.join("strict-mode.toml")));
assert_eq!(paths.explicit, Some(PathBuf::from("project.toml")));
}
#[test]
fn runtime_diagnostic_catalogs_load_before_normal_overrides() {
let directory = tempfile::tempdir().unwrap();
let first = directory.path().join("first.toml");
let second = directory.path().join("second.toml");
std::fs::write(
directory.path().join("diagnostics.toml"),
r#"
schema_version = 1
[[rules]]
id = "custom-review-marker"
category = "style"
severity = "warning"
matcher = "exact-phrase"
pattern = "REVIEW BEFORE PUBLISHING"
weight = 8.0
message = "a project review marker remains"
help = "Resolve or remove the marker before publishing."
occurrence_cap = 1
enabled = true
scope = { content = ["prose", "source-code"], extensions = [] }
"#,
)
.unwrap();
std::fs::write(
&first,
"schema_version = 1\n[[rules]]\nid = \"custom-review-marker\"\nweight = 9.0\n",
)
.unwrap();
std::fs::write(
&second,
"schema_version = 1\n[[rules]]\nid = \"custom-review-marker\"\nweight = 10.0\n",
)
.unwrap();
std::fs::write(
directory.path().join("config.toml"),
"[[rules]]\nid = \"custom-review-marker\"\nenabled = false\nweight = 11.0\n",
)
.unwrap();
let paths = ConfigPaths::in_directory(directory.path().to_owned(), None, None);
let config = ConfigLoader::from_paths(paths)
.with_diagnostic_files([first, second])
.load()
.unwrap();
let rule = config
.rules
.iter()
.find(|rule| rule.id == "custom-review-marker")
.unwrap();
assert!(!rule.enabled);
assert_eq!(rule.weight, 11.0);
assert_eq!(config.rules.len(), 13);
}
#[test]
fn runtime_diagnostic_catalogs_reject_unsafe_shapes_and_missing_files() {
let directory = tempfile::tempdir().unwrap();
let paths = ConfigPaths::in_directory(directory.path().to_owned(), None, None);
let missing = directory.path().join("missing.toml");
let error = ConfigLoader::from_paths(paths.clone())
.with_diagnostic_files([missing.clone()])
.load()
.unwrap_err();
assert!(matches!(
error,
ConfigError::ExplicitDiagnosticFileMissing { path } if path == missing
));
let catalog = directory.path().join("catalog.toml");
std::fs::write(&catalog, "schema_version = 2\n").unwrap();
let error = ConfigLoader::from_paths(paths.clone())
.with_diagnostic_files([catalog.clone()])
.load()
.unwrap_err();
assert!(matches!(
error,
ConfigError::UnsupportedDiagnosticSchema { actual: 2, .. }
));
std::fs::write(&catalog, "schema_version = 1\n[thresholds]\nlow = 10\n").unwrap();
let error = ConfigLoader::from_paths(paths.clone())
.with_diagnostic_files([catalog.clone()])
.load()
.unwrap_err();
assert!(matches!(error, ConfigError::Layer(layer) if layer.path == catalog));
std::fs::write(
&catalog,
"schema_version = 1\n[[rules]]\nid = \"unsafe-runtime\"\nmatcher = \"replacement\"\n",
)
.unwrap();
let error = ConfigLoader::from_paths(paths.clone())
.with_diagnostic_files([catalog.clone()])
.load()
.unwrap_err();
assert!(matches!(
error,
ConfigError::UnsupportedDiagnosticMatcher { .. }
));
std::fs::write(
&catalog,
"schema_version = 1\n[[rules]]\nid = \"incomplete-rule\"\n",
)
.unwrap();
let error = ConfigLoader::from_paths(paths)
.with_diagnostic_files([catalog])
.load()
.unwrap_err();
assert!(matches!(
error,
ConfigError::IncompleteEntry { kind: "rule", .. }
));
}
#[test]
fn layered_scalar_precedence_is_deterministic() {
let directory = tempfile::tempdir().unwrap();

View File

@ -19,7 +19,7 @@ pub use config::{
ConfigOverrides, ConfigPaths, ConfigValidationError, ConfusablePolicy, ContentKind,
DiagnosticCategories, DiagnosticPolicy, EvidenceThresholds, HeuristicRule, InputLimits,
InputOverrides, MatcherType, ReplacementRule, RuleScope, ThresholdOverrides, UnicodePolicy,
default_config_template,
default_config_template, default_diagnostics_template,
};
pub use detector::{AnalysisContext, Detector, DetectorBuildError, Rule};
pub use diagnostic::FindingDiagnostic;

View File

@ -35,8 +35,8 @@ workspace Tokio requirement enables no features: the LSP library selects
The modules within those crates retain deliberately narrow responsibilities:
- `config` owns validated embedded defaults, the generated Unicode policy, and
input limits;
- `config` owns validated embedded defaults, restricted runtime diagnostic
catalogs, the generated Unicode policy, and input limits;
- `input` streams files, directory entries, and archive members as documents;
- `detector` compiles configured matchers and path scopes once, then produces
explainable findings and a bounded low-care evidence score;
@ -77,10 +77,12 @@ points and presentation-neutral types:
`FindingDiagnostic` is the library bridge to `miette`; CLI-specific concise and
JSON rendering stays in the detector adapter so it cannot alter analysis.
`ConfigLoader` applies embedded, user base, named user, explicit file, and CLI
layers in order. Stable-ID merging and semantic validation happen before a
configuration reaches analysis. Keeping these operations behind the facade
avoids duplicating policy across the three binaries.
`ConfigLoader` applies embedded catalogs, runtime diagnostic catalogs, user
base, named user, explicit file, and CLI layers in order. Stable-ID merging and
semantic validation happen before a configuration reaches analysis. Keeping
these operations behind the facade avoids duplicating policy across the three
binaries. Runtime catalogs are declarative: they can add rules using existing
matcher implementations but cannot load executable code.
The formatter adapter owns filesystem mutation. It resolves configuration and
preflights every requested document before writing, then uses same-directory

View File

@ -9,10 +9,17 @@ default files.
Configuration layers are applied from lowest to highest priority:
1. embedded `assets/config.toml` and `assets/heuristics.toml`;
2. the platform user file `config.toml`;
3. a selected user `<config_name>.toml`;
4. an explicit `--config <FILE>`;
5. configuration flags for the current invocation.
2. the optional platform user diagnostic catalog `diagnostics.toml`, followed
by explicitly selected diagnostic catalogs in declaration order;
3. the platform user file `config.toml`;
4. a selected user `<config_name>.toml`;
5. an explicit `--config <FILE>`;
6. configuration flags for the current invocation.
Diagnostic catalogs load before normal configuration so a base, named, or
explicit configuration can tune or disable a catalog rule by stable ID. A
catalog accepts only `schema_version` and `[[rules]]`; unrelated settings are a
configuration error rather than being silently applied from the wrong file.
On Linux, the user directory conventionally resolves to
`~/.config/john_slop`. John Slop uses operating-system APIs rather than reading
@ -41,6 +48,24 @@ The command refuses to overwrite an existing file. Use
`john-slop --config config.toml path/to/input` or inspect it with the command
shown below.
Generate a dedicated runtime diagnostic catalog separately:
```sh
john-slop config init-diagnostics
```
Place the result at the `user_diagnostics` path printed by `config paths` for
automatic loading, or select one or more project/team catalogs explicitly:
```sh
john-slop --diagnostics team.toml --diagnostics project.toml article.md
john-slop-lsp --diagnostics project.toml
```
Explicit catalogs are applied in command-line order. All catalogs load before
`config.toml`, named configuration, and `--config`, allowing those normal
layers to override their rules.
## Schema
The current `schema_version` is `1`. The complete defaults live in
@ -95,6 +120,36 @@ can disable them or adjust severity, weight, occurrence cap, and scope without
changing code. Invisible findings never authorize edits; generated confusable
mappings follow the bulk policy below.
## Runtime diagnostic catalog
`diagnostics.toml` supports new data-driven diagnostics without recompilation.
Every new rule must provide the complete rule shape:
```toml
schema_version = 1
[[rules]]
id = "custom-review-marker"
category = "style"
severity = "warning"
matcher = "exact-phrase"
pattern = "REVIEW BEFORE PUBLISHING"
weight = 8.0
message = "a project review marker remains"
help = "Resolve or remove the marker before publishing."
occurrence_cap = 1
enabled = true
scope = { content = ["prose", "source-code"], extensions = [] }
```
Runtime rules may select `exact-phrase`, `regex`, or `repeated-regex`.
`replacement` and `invisible` are code-backed catalog sentinels and cannot
define new matching behavior. Categories remain the four stable values listed
above. Unknown fields, invalid or empty-match regular expressions, duplicate
IDs within one catalog, incomplete new rules, and missing explicit catalogs are
fatal. These constraints keep startup deterministic and prevent a configuration
file from executing code.
The generated UTS #39 mappings have one bulk policy:
```toml

View File

@ -67,8 +67,8 @@ Run line coverage with Cargo Tarpaulin:
cargo tarpaulin --config tarpaulin.toml
```
The configuration enforces a 90% floor. The current suite measured 93.09%
(1,523/1,636 lines) on 2026-09-30. The remaining lines are dominated by
The configuration enforces a 90% floor. The current suite measured 92.83%
(1,579/1,701 lines) on 2026-09-30. The remaining lines are dominated by
platform/I/O failure injection, malformed archive internals, coordinate
overflow, LSP logging/reload failures, and subprocess attribution. Do not add
brittle tests or production seams solely to make Tarpaulin count those paths.

View File

@ -109,8 +109,10 @@ formatter among multiple attached language servers.
The server uses the same configuration layers as the other binaries. Add
`args = ["--config-name", "editorial"]` to the Helix language-server table, or
append those arguments to the Vim `cmd` list, when an editor-specific named
configuration is wanted. `--log-json` is available for troubleshooting and
writes lifecycle metadata to stderr without document contents.
configuration is wanted. Use `args = ["--diagnostics", "diagnostics.toml"]` (and
the equivalent Vim command argument) for a project runtime diagnostic catalog.
`--log-json` is available for troubleshooting and writes lifecycle metadata to
stderr without document contents.
## Try the shared fixtures

View File

@ -63,3 +63,9 @@ near-miss cases, reporting changed per-rule/aggregate metrics, explaining the
false-positive tradeoff, updating the digest and decision text, and obtaining
explicit maintainer approval in the change review. A green test alone is not
approval to tune defaults.
Runtime diagnostic catalogs are deployment policy and are not part of the
embedded-catalog digest. Their rules use the same validation and scoring
formula, but teams must evaluate their own added patterns and near misses for
their corpus rather than treating the embedded sign-off as validation of custom
rules.

View File

@ -12,6 +12,12 @@ minified paths decide whether each rule applies. Findings are deduplicated by
rule and byte span, then sorted by start offset, end offset, and rule ID so
every adapter observes the same order.
Additional exact-phrase, regex, and repeated-regex rules can be supplied at
runtime through `diagnostics.toml` or repeatable `--diagnostics` arguments.
They receive the same validation, scoping, scoring, ordering, CLI presentation,
and LSP publication as embedded rules. New matcher algorithms and categories
remain code changes rather than executable configuration.
The generated Unicode 16.0 profile maps every non-ASCII scalar with a printable
ASCII UTS #39 skeleton, alongside ten manually reviewed punctuation mappings.
The default `replace` policy gives each of these findings a formatter/LSP edit;

View File

@ -62,7 +62,8 @@ the formula and [Limitations](limitations.md) before using thresholds in review
workflows.
Configuration layers can be selected with `--config-name NAME` and `--config
FILE`; command-line resource limits are the highest-precedence input overrides.
FILE`; repeat `--diagnostics FILE` to load runtime rule catalogs without
recompilation. Command-line resource limits are the highest-precedence input overrides.
Use `john-slop config show` to print the resolved TOML and `john-slop config
paths` to inspect source precedence. See [Configuration](configuration.md) for
the schema and merge rules.
@ -113,7 +114,10 @@ The modes are mutually exclusive:
- argument, configuration, UTF-8, input, or write failures exit `2`.
All modes use the same embedded/user/named/explicit configuration precedence as
the detector. `--config-name NAME` and `--config FILE` select those layers.
the detector. `--config-name NAME`, `--config FILE`, and repeatable
`--diagnostics FILE` select those layers. Diagnostic rules do not change the
formatter's replacement plan, but catalog validation stays consistent across
all adapters.
Replacement sources use deterministic longest-match semantics, and formatting
twice is byte-for-byte identical to formatting once.
@ -136,6 +140,7 @@ it without positional arguments:
john-slop-lsp
john-slop-lsp --config-name editorial
john-slop-lsp --config ./john-slop.toml
john-slop-lsp --diagnostics ./diagnostics.toml
```
The server advertises full-document synchronization and quick-fix code actions.
@ -151,7 +156,9 @@ code, the configured severity and remediation text, document-version metadata,
and an exact UTF-16 range. Advice maps to LSP information, while warning and
error retain their corresponding LSP severities.
Quick fixes remain intentionally narrower than diagnostics: they are recomputed
Runtime catalog rules are reloaded by
`workspace/didChangeConfiguration` together with normal configuration. Quick
fixes remain intentionally narrower than diagnostics: they are recomputed
from the current snapshot with the shared replacement planner and returned only
for findings carrying safe configured ASCII edits. Style, prompt-leakage, and
source-review findings are diagnostic-only. A request carrying stale John Slop

View File

@ -20,3 +20,16 @@ john-slop config init
```
It preserves an existing `config.toml` unless `--force` is explicit.
[`diagnostics.toml`](diagnostics.toml) is a complete runtime rule definition.
Place it at the `user_diagnostics` path reported by `john-slop config paths` for
automatic loading, or keep it with a project and select it explicitly:
```sh
john-slop --diagnostics examples/config/diagnostics.toml article.md
john-slop-lsp --diagnostics examples/config/diagnostics.toml
```
Generate the commented starter with `john-slop config init-diagnostics`. The
starter rule is disabled until its phrase and metadata are intentionally
customized.

View File

@ -0,0 +1,24 @@
# Runtime diagnostic catalog. Add data-driven rules here without rebuilding
# John Slop, then pass this file with `--diagnostics`.
schema_version = 1
[[rules]]
id = "custom-review-marker"
category = "style"
severity = "warning"
matcher = "exact-phrase"
pattern = "REVIEW BEFORE PUBLISHING"
weight = 8.0
message = "a project review marker remains in the source"
help = "Resolve or remove the marker before publishing."
occurrence_cap = 1
enabled = false
[rules.scope]
content = ["prose", "source-code"]
extensions = []
include = []
exclude = []
skip_generated = true
skip_vendor = true
skip_minified = true

6
fuzz/Cargo.lock generated
View File

@ -385,7 +385,7 @@ dependencies = [
[[package]]
name = "john-slop-core"
version = "0.1.23"
version = "0.1.24"
dependencies = [
"directories",
"figment",
@ -411,7 +411,7 @@ dependencies = [
[[package]]
name = "john-slop-lsp"
version = "0.1.23"
version = "0.1.24"
dependencies = [
"john-slop-core",
"serde_json",
@ -422,7 +422,7 @@ dependencies = [
[[package]]
name = "john_slop"
version = "0.1.23"
version = "0.1.24"
dependencies = [
"clap",
"globset",

View File

@ -36,6 +36,10 @@ struct Cli {
#[arg(long, value_name = "FILE")]
config: Option<PathBuf>,
/// Load a runtime diagnostic catalog; may be supplied more than once.
#[arg(long, value_name = "FILE", action = clap::ArgAction::Append)]
diagnostics: Vec<PathBuf>,
/// Exit 1 if any input would change; do not emit formatted text.
#[arg(long)]
check: bool,
@ -126,7 +130,9 @@ fn main() -> ExitCode {
fn run(cli: &Cli) -> Result<bool> {
let mode = mode(cli);
validate_invocation(cli, mode)?;
let config = ConfigLoader::discover(cli.config_name.as_ref(), cli.config.clone())?.load()?;
let config = ConfigLoader::discover(cli.config_name.as_ref(), cli.config.clone())?
.with_diagnostic_files(cli.diagnostics.clone())
.load()?;
let documents = load_documents(cli.path.as_deref(), cli.recursive, &config)?;
let formatted = format_documents(documents, &config)?;
let changed = formatted.iter().any(FormattedDocument::changed);
@ -333,12 +339,15 @@ mod tests {
"--recursive",
"--config-name",
"strict",
"--diagnostics",
"team.toml",
"docs",
])
.unwrap();
assert_eq!(mode(&write), Mode::Write);
assert!(write.recursive);
assert_eq!(write.config_name.unwrap().as_str(), "strict");
assert_eq!(write.diagnostics, [PathBuf::from("team.toml")]);
assert!(Cli::try_parse_from(["john-slop-fmt", "--check", "--write", "input.txt"]).is_err());
}

View File

@ -27,6 +27,10 @@ struct Cli {
#[arg(long, value_name = "FILE")]
config: Option<PathBuf>,
/// Load a runtime diagnostic catalog; may be supplied more than once.
#[arg(long, value_name = "FILE", action = clap::ArgAction::Append)]
diagnostics: Vec<PathBuf>,
/// Emit newline-delimited JSON lifecycle logs to standard error.
#[arg(long)]
log_json: bool,
@ -35,7 +39,8 @@ struct Cli {
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let loader = ConfigLoader::discover(cli.config_name.as_ref(), cli.config)?;
let loader = ConfigLoader::discover(cli.config_name.as_ref(), cli.config)?
.with_diagnostic_files(cli.diagnostics);
let config = loader.load()?;
let (service, socket) = LspService::new(|client| {
// `ConfigLoader::load` validated this exact snapshot immediately above.

View File

@ -14,7 +14,7 @@ use clap::{Parser, Subcommand, ValueEnum};
use globset::{Glob, GlobSet, GlobSetBuilder};
use john_slop::{
AnalysisContext, Config, ConfigLoader, ConfigName, ConfigOverrides, Detector, InputOverrides,
SourceId, default_config_template, read_inputs, read_stdin,
SourceId, default_config_template, default_diagnostics_template, read_inputs, read_stdin,
};
use miette::{IntoDiagnostic, Result, WrapErr};
@ -39,6 +39,10 @@ struct Cli {
#[arg(long, global = true, value_name = "FILE")]
config: Option<PathBuf>,
/// Load a runtime diagnostic catalog; may be supplied more than once.
#[arg(long, global = true, value_name = "FILE", action = clap::ArgAction::Append)]
diagnostics: Vec<PathBuf>,
/// Override the maximum accepted bytes for one input document.
#[arg(long, global = true, value_name = "BYTES")]
max_document_bytes: Option<u64>,
@ -129,6 +133,13 @@ enum ConfigCommand {
#[arg(long)]
force: bool,
},
/// Generate a commented diagnostics.toml starter in the current directory.
#[command(visible_alias = "diagnostics-init")]
InitDiagnostics {
/// Replace an existing diagnostics.toml instead of refusing to overwrite it.
#[arg(long)]
force: bool,
},
/// Print the fully resolved, validated configuration as deterministic TOML.
Show,
/// Print every selected configuration path in precedence order.
@ -165,6 +176,7 @@ struct RunOutcome {
/// Execute one parsed detector invocation and retain threshold/error state.
fn run(cli: &Cli) -> Result<RunOutcome> {
let loader = ConfigLoader::discover(cli.config_name.as_ref(), cli.config.clone())?
.with_diagnostic_files(cli.diagnostics.clone())
.with_overrides(ConfigOverrides {
input: InputOverrides {
max_document_bytes: cli.max_document_bytes,
@ -180,6 +192,7 @@ fn run(cli: &Cli) -> Result<RunOutcome> {
if let Some(Command::Config { command }) = &cli.command {
match command {
ConfigCommand::Init { force } => write_default_config(*force)?,
ConfigCommand::InitDiagnostics { force } => write_default_diagnostics(*force)?,
ConfigCommand::Show => {
let config = loader.load()?;
print!("{}", toml::to_string_pretty(&config).into_diagnostic()?);
@ -261,7 +274,32 @@ fn run(cli: &Cli) -> Result<RunOutcome> {
}
fn write_default_config(force: bool) -> Result<()> {
let path = Path::new("config.toml");
write_template(
Path::new("config.toml"),
default_config_template(),
force,
"config init --force",
)
}
fn write_default_diagnostics(force: bool) -> Result<()> {
write_template(
Path::new("diagnostics.toml"),
default_diagnostics_template(),
force,
"config init-diagnostics --force",
)
}
fn write_template(path: &Path, contents: &str, force: bool, force_hint: &str) -> Result<()> {
if force
&& std::fs::symlink_metadata(path).is_ok_and(|metadata| metadata.file_type().is_symlink())
{
return Err(miette::miette!(
"refusing to replace symlink `{}`",
path.display()
));
}
let mut options = OpenOptions::new();
options.write(true).create(true);
if force {
@ -271,15 +309,18 @@ fn write_default_config(force: bool) -> Result<()> {
}
let mut file = options.open(path).into_diagnostic().wrap_err_with(|| {
if path.exists() && !force {
"refusing to overwrite ./config.toml; rerun with `config init --force`".to_owned()
format!(
"refusing to overwrite ./{}; rerun with `{force_hint}`",
path.display()
)
} else {
"failed to create ./config.toml".to_owned()
format!("failed to create ./{}", path.display())
}
})?;
file.write_all(default_config_template().as_bytes())
file.write_all(contents.as_bytes())
.into_diagnostic()
.wrap_err("failed to write ./config.toml")?;
println!("wrote ./config.toml");
.wrap_err_with(|| format!("failed to write ./{}", path.display()))?;
println!("wrote ./{}", path.display());
Ok(())
}
@ -334,6 +375,17 @@ fn print_config_paths(loader: &ConfigLoader) {
let paths = loader.paths();
println!("embedded_config = \"<embedded:assets/config.toml>\"");
println!("embedded_heuristics = \"<embedded:assets/heuristics.toml>\"");
println!(
"user_diagnostics = {:?}",
paths.diagnostics().display().to_string()
);
if loader.diagnostic_files().is_empty() {
println!("explicit_diagnostics = \"<not selected>\"");
} else {
for path in loader.diagnostic_files() {
println!("explicit_diagnostics = {:?}", path.display().to_string());
}
}
println!("user_base = {:?}", paths.base.display().to_string());
println!(
"user_named = {:?}",
@ -376,6 +428,7 @@ mod tests {
assert_eq!(cli.fail_level, None);
assert_eq!(cli.output, OutputFormat::Miette);
assert_eq!(cli.config_name, None);
assert!(cli.diagnostics.is_empty());
assert!(cli.command.is_none());
assert_eq!(
cli.paths,
@ -428,6 +481,28 @@ mod tests {
command: ConfigCommand::Init { force: true }
})
));
let diagnostics = Cli::try_parse_from([
"john-slop",
"config",
"init-diagnostics",
"--force",
"--diagnostics",
"team.toml",
"--diagnostics",
"project.toml",
])
.unwrap();
assert_eq!(
diagnostics.diagnostics,
[PathBuf::from("team.toml"), PathBuf::from("project.toml")]
);
assert!(matches!(
diagnostics.command,
Some(Command::Config {
command: ConfigCommand::InitDiagnostics { force: true }
})
));
}
#[test]

View File

@ -606,6 +606,36 @@ feature matrices, evaluation, dependency policy/audit checks, and workspace
package assembly pass; coverage is 93.09% (1,523/1,636 lines), and all release
metadata and binary versions agree on `0.1.23`.
## Milestone 24 — Runtime diagnostic catalogs
- [x] Load a dedicated `$CONFIG_DIR/john_slop/diagnostics.toml` before normal
configuration overrides, and accept repeatable explicit diagnostic catalogs.
Restrict these files to schema metadata and `[[rules]]`, retain merge-by-ID,
reject malformed/incomplete/duplicate definitions, and test precedence.
- [x] Add repeatable `--diagnostics <FILE>` support to the detector, formatter,
and LSP adapters; add a safe command that generates a valid commented
`./diagnostics.toml` starter without overwriting it unless forced. Cover CLI
detection, LSP reload, help, missing files, and generated-template loading.
- [x] Update configuration/editor/development guides, examples, changelog,
evaluation sign-off, release metadata, coverage, badges, and ignored recap;
run all quality, audit, and package gates.
Acceptance: adding an exact-phrase, regex, or repeated-regex diagnostic to the
dedicated user catalog or an explicit catalog changes CLI and LSP diagnostics
without source edits or recompilation; later normal configuration layers can
override or disable those rules; code-backed matcher implementations,
replacement engines, and category expansion remain explicitly out of scope;
all release artifacts agree on `0.1.24` before the immutable `v0.1.24` tag is
created.
Accepted on 2026-09-30 after runtime catalogs added diagnostics through the CLI
and LSP without rebuilding, normal configuration disabled those rules by stable
ID, and invalid or code-backed definitions failed explicitly. Formatting,
Clippy, rustdoc, both feature matrices, evaluation, dependency policy/audit
checks, Unicode-catalog reproducibility, and workspace package assembly pass;
coverage is 92.83% (1,579/1,701 lines), and all release metadata and binary
versions agree on `0.1.24`.
## Deferred by design
- Statistical or model-based authorship classification.
@ -616,6 +646,10 @@ metadata and binary versions agree on `0.1.23`.
- In-place modification of archive members or office documents.
- Network-backed analysis or telemetry.
- Editor-specific extensions; the LSP is the integration boundary.
- Runtime-defined matcher algorithms, arbitrary new diagnostic categories, and
executable/script/plugin rules. TOML catalogs may select only the validated
built-in data-driven matchers; expanding executable behavior needs a separate
trust, sandboxing, compatibility, and performance design.
These are not implied follow-ups. Each requires a separate privacy, safety,
performance, and product-design review before entering the active milestones.

View File

@ -17,6 +17,7 @@ fn formatter_help_contains_helix_and_vim_setup() {
assert!(stdout.contains("Helix ~/.config/helix/languages.toml"));
assert!(stdout.contains("formatter = { command = \"john-slop-fmt\" }"));
assert!(stdout.contains("setlocal formatprg=john-slop-fmt"));
assert!(stdout.contains("--diagnostics <FILE>"));
}
#[test]
@ -32,4 +33,5 @@ fn lsp_help_contains_helix_and_vim_setup() {
assert!(stdout.contains("--log-json"));
assert!(stdout.contains("lsp#register_server"));
assert!(stdout.contains("['john-slop-lsp']"));
assert!(stdout.contains("--diagnostics <FILE>"));
}

View File

@ -57,6 +57,7 @@ fn config_help_lists_generation_and_inspection_commands() {
assert!(output.status.success());
assert!(stdout.contains("init"));
assert!(stdout.contains("init-diagnostics"));
assert!(stdout.contains("show"));
assert!(stdout.contains("paths"));
}
@ -193,6 +194,101 @@ fn config_init_writes_valid_defaults_and_requires_force_to_overwrite() {
assert_eq!(fs::read_to_string(&config).unwrap(), generated);
}
#[test]
fn diagnostics_init_generates_a_loadable_runtime_catalog() {
let directory = tempdir().expect("temp dir");
let catalog = directory.path().join("diagnostics.toml");
let config_home = directory.path().join("config-home");
let created = detector()
.current_dir(directory.path())
.env("XDG_CONFIG_HOME", &config_home)
.args(["config", "init-diagnostics"])
.output()
.expect("generate diagnostic catalog");
assert!(created.status.success());
assert_eq!(created.stdout, b"wrote ./diagnostics.toml\n");
let generated = fs::read_to_string(&catalog).unwrap();
let parsed = toml::from_str::<toml::Value>(&generated).expect("valid catalog TOML");
assert_eq!(parsed["schema_version"].as_integer(), Some(1));
assert_eq!(parsed["rules"].as_array().unwrap().len(), 1);
let loaded = detector()
.current_dir(directory.path())
.env("XDG_CONFIG_HOME", &config_home)
.args(["config", "show", "--diagnostics", "diagnostics.toml"])
.output()
.expect("load generated catalog");
assert!(
loaded.status.success(),
"{}",
String::from_utf8_lossy(&loaded.stderr)
);
let resolved = toml::from_slice::<toml::Value>(&loaded.stdout).unwrap();
assert_eq!(resolved["rules"].as_array().unwrap().len(), 13);
let refused = detector()
.current_dir(directory.path())
.env("XDG_CONFIG_HOME", &config_home)
.args(["config", "init-diagnostics"])
.output()
.unwrap();
assert_eq!(refused.status.code(), Some(2));
assert_eq!(fs::read_to_string(&catalog).unwrap(), generated);
fs::write(&catalog, "invalid").unwrap();
let forced = detector()
.current_dir(directory.path())
.env("XDG_CONFIG_HOME", &config_home)
.args(["config", "diagnostics-init", "--force"])
.output()
.unwrap();
assert!(forced.status.success());
assert_eq!(fs::read_to_string(&catalog).unwrap(), generated);
}
#[test]
fn explicit_runtime_catalog_adds_a_diagnostic_without_recompilation() {
let directory = tempdir().expect("temp dir");
let source = directory.path().join("article.md");
let catalog = directory.path().join("diagnostics.toml");
fs::write(&source, "REVIEW BEFORE PUBLISHING\n").unwrap();
fs::write(
&catalog,
r#"schema_version = 1
[[rules]]
id = "custom-review-marker"
category = "style"
severity = "warning"
matcher = "exact-phrase"
pattern = "REVIEW BEFORE PUBLISHING"
weight = 8.0
message = "a project review marker remains"
help = "Resolve or remove the marker before publishing."
occurrence_cap = 1
enabled = true
scope = { content = ["prose", "source-code"], extensions = [] }
"#,
)
.unwrap();
let output = detector()
.env(
"XDG_CONFIG_HOME",
directory.path().join("empty-config-home"),
)
.args(["--output", "json", "--diagnostics"])
.arg(&catalog)
.arg(&source)
.output()
.expect("run detector with runtime catalog");
assert!(output.status.success());
let records = json_records(&output);
assert_eq!(records[0]["findings"].as_array().unwrap().len(), 1);
assert_eq!(records[0]["findings"][0]["rule_id"], "custom-review-marker");
}
#[test]
fn category_and_individual_configuration_disable_cli_diagnostics() {
let directory = tempdir().expect("temp dir");
@ -262,6 +358,8 @@ fn config_paths_lists_embedded_and_platform_sources() {
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout).expect("UTF-8 stdout");
assert!(stdout.contains("<embedded:assets/config.toml>"));
assert!(stdout.contains("diagnostics.toml"));
assert!(stdout.contains("explicit_diagnostics"));
assert!(stdout.contains("config.toml"));
assert!(stdout.contains("<not selected>"));
}

View File

@ -145,7 +145,7 @@ fn reviewed_corpus_reports_per_rule_metrics_and_false_positive_rate() {
.collect::<String>();
assert_eq!(signoff.schema_version, 1);
assert_eq!(signoff.release, env!("CARGO_PKG_VERSION"));
assert_eq!(signoff.status, "accepted-after-diagnostic-policy");
assert_eq!(signoff.status, "accepted-with-runtime-catalog-boundary");
assert_eq!(signoff.catalog_sha256, catalog_hash);
assert!(signoff.limitations_acknowledged);
assert_eq!(signoff.reviewed_on, "2026-09-30");
@ -153,4 +153,5 @@ fn reviewed_corpus_reports_per_rule_metrics_and_false_positive_rate() {
assert!(signoff.decision.contains("0.90"));
assert!(signoff.decision.contains("UTS #39"));
assert!(signoff.decision.contains("review"));
assert!(signoff.decision.contains("runtime catalogs"));
}

View File

@ -217,4 +217,12 @@ fn commented_base_and_named_configs_form_a_valid_layered_example() {
.find(|rule| rule.id == "assistant-self-identification")
.expect("embedded rule remains present");
assert_eq!(rule.scope.include, vec!["articles/**", "docs/**"]);
assert!(
!config
.rules
.iter()
.find(|rule| rule.id == "custom-review-marker")
.expect("runtime diagnostic example remains present")
.enabled
);
}

View File

@ -1,7 +1,7 @@
schema_version = 1
release = "0.1.23"
release = "0.1.24"
reviewed_on = "2026-09-30"
status = "accepted-after-diagnostic-policy"
status = "accepted-with-runtime-catalog-boundary"
catalog_sha256 = "ae7f4c8309389c6703bc109cb053105da8421ada2e870e12903d5525109aa045"
limitations_acknowledged = true
decision = "Retain category-specific correlation damping: prompt-leakage uses 0.90 per later distinct rule while other families retain 0.75. Keep every diagnostic category enabled by default while allowing layered category gates and individual rule switches. Use generated Unicode 16.0 UTS #39 printable-ASCII mappings in replace mode by default, retain review and off policies for multilingual usage, and keep pinned Gitea invisible/control findings non-mutating. Reviewed corpus scores are pinned with 0/5 observed false-positive documents; the small authored sample does not establish real-world or multilingual accuracy."
decision = "Retain category-specific correlation damping: prompt-leakage uses 0.90 per later distinct rule while other families retain 0.75. Keep every diagnostic category enabled by default while allowing layered category gates and individual rule switches. Permit declarative runtime catalogs to add exact-phrase, regex, and repeated-regex rules, but reject code-backed matcher engines. Use generated Unicode 16.0 UTS #39 printable-ASCII mappings in replace mode by default, retain review and off policies for multilingual usage, and keep pinned Gitea invisible/control findings non-mutating. Reviewed corpus scores are pinned with 0/5 observed false-positive documents; the small authored sample does not establish real-world or multilingual accuracy."

View File

@ -19,23 +19,37 @@ struct Harness {
socket: tower_lsp_server::ClientSocket,
_directory: TempDir,
explicit: Option<PathBuf>,
diagnostics: Option<PathBuf>,
}
impl Harness {
async fn new(explicit_config: Option<&str>) -> Self {
Self::new_with_diagnostics(explicit_config, None).await
}
async fn new_with_diagnostics(
explicit_config: Option<&str>,
diagnostic_catalog: Option<&str>,
) -> Self {
let directory = tempfile::tempdir().unwrap();
let explicit = explicit_config.map(|contents| {
let path = directory.path().join("lsp.toml");
fs::write(&path, contents).unwrap();
path
});
let diagnostics = diagnostic_catalog.map(|contents| {
let path = directory.path().join("runtime-diagnostics.toml");
fs::write(&path, contents).unwrap();
path
});
let paths = ConfigPaths {
directory: directory.path().to_owned(),
base: directory.path().join("missing-base.toml"),
named: None,
explicit: explicit.clone(),
};
let loader = ConfigLoader::from_paths(paths);
let loader =
ConfigLoader::from_paths(paths).with_diagnostic_files(diagnostics.iter().cloned());
let config = loader.load().unwrap();
let (service, socket) = LspService::new(|client| {
LspBackend::new(client, loader, config).expect("build test LSP backend")
@ -45,6 +59,7 @@ impl Harness {
socket,
_directory: directory,
explicit,
diagnostics,
};
let response = harness
.request("initialize", json!({ "capabilities": {} }), 1)
@ -105,6 +120,30 @@ impl Harness {
fn explicit_path(&self) -> &std::path::Path {
self.explicit.as_deref().unwrap()
}
fn diagnostics_path(&self) -> &std::path::Path {
self.diagnostics.as_deref().unwrap()
}
}
fn custom_catalog(enabled: bool) -> String {
format!(
r#"schema_version = 1
[[rules]]
id = "custom-review-marker"
category = "style"
severity = "warning"
matcher = "exact-phrase"
pattern = "REVIEW BEFORE PUBLISHING"
weight = 8.0
message = "a project review marker remains"
help = "Resolve or remove the marker before publishing."
occurrence_cap = 1
enabled = {enabled}
scope = {{ content = ["prose", "source-code"], extensions = [] }}
"#
)
}
fn open_params(uri: &str, version: i32, text: &str) -> Value {
@ -564,6 +603,40 @@ async fn disabled_category_suppresses_lsp_diagnostics() {
assert!(published["diagnostics"].as_array().unwrap().is_empty());
}
#[tokio::test]
async fn runtime_diagnostic_catalog_loads_and_reloads_without_recompilation() {
let enabled = custom_catalog(true);
let mut harness = Harness::new_with_diagnostics(None, Some(&enabled)).await;
let uri = "file:///tmp/catalog.md";
harness
.notify(
"textDocument/didOpen",
open_params(uri, 1, "REVIEW BEFORE PUBLISHING"),
)
.await;
let published = harness
.notification("textDocument/publishDiagnostics")
.await;
let diagnostics = published["diagnostics"].as_array().unwrap();
assert_eq!(diagnostics.len(), 1);
assert_eq!(diagnostics[0]["code"], "custom-review-marker");
fs::write(harness.diagnostics_path(), custom_catalog(false)).unwrap();
let reload = Request::build("workspace/didChangeConfiguration")
.params(json!({ "settings": {} }))
.finish();
let service = &mut harness.service;
let socket = &mut harness.socket;
let reload_future = async { service.ready().await.unwrap().call(reload).await.unwrap() };
let notification_future = async { socket.next().await.unwrap() };
let (reload_response, notification) = tokio::join!(reload_future, notification_future);
assert!(reload_response.is_none());
let refreshed = notification.params().cloned().unwrap();
assert_eq!(refreshed["uri"], uri);
assert!(refreshed["diagnostics"].as_array().unwrap().is_empty());
}
#[tokio::test]
async fn malformed_messages_and_invalid_uris_are_rejected_without_panics() {
assert!("not JSON".parse::<Request>().is_err());

View File

@ -19,6 +19,8 @@ Options:
Load a named user configuration from the platform config directory
--config <FILE>
Load an explicit TOML configuration after user configuration
--diagnostics <FILE>
Load a runtime diagnostic catalog; may be supplied more than once
--max-document-bytes <BYTES>
Override the maximum accepted bytes for one input document
--max-archive-bytes <BYTES>