Files
vscode-cowriting-plugin/src/identity.ts
T
2026-06-10 23:00:03 -07:00

26 lines
847 B
TypeScript

/**
* Cross-rung identity (F5, spec §6.3 fork c): `email` is git's own join key —
* forges already map email → account. Resolved from the workspace git config,
* cached per root, FAIL-OPEN: absence just omits the optional field and the
* sidecar stays valid (spec §6.9). vscode-free, so it is unit-testable.
*/
import { execFileSync } from "node:child_process";
const cache = new Map<string, string | undefined>();
export function gitUserEmail(rootDir: string): string | undefined {
if (!cache.has(rootDir)) {
try {
const out = execFileSync("git", ["config", "user.email"], {
cwd: rootDir,
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
cache.set(rootDir, out || undefined);
} catch {
cache.set(rootDir, undefined);
}
}
return cache.get(rootDir);
}