Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/gradata/hooks/jit_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
import re
import time
from pathlib import Path
from typing import TYPE_CHECKING

from gradata.hooks._base import extract_message, resolve_brain_dir, run_hook
from gradata.hooks._profiles import Profile

if TYPE_CHECKING:
from gradata._types import Lesson

try:
from gradata.enhancements.self_improvement import parse_lessons
except ImportError:
Expand Down Expand Up @@ -96,13 +100,13 @@ def _float_env(name: str, default: float) -> float:


def rank_rules_for_draft(
lessons: list,
lessons: list[Lesson],
draft_text: str,
*,
k: int = DEFAULT_MAX_RULES,
min_confidence: float = DEFAULT_MIN_CONFIDENCE,
min_similarity: float = DEFAULT_MIN_SIMILARITY,
) -> list[tuple[object, float]]:
) -> list[tuple[Lesson, float]]:
"""Score each lesson against draft_text and return top-k above threshold.

Returns a list of (lesson, similarity) tuples, highest first. A rule
Expand All @@ -117,7 +121,7 @@ def rank_rules_for_draft(
if not draft_tokens:
return []

scored: list[tuple[object, float]] = []
scored: list[tuple[Lesson, float]] = []
for lesson in lessons:
conf = getattr(lesson, "confidence", 0.0)
if conf < min_confidence:
Expand Down
2 changes: 1 addition & 1 deletion src/gradata/rules/rule_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _rule_matches_domain(rule: GraduatedRule, domain_norm: str) -> bool:
if str(scope.get("domain", "")).strip().lower() == domain_norm:
return True
applies = str(scope.get("applies_to", "")).strip().lower()
return applies == domain_norm or (applies and applies.startswith(f"{domain_norm}:"))
return applies == domain_norm or applies.startswith(f"{domain_norm}:")


class RuleContext:
Expand Down
Loading