Semantic Duplication Scan
Overview
Detect business logic that has been reimplemented multiple times across different architectural layers. Unlike linters (which detect syntactic similarity) or domain-review (which catches single-instance layer violations), this skill detects semantic equivalence — the same domain calculation independently appearing in domain services, client adapters, and presentation components with different variable names and structure.
Annotation Prompt Version
promptVersion: 1.0
When this version changes, any register entry with a different promptVersion is treated as stale and re-annotated on the next scan pass that touches that file.
Pre-Filter Rules
Apply before any LLM call. No model invocation at this stage.
Trivial Function Definition
A function is trivial — and must be excluded from the register — if it meets ALL of the following:
- Contains no arithmetic operators:
+,-,*,/,%,** - Contains no boolean logic operators:
&&,||,!,not,and,or - Contains no branching constructs:
if,else,switch,case,ternary(?:),match - Contains no assignments to variables outside its own scope (no external state mutation)
- Contains no calls to higher-order collection operations:
map,filter,reduce,flatMap,forEach,find,some,every, or language equivalents
Trivial patterns (always excluded):
- Getters: read and return a field with no transformation
- Pass-through delegators: call one function with the same arguments, return the result unchanged
- Identity functions: return the input unchanged
- Constructors / initializers that only assign parameters to instance fields
If a file contains only trivial functions, output:
No computation units found to analyze
and do not create or modify the register.
File Exclusion Patterns
Exclude the following from annotation regardless of content:
*.test.*
*.spec.*
__tests__/
*.test-d.*
*.generated.*
*.pb.*
*.d.ts
dist/
build/
.next/
coverage/
Also exclude any path matching a pattern listed in .semanticscanignore (one glob per line) if that file exists in the project root.
Process Flow
Step 1 — Mode Detection
Check for computation-register.json in the project root:
- Absent → full-scan mode
- Present → incremental mode
Step 2 — Pre-Flight (Incremental Mode Only)
Run: git rev-parse --is-shallow-repository
If output is true:
- Output the exact string:
Shallow clone detected — semantic-scan requires full history for incremental mode. Run with --full to override. - Exit non-zero
If --full flag was passed: skip this check and force full-scan mode.
If lastScanCommit in the register is not found in git history:
- Output:
lastScanCommit not found in history — running full scan - Switch to full-scan mode
Step 3 — Scope Resolution
- If a path argument was provided (e.g.,
/semantic-scan src/pricing), use it as a prefix filter: only consider files whose paths start with the argument - Apply
.semanticscanignorepatterns: exclude any file matching a listed glob - Apply file exclusion patterns from the Pre-Filter Rules above
Step 4 — File Selection
Full-scan mode: Glob all source files in the resolved scope.
Incremental mode: Run git diff <lastScanCommit> HEAD --name-only, then filter to files in the resolved scope.
If the git diff result is empty (no files changed since lastScanCommit):
- Update
lastScanCommitto HEAD in the register and write the updated register - Output:
No changes since last scan — register up to date - Exit 0 — do not proceed to annotation or clustering
Graph-assisted file/function discovery. Prefer CodeGraph/Repowise over raw
Glob/Read for locating candidate computation functions across layers —
Repowise's semantic search (search_codebase) is particularly well suited
here, since it's built for exactly the kind of similarity search this skill
needs to find the same domain concept reimplemented in different layers. See