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
+37 -6
View File
@@ -7,7 +7,7 @@ from datetime import datetime
from core.database import Database
from core.repository import Repository
from core.frontmatter import FrontmatterParser
from core.rules import RulesEngine
from core.rules_processor import RulesProcessor
from core.template import TemplateManager
from core.llm import LLMClient
from core.changelog import ChangeLog
@@ -32,7 +32,7 @@ class FrontmatterProcessor:
api_config = self.config.get_api_config()
self.db = Database(repo.path / 'madomeda.db')
self.rules = RulesEngine(self.config.rules_dir)
self.rules = RulesProcessor(self.config.rules_dir)
self.templates = TemplateManager(self.config.templates_dir)
self.llm = LLMClient(self.config.prompts_dir, api_config)
self.changelog = ChangeLog(repo.path)
@@ -113,7 +113,7 @@ class FrontmatterProcessor:
)
# Apply rules
normalized_fm, is_conformant = self.rules.apply_rules(dict(original_fm))
normalized_fm, is_conformant, violations = self.rules.apply_rules(dict(original_fm))
# Check if we need to update
needs_update = self.force or not is_conformant or not self._matches_template(normalized_fm, template)
@@ -190,14 +190,21 @@ class FrontmatterProcessor:
new_fm = {}
all_tags = self.db.get_all_tags()
for field, strategy in template.items():
options = strategy.split('|')
for field, field_value in template.items():
# Parse field to get strategy and type
strategy_str, field_type = self.templates.parse_field(str(field_value))
options = strategy_str.split('|')
value = None
for option in options:
option = option.strip()
if option == 'heur':
if option.startswith('lit:'):
# Literal/static value
value = option[4:].strip()
# Convert based on type
value = self._convert_value_type(value, field_type)
elif option == 'heur':
# Use heuristics
value = self._get_heuristic_value(field, normalized_fm, body, file_path, git_info)
elif option == 'orig':
@@ -218,6 +225,30 @@ class FrontmatterProcessor:
return new_fm
def _convert_value_type(self, value: str, field_type: str):
"""Convert literal value to appropriate type"""
if field_type == 'checkbox':
return value.lower() in ('true', '1', 'yes', 'on')
elif field_type == 'number':
try:
if '.' in value:
return float(value)
return int(value)
except ValueError:
return value
elif field_type == 'list':
# Parse as JSON array or return empty list
if value == '[]':
return []
try:
import json
return json.loads(value)
except:
return [value]
else:
# text, date, datetime - keep as string
return value
def _get_heuristic_value(self, field: str, normalized_fm: dict, body: str,
file_path: Path, git_info: dict):
"""Get field value using heuristics"""