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(record): drop made-up side message ids and list a session from its first prompt
Eren1847c0b66a3b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8ae9d35..45ecde9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,9 @@ 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]+### Fixed+- A new session shows on the map while its first turn is still running; 0.21.1 listed it only once that turn ended.+- The side model's message ids are checked against the transcript: a node with an id it made up is no longer stored, so the real message stays unrecorded and the next catch-up records it. Before, the made-up nodes counted as recorded, the real messages were never recorded, and the closing pass wrote a stale "where it left off" line without them.## [0.21.1] - 2026-10-29### Changeddiff --git a/packages/cli/src/commands/backfill.ts b/packages/cli/src/commands/backfill.tsindex b3cba03..fd5e436 100644--- a/packages/cli/src/commands/backfill.ts+++ b/packages/cli/src/commands/backfill.ts@@ -72,7 +72,7 @@ function rules(language: string, messageSummaries: boolean, recorder: RecordModeconst writing = language === "auto" ? "the conversation's language" : language;const lines = ["Rules (from the cogit lineage skill):",- '- Send one "message" node for every message below, with the id exactly as given; skip none, even a short "ok".',+ '- Send one "message" node for every message below, with the id exactly as given in its heading (m1, m2, …); skip none, even a short "ok". Never make up an id.',`- kind is "message". title: a few words in the user's own wording.${messageSummaries ? " summary: one or two sentences on what came of it." : ""}`,diff --git a/packages/cli/src/commands/session.ts b/packages/cli/src/commands/session.tsindex b54584e..57c326b 100644--- a/packages/cli/src/commands/session.ts+++ b/packages/cli/src/commands/session.ts@@ -110,7 +110,9 @@ export async function sessionWrite(// Both ids work: the agent may send the stable `h…` id, or the `m1` label it// reads in `session show`; the CLI maps the label to the stable id.const messages = await readSessionMessages(root, redacted.sessionId, io.env);- const input = nameMessages(redacted, messages, io);+ // The side model runs on this same transcript, so a message id it does not+ // know is made up; its node is dropped instead of stored beside the real one.+ const input = nameMessages(redacted, messages, io, opts.by === "side");if (count > 0) io.warn(`redacted ${count} secret-looking value(s)`);if (input.epoch && !project.data.epochs.some((e) => e.id === input.epoch)) {io.warn(@@ -181,6 +183,7 @@ function nameMessages(input: SessionInput,messages: SessionMessage[] | null,io: Io,+ dropUnknown = false,): SessionInput {const nodes = input.nodes ?? [];if (!nodes.some((n) => n.kind === "message")) return input;@@ -192,9 +195,15 @@ function nameMessages(const own = parseMessageRef(id);return rename(own.sessionId === input.sessionId ? own.id : id);};+ const known = (node: (typeof nodes)[number]): boolean =>+ node.kind !== "message" || !messages || byHash.has(rename(node.id));+ for (const node of nodes) {+ if (dropUnknown && !known(node))+ io.warn(`message node ${node.id}: no such message in the transcript; not recorded`);+ }return {...input,- nodes: nodes.map((node) => {+ nodes: (dropUnknown ? nodes.filter(known) : nodes).map((node) => {if (node.kind !== "message") return node;const at = byHash.get(rename(node.id))?.at;if (!messages) {diff --git a/packages/cli/src/hooks/promptsubmit.ts b/packages/cli/src/hooks/promptsubmit.tsindex f6da9b9..4543fa6 100644--- a/packages/cli/src/hooks/promptsubmit.ts+++ b/packages/cli/src/hooks/promptsubmit.ts@@ -1,13 +1,16 @@import { refreshGitHooks } from "../git-hooks.js";+import { HookState, STATE_SCHEMA } from "../schema/state.js";import { atomicWriteJson } from "../store/fs.js";import { projectPaths } from "../store/paths.js";+import { updateState } from "../store/stores.js";import type { HookContext } from "./run.js";/*** UserPromptSubmit hook (Story 9.3). Records which session this working tree is* in, so the git pre-commit hook can carry its record with the next code commit.* The file is local state (`.cogit/.gitignore` keeps it out) and is rewritten on- * every message: a resumed or new session replaces the previous one.+ * every message: a resumed or new session replaces the previous one. It also+ * opens the session's hook state, so the map shows it from the first message.*/export async function onPromptSubmit(ctx: HookContext): Promise<undefined> {if (!ctx.initialized) return undefined;@@ -18,6 +21,16 @@ export async function onPromptSubmit(ctx: HookContext): Promise<undefined> {: { transcriptPath: ctx.input.transcript_path }),at: ctx.now,});+ // The map lists a session without a record by its state file; before the+ // first Stop there was none, so a long first turn kept it off the map.+ await updateState(+ ctx.root,+ ctx.sessionId,+ (cur) => cur ?? HookState.parse({ schema: STATE_SCHEMA }),+ {+ timeoutMs: 1500,+ },+ );// A plugin update moves the CLI: point the git hooks' blocks at this one.await refreshGitHooks(ctx.root).catch(() => undefined);return undefined;diff --git a/packages/cli/test/hooks.test.ts b/packages/cli/test/hooks.test.tsindex b405139..fb5f45b 100644--- a/packages/cli/test/hooks.test.ts+++ b/packages/cli/test/hooks.test.ts@@ -562,6 +562,18 @@ describe("runHook", () => {transcriptPath: "/t/s1.jsonl",at: T0,});+ // The state file opens with the first message, so the map lists the session.+ const statePath = projectPaths(root).state("s1");+ expect(JSON.parse(await readFile(statePath, "utf8"))).toMatchObject({ turns: 0 });+ await writeFile(statePath, JSON.stringify({ schema: 1, turns: 3 }));+ await runHook(+ "promptsubmit",+ JSON.stringify({ session_id: "s1", cwd: root }),+ env,+ T0,+ () => {},+ );+ expect(JSON.parse(await readFile(statePath, "utf8"))).toMatchObject({ turns: 3 });});it("points an existing git hook block at the CLI running now", async () => {diff --git a/packages/cli/test/session.test.ts b/packages/cli/test/session.test.tsindex a55ce42..146eb86 100644--- a/packages/cli/test/session.test.ts+++ b/packages/cli/test/session.test.ts@@ -73,6 +73,28 @@ describe("session write", () => {await epochAdd(root, "e2e", "E2E", fakeIo(envFor(dir)));});+ it("drops a side message node the transcript does not have", async () => {+ const folder = join(io.env.CLAUDE_CONFIG_DIR ?? "", "projects", "proj");+ await mkdir(folder, { recursive: true });+ const line = { type: "user", timestamp: T0, message: { content: "Hi" } };+ await writeFile(join(folder, "s1.jsonl"), `${JSON.stringify(line)}\n`);+ await sessionWrite({ dir: root, by: "side" }, io, async () =>+ JSON.stringify({+ sessionId: "s1",+ nodes: [+ { id: "m1", kind: "message", title: "Hi" },+ { id: "h7d21e4f0a9b3", kind: "message", title: "Made up" },+ ],+ }),+ );+ const loaded = await loadSession(root, "s1");+ if (!loaded.found || !loaded.ok) throw new Error("no record");+ expect(loaded.data.nodes.map((n) => n.title)).toEqual(["Hi"]);+ expect(io.warnings).toContain(+ "message node h7d21e4f0a9b3: no such message in the transcript; not recorded",+ );+ });+describe("side recording (Story 12.1)", () => {const side = (json: unknown) =>sessionWrite({ dir: root, by: "side" }, io, async () => JSON.stringify(json));