diff --git a/apps/desktop/e2e/keyboard-answers.spec.ts b/apps/desktop/e2e/keyboard-answers.spec.ts index c097b8ef..a58cbc73 100644 --- a/apps/desktop/e2e/keyboard-answers.spec.ts +++ b/apps/desktop/e2e/keyboard-answers.spec.ts @@ -94,6 +94,8 @@ test("Jump to latest from the keyboard hands focus to the message box at the bot await items(page, "approval").last().getByRole("button", { name: "Approve", exact: true }).click(); await expect(currentRow(page)).toHaveAttribute("data-status", "idle"); } + // A finished turn is short; add more if three do not yet overflow the window. + await ensureScrollable(); await tid(page, "turn-label").last().focus(); await expect(async () => { await page.keyboard.press("PageUp"); @@ -107,7 +109,7 @@ test("Jump to latest from the keyboard hands focus to the message box at the bot /** Enough finished turns for the transcript to scroll, whatever ran before (a failed test restarts the app). */ async function ensureScrollable() { - for (let turn = 0; turn < 4 && !(await tid(page, "transcript").evaluate((el) => el.scrollHeight > el.clientHeight + 300).catch(() => false)); turn++) { + for (let turn = 0; turn < 8 && !(await tid(page, "transcript").evaluate((el) => el.scrollHeight > el.clientHeight + 300).catch(() => false)); turn++) { if (!(await tid(page, "composer-input").count())) await page.keyboard.press("Meta+n"); await tid(page, "composer-input").focus(); await page.keyboard.type(`Turn ${turn} for scrolling`); diff --git a/apps/desktop/e2e/layout.spec.ts b/apps/desktop/e2e/layout.spec.ts index 2781bfce..e25b1b7b 100644 --- a/apps/desktop/e2e/layout.spec.ts +++ b/apps/desktop/e2e/layout.spec.ts @@ -253,14 +253,21 @@ test.describe("Phase 6 · transcript", () => { test("column, bubble, turn header and prose match the reference", async () => { await changesHidden(); const c = await box(tid(page, "composer-box")); - const header = await box(tid(page, "turn-label").first()); + // The column is the turn header's content box; its label is a small inline line, no longer the column's width. + const header = await tid(page, "turn-header").first().evaluate((el) => { + const r = el.getBoundingClientRect(); + const s = getComputedStyle(el); + const left = parseFloat(s.paddingLeft); + return { x: r.x + left, width: r.width - left - parseFloat(s.paddingRight) }; + }); expect(Math.abs(header.x - (c.x + 11))).toBeLessThanOrEqual(1); expect(Math.abs(header.width - (c.width - 22))).toBeLessThanOrEqual(1); const label = tid(page, "turn-label").first(); - expect(await css(label, "font-size")).toBe("14px"); + expect(await css(label, "font-size")).toBe("13px"); expect(await css(label, "font-weight")).toBe("500"); expect(await css(label, "color")).toBe("rgb(170, 165, 184)"); - expect(await css(label, "border-bottom-color")).toBe("rgb(43, 51, 71)"); + expect(await css(label, "border-bottom-width")).toBe("0px"); + expect((await box(label)).height).toBe(26); const bubble = items(page, "user").first().locator('[data-testid="item-text"]'); expect(await css(bubble, "background-color")).toBe("rgb(27, 34, 50)"); expect(await css(bubble, "border-top-left-radius")).toBe("8px"); diff --git a/apps/desktop/e2e/transcript-rows.spec.ts b/apps/desktop/e2e/transcript-rows.spec.ts new file mode 100644 index 00000000..2d6cd128 --- /dev/null +++ b/apps/desktop/e2e/transcript-rows.spec.ts @@ -0,0 +1,162 @@ +import { test, expect, type ElectronApplication, type Locator, type Page } from "@playwright/test"; +import fs from "node:fs"; +import path from "node:path"; +import { currentRow, items, launch, seedHome, tid } from "./support"; + +/** + * The transcript as one quiet column: a turn is one element, its status is a small line with a dot while + * it is live, work is a list of 34 px rows with an icon tile, an answered approval is a receipt row, reply + * actions show for the turn pointed at, and Jump to latest is a square icon button that keeps its name. + */ +let app: ElectronApplication; +let page: Page; +let home: string; +let repo: string; + +const at = "2026-11-16T10:00:00.000Z"; +const long = Array.from({ length: 60 }, (_, i) => `Paragraph ${i}. ${"text ".repeat(30)}`).join("\n\n"); +const row = (id: string) => page.locator(`[data-testid="thread-row"][data-thread-id="${id}"]`); +const height = async (locator: Locator) => Math.round((await locator.boundingBox())!.height); + +test.beforeAll(async () => { + ({ home, repo } = seedHome()); + const statePath = path.join(home, "app/state.json"); + const state = JSON.parse(fs.readFileSync(statePath, "utf8")); + state.threads = ["rows-saved", "rows-two-turns"].map((id) => ({ id, projectId: "p1", title: id, createdAt: at, updatedAt: at, cwd: repo, backend: "mock", model: "mock", mode: "chat", plan: false, status: "idle" })); + fs.writeFileSync(statePath, JSON.stringify(state)); + // A turn that never answered: its work stays in view. The approval was saved mid-delivery. + fs.writeFileSync(path.join(home, "app/threads/rows-saved.json"), JSON.stringify([ + { id: "u", kind: "user", text: "Run the checks", at }, + { id: "command", kind: "tool", name: "shell", title: "$ npm test", args: { command: "npm test" }, output: "ok", status: "done", ok: true, at }, + { id: "mystery", kind: "tool", name: "mystery_tool", title: "mystery_tool", args: {}, status: "done", ok: true, at }, + { id: "stopped", kind: "approval", question: "Allow the first push?", answer: "no", withdrawn: "stopped", at }, + { id: "sending", kind: "approval", question: "Allow the deploy?", detail: "deploy --prod", answer: "yes", delivery: "sending", at }, + ])); + fs.writeFileSync(path.join(home, "app/threads/rows-two-turns.json"), JSON.stringify([ + { id: "u1", kind: "user", text: "First question", at }, + { id: "a1", kind: "assistant", text: long, at }, + { id: "u2", kind: "user", text: "Second question", at }, + { id: "a2", kind: "assistant", text: "Second answer.", at }, + ])); + ({ app, page } = await launch(home)); +}); + +test.afterAll(async () => { + await app?.close(); + fs.rmSync(home, { recursive: true, force: true }); + fs.rmSync(repo, { recursive: true, force: true }); +}); + +test("saved work reads as rows: a verb for a command, an icon for every tool, and receipts for closed approvals", async () => { + await row("rows-saved").click(); + const command = items(page, "tool").filter({ hasText: "$ npm test" }); + await expect(tid(command, "tool-verb")).toHaveText("Ran"); + await expect(tid(command, "tool-summary")).toHaveText("$ npm test"); + await expect(tid(command, "item-toggle")).toHaveAttribute("aria-label", "Done: $ npm test"); + expect(await height(tid(command, "item-toggle"))).toBe(34); + const tile = command.locator(".tool-icon"); + expect(await tile.boundingBox()).toMatchObject({ width: 22, height: 22 }); + await expect(tile.locator("svg")).toHaveAttribute("data-icon", "terminal"); + // A tool the app has no picture for keeps its summary, with the generic icon and no verb. + const mystery = items(page, "tool").filter({ hasText: "mystery_tool" }); + await expect(tid(mystery, "tool-verb")).toHaveCount(0); + await expect(mystery.locator(".tool-icon svg")).toHaveAttribute("data-icon", "shapes"); + + // A request that closed unanswered is a neutral row with the reason, never "Denied". + const stopped = items(page, "approval").first(); + await expect(stopped).toHaveClass(/approval-receipt/); + await expect(stopped).toHaveClass(/\bneutral\b/); + await expect(tid(stopped, "approval-answer")).toHaveText("Not answered — the turn was stopped"); + await expect(stopped.getByRole("button", { name: "Approve", exact: true })).toHaveCount(0); + // An answer saved mid-delivery is uncertain after a restart: a warning row that never reads as answered. + const uncertain = items(page, "approval").last(); + await expect(uncertain).toHaveClass(/\bwarn\b/); + await expect(uncertain).toHaveAttribute("data-answered", "false"); + await expect(tid(uncertain, "approval-answer")).toHaveText("Delivery uncertain — not resent"); + await expect(tid(uncertain, "answer-note")).toHaveText("Modex stopped before it could confirm the agent received this answer."); + expect(await height(uncertain.locator(".receipt-head"))).toBe(34); + // The row opens to the request it answered. + const toggle = tid(uncertain, "item-toggle"); + await expect(toggle).toHaveAccessibleName("Request details"); + await expect(toggle).toHaveAttribute("aria-expanded", "false"); + await toggle.click(); + await expect(toggle).toHaveAttribute("aria-expanded", "true"); + await expect(tid(uncertain, "item-body")).toContainText("Allow the deploy?"); + await expect(tid(uncertain, "item-body")).toContainText("deploy --prod"); +}); + +test("reply actions show for the newest turn, and for an older one only when it is pointed at or holds focus", async () => { + await row("rows-two-turns").click(); + const turns = tid(page, "turn"); + await expect(turns).toHaveCount(2); + await expect(items(page, "assistant").last()).toContainText("Second answer."); + const older = tid(turns.first(), "message-actions"); + const newest = tid(turns.last(), "message-actions"); + await expect(newest).toHaveCSS("opacity", "1"); + await expect(older).toHaveCSS("opacity", "0"); + await tid(turns.first(), "item-text").hover(); + await expect(older).toHaveCSS("opacity", "1"); + await row("rows-two-turns").hover(); + await expect(older).toHaveCSS("opacity", "0"); + // Keyboard only: the actions are still in the tab order, and show once one of them has focus. + await tid(older, "message-copy").focus(); + await expect(older).toHaveCSS("opacity", "1"); +}); + +test("Jump to latest is a square icon button that keeps its name and returns to the bottom", async () => { + await row("rows-two-turns").click(); + const transcript = tid(page, "transcript"); + await expect(items(page, "assistant").last()).toContainText("Second answer."); + await transcript.evaluate((el) => { el.scrollTop = 0; el.dispatchEvent(new Event("scroll")); }); + const jump = tid(page, "jump-latest"); + await expect(jump).toBeVisible(); + expect(await jump.boundingBox()).toMatchObject({ width: 32, height: 32 }); + await expect(jump).toHaveAccessibleName("Jump to latest"); + await expect(jump.locator("svg")).toHaveAttribute("data-icon", "arrow-down"); + await jump.click(); + await expect(jump).toHaveCount(0); + expect(await transcript.evaluate((el) => el.scrollHeight - el.scrollTop - el.clientHeight)).toBeLessThanOrEqual(80); +}); + +test("a live turn is one element with a status dot; answering turns the approval into a receipt row", async () => { + await page.keyboard.press("Meta+n"); + await tid(page, "composer-input").fill("Add a contributing guide"); + await page.keyboard.press("Meta+Enter"); + const card = items(page, "approval").first(); + await expect(card.getByRole("button", { name: "Approve", exact: true })).toBeVisible({ timeout: 15_000 }); + await expect(currentRow(page)).toHaveAttribute("data-status", "waiting"); + // One element holds the message, the status line and the work. + const turn = tid(page, "turn"); + await expect(turn).toHaveCount(1); + await expect(turn).toHaveAttribute("data-live", "true"); + await expect(turn.locator('[data-testid="item"][data-item-kind="user"]')).toHaveCount(1); + await expect(turn.locator('[data-testid="item"][data-item-kind="approval"]')).toHaveCount(1); + // Waiting on the person: the dot is steady, and the label says what it waits for. + const header = tid(turn, "turn-header"); + await expect(header).toHaveClass(/\bwaiting\b/); + await expect(header.locator(".turn-dot")).toHaveCount(1); + await expect(header.locator(".turn-dot")).toHaveCSS("animation-name", "none"); + await expect(tid(header, "turn-label")).toHaveText(/^Waiting for approval · \d+s$/); + + await card.getByRole("button", { name: "Approve", exact: true }).click(); + await expect(tid(card, "approval-answer")).toHaveText("Approved"); + await expect(card).toHaveClass(/approval-receipt/); + await expect(card).toHaveClass(/\ballowed\b/); + // Main records that this window gave the answer; the row says so. + await expect(tid(card, "receipt-meta")).toHaveText("by you"); + await expect(card.getByRole("button", { name: "Approve", exact: true })).toHaveCount(0); + await expect(currentRow(page)).toHaveAttribute("data-status", "idle"); + // Finished: no dot, and the status line is the toggle for the folded work. + await expect(turn).toHaveAttribute("data-live", "false"); + await expect(header).not.toHaveClass(/\bwaiting\b/); + await expect(header.locator(".turn-dot")).toHaveCount(0); + const label = tid(header, "turn-label"); + await expect(label).toHaveText(/^Worked for \d+s$/); + await expect(label).toHaveAttribute("aria-expanded", "false"); + await expect(card).toBeHidden(); + await label.click(); + await expect(card).toBeVisible(); + expect(await height(card.locator(".receipt-head"))).toBe(34); + await tid(card, "item-toggle").click(); + await expect(tid(card, "item-body")).toContainText("Allow add CONTRIBUTING.md?"); +}); diff --git a/apps/desktop/src/renderer/components/ThreadView.tsx b/apps/desktop/src/renderer/components/ThreadView.tsx index d16f1603..b1955e01 100644 --- a/apps/desktop/src/renderer/components/ThreadView.tsx +++ b/apps/desktop/src/renderer/components/ThreadView.tsx @@ -1,8 +1,8 @@ -import { toolStatusLabel, toolSummary } from "../../shared/tool-summary"; +import { toolKind, toolStatusLabel, toolSummary, toolVerb, type ToolKind } from "../../shared/tool-summary"; import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; import type { AnswerResult, ApprovalPolicy, ApprovalReceipt, BackendId, FollowUp, Mode, ModelInfo, Project, Thread, ThreadItem, ThreadPatch, TurnFailure, TurnFix } from "../../shared/types"; import { failureReport } from "../../shared/failures"; -import { askedBecause, jevNotConsulted, receiptVia } from "../../shared/approval-receipt"; +import { answeredApproval, askedBecause, jevNotConsulted, receiptVia } from "../../shared/approval-receipt"; import { safeHref } from "../../shared/inline"; import { answerNote } from "../../shared/human-requests"; import { parseWebSearch, splitSources, type SourceLink, type WebSearch } from "../../shared/sources"; @@ -14,7 +14,7 @@ import { AttachmentChips } from "./Attachments"; import { Composer } from "./Composer"; import type { LocalMenu } from "./ModelMenu"; import { DeferMarkdown, Markdown } from "./Markdown"; -import { Icon } from "./ui/Icon"; +import { Icon, type IconName } from "./ui/Icon"; import { ErrorNotice } from "./ui/ErrorNotice"; import { TurnContent, groupTurns } from "./transcript/TurnContent"; import { readerStateFor, ReaderStateContext, useExpansionState } from "./transcript/reader-state"; @@ -244,7 +244,7 @@ export function ThreadView({ contextControls, contextBusy, thread, project, item const held = document.activeElement === e.currentTarget; jumpToLatest(); if (held) inputRef.current?.focus({ preventScroll: true }); - }}>Jump to latest} + }} title="Jump to latest">Jump to latest} {!busy && !thread.retired && items.at(-1)?.kind === "user" && !attachmentActions.sending &&

This message is saved. Start its coding turn when you are ready.

@@ -444,21 +444,16 @@ function FailureItem({ failure, onFix, onRetry }: { failure: TurnFailure; onFix: type ApprovalEntry = Extract; -/** A card closed without anyone answering it says why, rather than "Denied". */ -const WITHDRAWN: Record, string> = { - native: "Withdrawn — the agent no longer needs an answer", - stopped: "Not answered — the turn was stopped", - ended: "Not answered — the turn ended first", -}; - /** - * An approval. A rule's allow or refusal is a compact receipt row (the turn never waited on it); - * anything a human answers is today's card, plus one line saying why when a rule sent it here. + * An approval. While it waits it is a card with the answer buttons. Once a person has answered it, or it closed + * unanswered, it is one receipt row that expands to the request; a rule's allow or refusal is the same kind of + * row (the turn never waited on it). */ function ApprovalItem({ item, onAnswer, onPolicy }: { item: ApprovalEntry; onAnswer: Props["onAnswer"]; onPolicy?: (p: ApprovalPolicy) => void }) { const card = useRef(null); + const [open, setOpen] = useState(false); // The answer buttons go away once pressed. Someone answering from the keyboard or VoiceOver - // lands on the answer line ("Sending decision…", then "Approved") instead of the page body. + // lands on the answer ("Sending decision…", then "Approved") instead of the page body. const refocus = useRef(false); const answer = (value: "yes" | "no" | "always") => { refocus.current = !!card.current?.contains(document.activeElement); @@ -471,28 +466,47 @@ function ApprovalItem({ item, onAnswer, onPolicy }: { item: ApprovalEntry; onAns }, [item.answer]); const r = item.decidedBy; if (r && item.answer && r.decision !== "ask") return ; + const done = answeredApproval(item); + const answered = item.answer && (!item.delivery || item.delivery === "sent") ? "true" : "false"; + if (done) { + const note = item.withdrawn ? null : answerNote(item); + // The answer word takes focus after an answer, so it sits beside the toggle, not inside it. + return ( +
+
+ + + {done.text} {item.title ?? item.question} + + {done.by && {done.by}} + +
+ {note &&
{note}
} + {open && ( +
+
{item.question}
+ {r?.decision === "ask" &&
{askedBecause(r)}
} + {item.detail &&
{item.detail}
} +
+ )} +
+ ); + } return ( -
+
⚠ {item.question}
{r?.decision === "ask" &&
{askedBecause(r)}
} {item.detail &&
{item.detail}
} - {item.answer ? ( - <> -
{item.delivery === "uncertain" ? "Delivery uncertain — not resent" : item.delivery === "sending" ? "Sending decision…" : item.withdrawn ? WITHDRAWN[item.withdrawn] : item.answer === "yes" ? "Approved" : item.answer === "always" ? "Approved — always for this command" : "Denied"}
- {!item.withdrawn && answerNote(item) &&
{answerNote(item)}
} - - ) : ( -
- - {item.canAlways !== false && } - {onPolicy && } - {onPolicy && } - -
- )} +
+ + {item.canAlways !== false && } + {onPolicy && } + {onPolicy && } + +
); } @@ -506,7 +520,7 @@ function ApprovalReceiptRow({ item, receipt: r }: { item: ApprovalEntry; receipt return (
; } /** When a finished turn ended: its last item's time, plus that item's own duration when it has one. */ @@ -103,7 +104,10 @@ export function formatElapsed(ms: number): string { return `${Math.floor(m / 60)}h ${m % 60}m`; } -/** "Working for 7s" (live, ticking) or "Worked for 1m 36s" above a rule, between a message and the agent's work. */ +/** + * "Working for 7s" (live, ticking) or "Worked for 1m 36s", between a message and the agent's work. A live turn + * leads with a dot: pulsing while the agent works, steady while it waits on the person. + */ function TurnHeader({ start, end, status, asking, expanded, controls, toggleRef, onToggle }: { start: string; end?: number; status?: Thread["status"]; asking?: boolean; expanded?: boolean; controls?: string; toggleRef?: RefObject; onToggle?: () => void }) { const live = end === undefined; const [now, setNow] = useState(() => Date.now()); @@ -115,8 +119,10 @@ function TurnHeader({ start, end, status, asking, expanded, controls, toggleRef, const elapsed = formatElapsed((live ? now : end) - Date.parse(start)); const label = !live ? `Worked for ${elapsed}` : status === "waiting" ? `${asking ? "Waiting for your answer" : "Waiting for approval"} · ${elapsed}` : `Working for ${elapsed}`; return ( -
- {expanded === undefined ? {label} : } +
+ {expanded === undefined + ? {live && + : }
); } diff --git a/apps/desktop/src/renderer/components/ui/Icon.tsx b/apps/desktop/src/renderer/components/ui/Icon.tsx index 374abe48..43927bc7 100644 --- a/apps/desktop/src/renderer/components/ui/Icon.tsx +++ b/apps/desktop/src/renderer/components/ui/Icon.tsx @@ -48,6 +48,7 @@ const PATHS = { "arrow-left": "M12.5 8h-9M7 4.5L3.5 8 7 11.5", "arrow-right": "M3.5 8h9M9 4.5L12.5 8 9 11.5", "arrow-up": "M8 12.5v-9M4.5 7L8 3.5 11.5 7", + "arrow-down": "M8 3.5v9M4.5 9L8 12.5 11.5 9", download: "M8 2.5v7M5 6.5l3 3 3-3M3 10v3h10v-3", stop: "M5 5h6v6H5z", branch: "M5 5.5v5M11 6.5c0 2.5-6 1.5-6 4M5 2.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zM5 10.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3zM11 3.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3z", @@ -73,6 +74,7 @@ const PATHS = { "thumb-down": "M5.5 9l2.5 4.5a1.3 1.3 0 0 0 1.5-1.5L9 9.5h3.2a1.2 1.2 0 0 0 1.2-1.5l-1-4a1.5 1.5 0 0 0-1.4-1H5.5zM5.5 9h-3V3h3", agents: "M3.5 5.5h9a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1h-9a1 1 0 0 1-1-1v-5a1 1 0 0 1 1-1zM8 5.5V3M6 8.5v1M10 8.5v1", alert: "M8 2.5l6 10.5H2zM8 6.5v3M8 11.25h.01", + thought: "M6.25 11.5h3.5M7 13.5h2M8 2.5a3.75 3.75 0 0 0-2.3 6.7c.35.3.55.7.55 1.15v1.15h3.5v-1.15c0-.45.2-.85.55-1.15A3.75 3.75 0 0 0 8 2.5z", } as const; /** diff --git a/apps/desktop/src/renderer/styles.css b/apps/desktop/src/renderer/styles.css index b0a94010..eb59867e 100644 --- a/apps/desktop/src/renderer/styles.css +++ b/apps/desktop/src/renderer/styles.css @@ -406,6 +406,14 @@ body[data-streamer-mode="true"] ::search-text { color: transparent; background-c .rail-work-btn:hover { color: var(--text-1); } .rail-work-count { position: absolute; top: -3px; right: -3px; display: grid; min-width: 15px; height: 15px; padding: 0 3px; place-items: center; border: 2px solid var(--bg-window); border-radius: var(--radius-pill); background: var(--accent); color: var(--accent-ink); font: var(--weight-semibold) 10px/1 var(--font-sans); pointer-events: none; } .msg-actions { display: flex; align-items: center; gap: 2px; margin: 2px 0 10px -6px; color: var(--text-3); } +/* Reply actions stay out of the way until the turn is pointed at or holds focus; the newest turn always shows + them. They fade, never leave the layout or the tab order. A device that cannot hover always shows them. */ +.turn .msg-actions { opacity: 0; transition: opacity var(--duration-fast) var(--ease-out); } +.turn:hover .msg-actions, .turn:focus-within .msg-actions, .turn:last-child .msg-actions { opacity: 1; } +/* The first icon's glyph, not its 6 px hit padding, sits on the column edge. */ +.turn > .msg-actions { position: relative; left: -6px; } +@media (hover: none) { .turn .msg-actions { opacity: 1; } } +@media (prefers-reduced-motion: reduce) { .turn .msg-actions { transition: none; } } .msg-actions .icon-btn { color: var(--text-3); } .msg-actions .icon-btn:hover, .msg-actions .icon-btn[aria-pressed="true"] { color: var(--text-1); } .msg-actions .icon-btn { --icon-cut: var(--bg-main, var(--bg-window)); } @@ -549,7 +557,7 @@ a.thread-pr:hover { text-decoration: underline; } .attachment-size { color: var(--text-info); } .attachment-remove { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; margin-left: 2px; padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-3); cursor: pointer; } .attachment-remove:hover { background: var(--bg-row-selected); color: var(--text-1); } -.msg.user .attachments { justify-content: flex-end; max-width: 70%; padding: 0; } +.msg.user .attachments { justify-content: flex-end; max-width: 78%; padding: 0; } .msg.user .bubble + .attachments { padding-top: 6px; } .drop-overlay { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--bg-main) 72%, transparent); pointer-events: none; } .drop-overlay-card { display: inline-flex; align-items: center; gap: 10px; padding: 14px 22px; border: 1px dashed var(--accent); border-radius: var(--radius-md); background: var(--bg-elevated); color: var(--text-1); font-size: var(--text-md); font-weight: var(--weight-medium); box-shadow: 0 16px 46px rgba(0, 0, 0, .35); } @@ -605,11 +613,19 @@ a.thread-pr:hover { text-decoration: underline; } /* A scrollbar gutter on both edges keeps the column centred on the composer whether or not it scrolls. */ .transcript { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 24px 0 16px; overscroll-behavior: contain; scrollbar-gutter: stable both-edges; } .transcript > * { max-width: calc(938px + 54px); margin-left: auto; margin-right: auto; padding-left: 27px; padding-right: 27px; } +/* A turn is one element (TurnContent). The column rule above applies to what is inside it, at this same + place in the cascade, so every later rule that sets a margin on one of those children still wins. */ +.transcript > .turn { max-width: none; padding: 0; } +.turn > * { max-width: calc(938px + 54px); margin-left: auto; margin-right: auto; padding-left: 27px; padding-right: 27px; } +.turn + .turn { margin-top: 16px; } .transcript-empty { color: var(--text-3); } .transcript-empty code { padding: 1px 5px; border-radius: var(--radius-xs); background: var(--bg-row-selected); } -.msg { margin-bottom: 20px; color: var(--text-1); font-size: var(--text-md); line-height: 1.6; } -.msg.user { display: flex; flex-direction: column; align-items: flex-end; } -.msg.user .bubble { max-width: 70%; padding: 8px 16px; border: 1px solid var(--bubble-border); border-radius: var(--radius-md); background: var(--bg-user-bubble); white-space: pre-wrap; overflow-wrap: anywhere; } +.msg { margin-bottom: 16px; color: var(--text-1); font-size: var(--text-md); line-height: 1.6; } +.msg.user { display: flex; flex-direction: column; align-items: flex-end; margin-bottom: 12px; } +.msg.user .bubble { max-width: 78%; padding: 9px 16px; border: 1px solid var(--bubble-border); border-radius: var(--radius-md); background: var(--bg-user-bubble); white-space: pre-wrap; overflow-wrap: anywhere; } +/* A reply that is still streaming ends in a pulsing dot. */ +.turn-content > [data-live="true"] > .msg.assistant > .md > :last-child::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: var(--text-2); vertical-align: 1px; animation: live-pulse 1s var(--ease-out) infinite; } +@keyframes live-pulse { 50% { opacity: .25; transform: scale(.8); } } .md p { margin: 0 0 12px; } /* Text as written until it nears the view and parses (Markdown.tsx, DeferMarkdown). */ .md-deferred { white-space: pre-wrap; overflow-wrap: anywhere; } @@ -665,25 +681,40 @@ a.thread-pr:hover { text-decoration: underline; } .source-title { overflow: hidden; color: var(--text-1); font-size: var(--text-sm); line-height: 18px; text-overflow: ellipsis; white-space: nowrap; } .source-domain { overflow: hidden; color: var(--text-info); font-size: var(--text-xs); line-height: 16px; text-overflow: ellipsis; white-space: nowrap; } -/* Turn header: "Working for 7s" over a 1 px rule, between a message and the agent's work. */ -.turn-header { margin-top: 26px; margin-bottom: 16px; } -.turn-label { display: block; padding-bottom: 8px; border-bottom: 1px solid var(--rule); color: var(--text-3); font-size: var(--text-md); font-weight: var(--weight-medium); line-height: 22px; } - -/* Thinking, tools, routes: one quiet line each, expandable. */ -.thinking, .tool, .route { margin-bottom: 6px; } -.thinking-head, .tool-head, .route-head { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 26px; padding: 2px 0; border: 0; background: transparent; color: var(--text-muted); font: var(--weight-medium) var(--text-md)/22px var(--font-sans); text-align: left; cursor: pointer; } +/* Turn status: "Working for 7s" or "Worked for 38s" as one quiet line between a message and the agent's work. + A finished turn with work is a toggle. A live turn leads with a dot: pulsing while the agent works, steady + and amber while it waits on the person. */ +.turn-header { margin-top: 0; margin-bottom: 8px; } +.turn-label { display: inline-flex; align-items: center; gap: 6px; height: 26px; margin-left: -6px; padding: 0 8px 0 6px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-3); font: var(--weight-medium) var(--text-sm)/1 var(--font-sans); } +button.turn-label { position: relative; text-align: left; cursor: pointer; transition: background var(--duration-fast) var(--ease-out); } +/* 26 px drawn, 30 px to hit. */ +button.turn-label::before { content: ""; position: absolute; inset: -2px 0; } +button.turn-label:hover { background: var(--tint); color: var(--text-1); } +.turn-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--text-1); animation: live-pulse 1.2s var(--ease-out) infinite; } +.turn-header.waiting .turn-dot { background: var(--warn); animation: none; } +.turn-header.live:not(.waiting) .turn-text { background: linear-gradient(90deg, var(--text-3) 0%, var(--text-1) 50%, var(--text-3) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.8s linear infinite; } + +/* Work rows: thinking, tools, routes and receipts share one 34 px row with a 22 px icon tile. A row hangs + 6 px into the margin, so the tile sits on the column edge and the hover fill reaches past it. */ +.thinking, .tool, .route, .approval-receipt { margin: 0 0 2px -6px; } +.thinking-head, .tool-head, .route-head, .receipt-head { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 34px; padding: 0 10px 0 6px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-muted); font: var(--weight-regular) var(--text-sm)/20px var(--font-sans); text-align: left; cursor: pointer; transition: background var(--duration-fast) var(--ease-out); } +.thinking-head:hover, .tool-head:hover, .route-head:hover, .receipt-head:hover { background: var(--tint); } .thinking-head:hover, .tool-head:hover, .route-head:hover, .thinking.open .thinking-head, .route.open .route-head { color: var(--text-2); } +.row-tile, .tool-head .tool-icon, .receipt-icon { display: grid; place-items: center; width: 22px; height: 22px; flex: none; border-radius: var(--radius-xs); background: var(--tint-strong); color: var(--text-2); } .chev.icon-svg { transition: transform var(--duration-fast) var(--ease-out); } .chev.open { transform: rotate(90deg); } .thinking-label.shimmer { background: linear-gradient(90deg, var(--text-muted) 0%, var(--text-2) 50%, var(--text-muted) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; } -.thinking-body { margin: 2px 0 10px; padding-left: 12px; border-left: 2px solid var(--border-pane); color: var(--text-3); font-size: var(--text-sm); } +.thinking-body { margin: 2px 0 10px 38px; color: var(--text-3); font-size: var(--text-sm); } .thinking-body .md p { margin: 0 0 6px; } .thinking-body.dim { color: var(--text-info); } -.tool-icon { display: inline-flex; align-items: center; width: 16px; flex: none; color: var(--text-3); font: 12px var(--font-mono); } -.tool-title { flex: 1; min-width: 0; overflow: hidden; color: var(--text-2); font: 12.5px var(--font-mono); text-overflow: ellipsis; white-space: nowrap; } +.tool-verb { flex: none; } +.tool-title { flex: 1; min-width: 0; overflow: hidden; color: var(--text-1); font: 12.5px var(--font-mono); text-overflow: ellipsis; white-space: nowrap; } .tool.failed .tool-title { color: var(--danger); } +.tool.failed .tool-icon { background: var(--danger-bg); color: var(--danger-text); } .tool-meta { flex-shrink: 0; font-variant-numeric: tabular-nums; flex: none; color: var(--text-info); font-size: var(--text-xs); font-weight: var(--weight-regular); } -.tool-body { margin: 4px 0 10px 24px; overflow: hidden; border: 1px solid var(--border-pane); border-radius: var(--radius-md); background: var(--bg-sunken); } +.tool-body { margin: 4px 0 10px 38px; overflow: hidden; border: 1px solid var(--border-pane); border-radius: var(--radius-md); background: var(--bg-sunken); } +/* A message that follows a visible row gets air above it; rows themselves stay 2 px apart. */ +.turn-content > div:not([hidden]):has(> :is(.thinking, .tool, .route, .approval-receipt)) + div:has(> .msg) { margin-top: 10px; } .tool-arguments summary { padding: 6px 10px; color: var(--text-3); font-size: var(--text-xs); cursor: pointer; } .output { margin: 0; padding: 10px 12px; max-height: 320px; overflow: auto; color: var(--text-2); font: 12px/1.5 var(--font-mono); white-space: pre-wrap; } .output.dim { color: var(--text-3); } @@ -746,17 +777,26 @@ a.thread-pr:hover { text-decoration: underline; } .question-input { width: 100%; max-width: 420px; margin-top: 6px; padding: 5px 8px; border: 1px solid var(--border-pane); border-radius: var(--radius-sm); background: var(--bg-sunken); color: var(--text-1); font: inherit; } .question-error { color: var(--danger-text); font-size: var(--text-sm); } -/* Approval answered by a rule: no card, because nothing waited on it. One quiet line, expandable like a tool. */ -.approval-receipt { margin-bottom: 6px; } -.receipt-head { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 26px; padding: 2px 0; border: 0; background: transparent; color: var(--text-muted); font: var(--weight-medium) var(--text-md)/22px var(--font-sans); text-align: left; cursor: pointer; } +/* An answered approval is a receipt: one work row (above), expandable to the request. A rule's allow or refusal + never waited on anyone; a person's answer, or a request that closed unanswered, reads the same way. */ .receipt-head:hover, .approval-receipt.open .receipt-head { color: var(--text-2); } -.receipt-icon { width: 16px; flex: none; text-align: center; } -.approval-receipt.allowed .receipt-icon { color: var(--ok); } -.approval-receipt.refused .receipt-icon { color: var(--danger); } +.approval-receipt.allowed .receipt-icon { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); } +.approval-receipt.refused .receipt-icon { background: var(--danger-bg); color: var(--danger-text); } +.approval-receipt.warn .receipt-icon { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); } +.approval-receipt.warn .receipt-answer { color: var(--warn); } .receipt-label, .receipt-meta { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.receipt-label code, .receipt-meta code { color: var(--text-2); font: 12.5px var(--font-mono); } +.receipt-label { color: var(--text-2); } +.receipt-label code, .receipt-meta code { color: var(--text-1); font: 12.5px var(--font-mono); } .receipt-meta { margin-left: auto; flex: 0 1 auto; color: var(--text-info); font-size: var(--text-xs); font-weight: var(--weight-regular); } -.receipt-body { margin: 2px 0 10px 8px; padding-left: 16px; border-left: 2px solid var(--border-pane); color: var(--text-3); font-size: var(--text-sm); } +/* A person's answer: the answer word takes focus after the answer, so the toggle is a button beside it, and + that button's hit area is stretched over the whole row. */ +.approval-receipt.human .receipt-head { position: relative; } +.approval-receipt.human .receipt-meta + .receipt-toggle { margin-left: 0; } +.receipt-toggle { display: grid; place-items: center; width: 18px; height: 22px; flex: none; margin-left: auto; padding: 0; border: 0; border-radius: var(--radius-xs); background: transparent; color: inherit; cursor: pointer; } +.receipt-toggle::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius-sm); } +.approval-receipt > .answer-note { margin: 0 0 6px 38px; } +.receipt-body { margin: 2px 0 10px 38px; color: var(--text-3); font-size: var(--text-sm); } +.receipt-body .approval-reason { margin: 0 0 6px; } .receipt-question { margin-bottom: 6px; color: var(--text-2); } .receipt-body .detail { max-height: 200px; margin: 0 0 8px; padding: 8px 10px; overflow: auto; border-radius: var(--radius-sm); background: var(--bg-sunken); color: var(--text-2); white-space: pre-wrap; } .receipt-body .dim { opacity: .8; } @@ -791,9 +831,13 @@ a.thread-pr:hover { text-decoration: underline; } .thinking-tag { padding: 0 6px; border: 1px solid var(--border-pane); border-radius: var(--radius-pill); color: var(--text-3); font-size: var(--text-xs); line-height: 18px; } .attempt-divider { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; color: var(--text-3); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; } .attempt-divider::after { content: ""; flex: 1; height: 1px; background: var(--border-pane); } -.jump-latest { position: relative; z-index: 2; display: inline-flex; align-items: center; gap: 6px; align-self: center; height: 28px; margin: -40px auto 12px; padding: 0 12px; border: 1px solid var(--border-pane); border-radius: var(--radius-pill); background: var(--bg-elevated); color: var(--text-2); font-size: var(--text-sm); cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); } +/* A square icon button over the transcript's bottom edge; its name is in a visually hidden label. The margins + cancel its height, so the transcript does not move when it appears. */ +.jump-latest { position: relative; z-index: 2; display: inline-flex; align-items: center; justify-content: center; align-self: center; width: 32px; height: 32px; margin: -44px auto 12px; padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-elevated); color: var(--text-2); cursor: pointer; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); } .jump-latest:hover { color: var(--text-1); } .jump-latest:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +/* Tints vanish in forced colours: the tile and the jump button fall back to a system-colour border. */ +@media (forced-colors: active) { .row-tile, .tool-head .tool-icon, .receipt-icon, .route-icon { border: 1px solid CanvasText; } .jump-latest { border-color: ButtonText; } .turn-dot { background: CanvasText; } } /* ── Evidence (docs/conversation-evidence.md): the command that ran, truncation, patch caption, native citations. ── */ .tool-exec { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 2px 0 8px; font-size: var(--text-sm); } @@ -851,6 +895,9 @@ a.thread-pr:hover { text-decoration: underline; } @media (prefers-reduced-motion: reduce) { .thinking-label.shimmer { animation: none; background: none; color: var(--text-2); } + .turn-header.live:not(.waiting) .turn-text { animation: none; background: none; color: var(--text-2); } + .turn-dot, .turn-content > [data-live="true"] > .msg.assistant > .md > :last-child::after { animation: none; } + button.turn-label, .thinking-head, .tool-head, .route-head, .receipt-head { transition: none; } .spinner, .row-status.running { animation: none; } .row-status.running { border-color: var(--text-2); border-top-color: var(--text-2); border-style: dotted; } } @@ -1025,12 +1072,10 @@ body[data-panel-resizing], body[data-panel-resizing] * { cursor: col-resize !imp .sheet[data-surface="space"] > .main.space-chat { box-shadow: none; } -/* Completed turns use the same quiet disclosure as the reference transcript. */ -.transcript > .turn-content { max-width: none; padding: 0; } +/* A turn's items each sit in their own wrapper (so folded work stays mounted); the wrapper takes the column. */ +.turn > .turn-content { max-width: none; padding: 0; } .turn-content > div { max-width: calc(938px + 54px); margin-left: auto; margin-right: auto; padding-left: 27px; padding-right: 27px; } .turn-content .msg { padding-left: 0; padding-right: 0; } -button.turn-label { display: flex; align-items: center; gap: 6px; width: 100%; padding: 0 0 8px; border: 0; border-bottom: 1px solid var(--rule); background: none; text-align: left; cursor: pointer; } -button.turn-label:hover { color: var(--text-2); } .turn-content :is(.approval, .failure) { width: 100%; } @@ -1124,10 +1169,10 @@ button.turn-label:hover { color: var(--text-2); } /* The Auto routing receipt: one quiet line, and when opened a card with its reasons and three measures. */ .route { border-radius: var(--radius-md); transition: background 140ms, box-shadow 140ms; } -.route.open { margin: 4px 0 10px; background: color-mix(in srgb, var(--text-1) 3.5%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text-1) 9%, transparent); } +.route.open { margin: 4px 0 10px -6px; background: color-mix(in srgb, var(--text-1) 3.5%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text-1) 9%, transparent); } .route .route-head { gap: 10px; min-height: 34px; padding: 0 10px 0 6px; border-radius: var(--radius-md); } .route .route-head:hover { background: color-mix(in srgb, var(--text-1) 4%, transparent); } -.route-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: var(--radius-sm); color: var(--accent-warn); background: color-mix(in srgb, var(--accent-warn) 14%, transparent); } +.route-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: var(--radius-xs); color: var(--accent-warn); background: color-mix(in srgb, var(--accent-warn) 14%, transparent); } .route-label { color: var(--text-3); font-size: 13px; letter-spacing: .005em; } .route-label b { color: var(--text-1); font-weight: 500; } .route-meta, .route.heuristic .route-meta { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); } diff --git a/apps/desktop/src/shared/approval-receipt.ts b/apps/desktop/src/shared/approval-receipt.ts index 66cf8807..2110ad10 100644 --- a/apps/desktop/src/shared/approval-receipt.ts +++ b/apps/desktop/src/shared/approval-receipt.ts @@ -1,4 +1,4 @@ -import type { ApprovalReceipt } from "./types.js"; +import type { ApprovalReceipt, ThreadItem } from "./types.js"; /** How the deciding rule was found to apply: "exact match" or "Jev 0.94". */ export function receiptVia(r: ApprovalReceipt): string { @@ -22,3 +22,27 @@ export function askedBecause(r: ApprovalReceipt): string { : rule; return `Asked because: ${why}${jevNotConsulted(r) ? " · Jev not consulted" : ""}`; } + +export type AnsweredTone = "allowed" | "refused" | "warn" | "neutral"; +export interface AnsweredApproval { text: string; tone: AnsweredTone; by: string | null } + +/** A request that closed without anyone answering it says why, rather than "Denied". */ +const WITHDRAWN = { + native: "Withdrawn — the agent no longer needs an answer", + stopped: "Not answered — the turn was stopped", + ended: "Not answered — the turn ended first", +} as const; + +/** + * The receipt row for an approval a person answered, or that closed unanswered: its words, its tone, and + * "by you" only when the answer is recorded as given in this window. Null while the request still waits. + */ +export function answeredApproval(item: Extract): AnsweredApproval | null { + if (!item.answer) return null; + if (item.delivery === "uncertain") return { text: "Delivery uncertain — not resent", tone: "warn", by: null }; + if (item.delivery === "sending") return { text: "Sending decision…", tone: "neutral", by: null }; + if (item.withdrawn) return { text: WITHDRAWN[item.withdrawn], tone: "neutral", by: null }; + const by = item.answeredBy === "desktop" ? "by you" : null; + if (item.answer === "no") return { text: "Denied", tone: "refused", by }; + return { text: item.answer === "always" ? "Approved — always for this command" : "Approved", tone: "allowed", by }; +} diff --git a/apps/desktop/src/shared/tool-summary.ts b/apps/desktop/src/shared/tool-summary.ts index 5c958256..7aaf6a49 100644 --- a/apps/desktop/src/shared/tool-summary.ts +++ b/apps/desktop/src/shared/tool-summary.ts @@ -32,3 +32,25 @@ export function toolFoldsAsWork(item: Extract): bo if (item.status !== "done" || item.agent?.state === "running" || item.agent?.state === "waiting") return false; return item.outcome ? item.outcome === "succeeded" : item.ok !== false; } + +/** What a tool row is, for its icon. `other` is any tool Modex has no picture for. */ +export type ToolKind = "command" | "edit" | "search" | "fetch" | "agent" | "file" | "other"; + +/** Tools that change a file (the patch tools of shared/evidence.ts, plus the scripted engine's `write_file`). */ +const EDIT_TOOLS: ReadonlySet = new Set(["apply_patch", "Edit", "MultiEdit", "Write", "NotebookEdit", "write_file"]); + +export function toolKind(item: Extract): ToolKind { + if (item.name === "WebSearch" || item.name === "webSearch") return "search"; + if (item.name === "WebFetch") return "fetch"; + if (item.name === "Agent" || item.name === "Task") return "agent"; + if (EDIT_TOOLS.has(item.name)) return "edit"; + const text = (key: string) => typeof item.args[key] === "string" && !!(item.args[key] as string).trim(); + if (text("command") || item.name === "shell" || item.name === "Bash") return "command"; + return text("file_path") || text("path") || text("notebook_path") ? "file" : "other"; +} + +/** "Ran" or "Running" for a row whose summary is a command line ("$ …"). Any other summary is already a phrase and gets no verb. */ +export function toolVerb(item: Extract): "Ran" | "Running" | null { + if (!toolSummary(item).startsWith("$ ")) return null; + return item.status === "running" ? "Running" : "Ran"; +} diff --git a/apps/desktop/test/approval-receipt.test.ts b/apps/desktop/test/approval-receipt.test.ts index 5a352e63..9b1b9c6e 100644 --- a/apps/desktop/test/approval-receipt.test.ts +++ b/apps/desktop/test/approval-receipt.test.ts @@ -1,7 +1,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; -import { askedBecause, jevNotConsulted, receiptVia } from "../src/shared/approval-receipt.js"; -import type { ApprovalReceipt } from "../src/shared/types.js"; +import { answeredApproval, askedBecause, jevNotConsulted, receiptVia } from "../src/shared/approval-receipt.js"; +import type { ApprovalReceipt, ThreadItem } from "../src/shared/types.js"; const receipt = (over: Partial = {}): ApprovalReceipt => ({ source: "rule", ruleId: "r1", when: "run the test suite", decision: "ask", via: "jev", p: 0.94, ms: 410, ...over }); @@ -28,3 +28,20 @@ test("a receipt says when Jev was not consulted, next to any downgrade label; ol assert.equal(jevNotConsulted(receipt({ decision: "allow", via: "match", downgraded: "jev-unavailable" })), true, "a receipt written before the flag"); assert.equal(jevNotConsulted(receipt({ decision: "allow" })), false); }); + +test("an answered approval reads as one receipt line; a waiting one has none", () => { + type Approval = Extract; + const approval = (over: Partial = {}): Approval => ({ id: "a", kind: "approval", question: "Allow?", at: "", ...over }); + assert.equal(answeredApproval(approval()), null); + assert.deepEqual(answeredApproval(approval({ answer: "yes", answeredBy: "desktop" })), { text: "Approved", tone: "allowed", by: "by you" }); + assert.deepEqual(answeredApproval(approval({ answer: "yes", answeredBy: "desktop", delivery: "sent" })), { text: "Approved", tone: "allowed", by: "by you" }); + assert.deepEqual(answeredApproval(approval({ answer: "always", answeredBy: "desktop" })), { text: "Approved — always for this command", tone: "allowed", by: "by you" }); + assert.deepEqual(answeredApproval(approval({ answer: "no", answeredBy: "desktop" })), { text: "Denied", tone: "refused", by: "by you" }); + assert.deepEqual(answeredApproval(approval({ answer: "yes", answeredBy: "phone" })), { text: "Approved", tone: "allowed", by: null }, "the note under the row says where it was answered"); + assert.deepEqual(answeredApproval(approval({ answer: "yes" })), { text: "Approved", tone: "allowed", by: null }, "an answer saved before the field existed claims nobody"); + assert.deepEqual(answeredApproval(approval({ answer: "yes", delivery: "sending" })), { text: "Sending decision…", tone: "neutral", by: null }); + assert.deepEqual(answeredApproval(approval({ answer: "yes", delivery: "uncertain" })), { text: "Delivery uncertain — not resent", tone: "warn", by: null }); + assert.deepEqual(answeredApproval(approval({ answer: "no", withdrawn: "stopped" })), { text: "Not answered — the turn was stopped", tone: "neutral", by: null }); + assert.deepEqual(answeredApproval(approval({ answer: "no", withdrawn: "native" })), { text: "Withdrawn — the agent no longer needs an answer", tone: "neutral", by: null }); + assert.deepEqual(answeredApproval(approval({ answer: "no", withdrawn: "ended" })), { text: "Not answered — the turn ended first", tone: "neutral", by: null }); +}); diff --git a/apps/desktop/test/tool-summary.test.ts b/apps/desktop/test/tool-summary.test.ts index 8cb91edb..65ca7b0d 100644 --- a/apps/desktop/test/tool-summary.test.ts +++ b/apps/desktop/test/tool-summary.test.ts @@ -1,6 +1,6 @@ import { test } from "node:test"; import assert from "node:assert/strict"; -import { toolFoldsAsWork, toolStatusLabel, toolSummary } from "../src/shared/tool-summary.js"; +import { toolFoldsAsWork, toolKind, toolStatusLabel, toolSummary, toolVerb } from "../src/shared/tool-summary.js"; import type { ThreadItem } from "../src/shared/types.js"; const tool = (patch: Partial>) => ({ id: "1", kind: "tool" as const, name: "tool", title: "", args: {}, status: "running" as const, at: "", ...patch }); @@ -35,3 +35,18 @@ test("only finished work that succeeded folds under the turn header; failed, den assert.deepEqual([toolFoldsAsWork(done({ ok: true })), toolFoldsAsWork(done({})), toolFoldsAsWork(done({ ok: false }))], [true, true, false]); assert.equal(toolFoldsAsWork(done({ outcome: "succeeded", agent: { id: "a", label: "x", state: "running" } })), false); }); + +test("a row's kind follows the tool, and only a command line gets a verb", () => { + assert.deepEqual([ + toolKind(tool({ name: "shell", args: { command: "git status" } })), toolKind(tool({ name: "Bash", title: "Bash", args: { command: "npm test" } })), + toolKind(tool({ name: "apply_patch" })), toolKind(tool({ name: "Write", args: { file_path: "a.ts" } })), toolKind(tool({ name: "write_file", args: { path: "a.ts" } })), + toolKind(tool({ name: "WebSearch" })), toolKind(tool({ name: "webSearch" })), toolKind(tool({ name: "WebFetch" })), + toolKind(tool({ name: "Agent", args: { description: "x" } })), toolKind(tool({ name: "read_file", args: { file_path: "a.ts" } })), toolKind(tool({ name: "mystery" })), + ], ["command", "command", "edit", "edit", "edit", "search", "search", "fetch", "agent", "file", "other"]); + assert.equal(toolKind(tool({ name: "mystery", args: { command: " " } })), "other", "a blank command is not a command"); + assert.equal(toolVerb(tool({ name: "shell", args: { command: "git status" } })), "Running"); + assert.equal(toolVerb(tool({ name: "shell", status: "done", args: { command: "git status" } })), "Ran"); + assert.equal(toolVerb(tool({ title: "$ git status", status: "done" })), "Ran"); + assert.equal(toolVerb(tool({ name: "Bash", title: "Run the tests", status: "done", args: { command: "npm test" } })), null, "a CLI title is already a phrase"); + assert.equal(toolVerb(tool({ name: "read_file", status: "done", args: { file_path: "a.ts" } })), null); +}); diff --git a/docs/status.md b/docs/status.md index 3c5744de..57099709 100644 --- a/docs/status.md +++ b/docs/status.md @@ -149,7 +149,9 @@ before relying on a tick. - **Chat and prompts refresh, PR 1 of 5** (branch `chat-refresh-foundation`). Val approved the design on 2026-11-15: [`superpowers/specs/2026-11-15-chat-prompts-refresh-design.md`](superpowers/specs/2026-11-15-chat-prompts-refresh-design.md). This first PR is the foundation, per [`superpowers/plans/2026-11-15-chat-refresh-foundation.md`](superpowers/plans/2026-11-15-chat-refresh-foundation.md): one radius scale for every renderer stylesheet (8 px surfaces, 6 px controls, 4 px parts; only dots and spinners stay round), the `--tint`, `--tint-strong` and `--hairline` tokens, and one in-app confirm dialog that replaces all ten `window.confirm` calls (YOLO, cloud model, delete thread, remove project, discard changes, reset learning, remove local connection, delete task). The source was written in a session that could not install dependencies: the radius guard (`scripts/test/radius-scale.test.mjs`) and the confirm store's logic were run there, and the build, unit suite and Electron specs were not, so CI is the first full run. Menus, transcript rows, the request panel and the composer follow in PRs 2 to 5. CI on #527 then passed on its first full run (2,563 unit tests; 553 Electron cases with the 14 standing live and native skips). -- **Chat and prompts refresh, PR 2 of 5: menus** (branch `chat-refresh-menus`, stacked on #527). Per [`superpowers/plans/2026-11-16-chat-refresh-menus.md`](superpowers/plans/2026-11-16-chat-refresh-menus.md): `Menu` and `MenuItem` take an optional `hint`. A row with a hint stays on one line and carries the sentence as its `aria-description`; a menu with a hint shows one description at its foot for the row under the pointer or focus. The composer's access and `+` menus use it, with Plan and Auto as switches; every sentence is today's copy, plus one new line for Attach files. All menus take the refreshed shell (hairline border, elevated surface, tinted hover and selection); menus that pass no hint, the model picker included, keep their rows. Written without a local build, like PR 1: CI is its first full run. +- **Chat and prompts refresh, PR 2 of 5: menus** (branch `chat-refresh-menus`, stacked on #527). Per [`superpowers/plans/2026-11-16-chat-refresh-menus.md`](superpowers/plans/2026-11-16-chat-refresh-menus.md): `Menu` and `MenuItem` take an optional `hint`. A row with a hint stays on one line and carries the sentence as its `aria-description`; a menu with a hint shows one description at its foot for the row under the pointer or focus. The composer's access and `+` menus use it, with Plan and Auto as switches; every sentence is today's copy, plus one new line for Attach files. All menus take the refreshed shell (hairline border, elevated surface, tinted hover and selection); menus that pass no hint, the model picker included, keep their rows. Written without a local build, like PR 1: CI is its first full run. CI on #528 then passed on its first full run (2,563 unit tests; 556 Electron cases with the 14 standing skips). + +- **Chat and prompts refresh, PR 3 of 5: transcript** (branch `chat-refresh-transcript`, stacked on #528). Per [`superpowers/plans/2026-11-16-chat-refresh-transcript.md`](superpowers/plans/2026-11-16-chat-refresh-transcript.md): each turn is one element; its status ("Worked for 38s") is a small inline line with no rule under it, a toggle when the turn has work, with a dot while the turn is live (steady and amber while it waits on the person). Thinking, tool, route and receipt rows share one 34 px row with a 22 px icon tile; tool glyph characters are icons by kind, and a command line reads "Ran" or "Running". An approval a person answered, or one that closed unanswered, is now a receipt row that opens to the request ("Approved … by you", only when main recorded the answer as given in this window); the waiting approval and the question card keep today's card until the request panel in PR 4. Reply actions fade out on older turns until the turn is hovered or holds focus. A streaming reply ends in a pulsing dot. Jump to latest is a square icon button with the same name. Three calls for Val in the plan: the 938 px column stays until the composer PR, focus after an answer does not move yet, and only commands get a verb. Written without a local build: the two shared helpers' unit tests, the radius guard and a rendered check of the new markup against the real stylesheets ran in the session; CI is the first full run. - **Code Review person-run seed and header-panel focus.** The owned source candidate repairs the actual human-review seed: long description, 101 paged comments, checks/stack/deployment and coherent diffs for all listed synthetic PRs. A normal Electron regression reproduced header Review panel Close dropping focus; Review/Merge Close and scoped Escape now return to their own split-pane button, preserving instructions Escape. Build, workspace typechecks, 2,588 units with 36 skips, 531 desktop E2E cases with 17 opt-in skips, eight site cases and four web cases pass. The isolated seeded overview/activity/panel/diff journey passes; the final fixture-only D5 scroll-density correction passes actual wide/narrow PageDown checks with unchanged diff/inbox positions, its final full units also pass, and protected delivery is pending. Human Result cells stay blank. The checklist uses explicit private-home General opt-in, removes C07 and describes conditional tree folding. Initial signed source `1b2c58b` passed hosted units and iPhone suites but failed two desktop E2E cases. The immutable-comparison fixture race is reproduced and repaired with two deterministic request orderings; the unexplained Markdown ArrowRight failure has validated observation-only diagnostics, with all original assertions retained. The follow-up full build, workspace/E2E typechecks and 2,588 units with 36 skips pass. Full follow-up E2E passes 532 desktop cases with 17 opt-in skips, eight site cases and four web cases, zero failures/retries; exact-head hosted/protected qualification remains pending. The original human candidate is independently preserved and natively qualified in a portable runtime, with human rows still blank. State-change panel focus/Escape remains a named follow-up. [Repair and limits](reviews/2026-11-13-cr-human-seed-focus.md), [CI follow-up](reviews/2026-11-13-pr522-ci-followup.md). diff --git a/docs/superpowers/plans/2026-11-16-chat-refresh-transcript.md b/docs/superpowers/plans/2026-11-16-chat-refresh-transcript.md new file mode 100644 index 00000000..ee3397b3 --- /dev/null +++ b/docs/superpowers/plans/2026-11-16-chat-refresh-transcript.md @@ -0,0 +1,145 @@ +# Chat Refresh Transcript (PR 3 of 5) Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Make the transcript read as one quiet column: each turn is one element, its status is a small inline toggle, work is a list of 34 px rows, an answered approval is a receipt row, and reply actions stay out of the way until the turn is pointed at. + +**Architecture:** `TurnContent` wraps what it renders today in one `.turn` element, so spacing, hover and focus can be scoped to a turn; the column rule that applied to the transcript's children moves to the wrapper's children at the same place in the stylesheet, so the cascade is unchanged. Thinking, tool, route and receipt rows share one row style (the one the route row already has). Wording and row kind are pure functions in `src/shared`, unit tested; the components only place them. Markup changes keep every existing `data-testid`, role and accessible name on the element that keeps the meaning. + +**Tech Stack:** Existing TypeScript, React 19, Playwright; no new dependencies. + +**Spec:** `docs/superpowers/specs/2026-11-15-chat-prompts-refresh-design.md`, section "3. Transcript" and the receipt rows of "States the prototype did not show". Stacked on PR 2 (`chat-refresh-menus`). + +## Scope calls (for Val to check) + +1. **The reading column stays 938 px in this PR.** The design narrows it to 760 px for the transcript and the composer together; `layout.spec.ts` pins "column = composer box − 22 px". It moves with the composer in PR 5. +2. **An answered approval becomes a receipt row now; a waiting approval and the question card keep today's card.** The waiting card is replaced by the request panel in PR 4, and the answered question card (one answer per question, read by several specs) moves to a row there with the panel's question variant. +3. **Focus after an answer does not change here.** It still lands on the answer word, which is now in the receipt row. PR 4 moves it to the message box, as designed. +4. **A verb only for commands.** "Ran `$ git status`" / "Running …". Other tools' summaries come from the CLI's own title and already read as a phrase ("edit CONTRIBUTING.md"), so a verb in front would double it. Every row gets an icon for its kind. + +## Global Constraints + +- A work row is `34px` high with a `22px` icon tile (`--radius-xs`, `--tint-strong`), `10px` gap, text `--text-sm`; the target is `12.5px` `--font-mono`; meta is `--text-xs` in `--text-info` at the right. +- Row hover is `--tint`. Rows hang `6px` into the left margin so the tile, not the hover fill, sits on the column edge. +- The turn status line has no rule under it: `--text-sm`, weight `500`, `--text-3`, `26px` high. A live turn shows a `7px` dot: pulsing in `--text-1` while working, steady in `--warn` while waiting. Working text shimmers. +- Existing ids, roles and names stay: `turn-header` (`data-live`), `turn-label` (text exactly "Worked for 38s", "Working for 7s", "Waiting for approval · 7s", "Waiting for your answer · 7s"; a `button` with `aria-expanded` when the turn has work), `item`, `item-toggle`, `item-body`, `tool-title`, `tool-summary` (text unchanged), `tool-meta`, `thinking-label`, `approval-receipt`, `receipt-meta`, `approval-answer` (text unchanged, `tabindex="-1"`), `answer-note`, `approval-reason`, `message-actions`, `jump-latest` (accessible name "Jump to latest"). +- The tool row's `aria-label` stays `": "`. +- Decision words are unchanged: "Approved", "Approved — always for this command", "Denied", "Sending decision…", "Delivery uncertain — not resent", and the three withdrawn sentences. +- Hidden reply actions use `opacity`, never `display` or `visibility`: they stay in the tab order and show on `:focus-within`. On a device without hover they always show. +- No animation under `prefers-reduced-motion`; under `forced-colors` the tile and the jump button get a system-colour border. +- Only dots are round (`50%`); the radius guard in `scripts/test/radius-scale.test.mjs` counts them per file and its count for `styles.css` changes with this PR. +- No behavior change: folding, focus hand-off to the turn toggle, scroll following and "Jump to latest" keep their logic. + +## Review Focus + +1. **A finished turn folds while focus is on the answer word of a receipt row.** Expected: focus moves to the turn's toggle, as today. Pinned by `keyboard-answers.spec.ts` (unchanged) and Task 2's markup keeping `approval-answer` focusable outside any button. +2. **An approval whose delivery is uncertain, loaded from disk.** Expected: a receipt row in the warn tone reading "Delivery uncertain — not resent", `data-answered="false"`, and the note under it. Pinned in Task 1 (unit) and Task 4 (spec). +3. **A stored thread with a tool the app has no kind for.** Expected: a row with the generic icon and today's summary, never an empty tile or a verb. Pinned in Task 1. +4. **Keyboard only, an older turn.** Expected: tabbing into the turn shows its reply actions; they are reachable without the pointer. Pinned in Task 4. +5. **A reader scrolled up in a long thread.** Expected: the jump button is a 32 px square that still reads "Jump to latest" to assistive tech and still returns focus to the message box. Pinned by the existing jump specs plus Task 4's size and name check. + +--- + +### Task 1: Row kind, verb and answered-approval wording in `src/shared` + +**Files:** +- Modify: `apps/desktop/src/shared/tool-summary.ts` +- Modify: `apps/desktop/src/shared/approval-receipt.ts` +- Test: `apps/desktop/test/tool-summary.test.ts`, `apps/desktop/test/approval-receipt.test.ts` + +**Interfaces (produced):** + +```ts +// tool-summary.ts +export type ToolKind = "command" | "edit" | "search" | "fetch" | "agent" | "file" | "other"; +export function toolKind(item: Extract): ToolKind; +/** "Ran" or "Running" for a row whose summary is a command line ("$ …"); null for every other row. */ +export function toolVerb(item: Extract): "Ran" | "Running" | null; + +// approval-receipt.ts +export type AnsweredTone = "allowed" | "refused" | "warn" | "neutral"; +export interface AnsweredApproval { text: string; tone: AnsweredTone; by: string | null } +/** The receipt row for an approval a person answered, or that closed unanswered. Null while it waits. */ +export function answeredApproval(item: Extract): AnsweredApproval | null; +``` + +- [ ] **Step 1: failing tests** + +```ts +test("a row's kind follows the tool, and only a command line gets a verb", () => { + assert.deepEqual([ + toolKind(tool({ name: "shell", args: { command: "git status" } })), toolKind(tool({ name: "Bash", title: "Bash", args: { command: "npm test" } })), + toolKind(tool({ name: "apply_patch" })), toolKind(tool({ name: "Write", args: { file_path: "a.ts" } })), toolKind(tool({ name: "write_file", args: { path: "a.ts" } })), + toolKind(tool({ name: "WebSearch" })), toolKind(tool({ name: "webSearch" })), toolKind(tool({ name: "WebFetch" })), + toolKind(tool({ name: "Agent", args: { description: "x" } })), toolKind(tool({ name: "read_file", args: { file_path: "a.ts" } })), toolKind(tool({ name: "mystery" })), + ], ["command", "command", "edit", "edit", "edit", "search", "search", "fetch", "agent", "file", "other"]); + assert.equal(toolVerb(tool({ name: "shell", args: { command: "git status" } })), "Running"); + assert.equal(toolVerb(tool({ name: "shell", status: "done", args: { command: "git status" } })), "Ran"); + assert.equal(toolVerb(tool({ title: "$ git status", status: "done" })), "Ran"); + assert.equal(toolVerb(tool({ name: "Bash", title: "Run the tests", status: "done", args: { command: "npm test" } })), null, "a CLI title is already a phrase"); + assert.equal(toolVerb(tool({ name: "read_file", status: "done", args: { file_path: "a.ts" } })), null); +}); + +test("an answered approval reads as one receipt line; a waiting one has none", () => { + const approval = (over: object) => ({ id: "a", kind: "approval" as const, question: "Allow?", at: "", ...over }); + assert.equal(answeredApproval(approval({})), null); + assert.deepEqual(answeredApproval(approval({ answer: "yes", answeredBy: "desktop" })), { text: "Approved", tone: "allowed", by: "by you" }); + assert.deepEqual(answeredApproval(approval({ answer: "always", answeredBy: "desktop" })), { text: "Approved — always for this command", tone: "allowed", by: "by you" }); + assert.deepEqual(answeredApproval(approval({ answer: "no", answeredBy: "desktop" })), { text: "Denied", tone: "refused", by: "by you" }); + assert.deepEqual(answeredApproval(approval({ answer: "yes", answeredBy: "phone" })), { text: "Approved", tone: "allowed", by: null }, "the note under the row says where it was answered"); + assert.deepEqual(answeredApproval(approval({ answer: "yes" })), { text: "Approved", tone: "allowed", by: null }, "an answer saved before the field existed claims nobody"); + assert.deepEqual(answeredApproval(approval({ answer: "yes", delivery: "sending" })), { text: "Sending decision…", tone: "neutral", by: null }); + assert.deepEqual(answeredApproval(approval({ answer: "yes", delivery: "uncertain" })), { text: "Delivery uncertain — not resent", tone: "warn", by: null }); + assert.deepEqual(answeredApproval(approval({ answer: "no", withdrawn: "stopped" })), { text: "Not answered — the turn was stopped", tone: "neutral", by: null }); + assert.deepEqual(answeredApproval(approval({ answer: "no", withdrawn: "native" })), { text: "Withdrawn — the agent no longer needs an answer", tone: "neutral", by: null }); + assert.deepEqual(answeredApproval(approval({ answer: "no", withdrawn: "ended" })), { text: "Not answered — the turn ended first", tone: "neutral", by: null }); +}); +``` + +- [ ] **Step 2:** run them, expect "toolKind is not a function". +- [ ] **Step 3:** implement. Precedence in `answeredApproval` is today's: uncertain, then sending, then withdrawn, then the answer. `by` is "by you" only when `answeredBy === "desktop"`, the value main records for an answer given in this window; a phone or paired-desktop answer has its note instead, and an answer saved before the field existed claims nobody. `toolKind`: search and fetch by name (`WebSearch`, `webSearch`, `WebFetch`); agent by `Agent`/`Task`; edit by `PATCH_TOOLS` plus `write_file`; command when a `command` argument is a non-empty string or the name is `shell`/`Bash`; file when a path argument exists; else other. `toolVerb` is non-null only when `toolSummary(item)` starts with `"$ "`. +- [ ] **Step 4:** run them, expect pass. **Step 5:** commit. + +### Task 2: Markup — turn wrapper, status line, rows, receipts, jump button + +**Files:** +- Modify: `apps/desktop/src/renderer/components/transcript/TurnContent.tsx`, `ReasoningItem.tsx` +- Modify: `apps/desktop/src/renderer/components/ThreadView.tsx` (`ToolItem`, `ApprovalItem`, `ApprovalReceiptRow`, the jump button) +- Modify: `apps/desktop/src/renderer/components/ui/Icon.tsx` (`arrow-down`, `thought`) + +**Consumes:** Task 1's `toolKind`, `toolVerb`, `answeredApproval`. + +- [ ] `TurnContent` returns `
` around the user message, header, content and footer. Refs and effects are untouched. +- [ ] `TurnHeader`: class gains `waiting` while `status === "waiting"`; the label's text sits in ``; a live label starts with `