disclosure-bureau/web/app/c/[slug]/page.tsx

112 lines
4 KiB
TypeScript
Raw Normal View History

W3.8: Investigation Bureau complete — Poirot, Taleb, Tetlock, Case-Writer Brings the bureau from 4 → 8 detectives. All eight run as Bun + claude-CLI subprocesses against the same Supabase + investigation_jobs LISTEN/NOTIFY queue, sharing search.ts hybridSearch and writer-side validators that gate writes against schema + FK. New detectives: Poirot (witness_analysis) - prompts/poirot.md — credibility / access / bias / corroboration / verdict; uses entity_mentions JOIN chunks to pull 12 chunks per person; resolves corroboration_refs chunk_ids defensively (accepts bare cNNNN even when the model emits pNNN/cNNNN). - INSERT into public.witnesses with W-NNNN naming. - Tone: purple (#9b5de5). Taleb (outlier_scan) - prompts/taleb.md — "surprise is relative to a model"; at most 3 outliers; each requires explicit dominant_model + why_surprising + what_it_implies; fan-out into public.gaps with scope.kind="outlier". - Same unscoped-fallback as Dupin (Pass 1 with doc_id, Pass 2 widens to corpus if hits < 3). - Tone: yellow (#ffd23f). Tetlock (calibrate_hypothesis) - prompts/tetlock.md — honest Bayesian update; emits new_posterior + Δ + recommended_action ∈ {keep, downgrade, upgrade, supersede}. - write_calibration UPDATEs public.hypotheses + APPENDS a "## Calibration history" section to the H-NNNN.md case file (calibration is append-only — each datapoint matters). Posterior band auto-corrected to match Tetlock thresholds. - NO_NEW_EVIDENCE sentinel handled; pure 'keep' with |Δ|<0.005 only touches updated_at + reviewed_by. - Tone: teal (#26d4cc). Case-Writer (case_report) - prompts/case-writer.md — Dr. Watson assembles all artefacts (E-NNNN, H-NNNN, R-NNNN, W-NNNN, G-NNNN) into a five-act narrative. ILIKE filter on topic; doc_id optional scope. - Larger budget cap (≥ $0.50) + longer timeout for prose generation. - Writes case/reports/<slug>.md with frontmatter (topic + counts); no DB table for v0. - New page /c/[slug] renders the report via MarkdownBody + stat chips. - Tone: gold (#e0c080). Hardening across the bureau: - Sentinel parsing now accepts backticked AND prose-trailing forms (Holmes NO_HYPOTHESES, Dupin NO_CONTRADICTIONS, Schneier INSUFFICIENT_HYPOTHESIS, Poirot INSUFFICIENT_TESTIMONY, Taleb NO_OUTLIERS, Tetlock NO_NEW_EVIDENCE, Case-Writer INSUFFICIENT_ARTEFACTS). Avoids the failure mode where the model refuses honestly but the runtime treated it as a parse error (observed live with Poirot+Hoover identifying the DIRECTOR false-positive disambiguation issue in entity_mentions). Chat tool extensions (web/lib/chat/tools.ts): - request_investigation now accepts 7 kinds. Each routes to its detective with appropriate validation (hypothesis_id regex, person_id kebab-case, topic non-empty, doc_id for evidence_chain). - ETA per kind: Holmes/Dupin 60s, Poirot 45s, Schneier/Tetlock 30s, Taleb 50s, Case-Writer 180s (longer prose), Locard 30×n_chunks. UI integration: - chat-bubble inline card paints each detective in its tone color. - /jobs/[id] page header swaps name/subtitle/tone per detective; question label adapts ("Topic" / "Hypothesis under attack" / "Witness under analysis" / "Topic to outlier-scan" / "Hypothesis under recalibration" / "Case to assemble"). - job-status-poller renders: case-report link card (gold), outlier cards (yellow), witness cards (purple) — alongside existing hypothesis, evidence, contradiction cards. - /api/jobs/[id] hydrates witnesses (JOIN entities for canonical_name) + gaps (with scope JSONB). - /c/[slug] page reads /data/ufo/case/reports/<slug>.md and renders with MarkdownBody, frontmatter parsed for stat chips. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 01:11:39 +00:00
/**
* /c/[slug] Case report viewer.
*
* Reads /data/ufo/case/reports/<slug>.md, parses frontmatter for metadata,
* renders the markdown body via MarkdownBody. The case-writer detective
* writes these files; this page is the reader.
*/
import { notFound } from "next/navigation";
import Link from "next/link";
import { readFile } from "node:fs/promises";
import path from "node:path";
import { MarkdownBody } from "@/components/markdown-body";
import { AuthBar } from "@/components/auth-bar";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
const CASE_ROOT = process.env.CASE_ROOT || "/data/ufo/case";
interface Frontmatter {
topic?: string;
created_by?: string;
created_at?: string;
job_id?: string;
n_evidence?: number;
n_hypotheses?: number;
n_contradictions?: number;
n_witnesses?: number;
n_outliers?: number;
}
function parseFrontmatter(md: string): { fm: Frontmatter; body: string } {
const m = md.match(/^---\n([\s\S]+?)\n---\n([\s\S]*)$/);
if (!m) return { fm: {}, body: md };
const fm: Frontmatter = {};
for (const line of m[1].split("\n")) {
const kv = line.match(/^([a-z_]+):\s*(.+)$/);
if (!kv) continue;
const k = kv[1] as keyof Frontmatter;
let v: string | number = kv[2].trim();
if (v.startsWith('"') && v.endsWith('"')) v = v.slice(1, -1);
if (k === "n_evidence" || k === "n_hypotheses" || k === "n_contradictions"
|| k === "n_witnesses" || k === "n_outliers") {
const n = Number(v);
if (Number.isFinite(n)) (fm[k] as number) = n;
} else {
(fm[k] as string) = v as string;
}
}
return { fm, body: m[2] };
}
export default async function CaseReportPage({
params,
}: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) notFound();
let md: string;
try {
md = await readFile(path.join(CASE_ROOT, "reports", `${slug}.md`), "utf-8");
} catch {
notFound();
}
const { fm, body } = parseFrontmatter(md);
const stats: Array<{ label: string; value: number | undefined; color: string }> = [
{ label: "evidence", value: fm.n_evidence, color: "text-[#06d6a0]" },
{ label: "hypotheses", value: fm.n_hypotheses, color: "text-[#7fdbff]" },
{ label: "contradictions", value: fm.n_contradictions, color: "text-[#ff8a4d]" },
{ label: "witnesses", value: fm.n_witnesses, color: "text-[#9b5de5]" },
{ label: "outliers", value: fm.n_outliers, color: "text-[#ffd23f]" },
];
return (
<div className="min-h-screen bg-[#0a0e1a] text-[#e7ecf3]">
<AuthBar />
<div className="mx-auto max-w-3xl px-4 py-8 pt-16">
<div className="text-[11px] text-[#5a6678] font-mono mb-2">
<Link href="/" className="hover:text-[#7fdbff]">disclosure.top</Link>
<span className="mx-1">/</span>
<span>case-report</span>
<span className="mx-1">/</span>
<span className="text-[#e0c080]">{slug}</span>
</div>
<div className="rounded-lg border border-[rgba(224,192,128,0.18)] bg-gradient-to-br from-[rgba(224,192,128,0.06)] to-transparent p-4 mb-6">
<div className="text-[10px] font-mono text-[#5a6678] uppercase mb-2">
Case report{fm.created_by && <> · written by <span className="text-[#e0c080]">{fm.created_by}</span></>}
{fm.created_at && <> · {fm.created_at}</>}
</div>
{fm.topic && (
<h1 className="text-xl font-mono text-[#e7ecf3] leading-snug">{fm.topic}</h1>
)}
<div className="mt-3 flex flex-wrap gap-3 text-[10px] font-mono">
{stats.filter((s) => typeof s.value === "number").map((s) => (
<span key={s.label}>
<span className={s.color}>{s.value}</span>
<span className="text-[#5a6678] ml-1">{s.label}</span>
</span>
))}
</div>
</div>
<article className="prose prose-invert prose-sm max-w-none">
<MarkdownBody>{body}</MarkdownBody>
</article>
</div>
</div>
);
}