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(map): resizable columns for message rows

Eren2ff4fe713d5d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e7cd774..34a1189 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]
+### Added
+- The message rows of an open session stand in columns (time, number, message, commits and changes) under a small head; drag a column's edge in the head to make it wider or narrower, double-click it to reset. The widths apply to every session and are remembered in this browser.
## [0.21.2] - 2026-10-29
### Changed
diff --git a/packages/template/src/ColumnHead.tsx b/packages/template/src/ColumnHead.tsx
new file mode 100644
index 0000000..7934064
--- /dev/null
+++ b/packages/template/src/ColumnHead.tsx
@@ -0,0 +1,110 @@
+import { useStore } from "@xyflow/react";
+import { type PointerEvent, useState } from "react";
+import { columnVars } from "./GitGraph.js";
+import { clampColumns, DEFAULT_COLUMNS, type GitLayout, type RowColumns } from "./gitLayout.js";
+
+/**
+ * The head over an open session's message rows: the column names, and a handle
+ * on each column's right edge to drag it wider or narrower, like a table.
+ * Double-clicking a handle puts that column back to its default width. The
+ * widths are the same for every session and stay in this browser.
+ */
+
+const KEY = "cogit.mapColumns";
+
+export function loadColumns(): RowColumns {
+ try {
+ const raw = window.localStorage.getItem(KEY);
+ return raw ? clampColumns(JSON.parse(raw)) : DEFAULT_COLUMNS;
+ } catch {
+ return DEFAULT_COLUMNS;
+ }
+}
+
+export function saveColumns(columns: RowColumns): void {
+ try {
+ window.localStorage.setItem(KEY, JSON.stringify(columns));
+ } catch {
+ // Private window or blocked storage: the widths last until the page closes.
+ }
+}
+
+/** Keeps the drag on the handle when the pointer leaves it; best effort. */
+function capture(event: PointerEvent, on: boolean): void {
+ try {
+ if (on) event.currentTarget.setPointerCapture(event.pointerId);
+ else event.currentTarget.releasePointerCapture(event.pointerId);
+ } catch {
+ // The pointer is gone already; the drag still ends on pointerup.
+ }
+}
+
+/** Height of the head; the open session leaves this much room above its rows. */
+export const COLUMN_HEAD = 22;
+
+function Handle({
+ column,
+ columns,
+ onResize,
+}: {
+ column: keyof RowColumns;
+ columns: RowColumns;
+ onResize: (columns: RowColumns) => void;
+}) {
+ // The canvas may be zoomed: a screen pixel is 1/zoom of a column pixel.
+ const zoom = useStore((state) => state.transform[2]);
+ const [start, setStart] = useState<{ x: number; width: number } | null>(null);
+ return (
+ <span
+ className={`column-handle nodrag nopan${start ? " is-dragging" : ""}`}
+ role="separator"
+ aria-orientation="vertical"
+ aria-label={`Resize the ${column} column`}
+ title="Drag to resize · double-click to reset"
+ onPointerDown={(event: PointerEvent) => {
+ event.stopPropagation();
+ capture(event, true);
+ setStart({ x: event.clientX, width: columns[column] });
+ }}
+ onPointerMove={(event: PointerEvent) => {
+ if (!start) return;
+ const width = start.width + (event.clientX - start.x) / (zoom || 1);
+ onResize(clampColumns({ ...columns, [column]: width }));
+ }}
+ onPointerUp={(event: PointerEvent) => {
+ if (!start) return;
+ capture(event, false);
+ setStart(null);
+ }}
+ onDoubleClick={(event) => {
+ event.stopPropagation();
+ onResize({ ...columns, [column]: DEFAULT_COLUMNS[column] });
+ }}
+ />
+ );
+}
+
+export function ColumnHead({
+ git,
+ onResize,
+}: {
+ git: GitLayout;
+ onResize: (columns: RowColumns) => void;
+}) {
+ const columns = git.columns;
+ if (!columns) return null;
+ const handle = (column: keyof RowColumns) => (
+ <Handle column={column} columns={columns} onResize={onResize} />
+ );
+ return (
+ <div
+ className="column-head"
+ style={{ marginLeft: git.graphWidth + 8, width: git.rowWidth, ...columnVars(columns) }}
+ >
+ <span className="column-name">Time{handle("time")}</span>
+ <span className="column-name">#</span>
+ <span className="column-name">Message{handle("title")}</span>
+ <span className="column-name">Commits · changes{handle("details")}</span>
+ </div>
+ );
+}
diff --git a/packages/template/src/GitGraph.tsx b/packages/template/src/GitGraph.tsx
index 5377169..ed8ae40 100644
--- a/packages/template/src/GitGraph.tsx
+++ b/packages/template/src/GitGraph.tsx
@@ -1,4 +1,4 @@
-import { type MouseEvent, type ReactElement, useMemo } from "react";
+import { type CSSProperties, type MouseEvent, type ReactElement, useMemo } from "react";
import { formatChange, isBigChange } from "../../cli/src/view/change.js";
import type { ViewNode } from "../../cli/src/view/model.js";
import { formatStamp } from "./format.js";
@@ -7,9 +7,11 @@ import {
type GitLayout,
type GitMessageRow,
type GitRow,
+ ID_COLUMN,
LANE_COLORS,
linkArrow,
linkPath,
+ type RowColumns,
} from "./gitLayout.js";
/**
@@ -22,6 +24,17 @@ function color(index: number): string {
return `var(--l${index % LANE_COLORS})`;
}
+/** The column widths as CSS variables for the rows' grid (`styles.css`). */
+export function columnVars(columns: RowColumns | undefined): CSSProperties {
+ if (!columns) return {};
+ return {
+ "--col-time": `${columns.time}px`,
+ "--col-id": `${ID_COLUMN}px`,
+ "--col-title": `${columns.title}px`,
+ "--col-details": `${columns.details}px`,
+ } as CSSProperties;
+}
+
function rowRange(row: GitRow): string {
if (row.kind === "more") return "";
return row.message.at ? formatStamp(row.message.at) : "";
@@ -120,52 +133,54 @@ function Row({
<span className="git-time">{rowRange(row)}</span>
<span className="git-id">{message.label ?? message.id}</span>
<span className="git-title">{message.title}</span>
- {row.tags.length > 0 ? (
- <span className="git-tags">
- {row.tags.map((tag) => (
- // A span, not a button: the whole row is already a button.
- <span
- key={tag.hash}
- className={`git-tag${tag.missing ? " is-missing" : ""}`}
- title={
- tag.missing
- ? `commit ${tag.short} is not in this repository`
- : `${tag.short} ${tag.subject ?? ""}`
- }
- onClick={(event: MouseEvent) => {
- event.stopPropagation();
- onSelect(row);
- }}
- >
- {tag.short}
- </span>
- ))}
- </span>
- ) : null}
- {message.change ? (
- <span
- className="git-change"
- title={`The commits linked to this message changed ${message.change.added} lines added, ${message.change.removed} removed${read ? " (read)" : ""}`}
- >
- {formatChange(message.change)}
- </span>
- ) : null}
- {message.continues ? (
- <span
- className="git-continues"
- title={`Open ${message.continues.sessionTitle} at ${message.continues.label ?? message.continues.id}`}
- onClick={(event: MouseEvent) => {
- event.stopPropagation();
- onContinue(message.continues as NonNullable<ViewNode["continues"]>);
- }}
- >
- ↑ continues {message.continues.sessionTitle} ·{" "}
- {message.continues.label ?? message.continues.id}
- </span>
- ) : null}
- {returnMark(row)}
- {row.head ? <span className="left-off">left off here</span> : null}
- {message.unsummarized ? <span className="unsummarized">not summarized yet</span> : null}
+ <span className="git-details">
+ {row.tags.length > 0 ? (
+ <span className="git-tags">
+ {row.tags.map((tag) => (
+ // A span, not a button: the whole row is already a button.
+ <span
+ key={tag.hash}
+ className={`git-tag${tag.missing ? " is-missing" : ""}`}
+ title={
+ tag.missing
+ ? `commit ${tag.short} is not in this repository`
+ : `${tag.short} ${tag.subject ?? ""}`
+ }
+ onClick={(event: MouseEvent) => {
+ event.stopPropagation();
+ onSelect(row);
+ }}
+ >
+ {tag.short}
+ </span>
+ ))}
+ </span>
+ ) : null}
+ {message.change ? (
+ <span
+ className="git-change"
+ title={`The commits linked to this message changed ${message.change.added} lines added, ${message.change.removed} removed${read ? " (read)" : ""}`}
+ >
+ {formatChange(message.change)}
+ </span>
+ ) : null}
+ {message.continues ? (
+ <span
+ className="git-continues"
+ title={`Open ${message.continues.sessionTitle} at ${message.continues.label ?? message.continues.id}`}
+ onClick={(event: MouseEvent) => {
+ event.stopPropagation();
+ onContinue(message.continues as NonNullable<ViewNode["continues"]>);
+ }}
+ >
+ ↑ continues {message.continues.sessionTitle} ·{" "}
+ {message.continues.label ?? message.continues.id}
+ </span>
+ ) : null}
+ {returnMark(row)}
+ {row.head ? <span className="left-off">left off here</span> : null}
+ {message.unsummarized ? <span className="unsummarized">not summarized yet</span> : null}
+ </span>
</button>
);
}
@@ -211,7 +226,10 @@ export function GitGraph({
}, [git.segments]);
return (
- <div className="git-graph" style={{ width: git.width, height: git.height }}>
+ <div
+ className={git.columns ? "git-graph in-columns" : "git-graph"}
+ style={{ width: git.width, height: git.height }}
+ >
<svg
className="git-lanes"
width={git.graphWidth}
@@ -291,7 +309,10 @@ export function GitGraph({
);
})}
</svg>
- <div className="git-rows" style={{ left: git.graphWidth + 8, width: git.rowWidth }}>
+ <div
+ className="git-rows"
+ style={{ left: git.graphWidth + 8, width: git.rowWidth, ...columnVars(git.columns) }}
+ >
{git.rows.map((row) => {
const messageId = row.kind === "message" ? row.message.id : null;
return (
diff --git a/packages/template/src/Graph.tsx b/packages/template/src/Graph.tsx
index 02d938d..b25db9a 100644
--- a/packages/template/src/Graph.tsx
+++ b/packages/template/src/Graph.tsx
@@ -14,11 +14,12 @@ import { createContext, useCallback, useContext, useEffect, useMemo, useState }
import { unreadViewMessages } from "../../cli/src/view/change.js";
import type { LineageViewModel, ViewSession } from "../../cli/src/view/model.js";
import { hitMessageIds, hitSessionIds } from "../../cli/src/view/search.js";
+import { COLUMN_HEAD, ColumnHead, loadColumns, saveColumns } from "./ColumnHead.js";
import { pageToken, saveRead } from "./data.js";
import { type FilesTarget, FilesView } from "./FilesView.js";
import { useFullscreen } from "./fullscreen.js";
import { GitGraph } from "./GitGraph.js";
-import { type GitLayout, layoutGitGraph } from "./gitLayout.js";
+import { type GitLayout, layoutGitGraph, type RowColumns } from "./gitLayout.js";
import { centreViewport, headOf, type MapPoint } from "./graph.js";
import type { MapSearchState } from "./MapSearch.js";
import { Outline, type OutlineTarget } from "./Outline.js";
@@ -54,6 +55,8 @@ const GraphActions = createContext<{
openNode: (sessionId: string, messageId: string, branchId?: string) => void;
openContinue: (sessionId: string, messageId: string) => void;
unfold: (segmentId: string) => void;
+ /** Sets the message rows' column widths (the column head's handles). */
+ resizeColumns: (columns: RowColumns) => void;
}>({
selection: null,
openIds: new Set(),
@@ -63,6 +66,7 @@ const GraphActions = createContext<{
openNode: () => {},
openContinue: () => {},
unfold: () => {},
+ resizeColumns: () => {},
});
/** An opened session: its message graph and where it sits on the canvas. */
@@ -93,24 +97,27 @@ function SessionMessages({
highlights: ReadonlySet<string> | undefined;
activeHitId: string | null;
}) {
- const { selection, readIds, bigChangeLines, openNode, openContinue, unfold } =
+ const { selection, readIds, bigChangeLines, openNode, openContinue, unfold, resizeColumns } =
useContext(GraphActions);
const own = selection?.sessionId === session.sessionId;
if (git.rows.length === 0)
return <p className="graph-status empty">No messages recorded in this session yet.</p>;
return (
- <GitGraph
- git={git}
- selectedId={selection?.type === "node" && own ? selection.nodeId : null}
- activeSegmentId={selection?.type === "node" && own ? (selection.branchId ?? null) : null}
- highlightIds={highlights}
- activeHitId={activeHitId}
- readIds={readIds}
- bigChangeLines={bigChangeLines}
- onSelect={(row) => openNode(session.sessionId, row.message.id, row.segmentId)}
- onUnfold={unfold}
- onContinue={(continues) => openContinue(continues.sessionId, continues.id)}
- />
+ <>
+ <ColumnHead git={git} onResize={resizeColumns} />
+ <GitGraph
+ git={git}
+ selectedId={selection?.type === "node" && own ? selection.nodeId : null}
+ activeSegmentId={selection?.type === "node" && own ? (selection.branchId ?? null) : null}
+ highlightIds={highlights}
+ activeHitId={activeHitId}
+ readIds={readIds}
+ bigChangeLines={bigChangeLines}
+ onSelect={(row) => openNode(session.sessionId, row.message.id, row.segmentId)}
+ onUnfold={unfold}
+ onContinue={(continues) => openContinue(continues.sessionId, continues.id)}
+ />
+ </>
);
}
@@ -227,6 +234,9 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
return { type: "node", sessionId: initial.sessionId, nodeId: initial.messageId };
});
const [unfolded, setUnfolded] = useState<Set<string>>(() => new Set());
+ /** Message rows' column widths; the same for every session, kept in this browser. */
+ const [columns, setColumns] = useState<RowColumns>(loadColumns);
+ useEffect(() => saveColumns(columns), [columns]);
const [openAll, setOpenAll] = useState(false);
const [showOutline, setShowOutline] = useState(true);
// The files, unread and outline views share the left column; only one shows.
@@ -337,6 +347,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
let options = {
unfolded,
openAll,
+ columns,
headId: head?.sessionId === sessionId ? head.messageId : null,
};
// A search hit inside a folded branch must be visible to be highlighted,
@@ -372,6 +383,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
openIds,
unfolded,
openAll,
+ columns,
highlights,
head?.sessionId,
head?.messageId,
@@ -385,7 +397,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
for (const [sessionId, git] of messageGits)
out.set(
sessionId,
- OPEN_TOP + (git.rows.length === 0 ? OPEN_EMPTY : git.height) + OPEN_BOTTOM,
+ OPEN_TOP + (git.rows.length === 0 ? OPEN_EMPTY : COLUMN_HEAD + git.height) + OPEN_BOTTOM,
);
return out;
}, [messageGits]);
@@ -421,7 +433,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
// Frame the whole row (lanes and text), not only its dot.
return {
x: opening.left + opening.git.graphWidth / 2,
- y: opening.top + row.y,
+ y: opening.top + COLUMN_HEAD + row.y,
left: opening.left,
right: opening.left + opening.git.width,
};
@@ -579,6 +591,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
openNode,
openContinue,
unfold,
+ resizeColumns: setColumns,
}),
[selection, openIds, readIds, bigChangeLines, toggleSession, openNode, openContinue, unfold],
);
diff --git a/packages/template/src/gitLayout.ts b/packages/template/src/gitLayout.ts
index b90469e..d977138 100644
--- a/packages/template/src/gitLayout.ts
+++ b/packages/template/src/gitLayout.ts
@@ -64,6 +64,41 @@ const ROW_GAP = 8;
*/
export const TITLE_MIN_WIDTH = 180;
+/**
+ * Widths of a message row's resizable columns (px): the time, the title and
+ * the details after it (commits, changed lines, marks). The user drags them in
+ * the column head; the message number keeps its own narrow column.
+ */
+export interface RowColumns {
+ time: number;
+ title: number;
+ details: number;
+}
+
+export const DEFAULT_COLUMNS: RowColumns = { time: 74, title: 260, details: 150 };
+export const COLUMN_MIN: RowColumns = { time: 40, title: TITLE_MIN_WIDTH, details: 60 };
+export const COLUMN_MAX = 1200;
+/** The message number column, the gap between columns and the row's padding. */
+export const ID_COLUMN = 36;
+const COLUMN_GAP = 8;
+const COLUMN_PAD = 16;
+
+/** Row text width the columns add up to. */
+export function columnsWidth(columns: RowColumns): number {
+ return COLUMN_PAD + columns.time + ID_COLUMN + columns.title + columns.details + 3 * COLUMN_GAP;
+}
+
+/** Keeps every column between its minimum and `COLUMN_MAX`; junk falls back to the default. */
+export function clampColumns(value: unknown): RowColumns {
+ const raw = (typeof value === "object" && value !== null ? value : {}) as Record<string, unknown>;
+ const pick = (key: keyof RowColumns): number => {
+ const n = raw[key];
+ if (typeof n !== "number" || !Number.isFinite(n)) return DEFAULT_COLUMNS[key];
+ return Math.round(Math.min(COLUMN_MAX, Math.max(COLUMN_MIN[key], n)));
+ };
+ return { time: pick("time"), title: pick("title"), details: pick("details") };
+}
+
/** How many lane colours the page defines (`--l0` … `--l5`). */
export const LANE_COLORS = 6;
@@ -201,6 +236,8 @@ export interface GitLayout {
graphWidth: number;
/** Width of the row text right of the dots. */
rowWidth: number;
+ /** The column widths the rows were laid out with, if any. */
+ columns?: RowColumns;
/** Whole box: graph width, gap, then the row text. */
width: number;
height: number;
@@ -228,6 +265,11 @@ export interface GitLayoutOptions {
itemEnd?: (item: GitNode) => number | null;
/** Width of the row text area; defaults to `ROW_WIDTH`. */
rowWidth?: number;
+ /**
+ * Message rows laid out in resizable columns: the title wraps inside its own
+ * column and the details wrap inside theirs. Replaces `rowWidth`.
+ */
+ columns?: RowColumns;
/**
* Extra height to leave below an item's row, by item id: the project map opens
* a session in place by reserving room for its messages under the session's
@@ -262,6 +304,45 @@ const TAG_LINE = 18;
/** Padding, the time column and the gaps around it. */
const ROW_FIXED = 106;
+/** The things in a row's details column, as rough widths in px. */
+export interface RowDetails {
+ tags: number;
+ change: boolean;
+ continues: string | null;
+ returns: number;
+ head: boolean;
+ unsummarized: boolean;
+}
+
+const DETAIL_LINE = 18;
+
+/**
+ * Height of a message row laid out in columns: the title wraps in its column,
+ * the details wrap in theirs, and the taller of the two decides.
+ */
+export function columnRowHeight(title: string, details: RowDetails, columns: RowColumns): number {
+ const titleLines = Math.max(1, Math.ceil((title.length * TITLE_CHAR) / columns.title));
+ const widths = [
+ ...Array.from({ length: details.tags }, () => TAG_WIDTH),
+ ...(details.change ? [120] : []),
+ ...(details.continues === null ? [] : [150 + details.continues.length * 6.4]),
+ ...Array.from({ length: details.returns }, () => 44),
+ ...(details.head ? [92] : []),
+ ...(details.unsummarized ? [116] : []),
+ ];
+ let lines = 0;
+ let used = columns.details;
+ for (const wanted of widths) {
+ const width = Math.min(wanted, columns.details);
+ if (used + width > columns.details) {
+ lines += 1;
+ used = 0;
+ }
+ used += width + 4;
+ }
+ return Math.max(ROW_HEIGHT, 12 + Math.max(titleLines * TITLE_LINE, lines * DETAIL_LINE));
+}
+
/**
* Height of a message row whose title (and branch label) wrap instead of being
* cut with an ellipsis: the width left for the title after the fixed parts of
@@ -315,7 +396,8 @@ function branchOf(ids: string[], byId: Map<string, GitNode>): GitBranch {
}
export function layoutGitGraph(messages: GitNode[], options: GitLayoutOptions = {}): GitLayout {
- const rowWidth = options.rowWidth ?? ROW_WIDTH;
+ const columns = options.columns;
+ const rowWidth = columns ? columnsWidth(columns) : (options.rowWidth ?? ROW_WIDTH);
const index = new Map(messages.map((message, at) => [message.id, at]));
const byId = new Map(messages.map((message) => [message.id, message]));
const kids = new Map<string | null, string[]>();
@@ -435,17 +517,31 @@ export function layoutGitGraph(messages: GitNode[], options: GitLayoutOptions =
row.segment.ids[0] === row.id;
if (row.gap) cursor += ROOT_GAP;
const message = row.kind === "message" ? byId.get(row.id ?? "") : undefined;
- row.height = message
- ? rowHeight(
- message,
- {
- returns: (message.links ?? []).filter((id) => segOf.has(id)).length,
- tags: tagsOf(message).length,
- head: message.id === headId,
- },
- rowWidth,
- )
- : ROW_HEIGHT;
+ const returns = message ? (message.links ?? []).filter((id) => segOf.has(id)).length : 0;
+ row.height = !message
+ ? ROW_HEIGHT
+ : columns
+ ? columnRowHeight(
+ message.title,
+ {
+ tags: tagsOf(message).length,
+ change: message.change !== undefined,
+ continues: message.continues?.sessionTitle ?? null,
+ returns,
+ head: message.id === headId,
+ unsummarized: message.unsummarized === true,
+ },
+ columns,
+ )
+ : rowHeight(
+ message,
+ {
+ returns,
+ tags: tagsOf(message).length,
+ head: message.id === headId,
+ },
+ rowWidth,
+ );
row.y = cursor + row.height / 2;
cursor += row.height;
const space = row.kind === "message" ? options.spaceAfter?.get(row.id ?? "") : undefined;
@@ -563,6 +659,7 @@ export function layoutGitGraph(messages: GitNode[], options: GitLayoutOptions =
laneX,
graphWidth,
rowWidth,
+ ...(columns ? { columns } : {}),
width: graphWidth + ROW_GAP + rowWidth,
height: cursor,
headId,
diff --git a/packages/template/src/styles.css b/packages/template/src/styles.css
index 135191d..29fb4d9 100644
--- a/packages/template/src/styles.css
+++ b/packages/template/src/styles.css
@@ -2185,6 +2185,100 @@ time {
background: var(--hover);
}
+/* Outside columns the details are part of the row's flex line, as before. */
+.git-details {
+ display: contents;
+}
+
+/* Message rows in resizable columns: time, number, title, details. The widths
+ come from `--col-*`, set by `columnVars` from the column head's handles. */
+.in-columns .git-row {
+ display: grid;
+ grid-template-columns: var(--col-time) var(--col-id) var(--col-title) var(--col-details);
+ column-gap: 8px;
+}
+
+.in-columns .git-time {
+ width: auto;
+}
+
+.in-columns .git-title {
+ min-width: 0;
+}
+
+.in-columns .git-more .git-title {
+ grid-column: 1 / -1;
+}
+
+.in-columns .git-details {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 2px 4px;
+ min-width: 0;
+}
+
+.in-columns .git-tags {
+ justify-content: flex-start;
+ max-width: none;
+}
+
+.in-columns .git-continues {
+ max-width: 100%;
+}
+
+.in-columns .left-off,
+.in-columns .unsummarized {
+ margin-top: 0;
+}
+
+.column-head {
+ display: grid;
+ grid-template-columns: var(--col-time) var(--col-id) var(--col-title) var(--col-details);
+ column-gap: 8px;
+ height: 22px;
+ padding: 0 8px;
+ color: var(--muted);
+ font-size: 10px;
+ font-weight: 600;
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+ border-bottom: 1px solid var(--line);
+ align-items: center;
+}
+
+.column-name {
+ position: relative;
+ white-space: nowrap;
+}
+
+/* A thin bar on the column's right edge, inside the 8px gap; wider to grab. */
+.column-handle {
+ position: absolute;
+ top: -4px;
+ right: -8px;
+ width: 8px;
+ height: 22px;
+ cursor: col-resize;
+ touch-action: none;
+}
+
+.column-handle::after {
+ content: "";
+ position: absolute;
+ top: 4px;
+ bottom: 4px;
+ left: 3px;
+ width: 2px;
+ border-radius: 1px;
+ background: var(--line);
+}
+
+.column-handle:hover::after,
+.column-handle.is-dragging::after {
+ background: var(--accent);
+}
+
.git-row.in-branch {
background: color-mix(in srgb, var(--accent) 6%, transparent);
}
diff --git a/packages/template/test/columns.test.ts b/packages/template/test/columns.test.ts
new file mode 100644
index 0000000..b591154
--- /dev/null
+++ b/packages/template/test/columns.test.ts
@@ -0,0 +1,164 @@
+import { ReactFlowProvider } from "@xyflow/react";
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import type { ViewNode } from "../../cli/src/view/model.js";
+import { COLUMN_HEAD, ColumnHead, loadColumns, saveColumns } from "../src/ColumnHead.js";
+import { columnVars, GitGraph } from "../src/GitGraph.js";
+import {
+ COLUMN_MAX,
+ COLUMN_MIN,
+ clampColumns,
+ columnRowHeight,
+ columnsWidth,
+ DEFAULT_COLUMNS,
+ ID_COLUMN,
+ layoutGitGraph,
+ ROW_HEIGHT,
+} from "../src/gitLayout.js";
+
+const T0 = "2026-10-26T10:00:00.000Z";
+const node = (id: string, parent: string | null, extra: Partial<ViewNode> = {}): ViewNode => ({
+ id,
+ kind: "message",
+ title: `Message ${id}`,
+ at: T0,
+ parent,
+ ...extra,
+});
+const none = {
+ tags: 0,
+ change: false,
+ continues: null,
+ returns: 0,
+ head: false,
+ unsummarized: false,
+};
+
+describe("resizable message columns", () => {
+ it("clamps each column and falls back to the default for junk", () => {
+ expect(clampColumns({ time: 1, title: 99_999, details: 120.6 })).toEqual({
+ time: COLUMN_MIN.time,
+ title: COLUMN_MAX,
+ details: 121,
+ });
+ expect(clampColumns({ time: "wide", title: Number.NaN })).toEqual(DEFAULT_COLUMNS);
+ expect(clampColumns(null)).toEqual(DEFAULT_COLUMNS);
+ });
+
+ it("adds the columns, the number column, the gaps and the padding up to the row width", () => {
+ const columns = { time: 70, title: 300, details: 100 };
+ expect(columnsWidth(columns)).toBe(16 + 70 + ID_COLUMN + 300 + 100 + 3 * 8);
+ const git = layoutGitGraph([node("a", null)], { columns });
+ expect(git.columns).toEqual(columns);
+ expect(git.rowWidth).toBe(columnsWidth(columns));
+ expect(layoutGitGraph([node("a", null)]).columns).toBeUndefined();
+ });
+
+ it("wraps the title in its own column: a wider column needs fewer lines", () => {
+ const title = "a".repeat(120);
+ const narrow = columnRowHeight(title, none, { ...DEFAULT_COLUMNS, title: 200 });
+ const wide = columnRowHeight(title, none, { ...DEFAULT_COLUMNS, title: 800 });
+ expect(narrow).toBeGreaterThan(wide);
+ expect(wide).toBe(ROW_HEIGHT);
+ });
+
+ it("wraps the details in theirs: chips past the column's width start a new line", () => {
+ const busy = {
+ tags: 3,
+ change: true,
+ continues: "An earlier session",
+ returns: 1,
+ head: true,
+ unsummarized: true,
+ };
+ const short = "Short";
+ const narrow = columnRowHeight(short, busy, { ...DEFAULT_COLUMNS, details: 80 });
+ const wide = columnRowHeight(short, busy, { ...DEFAULT_COLUMNS, details: 1200 });
+ expect(narrow).toBeGreaterThan(wide);
+ expect(columnRowHeight(short, none, DEFAULT_COLUMNS)).toBe(ROW_HEIGHT);
+ });
+
+ it("lays rows out with the column heights and draws them as a grid", () => {
+ const git = layoutGitGraph(
+ [node("a", null, { title: "b".repeat(200) }), node("b", "a", { unsummarized: true })],
+ { columns: DEFAULT_COLUMNS },
+ );
+ expect(git.rows[0]?.height).toBeGreaterThan(ROW_HEIGHT);
+ const html = renderToStaticMarkup(
+ createElement(GitGraph, {
+ git,
+ selectedId: null,
+ activeSegmentId: null,
+ highlightIds: undefined,
+ activeHitId: null,
+ readIds: new Set<string>(),
+ bigChangeLines: 300,
+ onSelect: () => {},
+ onUnfold: () => {},
+ onContinue: () => {},
+ }),
+ );
+ expect(html).toContain('class="git-graph in-columns"');
+ expect(html).toContain("--col-title:260px");
+ expect(html).toMatch(/<span class="git-details">.*not summarized yet/);
+ expect(columnVars(undefined)).toEqual({});
+ });
+
+ it("heads the columns with a resize handle on time, message and details", () => {
+ const git = layoutGitGraph([node("a", null)], { columns: DEFAULT_COLUMNS });
+ const html = renderToStaticMarkup(
+ createElement(
+ ReactFlowProvider,
+ null,
+ createElement(ColumnHead, { git, onResize: () => {} }),
+ ),
+ );
+ expect(html).toContain("Time");
+ expect(html).toContain("Commits · changes");
+ expect(html.match(/role="separator"/g)).toHaveLength(3);
+ expect(COLUMN_HEAD).toBe(22);
+ const plain = layoutGitGraph([node("a", null)]);
+ expect(
+ renderToStaticMarkup(
+ createElement(
+ ReactFlowProvider,
+ null,
+ createElement(ColumnHead, { git: plain, onResize: () => {} }),
+ ),
+ ),
+ ).toBe("");
+ });
+});
+
+describe("column widths in the browser", () => {
+ afterEach(() => vi.unstubAllGlobals());
+
+ it("keeps the widths and reads junk or a blocked storage as the default", () => {
+ const store = new Map<string, string>();
+ vi.stubGlobal("window", {
+ localStorage: {
+ getItem: (key: string) => store.get(key) ?? null,
+ setItem: (key: string, value: string) => store.set(key, value),
+ },
+ });
+ expect(loadColumns()).toEqual(DEFAULT_COLUMNS);
+ saveColumns({ time: 60, title: 400, details: 90 });
+ expect(loadColumns()).toEqual({ time: 60, title: 400, details: 90 });
+ store.set("cogit.mapColumns", "{not json");
+ expect(loadColumns()).toEqual(DEFAULT_COLUMNS);
+
+ vi.stubGlobal("window", {
+ localStorage: {
+ getItem: () => {
+ throw new Error("blocked");
+ },
+ setItem: () => {
+ throw new Error("blocked");
+ },
+ },
+ });
+ expect(loadColumns()).toEqual(DEFAULT_COLUMNS);
+ expect(() => saveColumns(DEFAULT_COLUMNS)).not.toThrow();
+ });
+});