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.

fix(sync): drop the line per session from the first download

Eren8bbc28931260
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d6f51bc..9664c71 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- A git hook of your own that ended with `exit 0`, or read the push's input, no longer stops cogit: its block now sits at the top of the hook, hands git's input on to your lines, and adds the `Thought:` trailer after them. Existing hooks move on the next chat message; a Python or Node hook is left alone and `cogit doctor` says so.
- `git push --dry-run` no longer sends the record (Linux and macOS).
+- The first download of a team's records shows git's progress meter without one line per session (300 sessions printed over 600 lines), and when it fails, `cogit doctor` shows git's reason instead of "the download failed".
- 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`.
## [1.0.0] - 2026-11-04
diff --git a/packages/cli/src/record-sync.ts b/packages/cli/src/record-sync.ts
index afab804..631520c 100644
--- a/packages/cli/src/record-sync.ts
+++ b/packages/cli/src/record-sync.ts
@@ -478,13 +478,7 @@ export async function downloadRecords(
if (remote === undefined) return false;
const args = ["fetch", "--no-tags", "--no-write-fetch-head", remote, RECORD_REFSPEC];
const result = showProgress
- ? await new Promise<GitResult>((done) => {
- const child = spawn("git", ["-C", root, ...args], { env, stdio: "inherit" });
- const failed = (code: number): void =>
- done({ code, stdout: Buffer.alloc(0), stderr: "the download failed" });
- child.on("error", () => failed(1));
- child.on("close", (code) => failed(code ?? 1));
- })
+ ? 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));
await updateState(root, (state) => {
if (result.code === 0) {
@@ -496,6 +490,45 @@ export async function downloadRecords(
return result.code === 0;
}
+/** One `* [new ref] a -> b` line per session, and the `From <url>` above them. */
+const REF_LINE = /^(From | .* -> )/;
+
+/**
+ * A fetch a person watches: git's progress meter goes to the terminal as it
+ * comes (its `\r` redraws included), but the one line per session ref is
+ * dropped, so a first download of 300 sessions does not print 300 lines. The
+ * text is also kept, so a failure can say why. Prompts (an SSH passphrase) use
+ * the terminal directly and are not affected.
+ */
+function fetchWithProgress(
+ root: string,
+ args: string[],
+ env: NodeJS.ProcessEnv,
+): Promise<GitResult> {
+ return new Promise((done) => {
+ const child = spawn("git", ["-C", root, ...args], {
+ env,
+ stdio: ["inherit", "inherit", "pipe"],
+ });
+ const err: string[] = [];
+ let rest = "";
+ const show = (part: string): void => {
+ err.push(part);
+ if (!REF_LINE.test(part)) process.stderr.write(part);
+ };
+ child.stderr?.on("data", (chunk: Buffer) => {
+ const parts = (rest + chunk.toString("utf8")).split(/(?<=[\r\n])/);
+ rest = /[\r\n]$/.test(parts.at(-1) ?? "") ? "" : (parts.pop() ?? "");
+ for (const part of parts) show(part);
+ });
+ child.on("error", (error) => done({ code: 1, stdout: Buffer.alloc(0), stderr: error.message }));
+ child.on("close", (code) => {
+ if (rest !== "") show(rest);
+ done({ code: code ?? 1, stdout: Buffer.alloc(0), stderr: err.join("") });
+ });
+ });
+}
+
/**
* What the `pre-push` hook announces: how many sessions this push would take along,
* without any network. Pushes to other remotes take none, so a deploy remote or a
diff --git a/packages/cli/test/record-sync.test.ts b/packages/cli/test/record-sync.test.ts
index f87f6d0..863614e 100644
--- a/packages/cli/test/record-sync.test.ts
+++ b/packages/cli/test/record-sync.test.ts
@@ -604,10 +604,31 @@ describe("the record on its own refs", () => {
});
it("shows git's own progress to a person, and says when it failed", async () => {
- expect(await downloadRecords(alice, env, true)).toBe(true);
- await git(alice, "remote", "set-url", "origin", join(dir, "nowhere.git"));
- expect(await downloadRecords(alice, env, true)).toBe(false);
- expect((await recordSyncStatus(alice, env)).downloaded).toBe(true);
+ await record(alice, "s1", "First", "[email protected]");
+ await record(alice, "s2", "Second", "[email protected]");
+ await queueRecords(alice, env);
+ await sendRecords(alice, env);
+ const bob = await cloneAs("bob");
+ const stderr = process.stderr.write;
+ const printed: string[] = [];
+ process.stderr.write = ((text: string) => {
+ printed.push(text);
+ return true;
+ }) as typeof process.stderr.write;
+ try {
+ expect(await downloadRecords(bob, env, true)).toBe(true);
+ await git(bob, "remote", "set-url", "origin", join(dir, "nowhere.git"));
+ expect(await downloadRecords(bob, env, true)).toBe(false);
+ } finally {
+ process.stderr.write = stderr;
+ }
+ expect(await refs(bob, "refs/cogit-remote")).toHaveLength(2);
+ // Git's progress and errors reach the person; the line per session ref does not.
+ expect(printed.join("")).not.toContain(" -> ");
+ expect(printed.join("")).toContain("does not appear to be a git repository");
+ const status = await recordSyncStatus(bob, env);
+ expect(status.downloaded).toBe(true);
+ expect(status.downloadError).toContain("fatal:");
});
it("warns instead of failing the command when the record cannot be updated", async () => {