mach10 icon indicating copy to clipboard operation
mach10 copied to clipboard

Add duplicate-issue detection before creating deferred-finding issues

Open LeanAndMean opened this issue 8 months ago • 5 comments

Summary

When deferred findings from a PR review are turned into GitHub issues, there is no check for pre-existing issues covering the same topic. This can produce duplicate issues, especially when the same codebase concern surfaces across multiple review cycles.

Current Behavior

  • pr-review (Step 8) creates issues for deferred findings directly via gh issue create with no duplicate check.
  • pr-review-validate (Step 6) recommends /mach10:issue-create for deferred items, and issue-create itself also performs no duplicate check before drafting.

In both paths, if an open (or recently closed) issue already covers the same concern, a duplicate is silently created.

Proposed Behavior

Before creating an issue for a deferred finding, search existing issues for potential duplicates:

gh issue list --search "<keywords>" --state all --json number,title,state,url

If likely duplicates are found, present them to the user with options:

  • Proceed -- create the new issue anyway
  • Link -- add a comment to the existing issue referencing the new finding/PR instead
  • Skip -- do not create an issue for this finding

Acceptance Criteria

  • pr-review Step 8 checks for existing issues before creating each deferred-finding issue
  • issue-create checks for existing issues between drafting and user approval (Step 2 and Step 3)
  • When potential duplicates are found, the user is shown issue number, title, and state, and can choose to proceed, link, or skip
  • The check is advisory -- the user can always override and create the issue

Technical Notes

  • Relevant files: commands/pr-review.md (Step 8), commands/issue-create.md (between Steps 2-3)
  • Use gh issue list --search "..." --state all --json number,title,state,url for keyword-based search
  • Extract 2-3 key terms from the proposed issue title as search keywords
  • pr-review-validate delegates to issue-create, so fixing issue-create covers that path

LeanAndMean avatar Mar 31 '26 16:03 LeanAndMean

Independent Assessment

Current State

Two code paths create issues without duplicate checks:

  • pr-review Step 8: Creates issues inline for deferred findings via gh issue create -- no search beforehand.
  • issue-create: 5-step workflow (gather, draft, review, create, confirm) -- no duplicate check between drafting (Step 2) and approval (Step 3).
  • pr-review-validate Step 6 delegates to issue-create, so fixing that command covers this path automatically.

gh issue list --search is not used anywhere in the codebase today.

Observations

  • Well-scoped: Two files to modify (commands/issue-create.md, commands/pr-review.md), no new files or sync points.
  • Established patterns: The AskUserQuestion interaction for presenting discovered items and letting the user choose (Proceed/Link/Skip) follows the same structure as branch selection in issue-implement.
  • Batch UX consideration: In pr-review Step 8, multiple deferred items could each trigger a duplicate check, creating sequential prompts. Consider batching: run all searches upfront, then present a summary of which items have potential duplicates before creating any issues.
  • Search noise: --state all may surface old closed issues. A --limit 5 cap (as noted in Technical Notes) keeps the list manageable; the advisory nature ensures no harm from false matches.
  • "Link" action: The comment posted to an existing issue should reference both the PR and the specific finding, following the existing pattern of cross-referencing between PRs and issues.

Scope Estimate

Small -- roughly 15-20 lines of new instruction in each of the two command files. No architectural changes, no new sync points to track.

LeanAndMean avatar Mar 31 '26 19:03 LeanAndMean

Implementation Plan: Duplicate Issue Detection

Overview

Add duplicate-issue detection before creating GitHub issues in two code paths: issue-create (interactive) and pr-review Step 8 (deferred findings). The approach uses inline instructions in each command file with no new agents or files -- lightweight, minimal, and trusting Claude's judgment.

Stage 1: Add duplicate detection to issue-create.md

What it accomplishes: Prevents duplicate issue creation in the primary issue-creation workflow by searching for existing issues after the user approves the draft but before creation.

Files modified:

  • commands/issue-create.md

Changes:

  • Insert a new Step 4 (Check for Duplicates) between the current Step 3 (Review) and Step 4 (Create)
  • The new step searches with gh issue list --search "<keywords>" --state all --json number,title,state,url
  • Judgment-based handling: proceed silently if no match; act autonomously if clearly a duplicate (comment on/edit existing issue); prompt user via AskUserQuestion only when ambiguous
  • Renumber existing Step 4 (Create) to Step 5, Step 5 (Confirm) to Step 6

Dependencies: None

Stage 2: Add duplicate detection to pr-review.md Step 8

What it accomplishes: Prevents duplicate issue creation when deferred review findings are turned into GitHub issues.

Files modified:

  • commands/pr-review.md

Changes:

  • Add per-item duplicate detection before each gh issue create call in the deferred-items loop
  • Claude searches for existing issues, judges similarity, and handles duplicates autonomously (no additional user confirmation loop -- Claude has sufficient context from the review)
  • Reports actions taken (skipped duplicates, linked to existing issues) in CLI output

Dependencies: None (independent of Stage 1)

Stage 3: Convention note and version bump

What it accomplishes: Documents the duplicate-detection convention for future issue-creation code paths and bumps the plugin version.

Files modified:

  • CLAUDE.md (add "Duplicate issue detection" bullet to Writing Commands sync conventions)
  • .claude-plugin/plugin.json (version bump)

Dependencies: Stages 1 and 2 (convention note references both implementation sites)


This comment will guide staged implementation via /mach10:issue-implement.

LeanAndMean avatar Mar 31 '26 20:03 LeanAndMean

Stage 1 Progress: Duplicate detection in issue-create

Commit: 395ae0f — Add duplicate-issue detection to issue-create command

Changes

  • Inserted new Step 4: Check for Duplicates in commands/issue-create.md between Review (Step 3) and Create (now Step 5)
  • Three-tier handling: no matches (proceed silently), clear duplicates (link autonomously via gh issue comment), ambiguous matches (prompt user with Proceed/Link/Skip via AskUserQuestion)
  • Closed issues are flagged prominently when presenting ambiguous matches
  • Renumbered existing Steps 4-5 to Steps 5-6

Notes

  • Follows established AskUserQuestion patterns from CLAUDE.md conventions
  • Explicit gh issue comment syntax provided for both autonomous and user-directed linking paths
  • No model field added to frontmatter — left as pre-existing design choice since the command doesn't require deep reasoning at the level of reviews/planning

LeanAndMean avatar Mar 31 '26 20:03 LeanAndMean

Stage 2 Progress: Duplicate detection in pr-review Step 8

Commit: a6d09e0 — Add duplicate-issue detection to pr-review deferred items

Changes

  • Added per-item duplicate detection to commands/pr-review.md Step 8 before each gh issue create call
  • Keyword-based search via gh issue list --search with --state all --limit 5
  • Three-path handling: no results (proceed), clear open duplicate (skip and link via gh issue comment), ambiguous match (create with "Potentially related" note)
  • Link comments use PR-enriched format: "Related finding from PR #N review: "
  • Closed-issue guard: near-identical closed issues treated as ambiguous (do not block creation)
  • End-of-step summary block reports all outcomes: Created, Skipped (duplicate), Created (with overlap note), Skipped (not selected)

Notes

  • Fully autonomous — no user prompts during duplicate detection (Claude judges from review context)
  • Follows the same gh issue list --search pattern established in stage 1 (issue-create.md)
  • Independent of stage 1 as planned

LeanAndMean avatar Mar 31 '26 22:03 LeanAndMean

Stage 3 Progress: Convention note and version bump

Commit: a746ce3 — Add duplicate-detection sync convention and bump version to 1.3.0

Changes

  • Added Duplicate-issue detection sync convention bullet to CLAUDE.md (Writing Commands section), documenting that the search pattern (gh issue list --search) and keyword-extraction approach are duplicated between commands/issue-create.md (Step 4) and commands/pr-review.md (Step 8)
  • Bumped plugin version from 1.2.1 to 1.3.0 in .claude-plugin/plugin.json

Notes

  • Follows the established sync convention format (bold name, duplication sites, "any change must be applied to both locations")
  • Minor version bump chosen since duplicate-issue detection is new functionality spanning all three stages
  • All three stages of the implementation plan are now complete

LeanAndMean avatar Apr 01 '26 13:04 LeanAndMean