Skip to content

feat: organize query templates by subdirectory with dynamic category discovery - #44

Merged
codeasier merged 2 commits into
mainfrom
feat/dynamic-category-discovery
Apr 18, 2026
Merged

codeasier merged 2 commits into
mainfrom
feat/dynamic-category-discovery

Conversation

@codeasier

Copy link
Copy Markdown
Owner

📝 Description

Reorganizes query template YAML files from a flat directory into category subdirectories (basic/, business/, statistical/) and replaces the hardcoded category` field + enum list with automatic discovery from the directory structure.

Key changes:

  • Moved 7 YAML templates into 3 subdirectories matching their categories
  • Removed category: field from YAML files — category is now inferred from the parent directory name
  • QueryRegistry._load_yaml_templates() now recursively scans **/*.yaml
  • discover_categories() dynamically returns subdirectory names
  • cli.py replaces hardcoded ["basic", "statistical", "business"] with dynamic discovery
  • completion.py complete_categories() calls discover_categories() instead of returning a static list
  • All CLI parameters (--list, --category, --template-info, --template-use) remain unchanged in interface and behavior

This allows new categories and templates to be added by simply placing YAML files in the appropriate subdirectory, with no code changes needed.

🔗 Related Issue

Fixes #43

🧪 Testing

  • Tests added/updated
  • Manual testing completed

All 226 tests pass. Updated 2 test assertions in test_completion.py to verify the set of categories rather than hardcoded order.

✅ Checklist

  • Code follows project guidelines
  • Documentation updated (if applicable)
  • No new warnings introduced
  • Changes tested locally

📸 Screenshots (if applicable)

📋 Additional Notes

Template directory structure after this change:

src/pt_snap_cli/query/templates/
├── basic/
│   ├── active_blocks.yaml
│   ├── blocks_by_size.yaml
│   ├── events_by_action.yaml
│   └── memory_timeline.yaml
├── business/
│   └── leak_detection.yaml
└── statistical/
    ├── callstack_analysis.yaml
    └── memory_peak.yaml

codeasier added 2 commits April 18, 2026 21:16
…discovery

Move query template YAML files into category subdirectories (basic/,
business/, statistical/) and replace the hardcoded category field + enum
list with automatic discovery from the directory structure.

This allows new categories and templates to be added by simply placing
YAML files in the appropriate subdirectory, with no code changes needed.

All CLI parameters (--list, --category, --template-info, --template-use)
remain unchanged in their interface and behavior.

Fixes #43
Fixes formatting from dynamic category discovery changes.

@codeasier codeasier left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

LGTM

@codeasier
codeasier merged commit f34205f into main Apr 18, 2026
5 checks passed
@codeasier
codeasier deleted the feat/dynamic-category-discovery branch April 18, 2026 13:21
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.

[FEATURE] 基于目录结构的查询模板动态分类发现

1 participant