omp-plugin-duplicate-detector 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # omp-plugin-duplicate-detector
2
+
3
+ Real-time duplicate code detection for [oh-my-pi](https://github.com/oh-my-pi/oh-my-pi) (`omp`), built on [jscpd](https://github.com/kucherenko/jscpd).
4
+
5
+ The plugin indexes your repository in the background and watches the agent as it works. When newly written or edited code duplicates existing logic anywhere in the workspace, the agent is warned immediately, before the copy-paste hardens into a maintenance problem. Duplicate detection can be toggled on or off per project using `/duplicates on|off`.
6
+
7
+ Indexing and mutation checks run entirely in a background worker with a persistent on-disk cache, so sessions start instantly and the agent loop is never blocked, even in large repositories.
8
+ ## Installation
9
+
10
+ Link the plugin into your local `omp` registry:
11
+
12
+ ```bash
13
+ omp plugin link /path/to/omp-plugin-duplicate-detector
14
+ ```
15
+
16
+ Or declare it in `~/.omp/agent/config.yml` (or a project-level `.omp/config.yml`):
17
+
18
+ ```yaml
19
+ extensions:
20
+ - /path/to/omp-plugin-duplicate-detector
21
+ ```
22
+
23
+ Or load it for a single session:
24
+
25
+ ```bash
26
+ omp -e /path/to/omp-plugin-duplicate-detector
27
+ ```
28
+
29
+ On startup you'll see a short readiness note in the transcript, e.g. `Duplicate detector: Ready (1,420 Git files indexed, cached)`.
30
+
31
+ ## Usage
32
+
33
+ ### Real-time warnings
34
+
35
+ Enabled by default. Whenever the agent writes or edits a source file, the change is checked against the workspace index. If it duplicates existing code, a warning naming both locations is surfaced. How it's delivered is controlled by `reminderMode`:
36
+
37
+ - **`steer`** (default) — shows a warning card in the terminal and steers the agent to reconsider before its next step.
38
+ - **`in-band`** — appends a system reminder to the tool result instead.
39
+ - **`none`** — disables real-time warnings; the index stays warm for on-demand scans.
40
+
41
+ Previously reported duplicates are remembered per session, so iterative edits to the same file don't repeat the same warning.
42
+
43
+ ### `/duplicates` slash command
44
+
45
+ Toggle duplicate detection on or off on a per-project basis. The preference is stored persistently in `~/.cache/omp/duplicate-detector/projects.json`.
46
+
47
+ ```text
48
+ /duplicates on # enable duplicate detector for this project
49
+ /duplicates off # disable duplicate detector for this project
50
+ /duplicates status # show current status for this project
51
+ ```
52
+ ## Configuration
53
+
54
+ Plugin settings (via the extension's `settings` in your omp config):
55
+
56
+ | Setting | Default | Description |
57
+ |---|---|---|
58
+ | `minLines` | `5` | Minimum consecutive lines to report as a duplicate |
59
+ | `minTokens` | `40` | Minimum token count for a duplicate block |
60
+ | `maxLines` | `500` | Maximum line count for a duplicate block |
61
+ | `checkOnMutation` | `true` | Real-time checks on `write` / `edit` |
62
+ | `reminderMode` | `"steer"` | `"steer"`, `"in-band"`, or `"none"` |
63
+ | `ignorePatterns` | — | Glob patterns to exclude (array, or comma-separated string) |
64
+ | `ignoreTests` | `true` | Automatically ignore test files, test directories, mocks, and fixtures across languages |
65
+ | `customTestPatterns` | — | Additional glob patterns or substrings to treat as test files |
66
+ | `excludeTestPatterns` | — | Patterns to exclude from test detection (un-ignore, keeping them as production code) |
67
+ | `formatsExts` | — | Custom mapping of formats to file extensions (e.g. `{ "markdown": ["md", "mdx"] }`) |
68
+ | `maxIndexedFiles` | `10000` | Cap on files indexed during the baseline scan |
69
+
70
+ ### Project configuration
71
+
72
+ Standard `jscpd` configuration is discovered automatically — `.jscpd.json` and its `.jscpd.rc*` / `.config/` variants, or a `"jscpd"` key in `package.json`:
73
+
74
+ ```json
75
+ {
76
+ "minLines": 6,
77
+ "minTokens": 50,
78
+ "ignore": ["vendor/**", "build/**"],
79
+ "ignoreTests": true,
80
+ "customTestPatterns": ["**/custom_fixtures/**"],
81
+ "excludeTestPatterns": ["**/src/services/test-utils-in-prod.ts"],
82
+ "formatsExts": {
83
+ "yaml": ["yml", "yaml"],
84
+ "markdown": ["md", "mdx"]
85
+ }
86
+ }
87
+ ```
88
+
89
+ ## What is filtered by default
90
+
91
+ To prevent false alarms, noise from test fixtures, and unnecessary tokenization, the detector filters out non-production code, data files, and build artifacts by default:
92
+
93
+ - **Test files and directories (`ignoreTests: true`):** Test files, test suites, test doubles (mocks, stubs, fakes), fixtures, snapshots, and test runners across common languages and frameworks (e.g. Jest, Vitest, Pytest, Go, JUnit, Cargo, etc.) are skipped automatically. Use `customTestPatterns` to ignore additional paths, `excludeTestPatterns` to keep specific paths in production scope, or `ignoreTests: false` to disable test filtering entirely.
94
+ - **Non-code and data formats:** Documentation (`.md`, `.txt`), data and configuration files (`.json`, `.yaml`, `.toml`, `.csv`, `.ini`), server configs (`nginx`, `apacheconf`), diffs, logs, and standalone markup data (`.svg`, `.xml`) are excluded. To scan duplicates within specific data or doc formats, opt them in via `formatsExts`.
95
+ - **Generated code and lockfiles:** Files containing standard auto-generation header markers (such as `@generated` or `DO NOT EDIT`), generated file naming conventions (`*.generated.*`, `*.designer.cs`), lockfiles (`*.lock`, `*-lock.json`), and minified assets (`*.min.js`, `*.map`) are ignored.
96
+ - **Safety and resource limits:** Large files (>100 KiB) and files outside the Git repository are skipped to maintain minimal memory usage and fast background indexing.
97
+ ## Scope and performance
98
+
99
+ - Only Git-tracked files are indexed (`git ls-files`); outside a Git repository, baseline scanning is skipped.
100
+ - Hard caps on file size, file count, and total indexed bytes prevent runaway memory use in large monorepos.
101
+ - Tokenized files are cached on disk per workspace with size-bounded eviction, so repeat sessions skip re-tokenization entirely.
102
+
103
+ ## Development
104
+
105
+ Requires [Bun](https://bun.sh) and Git.
106
+
107
+ ```bash
108
+ bun install # dependencies
109
+ bun test # test suite
110
+ bun run typecheck # TypeScript
111
+ bun run check # lint (Biome)
112
+ bun run build:worker # rebuild dist/detector-worker.js after worker-side changes
113
+ ```
114
+
115
+ ## License
116
+
117
+ MIT — [Oh My Pi Contributors](https://github.com/oh-my-pi)