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): each session keeps its own message row width

Erene930a682b23b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5aab636..4bc10c3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
-- The map's resize edge now runs down its whole right side: dragging it widens the session rows and every open session's messages together, and the messages end where the session rows end.
+- Each session on the map now keeps its own message row width: dragging one session's edge leaves the others alone, and the width survives a reload.
## [0.22.0] - 2026-10-30
### Added
diff --git a/packages/template/src/Graph.tsx b/packages/template/src/Graph.tsx
index efc1825..15b02c2 100644
--- a/packages/template/src/Graph.tsx
+++ b/packages/template/src/Graph.tsx
@@ -18,17 +18,11 @@ 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,
- type GitLayoutOptions,
- layoutGitGraph,
- MAP_WIDTH,
- messageRowWidth,
-} from "./gitLayout.js";
+import { type GitLayout, layoutGitGraph, ROW_WIDTH } from "./gitLayout.js";
import { centreViewport, headOf, type MapPoint } from "./graph.js";
import type { MapSearchState } from "./MapSearch.js";
import { Outline, type OutlineTarget } from "./Outline.js";
-import { loadMapWidth, RowEdge, saveMapWidth } from "./RowEdge.js";
+import { loadRowWidths, RowEdge, type RowWidths, saveRowWidths } from "./RowEdge.js";
import { OPEN_LINK_DROP, SessionMap } from "./SessionMap.js";
import { DrillDown, type Selection } from "./SidePanel.js";
import { usePageWheel } from "./scroll.js";
@@ -62,8 +56,7 @@ const GraphActions = createContext<{
openContinue: (sessionId: string, messageId: string) => void;
unfold: (segmentId: string) => void;
/** Sets the width of the open sessions' message rows (their right edge). */
- mapWidth: number;
- resizeMap: (width: number) => void;
+ resizeRows: (sessionId: string, width: number) => void;
}>({
selection: null,
openIds: new Set(),
@@ -73,8 +66,7 @@ const GraphActions = createContext<{
openNode: () => {},
openContinue: () => {},
unfold: () => {},
- mapWidth: MAP_WIDTH,
- resizeMap: () => {},
+ resizeRows: () => {},
});
/** An opened session: its message graph and where it sits on the canvas. */
@@ -105,38 +97,34 @@ function SessionMessages({
highlights: ReadonlySet<string> | undefined;
activeHitId: string | null;
}) {
- const { selection, readIds, bigChangeLines, openNode, openContinue, unfold } =
+ const { selection, readIds, bigChangeLines, openNode, openContinue, unfold, resizeRows } =
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)}
- />
+ <div className="session-rows">
+ <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)}
+ />
+ <RowEdge git={git} onResize={(width) => resizeRows(session.sessionId, width)} />
+ </div>
);
}
function ProjectBox({ data }: NodeProps<ProjectFlowNode>) {
- const { openSession, openContinue, selection, openIds, mapWidth, resizeMap } =
- useContext(GraphActions);
+ const { openSession, openContinue, selection, openIds } = useContext(GraphActions);
return (
<div className="map-node">
- <RowEdge
- left={data.graph.git.width}
- height={data.graph.git.height}
- width={mapWidth}
- onResize={resizeMap}
- />
<SessionMap
model={data.model}
graph={data.graph}
@@ -246,9 +234,16 @@ 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());
- /** Where every row ends; dragged at the map's right edge. */
- const [mapWidth, setMapWidth] = useState(loadMapWidth);
- useEffect(() => saveMapWidth(mapWidth), [mapWidth]);
+ /** Each session's message row width, dragged at the rows' right edge. */
+ const [rowWidths, setRowWidths] = useState<RowWidths>(loadRowWidths);
+ useEffect(() => saveRowWidths(rowWidths), [rowWidths]);
+ const resizeRows = useCallback((sessionId: string, width: number) => {
+ setRowWidths((previous) => {
+ // Back at the default (double-click): forget the session.
+ const { [sessionId]: _, ...rest } = previous;
+ return width === ROW_WIDTH ? rest : { ...rest, [sessionId]: width };
+ });
+ }, []);
const [openAll, setOpenAll] = useState(false);
const [showOutline, setShowOutline] = useState(true);
// The files, unread and outline views share the left column; only one shows.
@@ -356,18 +351,10 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
for (const sessionId of openIds) {
const session = findSession(model, sessionId);
if (!session) continue;
- // The rows end where the session rows end; the lanes' width decides how
- // much of that is text, and it does not depend on the text width.
- const lay = (options: GitLayoutOptions): GitLayout => {
- const probe = layoutGitGraph(session.messages, options);
- return layoutGitGraph(session.messages, {
- ...options,
- rowWidth: messageRowWidth(mapWidth, probe.graphWidth),
- });
- };
- let options: GitLayoutOptions = {
+ let options = {
unfolded,
openAll,
+ rowWidth: rowWidths[sessionId] ?? ROW_WIDTH,
headId: head?.sessionId === sessionId ? head.messageId : null,
};
// A search hit inside a folded branch must be visible to be highlighted,
@@ -380,7 +367,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
.map((segment) => segment.id);
if (extra.length > 0) options = { ...options, unfolded: new Set([...unfolded, ...extra]) };
}
- let layout = lay(options);
+ let layout = layoutGitGraph(session.messages, options);
const targetId = target?.sessionId === sessionId ? target.nodeId : null;
if (
targetId !== null &&
@@ -390,7 +377,10 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
// rather than letting the page land on a row the user cannot see.
const segment = layout.segments.find((candidate) => candidate.ids.includes(targetId));
if (segment !== undefined)
- layout = lay({ ...options, unfolded: new Set([...unfolded, segment.id]) });
+ layout = layoutGitGraph(session.messages, {
+ ...options,
+ unfolded: new Set([...unfolded, segment.id]),
+ });
}
out.set(sessionId, layout);
}
@@ -400,7 +390,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
openIds,
unfolded,
openAll,
- mapWidth,
+ rowWidths,
highlights,
head?.sessionId,
head?.messageId,
@@ -419,10 +409,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
return out;
}, [messageGits]);
- const sessionGraph = useMemo(
- () => layoutSessionGraph(model, spaceAfter, mapWidth),
- [model, spaceAfter, mapWidth],
- );
+ const sessionGraph = useMemo(() => layoutSessionGraph(model, spaceAfter), [model, spaceAfter]);
const openings = useMemo(() => {
const out: Opening[] = [];
@@ -611,8 +598,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
openNode,
openContinue,
unfold,
- mapWidth,
- resizeMap: setMapWidth,
+ resizeRows,
}),
[
selection,
@@ -623,7 +609,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
openNode,
openContinue,
unfold,
- mapWidth,
+ resizeRows,
],
);
diff --git a/packages/template/src/RowEdge.tsx b/packages/template/src/RowEdge.tsx
index 226a33b..5ffedb0 100644
--- a/packages/template/src/RowEdge.tsx
+++ b/packages/template/src/RowEdge.tsx
@@ -1,30 +1,36 @@
import { useStore } from "@xyflow/react";
import { type PointerEvent, useState } from "react";
-import { clampMapWidth, MAP_WIDTH } from "./gitLayout.js";
+import { clampRowWidth, type GitLayout, ROW_WIDTH } from "./gitLayout.js";
/**
- * The project map's right edge, full height: drag it to make every row, the
- * sessions' and the open sessions' messages, wider or narrower; double-click it
- * to reset. Titles get the room and wrap into fewer lines. The width stays in
- * this browser.
+ * The right edge of an open session's message rows: drag it to make the rows
+ * wider or narrower, double-click it to reset. Titles get the room and wrap
+ * into fewer lines. Each session keeps its own width, and it stays in this
+ * browser.
*/
-const KEY = "cogit.mapWidth";
+const KEY = "cogit.sessionRowWidths";
/** The grab area stays this wide on screen whatever the zoom. */
const GRAB = 12;
-export function loadMapWidth(): number {
+/** Widths the user dragged, by session id; a session not listed has `ROW_WIDTH`. */
+export type RowWidths = Readonly<Record<string, number>>;
+
+export function loadRowWidths(): RowWidths {
try {
- const raw = window.localStorage.getItem(KEY);
- return raw === null ? MAP_WIDTH : clampMapWidth(Number(raw));
+ const raw: unknown = JSON.parse(window.localStorage.getItem(KEY) ?? "{}");
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return {};
+ const out: Record<string, number> = {};
+ for (const [sessionId, width] of Object.entries(raw)) out[sessionId] = clampRowWidth(width);
+ return out;
} catch {
- return MAP_WIDTH;
+ return {};
}
}
-export function saveMapWidth(width: number): void {
+export function saveRowWidths(widths: RowWidths): void {
try {
- window.localStorage.setItem(KEY, String(width));
+ window.localStorage.setItem(KEY, JSON.stringify(widths));
} catch {
// Private window or blocked storage: the width lasts until the page closes.
}
@@ -40,19 +46,7 @@ function capture(event: PointerEvent, on: boolean): void {
}
}
-export function RowEdge({
- left,
- height,
- width,
- onResize,
-}: {
- /** Where the edge sits on the canvas. */
- left: number;
- height: number;
- /** The width the edge sets; a drag adds to it. */
- width: number;
- onResize: (width: number) => void;
-}) {
+export function RowEdge({ git, onResize }: { git: GitLayout; onResize: (width: number) => void }) {
// The canvas may be zoomed: a screen pixel is 1/zoom of a canvas pixel.
const zoom = useStore((state) => state.transform[2]) || 1;
const [start, setStart] = useState<{ x: number; width: number } | null>(null);
@@ -62,17 +56,17 @@ export function RowEdge({
className={`row-edge nodrag nopan${start ? " is-dragging" : ""}`}
role="separator"
aria-orientation="vertical"
- aria-label="Resize the map's rows"
+ aria-label="Resize the message rows"
title="Drag to make the rows wider or narrower · double-click to reset"
- style={{ left: left - grab / 2, width: grab, height }}
+ style={{ left: git.width - grab / 2, width: grab, height: git.height }}
onPointerDown={(event: PointerEvent) => {
event.stopPropagation();
capture(event, true);
- setStart({ x: event.clientX, width });
+ setStart({ x: event.clientX, width: git.rowWidth });
}}
onPointerMove={(event: PointerEvent) => {
if (!start) return;
- onResize(clampMapWidth(start.width + (event.clientX - start.x) / zoom));
+ onResize(clampRowWidth(start.width + (event.clientX - start.x) / zoom));
}}
onPointerUp={(event: PointerEvent) => {
if (!start) return;
@@ -81,7 +75,7 @@ export function RowEdge({
}}
onDoubleClick={(event) => {
event.stopPropagation();
- onResize(MAP_WIDTH);
+ onResize(ROW_WIDTH);
}}
/>
);
diff --git a/packages/template/src/gitLayout.ts b/packages/template/src/gitLayout.ts
index e5e95ca..854da54 100644
--- a/packages/template/src/gitLayout.ts
+++ b/packages/template/src/gitLayout.ts
@@ -64,28 +64,14 @@ const ROW_GAP = 8;
*/
export const TITLE_MIN_WIDTH = 180;
-/**
- * The project map's text column: where the session rows end, measured from
- * their left edge. The user drags the map's right edge to change it, and an open
- * session's message rows end at the same place.
- */
-export const MAP_WIDTH = 720;
-export const MAP_WIDTH_MIN = 560;
-export const MAP_WIDTH_MAX = 1800;
-
-/** A dragged or stored map width, kept in range; junk falls back to `MAP_WIDTH`. */
-export function clampMapWidth(value: unknown): number {
- if (typeof value !== "number" || !Number.isFinite(value)) return MAP_WIDTH;
- return Math.round(Math.min(MAP_WIDTH_MAX, Math.max(MAP_WIDTH_MIN, value)));
-}
-
-/**
- * Text width for an open session's message rows so they end where the session
- * rows end; the session's own lanes (`graphWidth`) take the rest. A very wide
- * set of lanes still leaves the title room to read.
- */
-export function messageRowWidth(mapWidth: number, graphWidth: number): number {
- return Math.max(TITLE_MIN_WIDTH * 2, mapWidth - graphWidth - ROW_GAP);
+/** How far the user may drag an open session's message rows narrower or wider. */
+export const ROW_WIDTH_MIN = 360;
+export const ROW_WIDTH_MAX = 1600;
+
+/** A dragged or stored row width, kept in range; junk falls back to `ROW_WIDTH`. */
+export function clampRowWidth(value: unknown): number {
+ if (typeof value !== "number" || !Number.isFinite(value)) return ROW_WIDTH;
+ return Math.round(Math.min(ROW_WIDTH_MAX, Math.max(ROW_WIDTH_MIN, value)));
}
/** How many lane colours the page defines (`--l0` … `--l5`). */
diff --git a/packages/template/src/sessionLayout.ts b/packages/template/src/sessionLayout.ts
index 6024d28..04580f3 100644
--- a/packages/template/src/sessionLayout.ts
+++ b/packages/template/src/sessionLayout.ts
@@ -1,5 +1,5 @@
import type { LineageViewModel, ViewSession } from "../../cli/src/view/model.js";
-import { type GitLayout, type GitNode, layoutGitGraph, MAP_WIDTH } from "./gitLayout.js";
+import { type GitLayout, type GitNode, layoutGitGraph } from "./gitLayout.js";
import { headOf } from "./graph.js";
/**
@@ -10,6 +10,9 @@ import { headOf } from "./graph.js";
* root. Epochs are not boxes any more, just tags on the dots.
*/
+/** Wider than a message row: a session row carries a title, a count and a tag. */
+export const SESSION_ROW_WIDTH = 720;
+
function time(value: string | undefined): number {
if (!value) return Number.NEGATIVE_INFINITY;
const at = Date.parse(value);
@@ -68,8 +71,6 @@ export function layoutSessionGraph(
model: LineageViewModel,
/** Room to leave under a session's row for its opened messages, by session id. */
spaceAfter?: ReadonlyMap<string, number>,
- /** The session rows' width: the map's right edge, which the user may drag. */
- mapWidth: number = MAP_WIDTH,
): SessionGraph {
const sessions = allSessions(model);
const byId = new Map(sessions.map((session) => [session.sessionId, session]));
@@ -101,7 +102,7 @@ export function layoutSessionGraph(
const git = layoutGitGraph(items, {
fold: false,
- rowWidth: mapWidth,
+ rowWidth: SESSION_ROW_WIDTH,
headId: headOf(model)?.sessionId ?? null,
itemEnd: endIndex,
...(spaceAfter === undefined ? {} : { spaceAfter }),
diff --git a/packages/template/src/styles.css b/packages/template/src/styles.css
index fd7ee52..4b8ac44 100644
--- a/packages/template/src/styles.css
+++ b/packages/template/src/styles.css
@@ -2411,11 +2411,14 @@ time {
position: absolute;
}
-/* The map's right edge (RowEdge.tsx): a faint line that lights up to grab. */
+.session-rows {
+ position: relative;
+}
+
+/* The rows' right edge (RowEdge.tsx): a faint line that lights up to grab. */
.row-edge {
position: absolute;
top: 0;
- z-index: 2;
cursor: col-resize;
touch-action: none;
}
diff --git a/packages/template/test/rowEdge.test.ts b/packages/template/test/rowEdge.test.ts
index 389076d..9c913e7 100644
--- a/packages/template/test/rowEdge.test.ts
+++ b/packages/template/test/rowEdge.test.ts
@@ -4,45 +4,39 @@ import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
- clampMapWidth,
- MAP_WIDTH,
- MAP_WIDTH_MAX,
- MAP_WIDTH_MIN,
- messageRowWidth,
- TITLE_MIN_WIDTH,
+ clampRowWidth,
+ layoutGitGraph,
+ ROW_WIDTH,
+ ROW_WIDTH_MAX,
+ ROW_WIDTH_MIN,
} from "../src/gitLayout.js";
-import { loadMapWidth, RowEdge, saveMapWidth } from "../src/RowEdge.js";
+import { loadRowWidths, RowEdge, saveRowWidths } from "../src/RowEdge.js";
-describe("dragging the map's right edge", () => {
+const T0 = "2026-10-26T10:00:00.000Z";
+
+describe("dragging the message rows wider", () => {
afterEach(() => vi.unstubAllGlobals());
it("keeps a dragged width in range and reads junk as the default", () => {
- expect(clampMapWidth(10)).toBe(MAP_WIDTH_MIN);
- expect(clampMapWidth(99_999)).toBe(MAP_WIDTH_MAX);
- expect(clampMapWidth(700.4)).toBe(700);
- expect(clampMapWidth(Number.NaN)).toBe(MAP_WIDTH);
- expect(clampMapWidth("wide")).toBe(MAP_WIDTH);
- });
-
- it("ends an open session's messages where the session rows end", () => {
- // 900 wide, 60 of it lanes, 8 gap: the text gets the rest.
- expect(messageRowWidth(900, 60)).toBe(832);
- // Lanes wider than the map still leave a readable title.
- expect(messageRowWidth(600, 500)).toBe(TITLE_MIN_WIDTH * 2);
+ expect(clampRowWidth(10)).toBe(ROW_WIDTH_MIN);
+ expect(clampRowWidth(99_999)).toBe(ROW_WIDTH_MAX);
+ expect(clampRowWidth(700.4)).toBe(700);
+ expect(clampRowWidth(Number.NaN)).toBe(ROW_WIDTH);
+ expect(clampRowWidth("wide")).toBe(ROW_WIDTH);
});
- it("puts a full-height grab strip on the map's right edge", () => {
+ it("puts a full-height grab strip on the rows' right edge", () => {
+ const git = layoutGitGraph(
+ [{ id: "a", kind: "message", title: "A message", at: T0, parent: null }],
+ { rowWidth: 700 },
+ );
const html = renderToStaticMarkup(
- createElement(
- ReactFlowProvider,
- null,
- createElement(RowEdge, { left: 800, height: 1200, width: 720, onResize: () => {} }),
- ),
+ createElement(ReactFlowProvider, null, createElement(RowEdge, { git, onResize: () => {} })),
);
expect(html).toContain('role="separator"');
// At zoom 1 the strip is 12px wide, centred on the edge.
- expect(html).toContain("left:794px");
- expect(html).toContain("height:1200px");
+ expect(html).toContain(`left:${git.width - 6}px`);
+ expect(html).toContain(`height:${git.height}px`);
});
it("takes the pointer although React Flow turns it off inside map nodes", () => {
@@ -50,7 +44,7 @@ describe("dragging the map's right edge", () => {
expect(css).toMatch(/\.row-edge,[^{]*\{\s*pointer-events:\s*all/);
});
- it("remembers the width, and reads a blocked or empty storage as the default", () => {
+ it("remembers each session's width, and reads blocked, empty or junk storage as none", () => {
const store = new Map<string, string>();
vi.stubGlobal("window", {
localStorage: {
@@ -58,9 +52,13 @@ describe("dragging the map's right edge", () => {
setItem: (key: string, value: string) => store.set(key, value),
},
});
- expect(loadMapWidth()).toBe(MAP_WIDTH);
- saveMapWidth(840);
- expect(loadMapWidth()).toBe(840);
+ expect(loadRowWidths()).toEqual({});
+ saveRowWidths({ a: 840, b: 600 });
+ expect(loadRowWidths()).toEqual({ a: 840, b: 600 });
+ store.set("cogit.sessionRowWidths", JSON.stringify({ a: 99_999, b: "wide" }));
+ expect(loadRowWidths()).toEqual({ a: ROW_WIDTH_MAX, b: ROW_WIDTH });
+ store.set("cogit.sessionRowWidths", "[1,2]");
+ expect(loadRowWidths()).toEqual({});
vi.stubGlobal("window", {
localStorage: {
@@ -72,7 +70,7 @@ describe("dragging the map's right edge", () => {
},
},
});
- expect(loadMapWidth()).toBe(MAP_WIDTH);
- expect(() => saveMapWidth(600)).not.toThrow();
+ expect(loadRowWidths()).toEqual({});
+ expect(() => saveRowWidths({ a: 600 })).not.toThrow();
});
});
diff --git a/packages/template/test/sessionLayout.test.ts b/packages/template/test/sessionLayout.test.ts
index 6117495..2ce0ca3 100644
--- a/packages/template/test/sessionLayout.test.ts
+++ b/packages/template/test/sessionLayout.test.ts
@@ -84,12 +84,6 @@ describe("layoutSessionGraph", () => {
]);
});
- it("ends the session rows at the dragged map width", () => {
- const model = modelOf([session("a", 0, 60)]);
- expect(layoutSessionGraph(model).git.rowWidth).toBe(720);
- expect(layoutSessionGraph(model, undefined, 1020).git.rowWidth).toBe(1020);
- });
-
it("runs a child session in the parent's lane", () => {
const earlier = session("a", 0, 60);
const later = session("b", 90, 120, { sessionId: "a", id: "h1", sessionTitle: "Session a" });