Skip to main content

Module score

Module score 

Source
Expand description

ctx score engine: a quality scorecard for the changes between a git reference and the current working tree.

The pipeline is:

  1. Refresh the index incrementally (never a full reindex).
  2. Collect the changed-file set relative to the reference.
  3. For every changed file, compute the same metrics on two sides:
    • current: from the index, restricted to the file (per-file queries only – no global scans).
    • baseline: by parsing the file’s content at the reference in memory (no database writes).
  4. Diff the two sides into deltas, detect newly introduced duplication, and run the architecture-rules check.

§Approximation

Per-function complexity is 2 * fan_out + same_file_fan_in. The baseline side is parsed in isolation, so cross-file callers are unknowable there; fan-in is therefore approximated as same-file callers on both sides so the delta compares like with like. This is surfaced as a note in both human and JSON output.

Structs§

FailCondition
One parsed --fail-on condition (metric OP value).
FileScore
Per-changed-file breakdown (both sides of the delta metrics).
Metrics
The flat metric set of a score run. Field names are the exact metric names accepted by --fail-on and emitted under data.metrics in JSON.
ScoreReport
The complete result of a score run.

Enums§

Op
Comparison operator in a --fail-on condition.

Constants§

DUP_MIN_TOKENS
Minimum normalized token count for the new_duplication metric.
DUP_THRESHOLD
Jaccard threshold used for the new_duplication metric.
FAN_IN_NOTE
Note attached whenever complexity deltas are reported.
NO_RULES_NOTE
Note attached when .ctx/rules.toml does not exist.

Functions§

compute_score
Compute the score of the working tree (plus commits since the merge base) against reference.
failed_conditions
The subset of conditions satisfied by metrics (each one fails the gate).
parse_fail_on
Parse a comma-separated --fail-on expression like "new_duplication>0, complexity_delta >= 10".