diff --git a/packages/core/src/repo-face-initializer.ts b/packages/core/src/repo-face-initializer.ts index 75df5b0..f685a26 100644 --- a/packages/core/src/repo-face-initializer.ts +++ b/packages/core/src/repo-face-initializer.ts @@ -174,10 +174,12 @@ async function writeRepoFaceIdentity( repoPath: string, identityPath: string, ): Promise { + 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> { + try { + const parsed = JSON.parse(stripLeadingBom(await readFile(identityPath, "utf8"))) as unknown; + return parsed && typeof parsed === "object" && !Array.isArray(parsed) + ? parsed as Record + : {}; + } catch { + return {}; + } +} + async function writeReadmeIfMissing(path: string, content: string): Promise { if (existsSync(path)) { return;