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
feat(map): keep the conversation in a project store
Erenab447a52d102
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 43c5262..da351e1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,8 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Added+- The conversation store: `build` appends what the drill-down needs for turns not stored yet to `.codelineage/conversations/<sessionId>.jsonl.gz` (one gzip member per append, redacted with the same secret net as the page), reads it before the transcript, and keeps showing a session's conversation after Claude Code deletes the transcript. `init` writes `.codelineage/.gitignore` with `conversations/` even when `.codelineage/` is committed, an existing project gets the line on its next build, and the README explains where the raw chat lives.+### Fixed- Map: long message titles and branch labels in the git graph wrap onto more lines (the row grows) instead of being cut with an ellipsis; a not-yet-summarized message shows up to 200 characters of its text instead of 80.+- Transcript: `[Request interrupted by user]` and `[Request interrupted by user for tool use]` lines are Claude Code's own notes, not user messages; they no longer become message nodes.## [0.7.0] - 2026-10-23### Addeddiff --git a/README.md b/README.mdnew file mode 100644index 0000000..56c1ae6--- /dev/null+++ b/README.md@@ -0,0 +1,31 @@+# codelineage++The lineage of your AI coding sessions: every user message hangs from the message+it reacts to, and the map draws each session as a git graph you can zoom into.++## Quick start++```bash+npm install -g codelineage+codelineage init # answer the setup questions in the project you work in+codelineage open # open the map in the browser+```++`init` also installs the Claude Code side: the lineage skill updates the record as+you work, the hooks rebuild the map after each turn and at the end of a session.++## Privacy++- The skill records decisions and rationale, never raw chat; session files hold+ titles and summaries only.+- The map's Conversation panel needs the real turns, so `build` reads them from+ Claude Code's local transcript and keeps a copy in+ `.codelineage/conversations/<sessionId>.jsonl.gz`. This store lets the panel keep+ working after Claude Code deletes the transcript.+- That copy never goes into git: `init` writes `.codelineage/.gitignore` with+ `conversations/`, even when you chose to commit `.codelineage/`, and every build+ makes sure the line is there.+- Both the page and the conversation store go through the same redaction pass+ (common key and token patterns) before anything is written.+- Claude Code deletes transcripts after `cleanupPeriodDays` (30 days by default).+ `init` offers to raise it, never silently.diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.tsindex e2b9363..2d38067 100644--- a/packages/cli/src/commands/build.ts+++ b/packages/cli/src/commands/build.ts@@ -1,6 +1,8 @@+import { ensureConversationGitignore } from "../git.js";import { CliError, type Io } from "../io.js";import { redactDeep } from "../redact.js";import type { Session } from "../schema/session.js";+import { appendConversationTurns, readConversationStore } from "../store/conversations.js";import { atomicWrite } from "../store/fs.js";import { withLock } from "../store/lock.js";import { projectPaths } from "../store/paths.js";@@ -14,7 +16,7 @@ import {readUserMessages,} from "../transcript.js";import { buildViewModel, embedViewModel } from "../view/lineage.js";-import type { LineageViewModel, ViewPendingMessage } from "../view/model.js";+import type { LineageViewModel, ViewChatTurn, ViewPendingMessage } from "../view/model.js";import { buildPanel } from "../view/panel.js";import { TEMPLATE_HTML } from "../view/template.js";import { collectTranscripts } from "../view/transcripts.js";@@ -36,14 +38,29 @@ 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[]>;+ chats: Map<string, ViewChatTurn[]>;/** User messages with no node yet, per session, titled for the map. */pending: Map<string, ViewPendingMessage[]>;}+/** Drops the fields only the drill-down needs (uuid, hints) and keeps the contract. */+function toViewTurn(turn: ChatTurn, id = turn.id): ViewChatTurn {+ return {+ id,+ at: turn.at,+ text: turn.text,+ replies: turn.replies,+ tools: turn.tools,+ };+}+/**- * 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).+ * 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+ * appended to the store, so the drill-down survives Claude Code deleting the+ * transcript; a session whose transcript is already gone still shows what was+ * stored. A transcript that cannot be read leaves that session without a new+ * chat, with a warning (only when it had one to show).*/async function readTranscriptViews(sessions: Session[],@@ -51,26 +68,54 @@ async function readTranscriptViews(root: string,io: Io,): Promise<TranscriptViews> {- const chats = new Map<string, ChatTurn[]>();+ const chats = new Map<string, ViewChatTurn[]>();const pending = new Map<string, ViewPendingMessage[]>();for (const session of sessions) {const file = transcripts.get(session.sessionId);- if (!file) continue;const recordsMessages = session.nodes.some((node) => node.kind === "message");- let turns: ChatTurn[];- try {- 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 stored = await readConversationStore(root, session.sessionId);+ const storedByUuid = new Map(stored.map((turn) => [turn.uuid, turn]));+ let turns: ViewChatTurn[];+ if (file) {+ let transcript: ChatTurn[];+ try {+ transcript = await readConversation(file);+ } catch (err) {+ if (recordsMessages)+ io.warn(+ `could not read the conversation of ${session.sessionId}: ${(err as Error).message}`,+ );+ continue;+ }+ const fresh = transcript.filter(+ (turn) => turn.uuid !== undefined && !storedByUuid.has(turn.uuid),+ );+ if (fresh.length > 0) {+ const displayed = fresh.map((turn) => displayTurn(turn, roots));+ try {+ await appendConversationTurns(root, session.sessionId, displayed);+ } catch (err) {+ // Losing the transcript is a real risk, but a failed append must never+ // fail the map: the page still shows this build's conversation.+ io.warn(+ `could not store the conversation of ${session.sessionId}: ${(err as Error).message}`,+ );+ }+ }+ turns = transcript.map((turn) => {+ const kept = turn.uuid === undefined ? undefined : storedByUuid.get(turn.uuid);+ return kept+ ? { id: turn.id, at: kept.at, text: kept.text, replies: kept.replies, tools: kept.tools }+ : toViewTurn(displayTurn(turn, roots));+ });+ } else {+ // No transcript: the store is all that is left. The append-only order is+ // the transcript order, so `m1`, `m2`, … still line up with the records.+ turns = stored.map((turn, index) => toViewTurn({ ...turn, id: `m${index + 1}` }));+ }const recorded = new Set(session.nodes.map((node) => node.id));- const missing = displayed.filter((turn) => !recorded.has(turn.id));+ const missing = turns.filter((turn) => !recorded.has(turn.id));if (missing.length > 0) {pending.set(session.sessionId,@@ -81,7 +126,7 @@ async function readTranscriptViews(})),);}- if (recordsMessages || missing.length > 0) chats.set(session.sessionId, displayed);+ if (recordsMessages || missing.length > 0) chats.set(session.sessionId, turns);}return { chats, pending };}@@ -127,6 +172,13 @@ export async function buildProject(opts: BuildOptions): Promise<LineageViewModelfor (const warning of project.warnings) io.warn(warning);const paths = projectPaths(root);+ // Projects initialized before the conversation store get the privacy line on+ // their next build; an unwritable record must never fail the map.+ try {+ await ensureConversationGitignore(root);+ } catch (err) {+ io.warn(`could not update .codelineage/.gitignore: ${(err as Error).message}`);+ }// 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(diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.tsindex 8ebb49a..09b9d1b 100644--- a/packages/cli/src/commands/init.ts+++ b/packages/cli/src/commands/init.ts@@ -8,7 +8,12 @@ import {SKILL_RULE,setRetention,} from "../claude-settings.js";-import { ensureGitignore, findGitRoot, type GitPolicy } from "../git.js";+import {+ ensureConversationGitignore,+ ensureGitignore,+ findGitRoot,+ type GitPolicy,+} from "../git.js";import { CliError, type Io } from "../io.js";import { readJson } from "../store/fs.js";import { globalPaths, projectPaths } from "../store/paths.js";@@ -166,8 +171,14 @@ export async function init(dir: string, opts: InitOptions, io: Io): Promise<voidawait updateProject(root, (cur) => cur ?? { schema: 1, name, epochs: [] });await mkdir(projectPaths(root).sessions, { recursive: true });+ await bestEffort(io, "could not write .codelineage/.gitignore", () =>+ ensureConversationGitignore(root),+ );await register(io, root, name);+ io.out(+ "Conversations are stored in .codelineage/conversations/ (kept out of git, even with the commit policy).",+ );io.out(`Initialized ${name} in ${projectPaths(root).base}`);io.out("Next: install the Claude Code plugin, then run `codelineage open` after a session.");}diff --git a/packages/cli/src/git.ts b/packages/cli/src/git.tsindex 902bc39..323f82b 100644--- a/packages/cli/src/git.ts+++ b/packages/cli/src/git.ts@@ -44,3 +44,18 @@ export async function ensureGitignore(root: string, policy: GitPolicy): Promise<await atomicWrite(file, `${text}${sep}${block}\n`);return missing;}++/**+ * `.codelineage/.gitignore` keeps the conversation store out of git, even when+ * the user chose to commit `.codelineage/`: the raw chat stays on this machine.+ * Returns true when the line had to be added; a second call changes nothing.+ */+export async function ensureConversationGitignore(root: string): Promise<boolean> {+ const file = join(root, ".codelineage", ".gitignore");+ const text = await readFile(file, "utf8").catch(() => "");+ const present = new Set(text.split(/\r?\n/).map((l) => l.trim()));+ if (present.has("conversations/")) return false;+ const sep = text === "" || text.endsWith("\n") ? "" : "\n";+ await atomicWrite(file, `${text}${sep}conversations/\n`);+ return true;+}diff --git a/packages/cli/src/store/conversations.ts b/packages/cli/src/store/conversations.tsnew file mode 100644index 0000000..dcee04e--- /dev/null+++ b/packages/cli/src/store/conversations.ts@@ -0,0 +1,100 @@+import { appendFile, mkdir, readFile } from "node:fs/promises";+import { dirname } from "node:path";+import { constants, gunzipSync, gzipSync } from "node:zlib";+import { redactDeep } from "../redact.js";+import type { ChatTurn, ToolUse } from "../transcript.js";+import { projectPaths } from "./paths.js";++/**+ * The conversation as the drill-down shows it, kept in the project so it+ * survives Claude Code deleting the transcript. One JSON line per turn, each+ * append one more gzip member: the file is append-only and never rewritten.+ */+export interface StoredTurn {+ /** The transcript's uuid for the user line; the key that makes appends idempotent. */+ uuid: string;+ at: string;+ text: string;+ replies: string[];+ tools: ToolUse;+}++function isStoredTurn(value: unknown): value is StoredTurn {+ if (value === null || typeof value !== "object") return false;+ const turn = value as Partial<StoredTurn>;+ return (+ typeof turn.uuid === "string" &&+ turn.uuid !== "" &&+ typeof turn.at === "string" &&+ typeof turn.text === "string" &&+ Array.isArray(turn.replies) &&+ turn.replies.every((reply) => typeof reply === "string") &&+ turn.tools !== null &&+ typeof turn.tools === "object"+ );+}++/**+ * Every turn stored for the session, in the order they were appended. A missing+ * file is an empty store; a corrupted member ends the read at what parsed, so a+ * damaged tail never hides the turns before it.+ */+export async function readConversationStore(+ root: string,+ sessionId: string,+): Promise<StoredTurn[]> {+ let text: string;+ try {+ // A process killed mid-append leaves a partial last member; `Z_SYNC_FLUSH`+ // still returns every complete record before it instead of an empty store.+ text = gunzipSync(await readFile(projectPaths(root).conversation(sessionId)), {+ finishFlush: constants.Z_SYNC_FLUSH,+ }).toString("utf8");+ } catch {+ return [];+ }+ const turns: StoredTurn[] = [];+ for (const line of text.split("\n")) {+ if (line.trim() === "") continue;+ try {+ const value: unknown = JSON.parse(line);+ if (isStoredTurn(value)) turns.push(value);+ } catch {}+ }+ return turns;+}++/**+ * Appends the turns the store does not hold yet, redacted, and returns how many+ * were written. Turns without a transcript uuid cannot be recognised again, so+ * they are left to the transcript; a build that has a transcript keeps showing+ * them. Never rewrites an existing turn.+ */+export async function appendConversationTurns(+ root: string,+ sessionId: string,+ turns: ChatTurn[],+): Promise<number> {+ const known = new Set((await readConversationStore(root, sessionId)).map((turn) => turn.uuid));+ const fresh: StoredTurn[] = [];+ for (const turn of turns) {+ if (turn.uuid === undefined || known.has(turn.uuid)) continue;+ known.add(turn.uuid);+ fresh.push({+ uuid: turn.uuid,+ at: turn.at,+ text: turn.text,+ replies: turn.replies,+ tools: turn.tools,+ });+ }+ if (fresh.length === 0) return 0;+ // The store outlives the transcript and may be committed by mistake, so it+ // gets the same secret net as the page, not the raw text.+ const { value } = redactDeep(fresh);+ const chunk = `${value.map((turn) => JSON.stringify(turn)).join("\n")}\n`;+ const file = projectPaths(root).conversation(sessionId);+ await mkdir(dirname(file), { recursive: true });+ await appendFile(file, gzipSync(Buffer.from(chunk, "utf8")));+ return fresh.length;+}diff --git a/packages/cli/src/store/paths.ts b/packages/cli/src/store/paths.tsindex 78419ac..8bf8022 100644--- a/packages/cli/src/store/paths.ts+++ b/packages/cli/src/store/paths.ts@@ -10,6 +10,9 @@ export function projectPaths(root: string) {project: join(base, "project.json"),sessions: join(base, "sessions"),session: (id: string) => join(base, "sessions", `${id}.json`),+ /** The conversation store: what the drill-down needs, outliving the transcript. */+ conversations: join(base, "conversations"),+ conversation: (id: string) => join(base, "conversations", `${id}.jsonl.gz`),state: (id: string) => join(base, "state", `${id}.json`),locks: join(base, "locks"),/** Where the skill drops session JSON for `session write --file`. */diff --git a/packages/cli/src/transcript.ts b/packages/cli/src/transcript.tsindex 683b24d..b7c8525 100644--- a/packages/cli/src/transcript.ts+++ b/packages/cli/src/transcript.ts@@ -49,6 +49,8 @@ const NOT_A_MESSAGE =/^\s*<(bash-input|bash-stdout|bash-stderr|local-command-[a-z]+|command-message)>/;const COMMAND = /^\s*<command-name>([^<]*)<\/command-name>/;const COMMAND_ARGS = /<command-args>([\s\S]*?)<\/command-args>/;+/** Claude Code's own note that the user stopped a turn; the user typed nothing. */+const INTERRUPTED = /^\s*\[Request interrupted\b[^\]]*\]\s*$/;/*** The text of a user line when it is a message the user typed, else null. Tool@@ -76,6 +78,7 @@ export function messageText(line: Record<string, unknown>): string | null {return null;}if (NOT_A_MESSAGE.test(text)) return null;+ if (INTERRUPTED.test(text)) return null;const command = COMMAND.exec(text);if (command) {const args = COMMAND_ARGS.exec(text)?.[1]?.trim() ?? "";@@ -96,6 +99,8 @@ export interface ToolUse {/** One user message and what the agent wrote back before the next one. */export interface ChatTurn extends UserMessage {+ /** The transcript's uuid for the user line; the key of the conversation store. */+ uuid?: string;/** The agent's written replies, in order; tool output never appears here. */replies: string[];tools: ToolUse;@@ -219,6 +224,7 @@ export async function readConversation(file: string): Promise<ChatTurn[]> {id: `m${turns.length + 1}`,at: line.timestamp,text,+ ...(uuid === undefined ? {} : { uuid }),replies: [],tools: { commands: 0, files: [], other: 0 },...(!first && pendingResume ? { resumed: true } : {}),diff --git a/packages/cli/test/build.test.ts b/packages/cli/test/build.test.tsindex 604ecd4..1a97642 100644--- a/packages/cli/test/build.test.ts+++ b/packages/cli/test/build.test.ts@@ -1,5 +1,5 @@import { existsSync } from "node:fs";-import { mkdir, readFile, rm, writeFile } from "node:fs/promises";+import { appendFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";import { join } from "node:path";import { beforeEach, describe, expect, it } from "vitest";import { buildProject, countUnrecorded } from "../src/commands/build.js";@@ -8,6 +8,7 @@ import { epochAdd } from "../src/commands/epoch.js";import { init } from "../src/commands/init.js";import { sessionWrite } from "../src/commands/session.js";import type { LineageNode, Session } from "../src/schema/session.js";+import { readConversationStore } from "../src/store/conversations.js";import { projectPaths } from "../src/store/paths.js";import { buildMessages, buildViewModel, embedViewModel, statusCard } from "../src/view/lineage.js";import { DATA_ELEMENT_ID } from "../src/view/model.js";@@ -511,6 +512,118 @@ describe("codelineage build", () => {expect(await readFile(paths().session("s1"), "utf8")).not.toContain("Fix the card");});+ it("keeps the conversation in the project and shows it after the transcript is gone", async () => {+ const folder = join(dir, "claude", "projects", "-proj");+ await mkdir(folder, { recursive: true });+ const userLine = (uuid: string, text: string, at: string) => ({+ type: "user",+ uuid,+ parentUuid: null,+ timestamp: at,+ message: { content: text },+ });+ const reply = (uuid: string, parent: string, text: string) => ({+ type: "assistant",+ uuid,+ parentUuid: parent,+ message: { content: [{ type: "text", text }] },+ });+ const lines = [+ userLine("u1", "First", T0),+ reply("a1", "u1", "Answer one"),+ userLine("u2", "Second", "2026-10-21T11:00:00.000Z"),+ reply("a2", "u2", "Answer two"),+ ];+ const transcript = join(folder, "s1.jsonl");+ await writeFile(transcript, lines.map((line) => JSON.stringify(line)).join("\n"));+ await saveSession(+ "s1",+ session({ sessionId: "s1", epoch: "e1", nodes: [node("m1", "message", "First")] }),+ );++ const first = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });+ expect(first.epochs[0]?.sessions[0]?.chat?.map((t) => t.id)).toEqual(["m1", "m2"]);+ expect((await readConversationStore(root, "s1")).map((t) => [t.uuid, t.text])).toEqual([+ ["u1", "First"],+ ["u2", "Second"],+ ]);++ // A later turn is appended to the store, not to a rewritten file.+ await appendFile(transcript, `\n${JSON.stringify(userLine("u3", "Third", T0))}`);+ const second = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });+ expect(second.epochs[0]?.sessions[0]?.chat?.map((t) => t.text)).toEqual([+ "First",+ "Second",+ "Third",+ ]);+ expect((await readConversationStore(root, "s1")).map((t) => t.uuid)).toEqual([+ "u1",+ "u2",+ "u3",+ ]);++ // Claude Code deletes the transcript; the store still feeds the drill-down.+ await rm(transcript);+ const third = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });+ expect(third.epochs[0]?.sessions[0]).toMatchObject({+ transcriptAvailable: false,+ chat: [+ { id: "m1", text: "First", replies: ["Answer one"] },+ { id: "m2", text: "Second", replies: ["Answer two"] },+ { id: "m3", text: "Third", replies: [] },+ ],+ });+ });++ it("adds the conversation gitignore line once, also in an existing project", async () => {+ const ignore = join(paths().base, ".gitignore");+ // An older project has no inner .gitignore; the next build writes it.+ await rm(ignore, { force: true });+ await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });+ expect(await readFile(ignore, "utf8")).toBe("conversations/\n");+ await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });+ expect(await readFile(ignore, "utf8")).toBe("conversations/\n");+ });++ it("keeps the map when the conversation store cannot be written", async () => {+ const folder = join(dir, "claude", "projects", "-proj");+ await mkdir(folder, { recursive: true });+ await writeFile(+ join(folder, "s1.jsonl"),+ JSON.stringify({+ type: "user",+ uuid: "u1",+ timestamp: T0,+ message: { content: "Hi" },+ }),+ );+ await saveSession(+ "s1",+ session({ sessionId: "s1", epoch: "e1", nodes: [node("m1", "message", "Hi")] }),+ );+ // A file where the store's directory belongs makes the append fail.+ await writeFile(paths().conversations, "not a directory");++ const model = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });+ expect(model.epochs[0]?.sessions[0]?.chat?.[0]?.text).toBe("Hi");+ expect(io.warnings).toEqual(+ expect.arrayContaining([expect.stringMatching(/^could not store the conversation of s1: /)]),+ );+ });++ it("warns but still builds when the inner gitignore cannot be written", async () => {+ const ignore = join(paths().base, ".gitignore");+ await rm(ignore, { force: true });+ await mkdir(ignore);+ const model = await buildProject({ dir: root, io, templateHtml: TEMPLATE, quiet: true });+ expect(model.epochs[0]?.id).toBe("e1");+ expect(io.warnings).toEqual(+ expect.arrayContaining([+ expect.stringMatching(/^could not update \.codelineage\/\.gitignore: /),+ ]),+ );+ });+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 });diff --git a/packages/cli/test/conversations.test.ts b/packages/cli/test/conversations.test.tsnew file mode 100644index 0000000..1d9bdb4--- /dev/null+++ b/packages/cli/test/conversations.test.ts@@ -0,0 +1,76 @@+import { readFile, stat, truncate } from "node:fs/promises";+import { describe, expect, it } from "vitest";+import { appendConversationTurns, readConversationStore } from "../src/store/conversations.js";+import { projectPaths } from "../src/store/paths.js";+import type { ChatTurn } from "../src/transcript.js";+import { tempDir } from "./helpers.js";++function turn(uuid: string | undefined, text: string, replies: string[] = []): ChatTurn {+ return {+ id: "m1",+ at: "2026-10-24T10:00:00.000Z",+ text,+ ...(uuid === undefined ? {} : { uuid }),+ replies,+ tools: { commands: 1, files: ["src/a.ts"], other: 0 },+ };+}++describe("conversation store", () => {+ it("is empty when the session was never stored", async () => {+ expect(await readConversationStore(await tempDir(), "s1")).toEqual([]);+ });++ it("appends only turns it does not hold yet, one gzip member at a time", async () => {+ const root = await tempDir();+ expect(await appendConversationTurns(root, "s1", [turn("u1", "one"), turn("u2", "two")])).toBe(+ 2,+ );+ expect(+ await appendConversationTurns(root, "s1", [turn("u2", "two"), turn("u3", "three")]),+ ).toBe(1);+ expect((await readConversationStore(root, "s1")).map((t) => [t.uuid, t.text])).toEqual([+ ["u1", "one"],+ ["u2", "two"],+ ["u3", "three"],+ ]);++ const bytes = await readFile(projectPaths(root).conversation("s1"));+ expect([...bytes.subarray(0, 2)]).toEqual([0x1f, 0x8b]);+ // The second append is a second gzip member after the first, not a rewrite.+ expect(await appendConversationTurns(root, "s1", [turn("u1", "one")])).toBe(0);+ });++ it("redacts secrets before writing and keeps the tool summary", async () => {+ const root = await tempDir();+ await appendConversationTurns(root, "s1", [+ turn("u1", "deploy with sk-ant-api03-abcdefghijklmnopqrstuvwxyz0123", [+ "token: ghp_abcdefghijklmnopqrstuvwxyz0123456789",+ ]),+ ]);+ const [stored] = await readConversationStore(root, "s1");+ expect(stored?.text).toBe("deploy with [REDACTED]");+ expect(stored?.replies).toEqual(["token: [REDACTED]"]);+ expect(stored?.tools).toEqual({ commands: 1, files: ["src/a.ts"], other: 0 });+ });++ it("keeps the complete turns before a half-written last member", async () => {+ const root = await tempDir();+ await appendConversationTurns(root, "s1", [turn("u1", "one")]);+ const complete = (await stat(projectPaths(root).conversation("s1"))).size;+ await appendConversationTurns(root, "s1", [turn("u2", "two")]);+ const withSecond = (await stat(projectPaths(root).conversation("s1"))).size;+ // A killed process leaves the second member cut in the middle.+ await truncate(+ projectPaths(root).conversation("s1"),+ complete + Math.floor((withSecond - complete) / 2),+ );+ expect((await readConversationStore(root, "s1")).map((t) => t.text)).toEqual(["one"]);+ });++ it("skips a turn without a transcript uuid, because it cannot be recognised again", async () => {+ const root = await tempDir();+ expect(await appendConversationTurns(root, "s1", [turn(undefined, "no uuid")])).toBe(0);+ expect(await readConversationStore(root, "s1")).toEqual([]);+ });+});diff --git a/packages/cli/test/init.test.ts b/packages/cli/test/init.test.tsindex cb057d3..4139844 100644--- a/packages/cli/test/init.test.ts+++ b/packages/cli/test/init.test.ts@@ -9,7 +9,7 @@ import {setRetention,} from "../src/claude-settings.js";import { init } from "../src/commands/init.js";-import { ensureGitignore, findGitRoot } from "../src/git.js";+import { ensureConversationGitignore, ensureGitignore, findGitRoot } from "../src/git.js";import { loadConfig, loadProject, loadRegistry } from "../src/store/stores.js";import { envFor, fakeIo, T0, tempDir } from "./helpers.js";@@ -41,6 +41,18 @@ describe("init", () => {expect(io.asked).toHaveLength(4);expect(await readSkillAllowed(env)).toBe(true);expect(io.lines.at(-2)).toMatch(/^Initialized proj/);+ // The conversation store stays out of git even when records are committed.+ expect(await readText(join(root, ".codelineage", ".gitignore"))).toBe("conversations/\n");+ expect(io.lines).toContain(+ "Conversations are stored in .codelineage/conversations/ (kept out of git, even with the commit policy).",+ );+ });++ it("adds the conversation ignore line once", async () => {+ await mkdir(join(root, ".codelineage"));+ expect(await ensureConversationGitignore(root)).toBe(true);+ expect(await ensureConversationGitignore(root)).toBe(false);+ expect(await readText(join(root, ".codelineage", ".gitignore"))).toBe("conversations/\n");});it("asks nothing when every answer is given as an option", async () => {diff --git a/packages/cli/test/transcript.test.ts b/packages/cli/test/transcript.test.tsindex 5e72375..8794e6e 100644--- a/packages/cli/test/transcript.test.ts+++ b/packages/cli/test/transcript.test.ts@@ -47,6 +47,11 @@ describe("messageText", () => {["shell input", user("<bash-input>ls</bash-input>")],["shell output", user("<bash-stdout>x</bash-stdout><bash-stderr></bash-stderr>")],["local command output", user("<local-command-stdout>Bye</local-command-stdout>")],+ ["an interrupt notice", user("[Request interrupted by user]")],+ [+ "an interrupt notice for a tool use",+ user([{ type: "text", text: "[Request interrupted by user for tool use]" }]),+ ],["a slash command without arguments", user("<command-name>/exit</command-name>")],["empty text", user(" ")],["content of another shape", user({ text: "x" })],@@ -62,6 +67,7 @@ describe("readUserMessages", () => {const lines = [JSON.stringify(user("first", {}, 1)),JSON.stringify({ type: "assistant", timestamp: at(2), message: { content: [] } }),+ JSON.stringify(user("[Request interrupted by user for tool use]", {}, 3)),JSON.stringify(user([{ type: "tool_result", content: "x" }], {}, 3)),'{"type":"user", broken',JSON.stringify(user("second", {}, 4)),