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): rebuild after every turn and show messages not summarized yet

Eren6b2aada86134
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03493bb..ef5e73a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+- Live map: the `Stop` hook rebuilds `lineage.html` after every turn, detached like the SessionEnd catch-up and skipped while a build or the session's write holds its lock (a new `build` lock in `build`, `codelineage build --quiet` for the child). The build draws the user messages the record does not hold yet as cards titled with their first words, marked "not summarized yet" and sitting in a "New" topic at the end of the session, so the newest message is on the map before the agent summarizes it; "left off here" marks the newest of them and their drill-down shows the conversation from the transcript.
+
## [0.5.0] - 2026-10-23
### Added
- SessionEnd catch-up: when a session ends with user messages that have no node yet, the `SessionEnd` hook starts a detached `codelineage backfill <session-id> --tail` and returns at once; the child reads those messages with the agent's replies, runs `claude -p --safe-mode --no-session-persistence` with the skill's record rules on `catchUpModel` (default `haiku`) and passes the answer through `session write` (validation, redaction, transcript times, rebuild). The tail is not stored, so a dead child is retried from the transcript next time. With `sessionEndCatchUp` off no tokens are spent, and the map shows "N messages not recorded" on that session.
diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts
index 6288f6c..9f96184 100644
--- a/packages/cli/src/commands/build.ts
+++ b/packages/cli/src/commands/build.ts
@@ -2,12 +2,19 @@ import { CliError, type Io } from "../io.js";
import { redactDeep } from "../redact.js";
import type { Session } from "../schema/session.js";
import { atomicWrite } from "../store/fs.js";
+import { withLock } from "../store/lock.js";
import { projectPaths } from "../store/paths.js";
import { resolveProjectRoot } from "../store/root.js";
import { loadAllSessions, loadConfig, loadProject } from "../store/stores.js";
-import { type ChatTurn, displayTurn, readConversation, readUserMessages } from "../transcript.js";
+import {
+ type ChatTurn,
+ displayTurn,
+ excerpt,
+ readConversation,
+ readUserMessages,
+} from "../transcript.js";
import { buildViewModel, embedViewModel } from "../view/lineage.js";
-import type { LineageViewModel } from "../view/model.js";
+import type { LineageViewModel, ViewPendingMessage } from "../view/model.js";
import { buildPanel } from "../view/panel.js";
import { TEMPLATE_HTML } from "../view/template.js";
import { collectTranscripts } from "../view/transcripts.js";
@@ -21,33 +28,62 @@ export interface BuildOptions {
quiet?: boolean;
}
+/** How many characters of a not-yet-summarized message become its card title. */
+export const PENDING_TITLE_LENGTH = 80;
+
+export interface TranscriptViews {
+ /**
+ * The conversation of every session that shows messages, recorded or not. It
+ * goes into the page only, never into a session file.
+ */
+ chats: Map<string, ChatTurn[]>;
+ /** User messages with no node yet, per session, titled for the map. */
+ pending: Map<string, ViewPendingMessage[]>;
+}
+
/**
- * The conversation of every session that records messages and still has its
- * transcript. It goes into the page only, never into a session file. A transcript
- * that cannot be read leaves that session without a chat, with a warning.
+ * Reads each session's transcript once. A transcript that cannot be read leaves
+ * that session without a chat, with a warning (only when it had one to show).
*/
-async function readChats(
+async function readTranscriptViews(
sessions: Session[],
transcripts: ReadonlyMap<string, string>,
root: string,
io: Io,
-): Promise<Map<string, ChatTurn[]>> {
+): Promise<TranscriptViews> {
const chats = new Map<string, ChatTurn[]>();
+ const pending = new Map<string, ViewPendingMessage[]>();
for (const session of sessions) {
const file = transcripts.get(session.sessionId);
- if (!file || !session.nodes.some((node) => node.kind === "message")) continue;
+ if (!file) continue;
+ const recordsMessages = session.nodes.some((node) => node.kind === "message");
+ let turns: ChatTurn[];
try {
- const roots = [session.worktree?.path, root].filter((r): r is string => Boolean(r));
- const turns = await readConversation(file);
- chats.set(
+ turns = await readConversation(file);
+ } catch (err) {
+ if (recordsMessages)
+ io.warn(
+ `could not read the conversation of ${session.sessionId}: ${(err as Error).message}`,
+ );
+ continue;
+ }
+ const roots = [session.worktree?.path, root].filter((r): r is string => Boolean(r));
+ const displayed = turns.map((turn) => displayTurn(turn, roots));
+ const recorded = new Set(session.nodes.map((node) => node.id));
+ const missing = displayed.filter((turn) => !recorded.has(turn.id));
+ if (missing.length > 0) {
+ pending.set(
session.sessionId,
- turns.map((turn) => displayTurn(turn, roots)),
+ missing.map((turn) => ({
+ id: turn.id,
+ at: turn.at,
+ title: excerpt(turn.text, PENDING_TITLE_LENGTH) || "(blank message)",
+ })),
);
- } catch (err) {
- io.warn(`could not read the conversation of ${session.sessionId}: ${(err as Error).message}`);
}
+ if (recordsMessages || missing.length > 0) chats.set(session.sessionId, displayed);
}
- return chats;
+ return { chats, pending };
}
/**
@@ -91,34 +127,53 @@ export async function buildProject(opts: BuildOptions): Promise<LineageViewModel
for (const warning of project.warnings) io.warn(warning);
const paths = projectPaths(root);
- const sessions = await loadAllSessions(root, io.warn);
- const transcripts = await collectTranscripts(io.env);
- const config = await loadConfig(io.env);
- const model = buildViewModel({
- project: project.data,
- sessions,
- path: root,
- generatedAt: io.now(),
- transcripts: new Set(transcripts.keys()),
- chats: await readChats(sessions, transcripts, root, io),
- // With the catch-up on, the hook records the tail at session end, so the
- // count would only be a stale warning about work already scheduled.
- unrecorded: config.sessionEndCatchUp ? undefined : await countUnrecorded(sessions, transcripts),
- });
- // The skill already avoids secrets; this is the safety net before rendering.
- const redacted = redactDeep(model);
- if (redacted.count > 0) io.warn(`redacted ${redacted.count} secret-looking value(s) in the map`);
+ // The Stop hook skips a turn while this lock is held, and a second build waits
+ // for the first instead of interleaving reads and writes of the same files.
+ const model = await withLock(
+ paths.lock("build"),
+ async () => {
+ const sessions = await loadAllSessions(root, io.warn);
+ const transcripts = await collectTranscripts(io.env);
+ const config = await loadConfig(io.env);
+ const views = await readTranscriptViews(sessions, transcripts, root, io);
+ const built = buildViewModel({
+ project: project.data,
+ sessions,
+ path: root,
+ generatedAt: io.now(),
+ transcripts: new Set(transcripts.keys()),
+ chats: views.chats,
+ pending: views.pending,
+ // With the catch-up on, the hook records the tail at session end, so the
+ // count would only be a stale warning about work already scheduled.
+ unrecorded: config.sessionEndCatchUp
+ ? undefined
+ : await countUnrecorded(sessions, transcripts),
+ });
+ // The skill already avoids secrets; this is the safety net before rendering.
+ const redacted = redactDeep(built);
+ if (redacted.count > 0)
+ io.warn(`redacted ${redacted.count} secret-looking value(s) in the map`);
- const template = opts.templateHtml ?? TEMPLATE_HTML;
- await atomicWrite(paths.html, embedViewModel(template, redacted.value));
- if (!opts.quiet) io.out(`Wrote ${paths.html}`);
+ const template = opts.templateHtml ?? TEMPLATE_HTML;
+ await atomicWrite(paths.html, embedViewModel(template, redacted.value));
+ if (!opts.quiet) io.out(`Wrote ${paths.html}`);
+ return redacted.value;
+ },
+ { timeoutMs: 30_000 },
+ );
// The panel is derived state: a read-only home or a broken registry warning
// must never turn a successful map build into a failure.
try {
- await buildPanel({ env: io.env, io, templateHtml: template, quietPath: root });
+ await buildPanel({
+ env: io.env,
+ io,
+ templateHtml: opts.templateHtml ?? TEMPLATE_HTML,
+ quietPath: root,
+ });
} catch (err) {
io.warn(`could not build panel.html: ${(err as Error).message}`);
}
- return redacted.value;
+ return model;
}
diff --git a/packages/cli/src/hooks/stop.ts b/packages/cli/src/hooks/stop.ts
index c2f3731..794fd61 100644
--- a/packages/cli/src/hooks/stop.ts
+++ b/packages/cli/src/hooks/stop.ts
@@ -1,5 +1,7 @@
import type { HookState } from "../schema/state.js";
import { STATE_SCHEMA } from "../schema/state.js";
+import { isLockHeld } from "../store/lock.js";
+import { projectPaths } from "../store/paths.js";
import { loadConfig, loadSession, updateState } from "../store/stores.js";
import type { HookContext, HookOutput } from "./run.js";
@@ -36,14 +38,23 @@ export function countTurn(
};
}
+/** True while a build or this session's write is running; the next turn rebuilds. */
+async function mapBusy(root: string, sessionId: string): Promise<boolean> {
+ const paths = projectPaths(root);
+ if (await isLockHeld(paths.lock("build"))) return true;
+ return isLockHeld(paths.lock(`session-${sessionId}`));
+}
+
/**
- * Stop hook: every `updateEveryTurns` completed turns, asks the agent to run the
+ * Stop hook: rebuilds the map after every turn, detached so the hook returns at
+ * once, and every `updateEveryTurns` completed turns asks the agent to run the
* skill through `additionalContext` ("Stop hook feedback", not an error). Turns
* that a stop hook itself continued are not counted and never asked again.
*/
export async function onStop(ctx: HookContext): Promise<HookOutput | undefined> {
if (ctx.input.stop_hook_active) return undefined;
const { root, sessionId } = ctx;
+ if (!(await mapBusy(root, sessionId))) ctx.spawnDetached(["build", root, "--quiet"]);
const config = await loadConfig(ctx.env);
const record = await loadSession(root, sessionId);
const recordUpdatedAt = record.found && record.ok ? record.data.updatedAt : null;
diff --git a/packages/cli/src/program.ts b/packages/cli/src/program.ts
index 5dff0da..46c2bcf 100644
--- a/packages/cli/src/program.ts
+++ b/packages/cli/src/program.ts
@@ -76,9 +76,10 @@ export function createProgram(makeIo: IoFactory = processIo, deps: ProgramDeps =
.command("build")
.description("regenerate .codelineage/lineage.html")
.argument("[dir]", "project directory", ".")
+ .option("--quiet", "write the map without printing a success line")
.action(
- run(async (dir: string) => {
- await buildProject({ dir, io: makeIo(false) });
+ run(async (dir: string, opts: { quiet?: boolean }) => {
+ await buildProject({ dir, io: makeIo(false), quiet: opts.quiet === true });
}),
);
diff --git a/packages/cli/src/store/lock.ts b/packages/cli/src/store/lock.ts
index 31a4416..9b3092c 100644
--- a/packages/cli/src/store/lock.ts
+++ b/packages/cli/src/store/lock.ts
@@ -57,6 +57,17 @@ async function acquire(lockPath: string, opts: LockOptions): Promise<void> {
}
}
+/**
+ * Whether a lock is held right now, without taking it: the directory exists and
+ * its owner is alive (or it was touched within `staleMs`). Used by hooks that
+ * would otherwise queue work behind a lock they cannot wait for.
+ */
+export async function isLockHeld(lockPath: string, staleMs = 60_000): Promise<boolean> {
+ const info = await stat(lockPath).catch(() => undefined);
+ if (info === undefined) return false;
+ return !(await isStale(lockPath, staleMs));
+}
+
/** Runs `fn` while holding a directory lock (mkdir is atomic on every platform). */
export async function withLock<T>(
lockPath: string,
diff --git a/packages/cli/src/view/lineage.ts b/packages/cli/src/view/lineage.ts
index 0ae8b70..9da98a2 100644
--- a/packages/cli/src/view/lineage.ts
+++ b/packages/cli/src/view/lineage.ts
@@ -9,6 +9,7 @@ import {
type ViewChatTurn,
type ViewEpoch,
type ViewNode,
+ type ViewPendingMessage,
type ViewSession,
} from "./model.js";
@@ -150,11 +151,42 @@ export function statusCard(sessions: Session[], now: string): StatusCard {
};
}
+/** Title of the last group of a session: messages the record does not hold yet. */
+export const PENDING_GROUP_TITLE = "New";
+
+/**
+ * The messages the record does not hold yet, as cards under one "New" group at
+ * the end of the session, so the newest message is on the map before the agent
+ * summarizes it. The group id never collides with a recorded node's.
+ */
+function pendingGroup(session: Session, pending: ViewPendingMessage[] | undefined): ViewNode[] {
+ if (!pending?.length) return [];
+ const used = new Set(session.nodes.map((node) => node.id));
+ let id = "pending";
+ for (let n = 2; used.has(id); n += 1) id = `pending-${n}`;
+ return [
+ {
+ id,
+ kind: "phase",
+ title: PENDING_GROUP_TITLE,
+ children: pending.map((message) => ({
+ id: message.id,
+ kind: "message" as const,
+ title: message.title,
+ at: message.at,
+ unsummarized: true as const,
+ children: [],
+ })),
+ },
+ ];
+}
+
function toViewSession(
session: Session,
transcripts?: ReadonlySet<string>,
chat?: ViewChatTurn[],
unrecorded?: number,
+ pending?: ViewPendingMessage[],
): ViewSession {
return {
sessionId: session.sessionId,
@@ -164,7 +196,7 @@ function toViewSession(
startedAt: session.startedAt,
updatedAt: session.updatedAt,
status: session.status,
- nodes: buildNodeTree(session.nodes),
+ nodes: [...buildNodeTree(session.nodes), ...pendingGroup(session, pending)],
// Undefined means the caller did not ask (fixtures, unit tests); then the
// record is shown as resumable rather than pretending the transcript is gone.
transcriptAvailable: transcripts === undefined ? true : transcripts.has(session.sessionId),
@@ -191,6 +223,8 @@ export interface ViewModelInput {
chats?: ReadonlyMap<string, ViewChatTurn[]>;
/** Unrecorded message counts, shown while the catch-up is off. */
unrecorded?: ReadonlyMap<string, number> | undefined;
+ /** User messages with no node yet, drawn as not-yet-summarized cards. */
+ pending?: ReadonlyMap<string, ViewPendingMessage[]> | undefined;
}
/**
@@ -210,6 +244,7 @@ export function buildViewModel(input: ViewModelInput): LineageViewModel {
input.transcripts,
input.chats?.get(session.sessionId),
input.unrecorded?.get(session.sessionId),
+ input.pending?.get(session.sessionId),
);
const bucket = session.epoch === null ? undefined : buckets.get(session.epoch);
(bucket ?? unassigned).push(view);
diff --git a/packages/cli/src/view/model.ts b/packages/cli/src/view/model.ts
index f90a421..c1b0459 100644
--- a/packages/cli/src/view/model.ts
+++ b/packages/cli/src/view/model.ts
@@ -36,6 +36,8 @@ export interface ViewNode {
addedAt?: string;
/** When the node was last added or changed; marks where the work left off. */
touchedAt?: string;
+ /** A user message the record does not hold yet: the card is not summarized. */
+ unsummarized?: true;
/** Nested children, already ordered as the graph should draw them. */
children: ViewNode[];
}
@@ -58,6 +60,15 @@ export interface StatusCard extends ViewStatus {
lastActivity: string | null;
}
+/** A user message the record does not hold yet, read from the transcript at build time. */
+export interface ViewPendingMessage {
+ /** Same id the message will get as a node (`m1`, `m2`, …). */
+ id: string;
+ at: string;
+ /** The first words of the message, used as the card title. */
+ title: string;
+}
+
/** One user message and the agent's written answer, read from the transcript at build time. */
export interface ViewChatTurn {
/** Same id as the message node it belongs to (`m1`, `m2`, …). */
diff --git a/packages/cli/test/build.test.ts b/packages/cli/test/build.test.ts
index 757dfce..f31e6ae 100644
--- a/packages/cli/test/build.test.ts
+++ b/packages/cli/test/build.test.ts
@@ -202,6 +202,52 @@ describe("buildViewModel", () => {
expect(model.project).toEqual({ name: "p", path: "/tmp/p", generatedAt: T0 });
});
+ it("puts unrecorded messages in one New group at the end, with a free id", () => {
+ const model = buildViewModel({
+ project: { schema: 1, name: "p", epochs: [] },
+ sessions: [
+ session({ sessionId: "s", nodes: [node("pending", "phase", "A recorded topic")] }),
+ ],
+ path: "/tmp/p",
+ generatedAt: T0,
+ pending: new Map([
+ [
+ "s",
+ [
+ { id: "m2", at: "2026-10-21T10:02:00.000Z", title: "Second message" },
+ { id: "m3", at: "2026-10-21T10:03:00.000Z", title: "Third message" },
+ ],
+ ],
+ ]),
+ });
+ const nodes = model.unassigned[0]?.nodes ?? [];
+ expect(nodes.map((n) => n.title)).toEqual(["A recorded topic", "New"]);
+ // The recorded node already owns the id "pending".
+ expect(nodes[1]).toEqual({
+ id: "pending-2",
+ kind: "phase",
+ title: "New",
+ children: [
+ {
+ id: "m2",
+ kind: "message",
+ title: "Second message",
+ at: "2026-10-21T10:02:00.000Z",
+ unsummarized: true,
+ children: [],
+ },
+ {
+ id: "m3",
+ kind: "message",
+ title: "Third message",
+ at: "2026-10-21T10:03:00.000Z",
+ unsummarized: true,
+ children: [],
+ },
+ ],
+ });
+ });
+
it("has an empty status card without sessions", () => {
const model = buildViewModel({
project: { schema: 1, name: "p", epochs: [] },
@@ -473,17 +519,75 @@ describe("codelineage build", () => {
const model = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });
const [s1, s2] = model.epochs[0]?.sessions ?? [];
- expect(s1?.chat).toEqual([
+ const turn = {
+ id: "m1",
+ at: T0,
+ text: "Fix the card",
+ replies: ["Done, key [REDACTED]"],
+ tools: { commands: 0, files: ["src/a.ts"], other: 0 },
+ };
+ expect(s1?.chat).toEqual([turn]);
+ // s2 records no message, so its unrecorded turn is shown as a pending card
+ // and needs the same conversation for its drill-down.
+ expect(s2?.chat).toEqual([turn]);
+ expect(s2?.nodes.at(-1)).toMatchObject({
+ kind: "phase",
+ title: "New",
+ children: [{ id: "m1", kind: "message", title: "Fix the card", unsummarized: true }],
+ });
+ expect(await readFile(paths().session("s1"), "utf8")).not.toContain("Fix the card");
+ });
+
+ it("shows unrecorded messages as pending cards until the skill writes them", async () => {
+ const folder = join(dir, "claude", "projects", "-proj");
+ await mkdir(folder, { recursive: true });
+ const lines = [
+ { type: "user", timestamp: T0, message: { content: "First message" } },
{
- id: "m1",
- at: T0,
- text: "Fix the card",
- replies: ["Done, key [REDACTED]"],
- tools: { commands: 0, files: ["src/a.ts"], other: 0 },
+ type: "user",
+ timestamp: "2026-10-21T10:05:00.000Z",
+ message: {
+ content: "Second message, with the card <system-reminder>noise</system-reminder>",
+ },
},
- ]);
- expect(s2).not.toHaveProperty("chat");
- expect(await readFile(paths().session("s1"), "utf8")).not.toContain("Fix the card");
+ ];
+ await writeFile(join(folder, "s1.jsonl"), lines.map((l) => JSON.stringify(l)).join("\n"));
+ await saveSession(
+ "s1",
+ session({
+ sessionId: "s1",
+ epoch: "e1",
+ nodes: [
+ node("topic", "phase", "Topic"),
+ node("m1", "message", "First", "topic", { at: T0 }),
+ ],
+ }),
+ );
+
+ const before = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });
+ const nodes = before.epochs[0]?.sessions[0]?.nodes ?? [];
+ expect(nodes.map((n) => n.title)).toEqual(["Topic", "New"]);
+ expect(nodes[1]).toMatchObject({
+ children: [
+ {
+ id: "m2",
+ kind: "message",
+ title: "Second message, with the card",
+ at: "2026-10-21T10:05:00.000Z",
+ unsummarized: true,
+ },
+ ],
+ });
+
+ await sessionWrite({ dir: root }, io, async () =>
+ JSON.stringify({
+ sessionId: "s1",
+ nodes: [{ id: "m2", kind: "message", title: "Second message", parent: "topic" }],
+ }),
+ );
+ expect(io.warnings).toEqual([]);
+ const after = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });
+ expect(after.epochs[0]?.sessions[0]?.nodes.map((n) => n.title)).toEqual(["Topic"]);
});
it("counts unrecorded messages only while the catch-up is off", async () => {
diff --git a/packages/cli/test/hooks.test.ts b/packages/cli/test/hooks.test.ts
index f992c84..6e39611 100644
--- a/packages/cli/test/hooks.test.ts
+++ b/packages/cli/test/hooks.test.ts
@@ -1,5 +1,5 @@
import { existsSync } from "node:fs";
-import { mkdir, readFile, writeFile } from "node:fs/promises";
+import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { beforeEach, describe, expect, it } from "vitest";
import { configHintOff, configHintOn, configSet } from "../src/commands/config.js";
@@ -45,8 +45,16 @@ describe("runHook", () => {
let spawned: string[][];
const stop = (extra: Record<string, unknown> = {}, e = env) =>
- runHook("stop", JSON.stringify({ session_id: "s1", cwd: root, ...extra }), e, T0, (l) =>
- debug.push(l),
+ runHook(
+ "stop",
+ JSON.stringify({ session_id: "s1", cwd: root, ...extra }),
+ e,
+ T0,
+ (l) => debug.push(l),
+ {
+ cli: "/plugin/dist/cli.js",
+ spawnDetached: (cli, args) => spawned.push([cli, ...args]),
+ },
);
const sessionStart = (source: string, e = env) =>
@@ -150,6 +158,23 @@ describe("runHook", () => {
expect(await stop()).toBeUndefined();
});
+ it("rebuilds the map after every turn, detached", async () => {
+ await initialized(10);
+ expect(await stop()).toBeUndefined();
+ expect(spawned).toEqual([["/plugin/dist/cli.js", "build", root, "--quiet"]]);
+ });
+
+ it("skips the rebuild while a build or the session write holds the lock", async () => {
+ await initialized(10);
+ const paths = projectPaths(root);
+ await mkdir(paths.lock("build"), { recursive: true });
+ await stop();
+ await rm(paths.lock("build"), { recursive: true });
+ await mkdir(paths.lock("session-s1"), { recursive: true });
+ await stop();
+ expect(spawned).toEqual([]);
+ });
+
it("ignores turns a stop hook continued", async () => {
await initialized(1);
expect(await stop({ stop_hook_active: true })).toBeUndefined();
diff --git a/packages/cli/test/store.test.ts b/packages/cli/test/store.test.ts
index 97266be..0c4b760 100644
--- a/packages/cli/test/store.test.ts
+++ b/packages/cli/test/store.test.ts
@@ -3,7 +3,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { beforeEach, describe, expect, it } from "vitest";
import { atomicWrite, atomicWriteJson, readJson } from "../src/store/fs.js";
-import { LockBusyError, withLock } from "../src/store/lock.js";
+import { isLockHeld, LockBusyError, withLock } from "../src/store/lock.js";
import { globalPaths, projectPaths } from "../src/store/paths.js";
import {
loadConfig,
@@ -131,6 +131,18 @@ describe("withLock", () => {
);
});
+ it("reports a held lock without taking it, and ignores a dead or stale one", async () => {
+ const lock = join(dir, "held.lock");
+ expect(await isLockHeld(lock)).toBe(false);
+ await mkdir(lock);
+ await writeFile(join(lock, "owner"), "1");
+ expect(await isLockHeld(lock)).toBe(true);
+ // The hook may ask and still take the lock afterwards.
+ expect(await isLockHeld(lock)).toBe(true);
+ await writeFile(join(lock, "owner"), "999999999");
+ expect(await isLockHeld(lock)).toBe(false);
+ });
+
it("rethrows unexpected mkdir errors", async () => {
const ro = join(dir, "ro");
await mkdir(ro);
diff --git a/packages/template/src/Graph.tsx b/packages/template/src/Graph.tsx
index 98b0ca7..8486d13 100644
--- a/packages/template/src/Graph.tsx
+++ b/packages/template/src/Graph.tsx
@@ -146,6 +146,7 @@ function LineageBox({ id, data }: NodeProps<LineageFlowNode>) {
<strong title={data.title}>{data.title}</strong>
</div>
{data.isLast ? <span className="left-off">left off here</span> : null}
+ {data.unsummarized ? <span className="unsummarized">not summarized yet</span> : null}
{data.hasChildren && !data.expanded ? (
<p className="lineage-count">{itemsInside(data.count)}</p>
) : data.at && data.kind !== "message" ? (
diff --git a/packages/template/src/graph.ts b/packages/template/src/graph.ts
index 2376cc1..a1efb55 100644
--- a/packages/template/src/graph.ts
+++ b/packages/template/src/graph.ts
@@ -30,8 +30,9 @@ const ROOT_PADDING = 48;
const INDENT = 32;
const ROW_GAP = 16;
const COLUMN_GAP = 24;
-/** The "left off here" badge under the last touched card's title. */
+/** Room for the "left off here" or "not summarized yet" badge under the title. */
const LEFT_OFF_BADGE = 20;
+const PENDING_BADGE = 20;
/** Wide enough that a collapsed session shows a readable title. */
const SESSION_WIDTH = 380;
@@ -71,6 +72,8 @@ export type NodeDetail = {
agentDecisions?: ViewNode["agentDecisions"];
addedAt?: string;
touchedAt?: string;
+ /** A user message the record does not hold yet. */
+ unsummarized?: true;
/** Owning session, so the drill-down panel can show and resume it. */
sessionId: string;
/** The node's id in its session, which for a message is also its chat turn's id. */
@@ -302,7 +305,10 @@ export function placeSessionNodes(
const visit = (node: ViewNode, parent: string | null, depth: number): void => {
const id = nodeId(sessionGroup, node.id);
const open = isOpen(id);
- const height = nodeHeight(node, open) + (lastKeys.has(id) ? LEFT_OFF_BADGE : 0);
+ const height =
+ nodeHeight(node, open) +
+ (lastKeys.has(id) ? LEFT_OFF_BADGE : 0) +
+ (node.unsummarized ? PENDING_BADGE : 0);
boxes.set(id, { x: columnX + depth * INDENT, y, width: NODE_WIDTH, height });
y += height + ROW_GAP;
columnWidth = Math.max(columnWidth, depth * INDENT + NODE_WIDTH);
diff --git a/packages/template/src/styles.css b/packages/template/src/styles.css
index b6cbd6f..92e9c12 100644
--- a/packages/template/src/styles.css
+++ b/packages/template/src/styles.css
@@ -475,6 +475,18 @@ body:has(.map-shell.is-expanded) {
line-height: 14px;
}
+/* A card built from the transcript before the record summarizes it. */
+.lineage-box.kind-message .unsummarized {
+ display: inline-block;
+ margin-top: 4px;
+ padding: 1px 6px;
+ color: var(--muted);
+ border: 1px dashed var(--muted);
+ border-radius: 999px;
+ font-size: 10px;
+ line-height: 14px;
+}
+
.lineage-box p.card-meta {
font-size: 10px;
color: var(--accent);
diff --git a/packages/template/test/graph.test.ts b/packages/template/test/graph.test.ts
index f1e3935..c2d7d9b 100644
--- a/packages/template/test/graph.test.ts
+++ b/packages/template/test/graph.test.ts
@@ -57,6 +57,16 @@ describe("placeSessionNodes", () => {
const marked = placeSessionNodes(tree, "s", undefined, new Set(["node:s:a1"]));
expect(marked.boxes.get("node:s:a1")?.height).toBeGreaterThan(box("a1")?.height ?? 0);
});
+
+ it("makes room for the not-summarized badge, even on the last touched card", () => {
+ const card: ViewNode = { id: "m1", kind: "message", title: "Hi", children: [] };
+ const pending: ViewNode = { ...card, unsummarized: true, at: "2026-10-23T10:00:00.000Z" };
+ const plainHeight = placeSessionNodes([card], "s").boxes.get("node:s:m1")?.height ?? 0;
+ const pendingHeight = placeSessionNodes([pending], "s").boxes.get("node:s:m1")?.height ?? 0;
+ expect(pendingHeight).toBeGreaterThan(plainHeight);
+ const both = placeSessionNodes([pending], "s", undefined, new Set(["node:s:m1"]));
+ expect(both.boxes.get("node:s:m1")?.height).toBeGreaterThan(pendingHeight);
+ });
});
describe("absolutePosition", () => {