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): one full-height resize edge on the map's right side

Erend42f1ffce185
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 27728c1..5aab636 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
-- Dragging the message rows' edge on the map now widens the session rows too, so the whole map grows with it.
+- 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.
## [0.22.0] - 2026-10-30
### Added
diff --git a/packages/template/src/Graph.tsx b/packages/template/src/Graph.tsx
index 6e254ef..efc1825 100644
--- a/packages/template/src/Graph.tsx
+++ b/packages/template/src/Graph.tsx
@@ -18,11 +18,17 @@ 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,
+ type GitLayoutOptions,
+ layoutGitGraph,
+ MAP_WIDTH,
+ messageRowWidth,
+} 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 { loadRowWidth, RowEdge, saveRowWidth } from "./RowEdge.js";
+import { loadMapWidth, RowEdge, saveMapWidth } from "./RowEdge.js";
import { OPEN_LINK_DROP, SessionMap } from "./SessionMap.js";
import { DrillDown, type Selection } from "./SidePanel.js";
import { usePageWheel } from "./scroll.js";
@@ -56,7 +62,8 @@ 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). */
- resizeRows: (width: number) => void;
+ mapWidth: number;
+ resizeMap: (width: number) => void;
}>({
selection: null,
openIds: new Set(),
@@ -66,7 +73,8 @@ const GraphActions = createContext<{
openNode: () => {},
openContinue: () => {},
unfold: () => {},
- resizeRows: () => {},
+ mapWidth: MAP_WIDTH,
+ resizeMap: () => {},
});
/** An opened session: its message graph and where it sits on the canvas. */
@@ -97,34 +105,38 @@ function SessionMessages({
highlights: ReadonlySet<string> | undefined;
activeHitId: string | null;
}) {
- const { selection, readIds, bigChangeLines, openNode, openContinue, unfold, resizeRows } =
+ const { selection, readIds, bigChangeLines, openNode, openContinue, unfold } =
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 (
- <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={resizeRows} />
- </div>
+ <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)}
+ />
);
}
function ProjectBox({ data }: NodeProps<ProjectFlowNode>) {
- const { openSession, openContinue, selection, openIds } = useContext(GraphActions);
+ const { openSession, openContinue, selection, openIds, mapWidth, resizeMap } =
+ 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}
@@ -234,9 +246,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());
- /** Width of the open sessions' message rows; dragged at their right edge. */
- const [rowWidth, setRowWidth] = useState(loadRowWidth);
- useEffect(() => saveRowWidth(rowWidth), [rowWidth]);
+ /** Where every row ends; dragged at the map's right edge. */
+ const [mapWidth, setMapWidth] = useState(loadMapWidth);
+ useEffect(() => saveMapWidth(mapWidth), [mapWidth]);
const [openAll, setOpenAll] = useState(false);
const [showOutline, setShowOutline] = useState(true);
// The files, unread and outline views share the left column; only one shows.
@@ -344,10 +356,18 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
for (const sessionId of openIds) {
const session = findSession(model, sessionId);
if (!session) continue;
- let options = {
+ // 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 = {
unfolded,
openAll,
- rowWidth,
headId: head?.sessionId === sessionId ? head.messageId : null,
};
// A search hit inside a folded branch must be visible to be highlighted,
@@ -360,7 +380,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 = layoutGitGraph(session.messages, options);
+ let layout = lay(options);
const targetId = target?.sessionId === sessionId ? target.nodeId : null;
if (
targetId !== null &&
@@ -370,10 +390,7 @@ 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 = layoutGitGraph(session.messages, {
- ...options,
- unfolded: new Set([...unfolded, segment.id]),
- });
+ layout = lay({ ...options, unfolded: new Set([...unfolded, segment.id]) });
}
out.set(sessionId, layout);
}
@@ -383,7 +400,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
openIds,
unfolded,
openAll,
- rowWidth,
+ mapWidth,
highlights,
head?.sessionId,
head?.messageId,
@@ -403,8 +420,8 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
}, [messageGits]);
const sessionGraph = useMemo(
- () => layoutSessionGraph(model, spaceAfter, rowWidth),
- [model, spaceAfter, rowWidth],
+ () => layoutSessionGraph(model, spaceAfter, mapWidth),
+ [model, spaceAfter, mapWidth],
);
const openings = useMemo(() => {
@@ -594,9 +611,20 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta
openNode,
openContinue,
unfold,
- resizeRows: setRowWidth,
+ mapWidth,
+ resizeMap: setMapWidth,
}),
- [selection, openIds, readIds, bigChangeLines, toggleSession, openNode, openContinue, unfold],
+ [
+ selection,
+ openIds,
+ readIds,
+ bigChangeLines,
+ toggleSession,
+ openNode,
+ openContinue,
+ unfold,
+ mapWidth,
+ ],
);
const nodes = useMemo<MapFlowNode[]>(() => {
diff --git a/packages/template/src/RowEdge.tsx b/packages/template/src/RowEdge.tsx
index 34f0b7b..226a33b 100644
--- a/packages/template/src/RowEdge.tsx
+++ b/packages/template/src/RowEdge.tsx
@@ -1,28 +1,28 @@
import { useStore } from "@xyflow/react";
import { type PointerEvent, useState } from "react";
-import { clampRowWidth, type GitLayout, ROW_WIDTH } from "./gitLayout.js";
+import { clampMapWidth, MAP_WIDTH } from "./gitLayout.js";
/**
- * 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. The width is the same for every session and stays in this
- * browser.
+ * 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.
*/
-const KEY = "cogit.mapRowWidth";
+const KEY = "cogit.mapWidth";
/** The grab area stays this wide on screen whatever the zoom. */
const GRAB = 12;
-export function loadRowWidth(): number {
+export function loadMapWidth(): number {
try {
const raw = window.localStorage.getItem(KEY);
- return raw === null ? ROW_WIDTH : clampRowWidth(Number(raw));
+ return raw === null ? MAP_WIDTH : clampMapWidth(Number(raw));
} catch {
- return ROW_WIDTH;
+ return MAP_WIDTH;
}
}
-export function saveRowWidth(width: number): void {
+export function saveMapWidth(width: number): void {
try {
window.localStorage.setItem(KEY, String(width));
} catch {
@@ -40,7 +40,19 @@ function capture(event: PointerEvent, on: boolean): void {
}
}
-export function RowEdge({ git, onResize }: { git: GitLayout; onResize: (width: number) => 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;
+}) {
// 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);
@@ -50,17 +62,17 @@ export function RowEdge({ git, onResize }: { git: GitLayout; onResize: (width: n
className={`row-edge nodrag nopan${start ? " is-dragging" : ""}`}
role="separator"
aria-orientation="vertical"
- aria-label="Resize the message rows"
+ aria-label="Resize the map's rows"
title="Drag to make the rows wider or narrower · double-click to reset"
- style={{ left: git.width - grab / 2, width: grab, height: git.height }}
+ style={{ left: left - grab / 2, width: grab, height }}
onPointerDown={(event: PointerEvent) => {
event.stopPropagation();
capture(event, true);
- setStart({ x: event.clientX, width: git.rowWidth });
+ setStart({ x: event.clientX, width });
}}
onPointerMove={(event: PointerEvent) => {
if (!start) return;
- onResize(clampRowWidth(start.width + (event.clientX - start.x) / zoom));
+ onResize(clampMapWidth(start.width + (event.clientX - start.x) / zoom));
}}
onPointerUp={(event: PointerEvent) => {
if (!start) return;
@@ -69,7 +81,7 @@ export function RowEdge({ git, onResize }: { git: GitLayout; onResize: (width: n
}}
onDoubleClick={(event) => {
event.stopPropagation();
- onResize(ROW_WIDTH);
+ onResize(MAP_WIDTH);
}}
/>
);
diff --git a/packages/template/src/gitLayout.ts b/packages/template/src/gitLayout.ts
index 854da54..e5e95ca 100644
--- a/packages/template/src/gitLayout.ts
+++ b/packages/template/src/gitLayout.ts
@@ -64,14 +64,28 @@ const ROW_GAP = 8;
*/
export const TITLE_MIN_WIDTH = 180;
-/** 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)));
+/**
+ * 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 many lane colours the page defines (`--l0` … `--l5`). */
diff --git a/packages/template/src/sessionLayout.ts b/packages/template/src/sessionLayout.ts
index 24caa4f..6024d28 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, ROW_WIDTH } from "./gitLayout.js";
+import { type GitLayout, type GitNode, layoutGitGraph, MAP_WIDTH } from "./gitLayout.js";
import { headOf } from "./graph.js";
/**
@@ -10,17 +10,6 @@ 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;
-
-/**
- * Session rows follow the dragged width of the message rows, keeping the same
- * extra room, so widening one session's messages widens the whole map.
- */
-export function sessionRowWidth(messageRowWidth: number): number {
- return SESSION_ROW_WIDTH + messageRowWidth - ROW_WIDTH;
-}
-
function time(value: string | undefined): number {
if (!value) return Number.NEGATIVE_INFINITY;
const at = Date.parse(value);
@@ -79,8 +68,8 @@ 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 message rows' width; the session rows keep pace with it. */
- messageRowWidth: number = ROW_WIDTH,
+ /** 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]));
@@ -112,7 +101,7 @@ export function layoutSessionGraph(
const git = layoutGitGraph(items, {
fold: false,
- rowWidth: sessionRowWidth(messageRowWidth),
+ rowWidth: mapWidth,
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 4b8ac44..fd7ee52 100644
--- a/packages/template/src/styles.css
+++ b/packages/template/src/styles.css
@@ -2411,14 +2411,11 @@ time {
position: absolute;
}
-.session-rows {
- position: relative;
-}
-
-/* The rows' right edge (RowEdge.tsx): a faint line that lights up to grab. */
+/* The map's 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 4e10e9f..389076d 100644
--- a/packages/template/test/rowEdge.test.ts
+++ b/packages/template/test/rowEdge.test.ts
@@ -4,39 +4,45 @@ import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
- clampRowWidth,
- layoutGitGraph,
- ROW_WIDTH,
- ROW_WIDTH_MAX,
- ROW_WIDTH_MIN,
+ clampMapWidth,
+ MAP_WIDTH,
+ MAP_WIDTH_MAX,
+ MAP_WIDTH_MIN,
+ messageRowWidth,
+ TITLE_MIN_WIDTH,
} from "../src/gitLayout.js";
-import { loadRowWidth, RowEdge, saveRowWidth } from "../src/RowEdge.js";
+import { loadMapWidth, RowEdge, saveMapWidth } from "../src/RowEdge.js";
-const T0 = "2026-10-26T10:00:00.000Z";
-
-describe("dragging the message rows wider", () => {
+describe("dragging the map's right edge", () => {
afterEach(() => vi.unstubAllGlobals());
it("keeps a dragged width in range and reads junk as the default", () => {
- 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);
+ 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("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 },
- );
+ 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);
+ });
+
+ it("puts a full-height grab strip on the map's right edge", () => {
const html = renderToStaticMarkup(
- createElement(ReactFlowProvider, null, createElement(RowEdge, { git, onResize: () => {} })),
+ createElement(
+ ReactFlowProvider,
+ null,
+ createElement(RowEdge, { left: 800, height: 1200, width: 720, onResize: () => {} }),
+ ),
);
expect(html).toContain('role="separator"');
// At zoom 1 the strip is 12px wide, centred on the edge.
- expect(html).toContain(`left:${git.width - 6}px`);
- expect(html).toContain(`height:${git.height}px`);
+ expect(html).toContain("left:794px");
+ expect(html).toContain("height:1200px");
});
it("takes the pointer although React Flow turns it off inside map nodes", () => {
@@ -52,9 +58,9 @@ describe("dragging the message rows wider", () => {
setItem: (key: string, value: string) => store.set(key, value),
},
});
- expect(loadRowWidth()).toBe(ROW_WIDTH);
- saveRowWidth(840);
- expect(loadRowWidth()).toBe(840);
+ expect(loadMapWidth()).toBe(MAP_WIDTH);
+ saveMapWidth(840);
+ expect(loadMapWidth()).toBe(840);
vi.stubGlobal("window", {
localStorage: {
@@ -66,7 +72,7 @@ describe("dragging the message rows wider", () => {
},
},
});
- expect(loadRowWidth()).toBe(ROW_WIDTH);
- expect(() => saveRowWidth(600)).not.toThrow();
+ expect(loadMapWidth()).toBe(MAP_WIDTH);
+ expect(() => saveMapWidth(600)).not.toThrow();
});
});
diff --git a/packages/template/test/sessionLayout.test.ts b/packages/template/test/sessionLayout.test.ts
index ba3b543..6117495 100644
--- a/packages/template/test/sessionLayout.test.ts
+++ b/packages/template/test/sessionLayout.test.ts
@@ -84,10 +84,10 @@ describe("layoutSessionGraph", () => {
]);
});
- it("widens the session rows along with dragged message rows", () => {
+ 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, 820).git.rowWidth).toBe(1020);
+ expect(layoutSessionGraph(model, undefined, 1020).git.rowWidth).toBe(1020);
});
it("runs a child session in the parent's lane", () => {