Skip to content

[UPDATE PRIMITIVE] Resolve workflow-prompt query/pack paths across all workspace folders + include/exclude settings#307

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-mcp-workflow-prompts
Closed

[UPDATE PRIMITIVE] Resolve workflow-prompt query/pack paths across all workspace folders + include/exclude settings#307
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-mcp-workflow-prompts

Conversation

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

In a multi-root VS Code workspace, the MCP workflow prompts (slash commands) only surfaced and resolved CodeQL queries/packs in the first workspace folder (index 0). This makes the prompt completion providers scan every workspace root and adds two extension settings for explicit, ordering-independent control over resolution roots.

📝 Update Information

Primitive Details

  • Type: Prompt (argument completion providers)
  • Name: prompt-completionscompleteQueryPath, completeSarifPath, completeDatabasePath, completePackRoot
  • Update Category: Bug Fix (multi-root resolution) + Feature Enhancement (include/exclude settings)

⚠️ CRITICAL: PR SCOPE VALIDATION

This PR is for updating an existing MCP server primitive and must ONLY include these file types:

ALLOWED FILES:

  • Server implementation files (server/src/**/*.ts)
  • Updated primitive implementations
  • Modified registration files (server/src/tools/*.ts)
  • Updated or new test files (server/test/**/*.ts)
  • Documentation updates (README.md, server docs)
  • Updated type definitions (server/src/types/*.ts)
  • Modified supporting library files (server/src/lib/*.ts)
  • Configuration updates if needed (package.json, tsconfig.json)

Note: this fix is intrinsically extension-level, so it also touches extensions/vscode/** (environment builder, package.json settings, README, integration tests). The server-side primitive change is confined to server/src/prompts/prompt-completions.ts.

🚫 FORBIDDEN FILES:

  • Files unrelated to the primitive update
  • Temporary or test output files
  • IDE configuration files
  • Log files or debug output
  • Analysis or summary files

Rationale: This PR should contain only the files necessary to update and test the primitive.

🚨 PRs that include forbidden files will be rejected and must be revised.


🛑 MANDATORY PR VALIDATION CHECKLIST

BEFORE SUBMITTING THIS PR, CONFIRM:

  • ONLY server implementation files are included
  • NO temporary or output files are included
  • NO unrelated configuration files are included
  • ALL existing tests continue to pass
  • NEW functionality is properly tested

  • Impact Scope: Moderate

Update Metadata

  • Breaking Changes: No
  • API Compatibility: Maintained (single-root behavior unchanged via fallback)
  • Performance Impact: Neutral by default; multi-root scans more roots, which the new queryPackExcludeDirs setting lets users bound

🎯 Changes Description

Current Behavior

Completion providers scanned only getUserWorkspaceDir() (folder index 0). In a multi-root workspace, queries/packs/databases/SARIF in non-first roots were not surfaced. There was no way to explicitly include an out-of-workspace query repo or exclude a root.

Updated Behavior

  • Completion providers scan every workspace root via getUserWorkspaceDirs() (reads CODEQL_MCP_WORKSPACE_FOLDERS), de-duplicating results.
  • The extension computes effective resolution roots = all workspace folders + queryPackIncludeDirs queryPackExcludeDirs, and feeds them into CODEQL_MCP_WORKSPACE_FOLDERS and CODEQL_ADDITIONAL_PACKS. Workflow-prompt path resolution already consumes that env var, so include/exclude are honored end-to-end with no new server env var.

Motivation

Support the recommended multi-root layout (query repo + analysis-target repo as separate roots) and give users deterministic, folder-order-independent control over query/pack resolution.

🔄 Before vs. After Comparison

Functionality Changes

// BEFORE: single root (folder index 0)
export async function completeQueryPath(value: string): Promise<string[]> {
  const workspace = getUserWorkspaceDir();
  // ...scan `workspace` only
}

// AFTER: every workspace root, results de-duplicated
export async function completeQueryPath(value: string): Promise<string[]> {
  const workspaces = getUserWorkspaceDirs();
  const results: string[] = [];
  for (const workspace of workspaces) {
    if (results.length >= MAX_FILE_COMPLETIONS) break;
    await findFilesByExtension(workspace, workspace, ['.ql', '.qlref'], MAX_SCAN_DEPTH, results);
  }
  // ...filter `[...new Set(results)]`
}

API Changes

// New extension settings (extensions/vscode/package.json)
"codeql-mcp.queryPackIncludeDirs": []  // extra roots; absolute as-is, relative resolved against every folder
"codeql-mcp.queryPackExcludeDirs": []  // drop roots matching or nested inside these dirs

Output Format Changes

No change to completion output shape; the candidate set now spans all resolution roots.

🧪 Testing & Validation

Test Coverage Updates

  • Existing Tests: All existing tests continue to pass
  • New Test Cases: Added tests for new functionality
  • Regression Tests: Added tests to prevent regression of fixed issues
  • Edge Case Tests: Enhanced edge case coverage

Validation Scenarios

  1. Backward Compatibility: Single-root completions still resolve via getUserWorkspaceDirs() fallback to getUserWorkspaceDir().
  2. New Functionality: Queries/packs/databases discovered in a non-first root; queryPackIncludeDirs adds roots, queryPackExcludeDirs removes them.
  3. Error Handling: Unreadable/non-existent roots are skipped silently during scans.
  4. Performance: queryPackExcludeDirs lets users bound scan scope (e.g. drop large/vendor roots).

Test Results

  • Unit Tests: Server 1561/1561; extension 190/190
  • Integration Tests: Extension multi-root scenario tests added; run in CI (sandbox cannot install the GitHub.vscode-codeql dependency extension)
  • Manual Testing: Verified env-builder output and completion discovery across roots
  • Performance Testing: No regressions detected

📋 Implementation Details

Files Modified

  • Core Implementation: server/src/prompts/prompt-completions.ts (multi-root scans)
  • Supporting Libraries: extensions/vscode/src/bridge/environment-builder.ts (computeResolutionRoots)
  • Type Definitions: n/a
  • Tests: server/test/src/prompts/prompt-completions.test.ts, extensions/vscode/test/bridge/environment-builder.test.ts, extensions/vscode/test/suite/workspace-scenario.integration.test.ts
  • Documentation: extensions/vscode/README.md, CHANGELOG.md, extensions/vscode/package.json setting descriptions

Code Changes Summary

  • Algorithm Improvements: Enhanced core logic
  • Error Handling: Improved error handling and messaging
  • Performance Optimization: Optimized execution paths
  • Type Safety: Enhanced TypeScript types
  • Input Validation: Improved input validation
  • Output Format: Enhanced output structure

Dependencies

  • No New Dependencies: Update uses existing dependencies only
  • Updated Dependencies: Updated to newer versions (list changes)
  • New Dependencies: Added new dependencies (justify need)

🔍 Quality Improvements

Bug Fixes (if applicable)

  • Issue: Workflow prompts couldn't target queries outside the first workspace folder.
  • Root Cause: Completion providers (and the extension env builder) keyed off folder index 0.
  • Solution: Scan all roots via getUserWorkspaceDirs(); fold include/exclude settings into CODEQL_MCP_WORKSPACE_FOLDERS/CODEQL_ADDITIONAL_PACKS.
  • Prevention: CODEQL_MCP_WORKSPACE_FOLDERS is the single source of truth for resolution roots; regression tests assert non-first-folder discovery.

Performance Improvements

  • Baseline Performance: Single-root scan.
  • Improved Performance: Multi-root scan retains the existing MAX_FILE_COMPLETIONS cap and 5s cache; queryPackExcludeDirs bounds scope.
  • Optimization Techniques: Shared result cap across roots, cache keyed on the full root set.

Code Quality Enhancements

  • Readability: Improved code clarity and documentation
  • Maintainability: Better code organization and structure
  • Testability: Enhanced test coverage and clarity
  • Reusability: More modular and reusable components

🔗 References

Related Issues/PRs

External References

Validation Materials

  • Test Cases: Multi-root fixture with queries/databases in a non-first root (extensions/vscode/test/fixtures/multi-root-workspace)
  • Performance Benchmarks: n/a

🚀 Compatibility & Migration

Backward Compatibility

  • Fully Compatible: No breaking changes
  • Deprecation Warnings: Deprecated features with warnings
  • Breaking Changes: Changes that break existing usage (detailed below)

Breaking Changes (if any)

None.

API Evolution

  • Enhanced Parameters: New optional parameters added
  • Improved Responses: Richer response formats
  • Better Error Messages: More descriptive error information
  • Maintained Contracts: Core API contracts preserved

👥 Review Guidelines

For Reviewers

Please verify:

  • ⚠️ SCOPE COMPLIANCE: Server primitive change is confined to prompt-completions.ts; remaining changes are the intrinsically extension-level fix
  • ⚠️ NO UNRELATED FILES: No temporary, output, or unrelated files
  • ⚠️ BACKWARD COMPATIBILITY: Existing single-root behavior preserved
  • Functionality: Updates work as described
  • Test Coverage: All existing tests pass, new tests comprehensive
  • Performance: No performance regressions
  • Code Quality: Maintains or improves code quality
  • Documentation: Updated documentation accurate
  • Error Handling: Improved error handling
  • Type Safety: TypeScript types properly updated

Testing Instructions

# Server unit tests (includes multi-root completion tests)
npm run test:server

# Extension unit tests (includes environment-builder include/exclude tests)
npm run test -w extensions/vscode -- --run

# Extension integration tests (multi-root scenario) — runs in CI
npx vscode-test --label multiRoot

Validation Checklist

  1. Regression Testing: Single-root completions unchanged
  2. New Feature Testing: Non-first-folder discovery + include/exclude honored
  3. Performance Testing: Result cap/cache retained; exclude bounds scope
  4. Error Testing: Unreadable/missing roots skipped
  5. Integration Testing: workspace-scenario multi-root assertions on env vars
  6. Documentation Review: README + CHANGELOG describe settings and multi-root interaction

📊 Impact Assessment

Performance Impact

  • Memory Usage: Negligible (bounded result set)
  • Execution Time: Slightly higher with many roots; bounded by cap, cache, and queryPackExcludeDirs
  • Throughput: n/a

Server Impact

  • Startup Time: No significant impact on server startup
  • Runtime Stability: No impact on server stability
  • Resource Usage: Reasonable resource consumption
  • Concurrent Usage: Safe for concurrent access

AI Assistant Impact

  • Enhanced Accuracy: Improved AI assistant responses
  • Better Coverage: Expanded use case support
  • Improved Reliability: More reliable primitive behavior
  • Enhanced User Experience: Better AI assistant workflows

🔄 Deployment Strategy

Rollout Considerations

  • Safe Deployment: Can be deployed safely to production
  • Gradual Rollout: Consider gradual rollout if high-impact changes
  • Monitoring: Appropriate monitoring for the update
  • Rollback Plan: Clear rollback strategy if issues arise

Post-Deployment Validation

  • Monitoring: Key metrics to monitor after deployment
  • User Feedback: Channels for collecting user feedback
  • Performance Tracking: Performance metrics to track
  • Error Tracking: Error patterns to watch for

Update Methodology: This update follows best practices:

  1. ✅ Comprehensive backward compatibility analysis
  2. ✅ Thorough testing of all changes
  3. ✅ Performance impact assessment
  4. ✅ Clear documentation of changes
  5. ✅ Robust error handling improvements
  6. ✅ Maintained code quality standards

Copilot AI requested review from Copilot and removed request for Copilot June 24, 2026 16:00
Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 24, 2026 16:18
Copilot AI changed the title [WIP] Fix MCP workflow prompts targeting for multi-root workspaces [UPDATE PRIMITIVE] Resolve workflow-prompt query/pack paths across all workspace folders + include/exclude settings Jun 24, 2026
Copilot AI requested a review from data-douser June 24, 2026 16:21
@data-douser

Copy link
Copy Markdown
Collaborator

Closing this PR as superseded by #308.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants