Enhance Path Exclusion Logic and Semantic Brief Enrichment
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 43s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Has been cancelled

- Introduced `resolve_path_anti_patterns` to improve handling of path exclusions based on explicit negations and semantic briefs.
- Updated `enrich_brief_with_path_constraints` to incorporate path-specific exclusions into semantic briefs, enhancing exercise relevance.
- Modified roadmap step annotation to allow for anti-pattern overrides, improving flexibility in exercise selection.
- Enhanced tests to validate new path exclusion features and ensure correct functionality against learning goals.
- Incremented application version to reflect these updates.
This commit is contained in:
Lars committed 2026-06-11 08:43:59 +02:00
1 parent 07e147bc76
commit 3c12363b8f
6 files changed
+270 -18

No files matched your search

+71 -1
View File
@@ -246,6 +246,11 @@ def build_semantic_brief(query: Optional[str]) -> PlanningSemanticBrief:
if len(q) >= 24 and not technique:
strength = max(strength, 0.4)
path_constraints = parse_stage_goal_constraints(q)
for item in path_constraints.exclude_phrases:
if item not in exclude:
exclude.append(item)
return PlanningSemanticBrief(
primary_topic=primary,
topic_type=topic_type,
@@ -775,6 +780,63 @@ def _blob_matches_stage_excludes(blob: str, exclude_phrases: Sequence[str]) -> b
return False
def resolve_path_anti_patterns(
goal_query: str,
*,
semantic_brief: Optional[PlanningSemanticBrief] = None,
extra_context: Optional[str] = None,
) -> List[str]:
"""
Pfadweite Ausschlüsse — nur aus expliziten Quellen, kein Themen-Raten.
Quellen (in dieser Reihenfolge):
1. Negationen in Anfrage/Kontext (ohne/kein/nicht …) via parse_stage_goal_constraints
2. exclude_phrases im Semantic Brief (inkl. LLM/Technik-Regeln)
3. stage_specs.anti_patterns (Roadmap-Stufe, vom Trainer oder LLM)
Keine stillen Ausschlüsse aus dem Hauptthema (z. B. „Mawashi“ → kein Kumite).
"""
parts = [str(goal_query or "").strip(), str(extra_context or "").strip()]
combined = " ".join(p for p in parts if p)
if not combined and not semantic_brief:
return []
constraints = parse_stage_goal_constraints(combined) if combined else StageGoalConstraints()
out: List[str] = []
for item in constraints.exclude_phrases:
if item and item not in out:
out.append(item)
if semantic_brief:
for raw in semantic_brief.exclude_phrases or []:
for expanded in _expand_stage_exclude_phrase(str(raw or "")):
if expanded and expanded not in out:
out.append(expanded)
return out[:24]
def enrich_brief_with_path_constraints(
brief: PlanningSemanticBrief,
goal_query: str,
*,
extra_context: Optional[str] = None,
) -> PlanningSemanticBrief:
"""Negationen/Ausschlüsse aus der Gesamtanfrage in den Semantic Brief übernehmen."""
anti = resolve_path_anti_patterns(
goal_query,
semantic_brief=brief,
extra_context=extra_context,
)
if not anti:
return brief
exclude = list(brief.exclude_phrases or [])
for item in anti:
if item not in exclude:
exclude.append(item)
return brief.model_copy(update={"exclude_phrases": exclude[:16]})
_MIN_STAGE_FIT_SEMANTIC = 0.30
_MIN_STAGE_FIT_RELAXED = 0.20
@@ -787,6 +849,7 @@ def build_stage_match_brief(
load_profile: Optional[Sequence[str]] = None,
phase: Optional[str] = None,
path_context_note: Optional[str] = None,
path_anti_patterns: Optional[Sequence[str]] = None,
) -> PlanningSemanticBrief:
"""
Stufen-zentrierter Semantik-Brief — unabhängig vom Gesamt-Pfad-Thema.
@@ -797,7 +860,12 @@ def build_stage_match_brief(
if len(lg) < 3:
return PlanningSemanticBrief(semantic_strength=0.0)
constraints = parse_stage_goal_constraints(lg, anti_patterns)
merged_anti: List[str] = []
for raw in list(anti_patterns or []) + list(path_anti_patterns or []):
s = str(raw or "").strip()
if s and s not in merged_anti:
merged_anti.append(s)
constraints = parse_stage_goal_constraints(lg, merged_anti)
must: List[str] = []
norm_lg = _normalize_phrase(lg)
for token in constraints.positive_tokens:
@@ -1134,7 +1202,9 @@ __all__ = [
"StageGoalConstraints",
"apply_stage_match_retrieval_weights",
"build_stage_match_brief",
"enrich_brief_with_path_constraints",
"exercise_passes_stage_fit",
"resolve_path_anti_patterns",
"exercise_passes_stage_learning_goal_gate",
"merge_semantic_brief_llm",
"parse_stage_goal_constraints",