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(view): lay the map out top to bottom with a wider canvas and full screen
Eren5f9362a7dbdb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 59e5133..c88863e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- `codelineage session write --consume`: deletes the `--file` input once the record is saved and keeps it when the write fails. `gitPolicy=commit` now also ignores `.codelineage/inbox/`.### Changed+- Map: inside a session the nodes now read top to bottom, as an indented outline (phases in order along a left spine, their steps, decisions and questions indented below), so the map grows downwards instead of sideways.+- Map: the graph now spans the full window width and nearly its full height (the header and status card stay at a readable width), and a "Full screen" button expands it over the whole window, entering browser full screen when allowed; Esc or the button closes it.- `commander`, `zod` and `@inquirer/prompts` moved to `devDependencies`: they are bundled into `dist/cli.js`, so installing the package pulls in no runtime dependencies.### Fixeddiff --git a/packages/template/src/App.tsx b/packages/template/src/App.tsxindex b1015b1..a95bb59 100644--- a/packages/template/src/App.tsx+++ b/packages/template/src/App.tsx@@ -52,20 +52,22 @@ export function App({ model }: { model: LineageViewModel }) {return (<main>- <header className="project">- <div>- <h1>{model.project.name}</h1>- <p className="muted">{model.project.path}</p>- </div>- <div className="meta">- <span>- {model.epochs.length} epochs · {sessionCount} sessions- </span>- <span className="muted">generated {formatTime(model.project.generatedAt)}</span>- </div>- </header>+ <div className="page-head">+ <header className="project">+ <div>+ <h1>{model.project.name}</h1>+ <p className="muted">{model.project.path}</p>+ </div>+ <div className="meta">+ <span>+ {model.epochs.length} epochs · {sessionCount} sessions+ </span>+ <span className="muted">generated {formatTime(model.project.generatedAt)}</span>+ </div>+ </header>- <StatusPanel status={model.status} />+ <StatusPanel status={model.status} />+ </div><Graph model={model} /></main>diff --git a/packages/template/src/Graph.tsx b/packages/template/src/Graph.tsxindex 08059ca..901da57 100644--- a/packages/template/src/Graph.tsx+++ b/packages/template/src/Graph.tsx@@ -24,6 +24,7 @@ import {} from "react";import type { LineageViewModel } from "../../cli/src/view/model.js";import { formatDate, formatTime } from "./format.js";+import { useFullscreen } from "./fullscreen.js";import {defaultExpanded,type EpochFlowNode,@@ -31,6 +32,9 @@ import {type LineageFlowNode,layoutGraph,type SessionFlowNode,+ TREE_LEFT,+ TREE_OUT,+ TREE_TOP,} from "./graph.js";import { Outline, type OutlineTarget } from "./Outline.js";import { DrillDown, type Selection } from "./SidePanel.js";@@ -63,6 +67,35 @@ function GroupToggle({);}+/** Spine handles for the top-to-bottom outline inside a session (see placeSessionNodes). */+function TreeHandles() {+ return (+ <>+ <Handle+ id={TREE_TOP}+ type="target"+ position={Position.Top}+ className="flow-handle tree-handle"+ isConnectable={false}+ />+ <Handle+ id={TREE_LEFT}+ type="target"+ position={Position.Left}+ className="flow-handle"+ isConnectable={false}+ />+ <Handle+ id={TREE_OUT}+ type="source"+ position={Position.Bottom}+ className="flow-handle tree-handle"+ isConnectable={false}+ />+ </>+ );+}+/** Edges need handles; they are invisible because the layout owns the geometry. */function AnchorHandles() {return (@@ -112,7 +145,7 @@ function SessionNode({ id, data }: NodeProps<SessionFlowNode>) {function LineageBox({ data }: NodeProps<LineageFlowNode>) {return (<div className={`lineage-box kind-${data.kind}`}>- <AnchorHandles />+ <TreeHandles /><div className="lineage-head"><span className={`kind kind-${data.kind}`}>{data.kind}</span><strong title={data.title}>{data.title}</strong>@@ -148,6 +181,7 @@ function Flow({ model }: { model: LineageViewModel }) {const [layout, setLayout] = useState<Awaited<ReturnType<typeof layoutGraph>> | null>(null);const [error, setError] = useState<string | null>(null);const [showOutline, setShowOutline] = useState(false);+ const { expanded: fullscreen, toggle: toggleFullscreen } = useFullscreen();const [focusedId, setFocusedId] = useState<string | null>(null);/** Wait for the layout that contains this node, then centre on it. */const pendingFocus = useRef<string | null>(null);@@ -299,28 +333,38 @@ function Flow({ model }: { model: LineageViewModel }) {return (<GraphActions.Provider value={actions}>- <div className="map-toolbar">- <button- type="button"- className="outline-button"- aria-pressed={showOutline}- onClick={toggleOutline}- >- {showOutline ? "Hide outline" : "Show outline"}- </button>- </div>- <div className="graph-wrap">- {showOutline ? (- <Outline- model={model}- activeId={focusedId}- onSelect={selectFromOutline}- onClose={toggleOutline}- />- ) : null}- <div className="graph-canvas">- {content}- <DrillDown model={model} selection={selection} onClose={closePanel} />+ <div className={fullscreen ? "map-shell is-expanded" : "map-shell"}>+ <div className="map-toolbar">+ <button+ type="button"+ className="outline-button"+ aria-pressed={fullscreen}+ onClick={toggleFullscreen}+ >+ {fullscreen ? "Exit full screen" : "Full screen"}+ </button>+ <button+ type="button"+ className="outline-button"+ aria-pressed={showOutline}+ onClick={toggleOutline}+ >+ {showOutline ? "Hide outline" : "Show outline"}+ </button>+ </div>+ <div className="graph-wrap">+ {showOutline ? (+ <Outline+ model={model}+ activeId={focusedId}+ onSelect={selectFromOutline}+ onClose={toggleOutline}+ />+ ) : null}+ <div className="graph-canvas">+ {content}+ <DrillDown model={model} selection={selection} onClose={closePanel} />+ </div></div></div></GraphActions.Provider>diff --git a/packages/template/src/fullscreen.ts b/packages/template/src/fullscreen.tsnew file mode 100644index 0000000..8fd3ffd--- /dev/null+++ b/packages/template/src/fullscreen.ts@@ -0,0 +1,38 @@+import { useCallback, useEffect, useState } from "react";++/**+ * Expands the map over the whole window (CSS, always works) and asks the browser+ * for real full screen on top when it allows it. Esc or leaving full screen closes it.+ */+export function useFullscreen() {+ const [expanded, setExpanded] = useState(false);++ const close = useCallback(() => {+ setExpanded(false);+ if (document.fullscreenElement) document.exitFullscreen().catch(() => {});+ }, []);++ const toggle = useCallback(() => {+ if (expanded) return close();+ setExpanded(true);+ document.documentElement.requestFullscreen?.().catch(() => {});+ }, [expanded, close]);++ useEffect(() => {+ if (!expanded) return;+ const onKey = (e: KeyboardEvent) => {+ if (e.key === "Escape") close();+ };+ const onChange = () => {+ if (!document.fullscreenElement) setExpanded(false);+ };+ document.addEventListener("keydown", onKey);+ document.addEventListener("fullscreenchange", onChange);+ return () => {+ document.removeEventListener("keydown", onKey);+ document.removeEventListener("fullscreenchange", onChange);+ };+ }, [expanded, close]);++ return { expanded, toggle };+}diff --git a/packages/template/src/graph.ts b/packages/template/src/graph.tsindex c61205d..0cbb1d2 100644--- a/packages/template/src/graph.ts+++ b/packages/template/src/graph.ts@@ -23,6 +23,15 @@ const GROUP_HEADER = 44;const ROOT_PADDING = 48;+/** Inside a session nodes read top to bottom: phases in order, their items indented below. */+const INDENT = 32;+const ROW_GAP = 16;++/** Handle ids on lineage cards: the spine leaves at the bottom left, enters at the top left or the left side. */+export const TREE_OUT = "tree-out";+export const TREE_TOP = "tree-top";+export const TREE_LEFT = "tree-left";+export type EpochData = {title: string;count: number;@@ -143,23 +152,59 @@ function chainEdges(ids: string[]): ElkExtendedEdge[] {return edges;}-function collectNodeBoxes(- nodes: ViewNode[],- parent: string | null,- sessionGroup: string,- out: ElkNode[],- edges: ElkExtendedEdge[],- meta: Map<string, string | null>,-): void {- for (const node of nodes) {- const id = nodeId(sessionGroup, node.id);- out.push({ id, width: NODE_WIDTH, height: NODE_HEIGHT });- meta.set(id, sessionGroup);- if (parent !== null) {- edges.push({ id: `edge:${parent}->${id}`, sources: [parent], targets: [id] });+interface Placement {+ boxes: Map<string, Sized>;+ edges: FlowEdge[];+ width: number;+ height: number;+}++function treeEdge(source: string, target: string, targetHandle: string): FlowEdge {+ return {+ id: `edge:${source}->${target}`,+ source,+ target,+ sourceHandle: TREE_OUT,+ targetHandle,+ type: "smoothstep",+ };+}++/**+ * Places a session's nodes as an indented, top-to-bottom outline: one row per node+ * in recorded order. Phases are chained along the left spine and each item hangs+ * off its parent's spine, so the map grows downwards, never sideways.+ */+export function placeSessionNodes(nodes: ViewNode[], sessionGroup: string): Placement {+ const boxes = new Map<string, Sized>();+ const edges: FlowEdge[] = [];+ let row = 0;+ let maxDepth = 0;+ const visit = (list: ViewNode[], parent: string | null, depth: number): void => {+ let previous: string | null = null;+ for (const node of list) {+ const id = nodeId(sessionGroup, node.id);+ boxes.set(id, {+ x: GROUP_PADDING + depth * INDENT,+ y: GROUP_HEADER + 8 + row * (NODE_HEIGHT + ROW_GAP),+ width: NODE_WIDTH,+ height: NODE_HEIGHT,+ });+ row += 1;+ maxDepth = Math.max(maxDepth, depth);+ if (parent !== null) edges.push(treeEdge(parent, id, TREE_LEFT));+ else if (previous !== null) edges.push(treeEdge(previous, id, TREE_TOP));+ previous = id;+ visit(node.children, id, depth + 1);}- collectNodeBoxes(node.children, id, sessionGroup, out, edges, meta);- }+ };+ visit(nodes, null, 0);+ return {+ boxes,+ edges,+ width: GROUP_PADDING * 2 + maxDepth * INDENT + NODE_WIDTH,+ height: GROUP_HEADER + 8 + row * (NODE_HEIGHT + ROW_GAP) - ROW_GAP + GROUP_PADDING,+ };}function buildSession(@@ -167,28 +212,32 @@ function buildSession(expanded: ReadonlySet<string>,parentId: string,meta: Map<string, string | null>,+ placements: Map<string, Placement>,): ElkNode {const id = sessionId(session.sessionId);meta.set(id, parentId);const showChildren = expanded.has(id) && session.nodes.length > 0;if (!showChildren) return { id, width: GROUP_WIDTH, height: GROUP_HEIGHT };- const children: ElkNode[] = [];- const edges: ElkExtendedEdge[] = [];- collectNodeBoxes(session.nodes, null, id, children, edges, meta);- return { id, children, edges, layoutOptions: groupOptions() };+ // ELK sizes the session box; its contents are placed by hand.+ const placement = placeSessionNodes(session.nodes, id);+ placements.set(id, placement);+ return { id, width: Math.max(GROUP_WIDTH, placement.width), height: placement.height };}function buildEpoch(group: Group,expanded: ReadonlySet<string>,meta: Map<string, string | null>,+ placements: Map<string, Placement>,): ElkNode {meta.set(group.id, null);const showChildren = expanded.has(group.id) && group.sessions.length > 0;if (!showChildren) return { id: group.id, width: GROUP_WIDTH, height: GROUP_HEIGHT };- const children = group.sessions.map((session) => buildSession(session, expanded, group.id, meta));+ const children = group.sessions.map((session) =>+ buildSession(session, expanded, group.id, meta, placements),+ );const edges = chainEdges(children.map((child) => child.id));return { id: group.id, children, edges, layoutOptions: groupOptions() };}@@ -235,7 +284,8 @@ export async function layoutGraph(}const parents = new Map<string, string | null>();- const rootChildren = groups.map((group) => buildEpoch(group, expanded, parents));+ const placements = new Map<string, Placement>();+ const rootChildren = groups.map((group) => buildEpoch(group, expanded, parents, placements));const rootEdges = chainEdges(rootChildren.map((child) => child.id));const graph: ElkNode = {@@ -254,6 +304,9 @@ export async function layoutGraph(const sizes = new Map<string, Sized>();collectSizes(result, sizes);+ for (const placement of placements.values()) {+ for (const [id, box] of placement.boxes) sizes.set(id, box);+ }const seenEdges = new Set<string>();const edges: FlowEdge[] = [];const addEdge = (edge: ElkExtendedEdge): void => {@@ -263,10 +316,8 @@ export async function layoutGraph(for (const edge of rootEdges) addEdge(edge);for (const child of rootChildren) {for (const edge of child.edges ?? []) addEdge(edge);- for (const session of child.children ?? []) {- for (const edge of session.edges ?? []) addEdge(edge);- }}+ for (const placement of placements.values()) edges.push(...placement.edges);const nodes: GraphNode[] = [];const box = (id: string): Sized =>diff --git a/packages/template/src/styles.css b/packages/template/src/styles.cssindex c328fdb..adff39b 100644--- a/packages/template/src/styles.css+++ b/packages/template/src/styles.css@@ -26,9 +26,13 @@ body {}main {+ padding: 32px 24px 64px;+}++/* Text stays readable at 1200px; the map below uses the full window width. */+.page-head {max-width: 1200px;margin: 0 auto;- padding: 32px 24px 64px;}h1,@@ -117,9 +121,33 @@ ul {.map-toolbar {display: flex;justify-content: flex-end;+ gap: 8px;margin-top: 24px;}+body:has(.map-shell.is-expanded) {+ overflow: hidden;+}++.map-shell.is-expanded {+ position: fixed;+ inset: 0;+ z-index: 100;+ display: flex;+ flex-direction: column;+ padding: 12px;+ background: var(--bg);+}++.map-shell.is-expanded .map-toolbar {+ margin-top: 0;+}++.map-shell.is-expanded .graph-wrap {+ flex: 1;+ height: auto;+}+.outline-button {padding: 5px 12px;color: var(--muted);@@ -140,7 +168,7 @@ ul {.graph-wrap {position: relative;display: flex;- height: clamp(480px, 72vh, 900px);+ height: max(480px, calc(100vh - 96px));margin-top: 8px;background: #12151b;border: 1px solid var(--line);@@ -351,6 +379,11 @@ ul {}/* Edges attach here; handles stay invisible because layout decides the shape. */+/* The outline spine runs down the left edge of each card, clear of indented items. */+.react-flow__handle.tree-handle {+ left: 16px;+}+.react-flow__handle.flow-handle {width: 4px;height: 4px;diff --git a/packages/template/test/graph.test.ts b/packages/template/test/graph.test.tsnew file mode 100644index 0000000..7873cd5--- /dev/null+++ b/packages/template/test/graph.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from "vitest";+import type { ViewNode } from "../../cli/src/view/model.js";+import { placeSessionNodes, TREE_LEFT, TREE_TOP } from "../src/graph.js";++function node(id: string, children: ViewNode[] = []): ViewNode {+ return { id, kind: "phase", title: id, children };+}++describe("placeSessionNodes", () => {+ const tree = [node("a", [node("a1"), node("a2", [node("a2x")])]), node("b", [node("b1")])];+ const { boxes, edges, width, height } = placeSessionNodes(tree, "s");+ const box = (id: string) => boxes.get(`node:s:${id}`);++ it("puts every node on its own row in recorded order", () => {+ const order = ["a", "a1", "a2", "a2x", "b", "b1"].map((id) => box(id)?.y ?? -1);+ expect(order).toEqual([...order].sort((x, y) => x - y));+ expect(new Set(order).size).toBe(order.length);+ });++ it("indents children under their parent and keeps phases in one column", () => {+ expect(box("a")?.x).toBe(box("b")?.x);+ expect(box("a1")?.x).toBeGreaterThan(box("a")?.x ?? 0);+ expect(box("a2x")?.x).toBeGreaterThan(box("a2")?.x ?? 0);+ expect(width).toBeGreaterThanOrEqual((box("a2x")?.x ?? 0) + (box("a2x")?.width ?? 0));+ expect(height).toBeGreaterThan((box("b1")?.y ?? 0) + (box("b1")?.height ?? 0));+ });++ it("chains phases along the spine and hangs items off their parent", () => {+ const link = (from: string, to: string) =>+ edges.find((e) => e.source === `node:s:${from}` && e.target === `node:s:${to}`);+ expect(link("a", "b")?.targetHandle).toBe(TREE_TOP);+ expect(link("a", "a1")?.targetHandle).toBe(TREE_LEFT);+ expect(link("a2", "a2x")?.targetHandle).toBe(TREE_LEFT);+ expect(link("a1", "a2")).toBeUndefined();+ expect(edges).toHaveLength(5);+ });+});