Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.
JavaScript ai-codingclaudeclaude-codeclaude-code-pluginclicoding-agentsdeveloper-toolsgitllmtypescript
feat(init): warn when git has no user.email to credit sessions to
Erenbc0cf7a75d26
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 590dab0..da9f227 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Added+- `cogit init` warns when git has no `user.email`, since sessions are now told apart by it.- The map tells your sessions from your teammates': a teammate's session always shows their name and yours never needs to, the side panel marks yours "(you)", and a new Everyone / You / teammate choice in the toolbar fades the other people's sessions.### Changeddiff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.tsindex 6271fe7..d3272ee 100644--- a/packages/cli/src/commands/init.ts+++ b/packages/cli/src/commands/init.ts@@ -1,6 +1,7 @@import { mkdir } from "node:fs/promises";import { basename, resolve } from "node:path";import { defaultAgent } from "../agents/index.js";+import { sessionIdentity } from "../author.js";import {cogitIgnored,ensureCogitGitignore,@@ -224,6 +225,14 @@ export async function init(dir: string, opts: InitOptions, io: Io): Promise<void`${root} is not in a git repository; cogit ties its record to your commits, so run \`git init\` first`,);+ // A session is credited to the git identity (Story 9.3); without an email,+ // two teammates with one name would read as one person.+ if ((await sessionIdentity(root, io.env)).authorEmail === undefined)+ io.warn(+ "git has no user.email here; cogit tells people's sessions apart by it, so set one: " ++ "git config --global user.email [email protected]",+ );+const name = opts.name ?? (await io.prompt.input("Project name?", basename(root)));const config = await loadConfig(io.env);diff --git a/packages/cli/test/init.test.ts b/packages/cli/test/init.test.tsindex 3df0ffc..236d6d2 100644--- a/packages/cli/test/init.test.ts+++ b/packages/cli/test/init.test.ts@@ -31,6 +31,9 @@ beforeEach(async () => {const settingsFile = () => join(dir, "claude", "settings.json");const readText = (f: string) => readFile(f, "utf8");+/** The warnings a test is about; the test repos have no git email, which init also notes. */+const warningsOf = (io: { warnings: string[] }) =>+ io.warnings.filter((w) => !w.startsWith("git has no user.email"));describe("init", () => {it("leaves project settings it cannot read alone and says so", async () => {@@ -212,8 +215,8 @@ describe("init", () => {await writeFile(settingsFile(), "{oops");const io = fakeIo(env);await init(root, {}, io);- expect(io.warnings[0]).toMatch(/retention left unchanged/);- expect(io.warnings[1]).toMatch(/add Skill\(cogit:record\) to permissions.allow yourself/);+ expect(warningsOf(io)[0]).toMatch(/retention left unchanged/);+ expect(warningsOf(io)[1]).toMatch(/add Skill\(cogit:record\) to permissions.allow yourself/);expect(await readText(settingsFile())).toBe("{oops");});@@ -261,7 +264,7 @@ describe("init", () => {await writeFile(settingsFile(), JSON.stringify({ permissions: { allow: "all" } }));const io = fakeIo(env);await init(root, {}, io);- expect(io.warnings[0]).toMatch(/could not read Claude Code permissions/);+ expect(warningsOf(io)[0]).toMatch(/could not read Claude Code permissions/);expect(JSON.parse(await readText(settingsFile()))).toEqual({ permissions: { allow: "all" } });});@@ -292,7 +295,7 @@ describe("init", () => {await writeFile(join(dir, "home"), "a file, not a dir");const io = fakeIo(env);await init(root, {}, io);- expect(io.warnings.map((w) => w.split(":")[0])).toEqual([+ expect(warningsOf(io).map((w) => w.split(":")[0])).toEqual(["could not save global config","could not register the project in the global panel",]);@@ -341,6 +344,21 @@ describe("git helpers", () => {expect(existsSync(join(root, ".git", "hooks", "prepare-commit-msg"))).toBe(true);});+ it("warns when git has no email to tell this person's sessions apart by", async () => {+ const run = promisify(execFile);+ const git = (...args: string[]) => run("git", ["-C", root, ...args]);+ await git("init", "-q");+ const options = { name: "P", retention: "keep", allowSkill: false, language: "auto" } as const;+ const bare = fakeIo(env);+ await init(root, options, bare);+ expect(bare.warnings.join("\n")).toMatch(/no user\.email/);+ await rm(join(root, ".cogit"), { recursive: true });+ await git("config", "user.email", "[email protected]");+ const set = fakeIo(env);+ await init(root, options, set);+ expect(set.warnings.join("\n")).not.toMatch(/user\.email/);+ });+it("restores the record hook when init runs again on a commit project", async () => {const run = promisify(execFile);const git = (...args: string[]) => run("git", ["-C", root, ...args]);