tftsr-devops_investigation/src/pages/RCA/index.tsx
Shaun Arman 13c4969e31 feat: wire incident response methodology into AI and record triage events
Add INCIDENT_RESPONSE_FRAMEWORK to domainPrompts.ts and append it to
all 17 domain prompts via getDomainPrompt(). Add system_prompt param
to chat_message command so frontend can inject domain expertise. Record
UTC timeline events (triage_started, log_uploaded, why_level_advanced,
root_cause_identified, rca_generated, postmortem_generated,
document_exported) at key moments with non-blocking calls.

Update tauriCommands.ts with getTimelineEventsCmd, optional metadata on
addTimelineEventCmd, and systemPrompt on chatMessageCmd.

12 new frontend tests (9 domain prompts, 3 timeline events).
2026-04-19 18:13:47 -05:00

113 lines
3.5 KiB
TypeScript

import React, { useEffect, useState } from "react";
import { useParams, useNavigate, Link } from "react-router-dom";
import { ChevronRight } from "lucide-react";
import { Button } from "@/components/ui";
import { DocEditor } from "@/components/DocEditor";
import { useSettingsStore } from "@/stores/settingsStore";
import {
generateRcaCmd,
updateDocumentCmd,
exportDocumentCmd,
addTimelineEventCmd,
type Document_,
} from "@/lib/tauriCommands";
export default function RCA() {
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
void useSettingsStore((s) => s.getActiveProvider);
const [doc, setDoc] = useState<Document_ | null>(null);
const [content, setContent] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!id) return;
const load = async () => {
setIsLoading(true);
try {
const generated = await generateRcaCmd(id);
setDoc(generated);
setContent(generated.content_md);
addTimelineEventCmd(id, "rca_generated", "RCA document generated").catch(() => {});
} catch (err) {
setError(String(err));
} finally {
setIsLoading(false);
}
};
load();
}, [id]);
const handleContentChange = async (newContent: string) => {
setContent(newContent);
if (doc) {
try {
const updated = await updateDocumentCmd(doc.id, newContent);
setDoc(updated);
} catch (err) {
setError(String(err));
}
}
};
const handleExport = async (format: "md" | "pdf" | "docx") => {
if (!doc) return;
try {
const path = await exportDocumentCmd(doc.id, doc.title, content, format, "");
setError(`Document exported to: ${path}`);
addTimelineEventCmd(id!, "document_exported", `RCA exported as ${format}`).catch(() => {});
setTimeout(() => setError(null), 5000);
} catch (err) {
setError(`Export failed: ${String(err)}`);
}
};
return (
<div className="p-6 space-y-4 h-full flex flex-col">
{/* Breadcrumb */}
<nav className="flex items-center gap-1 text-sm text-muted-foreground">
<Link to={`/issue/${id}/triage`} className="hover:text-foreground">
Triage
</Link>
<ChevronRight className="w-3 h-3" />
<Link to={`/issue/${id}/resolution`} className="hover:text-foreground">
Resolution
</Link>
<ChevronRight className="w-3 h-3" />
<span className="text-foreground font-medium">RCA</span>
</nav>
<div className="flex items-center justify-between">
<h1 className="text-3xl font-bold">Root Cause Analysis</h1>
<Button onClick={() => navigate(`/issue/${id}/postmortem`)}>
Proceed to Post-Mortem
<ChevronRight className="w-4 h-4 ml-1" />
</Button>
</div>
{error && (
<div className="text-sm text-destructive bg-destructive/10 rounded-md p-3">
{error}
</div>
)}
{isLoading ? (
<div className="flex-1 flex items-center justify-center">
<p className="text-muted-foreground">Generating RCA document...</p>
</div>
) : (
<div className="flex-1 min-h-0">
<DocEditor
content={content}
onChange={handleContentChange}
updatedAt={doc?.updated_at?.toString()}
onExport={handleExport}
/>
</div>
)}
</div>
);
}