Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

feat(harness): session.diff shows in-flight dev work, not just merged

Jeromeffeac3d94e7e
diff --git a/.claude/hooks/render-status.mjs b/.claude/hooks/render-status.mjs
index d06c5f7f..38890c1f 100755
--- a/.claude/hooks/render-status.mjs
+++ b/.claude/hooks/render-status.mjs
@@ -98,23 +98,63 @@ function recentActivity(max = 25) {
const cell = (s) => String(s ?? "").replace(/\|/g, "\\|");
-// The cumulative diff of the session's merged work vs its fork anchor: the code
-// the harness has actually changed. Written as a `.diff` file so the developer
-// can open it and SEE the change on any surface (the VS Code extension can't show
-// the /tmp worktree diffs; the desktop diff pane is undocumented for subagents).
-// Returns null when the session branch does not exist yet or has no diff.
+// The cumulative diff of everything the session has changed so far: work already
+// merged into `session/<short>` PLUS in-flight work still on live dev branches
+// (`<short>/TASK-XXX`, `<short>/simple`) not yet merged. Written as a `.diff` file
+// so the developer can open it and SEE the change on any surface (the VS Code
+// extension does not show the /tmp worktree diffs). Updated on every agent STOP
+// (not continuously while an agent works), so a developer's work appears once THAT
+// developer stops - before the merge, not only after it. Null when nothing has
+// changed vs the fork anchor yet.
const verifyRef = (ref) =>
git(["rev-parse", "--verify", "--quiet", ref]).status === 0;
+function diffSection(label, range) {
+ const patch = git(["diff", range]).stdout;
+ if (!patch.trim()) return null;
+ return {
+ label,
+ range,
+ patch,
+ stat: git(["diff", "--stat", range]).stdout.trim(),
+ };
+}
+
function sessionDiff() {
- const branch = sessionBranch(ctx);
- if (!verifyRef(branch)) return null;
const anchor = sessionBaseBranch(ctx);
const baseRef = verifyRef(anchor) ? anchor : getBaseBranch();
- const range = `${baseRef}...${branch}`;
- const patch = git(["diff", range]).stdout;
- if (!patch.trim()) return null;
- return { range, stat: git(["diff", "--stat", range]).stdout.trim(), patch };
+ const sessRef = sessionBranch(ctx);
+ const sections = [];
+
+ // Merged work: fork anchor -> session branch.
+ if (verifyRef(sessRef)) {
+ const s = diffSection(`merged into ${sessRef}`, `${baseRef}...${sessRef}`);
+ if (s) sections.push(s);
+ }
+
+ // In-flight work: each <short>/* dev branch with commits not yet on the session
+ // branch (diffed against it, so the already-merged part is not counted twice).
+ const inflightBase = verifyRef(sessRef) ? sessRef : baseRef;
+ const devBranches = git([
+ "for-each-ref",
+ "--format=%(refname:short)",
+ `refs/heads/${ctx.sessionShort}/`,
+ ])
+ .stdout.split("\n")
+ .map((b) => b.trim())
+ .filter(Boolean);
+ for (const br of devBranches) {
+ const s = diffSection(`in flight: ${br}`, `${inflightBase}...${br}`);
+ if (s) sections.push(s);
+ }
+
+ if (!sections.length) return null;
+ return {
+ patch: sections
+ .map((s) => `### ${s.label} (${s.range})\n\n${s.patch}`)
+ .join("\n\n"),
+ stat: sections.map((s) => `${s.label}:\n${s.stat}`).join("\n\n"),
+ };
}
function build() {
@@ -151,7 +191,7 @@ function build() {
"## Changes",
diff
? `Full patch in \`session.diff\` (same folder).\n\n\`\`\`\n${diff.stat}\n\`\`\``
- : "_no changes on the session branch yet_",
+ : "_no changes yet_",
"",
"## Recent activity",
"```",
diff --git a/.claude/hooks/test/render-status.test.mjs b/.claude/hooks/test/render-status.test.mjs
index 24f66738..e2861fd3 100644
--- a/.claude/hooks/test/render-status.test.mjs
+++ b/.claude/hooks/test/render-status.test.mjs
@@ -153,12 +153,37 @@ describe("render-status", () => {
expect(md).toContain("Button.tsx");
});
+ test("includes in-flight dev-branch work before it is merged", () => {
+ const { app, outDir, run } = setup();
+ const g = (...a) =>
+ spawnSync("git", ["-C", app, ...a], { encoding: "utf8" });
+ g("init", "-q", "-b", "main");
+ g("config", "user.email", "[email protected]");
+ g("config", "user.name", "t");
+ writeFileSync(join(app, "List.tsx"), "no filter\n");
+ g("add", ".");
+ g("commit", "-qm", "base");
+ g("branch", `session-base/${SHORT}`);
+ g("branch", `session/${SHORT}`); // session branch at fork, nothing merged yet
+ // developer's in-flight branch, committed but NOT merged into the session
+ g("checkout", "-q", "-b", `${SHORT}/TASK-001`);
+ writeFileSync(join(app, "List.tsx"), "without-email filter\n");
+ g("add", ".");
+ g("commit", "-qm", "wip");
+ g("checkout", "-q", "main");
+
+ run();
+ const patch = readFileSync(join(outDir, "session.diff"), "utf8");
+ expect(patch).toContain(`in flight: ${SHORT}/TASK-001`);
+ expect(patch).toContain("+without-email filter");
+ });
+
test("omits session.diff when there is no git session branch", () => {
const { outDir, run } = setup();
run();
expect(existsSync(join(outDir, "session.diff"))).toBe(false);
const md = readFileSync(join(outDir, "STATUS.md"), "utf8");
- expect(md).toContain("no changes on the session branch yet");
+ expect(md).toContain("no changes yet");
});
test("is inert when there is no technical progress log", () => {