Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

deduplicate-code

БесплатноБез исполняемых скриптовНе проверен

Detect copy-pasted code blocks across the shared source (vscode-extension/src, the repo-root src/, cli/src, sharing-server/src, desktop/src…

rajbosот rajbos★ 127 звёзд на GitHub

Об этом скилле

Deduplicate Code

The CI step summary runs check-code-duplication.js and reports copy-pasted blocks across the six TypeScript source trees every PR (the CI duplication-check job also fails when the count grows past scripts/code-duplication-baseline.json, so remediating lets you lower that baseline). A growing "Code Duplication Analysis" section (or a review finding of "this is duplicated") is the signal this skill remediates: it finds the duplicate groups, picks one, extracts a single shared helper in their place, and verifies nothing broke. Like refactor-large-function, it changes one group per pass so the diff stays reviewable and a regression points at a single extraction.

What the detector does

scripts/check-code-duplication.js (run as pnpm run check:duplicates from vscode-extension/) normalizes source lines (whitespace collapsed, comment-only and blank lines dropped so re-indented or re-commented copies are still caught), hashes sliding windows of a minimum length, groups identical windows, and extends each group to its maximal shared block. It reports clone groups as Markdown (for the step summary) or --json. It is report-only by default (CI gates it only through --baseline); this skill does the remediation the report asks for.

A "duplicate group" is a normalized sequence of >= --min-lines lines that occurs in two or more places (cross-file, or non-overlapping within one file).

Step 1 - List the duplicate groups

Get the current clone groups in machine-readable form so you can pick a target:

node scripts/check-code-duplication.js --json --min-lines 14

Or, scoped to one area if the full scan is large:

node scripts/check-code-duplication.js --json --min-lines 14 --include 'src/**/*.ts'

Read the groups array: each entry has lines (maximal block length), occurrences ({ file, startLine, endLine }), and a preview (first 3 lines). Pick the single group to remediate following these priorities:

  1. Skip auto-generated or intentionally-mirrored files. The shared editor adapters under src/adapters/*.ts and the per-editor CLI store modules (src/kilo.ts, src/opencode.ts, src/copilotCliStore.ts, src/devinCli.ts, src/hermes.ts) deliberately mirror each other's SQLite/stat helpers because each editor's session layout differs. A pure structural clone between two of these is usually NOT a safe extraction \u2014 only consolidate when the exact same logic (not just the same shape) is being copied.
  2. Prefer groups where every occurrence is genuinely identical behavior (same inputs, same outputs, same side effects) \u2014 those extract cleanly.
  3. Among those, prefer groups with the most occurrences (one helper replaces many copies) and the most lines (biggest payoff), all else equal.
  4. Prefer files that already have unit tests (check vscode-extension/test/unit/ for a matching test file) so the extraction is covered.

Step 2 - Read the instructions file

Before touching code, read the relevant sub-project instructions file for the area you are changing \u2014 .github/instructions/vscode-extension.instructions.md for vscode-extension/ work, .github/instructions/cli.instructions.md for cli/, and the root AGENTS.md for shared src/ (notably the "CLI Must Reuse Shared Functions" rule: never reimplement session parsing or cost attribution in a place the shared module already covers).

Step 3 - Understand the duplicate

Open every occurrence the detector reported and read the full block plus a few lines of surrounding context. Confirm it is a true behavioral duplicate and not two blocks that merely look the same but read different inputs or have different error handling. If the occurrences are only structurally similar (condemn both, then act), stop and pick a different group \u2014 forcing a shared helper onto divergent logic is the failure mode this skill exists to avoid.

Decide where the extracted helper lives:

  • Same file, used by two places in that file \u2192 a private helper (_ prefix) at the top of the file, like refactor-large-function.
  • Same package, multiple files \u2192 a private helper in the most natural existing module of that package (do not create a new file just to host the helper unless it is independently reusable \u2014 keep new files to a minimum).
  • Cross-package (e.g. shared src/ and vscode-extension/src) \u2192 the helper must live in the shared src/ module and be imported by the consumer, never copied. This is the canonical split documented in AGENTS.md.

Step 4 - Run the baseline tests

Establish a green baseline before changing anything:

cd vscode-extension
pnpm install --frozen-lockfile --ignore-scripts
node_modules/.bin/tsc --noEmit        # type-check
pnpm run test:node                     # unit tests

Record which tests cover the target files so you know what to watch.

Step

Полный SKILL.md на GitHub

Установить deduplicate-code в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл deduplicate-code?

Detect copy-pasted code blocks across the shared source (vscode-extension/src, the repo-root src/, cli/src, sharing-server/src, desktop/src, release-video/src) with the dependency-free check-code-duplication.js detector, then pick one duplicate group and extract a shared helper to eliminate it, keeping all tests green. Use when a PR review notes duplication, when the CI step summary's "Code Duplication Analysis" grows, or when asked to reduce code duplication / DRY up the codebase.

Как установить скилл deduplicate-code?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл deduplicate-code запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить deduplicate-code с