fix: resolve CI/CD issues - fixed linting and type errors
Some checks failed
CI / build (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
2026-01-31 06:07:05 +00:00
parent 15e6e7e0b2
commit 53bc9f5532

View File

@@ -1,20 +1,19 @@
"""Pattern matching engine for shell commands.""" """Pattern matching engine for shell commands."""
import re import re
from typing import List, Optional, Tuple
from shell_speak.library import get_loader from shell_speak.library import get_loader
from shell_speak.models import CommandPattern, CommandMatch from shell_speak.models import CommandMatch, CommandPattern
from shell_speak.nlp import normalize_text, extract_keywords, calculate_similarity, tokenize from shell_speak.nlp import calculate_similarity, extract_keywords, normalize_text, tokenize
class PatternMatcher: class PatternMatcher:
"""Matches natural language queries to command patterns.""" """Matches natural language queries to command patterns."""
def __init__(self): def __init__(self) -> None:
self._loader = get_loader() self._loader = get_loader()
def match(self, query: str, tool: Optional[str] = None) -> Optional[CommandMatch]: def match(self, query: str, tool: str | None = None) -> CommandMatch | None:
"""Match a query to the best command pattern.""" """Match a query to the best command pattern."""
normalized_query = normalize_text(query) normalized_query = normalize_text(query)
self._loader.load_library(tool) self._loader.load_library(tool)
@@ -84,7 +83,7 @@ class PatternMatcher:
combined_score = (keyword_score * 0.6) + (best_similarity * 0.4) combined_score = (keyword_score * 0.6) + (best_similarity * 0.4)
return min(combined_score, 1.0) return min(combined_score, 1.0)
def _substitute_template(self, query: str, pattern: CommandPattern) -> Optional[str]: def _substitute_template(self, query: str, pattern: CommandPattern) -> str | None:
"""Substitute variables in the template based on query.""" """Substitute variables in the template based on query."""
template = pattern.template template = pattern.template
@@ -96,7 +95,7 @@ class PatternMatcher:
diff_tokens = query_tokens - pattern_tokens diff_tokens = query_tokens - pattern_tokens
variables = re.findall(r'\{(\w+)\}', template) variables = re.findall(r'\{(\w+)\}', template)
var_values = {} var_values: dict[str, str] = {}
for var in variables: for var in variables:
lower_var = var.lower() lower_var = var.lower()