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): show a new session before its first record and close on the end state
Eren8994f68456ec
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bc3b8f9..9d8625b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).## [Unreleased]+### Changed+- The session-end pass writes each thread's outcome, what is still open and where the session left off as things stood at the end: a problem a later message fixed no longer shows as open.+### Fixed+- A new session shows on the map from its first message. Before, it appeared only once its first record was written, a few turns in.## [0.21.0] - 2026-10-29### Addeddiff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.tsindex 853f7c0..756b8b5 100644--- a/packages/cli/src/commands/build.ts+++ b/packages/cli/src/commands/build.ts@@ -1,4 +1,5 @@-import { resolve } from "node:path";+import { readdir, stat } from "node:fs/promises";+import { dirname, resolve } from "node:path";import { type ChatTurn, defaultAgent } from "../agents/index.js";import {type CommitChange,@@ -17,7 +18,8 @@ import {upgradeSessionIds,} from "../messages.js";import { redactDeep } from "../redact.js";-import type { Session } from "../schema/session.js";+import { Slug } from "../schema/common.js";+import { SESSION_SCHEMA, type Session } from "../schema/session.js";import { readProjectChanges } from "../store/changes.js";import {appendConversationHashes,@@ -84,6 +86,49 @@ function toViewTurn(turn: ChatTurn): ViewChatTurn {};}+/**+ * Sessions the hooks have seen in this project that have no record yet: the+ * first records come only after a few turns, and until then the map would not+ * show the session at all. Each gets an empty record for this build only (never+ * written), so its messages appear as unsummarized rows from the first one.+ */+async function unrecordedSessions(+ root: string,+ sessions: Session[],+ transcripts: ReadonlyMap<string, string>,+): Promise<Session[]> {+ const dir = dirname(projectPaths(root).state("x"));+ let names: string[];+ try {+ names = await readdir(dir);+ } catch {+ return [];+ }+ const known = new Set(sessions.map((session) => session.sessionId));+ const found: Session[] = [];+ for (const name of names) {+ if (!name.endsWith(".json")) continue;+ const id = name.slice(0, -".json".length);+ if (known.has(id) || !transcripts.has(id) || !Slug.safeParse(id).success) continue;+ // Gone since the listing (the session just ended and was cleaned up): skip it.+ const info = await stat(resolve(dir, name)).catch(() => undefined);+ if (!info) continue;+ const startedAt = (info.birthtimeMs > 0 ? info.birthtime : info.mtime).toISOString();+ found.push({+ schema: SESSION_SCHEMA,+ sessionId: id,+ agent: "claude-code",+ title: "",+ epoch: null,+ startedAt,+ updatedAt: info.mtime.toISOString(),+ status: { goal: "", done: [], pending: [], next: "" },+ nodes: [],+ });+ }+ return found;+}+/*** Reads each session's conversation, preferring the project's own store and* reading the transcript only for turns it does not hold yet. New turns are@@ -275,8 +320,9 @@ export async function buildProject(opts: BuildOptions): Promise<LineageViewModelconst model = await withLock(paths.lock("build"),async () => {- const sessions = await loadAllSessions(root, io.warn);+ const recorded = await loadAllSessions(root, io.warn);const transcripts = await defaultAgent().collectTranscripts(io.env);+ const sessions = [...recorded, ...(await unrecordedSessions(root, recorded, transcripts))];const views = await readTranscriptViews(sessions, transcripts, root, io);// The `Thought:` trailers git holds (Story 9.4) attach commits to the// message they carry out, so the map, the file history and `blame` agreediff --git a/packages/cli/src/commands/close.ts b/packages/cli/src/commands/close.tsindex d8bf207..2baf353 100644--- a/packages/cli/src/commands/close.ts+++ b/packages/cli/src/commands/close.ts@@ -171,6 +171,7 @@ export function closePrompt("- For each thread give `from`: the message whose outcome it starts from. Usually the message just before the thread's first message; for a detour the message it interrupts (the same); for a new task after a finished one, the last message of the finished thread; null only if the first message would work as the first message of a brand-new chat.","","Then write a branch summary for every thread (asked: what the user wanted; outcome: what it meant and what came of it; open: what is still open, or empty), and leftOff: one line saying where the session left off, so a later session can decide whether to continue it.",+ "Outcome, open and leftOff describe the state at the end: read each thread to its last message, and the whole session to its last messages. A problem or task a later message fixed, finished or dropped is done, not open; never report a mid-session state as where things stand.",`Write text in ${writing}; JSON keys stay English. Never invent what is not in the record. Never write secrets, credentials or personal data.`,"",...candidatePart(opts.candidates),diff --git a/packages/cli/test/build.test.ts b/packages/cli/test/build.test.tsindex 5d80283..2261033 100644--- a/packages/cli/test/build.test.ts+++ b/packages/cli/test/build.test.ts@@ -1,7 +1,7 @@import { execFile } from "node:child_process";import { existsSync } from "node:fs";import { appendFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";-import { join } from "node:path";+import { dirname, join } from "node:path";import { promisify } from "node:util";import { gzipSync } from "node:zlib";import { beforeEach, describe, expect, it } from "vitest";@@ -657,6 +657,25 @@ describe("cogit build", () => {expect(await readFile(paths().session("s1"), "utf8")).not.toContain("Fix the card");});+ it("shows a session the hooks saw before its first record, without writing one", async () => {+ const folder = join(dir, "claude", "projects", "-proj");+ await mkdir(folder, { recursive: true });+ const line = { type: "user", timestamp: T0, message: { content: "Start the work" } };+ await writeFile(join(folder, "s3.jsonl"), JSON.stringify(line));+ await mkdir(dirname(paths().state("s3")), { recursive: true });+ await writeFile(paths().state("s3"), "{}");+ // No transcript: nothing to show. Not a session: the read state.+ await writeFile(paths().state("gone"), "{}");+ await writeFile(paths().readState, "[]");++ const model = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });+ expect(model.unassigned.map((s) => s.sessionId)).toEqual(["s3"]);+ expect(model.unassigned[0]?.messages).toEqual([+ expect.objectContaining({ title: "Start the work", unsummarized: true }),+ ]);+ await expect(readFile(paths().session("s3"), "utf8")).rejects.toThrow();+ });+it("reads commit subjects from git for the map and greys a hash git no longer has", async () => {const git = (...args: string[]) => run("git", ["-C", root, ...args]);await git("init", "-q");