improvements added to rules engine

This commit is contained in:
Test User
2025-10-23 20:14:21 +02:00
parent 7cfe9499ee
commit eea7ef0648
25 changed files with 1967 additions and 107 deletions
+90 -21
View File
@@ -76,12 +76,12 @@ OPENAI_API_KEY=""
"""Create default template"""
import json
default_template = {
"title": "heur|orig",
"created": "heur|orig",
"changed": "heur|orig",
"authors": "heur|orig",
"version": "heur|orig",
"tags": "heur|orig|ai default"
"title": "heur|orig:text",
"created": "heur|orig:datetime",
"changed": "heur|orig:datetime",
"authors": "heur|orig:list",
"version": "heur|orig:text",
"tags": "heur|orig|ai default:list"
}
with open(self.templates_dir / 'default.json', 'w', encoding='utf-8') as f:
json.dump(default_template, f, indent=2)
@@ -91,25 +91,94 @@ OPENAI_API_KEY=""
import json
rules = {
'tags_normalization.json': {
"name": "tags_normalization",
"description": "Normalize tags to lowercase with underscores",
"type": "tags"
},
'tag_to_tags.json': {
"name": "tag_to_tags",
"description": "Rename 'tag' key to 'tags'",
"type": "rename"
},
'lowercase_keys.json': {
'01_lowercase_keys.json': {
"name": "lowercase_keys",
"description": "All frontmatter keys must be lowercase",
"type": "keys"
"field": "*",
"priority": 1,
"action": "normalize_keys",
"transform": "lower",
"llm_prompt": "Ensure all keys are lowercase"
},
'summary_to_description.json': {
'02_tag_to_tags.json': {
"name": "tag_to_tags",
"description": "Rename 'tag' field to 'tags'",
"field": "tag",
"priority": 2,
"action": "rename_field",
"from": "tag",
"to": "tags",
"llm_prompt": "Convert tag field to tags array"
},
'03_summary_to_description.json': {
"name": "summary_to_description",
"description": "Rename 'summary' key to 'description'",
"type": "rename"
"description": "Rename 'summary' field to 'description'",
"field": "summary",
"priority": 2,
"action": "rename_field",
"from": "summary",
"to": "description",
"llm_prompt": "Convert summary to description"
},
'10_tags_format_list.json': {
"name": "tags_format_list",
"description": "Convert comma-separated tags to list",
"field": "tags",
"priority": 10,
"action": "normalize_value",
"split_on": ",",
"pattern": ".*",
"replacement": "\\g<0>",
"llm_prompt": "Ensure tags is a list, not a comma-separated string"
},
'20_tags_replace_spaces.json': {
"name": "tags_replace_spaces",
"description": "Replace spaces with underscores in tags",
"field": "tags",
"priority": 20,
"action": "normalize_value",
"pattern": " ",
"replacement": "_",
"llm_prompt": "Replace spaces with underscores in tags"
},
'21_tags_replace_hyphens.json': {
"name": "tags_replace_hyphens",
"description": "Replace hyphens with underscores in tags",
"field": "tags",
"priority": 21,
"action": "normalize_value",
"pattern": "-",
"replacement": "_",
"llm_prompt": "Replace hyphens with underscores in tags"
},
'30_tags_lowercase.json': {
"name": "tags_lowercase",
"description": "Convert tags to lowercase",
"field": "tags",
"priority": 30,
"action": "normalize_value",
"transform": "lower",
"llm_prompt": "Convert all tags to lowercase"
},
'40_tags_remove_invalid_chars.json': {
"name": "tags_remove_invalid_chars",
"description": "Remove characters that are not alphanumeric or underscore",
"field": "tags",
"priority": 40,
"action": "normalize_value",
"pattern": "[^a-z0-9_]",
"replacement": "",
"llm_prompt": "Remove any characters that are not lowercase letters, numbers, or underscores from tags"
},
'50_tags_validate_format.json': {
"name": "tags_validate_format",
"description": "Validate that tags only contain lowercase alphanumeric and underscores",
"field": "tags",
"priority": 50,
"action": "validate",
"pattern": "^[a-z0-9_]+$",
"multiline": False,
"llm_prompt": "Tags must contain only lowercase letters, numbers, and underscores"
}
}