import Link from 'next/link' import { redirect } from 'next/navigation' import { getCurrentUser } from '@/lib/session' import { execAgent } from '@/lib/agent-client' import { parseGitStatus } from '@/lib/parse-git' import DiffViewer from './_components/diff-viewer' export const dynamic = 'force-dynamic' type Props = { params: Promise<{ repo: string }> } function findRepoPath(repoName: string): string | null { const paths = (process.env.REPO_PATHS ?? '') .split(',') .map((p) => p.trim()) .filter(Boolean) return paths.find((p) => p.split('/').filter(Boolean).pop() === repoName) ?? null } export default async function GitRepoPage({ params }: Props) { const user = await getCurrentUser() if (!user) redirect('/login') const { repo } = await params const repoName = decodeURIComponent(repo) const repoPath = findRepoPath(repoName) if (!repoPath) { return (
← Repositories
Repo "{repoName}" not found in REPO_PATHS.
) } let statusSummary = '' let initialDiff = '' let initialError: string | null = null try { const [statusOut, diffOut] = await Promise.all([ execAgent('git_status', [repoPath]), execAgent('git_diff', [repoPath]), ]) const status = parseGitStatus(statusOut) statusSummary = `${status.branch}${status.dirty ? ' · dirty' : ' · clean'}${status.ahead ? ` · ↑${status.ahead} ahead` : ''}${status.behind ? ` · ↓${status.behind} behind` : ''}` initialDiff = diffOut } catch (err) { initialError = err instanceof Error ? err.message : 'Failed to fetch repo data' } return (
← Repositories /

{repoName}

{statusSummary && (
{repoPath} · {statusSummary}
)}

Uncommitted changes

) }