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(captures): distil the record's own pending work

Eren62371ef5d542
diff --git a/docs/guide/map.md b/docs/guide/map.md
index a58c65d..c355e96 100644
--- a/docs/guide/map.md
+++ b/docs/guide/map.md
@@ -131,11 +131,13 @@ the map. In the terminal: `cogit log --file <path>` and `cogit why <path>`.
Working with an agent is improvised: things that would have been a plan's items get done,
half-done or dropped along the way. The **Captured** list is a short, curated one. When a
-session ends, the side model reads what its record left open — pending items, open branch
-lines, the last messages — and drafts at most three **user-level** items: something you asked
-for or the session left undone, as a short imperative in the conversation's language. It never
-drafts a commit step, a test run, a release chore or a status fact, and a session with nothing
-open costs no model call.
+session ends, the side model reads what its record left open — the record's own pending items
+first, with the open line of each branch summary and the last messages as supporting context —
+and drafts at most three **user-level** items: something you asked for or the session left
+undone, as a short imperative in the conversation's language. Anything the record lists as done
+is never drafted, even when an older branch line still calls it open, and the model never
+invents a commit step, a test run, a status fact or a question a later message answered. A
+session with nothing open costs no model call.
Each drafted item waits in **To review** until you choose: **Accept** keeps it in **Open**,
**Dismiss** closes it without doing it. An open item is closed with **Done**. The last ten
diff --git a/packages/cli/src/captures.ts b/packages/cli/src/captures.ts
index 1cfd3c0..f37e50c 100644
--- a/packages/cli/src/captures.ts
+++ b/packages/cli/src/captures.ts
@@ -45,9 +45,9 @@ export interface ExistingCapture {
}
/**
- * The prompt of the captured-work pass: the session's leftover lines and last
- * message titles, plus the project's current open and suggested items so
- * nothing is drafted twice.
+ * The prompt of the captured-work pass: what the session finished (a veto), its
+ * pending lines, its branch summaries' open lines and last message titles, plus
+ * the project's current open and suggested items so nothing is drafted twice.
*/
export function distillPrompt(
input: CaptureInput,
@@ -55,6 +55,7 @@ export function distillPrompt(
language: string,
): string {
const writing = language === "auto" ? "the conversation's language" : language;
+ const done = input.done.map((text) => `- ${clip(text, 300)}`);
const pending = input.pending.map(
(item) => `- ${item.needsUser ? "(needs the user) " : ""}${clip(item.text, 300)}`,
);
@@ -75,19 +76,25 @@ export function distillPrompt(
];
return [
"You distil the work a coding session left undone into a few items its user would recognize.",
- "The session below lists what its record says is still open: pending items, the open line of each branch summary, and the titles of its last messages.",
+ "The session's pending items are the record's own word on what is still open: draft from them first. The open line of each branch summary and the titles of the last messages are supporting context only — a branch line can be out of date, so never draft an item from one while a pending item covers the same work.",
"",
"Rules:",
`- At most ${DISTILL_LIMIT} items. Each one is work a person would ask for, phrased as a short imperative (one line, at most 140 characters) in ${writing}.`,
- "- Name only work the user asked for and that is still not done, or that the session left undone. A problem a later message fixed, finished or dropped is done, not open.",
- '- Never draft a commit step, a test run, a release chore, a status fact ("0.24 is unreleased") or a question a later message answered.',
+ "- Work the done list names is finished: never draft it, even when an older branch line still calls it open. A problem a later message fixed, finished or dropped is done, not open.",
+ "- When the session has pending items, every item must come from one of them; the branch lines only help you understand or reword an item, they never add one. Only when there is no pending item at all may an open branch line become an item. Never invent a commit step, a test run, a status fact or a question a later message answered; a pending item is work, not a status report.",
+ "- Fold the lines that are steps of one goal into one item: a release, its push and the restart that follows are one piece of work, phrased as the goal, not three items. A line that only orders an operation (run a command, restart a service, try something once, check a result) is a step of the item it serves; when it serves nothing, drop it.",
"- Items belong to the session, not to one message: do not name a message.",
"- Existing captured items are the user's list: never rephrase, merge or close them. Only put an id in `duplicateOf`.",
"",
...current,
`Session ${input.sessionId} "${clip(input.title, 200)}"`,
- ...(pending.length === 0 ? [] : ["Pending items:", ...pending]),
- ...(branches.length === 0 ? [] : ["Open branch lines:", ...branches]),
+ ...(done.length === 0 ? [] : ["Done in this session (never draft these):", ...done]),
+ ...(pending.length === 0
+ ? []
+ : ["Pending items — the session's own list of what is still open:", ...pending]),
+ ...(branches.length === 0
+ ? []
+ : ["Open branch lines (supporting context; may be stale):", ...branches]),
...(messages.length === 0 ? [] : ["Last messages:", ...messages]),
"",
`Return only one JSON object, no code fences: {"items": [{"text": "..."}], "duplicateOf": []}`,
diff --git a/packages/cli/src/view/captures.ts b/packages/cli/src/view/captures.ts
index 40505e2..b531279 100644
--- a/packages/cli/src/view/captures.ts
+++ b/packages/cli/src/view/captures.ts
@@ -2,9 +2,9 @@ import type { ViewNode, ViewPendingItem } from "./model.js";
/**
* The input the captured-work distiller reads (Story 15.1). The record is the
- * only source: a session's pending items and its branch summaries' open lines,
- * next to the titles of its last messages so the model can tell what the session
- * was really about. The map and the CLI show the curated store, never these rows.
+ * only source: what the session finished (a veto), its pending items and its
+ * branch summaries' open lines, next to the titles of its last messages so the
+ * model can tell what the session was really about. The map and the CLI show the curated store, never these rows.
*
* Kept free of Node imports, like the rest of `view/`.
*/
@@ -14,7 +14,7 @@ export interface CaptureSourceSession {
sessionId: string;
title: string;
updatedAt: string;
- status: { pending: readonly ViewPendingItem[] };
+ status: { pending: readonly ViewPendingItem[]; done?: readonly string[] | undefined };
messages: readonly Pick<ViewNode, "id" | "label" | "title" | "branch" | "unsummarized">[];
}
@@ -40,6 +40,8 @@ export interface CaptureMessageTitle {
export interface CaptureInput {
sessionId: string;
title: string;
+ /** What the session finished: the pass never drafts these again. */
+ done: string[];
pending: CapturePendingLine[];
/** A branch summary's `open` line, on the branch's first message. */
branches: CaptureLine[];
@@ -64,6 +66,16 @@ export function captureInput(
lastMessageLimit = LAST_MESSAGE_LIMIT,
): CaptureInput {
const recorded = session.messages.filter((message) => message.unsummarized !== true);
+ // What the session finished is a veto on its own: an older branch line still
+ // naming the work as open must not bring it back.
+ const done: string[] = [];
+ const doneSeen = new Set<string>();
+ for (const raw of session.status.done ?? []) {
+ const text = raw.replace(/\s+/g, " ").trim();
+ if (text === "" || doneSeen.has(text)) continue;
+ doneSeen.add(text);
+ done.push(text);
+ }
// A pending item belongs to the session as a whole; it points at the newest
// recorded message, where the session left off.
const newest = recorded[recorded.length - 1];
@@ -95,6 +107,7 @@ export function captureInput(
return {
sessionId: session.sessionId,
title: session.title === "" ? session.sessionId : session.title,
+ done,
pending,
branches,
lastMessages,
diff --git a/packages/cli/test/captures.test.ts b/packages/cli/test/captures.test.ts
index 5ede343..ca8c68c 100644
--- a/packages/cli/test/captures.test.ts
+++ b/packages/cli/test/captures.test.ts
@@ -54,6 +54,7 @@ describe("the distiller's input", () => {
sessionId: "s1",
title: "Ship it",
status: {
+ done: ["ship the parser", " ", "ship the parser "],
pending: [
{ text: "write the docs", needsUser: false },
{ text: " ", needsUser: true },
@@ -68,6 +69,7 @@ describe("the distiller's input", () => {
],
}),
);
+ expect(input.done).toEqual(["ship the parser"]);
expect(input.pending).toEqual([
{ text: "write the docs", needsUser: false, messageId: "m3", label: "m3" },
]);
@@ -89,9 +91,12 @@ describe("the distiller's prompt and answer", () => {
source({
sessionId: "s9",
title: "Parser work",
- status: { pending: [{ text: "decide the error format", needsUser: true }] },
+ status: {
+ done: ["ship the parser"],
+ pending: [{ text: "decide the error format", needsUser: true }],
+ },
messages: [
- { id: "m1", label: "m1", title: "Build the parser" },
+ { id: "m1", label: "m1", title: "Build the parser", branch: branch("handle input") },
{ id: "m2", label: "m2", title: "Handle input" },
],
}),
@@ -99,6 +104,11 @@ describe("the distiller's prompt and answer", () => {
it("names the leftover lines, the messages and the current list", () => {
const prompt = distillPrompt(input, [{ id: "c1a2b3c4", text: "old item" }], "auto");
+ expect(prompt).toContain("Done in this session (never draft these):\n- ship the parser");
+ expect(prompt).toContain(
+ "Pending items — the session's own list of what is still open:\n- (needs the user) decide the error format",
+ );
+ expect(prompt).toContain("Open branch lines (supporting context; may be stale):");
expect(prompt).toContain("decide the error format");
expect(prompt).toContain("Handle input");
expect(prompt).toContain("c1a2b3c4: old item");
@@ -106,6 +116,8 @@ describe("the distiller's prompt and answer", () => {
expect(prompt).toContain("at most 140 characters");
expect(prompt).toContain("the conversation's language");
expect(prompt).toContain("Items belong to the session");
+ expect(prompt).toContain("Work the done list names is finished");
+ expect(prompt).toContain("Fold the lines that are steps of one goal into one item");
expect(prompt).toContain('{"items": [{"text": "..."}], "duplicateOf": []}');
expect(prompt).not.toContain("messageId");
});