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(map): drop the branch pill when it only repeats the message title

Eren0da59f0786e3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 45ecde9..ff4a55a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@ 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
+- The map no longer shows a branch pill that only repeats the message title next to it (a branch without a summary is named after its first message).
### Fixed
- A new session shows on the map while its first turn is still running; 0.21.1 listed it only once that turn ended.
- The side model's message ids are checked against the transcript: a node with an id it made up is no longer stored, so the real message stays unrecorded and the next catch-up records it. Before, the made-up nodes counted as recorded, the real messages were never recorded, and the closing pass wrote a stale "where it left off" line without them.
diff --git a/packages/template/src/GitGraph.tsx b/packages/template/src/GitGraph.tsx
index c0431e0..602c3cc 100644
--- a/packages/template/src/GitGraph.tsx
+++ b/packages/template/src/GitGraph.tsx
@@ -10,6 +10,7 @@ import {
LANE_COLORS,
linkArrow,
linkPath,
+ showsBranchPill,
} from "./gitLayout.js";
/**
@@ -123,7 +124,7 @@ function Row({
title={message.summary || message.title}
>
<span className="git-time">{rowRange(row)}</span>
- {row.first ? (
+ {showsBranchPill(row.first, branchTitle, message.title) ? (
<span className="git-branch" style={{ background: color(row.colorIndex) }}>
{branchTitle}
</span>
diff --git a/packages/template/src/gitLayout.ts b/packages/template/src/gitLayout.ts
index ec08fff..ac68fba 100644
--- a/packages/template/src/gitLayout.ts
+++ b/packages/template/src/gitLayout.ts
@@ -270,15 +270,24 @@ const ROW_FIXED = 106;
* cut with an ellipsis: the width left for the title after the fixed parts of
* the row decides how many lines it needs.
*/
+/**
+ * Whether a branch's first row shows its name: a branch without a summary is
+ * named after that first message, and the pill would only repeat its title.
+ */
+export function showsBranchPill(first: boolean, branchTitle: string, title: string): boolean {
+ return first && branchTitle.trim() !== title.trim();
+}
+
export function rowHeight(
message: GitNode,
row: { first: boolean; branchTitle: string; returns: number; tags: number; head: boolean },
rowWidth = ROW_WIDTH,
): number {
+ const pill = showsBranchPill(row.first, row.branchTitle, message.title);
const fixed =
ROW_FIXED +
(message.label ?? message.id).length * 7 +
- (row.first ? BRANCH_MAX + 8 : 0) +
+ (pill ? BRANCH_MAX + 8 : 0) +
row.returns * 44 +
Math.min(row.tags, TAGS_PER_LINE) * TAG_WIDTH +
(row.head ? 92 : 0) +
@@ -287,7 +296,7 @@ export function rowHeight(
(message.continues ? 150 + message.continues.sessionTitle.length * 6.4 : 0);
const room = Math.max(TITLE_MIN_WIDTH, rowWidth - fixed);
const titleLines = Math.max(1, Math.ceil((message.title.length * TITLE_CHAR) / room));
- const branchLines = row.first
+ const branchLines = pill
? Math.max(1, Math.ceil((row.branchTitle.length * BRANCH_CHAR) / (BRANCH_MAX - 12)))
: 1;
const tagLines = Math.ceil(row.tags / TAGS_PER_LINE);
diff --git a/packages/template/test/layout.test.ts b/packages/template/test/layout.test.ts
index f5c0ec3..7a2acca 100644
--- a/packages/template/test/layout.test.ts
+++ b/packages/template/test/layout.test.ts
@@ -1,6 +1,12 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
-import { ROW_HEIGHT, rowHeight, TAGS_PER_LINE, TITLE_MIN_WIDTH } from "../src/gitLayout.js";
+import {
+ ROW_HEIGHT,
+ rowHeight,
+ showsBranchPill,
+ TAGS_PER_LINE,
+ TITLE_MIN_WIDTH,
+} from "../src/gitLayout.js";
import { shouldForwardWheel } from "../src/scroll.js";
/**
@@ -117,6 +123,18 @@ describe("map layout (Story 9.2)", () => {
expect(height).toBeGreaterThanOrEqual(12 + Math.ceil((120 * 6.4) / TITLE_MIN_WIDTH) * 16);
});
+ it("leaves out a branch pill that would repeat the title", () => {
+ expect(showsBranchPill(true, "Fix the map", " Fix the map ")).toBe(false);
+ expect(showsBranchPill(true, "Map fixes", "Fix the map")).toBe(true);
+ expect(showsBranchPill(false, "Map fixes", "Fix the map")).toBe(false);
+ // Without the pill the title gets its room back and needs fewer lines.
+ const message = { id: "x", label: "m1", title: "a".repeat(90) };
+ const row = { first: true, returns: 0, tags: 0, head: false };
+ expect(rowHeight(message, { ...row, branchTitle: message.title })).toBeLessThan(
+ rowHeight(message, { ...row, branchTitle: "Map fixes" }),
+ );
+ });
+
it("wraps commit tags below each other instead of clipping them", () => {
expect(declarations(".git-tags")).toMatch(/flex-wrap:\s*wrap/);
expect(declarations(".git-tags")).not.toMatch(/overflow:\s*hidden/);