/dev-team:semantic-duplication-scanfrom dev-team
Detects business logic reimplemented across architectural layers by annotating computation functions and clustering semantically equivalent entries. Catches duplication that linters miss.
Ships in dev-team. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
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.
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.
Apply before any LLM call. No model invocation at this stage.
A function is trivial — and must be excluded from the register — if it meets ALL of the following:
+, -, *, /, %, **&&, ||, !, not, and, orif, else, switch, case, ternary (?:), matchmap, filter, reduce, flatMap, forEach, find, some, every, or language equivalentsTrivial patterns (always excluded):
If a file contains only trivial functions, output:
No computation units found to analyze
and do not create or modify the register.
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.
Check for computation-register.json in the project root:
Run: git rev-parse --is-shallow-repository
If output is true:
Shallow clone detected — semantic-scan requires full history for incremental mode. Run with --full to override.If --full flag was passed: skip this check and force full-scan mode.
If lastScanCommit in the register is not found in git history:
lastScanCommit not found in history — running full scan/semantic-scan src/pricing), use it as a prefix filter: only consider files whose paths start with the argument.semanticscanignore patterns: exclude any file matching a listed globFull-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):
lastScanCommit to HEAD in the register and write the updated registerNo changes since last scan — register up to dateGraph-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
knowledge/codegraph-vs-graphify.md
for tool selection and the fallback contract.
For each selected file, identify non-trivial computation functions using the Trivial Function Definition above. Apply without an LLM call — use structural heuristics (presence of operators, branches, higher-order calls).
If no non-trivial functions remain after filtering:
No computation units found to analyze → exit 0, no register createdNo new computation units found in changed files — register unchanged → exit 0, register not modifiedFor each file with non-trivial functions:
Annotating [N/total] <filename>{file, error} in scanErrors and continue — do not abortAnnotation prompt (pinned — do not paraphrase):
You are a semantic annotation assistant. For each function below, produce a JSON object describing what it computes in pure domain business terms.
Use this schema:
{
"function": "<function name>",
"layer": "<inferred layer — see rules below>",
"semanticDescription": {
"verb": "<lowercase infinitive verb>",
"domainConcept": "<lowercase, no articles, normalized>",
"inputs": ["<domain term>", ...],
"outputConcept": "<domain term>"
}
}
Layer inference rules — infer from what the function imports and uses:
- "infrastructure": imports DB clients, ORMs, HTTP clients, message brokers (pg, redis, axios, fetch, prisma, mongoose, etc.)
- "presentation": imports rendering primitives, formats for display, accesses DOM or templates (React, Vue, Svelte, JSX, HTML templates, etc.)
- "domain": depends only on domain types and pure functions, no external imports
- "application": orchestrates domain and infrastructure without owning business rules
- "unknown": cannot be determined from available context
domainConcept rules:
- Use lowercase
- Remove articles: a, an, the
- Normalize the verb to infinitive form
- Example: "calculates the discounted price" → domainConcept: "discounted price", verb: "calculate"
Describe only what the function computes in domain terms. Do not reference the implementation language, variable names, or data structure types.
Functions:
<paste function source here>
Canonicalize domainConcept after receiving the response:
a , an , the verb field to infinitive (e.g., "calculates" → "calculate", "computing" → "compute")Build a register entry for each annotated function:
{
"file": "<relative path from project root>",
"function": "<function name>",
"layer": "<inferred layer>",
"semanticDescription": {
"verb": "<canonicalized>",
"domainConcept": "<canonicalized>",
"inputs": ["<domain term>", ...],
"outputConcept": "<domain term>"
},
"promptVersion": "1.0",
"commitHash": "<HEAD commit hash>",
"line": <first line of function definition>
}
Merge strategy:
file matches a re-annotated filefile no longer exists on disk.semanticscanignore patternsIdempotency: Sort the full entry list by file ascending, then function ascending before writing.
Write the register. If the write fails (permissions, disk full):
Update lastScanCommit to the current HEAD commit hash after successful write.
Report partial failures. After writing (only if scanErrors is non-empty):
Warning: 1 file could not be annotated. Re-run /semantic-scan to retry.Warning: N files could not be annotated. Re-run /semantic-scan to retry.Exit code 0 — partial success is not a failure.
The full register may be too large to cluster in a single call. Use layer-pair sharding:
Shard the register by layer pair before sending to Sonnet:
domain × presentationdomain × infrastructureapplication × presentationapplication × infrastructuredomain × applicationFor each shard: if the shard exceeds 50,000 tokens, further shard by the first normalized token of domainConcept (split alphabetically into sub-groups).
After per-shard clustering, run a cross-shard reconciliation pass: send only the cluster representatives (one entry per cluster, the top-ranked candidate) back to Sonnet to catch equivalents that landed in different shards. Keep this merge input under 50,000 tokens.
For each shard, emit progress: Clustering [layer-pair]: <layer-a> × <layer-b>...
Clustering prompt (pinned — do not paraphrase):
Group these register entries by semantic equivalence — entries that compute the same domain concept regardless of implementation differences. Return clusters as JSON arrays of entry IDs (use "file:function" as the ID).
Two entries belong in the same cluster ONLY IF both would need to change if the underlying business rule changed.
Input entries:
<paste shard entries as JSON array>
Return only:
{ "clusters": [["file1:funcA", "file2:funcB"], ...] }
Entries that are semantically unique should not appear in any cluster.
For each cluster with 2 or more entries:
Layer rank (higher = more canonical):
domainapplicationpresentationinfrastructureunknownWithin the same layer rank: count infrastructure imports in the function's file; fewer imports = higher rank.
Ambiguity predicate: If the top two candidates tie on layer rank AND differ by ≤1 infrastructure import → escalate to Opus.
Before the Opus call, emit: Resolving ambiguous canonical for cluster: <domainConcept>...
Opus prompt:
Given these N entries that all compute the same domain concept, which one is the most appropriate canonical location for the business rule? Consider: domain purity, reusability, and least coupling to delivery mechanism. Return the file:function ID of the preferred canonical and a one-sentence rationale.
Entries:
<paste cluster entries>
If --no-opus flag was passed: skip Opus escalation. Report ambiguous clusters as:
canonical: ambiguous — human review required
canonical: suggested <file:line> — requires human confirmationcanonical: none — a new domain-layer implementation may be requiredCross-scope notice (scoped runs only): If a cluster contains entries outside the scoped path:
Note: this cluster includes <N> entry/entries outside the scoped path — run without scope argument to see full context
(Use "entry" when N=1, "entries" when N>1.)
After clustering is complete:
Duplicates found:
## Semantic Duplication Report
### Cluster: <domainConcept>
- <file>:<line> [<layer>] ← inferred canonical (or all entries if no canonical)
- <file>:<line> [<layer>]
canonical: suggested <file:line> — requires human confirmation
[Note: this cluster includes N entry/entries outside the scoped path ...]
---
No duplicates:
No semantic duplication detected
file:line accuracy: Line numbers point to the first line of the function definition. If the file has been modified since annotation, append: (line may have shifted — re-run scan to refresh)
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub bdfinst/agentic-dev-team --plugin dev-team103 skills in this plugin
/adr-toolsCreate and manage Architecture Decision Records using the npryce adr-tools CLI. Use when the user asks to "add an ADR", "record this decision", "create an ADR", "supersede ADR N", "link ADRs", "generate the ADR table of contents", or any request involving the `adr` command. Pairs with the adr-author agent — this skill is the mechanics (commands, files, links); adr-author is the decision framework (when an ADR is warranted) and the prose authoring./agent-auditAudit code-review agents, skills, and hooks for structural compliance. Use this when adding or modifying any agent, skill, or hook file, or for a periodic health check of the toolkit. Trigger phrases: "audit the agents", "check compliance", "validate the skills", "are the agents correct", or any time agent/skill files change./agent-evalRun eval fixtures against review agents and grade results. Use this after adding or modifying a review agent, to validate detection accuracy, or when the user says "run the evals", "test the agents", "check for regressions", or "how accurate is the agent"./agent-readinessScore how ready the current repository is for AI-assisted development against the Agent-Readiness Scorecard. Use when the user asks "how agent-ready is this repo", "score this repo for agents", "agent readiness", or wants a tiered readiness report. Scores YOUR project repo's readiness — not the dev-team plugin's own review agents and routing (for that, use /harness-audit)./api-designContract-first API design for stable, evolvable interfaces. Use whenever defining a new API endpoint, inter-service boundary, or modifying an existing contract. Includes backward compatibility checklist and error contract specification./apply-fixesApply correction prompts generated by /code-review. Use this whenever the user wants to apply, fix, or action the results of a code review — phrases like "apply the fixes", "fix the issues", "apply corrections", or after /code-review has run and produced a corrections/ directory.Other plugins' skills for the same job