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(sync): download the record with git older than 2.29
Erene39324d7513a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 39cbf7c..8ec5ca1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- `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.- `cogit build` in a fresh clone of a shared project downloads the team's sessions first, instead of writing an empty map.- The map's outline follows the search: it marks and scrolls to the hit you are on, and scrolls to a message you click on the map.+- Git older than 2.29 can download the team's records again: cogit no longer passes it `--no-write-fetch-head`, and a failed download names git's error instead of a line of its usage text.## [1.0.0] - 2026-11-04### Changeddiff --git a/packages/cli/src/record-sync.ts b/packages/cli/src/record-sync.tsindex 631520c..8135545 100644--- a/packages/cli/src/record-sync.ts+++ b/packages/cli/src/record-sync.ts@@ -103,11 +103,34 @@ function gitError(text: string): string {.split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== "");- // Git ends with advice; the reason is the line it marks as fatal.- const reason = lines.find((line) => line.startsWith("fatal:")) ?? lines.at(-1) ?? "git failed";+ // Git ends with advice or a usage list; the reason is the line it marks as fatal+ // or as an error.+ const reason =+ lines.find((line) => line.startsWith("fatal:")) ??+ lines.find((line) => line.startsWith("error:")) ??+ lines.at(-1) ??+ "git failed";return reason.slice(0, 300);}+/** `git version 2.39.3 (Apple Git-146)`, `2.45.1.windows.1`: the first two numbers. */+export function parseGitVersion(text: string): [number, number] | undefined {+ const match = /(\d+)\.(\d+)/.exec(text);+ return match === null ? undefined : [Number(match[1]), Number(match[2])];+}++/** True when git is at least this version, or when its version cannot be read. */+async function gitVersionAtLeast(+ root: string,+ env: NodeJS.ProcessEnv,+ major: number,+ minor: number,+): Promise<boolean> {+ const version = parseGitVersion((await runGit(root, ["version"], env)).stdout.toString("utf8"));+ if (version === undefined) return true;+ return version[0] > major || (version[0] === major && version[1] >= minor);+}+/** True when this project's record is shared: in a repository, and not kept private. */export async function isSharing(root: string): Promise<boolean> {if (!existsSync(projectPaths(root).project)) return false;@@ -476,7 +499,9 @@ export async function downloadRecords(): Promise<boolean> {const remote = await syncRemote(root, env);if (remote === undefined) return false;- const args = ["fetch", "--no-tags", "--no-write-fetch-head", remote, RECORD_REFSPEC];+ // Keeps FETCH_HEAD for the user's own fetches; git before 2.29 does not know the flag.+ const fetchHead = (await gitVersionAtLeast(root, env, 2, 29)) ? ["--no-write-fetch-head"] : [];+ const args = ["fetch", "--no-tags", ...fetchHead, remote, RECORD_REFSPEC];const result = showProgress? await fetchWithProgress(root, [...args.slice(0, 1), "--progress", ...args.slice(1)], env): await runGit(root, [...args.slice(0, 1), "--quiet", ...args.slice(1)], quietEnv(env));diff --git a/packages/cli/test/record-sync.test.ts b/packages/cli/test/record-sync.test.tsindex 4a99f80..0c7972b 100644--- a/packages/cli/test/record-sync.test.ts+++ b/packages/cli/test/record-sync.test.ts@@ -1,6 +1,6 @@import { execFile } from "node:child_process";import { existsSync } from "node:fs";-import { mkdir, readFile, rm, writeFile } from "node:fs/promises";+import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";import { join } from "node:path";import { promisify } from "node:util";import { beforeEach, describe, expect, it } from "vitest";@@ -19,6 +19,7 @@ import {downloadRecords,importRecords,isSharing,+ parseGitVersion,pushLanded,queueRecords,RECORD_REFSPEC,@@ -329,6 +330,46 @@ describe("the record on its own refs", () => {expect(await readFile(join(bob, ".cogit", "map.html"), "utf8")).toContain("First");});+ it("reads git's version, also Apple's and Windows' forms", () => {+ expect(parseGitVersion("git version 2.20.1")).toEqual([2, 20]);+ expect(parseGitVersion("git version 2.39.3 (Apple Git-146)")).toEqual([2, 39]);+ expect(parseGitVersion("git version 2.45.1.windows.1")).toEqual([2, 45]);+ expect(parseGitVersion("no version here")).toBeUndefined();+ });++ it("downloads with a git too old for --no-write-fetch-head, and names its error", async () => {+ await record(alice, "s1", "First", "[email protected]");+ await push(alice);+ const bob = await cloneAs("bob");+ // A git 2.20 stand-in: reports the old version and refuses the newer flag.+ const bin = join(dir, "old-git");+ await mkdir(bin, { recursive: true });+ const real = (await run("sh", ["-c", "command -v git"], { env: gitEnv })).stdout.trim();+ await writeFile(+ join(bin, "git"),+ [+ "#!/bin/sh",+ 'for a in "$@"; do',+ ' [ "$a" = version ] && { echo "git version 2.20.1"; exit 0; }',+ ' [ "$a" = --no-write-fetch-head ] && { echo "error: unknown option no-write-fetch-head" >&2; echo "usage: git fetch" >&2; echo " --filter <args> object filtering" >&2; exit 129; }',+ "done",+ `exec '${real}' "$@"`,+ ].join("\n"),+ );+ await chmod(join(bin, "git"), 0o755);+ const old = { ...env, PATH: `${bin}:${env.PATH ?? process.env.PATH ?? ""}` };+ expect(await downloadRecords(bob, old)).toBe(true);+ expect(await refs(bob, "refs/cogit-remote")).toHaveLength(1);++ // Claiming a newer version, it fails: the reason is git's error line, not its usage list.+ const script = await readFile(join(bin, "git"), "utf8");+ await writeFile(join(bin, "git"), script.replace("2.20.1", "2.30.0"));+ expect(await downloadRecords(bob, old)).toBe(false);+ expect((await recordSyncStatus(bob, env)).downloadError).toBe(+ "error: unknown option no-write-fetch-head",+ );+ });+it("adds the refspec once, in this clone's config only", async () => {const bob = await cloneAs("bob");expect(await addRecordRefspec(bob, env)).toBe(true);