Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/nornir

.nornir/mimir-analyze-duplicates.md

Mimir analyze duplicates — copied-not-moved detection

Class: design · A warehouse-native code analysis that finds the same code living in two places, so the move-means-delete + REUSE laws can be enforced by a query instead of by hand. This is the capability that would have found the release/brokkr duplication the extermination wave cleaned manually.

What it does

nornir mimir analyze duplicates clusters symbols that are the same code copied into more than one crate/repo, and prints a keep/kill recommendation per cluster as JSON (the CLI twin of the Knowledge/Mimir state_json).

A vector index alone is noisy — a trait impl and its default method embed alike — so the detector keeps a pair only when both signals agree:

Cross-scope survivors (different crates) are unioned into clusters, ranked by avg_cosine × size, and each cluster gets a canonical keep (preferring a shared reuse home — edda, skidbladnir, znippy-zoomies, facett, plus any --canonical <crate>) with the rest marked repoint (a home exists) or kill (no home).

Shape (two layers)

  1. Pure core — src/mimir_analyze.rs. Takes materialised SymbolVec rows (embedding + structural fingerprint) → DuplicateReport. No warehouse/GPU dependency, exhaustively unit-tested (cosine, structural gate, union-find clustering, ranking, canonical pick, state_json).

    • assemble_symbol_vecs(repo, symbols, calls, chunks, vectors) is the PURE join that turns raw warehouse rows into SymbolVecs: a symbol inherits the vector of the smallest embedding_manifest chunk that covers its file:line; its callees come from call_edges grouped by (file, caller last segment); a symbol with no covering chunk is dropped.
  2. Warehouse read — src/mimir_dup.rs (analyze_warehouse_duplicates). The thin wiring: per repo, load the latest-snapshot symbols + call-edges via the tested knowledge::query::load_preferred; read every embedding_manifest span + its embeddings vector; assemble_symbol_vecs each repo; run the core over all repos at once. Defensive — an empty/embedding-less warehouse yields an empty (green) report, never an error.

Join keys

symbol_facts(repo, crate, module, item_name, file, line, signature)
   ⋈ (file, line ∈ [start,end])  embedding_manifest(content_hash, file, start_line, end_line)
   ⋈ content_hash                embeddings(content_hash, vector: list<f32>)
   ⋈ (file, last_seg(caller_path)==item_name)  call_edges(caller_path, callee_ident)

CLI

nornir mimir analyze duplicates \
    [--cosine 0.92] [--structural 0.5] [--all-scopes] [--canonical <crate> ...]

Tests

Remaining

The pure core + join + CLI are wired and unit-tested; an end-to-end run against a freshly nornir populated + embedded warehouse (real clusters surfacing) is the live-drive follow-up, plus a facett cluster-list view over DuplicateReport.