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(view): merge needsUser items from active parallel sessions

Erenc91485c456eb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6144c59..111bc4a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
+- Status card at the top of the map: goal, done, pending and next from the most recently updated session, with `needsUser` items merged from every session active within 7 days (deduplicated by text, newest first).
- Template workspace (`packages/template`): React 19 + Vite 8 + `vite-plugin-singlefile`, dev fixture and the shared lineage view-model contract (`packages/cli/src/view/model.ts`).
- `codelineage build [dir]`: renders `.codelineage/lineage.html` from `project.json` and `sessions/*.json` (epochs in project order, nested node tree, unassigned sessions grouped), skips unreadable session files with a warning, redacts secrets and embeds the single-file template into the CLI bundle; `session write` rebuilds quietly afterwards.
diff --git a/packages/cli/src/view/lineage.ts b/packages/cli/src/view/lineage.ts
index f2174be..72c1fce 100644
--- a/packages/cli/src/view/lineage.ts
+++ b/packages/cli/src/view/lineage.ts
@@ -53,16 +53,56 @@ export function buildNodeTree(nodes: LineageNode[]): ViewNode[] {
return tree;
}
-/** The status card comes from the most recently updated session. */
-function statusCard(sessions: Session[]): StatusCard {
+/** A session counts as active while it was updated within this window. */
+export const ACTIVE_WINDOW_DAYS = 7;
+const ACTIVE_WINDOW_MS = ACTIVE_WINDOW_DAYS * 24 * 60 * 60 * 1000;
+
+/** Parsed timestamp, with `-Infinity` for a value the date parser rejects. */
+function timestamp(value: string): number {
+ const time = Date.parse(value);
+ return Number.isNaN(time) ? Number.NEGATIVE_INFINITY : time;
+}
+
+function isActive(session: Session, now: string): boolean {
+ const updated = timestamp(session.updatedAt);
+ const reference = timestamp(now);
+ if (updated === Number.NEGATIVE_INFINITY || reference === Number.NEGATIVE_INFINITY) return false;
+ return reference - updated <= ACTIVE_WINDOW_MS;
+}
+
+/** Most recently updated first; the session id keeps equal timestamps deterministic. */
+function byUpdatedAt(a: Session, b: Session): number {
+ return timestamp(b.updatedAt) - timestamp(a.updatedAt) || a.sessionId.localeCompare(b.sessionId);
+}
+
+/**
+ * The status card: goal, done, pending and next come from the most recently
+ * updated session; `needsUser` items are merged from every other session active
+ * within `ACTIVE_WINDOW_DAYS`, newest first and deduplicated by text.
+ * `now` is the build time the window is measured against.
+ */
+export function statusCard(sessions: Session[], now: string): StatusCard {
let latest: Session | undefined;
for (const session of sessions) {
- if (!latest || session.updatedAt > latest.updatedAt) latest = session;
+ if (!latest || timestamp(session.updatedAt) > timestamp(latest.updatedAt)) latest = session;
+ }
+
+ const pending = (latest?.status.pending ?? []).map((item) => ({ ...item }));
+ const seen = new Set(pending.map((item) => item.text));
+ const others = sessions.filter((session) => session !== latest).sort(byUpdatedAt);
+ for (const session of others) {
+ if (!isActive(session, now)) continue;
+ for (const item of session.status.pending) {
+ if (!item.needsUser || seen.has(item.text)) continue;
+ seen.add(item.text);
+ pending.push({ ...item });
+ }
}
+
return {
goal: latest?.status.goal ?? "",
done: latest?.status.done ?? [],
- pending: latest?.status.pending ?? [],
+ pending,
next: latest?.status.next ?? "",
lastActivity: latest?.updatedAt ?? null,
};
@@ -124,7 +164,7 @@ export function buildViewModel(input: ViewModelInput): LineageViewModel {
kind: "lineage",
schema: VIEW_SCHEMA,
project: { name: input.project.name, path: input.path, generatedAt: input.generatedAt },
- status: statusCard(sessions),
+ status: statusCard(sessions, input.generatedAt),
epochs,
unassigned,
};
diff --git a/packages/cli/test/build.test.ts b/packages/cli/test/build.test.ts
index 6775554..ec492b5 100644
--- a/packages/cli/test/build.test.ts
+++ b/packages/cli/test/build.test.ts
@@ -8,7 +8,7 @@ import { init } from "../src/commands/init.js";
import { sessionWrite } from "../src/commands/session.js";
import type { LineageNode, Session } from "../src/schema/session.js";
import { projectPaths } from "../src/store/paths.js";
-import { buildNodeTree, buildViewModel, embedViewModel } from "../src/view/lineage.js";
+import { buildNodeTree, buildViewModel, embedViewModel, statusCard } from "../src/view/lineage.js";
import { DATA_ELEMENT_ID } from "../src/view/model.js";
import { envFor, type FakeIo, fakeIo, T0, tempDir } from "./helpers.js";
@@ -162,6 +162,84 @@ describe("buildViewModel", () => {
});
});
+describe("statusCard", () => {
+ const NOW = "2026-10-21T10:00:00.000Z";
+
+ it("takes goal/done/next from the latest session and merges active needsUser items once", () => {
+ const sessions = [
+ session({
+ sessionId: "inactive",
+ updatedAt: "2026-09-01T00:00:00.000Z",
+ status: {
+ goal: "stale",
+ done: [],
+ pending: [{ text: "stale ask", needsUser: true }],
+ next: "stale",
+ },
+ }),
+ session({
+ sessionId: "latest",
+ updatedAt: "2026-10-20T09:00:00.000Z",
+ status: {
+ goal: "goal",
+ done: ["done"],
+ pending: [{ text: "mine", needsUser: true }],
+ next: "next",
+ },
+ }),
+ session({
+ sessionId: "active-new",
+ updatedAt: "2026-10-20T08:00:00.000Z",
+ status: {
+ goal: "",
+ done: [],
+ pending: [
+ { text: "mine", needsUser: true },
+ { text: "shared", needsUser: true },
+ { text: "not merged", needsUser: false },
+ ],
+ next: "",
+ },
+ }),
+ session({
+ sessionId: "active-old",
+ updatedAt: "2026-10-18T00:00:00.000Z",
+ status: {
+ goal: "",
+ done: [],
+ pending: [{ text: "older ask", needsUser: true }],
+ next: "",
+ },
+ }),
+ ];
+
+ expect(statusCard(sessions, NOW)).toEqual({
+ goal: "goal",
+ done: ["done"],
+ pending: [
+ { text: "mine", needsUser: true },
+ { text: "shared", needsUser: true },
+ { text: "older ask", needsUser: true },
+ ],
+ next: "next",
+ lastActivity: "2026-10-20T09:00:00.000Z",
+ });
+ });
+
+ it("treats unparseable timestamps as inactive instead of merging them", () => {
+ const sessions = [
+ session({ sessionId: "latest", updatedAt: "2026-10-20T00:00:00.000Z" }),
+ session({
+ sessionId: "broken",
+ updatedAt: "not-a-date",
+ status: { goal: "", done: [], pending: [{ text: "ask", needsUser: true }], next: "" },
+ }),
+ ];
+ expect(statusCard(sessions, NOW).pending).toEqual([]);
+ expect(statusCard(sessions, "also-broken").pending).toEqual([]);
+ });
+});
+
describe("embedViewModel", () => {
const model = buildViewModel({
project: { schema: 1, name: "p", epochs: [] },
diff --git a/packages/template/src/styles.css b/packages/template/src/styles.css
index eded4b0..d3bd1fd 100644
--- a/packages/template/src/styles.css
+++ b/packages/template/src/styles.css
@@ -111,6 +111,7 @@ ul {
border: 1px solid var(--warn);
border-radius: 999px;
font-size: 11px;
+ white-space: nowrap;
}
.epoch {
diff --git a/specs/codelineage-mvp.md b/specs/codelineage-mvp.md
index cc765f4..1cf9aa9 100644
--- a/specs/codelineage-mvp.md
+++ b/specs/codelineage-mvp.md
@@ -22,7 +22,8 @@ these records into static HTML:
- **Status card** at the top of every project: goal, done, pending (flags items
waiting on the user), next step, last activity. With parallel sessions, goal and
next come from the most recently updated session; `needsUser` items are merged
- from all active sessions.
+ from all active sessions. A session is **active** while its `updatedAt` is
+ within 7 days of the build, newest first; duplicate item texts are shown once.
- **Panel** (global): every registered project as a small status card, with quick
switching into each project map. Settings are shown read-only.