Preserve repo Face identity metadata

This commit is contained in:
Meta Vens 2026-05-18 14:23:02 +01:00
commit 80f3a4ccc1

View file

@ -174,10 +174,12 @@ async function writeRepoFaceIdentity(
repoPath: string,
identityPath: string,
): Promise<void> {
const existing = await readExistingIdentity(identityPath);
await writeFile(
identityPath,
`${JSON.stringify(
{
...existing,
schemaVersion: "voidbot.repo_face_identity.v0",
identityId: identity.id,
repoName: identity.repoName,
@ -194,6 +196,17 @@ async function writeRepoFaceIdentity(
);
}
async function readExistingIdentity(identityPath: string): Promise<Record<string, unknown>> {
try {
const parsed = JSON.parse(stripLeadingBom(await readFile(identityPath, "utf8"))) as unknown;
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
? parsed as Record<string, unknown>
: {};
} catch {
return {};
}
}
async function writeReadmeIfMissing(path: string, content: string): Promise<void> {
if (existsSync(path)) {
return;