Skip to content

feat(metrics): add Clone-family clustering and opt-in near-clone detection - #204

Merged
avidianity merged 8 commits into
mainfrom
feat/174-near-clones-families
Nov 23, 2026
Merged

avidianity merged 8 commits into
mainfrom
feat/174-near-clones-families

Conversation

@avidianity

@avidianity avidianity commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds Clone-family clustering (grouping 3+ overlapping or transitively related exact or near-clone fragments into worst-first Clone families across TOON, JSON, SARIF, Markdown, and MCP without double-counting) and opt-in bounded shingle/MinHash/LSH near-clone detection (duplication.near_clones, duplication.min_similarity) with codeint diff Regression gating while keeping exact Clone groups as the default.

Closes #174
Closes #196
Closes #197

Tier

Tier 3 from the tier check: crates/cli/tests/check.rs updates the unknown-key error assertion to include the new duplication key in codeint.json.

Task

Spec #174 and sub-issues #196, #197:

Fail-first test

  • Test: crates/metrics/src/duplication.rs (three_copies_across_files_form_one_clone_family_in_canonical_order, near_clones_enabled_catches_one_line_edit_with_similarity_and_keeps_exact_lines_separate) and crates/cli/tests/diff.rs (diff_gates_new_near_clones_and_classifies_unchanged_near_clones_by_stable_id)
  • Before the change: failed to compile / failed with exit code 0 instead of 1 on near-clone regression before implementation
  • After the change: passed (all workspace unit, integration, reference, and doc tests green)

Checks

Check Result
cargo test --workspace --locked passed
cargo clippy --workspace --all-targets -- -D warnings passed
cargo fmt --check passed
codeint diff 0e8977e passed (0 regressions)
lefthook pre-commit and commit-msg passed
Merged-result check (cargo run --package xtask -- merged-result) passed

Safety proof

  • Safety fact: Near-clone detection is disabled by default (duplication.near_clones: false), exact Clone group ratios and Verbosity remain strictly unchanged, and clone_families is omitted from JSON/TOON when empty.
  • Proof: crates/metrics/src/duplication.rs (near_clones_off_by_default_leaves_edited_copy_undetected), crates/cli/tests/check.rs (143/143), crates/cli/tests/diff.rs, and crates/cli/tests/mcp.rs all pass with zero regressions on codeint diff 0e8977e.
  • interrogate: Round 1 Independent Review + adversarial interrogate caught 7 verified issues, all fixed with regression tests in 7d5e5bb and merged with main (0e8977e) at 3514efb. Round 2 clean rerun verified all 7 fixes and caught 1 saved-report parity edge case (codeint report --format sarif leaking raw member CloneGroups for truncated families ranked past top 20), fixed in 8dfebcf via optional unlisted_clone_family_group_ids. Round 3 clean rerun on 8dfebcf passed with Verdict: PASS (0 open verified findings).

Runtime evidence

End-to-end CLI and MCP integration tests executed the compiled codeint binary on revision 8dfebcf across multi-file TypeScript/Rust fixtures and temporary Git repositories (check, diff, mcp, reference test suites all passed, and codeint diff 0e8977e exited 0 with zero regressions).

Gaps

  • Deferred coverage: none
  • Pre-existing failures: none
  • Environmental failures: none

Cluster overlapping and transitively related exact Clone group fragments across three or more locations into unified Clone families using connected components (union-find) in crates/metrics, ordered worst-first by unique duplicated lines without double-counting and with deterministic canonical location ordering and stable FindingIds. Expose Clone families across TOON, JSON, SARIF, Markdown, diff, and codeint mcp while preserving existing Duplication and Verbosity ratios and Reference ranges identically.

Closes #196
… gating

Add opt-in shingle/Jaccard near-clone detection configured via duplication.near_clones (default false) and duplication.min_similarity (default 0.85, validated in (0, 1]) in codeint.json and schema/codeint.schema.json. Use deterministic MinHash/LSH candidate pruning over normalized tokens with import-or-export exclusions and minimum token/distinct-token guards, report similarity ratios and percentages across JSON, TOON, SARIF, Markdown, diff, and codeint mcp, cluster overlapping exact and near-clone fragments into Clone families with stable FindingIds, gate new near-clone Regressions in codeint diff, and keep Verbosity coupled only to exact Clone groups.

Closes #197
@github-actions github-actions Bot added the tier-3 Tier 3 from the tier check label Nov 23, 2026
@avidianity
avidianity merged commit f5f6570 into main Nov 23, 2026
14 checks passed
@avidianity
avidianity deleted the feat/174-near-clones-families branch November 23, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tier-3 Tier 3 from the tier check

Projects

None yet

1 participant