import React, { useEffect, useMemo, useState } from "react";
export default function ConventionsTab({ owner, repo }) {
const [content, setContent] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState("");
const canUse = useMemo(() => Boolean(owner && repo), [owner, repo]);
async function load() {
if (!canUse) return;
setError("");
setBusy(true);
try {
const res = await fetch(`/api/repos/${owner}/${repo}/context`);
if (!res.ok) throw new Error(`Failed to load conventions (${res.status})`);
const data = await res.json();
// backend may return { context: "..."} or { conventions: "..."} depending on implementation
setContent(data.context || data.conventions || data.memory || data.text || "");
} catch (e) {
setError(e?.message || "Failed to load conventions");
} finally {
setBusy(false);
}
}
async function initialize() {
if (!canUse) return;
setError("");
setBusy(true);
try {
const res = await fetch(`/api/repos/${owner}/${repo}/context/init`, {
method: "POST",
});
if (!res.ok) {
const txt = await res.text().catch(() => "");
throw new Error(`Init failed (${res.status}) ${txt}`);
}
await load();
} catch (e) {
setError(e?.message || "Init failed");
} finally {
setBusy(false);
}
}
useEffect(() => {
load();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [owner, repo]);
return (
Project Conventions
This is the project memory/conventions file used by GitPilot.
{error ?
{error}
: null}
{content ? (
{content}
) : (
No conventions found yet. Click Initialize to create default
project memory if supported.
)}
Editing conventions is intentionally not included here to keep this
feature additive/non-destructive. You can extend this later with an
explicit "Edit" mode.