[NEW PRIMITIVE] Duplicated code detection prompts + codeql_lsp_document_symbols tool#122
Closed
Copilot wants to merge 8 commits intomichaelrfairhurst/duplicated-code-searchesfrom
Closed
[NEW PRIMITIVE] Duplicated code detection prompts + codeql_lsp_document_symbols tool#122Copilot wants to merge 8 commits intomichaelrfairhurst/duplicated-code-searchesfrom
Copilot wants to merge 8 commits intomichaelrfairhurst/duplicated-code-searchesfrom
Conversation
…ff-PATH by VS Code extension (#91) * auto-discover vscode-codeql managed CodeQL CLI dist The MCP server now automatically finds the CodeQL CLI binary installed by the GitHub.vscode-codeql extension, which stores it off-PATH at: <globalStorage>/github.vscode-codeql/distribution<N>/codeql/codeql Discovery uses distribution.json (folderIndex hint) with a fallback to scanning distribution* directories sorted by descending index. This is implemented at two layers: - VS Code extension CliResolver (Strategy 3, between PATH and known locations) — uses the StoragePaths-provided storage directory - Server-side cli-executor (fallback when CODEQL_PATH is unset) — probes platform-specific VS Code global storage directories for Code, Code - Insiders, and VSCodium Also fixes extension.test.ts constructor mocks for Vitest 4.x compatibility (vi.clearAllMocks instead of vi.resetAllMocks). T_EDITOR=true git rebase --continue * Implement changes for PR review comments * Fix deterministic vscode-codeql discovery tests and dual-casing path probe in CliResolver (#92) * Add getResolvedCodeQLDir() caching test assertion * auto-discover vscode-codeql managed CodeQL CLI dist The MCP server now automatically finds the CodeQL CLI binary installed by the GitHub.vscode-codeql extension, which stores it off-PATH at: <globalStorage>/github.vscode-codeql/distribution<N>/codeql/codeql Discovery uses distribution.json (folderIndex hint) with a fallback to scanning distribution* directories sorted by descending index. This is implemented at two layers: - VS Code extension CliResolver (Strategy 3, between PATH and known locations) — uses the StoragePaths-provided storage directory - Server-side cli-executor (fallback when CODEQL_PATH is unset) — probes platform-specific VS Code global storage directories for Code, Code - Insiders, and VSCodium Also fixes extension.test.ts constructor mocks for Vitest 4.x compatibility (vi.clearAllMocks instead of vi.resetAllMocks). T_EDITOR=true git rebase --continue * Implement changes for PR review comments * Fix deterministic vscode-codeql discovery tests and dual-casing path probe in CliResolver (#92) * Add getResolvedCodeQLDir() caching test assertion * Sync server/dist/** * Addres PR review comments * Address latest PR review feedback * Sync package-lock.json and server/dist/** * Address latest PR review comments * Sync package-lock.json & server/dist/ * Fix regex for CodeQL CLI dist discovery --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
…#114) * Upgrade codeql and pack deps to version 2.24.3 * Upgarde NodeJS dependencies to latest * Sync server/dist/**
* Initial plan * Fix CODEQL_PATH Tests (windows-latest): robust binary search and skip MSYS2 FIFOs Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Set ENABLE_MONITORING_TOOLS=false for client test:integration --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Co-authored-by: Nathan Randall <data-douser@github.com>
…ented guides (#113) * Initial plan * Rewrite static MCP resources with actionable LLM-oriented content, rename URIs, add new resources - Rewrite getting-started.md as MCP server orientation guide (codeql://server/overview) - Rewrite query-basics.md as practical query writing reference (codeql://server/queries) - Rewrite security-templates.md with multi-language templates and TDD workflow - Rewrite performance-patterns.md with profiling tool focus - Create server-prompts.md (codeql://server/prompts) with complete prompt reference - Create server-tools.md (codeql://server/tools) with complete default tool reference - Rewrite ql-test-driven-development.md as TDD theory overview with cross-links - Register ql-test-driven-development.md as MCP resource (codeql://learning/test-driven-development) - Update resources.ts with new imports and getters - Update codeql-resources.ts with new URIs and 7 resource registrations - Update resources.test.ts with tests for new resources - Update docs/ql-mcp/resources.md and server/README.md Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Fix tool name inconsistency: use codeql_generate_log-summary (with hyphen) Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Migrate language-specific MCP resources Address review feedback: rename files to match endpoint paths, split query-basics into learning and server resources, update docs to point to authoritative sources - Rename getting-started.md → server-overview.md to match codeql://server/overview - Rename query-basics.md → learning-query-basics.md for codeql://learning/query-basics - Create server-queries.md for codeql://server/queries (PrintAST, PrintCFG, CallGraphFrom, CallGraphTo overview) - Update docs/ql-mcp/tools.md to point to server-tools.md as authoritative source - Update docs/ql-mcp/prompts.md to point to server-prompts.md as authoritative source - Update resources.ts, codeql-resources.ts, tests, cross-references, and docs for 8 total resources Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Address latest PR review comments * Update docs to fix/remove tool counts * Remove qlt refs, broken cli links, fix deprecated API names, fix import order, fix java_ast and README - Remove qlt and broken ../resources/cli/ links from javascript, csharp, python security guides - Replace CLI References sections with MCP tool name references - Fix isAdditionalTaintStep → isAdditionalFlowStep in csharp guide (v2 API) - Fix alphabetical import order in resources.ts - Fix incomplete Example AST Hierarchy in java_ast.md with actual hierarchy - Remove ql from README language AST references list Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Cleanup language-specific security query guides * Migrate .github/skills/** as MCP server resources (#116) This commit migrates the ".github/skills/**" content for agent skills that are not specific to this repository. Converts, consolidates, and migrates such skills as refactored MCP server resources. * Address latest PR review comments --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Co-authored-by: Nathan Randall <data-douser@github.com>
Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add tools for duplicated code detection prompts
[NEW PRIMITIVE] Duplicated code detection prompts + codeql_lsp_document_symbols tool
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds workflow prompts and supporting tooling to detect duplicated CodeQL definitions and find overlapping queries/libraries. Fixes a TypeScript type error in
extractNamesFromDocumentSymbols, rebases ontomain, and resolvesserver/dist/**conflicts via rebuild.📝 Primitive Information
Primitive Details
codeql_lsp_document_symbols,check_for_duplicated_code,find_overlapping_queriesThis PR is for creating a new MCP server primitive and must ONLY include these file types:
✅ ALLOWED FILES:
server/src/**/*.ts)server/src/tools/*.ts)server/test/**/*.ts)README.md, server docs)server/src/types/*.ts)server/src/lib/*.ts)package.json,tsconfig.json)🚫 FORBIDDEN FILES:
Rationale: This PR should contain only the files necessary to implement and test the new primitive.
🚨 PRs that include forbidden files will be rejected and must be revised.
🛑 MANDATORY PR VALIDATION CHECKLIST
BEFORE SUBMITTING THIS PR, CONFIRM:
Primitive Metadata
codeql_lsp_document_symbols) + Prompts (check_for_duplicated_code,find_overlapping_queries)lspFileParamsSchema+names_only: boolean{ symbolCount: number, symbols: string[] | DocumentSymbol[] | SymbolInformation[] }🎯 Functionality Description
What This Primitive Does
codeql_lsp_document_symbols: Enumerates all top-level definitions (predicates, classes, imports) in a QL file via LSPtextDocument/documentSymbols. Passnames_only: truefor a flat name list suitable for diff/overlap checks.check_for_duplicated_codeprompt: Guides an agent to enumerate symbols from two QL files and compare them usingfind_predicate_position/find_class_positionto identify identical, equivalent, or overlapping definitions.find_overlapping_queriesprompt: Broader workflow to scan a set of query files and surface redundant or subsumable queries.codeql_resolve_packs: CLI wrapper forcodeql resolve packs— resolves pack locations without needing an input.qlfile (complements the existingcodeql_resolve_library_path).codeql_resolve_library_path: Corrects argument handling to use--queryflag.Use Cases
An AI assistant comparing two query packs for duplication:
codeql_lsp_document_symbolswithnames_only: trueon each file to get symbol name lists.find_predicate_position/find_class_positionto retrieve full definitions and compare bodies.Example Usage
Example Input/Output
🧪 Implementation Details
Files Added/Modified
server/src/tools/lsp/lsp-handlers.ts—lspDocumentSymbols,extractNamesFromDocumentSymbolsserver/src/tools/codeql/resolve-packs.tsserver/src/tools/lsp/lsp-tools.ts,server/src/tools/codeql-tools.ts,server/src/tools/codeql/index.tsserver/src/tools/codeql/resolve-library-path.ts— corrected--queryargumentserver/src/prompts/check-for-duplicated-code.prompt.md,server/src/prompts/find-overlapping-queries.prompt.mdserver/src/prompts/workflow-prompts.ts,server/src/prompts/prompt-loader.tsserver/test/src/tools/lsp/lsp-tools.test.ts,server/test/src/tools/codeql-tools.test.tsArchitecture Integration
extractNamesFromDocumentSymbolsDesign Patterns
Key Fix: TypeScript Type Error
collectSymbolNamesexpected(DocumentSymbol | SymbolInformation)[]but was called withDocumentSymbol[] | SymbolInformation[]— a union of arrays, not an array of the union:📋 Testing Coverage
Unit Tests
Test Scenarios
codeql_lsp_document_symbolsreturns symbol listnames_only: truereturns flat string array viaextractNamesFromDocumentSymbolsisErrorresponseTest Files
server/test/src/tools/lsp/lsp-tools.test.ts— updated mock + count (3→4)server/test/src/tools/codeql-tools.test.ts— updated count (35→36)🔗 References
Related Implementation
lspCompletion,lspDefinition,lspReferencescodeql_resolve_packsmirrorscodeql_resolve_library_pathExternal References
textDocument/documentSymbolrequestcodeql resolve packsserver/src/tools/lsp/lsp-handlers.tsValidation Materials
server/ql/*/examples/DocumentSymboltrees; flat forSymbolInformation🚀 Server Integration
Registration Details
Compatibility
Performance Considerations
🔍 Quality Assurance
Code Quality
Validation Testing
Security Considerations
👥 Review Guidelines
For Reviewers
Please verify:
Testing Instructions
Manual Validation Steps
codeql_lsp_document_symbols: Call against a QL file with and withoutnames_onlycheck_for_duplicated_codeandfind_overlapping_queriescodeql_resolve_packs: Confirm pack resolution without a.qlfile📊 Impact Analysis
Server Impact
AI Assistant Benefits
find_predicate_position/find_class_positionreferences corrected in promptsMonitoring & Reporting Integration
Maintenance Considerations
🔄 Deployment Considerations
Rollout Strategy
Migration Notes
No migration steps required. The
codeql_resolve_library_path--queryargument fix is a corrective change with no breaking impact.Implementation Methodology: This primitive follows best practices:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.