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
fix(pr): say where a teammate's missing thought may be
Erenc9b2b9f44156
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4068d98..5340680 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- After upgrading from a version that committed the record, `cogit doctor` asks you to commit the rewritten `.cogit/.gitignore` too; without it teammates and new clones saw `.cogit/sessions/` in `git status`.- A map with thousands of sessions no longer freezes on "Unfold all" and "Fold all": only the open sessions near the screen are drawn, and the session list no longer does quadratic work (10,000 sessions: 11 s down to 2 s).- `cogit init --help` and `cogit config git --help` named the removed `commit` policy; they now say `share` or `ignore`.+- `cogit pr` and `cogit show <sha>` no longer tell a reviewer that a teammate's thought is "not recorded yet" when it may never arrive: for someone else's commit they say it is not in this clone's record, because its author has not pushed it or it came from a fork.## [1.0.0] - 2026-11-04### Changeddiff --git a/packages/cli/src/commands/log.ts b/packages/cli/src/commands/log.tsindex aff28f9..f11aca5 100644--- a/packages/cli/src/commands/log.ts+++ b/packages/cli/src/commands/log.ts@@ -1,4 +1,10 @@-import { findGitRoot, projectFiles, readCommitFiles, readCommitSubjects } from "../git.js";+import {+ findGitRoot,+ gitUserEmail,+ projectFiles,+ readCommitFiles,+ readCommitSubjects,+} from "../git.js";import { CliError, type Io } from "../io.js";import { readSessionMessages, type SessionMessage, upgradeSessionIds } from "../messages.js";import type { LineageNode, Session } from "../schema/session.js";@@ -8,6 +14,7 @@ import { loadAllSessions, loadProject } from "../store/stores.js";import {attachThoughtTrailers,earliestSessionStart,+ readCommitAuthorEmail,readCommitThought,readThoughtTrailers,} from "../thought.js";@@ -546,10 +553,17 @@ export async function show(opts: ShowOptions): Promise<ShowModel> {const thought = COMMIT_REF.test(opts.ref)? await readCommitThought(root, opts.ref, opts.io.env): undefined;- if (thought !== undefined)+ if (thought !== undefined) {+ const author = await readCommitAuthorEmail(root, opts.ref, opts.io.env);+ const me = await gitUserEmail(root, opts.io.env);+ const others =+ author !== undefined && me !== undefined && author.toLowerCase() !== me.toLowerCase();throw new CliError(- `commit ${opts.ref} comes from thought ${thought}, which is not recorded yet; it appears after the next record update`,+ others+ ? `commit ${opts.ref} comes from thought ${thought}, which is not in this clone's record: its author has not pushed it yet, or the commit came from a fork, whose record stays in the fork`+ : `commit ${opts.ref} comes from thought ${thought}, which is not recorded yet; it appears after the next record update`,);+ }throw new CliError(result.reason);}if (result.kind === "ambiguous") {diff --git a/packages/cli/src/commands/pr.ts b/packages/cli/src/commands/pr.tsindex 3f86dba..d9101a4 100644--- a/packages/cli/src/commands/pr.ts+++ b/packages/cli/src/commands/pr.ts@@ -1,6 +1,6 @@import { execFile, spawn } from "node:child_process";import { promisify } from "node:util";-import { cogitIgnored, findGitRoot, readCommitFiles } from "../git.js";+import { cogitIgnored, findGitRoot, gitUserEmail, readCommitFiles } from "../git.js";import { CliError, type Io } from "../io.js";import { earliestSessionStart, readThoughtTrailers } from "../thought.js";import type { ViewNode } from "../view/model.js";@@ -38,6 +38,8 @@ export interface PrCommit {short: string;at: string;subject: string;+ /** The author's email, so a missing thought can be told apart: one's own, or someone else's. */+ authorEmail?: string;/** The messages the commit names; a squash can name several. */thoughts?: string[];/** Repository-relative paths; empty when git no longer has the commit. */@@ -51,6 +53,11 @@ export interface PrUnlinkedCommit {subject: string;/** Set when the trailer names a thought the record does not hold yet. */thought?: string;+ /**+ * True when someone else wrote the commit: their thought reaches this clone only+ * once they push it, and never from a fork, whose record stays in the fork.+ */+ others?: boolean;}export interface PrGoal {@@ -105,14 +112,20 @@ export interface PrModel {unlinked: PrUnlinkedCommit[];}-/** `git log` for a branch, oldest first: `%H%x00%h%x00%cI%x00%s` per line. */+/** `git log` for a branch, oldest first: `%H%x00%h%x00%cI%x00%ae%x00%s` per line. */export function parsePrCommits(stdout: string): Omit<PrCommit, "files" | "thought">[] {const out: Omit<PrCommit, "files" | "thought">[] = [];for (const line of stdout.split("\n")) {- const [full, short, at, subject] = line.split("\0");+ const [full, short, at, authorEmail, subject] = line.split("\0");if (full === undefined || !/^[0-9a-f]{40}$/.test(full)) continue;if (short === undefined || short === "") continue;- out.push({ full, short, at: at ?? "", subject: subject ?? "" });+ out.push({+ full,+ short,+ at: at ?? "",+ subject: subject ?? "",+ ...(authorEmail ? { authorEmail } : {}),+ });}return out;}@@ -180,7 +193,7 @@ async function readPrCommits(): Promise<Omit<PrCommit, "files" | "thought">[]> {const stdout = await git(root,- ["log", "--reverse", "--format=%H%x00%h%x00%cI%x00%s", `${base}..${head}`],+ ["log", "--reverse", "--format=%H%x00%h%x00%cI%x00%ae%x00%s", `${base}..${head}`],env,);return parsePrCommits(stdout ?? "");@@ -205,6 +218,8 @@ export interface BuildPrInput {commits: readonly PrCommit[];sessions: readonly EffectiveSession[];policy: "share" | "ignore";+ /** The local git user's email; a commit by anyone else is someone else's. */+ userEmail?: string;}/**@@ -231,11 +246,16 @@ export function buildPrModel(input: BuildPrInput): PrModel {const known = ids.filter((id) => index.has(id));if (known.length === 0) {const named = ids[0];+ const others =+ commit.authorEmail !== undefined &&+ input.userEmail !== undefined &&+ commit.authorEmail.toLowerCase() !== input.userEmail.toLowerCase();unlinked.push({full: commit.full,short: commit.short,subject: commit.subject,...(named === undefined ? {} : { thought: named }),+ ...(named !== undefined && others ? { others: true } : {}),});continue;}@@ -401,7 +421,12 @@ export function formatPr(model: PrModel, opts: PrFormatOptions): string {} else {for (const commit of model.unlinked) {const thought =- commit.thought === undefined ? "" : ` — thought \`${commit.thought}\` not recorded yet`;+ commit.thought === undefined+ ? ""+ : commit.others === true+ ? ` — thought \`${commit.thought}\` is not in this clone's record: its author has ` ++ "not pushed it yet, or it came from a fork, whose record stays in the fork"+ : ` — thought \`${commit.thought}\` not recorded yet`;lines.push(`- \`${commit.short}\` ${oneLine(commit.subject)}${thought}`);}}@@ -528,6 +553,7 @@ export async function pr(opts: PrOptions): Promise<PrModel> {const base = await resolvePrBase(gitRoot, opts.base, env);const commits = await readPrCommits(gitRoot, base.commit, head, env);const sessions = await loadEffectiveSessions(root, opts.io);+ const userEmail = await gitUserEmail(gitRoot, env);const trailers =commits.length === 0? new Map<string, string[]>()@@ -547,6 +573,7 @@ export async function pr(opts: PrOptions): Promise<PrModel> {base,head,policy: (await cogitIgnored(root)) ? "ignore" : "share",+ ...(userEmail === undefined ? {} : { userEmail }),sessions,commits: commits.map((commit) => {const thoughts = trailers.get(commit.full);diff --git a/packages/cli/src/thought.ts b/packages/cli/src/thought.tsindex 734b61d..5eda7b4 100644--- a/packages/cli/src/thought.ts+++ b/packages/cli/src/thought.ts@@ -222,6 +222,24 @@ export async function readThoughtTrailers(}}+/** The author email of a commit, or undefined when git cannot read it. */+export async function readCommitAuthorEmail(+ root: string,+ ref: string,+ env?: NodeJS.ProcessEnv,+): Promise<string | undefined> {+ const gitRoot = await findGitRoot(root);+ if (gitRoot === undefined) return undefined;+ try {+ const args = ["-C", gitRoot, "log", "-1", "--format=%ae", ref];+ const { stdout } = await exec("git", args, env === undefined ? undefined : { env });+ const email = String(stdout).trim();+ return email === "" ? undefined : email;+ } catch {+ return undefined;+ }+}+/*** The one message a commit's final trailer block names, or undefined (no trailer,* no such commit). This is what the commit itself was made for; a squash's quoteddiff --git a/packages/cli/test/pr.test.ts b/packages/cli/test/pr.test.tsindex 92a0741..ccde864 100644--- a/packages/cli/test/pr.test.ts+++ b/packages/cli/test/pr.test.ts@@ -6,6 +6,7 @@ import { beforeEach, describe, expect, it } from "vitest";import { init } from "../src/commands/init.js";import { shortHash } from "../src/commands/log.js";import {+ buildPrModel,copyToClipboard,formatPr,type PrModel,@@ -432,10 +433,44 @@ describe("cogit pr (Story 10.1)", () => {});it("parses only well-formed commit lines", () => {- const line = ["a".repeat(40), "aaaaaaa", T0, "feat: a"].join("\0");- const emptyShort = ["b".repeat(40), "", T0, "feat: b"].join("\0");- expect(parsePrCommits(`not a commit\n${line}\n${emptyShort}`)).toEqual([- { full: "a".repeat(40), short: "aaaaaaa", at: T0, subject: "feat: a" },+ const line = ["a".repeat(40), "aaaaaaa", T0, "[email protected]", "feat: a"].join("\0");+ const emptyShort = ["b".repeat(40), "", T0, "", "feat: b"].join("\0");+ const noEmail = ["c".repeat(40), "ccccccc", T0, "", "feat: c"].join("\0");+ expect(parsePrCommits(`not a commit\n${line}\n${emptyShort}\n${noEmail}`)).toEqual([+ {+ full: "a".repeat(40),+ short: "aaaaaaa",+ at: T0,+ subject: "feat: a",+ authorEmail: "[email protected]",+ },+ { full: "c".repeat(40), short: "ccccccc", at: T0, subject: "feat: c" },]);});++ it("tells a teammate's missing thought from one's own not yet recorded", () => {+ const commit = (n: string, authorEmail: string) => ({+ full: n.repeat(40),+ short: n.repeat(7),+ at: T0,+ subject: `feat: ${n}`,+ authorEmail,+ thoughts: ["h123456789ab"],+ files: [],+ });+ const model = buildPrModel({+ base: { ref: "main", commit: "0".repeat(40) },+ head: "f".repeat(40),+ policy: "share",+ userEmail: "[email protected]",+ sessions: [],+ commits: [commit("a", "[email protected]"), commit("b", "[email protected]")],+ });+ expect(model.unlinked.map((entry) => entry.others)).toEqual([undefined, true]);+ const text = renderPr(model, 1_000_000).text;+ expect(text).toContain("`aaaaaaa` feat: a — thought `h123456789ab` not recorded yet");+ expect(text).toContain(+ "`bbbbbbb` feat: b — thought `h123456789ab` is not in this clone's record: its author has not pushed it yet, or it came from a fork",+ );+ });});diff --git a/packages/cli/test/thought.test.ts b/packages/cli/test/thought.test.tsindex 5a28888..ebcb9df 100644--- a/packages/cli/test/thought.test.ts+++ b/packages/cli/test/thought.test.ts@@ -34,6 +34,7 @@ import {attachThoughtTrailers,earliestSessionStart,parseThoughtTrailers,+ readCommitAuthorEmail,readCommitThought,readThoughtTrailers,} from "../src/thought.js";@@ -636,6 +637,27 @@ describe("the thought behind a commit (Story 9.4)", () => {`commit ${short} comes from thought ${thought}, which is not recorded yet`,);+ // Someone else's commit: their thought may never reach this clone (a fork).+ await git("config", "user.email", "[email protected]");+ await git(+ "commit",+ "-q",+ "--allow-empty",+ "-m",+ "feat: theirs",+ "--author",+ "Bob <[email protected]>",+ "--trailer",+ `Thought: ${thought}`,+ );+ const theirs = (await git("rev-parse", "--short", "HEAD")).trim();+ expect(await readCommitAuthorEmail(root, theirs)).toBe("[email protected]");+ await expect(show({ dir: root, ref: theirs, io, chat: false })).rejects.toThrow(+ "not in this clone's record: its author has not pushed it yet, or the commit came from a fork",+ );+ expect(await readCommitAuthorEmail(root, "nope")).toBeUndefined();+ expect(await readCommitAuthorEmail(await noGitDir(), "HEAD")).toBeUndefined();+// No trailer, an unknown ref or no repository: nothing to name.await git("commit", "-q", "--allow-empty", "-m", "chore: plain");const plain = (await git("rev-parse", "--short", "HEAD")).trim();