feat: bill action pipeline, What Changed UI, citation backfill, admin panel

Backend:
- Add fetch_bill_actions task with pagination and idempotent upsert
- Add fetch_actions_for_active_bills nightly batch (4 AM UTC beat schedule)
- Wire fetch_bill_actions into new-bill creation and _update_bill_if_changed
- Add backfill_brief_citations task: detects pre-citation briefs by JSONB
  type check, deletes them, re-queues LLM processing against stored text
  (LLM calls only — zero Congress.gov or GovInfo calls)
- Add admin endpoints: POST /bills/{id}/reprocess, /backfill-citations,
  /trigger-fetch-actions; add uncited_briefs count to /stats

Frontend:
- New BriefPanel component: wraps AIBriefCard, adds amber "What Changed"
  badge for amendment briefs and collapsible version history with
  inline brief expansion
- Swap AIBriefCard for BriefPanel on bill detail page
- Admin panel: Backfill Citations + Fetch Bill Actions buttons; amber
  warning in stats when uncited briefs remain
- Add feature roadmap document with phased plan through Phase 5

Co-Authored-By: Jack Levy
This commit is contained in:
Jack Levy
2026-03-01 03:03:29 -05:00
parent b57833d4b7
commit d5711312b8
9 changed files with 419 additions and 7 deletions

View File

@@ -4,12 +4,12 @@ import { use } from "react";
import Link from "next/link";
import { ArrowLeft, ExternalLink, User } from "lucide-react";
import { useBill, useBillTrend } from "@/lib/hooks/useBills";
import { AIBriefCard } from "@/components/bills/AIBriefCard";
import { BriefPanel } from "@/components/bills/BriefPanel";
import { ActionTimeline } from "@/components/bills/ActionTimeline";
import { TrendChart } from "@/components/bills/TrendChart";
import { NewsPanel } from "@/components/bills/NewsPanel";
import { FollowButton } from "@/components/shared/FollowButton";
import { billLabel, formatDate, partyBadgeColor, cn } from "@/lib/utils";
import { billLabel, congressLabel, formatDate, partyBadgeColor, cn } from "@/lib/utils";
export default function BillDetailPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = use(params);
@@ -46,7 +46,7 @@ export default function BillDetailPage({ params }: { params: Promise<{ id: strin
{label}
</span>
<span className="text-sm text-muted-foreground">{bill.chamber}</span>
<span className="text-sm text-muted-foreground">119th Congress</span>
<span className="text-sm text-muted-foreground">{congressLabel(bill.congress_number)}</span>
</div>
<h1 className="text-xl font-bold leading-snug">
{bill.short_title || bill.title || "Untitled Bill"}
@@ -80,7 +80,7 @@ export default function BillDetailPage({ params }: { params: Promise<{ id: strin
{/* Content grid */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 md:gap-6">
<div className="md:col-span-2 space-y-6">
<AIBriefCard brief={bill.latest_brief} />
<BriefPanel briefs={bill.briefs} />
<ActionTimeline actions={bill.actions} />
</div>
<div className="space-y-4">

View File

@@ -149,6 +149,11 @@ export default function SettingsPage() {
style={{ width: `${pct}%` }}
/>
</div>
{stats.uncited_briefs > 0 && (
<p className="text-xs text-amber-600 dark:text-amber-400">
{stats.uncited_briefs.toLocaleString()} brief{stats.uncited_briefs !== 1 ? "s" : ""} missing citations run Backfill Citations to fix
</p>
)}
</div>
</>
) : (
@@ -352,6 +357,18 @@ export default function SettingsPage() {
>
<RefreshCw className="w-3.5 h-3.5" /> Backfill Sponsors
</button>
<button
onClick={() => trigger("citations", adminAPI.backfillCitations)}
className="flex items-center gap-2 px-4 py-2 text-sm bg-amber-100 text-amber-800 hover:bg-amber-200 dark:bg-amber-900/30 dark:text-amber-300 dark:hover:bg-amber-900/50 rounded-md transition-colors"
>
<RefreshCw className="w-3.5 h-3.5" /> Backfill Citations
</button>
<button
onClick={() => trigger("actions", adminAPI.triggerFetchActions)}
className="flex items-center gap-2 px-4 py-2 text-sm bg-muted hover:bg-accent rounded-md transition-colors"
>
<RefreshCw className="w-3.5 h-3.5" /> Fetch Bill Actions
</button>
</div>
{Object.entries(taskIds).map(([name, id]) => (
<p key={name} className="text-xs text-muted-foreground">{name}: task {id} queued</p>

View File

@@ -0,0 +1,116 @@
"use client";
import { useState } from "react";
import { ChevronDown, ChevronRight, RefreshCw } from "lucide-react";
import { BriefSchema } from "@/lib/types";
import { AIBriefCard } from "@/components/bills/AIBriefCard";
import { formatDate } from "@/lib/utils";
interface BriefPanelProps {
briefs?: BriefSchema[] | null;
}
const TYPE_LABEL: Record<string, string> = {
amendment: "AMENDMENT",
full: "FULL",
};
function typeBadge(briefType?: string) {
const label = TYPE_LABEL[briefType ?? ""] ?? (briefType?.toUpperCase() ?? "BRIEF");
const isAmendment = briefType === "amendment";
return (
<span
className={`text-xs font-mono px-1.5 py-0.5 rounded ${
isAmendment
? "bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-400"
: "bg-muted text-muted-foreground"
}`}
>
{label}
</span>
);
}
export function BriefPanel({ briefs }: BriefPanelProps) {
const [historyOpen, setHistoryOpen] = useState(false);
const [expandedId, setExpandedId] = useState<number | null>(null);
if (!briefs || briefs.length === 0) {
return <AIBriefCard brief={null} />;
}
const latest = briefs[0];
const history = briefs.slice(1);
const isAmendment = latest.brief_type === "amendment";
return (
<div className="space-y-3">
{/* "What Changed" badge row */}
{isAmendment && (
<div className="flex items-center gap-2 px-1">
<RefreshCw className="w-3.5 h-3.5 text-amber-500" />
<span className="text-sm font-semibold text-amber-600 dark:text-amber-400">
What Changed
</span>
<span className="text-xs text-muted-foreground">·</span>
<span className="text-xs text-muted-foreground">{formatDate(latest.created_at)}</span>
</div>
)}
{/* Latest brief */}
<AIBriefCard brief={latest} />
{/* Version history (only when there are older briefs) */}
{history.length > 0 && (
<div className="bg-card border border-border rounded-lg overflow-hidden">
<button
onClick={() => setHistoryOpen((o) => !o)}
className="w-full flex items-center gap-2 px-4 py-3 text-sm font-medium text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors text-left"
>
{historyOpen ? (
<ChevronDown className="w-3.5 h-3.5 shrink-0" />
) : (
<ChevronRight className="w-3.5 h-3.5 shrink-0" />
)}
Version History ({history.length} {history.length === 1 ? "version" : "versions"})
</button>
{historyOpen && (
<div className="border-t border-border divide-y divide-border">
{history.map((brief) => (
<div key={brief.id}>
<button
onClick={() =>
setExpandedId((id) => (id === brief.id ? null : brief.id))
}
className="w-full flex items-center gap-3 px-4 py-2.5 text-left hover:bg-accent/40 transition-colors"
>
<span className="text-xs text-muted-foreground w-20 shrink-0">
{formatDate(brief.created_at)}
</span>
{typeBadge(brief.brief_type)}
<span className="text-xs text-muted-foreground truncate flex-1">
{brief.summary?.slice(0, 120) ?? "No summary"}
{(brief.summary?.length ?? 0) > 120 ? "…" : ""}
</span>
{expandedId === brief.id ? (
<ChevronDown className="w-3 h-3 text-muted-foreground shrink-0" />
) : (
<ChevronRight className="w-3 h-3 text-muted-foreground shrink-0" />
)}
</button>
{expandedId === brief.id && (
<div className="px-4 pb-4">
<AIBriefCard brief={brief} />
</div>
)}
</div>
))}
</div>
)}
</div>
)}
</div>
);
}

View File

@@ -135,6 +135,7 @@ export interface AnalysisStats {
briefs_generated: number;
full_briefs: number;
amendment_briefs: number;
uncited_briefs: number;
remaining: number;
}
@@ -159,6 +160,10 @@ export const adminAPI = {
apiClient.post("/api/admin/trigger-trend-scores").then((r) => r.data),
backfillSponsors: () =>
apiClient.post("/api/admin/backfill-sponsors").then((r) => r.data),
backfillCitations: () =>
apiClient.post("/api/admin/backfill-citations").then((r) => r.data),
triggerFetchActions: () =>
apiClient.post("/api/admin/trigger-fetch-actions").then((r) => r.data),
getTaskStatus: (taskId: string) =>
apiClient.get(`/api/admin/task-status/${taskId}`).then((r) => r.data),
};