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(session): write pending as user-level work at close

Eren28e6a610cb9e
diff --git a/packages/cli/skills/record/SKILL.md b/packages/cli/skills/record/SKILL.md
index 220d4af..60ba9d7 100644
--- a/packages/cli/skills/record/SKILL.md
+++ b/packages/cli/skills/record/SKILL.md
@@ -15,7 +15,7 @@ The current record (`cogit session show`):
- `initialized: false`: reply exactly "cogit is not set up in this project yet; run
`npx @cogit/cli init` here first." and stop.
- `sessionError`: quote it and stop; never write over the record.
-- Nothing new or changed (`newMessages` empty): reply "Lineage is up to date." and stop.
+- Nothing new or changed (`newMessages` empty): reply "cogit is up to date." and stop.
## Look something up
@@ -36,8 +36,11 @@ One JSON object:
- `sessionId`: always `"${CLAUDE_SESSION_ID}"`.
- `title`: a few words; on the first write or when the focus changed.
-- `status`: replaces all four fields, so send each: `goal` (one sentence), `done`, `pending`
- (`{ "text", "needsUser": true }` when it waits on the user), `next` (concrete step).
+- `status`: replaces all four fields, so send each: `goal` (one sentence), `done` (what
+ finished, as outcomes), `pending` (the work still open, one item per ask in the user's
+ words — never a checklist of commands; a release and the restart it needs are one item, and
+ a step that serves nothing is dropped; `{ "text", "needsUser": true }` when it waits on the
+ user), `next` (concrete step).
- `nodes`: only new nodes or changed fields; the rest is kept.
## One node per user message
@@ -154,4 +157,4 @@ personal data, file contents or command output.
2. `node "${CLAUDE_PLUGIN_ROOT}/dist/cli.js" session write -C "<dir from the record>" --file "<inbox path>" --consume`
If it fails, fix the JSON according to the error and run it again. Then reply with one short
-line, e.g. "Lineage updated (3 nodes)"; never repeat the JSON.
+line, e.g. "cogit updated (3 nodes)"; never repeat the JSON.
diff --git a/packages/cli/src/commands/backfill.ts b/packages/cli/src/commands/backfill.ts
index 3a09ea3..60f3447 100644
--- a/packages/cli/src/commands/backfill.ts
+++ b/packages/cli/src/commands/backfill.ts
@@ -83,7 +83,7 @@ function rules(language: string, messageSummaries: boolean, recorder: RecordMode
'- The agent\'s work belongs inside the message node that caused it, never in nodes of its own: work (short items), agentDecisions ([{"title": "...", "why": "...", "alternatives": [...]}]) only for technical choices with a reason — never for proposals or work items — commits (short hashes) and files (a few paths).',
"- Write a branch summary ({title, asked, outcome, open}) on the first message of a branch when the branch ends.",
'- Never send "at"; the CLI takes each message\'s time from the transcript.',
- "- Replace the whole status (goal, done, pending [{text, needsUser}], next) when it changed; otherwise leave it out.",
+ "- Replace the whole status (goal, done, pending [{text, needsUser}], next) when it changed; otherwise leave it out. Pending is the work still open, one item per ask in the user's words, never a checklist of commands: a release and the restart it needs are one item, and a step that serves nothing is dropped.",
"- Record decisions and reasons, never secrets, credentials, personal data, file contents or command output.",
`- Write titles and text in ${writing}; JSON keys stay in English.`,
];
diff --git a/packages/cli/src/commands/close.ts b/packages/cli/src/commands/close.ts
index 7cca15b..88631d7 100644
--- a/packages/cli/src/commands/close.ts
+++ b/packages/cli/src/commands/close.ts
@@ -158,7 +158,7 @@ export function closePrompt(
].join("\n");
});
const status = opts.status
- ? ', "status": {"goal": "one sentence", "done": ["..."], "pending": [{"text": "...", "needsUser": true}], "next": "a concrete step"}'
+ ? ', "status": {"goal": "one sentence", "done": ["an outcome"], "pending": [{"text": "one piece of open work, in the user\'s words", "needsUser": false}], "next": "a concrete step"}'
: "";
return [
"You close a cogit lineage record at the end of a coding session. Each user message below is listed with what the agent did.",
@@ -173,6 +173,11 @@ export function closePrompt(
"",
"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.",
+ ...(opts.status
+ ? [
+ "Write the status the way the user would say it. `goal`: one sentence. `done`: what the session finished, as outcomes. `pending`: the work it still leaves open, one item per ask in the user's words — never a checklist of commands; a release and the restart it needs are one item, and a step that serves nothing is dropped. Mark `needsUser` when only the user can decide or act (a choice, an approval, a credential). A session usually leaves none or a few.",
+ ]
+ : []),
`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),
@@ -261,6 +266,12 @@ export function closePayload(
* recorded session and writes its answer as the side model. Nothing recorded
* yet means nothing to close.
*/
+/** Whether the record's status says nothing yet (a short session the agent never recorded). */
+export function statusIsEmpty(record: Session): boolean {
+ const { goal, done, pending, next } = record.status;
+ return goal === "" && done.length === 0 && pending.length === 0 && next === "";
+}
+
export async function closeSession(root: string, sessionId: string, io: Io): Promise<void> {
const agent = defaultAgent();
const file = await agent.findTranscript(sessionId, io.env);
@@ -287,7 +298,10 @@ export async function closeSession(root: string, sessionId: string, io: Io): Pro
const candidates =
firstNode && firstNode.parent === null ? await candidateSessions(root, sessionId, io.env) : [];
// The status belongs to the main agent unless only the side model records.
- const status = config.recorder === "side";
+ // A session that ended before the agent's first record pass (a short chat)
+ // leaves it empty, so this pass fills it: without a status there are no
+ // pending items for the captured-work pass to read.
+ const status = config.recorder === "side" || statusIsEmpty(record);
const prompt = closePrompt(closing, record, {
language: config.language,
candidates,
diff --git a/packages/cli/test/close.test.ts b/packages/cli/test/close.test.ts
index cb01434..dd51dee 100644
--- a/packages/cli/test/close.test.ts
+++ b/packages/cli/test/close.test.ts
@@ -11,6 +11,7 @@ import {
type Thread,
threadMembers,
} from "../src/commands/close.js";
+import { configSet } from "../src/commands/config.js";
import { init } from "../src/commands/init.js";
import { sessionWrite } from "../src/commands/session.js";
import { messageHash } from "../src/messages.js";
@@ -125,9 +126,17 @@ describe("closePrompt", () => {
expect(prompt).toContain("· Release → s0:h10");
expect(prompt).toContain('"continues": null');
expect(prompt).not.toContain('"status"');
- expect(
- closePrompt(turns, session([]), { language: "Turkish", status: true, candidates: [] }),
- ).toContain('"status": {"goal"');
+ const withStatus = closePrompt(turns, session([]), {
+ language: "Turkish",
+ status: true,
+ candidates: [],
+ });
+ expect(withStatus).toContain('"status": {"goal"');
+ // Pending is leftover work in the user's words, never a command list.
+ expect(withStatus).toContain("never a checklist of commands");
+ expect(withStatus).toContain("one piece of open work, in the user's words");
+ // The status guidance stays out when the pass does not write a status.
+ expect(prompt).not.toContain("never a checklist of commands");
});
});
@@ -297,4 +306,89 @@ process.stdin.on("end", async () => {
"Split the session into threads",
);
});
+
+ it("fills a status the agent never wrote, and keeps the one it did", async () => {
+ const bin = join(dir, "bin");
+ await mkdir(bin, { recursive: true });
+ // Only the close pass answers; the tail backfill before it writes no status.
+ const fake = async (answer: unknown): Promise<void> => {
+ await writeFile(
+ join(bin, "claude"),
+ `#!/usr/bin/env node
+let input = "";
+process.stdin.on("data", (c) => { input += c; });
+process.stdin.on("end", () => {
+ const answer = input.includes("You close a cogit lineage record")
+ ? ${JSON.stringify(JSON.stringify(answer))}
+ : "{}";
+ process.stdout.write(JSON.stringify({ result: answer }));
+});
+`,
+ );
+ await chmod(join(bin, "claude"), 0o755);
+ };
+ const closedStatus = {
+ goal: "Ship it",
+ done: ["built it"],
+ pending: [{ text: "publish", needsUser: true }],
+ next: "push",
+ };
+ const threads = [
+ { name: "Work", messages: "m1-m2", from: null, asked: "a", outcome: "o", open: "" },
+ ];
+ await fake({ threads, leftOff: "Built", status: closedStatus });
+ const env = { ...envFor(dir), PATH: `${bin}:${process.env.PATH ?? ""}` };
+ await init(root, { name: "proj", retention: "keep", language: "auto" }, fakeIo(env));
+ // The agent owns the status in mixed mode; the close pass fills it only when empty.
+ await configSet("recorder", "mixed", fakeIo(env));
+ const folder = join(envFor(dir).CLAUDE_CONFIG_DIR ?? "", "projects", "proj");
+ await mkdir(folder, { recursive: true });
+ const at = (m: number) => `2026-10-23T10:0${m}:00.000Z`;
+ const typed = (m: number) => ({
+ type: "user",
+ timestamp: at(m),
+ message: { role: "user", content: `message ${m}` },
+ });
+ await writeFile(
+ join(folder, "s1.jsonl"),
+ `${[1, 2].map((m) => JSON.stringify(typed(m))).join("\n")}\n`,
+ );
+ await sessionWrite({ dir: root, by: "side" }, fakeIo(env), async () =>
+ JSON.stringify({
+ sessionId: "s1",
+ nodes: [1, 2].map((m) => ({
+ id: `m${m}`,
+ kind: "message",
+ title: `T${m}`,
+ parent: m === 1 ? null : `m${m - 1}`,
+ })),
+ }),
+ );
+
+ // A short session closed before the agent's first record pass: filled here.
+ await backfillTail(root, "s1", fakeIo(env), { close: true });
+ const first = await loadSession(root, "s1");
+ expect(first.found && first.ok ? first.data.status : undefined).toEqual(closedStatus);
+
+ // Once the agent has written a status, a later close leaves it alone.
+ const agentStatus = {
+ goal: "The agent's goal",
+ done: [],
+ pending: [],
+ next: "keep going",
+ };
+ await sessionWrite({ dir: root, by: "agent" }, fakeIo(env), async () =>
+ JSON.stringify({ sessionId: "s1", status: agentStatus }),
+ );
+ const agent = await loadSession(root, "s1");
+ expect(agent.found && agent.ok ? agent.data.status : undefined).toEqual(agentStatus);
+ await fake({
+ threads,
+ leftOff: "Built",
+ status: { ...closedStatus, goal: "A different goal" },
+ });
+ await backfillTail(root, "s1", fakeIo(env), { close: true });
+ const second = await loadSession(root, "s1");
+ expect(second.found && second.ok ? second.data.status : undefined).toEqual(agentStatus);
+ });
});