feat(halachot): canonical lookup-before-insert + MCP tools (Phase 3+4, V41)
All checks were successful
G12 Leak-Guard / leak-guard (pull_request) Successful in 4s
Lint — undefined names / undefined-names (pull_request) Successful in 10s

store_halachot_for_chunk: לפני כל INSERT — חיפוש cosine ב-canonical_halachot (≥0.85).
  עיקרון קיים → instance_type='citation' (אין canonical חדש).
  עיקרון חדש → instance_type='original' + יצירת canonical אוטומטית + עדכון instance_count.

config: HALACHA_CANONICAL_LOOKUP_ENABLED=true, HALACHA_CANONICAL_THRESHOLD=0.85.

db.list_halachot: פרמטר instance_type חדש לסינון.
db.list_canonical_halachot: שאילתת רשימה לפי practice_area/status.
db.update_canonical_statement: עדכון ניסוח קנוני ע"י היו"ר.

tools/precedent_library.py:
  halachot_pending: ברירת-מחדל instance_type='original' (תור ריאלי).
  halacha_review: פרמטר canonical_statement חדש (עריכת ניסוח העיקרון).
  canonical_halacha_list: כלי MCP חדש — רשימת עקרונות קנוניים.
  canonical_halacha_get: כלי MCP חדש — עיקרון + אינסטנסים.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 17:36:09 +00:00
parent aba87737e3
commit 7c39c685e5
4 changed files with 203 additions and 10 deletions

View File

@@ -320,6 +320,7 @@ async def halacha_review(
reasoning_summary: str = "",
subject_tags: list[str] | None = None,
practice_areas: list[str] | None = None,
canonical_statement: str = "",
) -> str:
"""אישור / דחייה / עריכה של הלכה שחולצה אוטומטית.
@@ -331,6 +332,7 @@ async def halacha_review(
reasoning_summary: עריכת תמצית ההיגיון (ריק = ללא שינוי).
subject_tags: עריכת תגיות (None = ללא שינוי).
practice_areas: עריכת תחומים (None = ללא שינוי).
canonical_statement: עריכת הניסוח הקנוני הרחב של העיקרון (ריק = ללא שינוי).
"""
if status not in {"pending_review", "approved", "rejected", "published"}:
return _err(
@@ -353,25 +355,87 @@ async def halacha_review(
)
if row is None:
return _err("הלכה לא נמצאה")
# V41: propagate canonical_statement edit to the canonical principle.
if canonical_statement and row.get("canonical_id"):
try:
await db.update_canonical_statement(
UUID(str(row["canonical_id"])), canonical_statement,
)
except Exception as e:
import logging
logging.getLogger(__name__).warning(
"halacha_review: failed to update canonical_statement: %s", e,
)
return _ok(row)
async def halachot_pending(limit: int = 100, include_low_quality: bool = False) -> str:
async def halachot_pending(
limit: int = 100,
include_low_quality: bool = False,
instance_type: str = "original",
) -> str:
"""תור ההלכות הממתינות לאישור (review_status='pending_review').
כברירת-מחדל (#84.1, #84.3) התור **מסונן** — הלכות עם דגל-איכות כלשהו
כברירת-מחדל (#84.1, #84.3, V41) התור **מסונן** — הלכות עם דגל-איכות כלשהו
(application / ציטוט-לא-מאומת / קטוע / obiter / restatement דק / לא-נתמך /
near-duplicate) מוסתרות (הן שייכות ל'דורש תיקון-חילוץ', לא לתור-האישור),
ו**ממוין לפי עדיפות** (טופלו-לרעה תחילה, אז הכי לא-ודאיים, אז הישנים).
V41: כברירת-מחדל מציג רק instance_type='original' (עקרונות חדשים, לא ציטוטים).
העברת instance_type='' מציגה הכל (כולל ציטוטים).
Args:
limit: מספר מקסימלי.
include_low_quality: True כדי לחשוף גם פריטים מסומני-איכות (בקט 'דורש תיקון').
instance_type: 'original' (ברירת מחדל) / 'citation' / 'application' / '' (הכל).
"""
rows = await db.list_halachot(
review_status="pending_review",
instance_type=instance_type or None,
limit=limit,
exclude_low_quality=not include_low_quality,
order_by_priority=True,
)
return _ok(rows)
async def canonical_halacha_list(
practice_area: str = "",
review_status: str = "",
limit: int = 50,
offset: int = 0,
) -> str:
"""רשימת עקרונות קנוניים (canonical_halachot) — שאילתת נוחות לסוכני-הכתיבה.
Args:
practice_area: סינון לפי תחום עיסוק (ריק = הכל).
review_status: pending_synthesis / pending_review / approved / published (ריק = הכל).
limit: מספר מקסימלי (עד 200).
offset: עמוד (pagination).
"""
rows = await db.list_canonical_halachot(
practice_area=practice_area or None,
review_status=review_status or None,
limit=min(limit, 200),
offset=offset,
)
return _ok(rows)
async def canonical_halacha_get(canonical_id: str) -> str:
"""שלוף עיקרון קנוני אחד (canonical_statement, practice_areas, subject_tags,
review_status, instance_count) + כל האינסטנסים שלו (לפי פסיקה).
Args:
canonical_id: מזהה (UUID) של העיקרון הקנוני.
"""
try:
cid = UUID(canonical_id)
except ValueError:
return _err("canonical_id לא תקין")
row = await db.get_canonical_halacha(cid)
if row is None:
return _err("עיקרון קנוני לא נמצא")
return _ok(row)