Skip to content

Commit 227044c

Browse files
devakoneclaude
andcommitted
fix: use vibe_insights (v2) for repo VCP pages to match unified profile
The Repo VCPs and Analysis listing pages were reading from the legacy analysis_insights table, while the unified profile reads from vibe_insights. This caused persona mismatches (e.g., "Rapid Risk-Taker" on repo pages but "Agent Orchestrator" on unified profile). Now both pages query vibe_insights first and fall back to analysis_insights for older jobs that don't have v2 data. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ecefd95 commit 227044c

2 files changed

Lines changed: 80 additions & 22 deletions

File tree

apps/web/src/app/analysis/page.tsx

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ type JobRow = {
1515
error_message: string | null;
1616
};
1717

18-
type InsightRow = {
18+
type VibeInsightRow = {
19+
job_id: string;
20+
persona_name: string | null;
21+
persona_confidence: string | null;
22+
generated_at: string | null;
23+
};
24+
25+
type LegacyInsightRow = {
1926
job_id: string;
2027
persona_label: string | null;
2128
persona_confidence: string | null;
@@ -54,33 +61,55 @@ export default async function AnalysisIndexPage() {
5461
repoNameById.set(row.id, row.full_name);
5562
}
5663

57-
// Get insights for completed jobs
64+
// Get vibe insights (v2) for completed jobs
5865
const jobIds = jobs.map((j) => j.id);
59-
const insightsResult =
66+
const vibeInsightsResult =
6067
jobIds.length > 0
68+
? await supabase
69+
.from("vibe_insights")
70+
.select("job_id, persona_name, persona_confidence, generated_at")
71+
.in("job_id", jobIds)
72+
: null;
73+
74+
const vibeInsightByJobId = new Map<string, VibeInsightRow>();
75+
for (const row of (vibeInsightsResult?.data ?? []) as VibeInsightRow[]) {
76+
vibeInsightByJobId.set(row.job_id, row);
77+
}
78+
79+
// Find jobs missing from vibe_insights and fetch from legacy analysis_insights
80+
const missingJobIds = jobIds.filter((id) => !vibeInsightByJobId.has(id));
81+
const legacyInsightsResult =
82+
missingJobIds.length > 0
6183
? await supabase
6284
.from("analysis_insights")
6385
.select("job_id, persona_label, persona_confidence, generated_at")
64-
.in("job_id", jobIds)
86+
.in("job_id", missingJobIds)
6587
: null;
6688

67-
const insightByJobId = new Map<string, InsightRow>();
68-
for (const row of (insightsResult?.data ?? []) as InsightRow[]) {
69-
insightByJobId.set(row.job_id, row);
89+
const legacyInsightByJobId = new Map<string, LegacyInsightRow>();
90+
for (const row of (legacyInsightsResult?.data ?? []) as LegacyInsightRow[]) {
91+
legacyInsightByJobId.set(row.job_id, row);
7092
}
7193

7294
// Build reports list (completed jobs, with insight data when available)
7395
const reports = jobs
7496
.filter((j) => j.status === "done")
7597
.map((j) => {
76-
const insight = insightByJobId.get(j.id);
98+
const vibeInsight = vibeInsightByJobId.get(j.id);
99+
const legacyInsight = legacyInsightByJobId.get(j.id);
100+
101+
// Use vibe_insights (v2) if available, fall back to analysis_insights (legacy)
102+
const personaLabel = vibeInsight?.persona_name ?? legacyInsight?.persona_label ?? null;
103+
const personaConfidence = vibeInsight?.persona_confidence ?? legacyInsight?.persona_confidence ?? null;
104+
const generatedAt = vibeInsight?.generated_at ?? legacyInsight?.generated_at ?? j.created_at;
105+
77106
return {
78107
jobId: j.id,
79108
repoId: j.repo_id,
80109
repoName: repoNameById.get(j.repo_id) ?? null,
81-
personaLabel: insight?.persona_label ?? null,
82-
personaConfidence: insight?.persona_confidence ?? null,
83-
generatedAt: insight?.generated_at ?? j.created_at,
110+
personaLabel,
111+
personaConfidence,
112+
generatedAt,
84113
status: j.status,
85114
};
86115
});

apps/web/src/app/vibes/page.tsx

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ type JobRow = {
1818
created_at: string;
1919
};
2020

21-
type InsightRow = {
21+
type VibeInsightRow = {
22+
job_id: string;
23+
persona_name: string | null;
24+
persona_confidence: string | null;
25+
generated_at: string | null;
26+
};
27+
28+
type LegacyInsightRow = {
2229
job_id: string;
2330
persona_label: string | null;
2431
persona_confidence: string | null;
@@ -74,18 +81,33 @@ export default async function VibesPage() {
7481
const jobs = (jobsData ?? []) as JobRow[];
7582
const jobIds = jobs.map((j) => j.id);
7683

77-
// Fetch insights for completed jobs
78-
const { data: insightsData } =
84+
// Fetch vibe insights (v2) for completed jobs
85+
const { data: vibeInsightsData } =
7986
jobIds.length > 0
87+
? await supabase
88+
.from("vibe_insights")
89+
.select("job_id, persona_name, persona_confidence, generated_at")
90+
.in("job_id", jobIds)
91+
: { data: [] };
92+
93+
const vibeInsightByJobId = new Map<string, VibeInsightRow>();
94+
for (const row of (vibeInsightsData ?? []) as VibeInsightRow[]) {
95+
vibeInsightByJobId.set(row.job_id, row);
96+
}
97+
98+
// Find jobs missing from vibe_insights and fetch from legacy analysis_insights
99+
const missingJobIds = jobIds.filter((id) => !vibeInsightByJobId.has(id));
100+
const { data: legacyInsightsData } =
101+
missingJobIds.length > 0
80102
? await supabase
81103
.from("analysis_insights")
82104
.select("job_id, persona_label, persona_confidence, generated_at")
83-
.in("job_id", jobIds)
105+
.in("job_id", missingJobIds)
84106
: { data: [] };
85107

86-
const insightByJobId = new Map<string, InsightRow>();
87-
for (const row of (insightsData ?? []) as InsightRow[]) {
88-
insightByJobId.set(row.job_id, row);
108+
const legacyInsightByJobId = new Map<string, LegacyInsightRow>();
109+
for (const row of (legacyInsightsData ?? []) as LegacyInsightRow[]) {
110+
legacyInsightByJobId.set(row.job_id, row);
89111
}
90112

91113
// Fetch metrics for commit counts
@@ -114,14 +136,21 @@ export default async function VibesPage() {
114136
const repos = connectedRepos.map((repo) => {
115137
const repoJobs = jobsByRepoId.get(repo.repoId) ?? [];
116138
const versions = repoJobs.map((job) => {
117-
const insight = insightByJobId.get(job.id);
139+
const vibeInsight = vibeInsightByJobId.get(job.id);
140+
const legacyInsight = legacyInsightByJobId.get(job.id);
118141
const metrics = metricsByJobId.get(job.id);
142+
143+
// Use vibe_insights (v2) if available, fall back to analysis_insights (legacy)
144+
const personaLabel = vibeInsight?.persona_name ?? legacyInsight?.persona_label ?? null;
145+
const personaConfidence = vibeInsight?.persona_confidence ?? legacyInsight?.persona_confidence ?? null;
146+
const generatedAt = vibeInsight?.generated_at ?? legacyInsight?.generated_at ?? job.created_at;
147+
119148
return {
120149
jobId: job.id,
121-
personaLabel: insight?.persona_label ?? null,
122-
personaConfidence: insight?.persona_confidence ?? null,
150+
personaLabel,
151+
personaConfidence,
123152
commitCount: metrics?.commit_count ?? null,
124-
generatedAt: insight?.generated_at ?? job.created_at,
153+
generatedAt,
125154
};
126155
});
127156

0 commit comments

Comments
 (0)