Skip to content

Conversation

@thomas-bartlett
Copy link
Collaborator

@thomas-bartlett thomas-bartlett commented Nov 17, 2025

Add Tags Filtering Support

Summary

Adds optional tags field to YAML frontmatter and --tag/--tags CLI filtering to enable categorization and flexible rule selection beyond language-based filters.

Changes

  • Added tags: list[str] field to source rule frontmatter (optional)
  • Implemented --tag/--tags CLI argument with comma-separated values and AND logic (case-insensitive)
  • Added validate_tags() utility function in utils.py for shared validation logic
  • Tags validation: must be strings without whitespace, normalized to lowercase
  • Both validate_unified_rules.py and converter.py use the same validation logic
  • Added example tags to authentication and API rules

Usage

In source/*.md frontmatter:

tags:
  - authentication
  - web-security
  - api

Filter by single tag

uv run python src/convert_to_ide_formats.py --source core --tag api

Filter by multiple tags (comma-separated, AND logic - must have ALL)

uv run python src/convert_to_ide_formats.py --source core --tag api,web-security

Breaking Changes

None - fully backwards compatible.

Fixes #69

@thomas-bartlett thomas-bartlett self-assigned this Nov 17, 2025
Copilot AI review requested due to automatic review settings November 17, 2025 18:17
@thomas-bartlett thomas-bartlett added the enhancement New feature or request label Nov 17, 2025
Copilot finished reviewing on behalf of thomas-bartlett November 17, 2025 18:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an optional tags field to rule frontmatter with corresponding CLI filtering capabilities, enabling flexible rule categorization and selection beyond language-based filters. The implementation includes validation, normalization, and filtering logic with backwards compatibility maintained.

  • Added optional tags field to rule YAML frontmatter with validation (must be strings without whitespace)
  • Implemented --tag/--tags CLI arguments supporting case-insensitive AND logic filtering
  • Tags are normalized to lowercase during parsing for consistent matching

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/validate_unified_rules.py Added validation logic for optional tags field in rule frontmatter
src/formats/base.py Extended ProcessedRule dataclass with tags field for rule metadata
src/converter.py Added tag parsing, validation, and normalization; updated ConversionResult to include tags
src/convert_to_ide_formats.py Implemented tag filtering function, added CLI arguments, and integrated filtering into conversion pipeline
sources/core/codeguard-0-authentication-mfa.md Added example tags (authentication, web-security) to demonstrate usage
sources/core/codeguard-0-api-web-services.md Added example tags (api, web-security, microservices) to demonstrate usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thomas-bartlett thomas-bartlett force-pushed the feature/add-tags-filtering branch from c46399b to 939550f Compare November 17, 2025 18:34
@thomas-bartlett thomas-bartlett force-pushed the feature/add-tags-filtering branch from 939550f to 0850522 Compare November 17, 2025 18:42
Copilot AI review requested due to automatic review settings November 17, 2025 18:42
Copilot finished reviewing on behalf of thomas-bartlett November 17, 2025 18:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

src/convert_to_ide_formats.py:117

  • The docstring states the function returns a dictionary with 'success' and 'errors' lists, but the implementation now also includes a 'skipped' list (added at line 159). The docstring and example should be updated to reflect this change:
Returns:
    Dictionary with 'success', 'skipped', and 'errors' lists:
    {
        "success": ["rule1.md", "rule2.md"],
        "skipped": ["rule3.md"],  # Rules filtered out by tags
        "errors": ["rule4.md: error message"]
    }
    Returns:
        Dictionary with 'success' and 'errors' lists:
        {
            "success": ["rule1.md", "rule2.md"],
            "errors": ["rule3.md: error message"]
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings November 18, 2025 16:59
Copilot finished reviewing on behalf of thomas-bartlett November 18, 2025 17:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/convert_to_ide_formats.py:385

  • When tag filtering is active and all rules are skipped (no rules match the filter), the script still reports "✅ All conversions successful" even though no rules were actually converted. This could be confusing for users who may not notice that all rules were filtered out. Consider adding a check to warn users or exit with an error when filtering results in zero rules being converted, or at least modify the success message to indicate that filtering was active and how many rules were actually converted.
    if aggregated["errors"]:
        print("❌ Some conversions failed")
        sys.exit(1)
    
    print("✅ All conversions successful")

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thomas-bartlett thomas-bartlett merged commit 6674a57 into main Nov 18, 2025
4 checks passed
@thomas-bartlett thomas-bartlett deleted the feature/add-tags-filtering branch November 18, 2025 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tags: metadata and tag-based filtering

3 participants