Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 47 additions & 12 deletions artifacts/ai-context-analyzer/src/pages/analyzer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,46 @@ export default function AnalyzerPage() {

const { isPending, data, isError, error } = analyzeCodebase;
const apiError = error as any;
const handleExport = (type: "json" | "md") => {
if (!data || !data.results) return;

try {
if (type === "json") {
const blob = new Blob(
[JSON.stringify(data, null, 2)],
{ type: "application/json" }
);

const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "context.json";
a.click();
URL.revokeObjectURL(url);
}

if (type === "md") {
const md = `# AI Context Output

Query: ${data.query ?? ""}

Files Scanned: ${data.totalFilesScanned ?? 0}
Matches Found: ${data.results?.length ?? 0}
`;

const blob = new Blob([md], { type: "text/markdown" });
const url = URL.createObjectURL(blob);

const a = document.createElement("a");
a.href = url;
a.download = "context.md";
a.click();
URL.revokeObjectURL(url);
}
} catch (err) {
console.error("Export failed:", err);
}
};

return (
<div className="flex flex-col h-full">
Expand All @@ -89,18 +129,11 @@ export default function AnalyzerPage() {
Surface relevant files from a codebase using keyword matching and dependency tracing.
</p>
</div>

{data && (
<div className="flex items-center gap-3 text-sm shrink-0 ml-6">

{/* Export buttons */}
<Button
size="sm"
variant="outline"
onClick={() => handleExport("json")}
>
Export JSON
</Button>

{/* JSON Export */}
<Button
size="sm"
variant="outline"
Expand All @@ -110,14 +143,16 @@ export default function AnalyzerPage() {
JSON
</Button>

{/* Markdown Export */}
<Button
size="sm"
variant="outline"
onClick={() => handleExport("md")}
>

<FileText className="h-3.5 w-3.5 mr-1" />
MD
</Button>
</Button>

{/* Stats */}
<div className="text-right ml-3">
Expand All @@ -130,12 +165,12 @@ export default function AnalyzerPage() {
<div className="text-right">
<p className="text-muted-foreground text-xs mb-0.5">Matches found</p>
<p className="font-semibold font-mono text-primary">
{data.results.length}
{data.results?.length ?? 0}
</p>
</div>

</div>
)}
)}
</div>
</div>

Expand Down
Loading