Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.
JavaScript ai-codingclaudeclaude-codeclaude-code-pluginclicoding-agentsdeveloper-toolsgitllmtypescript
fix(map): keep Unfold all usable on maps with thousands of sessions
Eren257ca856e0a4
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9664c71..5f69b8c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- `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`.+- A map with thousands of sessions no longer freezes on "Unfold all" and "Fold all": only the open sessions near the screen are drawn, and the session list no longer does quadratic work (10,000 sessions: 11 s down to 2 s).## [1.0.0] - 2026-11-04### Changeddiff --git a/packages/template/src/Graph.tsx b/packages/template/src/Graph.tsxindex aaa75d2..be251d1 100644--- a/packages/template/src/Graph.tsx+++ b/packages/template/src/Graph.tsx@@ -5,7 +5,9 @@ import {type NodeTypes,ReactFlow,ReactFlowProvider,+ type ReactFlowState,useReactFlow,+ useStore,} from "@xyflow/react";import "@xyflow/react/dist/style.css";import {@@ -25,7 +27,7 @@ import { type FilesFocus, type FilesTarget, FilesView } from "./FilesView.js";import { useFullscreen } from "./fullscreen.js";import { GitGraph } from "./GitGraph.js";import { type GitLayout, layoutGitGraph, ROW_WIDTH } from "./gitLayout.js";-import { centreViewport, headOf, type MapPoint } from "./graph.js";+import { centreViewport, headOf, inBand, type MapPoint, visibleBand } from "./graph.js";import type { MapSearchState } from "./MapSearch.js";import { Outline, type OutlineTarget } from "./Outline.js";import { filterOf, type PersonFilter, peopleOf, valueOf } from "./people.js";@@ -158,29 +160,52 @@ function ProjectBox({ data }: NodeProps<ProjectFlowNode>) {onOpenCard={openSessionCard}onContinue={openContinue}/>- {data.openings.map((opening) => {- const active = data.activeHit;- return (- <div- key={opening.session.sessionId}- className="session-open"- style={{ top: opening.top, left: opening.left }}- >- <SessionMessages- session={opening.session}- git={opening.git}- highlights={data.highlights.get(opening.session.sessionId)}- activeHitId={- active?.sessionId === opening.session.sessionId ? active.messageId : null- }- />- </div>- );- })}+ <OpenSessions+ openings={data.openings}+ highlights={data.highlights}+ activeHit={data.activeHit}+ /></div>);}+/** The viewport's band as a string, so the store re-renders only when it moves a step. */+function bandKey(state: ReactFlowState): string {+ const band = visibleBand(state.transform, state.height);+ return band === null ? "all" : band.join(":");+}++/**+ * The open sessions' messages, only those near the viewport. Its own component,+ * so a pan re-renders these rows and never the session list above them.+ */+function OpenSessions({+ openings,+ highlights,+ activeHit,+}: Pick<ProjectData, "openings" | "highlights" | "activeHit">) {+ const key = useStore(bandKey);+ const band = key === "all" ? null : (key.split(":").map(Number) as [number, number]);+ return openings+ .filter((opening) => inBand(opening.top, opening.git.height, band))+ .map((opening) => (+ <div+ key={opening.session.sessionId}+ className="session-open"+ style={{ top: opening.top, left: opening.left }}+ >+ <SessionMessages+ session={opening.session}+ git={opening.git}+ highlights={highlights.get(opening.session.sessionId)}+ activeHitId={+ activeHit?.sessionId === opening.session.sessionId ? activeHit.messageId : null+ }+ />+ </div>+ ));+}+const nodeTypes: NodeTypes = {project: ProjectBox,};@@ -399,11 +424,16 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta/** The open drill-down's message, if any. */const target = selection?.type === "node" ? selection : null;+ const sessionsById = useMemo(+ () => new Map(model.sessions.map((session) => [session.sessionId, session])),+ [model],+ );+/** Message graph of every open session. */const messageGits = useMemo(() => {const out = new Map<string, GitLayout>();for (const sessionId of openIds) {- const session = findSession(model, sessionId);+ const session = sessionsById.get(sessionId);if (!session) continue;let options = {unfolded,@@ -440,7 +470,7 @@ function Flow({ model, search }: { model: LineageViewModel; search: MapSearchSta}return out;}, [- model,+ sessionsById,openIds,unfolded,openAll,diff --git a/packages/template/src/SessionMap.tsx b/packages/template/src/SessionMap.tsxindex c20ea5c..86e369b 100644--- a/packages/template/src/SessionMap.tsx+++ b/packages/template/src/SessionMap.tsx@@ -178,6 +178,13 @@ export function SessionMap({}) {const { git } = graph;const segments = new Map(git.segments.map((segment) => [segment.id, segment]));+ // Grouped once: filtering every row per segment was quadratic, seconds at 10,000 sessions.+ const rowsBySegment = new Map<string, GitRow[]>();+ for (const row of git.rows) {+ const rows = rowsBySegment.get(row.segmentId);+ if (rows === undefined) rowsBySegment.set(row.segmentId, [row]);+ else rows.push(row);+ }const people = peopleOf(model);const open: (row: GitRow) => void = (row) => {@@ -195,7 +202,7 @@ export function SessionMap({>{git.segments.map((segment) => {const start = branchPath(segment, git.laneX);- const rows = git.rows.filter((row) => row.segmentId === segment.id);+ const rows = rowsBySegment.get(segment.id) ?? [];const x = git.laneX[segment.lane] ?? 0;return (<g key={segment.id} stroke={color(segment.colorIndex)} fill="none">diff --git a/packages/template/src/graph.ts b/packages/template/src/graph.tsindex bbe0cb1..34dde80 100644--- a/packages/template/src/graph.ts+++ b/packages/template/src/graph.ts@@ -145,3 +145,31 @@ export function centreViewport(}return { zoom, y, x: canvas.width / 2 - point.x * zoom };}++/** The band moves in steps this tall, so a pan re-renders only when it crosses one. */+export const BAND_STEP = 400;++/**+ * The canvas rows worth drawing: what the viewport shows plus one screen above+ * and below, rounded out to `BAND_STEP`. With 10,000 sessions open, drawing+ * every one froze the page for seconds; only these are drawn, the rest wait+ * off-screen. Null (draw everything) until the canvas has a height.+ */+export function visibleBand(+ transform: readonly [number, number, number],+ height: number,+): [number, number] | null {+ if (height <= 0) return null;+ const [, y, zoom] = transform;+ const top = -y / zoom;+ const span = height / zoom;+ return [+ Math.floor((top - span) / BAND_STEP) * BAND_STEP,+ Math.ceil((top + 2 * span) / BAND_STEP) * BAND_STEP,+ ];+}++/** True when a block from `top`, `height` tall, reaches into the band. */+export function inBand(top: number, height: number, band: [number, number] | null): boolean {+ return band === null || (top + height >= band[0] && top <= band[1]);+}diff --git a/packages/template/test/graph.test.ts b/packages/template/test/graph.test.tsindex 3b3f249..d90ccd1 100644--- a/packages/template/test/graph.test.ts+++ b/packages/template/test/graph.test.ts@@ -1,13 +1,16 @@import { describe, expect, it } from "vitest";import type { LineageViewModel, ViewNode } from "../../cli/src/view/model.js";import {+ BAND_STEP,CENTRE_MARGIN,centreViewport,headOf,+ inBand,messageNeighbors,nodeId,sessionId,toNodeDetail,+ visibleBand,} from "../src/graph.js";const AT = "2026-10-21T10:00:00.000Z";@@ -146,3 +149,26 @@ describe("centreViewport", () => {expect(centreViewport({ x: 100, y: 100 }, canvas, 0.5)).toEqual({ zoom: 0.5, x: 350, y: 150 });});});++describe("the band of open sessions worth drawing", () => {+ it("covers the viewport plus a screen either side, in whole steps", () => {+ // Viewport at canvas y 4000..4800 (zoom 1, 800 tall).+ const band = visibleBand([0, -4000, 1], 800);+ expect(band).toEqual([3200, 5600]);+ expect((band?.[0] ?? 1) % BAND_STEP).toBe(0);+ // Zoomed out to a half, the same screen shows twice the canvas.+ expect(visibleBand([0, -4000, 0.5], 800)).toEqual([6400, 11200]);+ });++ it("draws everything until the canvas has a height", () => {+ expect(visibleBand([0, 0, 1], 0)).toBeNull();+ expect(inBand(99_999, 10, null)).toBe(true);+ });++ it("keeps a block that reaches into the band and drops one wholly outside", () => {+ expect(inBand(3000, 300, [3200, 5600])).toBe(true);+ expect(inBand(5600, 100, [3200, 5600])).toBe(true);+ expect(inBand(2000, 300, [3200, 5600])).toBe(false);+ expect(inBand(5601, 100, [3200, 5600])).toBe(false);+ });+});