Compare commits
4 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
964347d041 | |
|
|
ae448ad60c | |
|
|
cd15bb8503 | |
|
|
cdc05af416 |
|
|
@ -1,11 +1,11 @@
|
|||
[last_run_clean]
|
||||
run_status = "Success"
|
||||
lines_parsed = 393
|
||||
coverage = 93.05
|
||||
lines_parsed = 408
|
||||
coverage = 93.09
|
||||
|
||||
[last_run_clean.run_duration]
|
||||
secs = 50
|
||||
nanos = 858077900
|
||||
secs = 52
|
||||
nanos = 332052570
|
||||
|
||||
[last_run_incremental]
|
||||
run_status = "Success"
|
||||
|
|
|
|||
|
|
@ -117,7 +117,9 @@ Start with high-precision, independently testable signals:
|
|||
|
||||
Avoid weak demographic, dialect, spelling, grammar, vocabulary, or
|
||||
English-fluency proxies. Repetition alone must not trigger a high evidence-band
|
||||
verdict. Give users a per-rule disable/weight override and path/language scopes.
|
||||
verdict. Give users category and per-rule enablement controls, per-rule weight
|
||||
overrides, and path/language scopes. A rule is active only when both its
|
||||
category gate and individual `enabled` field are active.
|
||||
|
||||
Scoring must be documented and deterministic. Use bounded weighted evidence,
|
||||
apply a per-rule occurrence cap, and damp correlated findings from the same rule
|
||||
|
|
|
|||
18
CHANGELOG.md
18
CHANGELOG.md
|
|
@ -6,6 +6,21 @@ All notable changes to John Slop are recorded here. The format follows
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.1.23] - 2026-09-30
|
||||
|
||||
### Added
|
||||
|
||||
- Added typed category-level diagnostic switches for `typography`, `style`,
|
||||
`prompt-leakage`, and `source-code`, composed with the existing individual
|
||||
rule switches through every configuration layer.
|
||||
- Added `john-slop config init` and its `config generate` alias to write the
|
||||
commented embedded base configuration into the current directory.
|
||||
|
||||
### Changed
|
||||
|
||||
- Configuration generation protects an existing `config.toml` unless
|
||||
`--force` is explicitly supplied.
|
||||
|
||||
## [0.1.22] - 2026-09-30
|
||||
|
||||
### Added
|
||||
|
|
@ -77,7 +92,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.22...HEAD
|
||||
[Unreleased]: https://git.dandaedre.com/idle-org/john_slop/compare/v0.1.23...HEAD
|
||||
[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
|
||||
[0.1.20]: https://git.dandaedre.com/idle-org/john_slop/compare/v0.1.0...v0.1.20
|
||||
|
|
|
|||
|
|
@ -699,7 +699,7 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
|||
|
||||
[[package]]
|
||||
name = "john-slop-core"
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
dependencies = [
|
||||
"directories",
|
||||
"figment",
|
||||
|
|
@ -717,7 +717,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "john-slop-lsp"
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
dependencies = [
|
||||
"john-slop-core",
|
||||
"serde_json",
|
||||
|
|
@ -728,7 +728,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "john_slop"
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"criterion",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = [".", "crates/john-slop-core", "crates/john-slop-lsp"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
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.22", path = "crates/john-slop-core" }
|
||||
john-slop-lsp-engine = { package = "john-slop-lsp", version = "0.1.22", path = "crates/john-slop-lsp" }
|
||||
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" }
|
||||
miette = { version = "7.6.0", default-features = false, features = ["derive"] }
|
||||
regex = "1.13.1"
|
||||
serde = { version = "1.0.229", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -29,6 +29,13 @@ Scan a document or source directory:
|
|||
john-slop path/to/document path/to/source-directory
|
||||
```
|
||||
|
||||
Generate a commented `config.toml` in the current directory, then edit category
|
||||
or individual-rule switches as needed:
|
||||
|
||||
```sh
|
||||
john-slop config init
|
||||
```
|
||||
|
||||
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`:
|
||||
|
||||
|
|
|
|||
|
|
@ -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.22"><title>version: 0.1.22</title><linearGradient id="bms-49fd3ccd9d32982d" 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-49fd3ccd9d32982d"><rect width="96" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-49fd3ccd9d32982d)"><rect width="51" height="18" fill="#555"/><rect x="51" width="45" height="18" fill="#fe7d37"/><rect width="96" height="18" fill="url(#bms-49fd3ccd9d32982d)"/></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.22</text><text x="725" y="130" transform="scale(.1)" fill="#fff" textLength="350">0.1.22</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.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>
|
||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
|
@ -3,6 +3,21 @@
|
|||
schema_version = 1
|
||||
replacements = []
|
||||
|
||||
# Diagnostic category gates are applied in addition to each rule's `enabled`
|
||||
# field. Set a category to false to silence that family without copying every
|
||||
# embedded rule into this file.
|
||||
[diagnostics.categories]
|
||||
typography = true
|
||||
style = true
|
||||
prompt-leakage = true
|
||||
source-code = true
|
||||
|
||||
# Disable or re-enable one diagnostic by its stable ID. Uncomment and change
|
||||
# the ID as needed; `john-slop config show` lists the complete resolved rules.
|
||||
# [[rules]]
|
||||
# id = "templated-conclusion"
|
||||
# enabled = false
|
||||
|
||||
[input]
|
||||
max_document_bytes = 8388608
|
||||
max_archive_bytes = 67108864
|
||||
|
|
|
|||
|
|
@ -17,6 +17,11 @@ 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");
|
||||
|
||||
/// Return the commented base configuration suitable for a user or project layer.
|
||||
pub const fn default_config_template() -> &'static str {
|
||||
EMBEDDED_CONFIG
|
||||
}
|
||||
|
||||
/// A validated named configuration without path syntax or a file extension.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct ConfigName(String);
|
||||
|
|
@ -495,6 +500,7 @@ fn apply_cli_overrides(config: &mut Config, overrides: &ConfigOverrides) {
|
|||
#[serde(default, deny_unknown_fields)]
|
||||
struct ConfigLayer {
|
||||
schema_version: Option<u32>,
|
||||
diagnostics: DiagnosticLayer,
|
||||
input: InputLayer,
|
||||
thresholds: ThresholdLayer,
|
||||
unicode: UnicodeLayer,
|
||||
|
|
@ -502,6 +508,21 @@ struct ConfigLayer {
|
|||
rules: Vec<RulePatch>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
struct DiagnosticLayer {
|
||||
categories: DiagnosticCategoryLayer,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields, rename_all = "kebab-case")]
|
||||
struct DiagnosticCategoryLayer {
|
||||
typography: Option<bool>,
|
||||
style: Option<bool>,
|
||||
prompt_leakage: Option<bool>,
|
||||
source_code: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
struct UnicodeLayer {
|
||||
|
|
@ -561,6 +582,7 @@ fn apply_layer(
|
|||
if let Some(value) = layer.schema_version {
|
||||
config.schema_version = value;
|
||||
}
|
||||
apply_diagnostic_layer(&mut config.diagnostics, layer.diagnostics);
|
||||
apply_input_layer(&mut config.input, layer.input);
|
||||
apply_threshold_layer(&mut config.thresholds, layer.thresholds);
|
||||
if let Some(value) = layer.unicode.confusables {
|
||||
|
|
@ -570,6 +592,22 @@ fn apply_layer(
|
|||
merge_rules(&mut config.rules, layer.rules, path)
|
||||
}
|
||||
|
||||
fn apply_diagnostic_layer(target: &mut DiagnosticPolicy, layer: DiagnosticLayer) {
|
||||
let categories = layer.categories;
|
||||
if let Some(value) = categories.typography {
|
||||
target.categories.typography = value;
|
||||
}
|
||||
if let Some(value) = categories.style {
|
||||
target.categories.style = value;
|
||||
}
|
||||
if let Some(value) = categories.prompt_leakage {
|
||||
target.categories.prompt_leakage = value;
|
||||
}
|
||||
if let Some(value) = categories.source_code {
|
||||
target.categories.source_code = value;
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_input_layer(target: &mut InputLimits, layer: InputLayer) {
|
||||
if let Some(value) = layer.max_document_bytes {
|
||||
target.max_document_bytes = value;
|
||||
|
|
@ -782,6 +820,8 @@ pub struct ReplacementRule {
|
|||
pub struct Config {
|
||||
/// Configuration schema understood by this build.
|
||||
pub schema_version: u32,
|
||||
/// Category-level diagnostic switches.
|
||||
pub diagnostics: DiagnosticPolicy,
|
||||
/// Enabled replacement rules in deterministic matching order.
|
||||
pub replacements: Vec<ReplacementRule>,
|
||||
/// Bulk behavior for generated Unicode mappings.
|
||||
|
|
@ -795,6 +835,51 @@ pub struct Config {
|
|||
pub input: InputLimits,
|
||||
}
|
||||
|
||||
/// Category-level switches applied in addition to individual rule settings.
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct DiagnosticPolicy {
|
||||
/// Enablement of each stable diagnostic category.
|
||||
pub categories: DiagnosticCategories,
|
||||
}
|
||||
|
||||
impl DiagnosticPolicy {
|
||||
/// Return whether diagnostics in `category` are enabled.
|
||||
pub const fn category_enabled(self, category: Category) -> bool {
|
||||
match category {
|
||||
Category::Typography => self.categories.typography,
|
||||
Category::Style => self.categories.style,
|
||||
Category::PromptLeakage => self.categories.prompt_leakage,
|
||||
Category::SourceCode => self.categories.source_code,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Enablement switches for the four built-in diagnostic categories.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
|
||||
pub struct DiagnosticCategories {
|
||||
/// Suspicious typography or character usage.
|
||||
pub typography: bool,
|
||||
/// Repeated or templated writing style.
|
||||
pub style: bool,
|
||||
/// Prompt, response, or assistant scaffolding.
|
||||
pub prompt_leakage: bool,
|
||||
/// Low-care source-code patterns.
|
||||
pub source_code: bool,
|
||||
}
|
||||
|
||||
impl Default for DiagnosticCategories {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
typography: true,
|
||||
style: true,
|
||||
prompt_leakage: true,
|
||||
source_code: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Bulk policy for Unicode mappings whose targets come from UTS #39.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
|
|
@ -1337,6 +1422,53 @@ mod tests {
|
|||
assert_eq!(config.thresholds.medium, 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diagnostic_categories_follow_layer_precedence() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let name = "strict".parse::<ConfigName>().unwrap();
|
||||
let explicit = directory.path().join("project.toml");
|
||||
std::fs::write(
|
||||
directory.path().join("config.toml"),
|
||||
"[diagnostics.categories]\nstyle = false\nprompt-leakage = false\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
directory.path().join("strict.toml"),
|
||||
"[diagnostics.categories]\nstyle = true\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
&explicit,
|
||||
"[diagnostics.categories]\nprompt-leakage = true\nsource-code = false\n",
|
||||
)
|
||||
.unwrap();
|
||||
let paths =
|
||||
ConfigPaths::in_directory(directory.path().to_owned(), Some(&name), Some(explicit));
|
||||
|
||||
let config = ConfigLoader::from_paths(paths).load().unwrap();
|
||||
|
||||
assert!(config.diagnostics.categories.typography);
|
||||
assert!(config.diagnostics.categories.style);
|
||||
assert!(config.diagnostics.categories.prompt_leakage);
|
||||
assert!(!config.diagnostics.categories.source_code);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_diagnostic_category_is_a_layer_error() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join("config.toml");
|
||||
std::fs::write(
|
||||
&path,
|
||||
"[diagnostics.categories]\nmade-up-category = false\n",
|
||||
)
|
||||
.unwrap();
|
||||
let paths = ConfigPaths::in_directory(directory.path().to_owned(), None, None);
|
||||
|
||||
let error = ConfigLoader::from_paths(paths).load().unwrap_err();
|
||||
|
||||
assert!(matches!(error, ConfigError::Layer(layer) if layer.path == path));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn absent_optional_files_are_ignored_but_missing_explicit_file_is_fatal() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
|
|
@ -165,7 +165,11 @@ impl Detector {
|
|||
let mut findings = self
|
||||
.rules
|
||||
.iter()
|
||||
.filter(|rule| rule.is_enabled() && rule.applies(context))
|
||||
.filter(|rule| {
|
||||
rule.is_enabled()
|
||||
&& self.config.diagnostics.category_enabled(rule.category())
|
||||
&& rule.applies(context)
|
||||
})
|
||||
.flat_map(|rule| rule.findings(&self.config, source))
|
||||
.collect::<Vec<_>>();
|
||||
normalize_findings(&mut findings);
|
||||
|
|
@ -555,6 +559,50 @@ mod tests {
|
|||
assert_eq!(analysis.evidence_band, Some(EvidenceBand::BelowThreshold));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn category_and_individual_switches_are_both_required() {
|
||||
let source = "In conclusion, it is complete.";
|
||||
let mut config = Config::embedded();
|
||||
config.diagnostics.categories.style = false;
|
||||
assert!(
|
||||
Detector::new(&config)
|
||||
.unwrap()
|
||||
.analyze(source)
|
||||
.findings
|
||||
.is_empty()
|
||||
);
|
||||
|
||||
config.diagnostics.categories.style = true;
|
||||
config
|
||||
.rules
|
||||
.iter_mut()
|
||||
.find(|rule| rule.id == "templated-conclusion")
|
||||
.unwrap()
|
||||
.enabled = false;
|
||||
assert!(
|
||||
Detector::new(&config)
|
||||
.unwrap()
|
||||
.analyze(source)
|
||||
.findings
|
||||
.is_empty()
|
||||
);
|
||||
|
||||
config
|
||||
.rules
|
||||
.iter_mut()
|
||||
.find(|rule| rule.id == "templated-conclusion")
|
||||
.unwrap()
|
||||
.enabled = true;
|
||||
assert_eq!(
|
||||
Detector::new(&config)
|
||||
.unwrap()
|
||||
.analyze(source)
|
||||
.findings
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unicode_review_findings_have_exact_spans_and_safe_fixes() {
|
||||
let detector = Detector::new(&Config::embedded()).unwrap();
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@ mod unicode_review;
|
|||
pub use config::{
|
||||
Config, ConfigError, ConfigLayerError, ConfigLoader, ConfigName, ConfigNameError,
|
||||
ConfigOverrides, ConfigPaths, ConfigValidationError, ConfusablePolicy, ContentKind,
|
||||
EvidenceThresholds, HeuristicRule, InputLimits, InputOverrides, MatcherType, ReplacementRule,
|
||||
RuleScope, ThresholdOverrides, UnicodePolicy,
|
||||
DiagnosticCategories, DiagnosticPolicy, EvidenceThresholds, HeuristicRule, InputLimits,
|
||||
InputOverrides, MatcherType, ReplacementRule, RuleScope, ThresholdOverrides, UnicodePolicy,
|
||||
default_config_template,
|
||||
};
|
||||
pub use detector::{AnalysisContext, Detector, DetectorBuildError, Rule};
|
||||
pub use diagnostic::FindingDiagnostic;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,20 @@ Named configurations accept only ASCII letters, digits, `_`, and `-`. Do not
|
|||
include a directory, dot component, or `.toml` extension. Missing user and named
|
||||
files are optional; a selected explicit file must exist.
|
||||
|
||||
## Generate a project configuration
|
||||
|
||||
Create the embedded, commented base configuration as `./config.toml`:
|
||||
|
||||
```sh
|
||||
john-slop config init
|
||||
```
|
||||
|
||||
The command refuses to overwrite an existing file. Use
|
||||
`john-slop config init --force` only when replacing that file is intentional.
|
||||
`config generate` is an alias for `config init`. Load a project-local file with
|
||||
`john-slop --config config.toml path/to/input` or inspect it with the command
|
||||
shown below.
|
||||
|
||||
## Schema
|
||||
|
||||
The current `schema_version` is `1`. The complete defaults live in
|
||||
|
|
@ -41,15 +55,27 @@ Replacement and heuristic arrays merge by stable `id`. A partial record changes
|
|||
only the supplied fields:
|
||||
|
||||
```toml
|
||||
[diagnostics.categories]
|
||||
# Disable every style diagnostic as one family.
|
||||
style = false
|
||||
|
||||
[[replacements]]
|
||||
id = "em-dash"
|
||||
enabled = false
|
||||
|
||||
[[rules]]
|
||||
id = "templated-conclusion"
|
||||
weight = 2.5
|
||||
# An individual rule switch is independent of the category switch.
|
||||
enabled = false
|
||||
```
|
||||
|
||||
The category keys are `typography`, `style`, `prompt-leakage`, and
|
||||
`source-code`. A diagnostic runs only when its category switch and its
|
||||
individual `[[rules]]` `enabled` field are both `true`. Consequently, enabling
|
||||
a category does not silently re-enable a rule that another layer disabled
|
||||
individually; set that rule's `enabled = true` explicitly when that is intended.
|
||||
Later files override earlier category values using the normal precedence above.
|
||||
|
||||
A new ID must provide every field. Scope arrays replace the prior array as a
|
||||
whole. A rule scope can select `prose` or `source-code`, restrict lowercase
|
||||
extensions, and use `include`/`exclude` path globs. The `skip_generated`,
|
||||
|
|
|
|||
|
|
@ -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.05%
|
||||
(1,487/1,598 lines) on 2026-09-30. The remaining lines are dominated by
|
||||
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
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ categories. The Milestone 22 review makes printable-ASCII UTS #39 mappings
|
|||
replaceable by default, retains a non-mutating `review` policy, and keeps the
|
||||
Gitea-compatible invisible/control profile diagnostic-only, with explicit
|
||||
multilingual limitations. The checked-in `signoff.toml` records those decisions
|
||||
and contains the SHA-256 digest of both `heuristics.toml` and `unicode.toml`.
|
||||
and contains the SHA-256 digest of `config.toml`, `heuristics.toml`, and
|
||||
`unicode.toml`. This binds the reviewed scoring behavior to both rule catalogs
|
||||
and the default category policy.
|
||||
|
||||
Any default rule, matcher, pattern, weight, occurrence cap, scope, or threshold
|
||||
change invalidates the sign-off test. Renewal requires reviewing positive and
|
||||
|
|
|
|||
|
|
@ -13,3 +13,10 @@ john-slop config show --config-name editorial
|
|||
```
|
||||
|
||||
Project-local policy can use either file with `--config path/to/file.toml`.
|
||||
The CLI can also create the embedded commented base in the current directory:
|
||||
|
||||
```sh
|
||||
john-slop config init
|
||||
```
|
||||
|
||||
It preserves an existing `config.toml` unless `--force` is explicit.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
# it out makes compatibility expectations explicit.
|
||||
schema_version = 1
|
||||
|
||||
[diagnostics.categories]
|
||||
# Category gates can silence a complete diagnostic family. All four categories
|
||||
# (`typography`, `style`, `prompt-leakage`, and `source-code`) default to true.
|
||||
style = true
|
||||
prompt-leakage = true
|
||||
|
||||
[input]
|
||||
# Bound each decoded document to 4 MiB for this installation.
|
||||
max_document_bytes = 4194304
|
||||
|
|
@ -20,7 +26,7 @@ enabled = false
|
|||
|
||||
[[rules]]
|
||||
id = "templated-conclusion"
|
||||
# Disable a rule that is unsuitable for the user's normal documents.
|
||||
# Disable one rule even while its `style` category remains enabled.
|
||||
enabled = false
|
||||
|
||||
[[rules]]
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "john-slop-core"
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
dependencies = [
|
||||
"directories",
|
||||
"figment",
|
||||
|
|
@ -411,7 +411,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "john-slop-lsp"
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
dependencies = [
|
||||
"john-slop-core",
|
||||
"serde_json",
|
||||
|
|
@ -422,7 +422,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "john_slop"
|
||||
version = "0.1.22"
|
||||
version = "0.1.23"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"globset",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
mod output;
|
||||
|
||||
use std::{
|
||||
fs::OpenOptions,
|
||||
io::Write,
|
||||
path::{Path, PathBuf},
|
||||
process::ExitCode,
|
||||
};
|
||||
|
|
@ -12,7 +14,7 @@ use clap::{Parser, Subcommand, ValueEnum};
|
|||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
use john_slop::{
|
||||
AnalysisContext, Config, ConfigLoader, ConfigName, ConfigOverrides, Detector, InputOverrides,
|
||||
SourceId, read_inputs, read_stdin,
|
||||
SourceId, default_config_template, read_inputs, read_stdin,
|
||||
};
|
||||
use miette::{IntoDiagnostic, Result, WrapErr};
|
||||
|
||||
|
|
@ -120,6 +122,13 @@ enum Command {
|
|||
/// Configuration inspection operations.
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum ConfigCommand {
|
||||
/// Generate a commented config.toml in the current directory.
|
||||
#[command(visible_alias = "generate")]
|
||||
Init {
|
||||
/// Replace an existing config.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.
|
||||
|
|
@ -170,6 +179,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::Show => {
|
||||
let config = loader.load()?;
|
||||
print!("{}", toml::to_string_pretty(&config).into_diagnostic()?);
|
||||
|
|
@ -250,6 +260,29 @@ fn run(cli: &Cli) -> Result<RunOutcome> {
|
|||
Ok(outcome)
|
||||
}
|
||||
|
||||
fn write_default_config(force: bool) -> Result<()> {
|
||||
let path = Path::new("config.toml");
|
||||
let mut options = OpenOptions::new();
|
||||
options.write(true).create(true);
|
||||
if force {
|
||||
options.truncate(true);
|
||||
} else {
|
||||
options.create_new(true);
|
||||
}
|
||||
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()
|
||||
} else {
|
||||
"failed to create ./config.toml".to_owned()
|
||||
}
|
||||
})?;
|
||||
file.write_all(default_config_template().as_bytes())
|
||||
.into_diagnostic()
|
||||
.wrap_err("failed to write ./config.toml")?;
|
||||
println!("wrote ./config.toml");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn emit_input_error(format: OutputFormat, source: &str, message: &str) -> Result<()> {
|
||||
let rendered = render_input_error(format, source, message).into_diagnostic()?;
|
||||
if format == OutputFormat::Json {
|
||||
|
|
@ -378,6 +411,25 @@ mod tests {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_config_init_and_force_without_detector_paths() {
|
||||
let init = Cli::try_parse_from(["john-slop", "config", "init"]).unwrap();
|
||||
assert!(matches!(
|
||||
init.command,
|
||||
Some(Command::Config {
|
||||
command: ConfigCommand::Init { force: false }
|
||||
})
|
||||
));
|
||||
|
||||
let forced = Cli::try_parse_from(["john-slop", "config", "generate", "--force"]).unwrap();
|
||||
assert!(matches!(
|
||||
forced.command,
|
||||
Some(Command::Config {
|
||||
command: ConfigCommand::Init { force: true }
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_stdin_filename_ignore_and_resource_limits() {
|
||||
let cli = Cli::try_parse_from([
|
||||
|
|
|
|||
27
tasks.md
27
tasks.md
|
|
@ -579,6 +579,33 @@ covered across both feature matrices. Formatting, Clippy, rustdoc, evaluation,
|
|||
dependency policy/audit checks, and workspace package assembly pass; coverage
|
||||
is 93.05% (1,487/1,598 lines), and release metadata agrees on `0.1.22`.
|
||||
|
||||
## Milestone 23 — Diagnostic policy and local configuration bootstrap
|
||||
|
||||
- [x] Add typed category gates to the existing layered TOML schema while
|
||||
retaining `[[rules]] enabled = true|false` for individual diagnostics. A rule
|
||||
runs only when both its category and individual switches are enabled; test
|
||||
user, named, and explicit-layer precedence plus unknown configuration keys.
|
||||
- [x] Add `john-slop config init` to write the embedded, commented default
|
||||
configuration to `./config.toml`. Refuse to replace an existing file by
|
||||
default, support an explicit `--force`, and test the generated file by loading
|
||||
it through the public configuration path.
|
||||
- [x] Update the quickstart, configuration examples, CLI help, changelog,
|
||||
release metadata, badges, and ignored recap; run both feature matrices,
|
||||
formatting, Clippy, rustdoc, package/audit checks, and Tarpaulin.
|
||||
|
||||
Acceptance: category and individual diagnostic switches work identically in the
|
||||
CLI and LSP because they resolve in the shared core configuration; a fresh
|
||||
`john-slop config init` creates a valid documented `config.toml` in the current
|
||||
directory without silently destroying user data; all release artifacts agree
|
||||
on `0.1.23` before the immutable `v0.1.23` tag is created.
|
||||
|
||||
Accepted on 2026-09-30 after layered category and individual switches produced
|
||||
matching CLI/LSP behavior, and config generation passed create, preserve,
|
||||
force-overwrite, parse, and reload checks. Formatting, Clippy, rustdoc, both
|
||||
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`.
|
||||
|
||||
## Deferred by design
|
||||
|
||||
- Statistical or model-based authorship classification.
|
||||
|
|
|
|||
126
tests/cli.rs
126
tests/cli.rs
|
|
@ -47,6 +47,20 @@ fn help_is_successful_and_names_the_command() {
|
|||
insta::assert_snapshot!(String::from_utf8(output.stdout).expect("UTF-8 stdout"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_help_lists_generation_and_inspection_commands() {
|
||||
let output = detector()
|
||||
.args(["config", "--help"])
|
||||
.output()
|
||||
.expect("run config help");
|
||||
let stdout = String::from_utf8(output.stdout).expect("UTF-8 stdout");
|
||||
|
||||
assert!(output.status.success());
|
||||
assert!(stdout.contains("init"));
|
||||
assert!(stdout.contains("show"));
|
||||
assert!(stdout.contains("paths"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_evidence_score_is_a_usage_error() {
|
||||
let output = detector()
|
||||
|
|
@ -124,6 +138,118 @@ fn config_show_emits_resolved_toml_with_explicit_overrides() {
|
|||
assert_eq!(resolved["replacements"].as_array().unwrap().len(), 1_829);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_init_writes_valid_defaults_and_requires_force_to_overwrite() {
|
||||
let directory = tempdir().expect("temp dir");
|
||||
let config = directory.path().join("config.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"])
|
||||
.output()
|
||||
.expect("generate default config");
|
||||
assert!(created.status.success());
|
||||
assert_eq!(created.stdout, b"wrote ./config.toml\n");
|
||||
let generated = fs::read_to_string(&config).expect("read generated config");
|
||||
let parsed = toml::from_str::<toml::Value>(&generated).expect("valid generated TOML");
|
||||
assert_eq!(parsed["schema_version"].as_integer(), Some(1));
|
||||
assert_eq!(
|
||||
parsed["diagnostics"]["categories"]["prompt-leakage"].as_bool(),
|
||||
Some(true)
|
||||
);
|
||||
|
||||
let loaded = detector()
|
||||
.current_dir(directory.path())
|
||||
.env("XDG_CONFIG_HOME", &config_home)
|
||||
.args(["config", "show", "--config", "config.toml"])
|
||||
.output()
|
||||
.expect("load generated config");
|
||||
assert!(
|
||||
loaded.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&loaded.stderr)
|
||||
);
|
||||
|
||||
let refused = detector()
|
||||
.current_dir(directory.path())
|
||||
.env("XDG_CONFIG_HOME", &config_home)
|
||||
.args(["config", "init"])
|
||||
.output()
|
||||
.expect("refuse overwrite");
|
||||
assert_eq!(refused.status.code(), Some(2));
|
||||
assert!(String::from_utf8_lossy(&refused.stderr).contains("refusing to overwrite"));
|
||||
assert_eq!(fs::read_to_string(&config).unwrap(), generated);
|
||||
|
||||
fs::write(&config, "not valid TOML").unwrap();
|
||||
let forced = detector()
|
||||
.current_dir(directory.path())
|
||||
.env("XDG_CONFIG_HOME", &config_home)
|
||||
.args(["config", "generate", "--force"])
|
||||
.output()
|
||||
.expect("force overwrite");
|
||||
assert!(forced.status.success());
|
||||
assert_eq!(fs::read_to_string(&config).unwrap(), generated);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn category_and_individual_configuration_disable_cli_diagnostics() {
|
||||
let directory = tempdir().expect("temp dir");
|
||||
let source = directory.path().join("article.md");
|
||||
fs::write(&source, "As an AI language model, I can help.\n").unwrap();
|
||||
|
||||
let category_config = directory.path().join("category.toml");
|
||||
fs::write(
|
||||
&category_config,
|
||||
"[diagnostics.categories]\nprompt-leakage = false\n",
|
||||
)
|
||||
.unwrap();
|
||||
let category = detector()
|
||||
.env(
|
||||
"XDG_CONFIG_HOME",
|
||||
directory.path().join("empty-config-home"),
|
||||
)
|
||||
.args(["--output", "json"])
|
||||
.arg("--config")
|
||||
.arg(&category_config)
|
||||
.arg(&source)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(category.status.success());
|
||||
assert!(
|
||||
json_records(&category)[0]["findings"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
|
||||
let rule_config = directory.path().join("rule.toml");
|
||||
fs::write(
|
||||
&rule_config,
|
||||
"[[rules]]\nid = \"assistant-self-identification\"\nenabled = false\n",
|
||||
)
|
||||
.unwrap();
|
||||
let individual = detector()
|
||||
.env(
|
||||
"XDG_CONFIG_HOME",
|
||||
directory.path().join("empty-config-home"),
|
||||
)
|
||||
.args(["--output", "json"])
|
||||
.arg("--config")
|
||||
.arg(&rule_config)
|
||||
.arg(&source)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(individual.status.success());
|
||||
assert!(
|
||||
json_records(&individual)[0]["findings"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_paths_lists_embedded_and_platform_sources() {
|
||||
let directory = tempdir().expect("temp dir");
|
||||
|
|
|
|||
|
|
@ -127,6 +127,10 @@ fn reviewed_corpus_reports_per_rule_metrics_and_false_positive_rate() {
|
|||
)
|
||||
.expect("parse evaluation sign-off");
|
||||
let mut catalog = Sha256::new();
|
||||
catalog.update(include_bytes!(
|
||||
"../crates/john-slop-core/assets/config.toml"
|
||||
));
|
||||
catalog.update([0]);
|
||||
catalog.update(include_bytes!(
|
||||
"../crates/john-slop-core/assets/heuristics.toml"
|
||||
));
|
||||
|
|
@ -141,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-unicode-replacement-profile");
|
||||
assert_eq!(signoff.status, "accepted-after-diagnostic-policy");
|
||||
assert_eq!(signoff.catalog_sha256, catalog_hash);
|
||||
assert!(signoff.limitations_acknowledged);
|
||||
assert_eq!(signoff.reviewed_on, "2026-09-30");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
schema_version = 1
|
||||
release = "0.1.22"
|
||||
release = "0.1.23"
|
||||
reviewed_on = "2026-09-30"
|
||||
status = "accepted-after-unicode-replacement-profile"
|
||||
catalog_sha256 = "74be9257120a8830f546b3b6e87c1a73b4c55041cf1022c1fe568eb84ef30117"
|
||||
status = "accepted-after-diagnostic-policy"
|
||||
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. 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. 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."
|
||||
|
|
|
|||
22
tests/lsp.rs
22
tests/lsp.rs
|
|
@ -542,6 +542,28 @@ enabled = true
|
|||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn disabled_category_suppresses_lsp_diagnostics() {
|
||||
let mut harness =
|
||||
Harness::new(Some("[diagnostics.categories]\nprompt-leakage = false\n")).await;
|
||||
harness
|
||||
.notify(
|
||||
"textDocument/didOpen",
|
||||
open_params(
|
||||
"file:///tmp/category.md",
|
||||
1,
|
||||
"As an AI language model, I can help.",
|
||||
),
|
||||
)
|
||||
.await;
|
||||
|
||||
let published = harness
|
||||
.notification("textDocument/publishDiagnostics")
|
||||
.await;
|
||||
|
||||
assert!(published["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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue