A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Windows: live diff in the ticker, the diff card, and Claude's final line
Claude122e130bf6a9
diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rsindex d9ec3353..0cd30c1a 100644--- a/windows/src-tauri/src/lib.rs+++ b/windows/src-tauri/src/lib.rs@@ -165,6 +165,33 @@ fn open_in_vscode(path: Option<String>) -> bool {false}+/// The file behind a live diff, if it may be handed to the editor: an existing+/// regular file given by its full path. Anything else — a relative path, a+/// folder, a path `code` could read as an option — goes no further.+fn diff_file(path: &str) -> Option<&std::path::Path> {+ let p = std::path::Path::new(path);+ (p.is_absolute() && p.is_file()).then_some(p)+}++/// The diff card's ↗: opens the edited file in VS Code when `code` is on PATH,+/// otherwise shows its folder. The file itself is never opened by its type —+/// xdg-open or Explorer would run a script that Claude just wrote.+#[tauri::command]+fn open_file_in_vscode(path: String) -> bool {+ let Some(file) = diff_file(&path) else { return false };+ if let Some(code) = platform::find_on_path("code") {+ let mut cmd = Command::new(code);+ cmd.arg(file);+ if platform::no_console(&mut cmd).spawn().is_ok() {+ return true;+ }+ }+ if let Some(folder) = file.parent().filter(|d| d.is_dir()) {+ platform::reveal_folder(&folder.to_string_lossy());+ }+ false+}+#[tauri::command]fn quit_app(app: AppHandle) {app.exit(0);@@ -385,6 +412,7 @@ pub fn run() {reposition,open_url,open_in_vscode,+ open_file_in_vscode,quit_app,hooks_status,hooks_preview,@@ -433,3 +461,26 @@ pub fn run() {.run(tauri::generate_context!()).expect("error while running Coucou");}++#[cfg(test)]+mod tests {+ use super::diff_file;++ #[test]+ fn only_an_existing_file_by_its_full_path_reaches_the_editor() {+ let dir = std::env::temp_dir().join(format!("coucou-diff-file-{}", std::process::id()));+ std::fs::create_dir_all(&dir).unwrap();+ let file = dir.join("edited.ts");+ std::fs::write(&file, "x").unwrap();++ assert!(diff_file(&file.to_string_lossy()).is_some());+ // A folder, a missing file, a relative path or an option never pass.+ assert!(diff_file(&dir.to_string_lossy()).is_none());+ assert!(diff_file(&dir.join("missing.ts").to_string_lossy()).is_none());+ assert!(diff_file("edited.ts").is_none());+ assert!(diff_file("--help").is_none());+ assert!(diff_file("").is_none());++ let _ = std::fs::remove_dir_all(&dir);+ }+}diff --git a/windows/src/core/bridge.ts b/windows/src/core/bridge.tsindex 24aaf55f..1e2c298f 100644--- a/windows/src/core/bridge.ts+++ b/windows/src/core/bridge.ts@@ -55,6 +55,9 @@ export const Bridge = {/** "Open terminal" → opens the folder in VS Code when `code` is on PATH. */openInVSCode: (path: string | null) => call<boolean>("open_in_vscode", { path }),+ /** The diff card's ↗: an existing file, in VS Code; never launched by its type. */+ openFileInVSCode: (path: string) => call<boolean>("open_file_in_vscode", { path }),+quit: () => call<void>("quit_app"),openSettingsWindow: () => call<void>("open_settings_window"),diff --git a/windows/src/core/state.ts b/windows/src/core/state.tsindex 01236b80..bd801c4b 100644--- a/windows/src/core/state.ts+++ b/windows/src/core/state.ts@@ -2,6 +2,7 @@import type { BotEmoteName, BotStateName, IslandMode, IslandViewName } from "./layout";import type { EyeShape } from "../mochi/engine";+import type { FileDiff } from "./diff";export type AgentSource = "claudeCode" | "n8n" | "agent";export type PillBadge = "approval" | "finished" | "error";@@ -19,6 +20,8 @@ export interface AgentTask {miniEye?: EyeShape | null;pillBadge?: PillBadge | null;sessionCwd?: string | null;+ /** Claude's final message after Stop, one line; cleared when a new turn starts. */+ finalLine?: string | null;}export interface ApprovalInfo {@@ -110,6 +113,11 @@ export const DEFAULT_SETTINGS: Settings = {type Listener = () => void;+/** Live diffs kept per pill (oldest dropped first) — same cap as macOS. */+export const MAX_DIFFS_PER_PILL = 50;+/** A pill's diffs are forgotten after an hour without a new one, as on macOS. */+export const DIFF_TTL_MS = 3_600_000;+class AppState {mode: IslandMode = "hidden";view: IslandViewName = "overview";@@ -140,6 +148,12 @@ class AppState {integrations: Record<string, IntegrationInfo> = {};+ /** Per-pill file diffs, in order of reception. Steps carry their ids. */+ sessionDiffs = new Map<string, FileDiff[]>();+ private sessionDiffTimers = new Map<string, number>();+ /** Never reset, so an id can never point at a newer diff than the one tapped. */+ private nextDiffId = 0;+lastActivity = performance.now();settings: Settings = { ...DEFAULT_SETTINGS };@@ -199,6 +213,34 @@ class AppState {this.notify();}+ /** Stores a diff for a pill and returns its id (for the ticker step). */+ appendSessionDiff(pillId: string, diff: FileDiff): number {+ const id = this.nextDiffId++;+ const list = this.sessionDiffs.get(pillId) ?? [];+ list.push({ ...diff, id });+ while (list.length > MAX_DIFFS_PER_PILL) list.shift();+ this.sessionDiffs.set(pillId, list);+ // One timer per pill, re-armed on every diff — nothing polls.+ const prev = this.sessionDiffTimers.get(pillId);+ if (prev != null) window.clearTimeout(prev);+ this.sessionDiffTimers.set(+ pillId,+ window.setTimeout(() => this.clearSessionDiffs(pillId), DIFF_TTL_MS),+ );+ return id;+ }++ findDiff(pillId: string, id: number): FileDiff | null {+ return this.sessionDiffs.get(pillId)?.find((d) => d.id === id) ?? null;+ }++ clearSessionDiffs(pillId: string) {+ const timer = this.sessionDiffTimers.get(pillId);+ if (timer != null) window.clearTimeout(timer);+ this.sessionDiffTimers.delete(pillId);+ this.sessionDiffs.delete(pillId);+ }+/** loadIntegrationTasks() — VS Code always on, the rest opt-in (max 4). */loadIntegrationTasks() {for (const proto of INTEGRATION_AGENTS) {@@ -232,6 +274,7 @@ class AppState {const idx = this.tasks.findIndex((t) => t.id === id);if (idx < 0) return;this.tasks.splice(idx, 1);+ this.clearSessionDiffs(id);if (this.focusId === id) this.focusId = this.tasks[0]?.id ?? "integration_claude";this.notify();}diff --git a/windows/src/island/hooks.ts b/windows/src/island/hooks.tsindex 573e1f63..7b471446 100644--- a/windows/src/island/hooks.ts+++ b/windows/src/island/hooks.ts@@ -4,6 +4,7 @@// terminal (Windows Terminal, VS Code, PowerShell…) and all of them are handled.import { Bridge, onEvent } from "../core/bridge";+import { buildFileDiff, fileName, makeDiffStep, toOneLine } from "../core/diff";import { Sound } from "../core/sound";import { State } from "../core/state";import type { Island } from "./island";@@ -32,8 +33,12 @@ interface HookPayload {message?: string;/** UserPromptSubmit carries `prompt`; `message` belongs to Notification/Stop. */prompt?: string;+ /** Stop: Claude's final answer of the turn (Markdown). */+ last_assistant_message?: string;tool_name?: string;tool_input?: Record<string, unknown>;+ /** Set by the relay when an edit was too big to forward whole (> 256 KB). */+ coucou_diff_truncated?: boolean;/** Optional agent tag: lowercase, digits and hyphens, ≤ 24 chars. */coucou_agent?: string;}@@ -145,6 +150,28 @@ function clearSession() {t.stepIndex = 0;t.name = "VS Code";t.pillBadge = null;+ t.finalLine = null;+}++/** The final message stays on the card until the next turn starts. */+function clearFinalLine(id: string) {+ const t = State.tasks.find((x) => x.id === id);+ if (t) t.finalLine = null;+}++/**+ * PostToolUse of Edit / MultiEdit / Write → a diff stored for the pill and a+ * ticker step with its +N −M counts. Nothing is kept for a pill that does not+ * exist, so a stray event cannot grow memory. An edit the relay had to cut+ * would give wrong counts: the PreToolUse step ("Modifie · file") stands alone.+ */+function recordDiff(agentId: string, payload: HookPayload) {+ if (payload.coucou_diff_truncated) return;+ if (!State.tasks.some((t) => t.id === agentId)) return;+ const diff = buildFileDiff(payload.tool_name ?? "", payload.tool_input ?? {});+ if (!diff) return;+ const id = State.appendSessionDiff(agentId, diff);+ State.appendStep(agentId, makeDiffStep(fileName(diff.path), diff.added, diff.removed, id));}export function registerHookHandlers(island: Island) {@@ -205,6 +232,7 @@ function handleHook(island: Island, payload: HookPayload) {switch (name) {case "SessionStart":ensurePill();+ clearFinalLine(agentId);surface("overview", false);Sound.play("work");break;@@ -212,6 +240,7 @@ function handleHook(island: Island, payload: HookPayload) {case "UserPromptSubmit": {ensurePill();supersedeStop();+ clearFinalLine(agentId);State.updateTask(agentId, "thinking");// The field is `prompt`; reading `message` meant this step was always blank.const asked = payload.prompt ?? payload.message;@@ -223,6 +252,7 @@ function handleHook(island: Island, payload: HookPayload) {case "PreToolUse": {ensurePill();supersedeStop();+ clearFinalLine(agentId);State.updateTask(agentId, "working");const tool = payload.tool_name ?? "Tool";State.appendStep(agentId, stepLabel(tool, payload.tool_input ?? {}));@@ -233,6 +263,7 @@ function handleHook(island: Island, payload: HookPayload) {case "PostToolUse":supersedeStop();State.updateTask(agentId, "working");+ recordDiff(agentId, payload);break;case "PostToolUseFailure":@@ -256,9 +287,16 @@ function handleHook(island: Island, payload: HookPayload) {break;}- case "Stop":+ case "Stop": {State.updateTask(agentId, "finished");- if (payload.message) State.appendStep(agentId, payload.message.slice(0, 60));+ // Claude Code puts the turn's answer in the Stop payload itself, so there is+ // no transcript to read (the relay does not even forward its path).+ const finalText = toOneLine(payload.last_assistant_message ?? payload.message ?? "");+ if (finalText) {+ State.appendStep(agentId, finalText);+ const t = State.tasks.find((x) => x.id === agentId);+ if (t) t.finalLine = finalText;+ }Sound.play("finish");if (focused) surface("finished", true);else State.setPillBadge(agentId, "finished");@@ -276,6 +314,7 @@ function handleHook(island: Island, payload: HookPayload) {}, 5200),);break;+ }case "StopFailure":supersedeStop();@@ -289,6 +328,7 @@ function handleHook(island: Island, payload: HookPayload) {// Nothing left for the timer to do, and it must not outlive the session: a// pill recreated within 5.2 s would be removed by it.cancelStopTimer(agentId);+ State.clearSessionDiffs(agentId);if (isExternalAgent) {State.removeTask(agentId);} else {diff --git a/windows/src/style.css b/windows/src/style.cssindex b2cf6756..6fd4a3b2 100644--- a/windows/src/style.css+++ b/windows/src/style.css@@ -482,6 +482,137 @@ body {text-overflow: ellipsis;}+/* Live diff step: file name, then +N −M right after it (TickerRowView). */+.ticker-row .tick-count {+ flex: 0 0 auto;+ margin-left: -6px; /* no row gap: the counts sit right after the name */+ font: 500 10px var(--mono);+ white-space: pre;+}++.ticker-row .tick-count .plus {+ color: var(--green);+}++.ticker-row .tick-count .minus {+ color: var(--red);+}++/* ── Diff card (overview, left card) — DiffCardView ─────────────────────── */++.diff-card {+ position: relative;+ z-index: 1;+ height: 100%;+ display: flex;+ flex-direction: column;+ padding: 4px 10px 4px 108px;+}++.diff-head {+ display: flex;+ align-items: center;+ gap: 6px;+ padding: 6px 0 3px;+ min-width: 0;+}++.diff-back {+ display: flex;+ align-items: center;+ gap: 3px;+ min-width: 0;+ border: 0;+ background: transparent;+ color: var(--ink);+ cursor: default;+}++.diff-back b {+ font: 600 12px var(--font);+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+}++.diff-head .grow {+ flex: 1 1 auto;+}++.diff-head .tick-count {+ flex: 0 0 auto;+ font: 500 10px var(--mono);+}++.diff-head .plus {+ color: var(--green);+}++.diff-head .minus {+ color: var(--red);+}++.diff-head .icon-btn {+ width: 14px;+ height: 14px;+ flex: 0 0 auto;+}++.diff-note {+ font: 400 10.5px var(--font);+ color: var(--dim-3);+}++.diff-lines {+ flex: 1 1 auto;+ min-height: 0;+ overflow-y: auto;+ scrollbar-width: none;+ user-select: text;+}++.diff-lines::-webkit-scrollbar {+ display: none;+}++.diff-line {+ display: flex;+ min-height: 14px; /* an empty line still takes a row */+ font: 400 10.5px/1.35 var(--mono);+ color: var(--dim-3);+}++.diff-line .sym {+ flex: 0 0 12px;+ color: #454850;+}++.diff-line .txt {+ flex: 1 1 auto;+ min-width: 0;+ white-space: pre;+ overflow: hidden;+ text-overflow: ellipsis;+}++.diff-line.added {+ background: rgba(34, 197, 94, 0.12);+ color: #86efac;+}++.diff-line.added .sym {+ color: var(--green);+}++.diff-line.removed {+ background: rgba(244, 80, 94, 0.12);+ color: #fca5a5;+}++.diff-line.removed .sym {+ color: var(--red);+}+/* Shimmer sweep, 2.2 s — same as TickerShimmerText / ShimmeringText */.shimmer {background: linear-gradient(@@ -588,6 +719,14 @@ body {font: 600 15px var(--font);}+/* Claude's final message on the finished card: one line, never past the card. */+.title.one-line {+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+ min-width: 0;+}+.sub {font: 400 13px var(--font);color: var(--dim);diff --git a/windows/src/views/diff.ts b/windows/src/views/diff.tsnew file mode 100644index 00000000..9fface6e--- /dev/null+++ b/windows/src/views/diff.ts@@ -0,0 +1,66 @@+// Diff card — port of DiffCardView / DiffLineRowView (IslandViewContent.swift).+// Opens in the overview's left card when a diff step of the ticker is clicked.++import { h, svg } from "./dom";+import { ICONS } from "./icons";+import { fileName, type DiffKind, type FileDiff } from "../core/diff";++const STRINGS = {+ back: "Back",+ open: "Open in VS Code",+ tooLarge: "Diff too large",+ noChanges: "No changes",+};++const SYMBOLS: Record<DiffKind, string> = { added: "+", removed: "−", context: " " };++export interface DiffCardHooks {+ dismiss(): void;+ /** ↗ — opens the file in the editor. */+ open(path: string): void;+}++export function buildDiffCard(diff: FileDiff, hooks: DiffCardHooks): HTMLElement {+ const head = h(+ "div",+ { class: "diff-head" },+ h(+ "button",+ { class: "diff-back", title: STRINGS.back, onclick: () => hooks.dismiss() },+ svg(ICONS.chevronLeft, 9, { stroke: 2.4 }),+ h("b", { text: fileName(diff.path) }),+ ),+ h("span", { class: "grow" }),+ diff.added > 0 ? h("span", { class: "tick-count plus", text: `+${diff.added}` }) : null,+ diff.removed > 0 ? h("span", { class: "tick-count minus", text: `−${diff.removed}` }) : null,+ h(+ "button",+ { class: "icon-btn", title: STRINGS.open, onclick: () => hooks.open(diff.path) },+ svg(ICONS.arrowUpRight, 8),+ ),+ );++ const lines = diff.hunks.flatMap((hunk) => hunk.lines);+ let content: HTMLElement;+ if (diff.tooLarge) {+ content = h("div", { class: "diff-note", text: STRINGS.tooLarge });+ } else if (lines.length === 0) {+ content = h("div", { class: "diff-note", text: STRINGS.noChanges });+ } else {+ content = h("div", { class: "diff-lines" });+ const rows = document.createDocumentFragment();+ for (const line of lines) {+ rows.append(+ h(+ "div",+ { class: `diff-line ${line.kind}` },+ h("span", { class: "sym", text: SYMBOLS[line.kind] }),+ h("span", { class: "txt", text: line.text }),+ ),+ );+ }+ content.append(rows);+ }++ return h("div", { class: "diff-card" }, head, content);+}diff --git a/windows/src/views/ticker.ts b/windows/src/views/ticker.tsindex 72b18023..3b0bf3f2 100644--- a/windows/src/views/ticker.ts+++ b/windows/src/views/ticker.ts@@ -7,9 +7,16 @@// and any step that arrived mid-animation was dropped outright. Steps are now// queued instead, so a burst scrolls past rather than vanishing.+//+// Diff steps (see core/diff.ts) render as the file name followed by +N −M, and+// a click on one opens its diff. After Stop the card holds Claude's final+// message: no shimmer, no chevron, the ✓ on every row (TickerRowView isActive+// = false on macOS).+import { h, svg } from "./dom";import { ICONS } from "./icons";import { cubicBezier, clamp, lerp } from "../core/anim";+import { parseDiffStep, type DiffStep } from "../core/diff";import type { AgentTask } from "../core/state";const ROW_H = 22;@@ -20,13 +27,24 @@ const MAX_QUEUE = 4;const COMPLETED_SCALE = 11.5 / 13; // 0.885 — the completed font sizeconst EASE = cubicBezier(0.4, 0, 0.2, 1);+/** The current row's text once the turn is over (TickerRowView staticColor). */+const STILL_CURRENT = "#c9cdd4";+const DIM = "#6b7079";+interface Row {el: HTMLElement;chevron: SVGElement;check: SVGElement;+ body: HTMLElement;shimmer: HTMLElement;dim: HTMLElement;+ /** +N −M, attached to the row only while it shows a diff. */+ counts: HTMLElement;+ plus: HTMLElement;+ minus: HTMLElement;text: string;+ /** Set when the row shows a file diff. */+ diff: DiffStep | null;}function makeRow(): Row {@@ -38,36 +56,70 @@ function makeRow(): Row {const shimmer = h("span", { class: "tick-text shimmer" });const dim = h("span", {class: "tick-text",- style: "position:absolute;left:0;right:0;color:#6b7079",+ // top:0 is where a one-line row already put it; it also keeps a text wider+ // than the row on that line instead of dropping it below the row.+ style: `position:absolute;top:0;left:0;right:0;color:${DIM}`,});+ const body = h("span", { style: "position:relative;flex:1 1 auto;min-width:0" }, shimmer, dim);+ const plus = h("span", { class: "plus" });+ const minus = h("span", { class: "minus" });+ const counts = h("span", { class: "tick-count" }, plus, minus);const el = h("div",{ class: "ticker-row" },h("span", { class: "tick-icon", style: "position:relative" }, chevron, check),- h("span", { style: "position:relative;flex:1 1 auto;min-width:0" }, shimmer, dim),+ body,);- return { el, chevron, check, shimmer, dim, text: "" };+ return { el, chevron, check, body, shimmer, dim, counts, plus, minus, text: "", diff: null };}function setText(row: Row, text: string) {if (row.text === text) return;row.text = text;- row.shimmer.textContent = text;- row.dim.textContent = text;+ const diff = parseDiffStep(text);+ row.diff = diff;+ const shown = diff ? diff.filename : text;+ row.shimmer.textContent = shown;+ row.dim.textContent = shown;+ if (diff) {+ // Filename, then the counts right after it; the name truncates first.+ row.body.style.flex = "0 1 auto";+ row.plus.textContent = diff.added > 0 ? ` +${diff.added}` : "";+ row.minus.textContent = diff.removed > 0 ? ` −${diff.removed}` : "";+ if (row.counts.parentNode !== row.el) row.el.append(row.counts);+ row.el.classList.add("diff");+ } else if (row.el.classList.contains("diff")) {+ // Back to an ordinary step: exactly the row it always was.+ row.body.style.flex = "1 1 auto";+ row.counts.remove();+ row.el.classList.remove("diff");+ }}/*** Places a row. `phase` 0 = current (shimmering, full size), 1 = completed* (dim, shifted up-left and scaled down) — same crossfades as the Swift view.+ * `still` is the finished look: static text, ✓ only, nothing animating.*/-function place(row: Row, y: number, phase: number, opacity: number) {+function place(row: Row, y: number, phase: number, opacity: number, still: boolean) {const scale = 1 - phase * (1 - COMPLETED_SCALE);row.el.style.transform = `translate(${-phase * 10}px, ${y}px) scale(${scale})`;row.el.style.opacity = String(opacity);- row.chevron.style.opacity = String(clamp(1 - phase * 2, 0, 1));- row.check.style.opacity = String(clamp(phase * 2 - 1, 0, 1));- row.shimmer.style.opacity = String(clamp(1 - phase * 1.6, 0, 1));- row.dim.style.opacity = String(clamp(phase * 2 - 0.4, 0, 1));+ if (still) {+ row.chevron.style.opacity = "0";+ row.check.style.opacity = "1";+ row.shimmer.style.opacity = "0";+ row.dim.style.opacity = "1";+ row.dim.style.color = phase < 0.5 ? STILL_CURRENT : DIM;+ } else {+ row.chevron.style.opacity = String(clamp(1 - phase * 2, 0, 1));+ row.check.style.opacity = String(clamp(phase * 2 - 1, 0, 1));+ row.shimmer.style.opacity = String(clamp(1 - phase * 1.6, 0, 1));+ row.dim.style.opacity = String(clamp(phase * 2 - 0.4, 0, 1));+ row.dim.style.color = DIM;+ }+ // An invisible shimmer must not keep the webview repainting.+ row.shimmer.style.animationPlayState = still ? "paused" : "";}export class Ticker {@@ -78,17 +130,27 @@ export class Ticker {private queue: string[] = [];private startMs: number | null = null;private displayIndex = -1;+ /** True once Claude has finished: the final message holds still. */+ private still = false;- constructor() {+ /** `onDiffTap` receives the diff id of a clicked diff row. */+ constructor(onDiffTap?: (diffId: number) => void) {this.el = h("div", { class: "ticker" }, this.a.el, this.b.el, this.c.el);+ // The completed and the current row answer a click, as on macOS; the+ // incoming row is only ever seen mid-slide.+ for (const row of [this.a, this.b]) {+ row.el.addEventListener("click", () => {+ if (row.diff && onDiffTap) onDiffTap(row.diff.diffId);+ });+ }this.rest();}/** The state between transitions: completed on top, current below. */private rest() {- place(this.a, 0, 1, 1);- place(this.b, ROW_H, 0, 1);- place(this.c, ROW_H * 2, 0, 0);+ place(this.a, 0, 1, 1, this.still);+ place(this.b, ROW_H, 0, 1, this.still);+ place(this.c, ROW_H * 2, 0, 0, this.still);}get animating(): boolean {@@ -99,6 +161,13 @@ export class Ticker {const steps = task && task.steps.length > 0 ? task.steps : ["…"];const idx = task ? Math.min(task.stepIndex, steps.length - 1) : -1;+ const still = !!task?.finalLine;+ if (still !== this.still) {+ this.still = still;+ // Mid-slide, the next frame places every row with the new look anyway.+ if (this.startMs == null) this.rest();+ }+// First render: drop straight into place, no animation.if (this.displayIndex < 0) {this.displayIndex = idx;@@ -131,7 +200,7 @@ export class Ticker {if (this.startMs == null) {if (this.queue.length === 0) return;setText(this.c, this.queue[0]);- place(this.c, ROW_H * 2, 0, 0);+ place(this.c, ROW_H * 2, 0, 0, this.still);this.startMs = nowMs;}@@ -139,9 +208,9 @@ export class Ticker {const e = EASE(p);// A leaves upwards and fades a little faster than it moves, as on macOS.- place(this.a, lerp(0, -ROW_H, e), 1, clamp(1 - p * 1.35, 0, 1));- place(this.b, lerp(ROW_H, 0, e), e, 1);- place(this.c, lerp(ROW_H * 2, ROW_H, e), 0, e);+ place(this.a, lerp(0, -ROW_H, e), 1, clamp(1 - p * 1.35, 0, 1), this.still);+ place(this.b, lerp(ROW_H, 0, e), e, 1, this.still);+ place(this.c, lerp(ROW_H * 2, ROW_H, e), 0, e, this.still);if (p < 1) return;diff --git a/windows/src/views/views.ts b/windows/src/views/views.tsindex ac0ac7b6..96104c51 100644--- a/windows/src/views/views.ts+++ b/windows/src/views/views.ts@@ -11,6 +11,9 @@ import { createMiniBot, pruneMiniBots } from "../mochi/minibots";import { buildPrompt } from "./chat";import { buildChoose, buildUpload, buildUploading } from "./upload";import { renderIntegrationCard, type IntegrationCardHooks } from "./integrations";+import { buildDiffCard } from "./diff";+import { lastTextStep } from "../core/diff";+import { Bridge } from "../core/bridge";export interface ViewActions {setView(v: IslandViewName): void;@@ -117,7 +120,18 @@ export function buildHeader(actions: ViewActions): ViewHost {// ── Overview ──────────────────────────────────────────────────────────────────function buildOverview(actions: ViewActions): ViewHost {- const ticker = new Ticker();+ /** The diff open in the left card (a FileDiff id), as activeDiffId on macOS. */+ let activeDiffId: number | null = null;+ const closeDiff = () => {+ if (activeDiffId == null) return;+ activeDiffId = null;+ State.notify();+ };+ const ticker = new Ticker((diffId) => {+ actions.blip();+ activeDiffId = diffId;+ State.notify();+ });const who = h("div", { class: "who" });const tickerBody = h("div", { class: "card-body" }, who, ticker.el);const leftBody = h("div", { class: "left-body" });@@ -138,9 +152,26 @@ function buildOverview(actions: ViewActions): ViewHost {let pillIds = "";let detailOpen = false;let lastFocus: string | null = null;- let mode: "ticker" | "card" | null = null;+ let mode: "ticker" | "card" | "diff" | null = null;let cardKey = "";+ // Leaving the overview or folding the island closes the diff, as on macOS.+ State.subscribe(() => {+ if (activeDiffId != null && (State.view !== "overview" || State.mode !== "expanded")) {+ activeDiffId = null;+ }+ });+ // Escape steps back out of the diff before it closes the island.+ window.addEventListener(+ "keydown",+ (e) => {+ if (e.key !== "Escape" || activeDiffId == null || State.view !== "overview") return;+ e.stopImmediatePropagation();+ closeDiff();+ },+ true,+ );+const hooks: IntegrationCardHooks = {get detailOpen() {return detailOpen;@@ -168,6 +199,7 @@ function buildOverview(actions: ViewActions): ViewHost {if (task?.id !== lastFocus) {lastFocus = task?.id ?? null;detailOpen = false;+ activeDiffId = null;cardKey = "";mode = null;}@@ -177,7 +209,25 @@ function buildOverview(actions: ViewActions): ViewHost {const sessionActive =task?.id === "integration_claude" && (task.state !== "idle" || task.steps.length > 0);- if (task && sessionActive) {+ // A diff that has since been dropped (cap, expiry, session end) just closes.+ const diff = task && activeDiffId != null ? State.findDiff(task.id, activeDiffId) : null;+ if (!diff) activeDiffId = null;++ if (task && diff) {+ const key = `diff~${task.id}~${diff.id}`;+ if (key !== cardKey) {+ cardKey = key;+ mode = "diff";+ clear(leftBody);+ leftBody.append(buildDiffCard(diff, {+ dismiss: () => {+ actions.blip();+ closeDiff();+ },+ open: (path) => void Bridge.openFileInVSCode(path),+ }));+ }+ } else if (task && sessionActive) {if (mode !== "ticker") {clear(leftBody);leftBody.append(tickerBody);@@ -212,7 +262,7 @@ function buildOverview(actions: ViewActions): ViewHost {}}- jump.style.display = detailOpen ? "none" : "";+ jump.style.display = detailOpen || mode === "diff" ? "none" : "";const others = State.otherTasks.slice(0, 4);const pillKey = others.map((t) => `${t.id}:${t.pillBadge ?? ""}`).join("|");@@ -330,7 +380,7 @@ function buildQuestion(): ViewHost {clear(who);who.append(agentWho(State.focusTask, "Claude Code is asking a question"));const task = State.focusTask;- title.textContent = task?.steps.at(-1) ?? "Claude needs an answer.";+ title.textContent = (task && lastTextStep(task.steps)) ?? "Claude needs an answer.";clear(row);row.append(h("div", { class: "sub", text: "Answer in your terminal — Coucou can't reply for you yet." }));},@@ -355,7 +405,7 @@ function buildError(actions: ViewActions): ViewHost {clear(who);who.append(agentWho(task, task?.source === "n8n" ? "n8n" : "Claude Code"));title.textContent = task?.source === "n8n" ? "Workflow stopped." : "Session stopped on an error.";- detail.textContent = task?.steps.at(-1) ?? "No detail available.";+ detail.textContent = (task && lastTextStep(task.steps)) ?? "No detail available.";},};}@@ -364,7 +414,7 @@ function buildError(actions: ViewActions): ViewHost {function buildFinished(actions: ViewActions): ViewHost {const who = h("div");- const title = h("div", { class: "title" });+ const title = h("div", { class: "title one-line" });const row = h("div", { class: "actions" },btn("Open terminal", "primary", () => actions.openTerminal()),btn("OK", "secondary", () => actions.collapse()),@@ -375,7 +425,9 @@ function buildFinished(actions: ViewActions): ViewHost {sync() {clear(who);who.append(agentWho(State.focusTask, "Claude Code finished"));- title.textContent = State.focusTask?.steps.at(-1) ?? "Session finished";+ // Claude's final message, else the last step that is not a diff (FinishedView).+ const task = State.focusTask;+ title.textContent = task?.finalLine || (task && lastTextStep(task.steps)) || "Session finished";},};}diff --git a/windows/tests/livediff.test.mjs b/windows/tests/livediff.test.mjsnew file mode 100644index 00000000..4c330cef--- /dev/null+++ b/windows/tests/livediff.test.mjs@@ -0,0 +1,163 @@+// Live diff and the finished line, end to end through the hook handler: file+// edits become ticker steps with their diff stored (and bounded), and Stop leaves+// Claude's final message on the card until the next turn.++import { afterEach, beforeEach, mock, test } from "node:test";+import assert from "node:assert/strict";+import { emit } from "./tauri.mjs";+import { registerHookHandlers } from "../src/island/hooks.ts";+import { DEFAULT_SETTINGS, DIFF_TTL_MS, MAX_DIFFS_PER_PILL, State } from "../src/core/state.ts";+import { parseDiffStep } from "../src/core/diff.ts";++const CLAUDE = "integration_claude";++const island = { alert() {}, setView() {}, reveal() {}, dropPin() {} };+registerHookHandlers(island);++const hook = (payload) => emit("hook", payload);+const task = (id = CLAUDE) => State.tasks.find((t) => t.id === id);+const diffs = (id = CLAUDE) => State.sessionDiffs.get(id) ?? [];++const edit = (extra = {}) =>+ hook({+ hook_event_name: "PostToolUse",+ cwd: "/p/proj",+ tool_name: "Edit",+ tool_input: { file_path: "/p/proj/src/app.ts", old_string: "a\nb\n", new_string: "a\nc\nd\n" },+ ...extra,+ });++beforeEach(() => {+ mock.timers.enable({ apis: ["setTimeout"] });+ for (const id of [...State.sessionDiffs.keys()]) State.clearSessionDiffs(id);+ State.tasks = [];+ State.focusId = null;+ State.mode = "hidden";+ State.view = "overview";+ State.paused = false;+ State.isPinned = false;+ State.pendingApproval = null;+ State.settings = { ...DEFAULT_SETTINGS };+ State.loadIntegrationTasks();+});++afterEach(() => {+ mock.timers.runAll();+ mock.timers.reset();+});++// ── Live diff ─────────────────────────────────────────────────────────────────++test("a finished Edit adds a diff step with its counts, and keeps the diff", () => {+ edit();+ const step = parseDiffStep(task().steps.at(-1));+ assert.deepEqual({ ...step, diffId: undefined }, { filename: "app.ts", added: 2, removed: 1, diffId: undefined });+ const diff = State.findDiff(CLAUDE, step.diffId);+ assert.equal(diff.path, "/p/proj/src/app.ts");+ assert.ok(diff.hunks.length > 0);+});++test("Write and MultiEdit are diffed too; other tools and PreToolUse are not", () => {+ hook({ hook_event_name: "PostToolUse", tool_name: "Write", tool_input: { file_path: "C:\\p\\new.md", content: "x\ny\n" } });+ assert.deepEqual(parseDiffStep(task().steps.at(-1)).filename, "new.md");+ hook({+ hook_event_name: "PostToolUse",+ tool_name: "MultiEdit",+ tool_input: { file_path: "/p/m.ts", edits: [{ old_string: "a", new_string: "b" }, { old_string: "c", new_string: "d" }] },+ });+ const multi = parseDiffStep(task().steps.at(-1));+ assert.deepEqual([multi.added, multi.removed], [2, 2]);++ const before = task().steps.length;+ hook({ hook_event_name: "PostToolUse", tool_name: "Bash", tool_input: { command: "ls" } });+ hook({ hook_event_name: "PreToolUse", tool_name: "Edit", tool_input: { file_path: "/p/a.ts", old_string: "a", new_string: "b" } });+ assert.equal(task().steps.length, before + 1); // only the PreToolUse label+ assert.equal(parseDiffStep(task().steps.at(-1)), null);+ assert.equal(diffs().length, 2);+});++test("an edit with no change, or one the relay had to cut, adds no diff", () => {+ hook({ hook_event_name: "PostToolUse", tool_name: "Edit", tool_input: { file_path: "/p/a.ts", old_string: "same", new_string: "same" } });+ edit({ coucou_diff_truncated: true });+ assert.deepEqual(task().steps, []);+ assert.equal(diffs().length, 0);+});++test("diffs are capped per pill, oldest first, and ids stay unique", () => {+ for (let i = 0; i < MAX_DIFFS_PER_PILL + 5; i++) edit();+ const kept = diffs();+ assert.equal(kept.length, MAX_DIFFS_PER_PILL);+ assert.equal(new Set(kept.map((d) => d.id)).size, MAX_DIFFS_PER_PILL);+ // The ticker keeps fewer steps than diffs; every step still finds its diff.+ for (const s of task().steps) assert.ok(State.findDiff(CLAUDE, parseDiffStep(s).diffId));+ // The first ones are gone: tapping their step would be a no-op.+ assert.equal(State.findDiff(CLAUDE, kept[0].id - 1), null);+});++test("diffs are forgotten an hour after the last one, and at the end of the session", () => {+ edit();+ mock.timers.tick(DIFF_TTL_MS - 1000);+ edit(); // re-arms the hour+ mock.timers.tick(2000);+ assert.equal(diffs().length, 2);+ mock.timers.tick(DIFF_TTL_MS);+ assert.equal(diffs().length, 0);++ edit();+ hook({ hook_event_name: "SessionEnd", cwd: "/p/proj" });+ assert.equal(diffs().length, 0);+});++test("an agent pill's diffs go with the pill", () => {+ hook({ hook_event_name: "PreToolUse", coucou_agent: "gemini", tool_name: "Edit", tool_input: { file_path: "/p/a.ts" } });+ edit({ coucou_agent: "gemini" });+ assert.equal(diffs("agent_gemini").length, 1);+ hook({ hook_event_name: "SessionEnd", coucou_agent: "gemini" });+ assert.equal(task("agent_gemini"), undefined);+ assert.equal(State.sessionDiffs.has("agent_gemini"), false);+ // An event for a pill that does not exist stores nothing.+ edit({ coucou_agent: "ghost" });+ assert.equal(State.sessionDiffs.has("agent_ghost"), false);+});++// ── Final message ─────────────────────────────────────────────────────────────++test("Stop shows the first paragraph of Claude's final message, on one line", () => {+ hook({+ hook_event_name: "Stop",+ last_assistant_message: "**Done.** Fixed the `parser` and\nadded tests.\n\n## Details\n- a\n- b",+ });+ const line = "Done. Fixed the parser and added tests.";+ assert.equal(task().finalLine, line);+ assert.equal(task().steps.at(-1), line);+});++test("Stop falls back to `message`, and adds nothing when both are empty", () => {+ hook({ hook_event_name: "Stop", message: "All good." });+ assert.equal(task().finalLine, "All good.");+ hook({ hook_event_name: "UserPromptSubmit", prompt: "again" });+ hook({ hook_event_name: "Stop", last_assistant_message: "\n\n---\n" });+ assert.equal(task().finalLine, null);+ assert.equal(task().steps.at(-1), "again");+});++test("a long final message is kept to 200 characters", () => {+ hook({ hook_event_name: "Stop", last_assistant_message: "word ".repeat(100) });+ assert.ok(task().finalLine.length <= 200);+});++for (const [what, event] of [+ ["a new prompt", { hook_event_name: "UserPromptSubmit", prompt: "next" }],+ ["a tool starting", { hook_event_name: "PreToolUse", tool_name: "Bash", tool_input: { command: "ls" } }],+ ["a new session", { hook_event_name: "SessionStart" }],+ ["the end of the session", { hook_event_name: "SessionEnd" }],+]) {+ test(`the final message stays until ${what}`, () => {+ hook({ hook_event_name: "Stop", last_assistant_message: "Done." });+ mock.timers.tick(5200); // back to idle: the line is still there+ assert.equal(task().state, "idle");+ assert.equal(task().finalLine, "Done.");+ hook({ cwd: "/p/proj", ...event });+ assert.equal(task().finalLine, null);+ });+}