Skip to content

Commit 9e5cc43

Browse files
authored
Merge pull request #27 from Hypercart-Dev-Tools/rules/add-logic-clone-detection-fuzzy
Rules/add logic clone detection fuzzy to Development
2 parents d9afee9 + d4f3eb3 commit 9e5cc43

16 files changed

Lines changed: 2705 additions & 30 deletions

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,51 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.79] - 2026-01-02
9+
10+
### Fixed
11+
- **HTML Report Generation** - Fixed `url_encode: command not found` error
12+
- Changed `url_encode()` to `url_encode_path()` on line 859
13+
- Function was removed in v1.0.77 but one call site was missed
14+
- Now uses correct function from `common-helpers.sh`
15+
- **Impact:** HTML reports now generate without errors
16+
17+
## [1.0.78] - 2026-01-02
18+
19+
### Added
20+
- **Function Clone Detector (Tier 1)** - Hash-based detection of duplicate function definitions across files
21+
- New pattern: `dist/patterns/duplicate-functions.json` - Detects exact function clones (Type 1)
22+
- New function: `process_clone_detection()` - Extracts functions, normalizes code, computes MD5 hashes
23+
- Thresholds: min 5 lines, min 2 files, min 2 occurrences
24+
- Normalization: Strips comments and whitespace before hashing
25+
- **Impact:** Catches copy-paste violations where identical functions exist in multiple files
26+
- **Coverage:** 60-70% of all clones (Type 1 exact copies only)
27+
- **False Positive Rate:** < 5% (proven hash-based approach)
28+
29+
- **Test Fixtures for Clone Detection**
30+
- `dist/tests/fixtures/dry/duplicate-functions.php` - Single-file fixture with documented test cases
31+
- `dist/tests/fixtures/dry/file-a.php` - Multi-file test (includes/user-validation.php)
32+
- `dist/tests/fixtures/dry/file-b.php` - Multi-file test (admin/settings.php)
33+
- `dist/tests/fixtures/dry/file-c.php` - Multi-file test (ajax/handlers.php)
34+
- Expected violations: `validate_user_email` (3 files), `sanitize_api_key` (2 files)
35+
36+
### Changed
37+
- **HTML Report Template** - Updated "Magic Strings" section to "DRY Violations"
38+
- Now includes both magic strings and duplicate functions
39+
- Added subtitle: "Includes magic strings and duplicate functions"
40+
- Stat card label changed from "Magic Strings" to "DRY Violations"
41+
42+
- **Scanner Output** - Added new section "FUNCTION CLONE DETECTOR"
43+
- Displays after "MAGIC STRING DETECTOR" section
44+
- Shows count of duplicate functions found
45+
- Uses same violation reporting format as magic strings
46+
47+
### Improved
48+
- **File Path Handling** - Enhanced `process_clone_detection()` to handle both files and directories
49+
- Detects if `$PATHS` is a single file or directory
50+
- Uses `safe_file_iterator()` for paths with spaces
51+
- Excludes vendor/, node_modules/ directories
52+
853
## [1.0.77] - 2026-01-02
954

1055
### Added

PROJECT/1-INBOX/PROJECT-LOGIC-DUPLICATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ detect_exact_function_clones() {
349349
**Method:** Replace identifiers with placeholders, hash
350350
**Threshold:** Minimum 10 lines, 70%+ similarity
351351
**Expected False Positive Rate:** 10-20%
352+
**Status**: Deferred as of Jan. 2, 2026 - wait for feedback
352353

353354
```bash
354355
detect_normalized_clones() {
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
# PROJECT Inbox Triage – 2026-01-02
2+
3+
**Created:** 2026-01-02
4+
**Status:** In Progress
5+
**Purpose:** Summarize recommended actions for each `PROJECT/1-INBOX` document so the maintainer can review and decide, one by one.
6+
7+
---
8+
9+
## 1. CONSOLIDATION-COMPLETE.md
10+
11+
**File:** `PROJECT/1-INBOX/CONSOLIDATION-COMPLETE.md`
12+
**Type:** Update log for logic-duplication spec
13+
14+
### Observation
15+
- States that `LOGIC-DUPLICATION-UPDATES.md` has been merged into `PROJECT-LOGIC-DUPLICATION.md`.
16+
- Status inside file already says consolidation is **complete**.
17+
- `LOGIC-DUPLICATION-UPDATES.md` currently lives in `PROJECT/3-COMPLETED/` (summary of changes).
18+
19+
### Recommended Changes
20+
- Treat as a **completed documentation update**, not an active task.
21+
- Add/confirm frontmatter:
22+
- `Status: Completed`
23+
- `Completed: 2026-01-01` (or actual date)
24+
- **Move:** `CONSOLIDATION-COMPLETE.md``PROJECT/3-COMPLETED/`.
25+
26+
### Questions for You
27+
1. Do you want to keep this as a separate “update log” file, or fold its contents into the bottom of `PROJECT-LOGIC-DUPLICATION.md` under a "Document History" section and then archive/delete it?
28+
29+
---
30+
31+
## 2. DRY-POC-SUMMARY.md
32+
33+
**File:** `PROJECT/1-INBOX/DRY-POC-SUMMARY.md`
34+
**Type:** Proof-of-concept summary for Magic String Detector (DRY)
35+
36+
### Observation
37+
- Status line: `Planning Complete – Ready for Implementation`.
38+
- Describes:
39+
- Planning doc: `NEXT-FIND-DRY.md`.
40+
- 3 DRY JSON patterns under `dist/patterns/dry/`.
41+
- `dist/patterns/dry/README.md` for documentation.
42+
- Lists remaining work: fixtures + aggregation wiring.
43+
- Codebase already contains DRY patterns/docs; there are also fixture-related reports in `PROJECT/3-COMPLETED/`.
44+
45+
### Recommended Changes
46+
- Treat this as a **completed POC planning+design summary**, not an active task.
47+
- Update status block to:
48+
- `Status: Completed`
49+
- Add a small **“Implementation Outcome”** subsection linking to:
50+
- `dist/patterns/dry/` JSONs
51+
- `dist/patterns/dry/README.md`
52+
- Any relevant `TEST_FIXTURES_*` docs if they cover DRY
53+
- **Move:** `DRY-POC-SUMMARY.md``PROJECT/3-COMPLETED/`.
54+
55+
### Questions for You
56+
1. Is Phase 1 DRY (3 patterns + fixtures + aggregation) effectively shipped, or are fixtures/aggregation still partially TODO?
57+
2. Should we add a short "Shipped In" version tag here (e.g., `Shipped In: v1.0.xx`)?
58+
59+
---
60+
61+
## 3. FIND-DRY.md
62+
63+
**File:** `PROJECT/1-INBOX/FIND-DRY.md`
64+
**Type:** Generic DRY + architecture checker specification (repo-agnostic)
65+
66+
### Observation
67+
- Large, general spec for a grep-first DRY/architecture checker.
68+
- Not specific to wp-code-check; more of a background design document.
69+
- You now have wp-code-check–specific DRY plan in `NEXT-FIND-DRY.md` and POC summary in `DRY-POC-SUMMARY.md`.
70+
71+
### Recommended Changes
72+
- Reclassify as **reference/spec**, not an INBOX task.
73+
- Add a short header note:
74+
- `Status: Reference`
75+
- `Note: Background spec informing NEXT-FIND-DRY.md and DRY implementation.`
76+
- **Move:** `FIND-DRY.md``PROJECT/FIND-DRY.md` (root-level reference).
77+
78+
### Questions for You
79+
1. Do you still actively iterate on this generic spec, or is it stable reference now?
80+
2. Do you want this re-titled to something like `PROJECT-DRY-ARCH-SPEC.md`, or keep the existing filename for now?
81+
82+
---
83+
84+
## 4. GITHUB-ADD-ISSUE.md
85+
86+
**File:** `PROJECT/1-INBOX/GITHUB-ADD-ISSUE.md`
87+
**Type:** Raw research note / web-scraped style answer
88+
89+
### Observation
90+
- Describes third-party browser extensions for quickly creating GitHub issues.
91+
- No task framing (no status, acceptance criteria, or link to wp-code-check roadmap).
92+
- Looks more like an ad-hoc research answer than a concrete project task.
93+
94+
### Recommended Changes
95+
Two options depending on whether you care about this item:
96+
97+
**Option A – Archive as Cancelled**
98+
- Add frontmatter:
99+
- `Status: Cancelled`
100+
- `Cancelled Reason: Out of scope for wp-code-check core roadmap (developer tooling only).`
101+
- **Move:** `GITHUB-ADD-ISSUE.md``PROJECT/3-COMPLETED/` as an archived research note.
102+
103+
**Option B – Keep as Deferred Idea**
104+
- Add frontmatter:
105+
- `Status: Deferred`
106+
- `Deferred Until: After v1.x baseline + DRY work`
107+
- `Deferred Reason: Nice-to-have productivity tool, not core functionality.`
108+
- Keep in `1-INBOX/` but clearly marked as deferred.
109+
110+
### Questions for You
111+
1. Is "quick GitHub issue creation" something you realistically want to pursue as part of this repo, or should we mark it Cancelled and archive it?
112+
113+
---
114+
115+
## 5. NEW-PATTERN-OPPORTUNITIES.md
116+
117+
**File:** `PROJECT/1-INBOX/NEW-PATTERN-OPPORTUNITIES.md`
118+
**Type:** Pattern ideas from Woo All Products for Subscriptions audit
119+
120+
### Observation
121+
- Lists 8+ pattern ideas with details (severity, rule IDs, proposed grep expressions).
122+
- Some entries already marked as COMPLETE or ENHANCED (e.g., unsanitized `$_GET`, admin capability checks).
123+
- Mix of:
124+
- Implemented patterns
125+
- Pending ideas
126+
- Future possibilities
127+
128+
### Recommended Changes
129+
- Convert into a **pattern backlog / idea bank**, not an INBOX task.
130+
- Add a top-level **Status Summary** section grouping patterns into:
131+
- Implemented (with version numbers)
132+
- Pending / To Evaluate
133+
- Rejected / Low ROI
134+
- Add frontmatter:
135+
- `Status: Reference`
136+
- `Purpose: Backlog of potential detection rules derived from IRL audits.`
137+
- **Move:** `NEW-PATTERN-OPPORTUNITIES.md``PROJECT/NEW-PATTERN-OPPORTUNITIES.md` (root-level reference).
138+
139+
### Questions for You
140+
1. Do you want to keep treating this as a living idea bank, updated as patterns ship, or should we snapshot it and spin off a smaller "NEXT-PATTERNS" task doc for near-term work?
141+
142+
---
143+
144+
## 6. NEXT-BASELINE-ISSUE.md
145+
146+
**File:** `PROJECT/1-INBOX/NEXT-BASELINE-ISSUE.md`
147+
**Type:** Support-style explanation of baseline behavior for a specific plugin
148+
149+
### Observation
150+
- Reads like a conversation transcript explaining baseline behavior (69 baselined findings, 0 new).
151+
- Clarifies that behavior is correct but UX could be clearer.
152+
- Not structured as a spec (no acceptance criteria or implementation plan).
153+
154+
### Recommended Changes
155+
If you want to preserve it:
156+
- Add frontmatter:
157+
- `Status: Completed`
158+
- `Type: Support Explanation / UX Note`
159+
- Add short summary section:
160+
- "Key UX Observations & Potential Improvements" (2–3 bullets).
161+
- **Move:** `NEXT-BASELINE-ISSUE.md``PROJECT/3-COMPLETED/`.
162+
163+
If you don't need it:
164+
- Mark `Status: Cancelled` and archive in `3-COMPLETED/` (or delete).
165+
166+
### Questions for You
167+
1. Would you like this turned into a more formal "Baseline UX / FAQ" entry under `PROJECT/` (e.g., `BASELINE-BEHAVIOR-FAQ.md`), or is the existing explanation enough and can be archived as-is?
168+
169+
---
170+
171+
## 7. NEXT-CALIBRATION.md
172+
173+
**File:** `PROJECT/1-INBOX/NEXT-CALIBRATION.md`
174+
**Type:** Calibration plan (false-positive reduction roadmap)
175+
176+
### Observation
177+
- Status: `In Progress` (already in the file).
178+
- Phase 1 priorities 1–3.5 marked as COMPLETED.
179+
- Phase 2 / 3 tasks still open.
180+
- Multiple COMPLETED docs in `3-COMPLETED/` directly relate (fixtures eval, severity overrides, test fixtures reports).
181+
182+
### Recommended Changes
183+
- This is an **active working document**.
184+
- Keep as the primary calibration tracker.
185+
- Update/confirm metadata:
186+
- `Status: In Progress`
187+
- Possibly `Assigned Version:` if you want a target.
188+
- **Move:** `NEXT-CALIBRATION.md``PROJECT/2-WORKING/NEXT-CALIBRATION.md`.
189+
190+
### Questions for You
191+
1. Do you want to split out finished Phase 1 into a separate `CALIBRATION-PHASE-1-COMPLETED.md` summary, leaving this file only for future work (Phase 2/3)?
192+
193+
---
194+
195+
## 8. NEXT-FIND-DRY.md
196+
197+
**File:** `PROJECT/1-INBOX/NEXT-FIND-DRY.md`
198+
**Type:** WP Code Check–specific DRY implementation plan
199+
200+
### Observation
201+
- Status: `Planning`.
202+
- Concrete 3-phase plan reusing existing pattern infrastructure.
203+
- `DRY-POC-SUMMARY.md` shows Phase 1 planning and pattern creation are done.
204+
205+
### Recommended Changes
206+
- Treat this as a **completed planning spec** backing the DRY POC.
207+
- Add metadata:
208+
- `Status: Completed (Phase 1 Planning)`
209+
- Optional: `Linked Summary: DRY-POC-SUMMARY.md`
210+
- **Move:** `NEXT-FIND-DRY.md``PROJECT/NEXT-FIND-DRY.md` (root-level reference for DRY work).
211+
212+
### Questions for You
213+
1. Do you want to keep Phases 2–3 in this same file, or spin them into a new `NEXT-DRY-EXPANSION.md` so this doc reflects "what we planned for Phase 1" only?
214+
215+
---
216+
217+
## 9. PROJECT-LOGIC-DUPLICATION.md
218+
219+
**File:** `PROJECT/1-INBOX/PROJECT-LOGIC-DUPLICATION.md`
220+
**Type:** Canonical spec for logic clone detection (grep+aggregation)
221+
222+
### Observation
223+
- `LOGIC-DUPLICATION-UPDATES.md` (already in `3-COMPLETED/`) claims this doc has been updated with:
224+
- Real-world context
225+
- Adjusted timelines
226+
- Go/No-Go criteria
227+
- JSON schema example
228+
- Lessons learned from v1.0.73
229+
- Integration checklist & WP-specific patterns
230+
- Implementation itself (duplicate-functions pattern, fixtures, wiring) is **not yet obviously present** from the high-level repo listing.
231+
232+
### Recommended Changes
233+
Two paths, depending on your intent:
234+
235+
**Option A – Treat as Ready-to-Start Implementation**
236+
- Add frontmatter:
237+
- `Status: Not Started`
238+
- `Priority: HIGH`
239+
- Keep in `1-INBOX/` for now as "next candidate big feature".
240+
- Add a small "Next Actions" list pointing to the concrete files from the integration checklist.
241+
242+
**Option B – Move to Active Work**
243+
- If you intend to start implementation soon:
244+
- Set `Status: In Progress`.
245+
- **Move:** `PROJECT-LOGIC-DUPLICATION.md``PROJECT/2-WORKING/`.
246+
247+
### Questions for You
248+
1. Is logic-clone detection something you want to start in the current milestone (then we move it to `2-WORKING`), or should it remain a high-priority backlog item in `1-INBOX`?
249+
250+
---
251+
252+
## 10. LOGIC-DUPLICATION-UPDATES.md (Context Check)
253+
254+
**File:** `PROJECT/3-COMPLETED/LOGIC-DUPLICATION-UPDATES.md`
255+
**Type:** Summary of updates applied to `PROJECT-LOGIC-DUPLICATION.md`
256+
257+
### Observation
258+
- Already in `3-COMPLETED/`.
259+
- Describes how the feasibility study was updated to align with proven v1.0.73 architecture.
260+
261+
### Recommended Changes
262+
- No folder move needed (already COMPLETED).
263+
- Optional: Add at top:
264+
- `Status: Completed`
265+
- `Linked Spec: PROJECT-LOGIC-DUPLICATION.md`.
266+
267+
### Questions for You
268+
1. Do you want `CONSOLIDATION-COMPLETE.md` and `LOGIC-DUPLICATION-UPDATES.md` eventually merged into a single "Document History" section inside `PROJECT-LOGIC-DUPLICATION.md`?
269+
270+
---
271+
272+
## Next Steps Checklist (For You)
273+
274+
You can now go through each item and decide:
275+
276+
- [ ] **CONSOLIDATION-COMPLETE.md** – Archive to COMPLETED? Merge into spec?
277+
- [ ] **DRY-POC-SUMMARY.md** – Mark Completed + move to COMPLETED?
278+
- [ ] **FIND-DRY.md** – Move to PROJECT root as reference?
279+
- [ ] **GITHUB-ADD-ISSUE.md** – Cancel & archive, or defer?
280+
- [ ] **NEW-PATTERN-OPPORTUNITIES.md** – Convert to pattern backlog and move to PROJECT root?
281+
- [ ] **NEXT-BASELINE-ISSUE.md** – Archive as support note or convert to FAQ?
282+
- [ ] **NEXT-CALIBRATION.md** – Move to 2-WORKING as active calibration driver?
283+
- [ ] **NEXT-FIND-DRY.md** – Mark Phase 1 planning completed and move to PROJECT root?
284+
- [ ] **PROJECT-LOGIC-DUPLICATION.md** – Keep as backlog or promote to 2-WORKING?
285+
286+
If you confirm your decisions on each bullet, I can apply the moves, add the frontmatter changes, and keep everything consistent with the `AGENTS.md` workflow rules.

0 commit comments

Comments
 (0)