### Install via Homebrew Source: https://github.com/kucherenko/jscpd/blob/master/rust/README.md Installs the tool using Homebrew. ```bash brew install jscpd ``` -------------------------------- ### Quick Start jscpd Source: https://github.com/kucherenko/jscpd/blob/master/rust/jscpd/README.md Common command-line usage examples for scanning directories and configuring detection sensitivity. ```bash jscpd . # scan current directory jscpd ./src ./lib # scan specific paths jscpd . --min-tokens 30 --min-lines 3 # tune detection sensitivity jscpd . --blame --reporters console-full # git blame, side-by-side authors jscpd . --reporters json,html # write report files jscpd . --threshold 10 # fail CI if >10% duplicated jscpd --list # list all supported formats ``` -------------------------------- ### Install pre-commit framework Source: https://github.com/kucherenko/jscpd/blob/master/docs/ci-and-hooks.md Install the pre-commit tool using pip, brew, or npm. ```bash # pip pip install pre-commit # brew brew install pre-commit # npm (wrapper around the Python tool) npm install -g pre-commit ``` -------------------------------- ### Install via Nix Source: https://github.com/kucherenko/jscpd/blob/master/rust/README.md Run or install the tool using the Nix package manager. ```bash # Run without installing nix run github:kucherenko/jscpd -- /path/to/code # Install permanently nix profile install github:kucherenko/jscpd ``` -------------------------------- ### Configuration File Example (.cpd.yaml) Source: https://github.com/kucherenko/jscpd/blob/master/fixtures/markdown/file2.md Example configuration file defining languages, file patterns, exclusions, reporters, and language extensions. ```yaml #.cpd.yaml languages: - javascript - coffeescript - typescript - php - python - jsx - haxe - yaml - css - ruby - go - swift - twig - java - clike # c++, c, objective-c source - csharp # c# source - htmlmixed # html mixed source like knockout.js templates files: - "test/**/*" exclude: - "**/*.min.js" - "**/*.mm.js" reporter: json languages-exts: coffeescript: - coffeee javascript: - es - es5 - es6 - es7 ``` -------------------------------- ### Configure cpd with .jscpd.json Source: https://github.com/kucherenko/jscpd/blob/master/rust/npm/README.md Example configuration file for project-level settings. ```json { "minTokens": 30, "minLines": 3, "format": ["javascript", "typescript", "python"], "ignorePattern": ["node_modules", "dist", "*.min.js"], "reporters": ["console", "json"], "output": "report", "threshold": 5, "blame": false } ``` -------------------------------- ### Install @jscpd/finder Source: https://github.com/kucherenko/jscpd/blob/master/packages/finder/README.md Install the package via npm. ```bash npm install @jscpd/finder --save ``` -------------------------------- ### Install cpd and jscpd Source: https://github.com/kucherenko/jscpd/blob/master/rust/npm/README.md Commands to install the tool via npm, cargo, Nix, or Homebrew. ```bash # npm — installs the jscpd command npm install -g jscpd # npm — installs only the cpd command npm install -g cpd # crates.io — installs both jscpd and cpd binaries cargo install jscpd # Nix — run without installing nix run github:kucherenko/jscpd -- /path/to/code # Nix — install permanently nix profile install github:kucherenko/jscpd # Homebrew (macOS/Linux) brew install jscpd ``` -------------------------------- ### Quick Start CLI usage Source: https://github.com/kucherenko/jscpd/blob/master/rust/README.md Common commands for running the cpd detector. ```bash cpd . cpd ./src ./lib cpd . --blame --reporters console-full cpd . --reporters json,html cpd . --threshold 10 cpd --list ``` -------------------------------- ### jscpd Configuration File Example Source: https://github.com/kucherenko/jscpd/blob/master/docs/typescript.md An example of a .jscpd.json file to configure detection settings and reporters. ```json { "path": ["./src"], "reporters": ["console", "json"], "minLines": 5, "minTokens": 50, "maxLines": 1000, "maxSize": "100kb", "threshold": 0, "format": ["javascript", "typescript"], "ignore": ["**/node_modules/**"], "gitignore": true, "mode": "mild", "absolute": false, "skipLocal": false, "skipComments": false } ``` -------------------------------- ### Install @jscpd/sarif-reporter Source: https://github.com/kucherenko/jscpd/blob/master/packages/sarif-reporter/README.md Install the package via npm. ```bash npm install @jscpd/sarif-reporter ``` -------------------------------- ### Install and run pre-commit hooks Source: https://github.com/kucherenko/jscpd/blob/master/docs/ci-and-hooks.md Commands to install the hook into the git repository and run it manually. ```bash pre-commit install ``` ```bash pre-commit run jscpd --all-files ``` -------------------------------- ### Install @jscpd/badge-reporter Source: https://github.com/kucherenko/jscpd/blob/master/packages/badge-reporter/README.md Install the package via npm. ```bash npm install @jscpd/badge-reporter ``` -------------------------------- ### Install AI Agent Skills Source: https://github.com/kucherenko/jscpd/blob/master/README.md Install specific skills to enable AI coding assistants to perform duplication detection and guided refactoring. ```bash npx skills add kucherenko/jscpd --skill jscpd ``` ```bash npx skills add kucherenko/jscpd --skill dry-refactoring ``` -------------------------------- ### Shell Script Example Source: https://github.com/kucherenko/jscpd/blob/master/packages/tokenizer/__tests__/fixtures/markdown/synonym-langs.md Basic shell commands for demonstration. ```shell echo "hello world" ls -la /tmp cd /home ``` -------------------------------- ### Install via npm Source: https://github.com/kucherenko/jscpd/blob/master/rust/README.md Installs the jscpd or cpd command globally using npm. ```bash # npm — installs the jscpd command npm install -g jscpd # npm — installs only the cpd command npm install -g cpd ``` -------------------------------- ### Start Server with LevelDB Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Launch the jscpd server using LevelDB for persistence. ```bash jscpd server /path/to/project --store leveldb --port 3000 ``` -------------------------------- ### Install @jscpd/leveldb-store Source: https://github.com/kucherenko/jscpd/blob/master/packages/leveldb-store/README.md Install the package via npm. ```bash npm install @jscpd/leveldb-store --save ``` -------------------------------- ### Install jscpd Globally or Use npx Source: https://github.com/kucherenko/jscpd/blob/master/docs/typescript.md Install the jscpd command-line tool globally using npm or run it directly without installation using npx. ```bash # npm npm install -g jscpd # npx (no install required) npx jscpd /path/to/code ``` -------------------------------- ### Install LevelDB Store Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Install the required package to enable disk-based storage for scan results. ```bash npm install @jscpd/leveldb-store ``` -------------------------------- ### Run Simian help Source: https://github.com/kucherenko/jscpd/blob/master/benchmark/tools/README.md Verify the Simian JAR installation using the Java runtime. ```bash java -jar tools/simian.jar -help ``` -------------------------------- ### Start jscpd-server Source: https://github.com/kucherenko/jscpd/blob/master/docs/ai-ready.md Start the jscpd-server, optionally specifying port, host, or storage options. This makes jscpd accessible as an MCP tool. ```bash jscpd-server /path/to/project ``` -------------------------------- ### Install jscpd Source: https://github.com/kucherenko/jscpd/blob/master/rust/jscpd/README.md Commands to install jscpd using various package managers or run it via Nix. ```bash # npm — installs the jscpd command npm install -g jscpd # crates.io — installs both jscpd and cpd binaries cargo install jscpd # Nix — run without installing nix run github:kucherenko/jscpd -- /path/to/code # Nix — install permanently nix profile install github:kucherenko/jscpd # Homebrew (macOS/Linux) brew install jscpd ``` -------------------------------- ### Start JSCPD Server via Command Line Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Various commands to launch the server with different directory, port, host, and storage configurations. ```bash # Start server in current directory jscpd-server # Start server in specific directory jscpd-server /path/to/project # Start server on specific port jscpd-server . --port 8080 # Start server with custom host jscpd-server . --host localhost --port 3000 # Start server with persistent storage (recommended for production) jscpd-server . --store leveldb ``` -------------------------------- ### Install jscpd-rs or Fallow Source: https://github.com/kucherenko/jscpd/blob/master/benchmark/tools/README.md Install the specific npm package for the tool. ```bash npm install ``` -------------------------------- ### Install @jscpd/html-reporter Source: https://github.com/kucherenko/jscpd/blob/master/packages/html-reporter/README.md Install the package via npm to enable HTML reporting capabilities. ```bash npm install @jscpd/html-reporter ``` -------------------------------- ### Install jscpd-server Source: https://github.com/kucherenko/jscpd/blob/master/docs/ai-ready.md Install the jscpd-server globally using npm to expose jscpd's detection capabilities as MCP tools for AI assistants. ```bash npm install -g jscpd-server ``` -------------------------------- ### Install @jscpd/redis-store Source: https://github.com/kucherenko/jscpd/blob/master/packages/redis-store/README.md Install the package via npm to add it to your project dependencies. ```bash npm install @jscpd/redis-store --save ``` -------------------------------- ### Install npm-based tools Source: https://github.com/kucherenko/jscpd/blob/master/benchmark/tools/README.md Install jscpd-rs and Fallow dependencies within the tools directory. ```bash cd tools/ npm install ``` -------------------------------- ### Verify Duplo installation Source: https://github.com/kucherenko/jscpd/blob/master/benchmark/tools/README.md Check the Duplo binary help output after setting execution permissions. ```bash # Verify ./duplo -help ``` -------------------------------- ### jscpd Configuration File Example Source: https://github.com/kucherenko/jscpd/blob/master/fixtures/markdown/file1.md An example YAML configuration file for jscpd, defining languages, files, exclusions, reporters, and language extensions. ```yaml #.cpd.yaml languages: - javascript - coffeescript - typescript - php - python - jsx - haxe - yaml - css - ruby - go - swift - twig - java - clike # c++, c, objective-c source - csharp # c# source - htmlmixed # html mixed source like knockout.js templates files: - "test/**/*" exclude: - "**/*.min.js" - "**/*.mm.js" reporter: json languages-exts: coffeescript: - coffee javascript: - es - es5 - es6 - es7 ``` -------------------------------- ### Skip Installation Source: https://github.com/kucherenko/jscpd/blob/master/docs/ci-and-hooks.md Prevents the action from installing the binary, useful if the binary is already present in the runner image. ```yaml - uses: kucherenko/jscpd@master with: skip-install: true ``` -------------------------------- ### Configure GitHub Actions for jscpd server Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Automates the installation, server startup, and code duplication check for changed files in a CI/CD pipeline. ```yaml name: Check Code Duplication on: [push, pull_request] jobs: check-duplication: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '18' - name: Install jscpd run: npm install -g jscpd - name: Start jscpd server run: | jscpd server . --port 3000 & sleep 10 # Wait for server to initialize - name: Check new code run: | # Check files changed in this PR for file in $(git diff --name-only HEAD~1); do if [[ -f "$file" ]]; then # Extract file extension to determine format ext="${file##*.}" curl -X POST http://localhost:3000/api/check \ -H "Content-Type: application/json" \ -d "{\"code\": \"$(cat $file | jq -Rs .)\", \"format\": \"$ext\"}" \ | jq . fi done ``` -------------------------------- ### Install PMD CPD via Homebrew Source: https://github.com/kucherenko/jscpd/blob/master/benchmark/tools/README.md Install PMD using Homebrew on macOS; requires Java 8+. ```bash brew install pmd ``` -------------------------------- ### Install jscpd Globally Source: https://github.com/kucherenko/jscpd/blob/master/fixtures/markdown/file1.md Install the jscpd command-line tool globally using npm for system-wide access. ```bash npm install jscpd -g ``` -------------------------------- ### Install and Run jscpd v5 Source: https://github.com/kucherenko/jscpd/blob/master/docs/rust.md Commands for installing and executing the jscpd Rust engine across various package managers and platforms. ```bash # npm — installs the jscpd command (same binary as v4 command name) npm install -g jscpd@5 jscpd /path/to/code # npm — installs only the cpd command (lighter) npm install -g cpd cpd /path/to/code # crates.io — Rust-native install (exposes both jscpd and cpd commands) cargo install jscpd jscpd /path/to/code cpd /path/to/code # Nix — run without installing nix run github:kucherenko/jscpd -- /path/to/code # Nix — install permanently nix profile install github:kucherenko/jscpd # Homebrew (macOS/Linux) brew install jscpd ``` -------------------------------- ### Manual Git hook setup Source: https://github.com/kucherenko/jscpd/blob/master/docs/ci-and-hooks.md Create and enable a shell script in .git/hooks/ to run jscpd. ```bash #!/bin/sh jscpd --threshold 5 --reporters console,silent . ``` ```bash chmod +x .git/hooks/pre-commit ``` -------------------------------- ### Initialize LeveldbStore in jscpd Source: https://github.com/kucherenko/jscpd/blob/master/packages/leveldb-store/README.md Basic setup for integrating LeveldbStore with the jscpd Detector. ```typescript import {Tokenizer} from '@jscpd/tokenizer'; import { Detector, IOptions, IClone, IStore, ITokenizer } from '@jscpd/core'; import LeveldbStore from '@jscpd/leveldb-store'; const options: IOptions = { minLines: 5, maxLines: 500, } const tokenizer: ITokenizer = new Tokenizer(); // Default: stores cache in .jscpd/ relative to cwd const store: IStore = new LeveldbStore(); const detector = new Detector(tokenizer, store, [], options); ``` -------------------------------- ### Install @jscpd/tokenizer Source: https://github.com/kucherenko/jscpd/blob/master/packages/tokenizer/README.md Use npm to add the tokenizer package to your project dependencies. ```bash npm install @jscpd/tokenizer --save ``` -------------------------------- ### Install and Run jscpd Source: https://github.com/kucherenko/jscpd/blob/master/README.md Various methods to install and execute the jscpd copy/paste detector across different environments and versions. ```bash # Install (all platforms — installs the jscpd command) curl -fsSL https://jscpd.dev/install.sh | bash # TypeScript engine (Node.js, v4.x) npm install -g jscpd@4 jscpd /path/to/code # or use without installing npx jscpd@4 /path/to/code # Rust engine (v5.x, 24-37x faster) — installs the jscpd command npm install -g jscpd@5 jscpd /path/to/code # Rust engine — cpd command only npm install -g cpd cpd /path/to/code # Rust-native install (exposes both jscpd and cpd) cargo install jscpd # Nix (installs both jscpd and cpd) nix run github:kucherenko/jscpd -- /path/to/code # or install permanently nix profile install github:kucherenko/jscpd # Homebrew (macOS/Linux) brew install jscpd ``` -------------------------------- ### Install jscpd via Cargo Source: https://github.com/kucherenko/jscpd/blob/master/rust/crates/cpd/README.md Install the tool directly from crates.io using the Rust package manager. ```bash cargo install jscpd ``` -------------------------------- ### Install @jscpd/core Source: https://github.com/kucherenko/jscpd/blob/master/packages/core/README.md Use npm to add the core package to your project dependencies. ```bash npm install @jscpd/core --save ``` -------------------------------- ### AI Reporter Example Output Source: https://github.com/kucherenko/jscpd/blob/master/docs/ai-ready.md This is an example of the compact output format generated by the 'ai' reporter, suitable for piping into an LLM. ```text src/utils/ auth.ts:10-25 ~ helpers.ts:40-55 src/utils/auth.ts 30-45 ~ 80-95 src/ utils/auth.ts:10-25 ~ api/routes.ts:5-20 --- 23 clones · 4.2% duplication ``` -------------------------------- ### Common jscpd CLI Examples Source: https://github.com/kucherenko/jscpd/blob/master/docs/rust.md Various command-line usage patterns for jscpd, including configuration flags, reporters, and directory filtering. ```bash # Drop-in replacement for jscpd v4 jscpd /path/to/source # or cpd /path/to/source # Same flags as v4 cpd /path/to/source --min-tokens 30 --min-lines 3 --reporters console,json,html # Git blame with side-by-side author comparison cpd /path/to/source --blame --reporters console-full # List supported formats cpd --list # Use multiple reporters with custom output cpd ./src -r console,json,sarif -o ./reports # Skip clones within the same directory cpd --skip-local /path/to/source ``` -------------------------------- ### jscpd CLI with argv Source: https://github.com/kucherenko/jscpd/blob/master/docs/typescript.md Example of using the jscpd CLI with command-line arguments to detect clones. ```APIDOC ## `jscpd` with argv ### Description This example demonstrates how to invoke the jscpd command-line interface with arguments to perform clone detection. ### Method CLI Command ### Endpoint N/A ### Parameters - `path` (string[]): The path(s) to analyze for clones. - `mode` (string): The detection mode (e.g., 'weak'). - `silent` (boolean): Suppresses output. ### Request Example ```typescript import { IClone } from '@jscpd/core'; import { jscpd } from 'jscpd'; const clones: IClone[] = await jscpd(['', '', './fixtures', '-m', 'weak', '--silent']); ``` ### Response #### Success Response Returns an array of detected clones (`IClone[]`). #### Response Example ```json [ { "start": {"line": 10, "column": 0}, "end": {"line": 20, "column": 5}, "startInFile": "/path/to/file1.js", "endInFile": "/path/to/file2.js", "density": 0.85, "tokenLength": 150 } ] ``` ``` -------------------------------- ### AI Reporter Output Example Source: https://github.com/kucherenko/jscpd/blob/master/skills/jscpd/SKILL.md Illustrates the compact output format of the AI reporter, showing detected clone pairs and overall duplication statistics. ```text Clones: src/ foo.ts:10-25 ~ bar.ts:42-57 src/utils/helpers.ts:100-120 ~ src/utils/other.ts:5-25 --- 3 clones · 4.2% duplication ``` -------------------------------- ### GET / Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Retrieves information about the API and available endpoints. ```APIDOC ## GET / ### Description Get information about the API and available endpoints. ### Method GET ### Endpoint / ### Response #### Success Response (200) - **name** (string) - The name of the server. - **version** (string) - The version of the server. - **endpoints** (object) - A map of available endpoints and their descriptions. - **documentation** (string) - A link to the project documentation. #### Response Example { "name": "jscpd-server", "version": "1.0.0", "endpoints": { "POST /api/check": "Check code snippet for duplications", "GET /api/stats": "Get overall project statistics", "GET /api/health": "Server health check" }, "documentation": "https://github.com/kucherenko/jscpd" } ``` -------------------------------- ### Get API Information Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Retrieves metadata about the server, including version and available endpoints. ```bash curl http://localhost:3000/ ``` ```json { "name": "jscpd-server", "version": "1.0.0", "endpoints": { "POST /api/check": "Check code snippet for duplications", "GET /api/stats": "Get overall project statistics", "GET /api/health": "Server health check" }, "documentation": "https://github.com/kucherenko/jscpd" } ``` -------------------------------- ### Install dry-refactoring Workflow Skill Source: https://github.com/kucherenko/jscpd/blob/master/docs/ai-ready.md Add the dry-refactoring skill to your AI agent to enable a guided process for reading clone output, refactoring, and verifying duplication removal. ```bash npx skills add kucherenko/jscpd --skill dry-refactoring ``` -------------------------------- ### Install jscpd Tool Reference Skill Source: https://github.com/kucherenko/jscpd/blob/master/docs/ai-ready.md Add the jscpd tool reference skill to your AI agent to teach it about jscpd's CLI options, AI reporter format, and configuration. ```bash npx skills add kucherenko/jscpd --skill jscpd ``` -------------------------------- ### Build from source Source: https://github.com/kucherenko/jscpd/blob/master/rust/README.md Clones the repository and builds the binaries from source. ```bash git clone https://github.com/kucherenko/jscpd.git cd jscpd/rust cargo build --release # binaries at target/release/jscpd and target/release/cpd ``` -------------------------------- ### Get Project Statistics via API Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Retrieves overall duplication statistics for the scanned codebase. Returns a 503 error if the server is still initializing. ```bash curl http://localhost:3000/api/stats ``` ```json { "statistics": { "detectionDate": "2025-11-17T10:30:00.000Z", "total": { "lines": 10000, "tokens": 50000, "sources": 50, "duplicatedLines": 500, "duplicatedTokens": 2500, "clones": 10, "percentage": 5.0, "percentageTokens": 5.0, "newDuplicatedLines": 0, "newClones": 0 }, "formats": { "javascript": { "total": { "lines": 5000, "tokens": 25000, "sources": 30, "duplicatedLines": 300, "duplicatedTokens": 1500, "clones": 6, "percentage": 6.0, "percentageTokens": 6.0, "newDuplicatedLines": 0, "newClones": 0 }, "sources": { "src/file1.js": { "lines": 100, "tokens": 500, "sources": 1, "duplicatedLines": 10, "duplicatedTokens": 50, "clones": 1, "percentage": 10.0, "percentageTokens": 10.0, "newDuplicatedLines": 0, "newClones": 0 } } } } }, "timestamp": "2025-11-17T10:30:00.000Z" } ``` ```json { "error": "NotReady", "message": "Statistics not available yet. Server is still initializing.", "statusCode": 503 } ``` -------------------------------- ### MCP Server Installation and Usage Source: https://github.com/kucherenko/jscpd/blob/master/docs/ai-ready.md The jscpd-server implements the Model Context Protocol (MCP), exposing jscpd's detection capabilities as tools that AI assistants can call directly from the editor. ```APIDOC ## MCP Server [jscpd-server](../apps/jscpd-server) implements the [Model Context Protocol (MCP)](https://modelcontextprotocol.io), exposing jscpd's detection capabilities as tools that AI assistants can call directly from the editor. Start the server once against your codebase, then let your AI assistant check any snippet for duplication on demand — no CLI invocation needed. ### Installation ```bash npm install -g jscpd-server ``` ### Usage Start the server: ```bash jscpd-server /path/to/project ``` Options: - `--port` — Port number (default: 3000) - `--host` — Host to bind (default: 0.0.0.0) - `--store leveldb` — Use LevelDB persistent storage - Plus all standard jscpd detection options ``` -------------------------------- ### Extract Module/Utility Refactoring Example Source: https://github.com/kucherenko/jscpd/blob/master/skills/dry-refactoring/SKILL.md Demonstrates the 'extract module/utility' refactoring strategy. This is used when duplicated code spans multiple files across different domains, suggesting a need for a shared utility file. ```typescript // Move shared logic to a shared utility file and import it ``` -------------------------------- ### Build and Test Source: https://github.com/kucherenko/jscpd/blob/master/rust/README.md Commands to build and test the project. ```bash cargo build --release cargo test ``` -------------------------------- ### Go Hello World Program Source: https://github.com/kucherenko/jscpd/blob/master/packages/tokenizer/__tests__/fixtures/markdown/synonym-langs.md A simple 'Hello, World!' program in Go. ```go package main import "fmt" func main() { fmt.Println("hello world") } ``` -------------------------------- ### Configure jscpd for Qore files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .q and .qm extensions to the qore grammar. ```bash jscpd --formats-exts "qore:q,qm" ./src ``` -------------------------------- ### Development Workflow Commands Source: https://github.com/kucherenko/jscpd/blob/master/README.md Standard commands for setting up the development environment, running tests, and building the project. ```bash git clone https://github.com/{your-id}/jscpd ``` ```bash pnpm install ``` ```bash pnpm dev ``` ```bash pnpm test ``` ```bash pnpm build ``` -------------------------------- ### Initialize and run the Detector Source: https://github.com/kucherenko/jscpd/blob/master/packages/core/README.md Configure the detector with a tokenizer and store, then execute detection on a code string. ```typescript import {Tokenizer} from '@jscpd/tokenizer'; import { Detector, MemoryStore, IOptions, IClone, IStore, ITokenizer } from '@jscpd/core'; const options: IOptions = { minLines: 5, maxLines: 500, } const tokenizer: ITokenizer = new Tokenizer(); // here you can use any store what implement IStore interface const store: IStore = new MemoryStore(); // list of validators, implemented IValidator interface, validate clones const validators = []; const detector = new Detector(tokenizer, store, validators, options); ( async () => { const format = 'javascript'; const code: string = '...string with code...'; const clones: IClone[] = await detector.detect('source_id', code, format); console.log(clones); })(); ``` -------------------------------- ### Using a Configuration File Source: https://github.com/kucherenko/jscpd/blob/master/fixtures/markdown/file2.md Specify a configuration file for jscpd settings. ```bash jscpd --config test/.cpd.yaml ``` -------------------------------- ### Configure jscpd for MediaWiki files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .wiki extension to the wiki grammar. ```bash jscpd --formats-exts "wiki:wiki" ./src ``` -------------------------------- ### Install dry-refactoring Skill Source: https://github.com/kucherenko/jscpd/blob/master/skills/jscpd/SKILL.md Command to install the 'dry-refactoring' skill, which assists in refactoring duplicated code detected by jscpd. ```bash npx skills add https://github.com/kucherenko/jscpd --skill dry-refactoring ``` -------------------------------- ### Configure jscpd for Prolog files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .pl and .pro extensions to the prolog grammar. ```bash jscpd --formats-exts "prolog:pl,pro" ./src ``` -------------------------------- ### Configure jscpd for Nix files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .nix extension to the nix grammar. ```bash jscpd --formats-exts "nix:nix" ./src ``` -------------------------------- ### Configure jscpd for PromQL files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .promql extension to the promql grammar. ```bash jscpd --formats-exts "promql:promql" ./src ``` -------------------------------- ### Configure jscpd for Xeora files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .xeora and .xchtml extensions to the xeora grammar. ```bash jscpd --formats-exts "xeora:xeora,xchtml" ./src ``` -------------------------------- ### Configure jscpd for ReasonML files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .re and .rei extensions to the reason grammar. ```bash jscpd --formats-exts "reason:re,rei" ./src ``` -------------------------------- ### GET /api/health Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Checks the server health and initialization status. ```APIDOC ## GET /api/health ### Description Check server health and initialization status. ### Method GET ### Endpoint /api/health ### Response #### Success Response (200) - **status** (string) - The current status of the server (initializing or ready). - **workingDirectory** (string) - The path to the project being scanned. - **lastScanTime** (string) - The timestamp of the last scan. #### Response Example { "status": "ready", "workingDirectory": "/path/to/project", "lastScanTime": "2025-11-17T10:30:00.000Z" } ``` -------------------------------- ### GET /api/stats Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Retrieves the overall duplication statistics for the scanned codebase. ```APIDOC ## GET /api/stats ### Description Get overall duplication statistics for the scanned codebase. ### Method GET ### Endpoint /api/stats ### Response #### Success Response (200) - **statistics** (object) - The full statistics object from the initial scan. - **timestamp** (string) - The time the statistics were generated. #### Response Example { "statistics": { "detectionDate": "2025-11-17T10:30:00.000Z", "total": { "lines": 10000, "tokens": 50000, "sources": 50, "duplicatedLines": 500, "duplicatedTokens": 2500, "clones": 10, "percentage": 5.0, "percentageTokens": 5.0, "newDuplicatedLines": 0, "newClones": 0 } }, "timestamp": "2025-11-17T10:30:00.000Z" } ``` -------------------------------- ### Configure Husky hooks Source: https://github.com/kucherenko/jscpd/blob/master/docs/ci-and-hooks.md Initialize Husky and add a jscpd pre-commit hook. ```bash npm install -D husky npx husky init ``` ```bash echo 'npx jscpd@5 --threshold 5 --reporters console,silent .' > .husky/pre-commit ``` -------------------------------- ### cpd_finder::orchestrate::run(config: &RunConfig) Source: https://github.com/kucherenko/jscpd/blob/master/docs/api.md Rust API for orchestrating clone detection using the cpd-finder crate. ```APIDOC ## cpd_finder::orchestrate::run ### Description Executes clone detection in Rust applications using the provided `RunConfig`. ### Signature `pub fn run(config: &RunConfig) -> Result` ### Parameters - **config** (RunConfig) - Required - Configuration struct containing paths, min_tokens, and other detection settings. ### Example ```rust use cpd_finder::orchestrate::{RunConfig, run}; let config = RunConfig { paths: vec!["./src".into()], min_tokens: 50, ..Default::default() }; let result = run(&config).unwrap(); ``` ``` -------------------------------- ### Basic Usage: Specify Path and Languages Source: https://github.com/kucherenko/jscpd/blob/master/fixtures/markdown/file2.md Use this command to scan a specific directory for JavaScript and CoffeeScript files. ```bash jscpd --path my_project/ --languages javascript,coffee ``` -------------------------------- ### Pin Specific Version Source: https://github.com/kucherenko/jscpd/blob/master/docs/ci-and-hooks.md Forces the action to install a specific version of the jscpd engine. ```yaml - uses: kucherenko/jscpd@master with: version: "5.0.9" ``` -------------------------------- ### Configure jscpd for OpenCL files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .cl extension to the opencl grammar. ```bash jscpd --formats-exts "opencl:cl" ./src ``` -------------------------------- ### JSON Reporter Format Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd/README.md Example of the structured JSON output containing duplication details and statistics. ```json { "duplicates": [{ "format": "javascript", "lines": 27, "fragment": "...code fragment... ", "tokens": 0, "firstFile": { "name": "tests/fixtures/javascript/file2.js", "start": 1, "end": 27, "startLoc": { "line": 1, "column": 1 }, "endLoc": { "line": 27, "column": 2 } }, "secondFile": { "name": "tests/fixtures/javascript/file1.js", "start": 1, "end": 24, "startLoc": { "line": 1, "column": 1 }, "endLoc": { "line": 24, "column": 2 } } }], "statistic": { "detectionDate": "2018-11-09T15:32:02.397Z", "formats": { "javascript": { "sources": { "/path/to/file": { "lines": 24, "sources": 1, "clones": 1, "duplicatedLines": 26, "percentage": 45.33, "newDuplicatedLines": 0, "newClones": 0 } }, "total": { "lines": 297, "sources": 1, "clones": 1, "duplicatedLines": 26, "percentage": 45.33, "newDuplicatedLines": 0, "newClones": 0 } } }, "total": { "lines": 297, "sources": 6, "clones": 5, "duplicatedLines": 26, "percentage": 45.33, "newDuplicatedLines": 0, "newClones": 0 } } } ``` -------------------------------- ### PMD CPD XML Format Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd/README.md Example of the XML output format compatible with PMD CPD. ```xml ``` -------------------------------- ### Configure jscpd for WebAssembly text files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .wat extension to the wasm grammar. ```bash jscpd --formats-exts "wasm:wat" ./src ``` -------------------------------- ### run(config: &RunConfig) Source: https://github.com/kucherenko/jscpd/blob/master/docs/rust.md Executes the clone detection process based on the provided configuration. ```APIDOC ## run(config: &RunConfig) ### Description Executes the clone detection process using the specified configuration settings. ### Signature `pub fn run(config: &RunConfig) -> Result` ### Parameters - **config** (RunConfig) - Required - Configuration object containing paths to analyze and detection thresholds (e.g., min_tokens). ### Usage Example ```rust use cpd_finder::orchestrate::{RunConfig, run}; let config = RunConfig { paths: vec!["./src".into()], min_tokens: 50, ..Default::default() }; let result = run(&config).unwrap(); ``` ``` -------------------------------- ### Build jscpd v4 TypeScript CLI Source: https://github.com/kucherenko/jscpd/blob/master/benchmark/tools/README.md Install dependencies and build the TypeScript version of jscpd v4. ```bash cd ../../apps/jscpd/ npm install npm run build ``` -------------------------------- ### Interpret Blame Output Source: https://github.com/kucherenko/jscpd/blob/master/docs/rust.md Example of side-by-side author comparison output when using the --blame flag. ```text 176 │ Andrii Kucherenko │ <= │ 196 │ Josh Soref │ ## TODO 177 │ Andrii Kucherenko │ <= │ 197 │ Josh Soref │ 180 │ Andrii Kucherenko │ == │ 200 │ Andrii Kucherenko │ ## License ``` -------------------------------- ### Programmatic Usage in CoffeeScript Source: https://github.com/kucherenko/jscpd/blob/master/fixtures/markdown/file2.md Example of using jscpd programmatically within a CoffeeScript application to run checks. ```coffeescript # coffeescript jscpd = require('jscpd') result = jscpd::run path: 'my/project/folder' files: '**/*.js' exclude: ['**/*.min.js', '**/node_modules/**'] reporter: json ``` -------------------------------- ### List Supported Formats Source: https://github.com/kucherenko/jscpd/blob/master/packages/tokenizer/README.md Run the jscpd CLI command to view all supported programming languages and formats. ```bash jscpd --list ``` -------------------------------- ### GET /api/stats Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Retrieves the current statistics for the project, including total lines, tokens, and clone information. ```APIDOC ## GET /api/stats ### Description Retrieves aggregated statistics for the project. ### Method GET ### Endpoint /api/stats ### Response #### Success Response (200) - **statistics** (object) - Contains project metrics such as lines, tokens, sources, duplicatedLines, duplicatedTokens, clones, and percentage. ``` -------------------------------- ### Clear Cached Data Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd-server/README.md Remove the local storage directory to force a fresh scan on the next server start. ```bash rm -rf .jscpd/ ``` -------------------------------- ### MCP Tools Source: https://github.com/kucherenko/jscpd/blob/master/docs/ai-ready.md The jscpd-server exposes MCP tools for checking duplications, getting statistics, and re-scanning the working directory. ```APIDOC ### MCP Tools Available MCP tools exposed via the `/mcp` endpoint: - `check_duplication` — Check a code snippet for duplications (inputs: `code`, `format`) - `get_statistics` — Get project stats (no inputs) - `check_current_directory` — Re-scan the working directory (no inputs) Snippet checking uses an ephemeral in-memory store per request for isolation — no cross-request contamination, automatic cleanup, concurrent-request safe. ``` -------------------------------- ### Run jscpd commands Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd/README.md Execute jscpd to scan source code for duplications using npx or the installed binary, with optional pattern matching. ```bash $ npx jscpd /path/to/source ``` ```bash $ jscpd /path/to/code ``` ```bash $ jscpd --pattern "src/**/*.js" ``` -------------------------------- ### Agent Skills Installation Source: https://github.com/kucherenko/jscpd/blob/master/docs/ai-ready.md jscpd provides AI agent skills to teach coding assistants how to use jscpd for detecting and refactoring duplications. ```APIDOC ## Agent Skills jscpd ships two AI agent skills that teach coding assistants how to use jscpd and refactor detected duplications. ### jscpd — Tool Reference Skill Covers all CLI options, the AI reporter output format, and configuration file syntax. ```bash npx skills add kucherenko/jscpd --skill jscpd ``` ### dry-refactoring — Refactoring Workflow Skill A guided process for reading clone output, choosing the right extraction strategy, applying the refactor, and verifying the clone is eliminated. ```bash npx skills add kucherenko/jscpd --skill dry-refactoring ``` After installation, ask your agent to "find and fix code duplication" and it will invoke jscpd with the right options and act on the results. ``` -------------------------------- ### detectClones with custom store Source: https://github.com/kucherenko/jscpd/blob/master/docs/typescript.md Demonstrates using `detectClones` with a custom store (e.g., `MemoryStore`) for managing clone data and enabling incremental detection. ```APIDOC ## `detectClones` with custom store ### Description This example shows how to use `detectClones` with a custom store implementation, such as `MemoryStore`, to manage detected clones. This is useful for incremental detection or custom storage needs. ### Method `detectClones(options: DetectClonesOptions, store: IStore): Promise` ### Endpoint N/A (API Function) ### Parameters #### Options Object - **path** (string[]): Required. The path(s) to analyze. - **silent** (boolean): Optional. Suppresses output. #### Store Object - **store** (IStore): An instance of a store implementation (e.g., `MemoryStore`, `LeveldbStore`). ### Request Example ```typescript import { detectClones } from 'jscpd'; import { IMapFrame, MemoryStore } from '@jscpd/core'; const store = new MemoryStore(); // Initial detection await detectClones({ path: ['./src'], }, store); // Incremental detection using the same store await detectClones({ path: ['./src'], silent: true, }, store); ``` ### Response #### Success Response Returns a promise that resolves to an array of `IClone` objects detected during the operation. #### Response Example ```json [ { "start": {"line": 10, "column": 0}, "end": {"line": 20, "column": 5}, "startInFile": "/path/to/file1.js", "endInFile": "/path/to/file2.js", "density": 0.85, "tokenLength": 150 } ] ``` ``` -------------------------------- ### detectClones(options: IOptions, store?: IStore) Source: https://github.com/kucherenko/jscpd/blob/master/apps/jscpd/README.md Detects clones based on a configuration object, with optional support for a persistent store. ```APIDOC ## detectClones(options: IOptions, store?: IStore) ### Description Performs clone detection using a configuration object. An optional store can be provided to persist detection data across multiple calls. ### Signature `detectClones(options: IOptions, store?: IStore): Promise` ### Parameters - **options** (IOptions) - Required - Configuration object containing paths and detection settings. - **store** (IStore) - Optional - A store instance (e.g., MemoryStore) for persisting detection state. ``` -------------------------------- ### CSS Styling Example Source: https://github.com/kucherenko/jscpd/blob/master/fixtures/markup.html A basic CSS rule defining styles for an element with the class 'content'. It sets the color, width, and border properties. ```css .content { color: blue; width: 400px; border: 1px solid red; } ``` -------------------------------- ### Configure jscpd for Roboconf files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .graph and .instances extensions to the roboconf grammar. ```bash jscpd --formats-exts "roboconf:graph,instances" ./src ``` -------------------------------- ### Configure jscpd for Pure files Source: https://github.com/kucherenko/jscpd/blob/master/FORMATS.md Maps the .pure extension to the pure grammar. ```bash jscpd --formats-exts "pure:pure" ./src ``` -------------------------------- ### jscpd CLI with argv Source: https://github.com/kucherenko/jscpd/blob/master/docs/typescript.md Use the jscpd CLI to detect clones by passing arguments directly. This example shows how to specify a path and detection mode. ```typescript import { IClone } from '@jscpd/core'; import { jscpd } from 'jscpd'; const clones: IClone[] = await jscpd(['', '', './fixtures', '-m', 'weak', '--silent']); ``` -------------------------------- ### jscpd AI Reporter Output Format Source: https://github.com/kucherenko/jscpd/blob/master/benchmark/BENCHMARK.md Example of the compressed plain-text output generated by the jscpd AI reporter, featuring path prefix compression and a summary footer. ```text fixtures/clike/ file1.cpp:1-88 ~ file2.cpp:1-88 fixtures/clike/ file1.cs:1-91 ~ file2.cs:1-91 fixtures/svelte/ component1.svelte:css:112-230 ~ component2.svelte:css:112-230 fixtures/markdown/ file3.md:typescript:34-64 ~ file4.md:typescript:34-64 --- 212 clones · 37.1% duplication ```