Skip to main content

Module code_health

Module code_health 

Source
Expand description

Native code-health engine — clean code as a token-cost lever.

Computes the structural signals the Sonar study links to agent token cost — cognitive complexity (S3776-style), naming quality, and module coupling — once during indexing, then fans them out across the data fabric and every agent surface (see the Code Health Engine plan).

Naming note: this is distinct from crate::core::quality (compression fidelity) and from crate::core::gain’s usage-quality component; this module scores the source code’s navigability.

Re-exports§

pub use annotate::ReadAnnotation;
pub use annotate::annotations_for_file;
pub use cognitive::FunctionCognitive;
pub use cognitive::cognitive_per_function;
pub use coupling::ModuleCoupling;
pub use coupling::module_coupling;
pub use delta::CognitiveDelta;
pub use delta::cognitive_delta;
pub use delta::format_gate_notice;
pub use delta::worst_regression;
pub use naming::NamingFinding;
pub use naming::cryptic_reason;
pub use naming::naming_findings;
pub use scan::FileReport;
pub use scan::ProjectHealth;
pub use scan::scan_project;
pub use score::Hotspot;
pub use score::NavigabilityInputs;
pub use score::NavigabilityScore;
pub use score::grade;
pub use score::navigability;

Modules§

annotate
Read-time code-health annotations.
cognitive
Cognitive complexity (SonarQube S3776-style) via tree-sitter.
coupling
Module coupling metrics — Robert C. Martin’s afferent/efferent coupling and instability.
delta
Edit-time cognitive-complexity delta.
fabric
Code-health interconnection fabric (Phase 3 / #1083).
gate
Edit-time code-health gate — shared by ctx_edit, ctx_patch, and the native-edit hook.
naming
Naming-quality heuristic.
persist
Persisted project health (health.json) + stale-guarded background refresh.
report
Shared rendering of a ProjectHealth report (text + JSON).
scan
Project-wide code-health scan — the shared report behind lean-ctx health, the ctx_quality tool, and the dashboard.
score
Project navigability score (0–100) and its estimated token-cost (“quality tax”).

Structs§

FileHealth
Combined per-file health: cognitive scores plus naming findings. This is the single entry point used by the edit-gate, read annotations, and the ctx_quality tool.

Enums§

GateMode
Edit-gate behavior when an edit increases cognitive complexity.

Constants§

DEFAULT_COGNITIVE_THRESHOLD
Default cognitive-complexity threshold (SonarQube S3776 “HIGH” default). A function at or below this is considered navigable. Mirrored by CodeHealthConfig::default().cognitive_threshold.

Functions§

analyze_file
Analyze one file’s source for the given file extension.