Skip to content

armgit / cogit

Public Imported from GitHub
0

Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.

feat(record): tell people apart by git email and keep each person's sessions their own

Eren0e095cbb1383
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 940dc97..b57e40c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
+### Changed
+- A session records its author's git email next to their name, and people are told apart by email, as in git.
+- A session only continues its author's own earlier sessions: after a pull, a teammate's sessions are no longer offered as the start of yours, and the map no longer draws a session as the continuation of someone else's.
## [0.24.0] - 2026-10-30
### Fixed
diff --git a/docs/guide/teams-and-git.md b/docs/guide/teams-and-git.md
index 754dba5..2d09ab9 100644
--- a/docs/guide/teams-and-git.md
+++ b/docs/guide/teams-and-git.md
@@ -52,6 +52,11 @@ cogit hooks uninstall # remove only the cogit block
3. Each person's sessions are committed with their code. After a pull, teammates' sessions
appear on the map with their author, and "Unread" lists what changed most.
+A session belongs to the person who recorded it: cogit stamps it with their git `user.name`
+and `user.email`, and like git it tells people apart by email. Your sessions only ever
+continue your own earlier sessions; a teammate's session is never taken for the start of
+yours, so everyone's line of thought stays their own on the map.
+
Raw conversations stay on each author's machine unless they turn `shareConversations` on, so
teammates see the record (titles, decisions, reasons) but not the chat itself.
diff --git a/docs/schema/session.json b/docs/schema/session.json
index 19103ea..998d00c 100644
--- a/docs/schema/session.json
+++ b/docs/schema/session.json
@@ -381,6 +381,11 @@
"minLength": 1,
"maxLength": 200
},
+ "authorEmail": {
+ "type": "string",
+ "minLength": 3,
+ "maxLength": 320
+ },
"lastRecordedBy": {
"type": "string",
"enum": [
diff --git a/packages/cli/src/author.ts b/packages/cli/src/author.ts
new file mode 100644
index 0000000..d55b3dc
--- /dev/null
+++ b/packages/cli/src/author.ts
@@ -0,0 +1,70 @@
+import { userInfo } from "node:os";
+import { findGitRoot, gitUserEmail, gitUserName } from "./git.js";
+
+/**
+ * Who a session belongs to (Story 9.3): the git identity it was recorded with.
+ * Like git, a person is their email when there is one, else their name. A
+ * session's thoughts are its author's own; another person's session is never
+ * taken for a continuation of yours.
+ */
+export interface Author {
+ author?: string | undefined;
+ authorEmail?: string | undefined;
+}
+
+/**
+ * Whether two sessions were recorded by the same person. Emails decide when both
+ * have one, else names; a record from before authors were stamped matches
+ * anyone, since it was made before teammates' records could be told apart.
+ */
+export function sameAuthor(a: Author, b: Author): boolean {
+ if (a.authorEmail !== undefined && b.authorEmail !== undefined)
+ return a.authorEmail.toLowerCase() === b.authorEmail.toLowerCase();
+ if (a.author !== undefined && b.author !== undefined) return a.author === b.author;
+ return true;
+}
+
+/**
+ * Who gets credited for a session (Story 9.3): the git name this repository
+ * commits with, else the OS user. Recorded once, on the first write; a record
+ * made on another machine keeps its own author.
+ */
+export async function sessionAuthor(
+ root: string,
+ env: NodeJS.ProcessEnv = process.env,
+): Promise<string | undefined> {
+ const gitRoot = await findGitRoot(root);
+ const fromGit = gitRoot === undefined ? undefined : await gitUserName(gitRoot, env);
+ if (fromGit !== undefined) return fromGit;
+ try {
+ return userInfo().username || undefined;
+ } catch {
+ return env.USER ?? env.USERNAME ?? undefined;
+ }
+}
+
+/** The name and git email a session is credited to on this machine. */
+export async function sessionIdentity(
+ root: string,
+ env: NodeJS.ProcessEnv = process.env,
+): Promise<Author> {
+ const gitRoot = await findGitRoot(root);
+ const email = gitRoot === undefined ? undefined : await gitUserEmail(gitRoot, env);
+ return { author: await sessionAuthor(root, env), authorEmail: email };
+}
+
+/**
+ * The identity a write stamps: the record's own once it has one, so a record
+ * made elsewhere keeps its author; a record that has a name but no email yet
+ * (written before emails) gets this machine's email only when the names match.
+ */
+export function stampedIdentity(stored: Author | undefined, here: Author): Author {
+ const author = stored?.author ?? here.author;
+ const authorEmail =
+ stored?.authorEmail ??
+ (stored?.author === undefined || stored.author === here.author ? here.authorEmail : undefined);
+ return {
+ ...(author === undefined ? {} : { author }),
+ ...(authorEmail === undefined ? {} : { authorEmail }),
+ };
+}
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts
index 8fa929e..dd1665d 100644
--- a/packages/cli/src/commands/build.ts
+++ b/packages/cli/src/commands/build.ts
@@ -2,6 +2,7 @@ import { readdir, stat } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import pkg from "../../package.json" with { type: "json" };
import { type ChatTurn, defaultAgent } from "../agents/index.js";
+import { sessionIdentity } from "../author.js";
import {
type CommitChange,
findGitRoot,
@@ -351,6 +352,7 @@ export async function buildProject(opts: BuildOptions): Promise<LineageViewModel
// Over `file://` the settings modal shows these; a server page reads the
// live values instead, so a map built before a change still agrees.
settings: panelSettings(config),
+ viewer: await sessionIdentity(root, io.env),
// With the catch-up on, the hook records the tail at session end, so the
// count would only be a stale warning about work already scheduled.
unrecorded: config.sessionEndCatchUp ? undefined : views.unrecorded,
diff --git a/packages/cli/src/commands/session.ts b/packages/cli/src/commands/session.ts
index fdb7626..0eae3b6 100644
--- a/packages/cli/src/commands/session.ts
+++ b/packages/cli/src/commands/session.ts
@@ -1,8 +1,11 @@
import { readFile, rm } from "node:fs/promises";
-import { userInfo } from "node:os";
import { resolve } from "node:path";
import { defaultAgent } from "../agents/index.js";
-import { commitBetween, findGitRoot, gitUserName } from "../git.js";
+import { type Author, sameAuthor, sessionIdentity, stampedIdentity } from "../author.js";
+
+export { sessionAuthor } from "../author.js";
+
+import { commitBetween, findGitRoot } from "../git.js";
import { CliError, type Io } from "../io.js";
import {
hashesToLabels,
@@ -46,25 +49,6 @@ export async function readStdin(stream: NodeJS.ReadableStream = process.stdin):
return Buffer.concat(chunks).toString("utf8");
}
-/**
- * Who gets credited for a session (Story 9.3): the git name this repository
- * commits with, else the OS user. Recorded once, on the first write; a record
- * made on another machine keeps its own author.
- */
-export async function sessionAuthor(
- root: string,
- env: NodeJS.ProcessEnv = process.env,
-): Promise<string | undefined> {
- const gitRoot = await findGitRoot(root);
- const fromGit = gitRoot === undefined ? undefined : await gitUserName(gitRoot, env);
- if (fromGit !== undefined) return fromGit;
- try {
- return userInfo().username || undefined;
- } catch {
- return env.USER ?? env.USERNAME ?? undefined;
- }
-}
-
export interface SessionWriteOptions {
dir: string;
/** Read JSON from this file instead of stdin. */
@@ -124,11 +108,18 @@ export async function sessionWrite(
// merge; `startedAt` is the current session's own start.
const current = await loadSession(root, input.sessionId);
const startedAt = current.found && current.ok ? current.data.startedAt : io.now();
- const author =
- current.found && current.ok && current.data.author
- ? current.data.author
- : await sessionAuthor(root, io.env);
- const crossTargets = await crossSessionTargets(root, input.sessionId, startedAt, input, io.env);
+ const identity = stampedIdentity(
+ current.found && current.ok ? current.data : undefined,
+ await sessionIdentity(root, io.env),
+ );
+ const crossTargets = await crossSessionTargets(
+ root,
+ input.sessionId,
+ startedAt,
+ input,
+ io.env,
+ identity,
+ );
let warnings: string[] = [];
const saved = await updateSession(root, input.sessionId, async (cur) => {
// A record written before 8.5 still names messages `m1`, `m2`, …; the file is
@@ -158,7 +149,7 @@ export async function sessionWrite(
// Story 12.1: the Stop hook tells an agent write from a side one.
const stamped = { ...stored, lastRecordedBy: by };
// Story 9.3: the first write stamps who recorded the session.
- return stamped.author === undefined && author !== undefined ? { ...stamped, author } : stamped;
+ return { ...stamped, ...stampedIdentity(stamped, identity) };
});
for (const w of warnings) io.warn(w);
if (opts.file && opts.consume) await rm(opts.file, { force: true });
@@ -260,8 +251,9 @@ export function withForkParent(
/**
* The `<sessionId>:<id>` parents and links the input sends, kept only when the
- * other session belongs to this project, started no later than this one and holds
- * that message (Story 8.6). The rest reach the merge as unknown references and
+ * other session belongs to this project, started no later than this one, holds
+ * that message (Story 8.6) and was recorded by the same person: a session never
+ * grows out of a teammate's. The rest reach the merge as unknown references and
* are warned about there; nothing is dropped silently.
*/
export async function crossSessionTargets(
@@ -270,6 +262,7 @@ export async function crossSessionTargets(
startedAt: string,
input: SessionInput,
env: NodeJS.ProcessEnv = process.env,
+ author: Author = {},
): Promise<Set<string>> {
const refs = new Set<string>();
for (const node of input.nodes ?? []) {
@@ -282,7 +275,7 @@ export async function crossSessionTargets(
const { sessionId: otherId, id } = parseMessageRef(value);
if (otherId === null || otherId === sessionId) continue;
const loaded = await loadSession(root, otherId);
- if (!loaded.found || !loaded.ok) continue;
+ if (!loaded.found || !loaded.ok || !sameAuthor(loaded.data, author)) continue;
const otherStart = Date.parse(loaded.data.startedAt);
if (Number.isNaN(otherStart) || otherStart > Date.parse(startedAt)) continue;
const messages = await readSessionMessages(root, otherId, env);
@@ -573,11 +566,17 @@ export async function candidateSessions(
env: NodeJS.ProcessEnv,
limit = CANDIDATE_SESSIONS,
): Promise<CandidateSession[]> {
+ // Only this person's sessions: a teammate's thoughts are never a continuation.
+ const current = await loadSession(root, sessionId);
+ const me = stampedIdentity(
+ current.found && current.ok ? current.data : undefined,
+ await sessionIdentity(root, env),
+ );
const recent: Session[] = [];
for (const id of await listSessionIds(projectPaths(root).sessions)) {
if (id === sessionId) continue;
const loaded = await loadSession(root, id);
- if (loaded.found && loaded.ok) recent.push(loaded.data);
+ if (loaded.found && loaded.ok && sameAuthor(loaded.data, me)) recent.push(loaded.data);
}
recent.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
const out: CandidateSession[] = [];
diff --git a/packages/cli/src/git.ts b/packages/cli/src/git.ts
index 7d2fe14..7f4db69 100644
--- a/packages/cli/src/git.ts
+++ b/packages/cli/src/git.ts
@@ -435,11 +435,27 @@ export function projectFiles(
export async function gitUserName(
root: string,
env: NodeJS.ProcessEnv = process.env,
+): Promise<string | undefined> {
+ return gitConfig(root, "user.name", env);
+}
+
+/** `git config user.email`; undefined when it is not set. */
+export async function gitUserEmail(
+ root: string,
+ env: NodeJS.ProcessEnv = process.env,
+): Promise<string | undefined> {
+ return gitConfig(root, "user.email", env);
+}
+
+async function gitConfig(
+ root: string,
+ key: string,
+ env: NodeJS.ProcessEnv,
): Promise<string | undefined> {
try {
- const { stdout } = await exec("git", ["-C", root, "config", "user.name"], { env });
- const name = stdout.trim();
- return name === "" ? undefined : name;
+ const { stdout } = await exec("git", ["-C", root, "config", key], { env });
+ const value = stdout.trim();
+ return value === "" ? undefined : value;
} catch {
return undefined;
}
diff --git a/packages/cli/src/schema/session.ts b/packages/cli/src/schema/session.ts
index d16f11f..786a8a1 100644
--- a/packages/cli/src/schema/session.ts
+++ b/packages/cli/src/schema/session.ts
@@ -132,6 +132,12 @@ export const Session = z.object({
* on the first write (Story 9.3). Old records have none.
*/
author: z.string().min(1).max(200).optional(),
+ /**
+ * The recorder's git `user.email`, stamped with `author`: like git, a person is
+ * told apart by email, so two people with one name stay two and a renamed
+ * one stays one. Records from before it have none.
+ */
+ authorEmail: z.string().min(3).max(320).optional(),
/**
* Who wrote the record last (Story 12.1): the Stop hook counts the main
* agent's turns separately when the side model keeps writing in between.
diff --git a/packages/cli/src/view/lineage.ts b/packages/cli/src/view/lineage.ts
index 65448dd..f9d6cdd 100644
--- a/packages/cli/src/view/lineage.ts
+++ b/packages/cli/src/view/lineage.ts
@@ -1,3 +1,4 @@
+import { type Author, sameAuthor } from "../author.js";
import type { Project } from "../schema/project.js";
import type { LineageNode, Session } from "../schema/session.js";
import {
@@ -257,6 +258,7 @@ function toViewSession(
agent: session.agent,
title: sessionTitle(session),
...(session.author === undefined ? {} : { author: session.author }),
+ ...(session.authorEmail === undefined ? {} : { authorEmail: session.authorEmail }),
startedAt: session.startedAt,
updatedAt: session.updatedAt,
status: session.status,
@@ -295,13 +297,17 @@ export interface ViewModelInput {
commitFiles?: ReadonlyMap<string, string[]> | undefined;
/** Settings embedded for the modal's `file://` view (Story 8.13). */
settings?: PanelSettings | undefined;
+ /** The git identity of whoever builds the page, to tell their sessions from others'. */
+ viewer?: Author | undefined;
}
/**
* Turns a `<sessionId>:<id>` parent into the `continues` mark the map draws and
* leaves the message a root of its own session, so one session's graph never
* leaks into another's (8.6). Runs once every session's labels are known.
- * A target the map no longer holds still gets the mark, with the raw id.
+ * A target the map no longer holds still gets the mark, with the raw id. A
+ * session never continues another person's: such a parent (written before that
+ * rule) leaves the message a plain root.
*/
export function resolveContinues(sessions: ViewSession[]): void {
const byId = new Map(sessions.map((session) => [session.sessionId, session]));
@@ -316,6 +322,7 @@ export function resolveContinues(sessions: ViewSession[]): void {
const other = byId.get(otherId);
const target = other?.messages.find((candidate) => candidate.id === id);
message.parent = null;
+ if (other && !sameAuthor(session, other)) continue;
message.continues = {
sessionId: otherId,
sessionTitle: other?.title || otherId,
@@ -352,6 +359,14 @@ export function buildViewModel(input: ViewModelInput): LineageViewModel {
status: statusCard(sessions, input.generatedAt),
sessions: views,
...(input.settings === undefined ? {} : { settings: input.settings }),
+ ...(input.viewer === undefined ? {} : { viewer: viewerOf(input.viewer) }),
+ };
+}
+
+function viewerOf(viewer: Author): NonNullable<LineageViewModel["viewer"]> {
+ return {
+ ...(viewer.author === undefined ? {} : { author: viewer.author }),
+ ...(viewer.authorEmail === undefined ? {} : { authorEmail: viewer.authorEmail }),
};
}
diff --git a/packages/cli/src/view/model.ts b/packages/cli/src/view/model.ts
index d325653..a1d78c1 100644
--- a/packages/cli/src/view/model.ts
+++ b/packages/cli/src/view/model.ts
@@ -192,6 +192,8 @@ export interface ViewSession {
title: string;
/** Who recorded the session (Story 9.3); absent on records written before it. */
author?: string;
+ /** Their git email, which tells people apart; absent on older records. */
+ authorEmail?: string;
startedAt: string;
updatedAt: string;
status: ViewStatus;
@@ -278,6 +280,11 @@ export interface LineageViewModel {
status: StatusCard;
/** Every session, in start order. */
sessions: ViewSession[];
+ /**
+ * Who is looking: the git identity of the machine that built the page, so the
+ * map can tell your sessions from your teammates'. Absent when unknown.
+ */
+ viewer?: { author?: string; authorEmail?: string };
/**
* Every registered project, most recently active first, for the map's
* switcher (Story 8.12). Missing directories are left out; older pages simply
diff --git a/packages/cli/test/author.test.ts b/packages/cli/test/author.test.ts
new file mode 100644
index 0000000..70b64e0
--- /dev/null
+++ b/packages/cli/test/author.test.ts
@@ -0,0 +1,68 @@
+import { describe, expect, it } from "vitest";
+import { sameAuthor, stampedIdentity } from "../src/author.js";
+import { resolveContinues } from "../src/view/lineage.js";
+import type { ViewSession } from "../src/view/model.js";
+
+describe("sameAuthor", () => {
+ it("tells people apart by email, whatever their names", () => {
+ expect(sameAuthor({ author: "Eren", authorEmail: "[email protected]" }, { authorEmail: "[email protected]" })).toBe(
+ true,
+ );
+ expect(
+ sameAuthor(
+ { author: "Eren", authorEmail: "[email protected]" },
+ { author: "Eren", authorEmail: "[email protected]" },
+ ),
+ ).toBe(false);
+ });
+
+ it("falls back to names, and lets a record without an author match anyone", () => {
+ expect(sameAuthor({ author: "Eren" }, { author: "Ayşe", authorEmail: "[email protected]" })).toBe(false);
+ expect(sameAuthor({ author: "Eren" }, { author: "Eren" })).toBe(true);
+ expect(sameAuthor({}, { author: "Ayşe" })).toBe(true);
+ });
+});
+
+describe("stampedIdentity", () => {
+ const here = { author: "Eren", authorEmail: "[email protected]" };
+
+ it("stamps this machine's identity on a new record", () => {
+ expect(stampedIdentity(undefined, here)).toEqual(here);
+ });
+
+ it("keeps a record's own author and adds the email only for the same name", () => {
+ expect(stampedIdentity({ author: "Eren" }, here)).toEqual(here);
+ expect(stampedIdentity({ author: "Ayşe" }, here)).toEqual({ author: "Ayşe" });
+ expect(stampedIdentity({ author: "Ayşe", authorEmail: "[email protected]" }, here)).toEqual({
+ author: "Ayşe",
+ authorEmail: "[email protected]",
+ });
+ expect(stampedIdentity(undefined, {})).toEqual({});
+ });
+});
+
+describe("resolveContinues", () => {
+ const session = (sessionId: string, author: string, parent: string | null): ViewSession => ({
+ sessionId,
+ agent: "claude-code",
+ title: sessionId,
+ author,
+ startedAt: "2026-10-22T09:00:00.000Z",
+ updatedAt: "2026-10-22T09:00:00.000Z",
+ status: { goal: "", done: [], pending: [], next: "" },
+ messages: [{ id: "h1", label: "m1", kind: "message", title: "One", parent }],
+ transcriptAvailable: true,
+ });
+
+ it("never draws a session as the continuation of a teammate's", () => {
+ const sessions = [
+ session("a", "Eren", null),
+ session("b", "Eren", "a:h1"),
+ session("c", "Ayşe", "a:h1"),
+ ];
+ resolveContinues(sessions);
+ expect(sessions[1]?.messages[0]?.continues?.sessionId).toBe("a");
+ expect(sessions[2]?.messages[0]?.continues).toBeUndefined();
+ expect(sessions[2]?.messages[0]?.parent).toBeNull();
+ });
+});
diff --git a/packages/cli/test/session.test.ts b/packages/cli/test/session.test.ts
index 3f75681..b4a96fb 100644
--- a/packages/cli/test/session.test.ts
+++ b/packages/cli/test/session.test.ts
@@ -1,6 +1,6 @@
import { execFile } from "node:child_process";
import { existsSync } from "node:fs";
-import { mkdir, writeFile } from "node:fs/promises";
+import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { Readable } from "node:stream";
import { promisify } from "node:util";
@@ -714,6 +714,32 @@ ${line("second", 2)}
});
});
+ it("offers only this person's sessions, never a teammate's", async () => {
+ await init(root, { name: "p", retention: "keep", language: "auto" }, fakeIo(envFor(dir)));
+ const one = (sessionId: string) =>
+ JSON.stringify({
+ sessionId,
+ nodes: [{ id: "m1", kind: "message", title: "One", at: "2026-10-22T09:00:00.000Z" }],
+ });
+ await sessionWrite({ dir: root }, fakeIo(envFor(dir)), async () => one("mine"));
+ await sessionWrite({ dir: root }, fakeIo(envFor(dir)), async () => one("theirs"));
+ // A teammate's record, as `git pull` brings it in.
+ const file = join(root, ".cogit", "sessions", "theirs.json");
+ const record = JSON.parse(await readFile(file, "utf8"));
+ await writeFile(file, JSON.stringify({ ...record, author: "Ayşe", authorEmail: "[email protected]" }));
+ const folder = join(dir, "claude", "projects", "-p");
+ await mkdir(folder, { recursive: true });
+ const line = { type: "user", timestamp: "2026-10-22T10:00:00.000Z" };
+ await writeFile(
+ join(folder, "second.jsonl"),
+ JSON.stringify({ ...line, message: { role: "user", content: "Devam" } }),
+ );
+
+ await sessionShow(root, "second", io);
+ const sessions = (shown().candidates as { sessions: { sessionId: string }[] }).sessions;
+ expect(sessions.map((session) => session.sessionId)).toEqual(["mine"]);
+ });
+
it("sets the continues hint when the transcript read a handoff file", async () => {
await init(root, { name: "p", retention: "keep", language: "auto" }, fakeIo(envFor(dir)));
const folder = join(dir, "claude", "projects", "-p");