feat(knowledge-flywheel): add Phase 3 Knowledge Flywheel — AI analysis, review queue, analytics
Phase 3 implementation: - AI session analysis service that generates flow proposals from resolved sessions - APScheduler job for batch processing pending analyses (max_instances=1) - Knowledge gap detection (weak options, high escalation signals) - Flow proposals CRUD with team admin review workflow (approve/edit/dismiss/reject) - FlowPilot analytics dashboard with confidence tiers, PSA metrics, knowledge gaps - In-session script generator component - Review queue page with filtering and proposal detail panel Bug fixes from review (12 total): - Fix "Edit & Publish" navigating to non-existent /editor/new route - Hide Approve button for enhancement proposals (require Edit & Publish) - Add max_instances=1 to scheduler to prevent TOCTOU race - Fix eventual_success case() double-counting failed retries - Add tree_structure validation before creating tree from proposal - Simplify script generator rendering condition - Add severity style fallback, toFixed on rates, Link instead of <a href> - Add toast.warning on dismiss failure, fix dedup for domain-less sessions - Cast Decimal to int in knowledge gap evidence dicts Also updates CLAUDE.md with lessons 67-71 and Phase 3 project structure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
51
backend/app/schemas/flow_proposal.py
Normal file
51
backend/app/schemas/flow_proposal.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""Pydantic schemas for flow proposals (Knowledge Flywheel / Review Queue)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, Any
|
||||
from uuid import UUID
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class FlowProposalSummary(BaseModel):
|
||||
"""Compact proposal for list views."""
|
||||
id: UUID
|
||||
proposal_type: str
|
||||
title: str
|
||||
description: str | None = None
|
||||
problem_domain: str | None = None
|
||||
confidence_score: float
|
||||
supporting_session_count: int
|
||||
status: str
|
||||
target_flow_id: UUID | None = None
|
||||
source_session_id: UUID
|
||||
created_at: datetime
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class FlowProposalDetail(FlowProposalSummary):
|
||||
"""Full proposal detail with flow data."""
|
||||
proposed_flow_data: dict[str, Any]
|
||||
proposed_diff: dict[str, Any] | None = None
|
||||
supporting_session_ids: list[str] = []
|
||||
reviewer_notes: str | None = None
|
||||
reviewed_by: UUID | None = None
|
||||
reviewed_at: datetime | None = None
|
||||
|
||||
|
||||
class ReviewProposalRequest(BaseModel):
|
||||
"""Review action on a proposal."""
|
||||
action: str = Field(..., pattern="^(approve|reject|modify|dismiss)$")
|
||||
reviewer_notes: str | None = None
|
||||
modified_flow_data: dict[str, Any] | None = None # Only for "modify"
|
||||
|
||||
|
||||
class FlowProposalStats(BaseModel):
|
||||
"""Dashboard stats for the review queue."""
|
||||
pending_count: int
|
||||
approved_this_week: int
|
||||
rejected_this_week: int
|
||||
auto_reinforced_this_week: int
|
||||
top_domains: list[dict[str, Any]] = [] # [{domain, count}]
|
||||
Reference in New Issue
Block a user