feat(learning): מסלול נקי להעלאת החלטה סופית + פאנל-סגנון דו-סוכני (DeepSeek+Gemini)
מוסיף מסלול ייעודי לקליטת ההחלטה החתומה של היו"ר, ומפעיל אותו דרך שני
שלבים אוטומטיים מדורגים עם פאנלי-סוכנים (אוטו-אישור + אסקלציה ליו"ר).
Backend (web/):
- POST /api/cases/{case}/final/upload — קליטת final חיצוני: שמירה קנונית
(סופי-{case}.docx + עותק קורפוס-סגנון תחת case_number מלא כדי שבל"מ לא
יתנגש עם ערר באותו מספר), פתיחת draft_final_pairs (final_received). לא נוגע
ב-active_draft ולא מריץ retrofit (נבדל מ-exports/upload ו-mark-final → לא G2).
- POST .../final/run-learning + .../final/run-halacha — שלבים מדורגים שמעירים
worker מקומי (claude/DeepSeek/Gemini מקומיים בלבד) דרך הרחבת
wake_curator_for_final עם param task=learning|halacha.
פאנל-סגנון חדש (scripts/style_lesson_panel.py): שני שופטים (DeepSeek+Gemini)
על-גבי דיסטילציית-ה-Opus; הסכמה 2/2-keep → decision_lesson
(source=panel:deepseek+gemini); substance מדולג (INV-LRN5); הפיך + גיבוי CSV.
פאנל-הלכות: docstring/SCRIPTS.md עודכנו (--apply מחווט).
Frontend (web-ui/): כפתור "העלאת החלטה סופית של היו"ר" + שני כפתורים מדורגים
"הרץ למידת-קול"/"הרץ אימות-הלכות" ב-drafts-panel; כל התוויות בעברית
(badge מקור-לקח: "פאנל: דיפסיק+גמיני", "הרמס (סקירה)"...).
Spec: docs/spec/07-learning.md §0.6. Invariants: INV-LRN1/LRN4/LRN5, G10
(שער-יו"ר ידני להטמעה ל-SKILL.md/lessons.md — הפאנלים יוצרים הצעות בלבד);
G2 (מסלול-סופי הוא יכולת חסרה, לא מסלול-מקביל).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,9 @@ import {
|
||||
useMarkFinal,
|
||||
useDeleteDraft,
|
||||
useActiveDraft,
|
||||
useUploadFinalDecision,
|
||||
useRunFinalLearning,
|
||||
useRunFinalHalacha,
|
||||
} from "@/lib/api/exports";
|
||||
import {
|
||||
useCaseFeedback,
|
||||
@@ -41,6 +44,9 @@ import {
|
||||
FileOutput,
|
||||
Plus,
|
||||
Trash2,
|
||||
Brain,
|
||||
Scale,
|
||||
Stamp,
|
||||
} from "lucide-react";
|
||||
|
||||
/* Statuses at which a draft is considered ready */
|
||||
@@ -86,13 +92,22 @@ export function DraftsPanel({
|
||||
const markFinal = useMarkFinal(caseNumber);
|
||||
const deleteDraft = useDeleteDraft(caseNumber);
|
||||
const resolveMutation = useResolveFeedback();
|
||||
const uploadFinal = useUploadFinalDecision(caseNumber);
|
||||
const runLearning = useRunFinalLearning(caseNumber);
|
||||
const runHalacha = useRunFinalHalacha(caseNumber);
|
||||
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
const finalFileRef = useRef<HTMLInputElement>(null);
|
||||
const [deleteTarget, setDeleteTarget] = useState<string | null>(null);
|
||||
|
||||
const isDraftReady = status && DRAFT_READY.includes(status);
|
||||
const openFeedbacks = feedbacks?.filter((f) => !f.resolved) ?? [];
|
||||
|
||||
// The chair's signed final exists once a "סופי-" file is present (or any is_final).
|
||||
const hasFinal = Boolean(
|
||||
exports?.some((f) => f.is_final || f.filename.startsWith("סופי-")),
|
||||
);
|
||||
|
||||
// Determine draft label based on *actual* v-numbers in filenames (not counts).
|
||||
// "(מתוקנת)" suffix appears when there's at least one עריכה-* file.
|
||||
const draftLabel = (() => {
|
||||
@@ -145,6 +160,38 @@ export function DraftsPanel({
|
||||
});
|
||||
}
|
||||
|
||||
function handleUploadFinal(file: File) {
|
||||
uploadFinal.mutate(file, {
|
||||
onSuccess: (data) => {
|
||||
toast.success(
|
||||
`ההחלטה הסופית נקלטה — ${data.final_words} מילים (לעומת ${data.draft_words} בטיוטה)`,
|
||||
);
|
||||
},
|
||||
onError: (err) =>
|
||||
toast.error(err instanceof Error ? err.message : "שגיאה בהעלאה"),
|
||||
});
|
||||
}
|
||||
|
||||
function handleRunLearning() {
|
||||
runLearning.mutate(undefined, {
|
||||
onSuccess: (d) =>
|
||||
d.status === "ok"
|
||||
? toast.success("למידת-הקול הופעלה — רצה ברקע (אופוס + פאנל דיפסיק/גמיני)")
|
||||
: toast.warning(`לא הופעלה למידה: ${d.reason ?? d.error ?? d.status}`),
|
||||
onError: () => toast.error("שגיאה בהפעלת למידת-הקול"),
|
||||
});
|
||||
}
|
||||
|
||||
function handleRunHalacha() {
|
||||
runHalacha.mutate(undefined, {
|
||||
onSuccess: (d) =>
|
||||
d.status === "ok"
|
||||
? toast.success("אימות-ההלכות הופעל — רץ ברקע (פאנל אופוס/דיפסיק/גמיני)")
|
||||
: toast.warning(`לא הופעל אימות: ${d.reason ?? d.error ?? d.status}`),
|
||||
onError: () => toast.error("שגיאה בהפעלת אימות-ההלכות"),
|
||||
});
|
||||
}
|
||||
|
||||
function handleMarkFinal(filename: string) {
|
||||
markFinal.mutate(filename, {
|
||||
onSuccess: () => toast.success("סומן כסופי"),
|
||||
@@ -200,6 +247,86 @@ export function DraftsPanel({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Chair's signed final decision — clean upload + staged learning pipeline ── */}
|
||||
<section className="rounded-lg border border-gold/40 bg-gold-wash/40 p-4 space-y-3">
|
||||
<input
|
||||
ref={finalFileRef}
|
||||
type="file"
|
||||
accept=".docx"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
const f = e.target.files?.[0];
|
||||
if (f) handleUploadFinal(f);
|
||||
if (finalFileRef.current) finalFileRef.current.value = "";
|
||||
}}
|
||||
/>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Stamp className="w-5 h-5 text-gold-deep shrink-0" />
|
||||
<h3 className="text-navy text-base">החלטה סופית של היו״ר</h3>
|
||||
{hasFinal && (
|
||||
<Badge className="bg-success-bg text-success border-success/40 text-[0.65rem]">
|
||||
נקלטה
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => finalFileRef.current?.click()}
|
||||
disabled={uploadFinal.isPending}
|
||||
>
|
||||
{uploadFinal.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin me-1.5" />
|
||||
) : (
|
||||
<Upload className="w-4 h-4 me-1.5" />
|
||||
)}
|
||||
{hasFinal ? "החלף החלטה סופית" : "העלאת החלטה סופית של היו״ר"}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-ink-muted leading-relaxed">
|
||||
העלאת ההחלטה החתומה של דפנה (נבדל מ״העלה גרסה מתוקנת״). הקליטה פותחת השוואת
|
||||
טיוטה↔סופי; לאחר מכן הפעל את שני השלבים האוטומטיים — הכל רץ ברקע, ורק מחלוקות
|
||||
בין הסוכנים מוסלמות אליך.
|
||||
</p>
|
||||
{hasFinal && (
|
||||
<div className="flex flex-wrap items-center gap-2 pt-1">
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleRunLearning}
|
||||
disabled={runLearning.isPending}
|
||||
className="bg-navy hover:bg-navy-soft text-parchment"
|
||||
>
|
||||
{runLearning.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin me-1.5" />
|
||||
) : (
|
||||
<Brain className="w-4 h-4 me-1.5" />
|
||||
)}
|
||||
הרץ למידת-קול
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleRunHalacha}
|
||||
disabled={runHalacha.isPending}
|
||||
className="bg-navy hover:bg-navy-soft text-parchment"
|
||||
>
|
||||
{runHalacha.isPending ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin me-1.5" />
|
||||
) : (
|
||||
<Scale className="w-4 h-4 me-1.5" />
|
||||
)}
|
||||
הרץ אימות-הלכות
|
||||
</Button>
|
||||
<span className="text-[0.7rem] text-ink-muted">
|
||||
סטטוס הריצה — בדף{" "}
|
||||
<a href="/operations" className="underline">
|
||||
התפעול
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* ── Exports list ── */}
|
||||
<section>
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
|
||||
@@ -44,13 +44,18 @@ const CATEGORIES = [
|
||||
{ value: "tabular", label: "טבלאי" },
|
||||
] as const;
|
||||
|
||||
const SOURCE_BADGE: Record<DecisionLesson["source"], { label: string; cls: string }> = {
|
||||
// All labels in Hebrew. Keyed loosely (string) so new sources — e.g. the
|
||||
// two-judge style panel — render correctly with a graceful fallback.
|
||||
const SOURCE_BADGE: Record<string, { label: string; cls: string }> = {
|
||||
manual: { label: "ידני", cls: "bg-rule-soft text-ink-soft" },
|
||||
chair: { label: "יו״ר", cls: "bg-gold-wash text-gold-deep" },
|
||||
curator: { label: "Curator", cls: "bg-info-bg text-info" },
|
||||
style_analyzer: { label: "Analyzer", cls: "bg-success-bg text-success" },
|
||||
curator: { label: "הרמס (סקירה)", cls: "bg-info-bg text-info" },
|
||||
style_analyzer: { label: "מנתח-סגנון", cls: "bg-success-bg text-success" },
|
||||
"panel:deepseek+gemini": { label: "פאנל: דיפסיק+גמיני", cls: "bg-gold-wash text-gold-deep" },
|
||||
};
|
||||
|
||||
const SOURCE_BADGE_FALLBACK = { label: "פאנל", cls: "bg-rule-soft text-ink-soft" };
|
||||
|
||||
export function LessonsTab({ corpusId }: { corpusId: string }) {
|
||||
const { data, isPending } = useCorpusLessons(corpusId);
|
||||
const add = useAddLesson(corpusId);
|
||||
@@ -147,7 +152,7 @@ function LessonItem({
|
||||
const patch = usePatchLesson(corpusId);
|
||||
const del = useDeleteLesson(corpusId);
|
||||
|
||||
const sourceBadge = SOURCE_BADGE[lesson.source];
|
||||
const sourceBadge = SOURCE_BADGE[lesson.source] ?? SOURCE_BADGE_FALLBACK;
|
||||
const dirty = text !== lesson.lesson_text || category !== lesson.category;
|
||||
|
||||
const onSave = async () => {
|
||||
|
||||
@@ -181,6 +181,73 @@ export function useDeleteDraft(caseNumber: string) {
|
||||
});
|
||||
}
|
||||
|
||||
/* ── Chair's signed final decision — clean upload path + staged pipeline ── */
|
||||
|
||||
export type FinalUploadResult = {
|
||||
final_filename: string;
|
||||
training_copy: string;
|
||||
pair_id: string | null;
|
||||
draft_words: number;
|
||||
final_words: number;
|
||||
status: string;
|
||||
};
|
||||
|
||||
export type FinalTaskResult = {
|
||||
status: string;
|
||||
sub_issue_id?: string;
|
||||
curator_id?: string;
|
||||
reason?: string;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
/** Upload Dafna's signed final decision (distinct from "upload a revised draft"). */
|
||||
export function useUploadFinalDecision(caseNumber: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: async (file: File): Promise<FinalUploadResult> => {
|
||||
const form = new FormData();
|
||||
form.append("file", file);
|
||||
const res = await fetch(`/api/cases/${caseNumber}/final/upload`, {
|
||||
method: "POST",
|
||||
body: form,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const err = await res
|
||||
.json()
|
||||
.catch(() => ({ detail: "שגיאה בהעלאת ההחלטה הסופית" }));
|
||||
throw new Error(err.detail ?? "שגיאה בהעלאת ההחלטה הסופית");
|
||||
}
|
||||
return res.json() as Promise<FinalUploadResult>;
|
||||
},
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: exportsKeys.list(caseNumber) });
|
||||
qc.invalidateQueries({ queryKey: casesKeys.detail(caseNumber) });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** Staged step 1 — voice learning (Opus distillation + DeepSeek+Gemini style panel). */
|
||||
export function useRunFinalLearning(caseNumber: string) {
|
||||
return useMutation({
|
||||
mutationFn: () =>
|
||||
apiRequest<FinalTaskResult>(
|
||||
`/api/cases/${caseNumber}/final/run-learning`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
/** Staged step 2 — halacha validation (cited-halacha extraction + 3-judge panel). */
|
||||
export function useRunFinalHalacha(caseNumber: string) {
|
||||
return useMutation({
|
||||
mutationFn: () =>
|
||||
apiRequest<FinalTaskResult>(
|
||||
`/api/cases/${caseNumber}/final/run-halacha`,
|
||||
{ method: "POST" },
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useMarkFinal(caseNumber: string) {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
@@ -469,7 +469,9 @@ export type DecisionLesson = {
|
||||
style_corpus_id: string;
|
||||
lesson_text: string;
|
||||
category: "style" | "structure" | "lexicon" | "tabular" | "general";
|
||||
source: "manual" | "curator" | "chair" | "style_analyzer";
|
||||
// "panel:deepseek+gemini" — the two-judge style panel; (string) keeps it open
|
||||
// to future panel sources without a type break.
|
||||
source: "manual" | "curator" | "chair" | "style_analyzer" | (string & {});
|
||||
applied_to_skill: boolean;
|
||||
created_by: string;
|
||||
created_at: string;
|
||||
|
||||
Reference in New Issue
Block a user