chore: codebase audit — remove dead code, unused deps, clean configs

Phase 1: Delete 19 dead component/service/tool files (4,200+ lines)
Phase 2: Remove 13 unused npm packages (Radix UI, shadcn utilities, ytdl-core, etc.)
Phase 3: Database schema — drop agent_delegations, add performance indexes
Phase 4: Remove 12 dead types from database.ts/analytics.ts/helpers.ts
Phase 5: Strip shadcn/ui theme from tailwind config
Phase 6: Clean env vars, fix broken imports (LocalKeyGate, MapViewer)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
“BeeRad”
2026-01-29 08:52:15 +11:00
co-authored by Claude Opus 4.5
parent 65d22315e1
commit 9b2db68751
33 changed files with 13 additions and 5683 deletions
-63
View File
@@ -1,63 +0,0 @@
import { NextRequest, NextResponse } from 'next/server';
import { CostAnalytics } from '@/services/analytics/costs';
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const period = searchParams.get('period') || 'week';
const agent = searchParams.get('agent');
const traceId = searchParams.get('trace_id');
const startDate = searchParams.get('start_date');
const endDate = searchParams.get('end_date');
if (traceId) {
const traceCosts = CostAnalytics.getCostsByTrace(traceId);
return NextResponse.json(traceCosts);
}
if (agent) {
const agentCosts = CostAnalytics.getCostsByAgent(
agent,
startDate || undefined,
endDate || undefined
);
return NextResponse.json(agentCosts);
}
const days = period === 'day' ? 1 : period === 'week' ? 7 : period === 'month' ? 30 : 7;
if (startDate && endDate) {
const dateRangeCosts = CostAnalytics.getCostsByDateRange(startDate, endDate);
return NextResponse.json(dateRangeCosts);
}
const now = new Date();
const start = new Date(now.getTime() - days * 24 * 60 * 60 * 1000);
const periodCosts = CostAnalytics.getCostsByDateRange(
start.toISOString(),
now.toISOString()
);
const cacheStats = CostAnalytics.getCacheEffectiveness(
start.toISOString(),
now.toISOString()
);
const dailyBreakdown = CostAnalytics.getDailyBreakdown(days);
return NextResponse.json({
period: period,
summary: periodCosts,
cache: cacheStats,
daily: dailyBreakdown,
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
console.error('❌ [Analytics] Error:', errorMessage);
return NextResponse.json(
{ error: errorMessage },
{ status: 500 }
);
}
}
-67
View File
@@ -1,67 +0,0 @@
import { NextResponse } from 'next/server';
import type { CacheStats } from '@/types/prompts';
declare global {
// eslint-disable-next-line no-var
var lastCacheStats: CacheStats | undefined;
}
export async function GET() {
try {
const stats = global.lastCacheStats;
if (!stats) {
return NextResponse.json({
error: 'No cache statistics available yet',
message: 'Send a message to ra-h to generate cache stats'
}, { status: 404 });
}
const hitRate = stats.cacheReadInputTokens > 0 ? 'HIT' : 'MISS';
const totalInputTokens = stats.inputTokens + stats.cacheCreationInputTokens + stats.cacheReadInputTokens;
// Cost calculation (Sonnet 4.5 pricing)
const baseCost = 3.0; // $3 per million input tokens
const writeCost = baseCost * 1.25; // $3.75 per million
const readCost = baseCost * 0.1; // $0.30 per million
const actualCost = (
(stats.inputTokens * baseCost) +
(stats.cacheCreationInputTokens * writeCost) +
(stats.cacheReadInputTokens * readCost)
) / 1_000_000;
const noCacheCost = (totalInputTokens * baseCost) / 1_000_000;
const costSavingsPercentage = noCacheCost > 0
? Math.round(((noCacheCost - actualCost) / noCacheCost) * 100)
: 0;
return NextResponse.json({
status: 'success',
timestamp: new Date().toISOString(),
lastRequest: {
hitRate,
tokens: {
cacheWrite: stats.cacheCreationInputTokens,
cacheRead: stats.cacheReadInputTokens,
regular: stats.inputTokens,
totalInput: totalInputTokens,
output: stats.outputTokens
},
savings: {
tokenPercentage: stats.savingsPercentage,
costPercentage: costSavingsPercentage,
actualCostUSD: actualCost.toFixed(6),
noCacheCostUSD: noCacheCost.toFixed(6),
savedUSD: (noCacheCost - actualCost).toFixed(6)
}
}
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
return NextResponse.json(
{ error: 'Failed to fetch cache stats', details: errorMessage },
{ status: 500 }
);
}
}
-28
View File
@@ -1,28 +0,0 @@
import { NextRequest } from 'next/server';
import { resultCache } from '@/services/tools/resultCache';
export async function GET(
request: NextRequest,
ctx: { params: Promise<{ id: string }> }
) {
try {
const { id } = await ctx.params; // Next.js 15: params is a Promise
const data = resultCache.get(id);
if (!data) {
return new Response(JSON.stringify({ success: false, error: 'Not found' }), {
status: 404,
headers: { 'Content-Type': 'application/json' }
});
}
return new Response(JSON.stringify({ success: true, data }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
return new Response(JSON.stringify({ success: false, error: e?.message || 'Failed' }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
}
+1 -6
View File
@@ -1,10 +1,5 @@
import ThreePanelLayout from '@/components/layout/ThreePanelLayout';
import { LocalKeyGate } from '@/components/auth/LocalKeyGate';
export default function Home() {
return (
<LocalKeyGate>
<ThreePanelLayout />
</LocalKeyGate>
);
return <ThreePanelLayout />;
}