Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/desktop/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -1866,3 +1866,23 @@
inset: -4px -12px;
z-index: -1;
}

.turn-history {
--turn-fade-top: 0px;
--turn-fade-bottom: 0px;
mask-image: linear-gradient(
to bottom,
transparent,
#000 var(--turn-fade-top),
#000 calc(100% - var(--turn-fade-bottom)),
transparent
);
}

.turn-history[data-more-above] {
--turn-fade-top: 18px;
}

.turn-history[data-more-below] {
--turn-fade-bottom: 18px;
}
15 changes: 9 additions & 6 deletions apps/desktop/src/state/turnEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { TranscriptItem } from "./thread";
import { eventsText, keepEvent, turnEvents } from "./turnEvents";

const items = [
{ kind: "user", id: "u", text: "Fix it", at: 1 },
{ kind: "user", id: "u", text: "Fix it\nKeep the sidebar visible.", at: 1 },
{ kind: "thought", id: "t", text: "Reading the request\nmore", summary: false, startedAt: 2, done: true },
{
kind: "tool",
Expand All @@ -24,20 +24,23 @@ const items = [
test("a turn's rows become its events in order, with badges and kinds", () => {
const events = turnEvents(items);
expect(events.map((e) => [e.badge, e.kind, e.at])).toEqual([
["You", "user", 1],
["Thinking", "thinking", 2],
["Bash", "run", 3],
["Edit", "failed", 4],
["Agent", "agent", 5],
]);
expect(events[0]!.line).toBe("Reading the request");
expect(events[1]!.body).toContain("bun test");
expect(events[1]!.body).toContain("ok");
expect(events[0]!.line).toBe("Fix it");
expect(events[0]!.body).toBe("Fix it\nKeep the sidebar visible.");
expect(events[1]!.line).toBe("Reading the request");
expect(events[2]!.body).toContain("bun test");
expect(events[2]!.body).toContain("ok");
});

test("filters keep what they name", () => {
const events = turnEvents(items);
expect(events.filter((e) => keepEvent(e, "tools")).map((e) => e.id)).toEqual(["c", "f"]);
expect(events.filter((e) => keepEvent(e, "agent")).map((e) => e.id)).toEqual(["t", "a"]);
expect(events.filter((e) => keepEvent(e, "agent")).map((e) => e.id)).toEqual(["u", "t", "a"]);
expect(events.filter((e) => keepEvent(e, "failed")).map((e) => e.id)).toEqual(["f"]);
expect(eventsText(events)).toStartWith("#1 Thinking: Reading the request");
expect(eventsText(events)).toStartWith("#1 You: Fix it");
});
15 changes: 8 additions & 7 deletions apps/desktop/src/state/turnEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { stripHarnessMarkup } from "./threadFormat";
import { displayTool, usefulSummary } from "./toolNames";

/**
* A turn as a list of events, for the turn's event log (ui/TurnEvents.tsx): what the agent said,
* A turn as a list of events, for the turn's event log (ui/TurnEvents.tsx): what the user and agent said,
* what it thought and each tool call, in the order they happened, each with a short line for its
* row and the whole text for when the row is opened. The trace (lib/trace.ts) says where the time
* went; this says what was done.
*/
/** What an event is, which picks its badge's colour and the filter it falls under. */
export type TurnEventKind = "agent" | "thinking" | "run" | "read" | "edit" | "tool" | "failed";
export type TurnEventKind = "user" | "agent" | "thinking" | "run" | "read" | "edit" | "tool" | "failed";

export interface TurnEvent {
id: string;
Expand Down Expand Up @@ -37,9 +37,9 @@ export type EventFilter = (typeof EVENT_FILTERS)[number]["id"];

export function keepEvent(event: TurnEvent, filter: EventFilter): boolean {
if (filter === "all") return true;
if (filter === "agent") return event.kind === "agent" || event.kind === "thinking";
if (filter === "failed") return event.kind === "failed";
return event.kind !== "agent" && event.kind !== "thinking";
const message = event.kind === "user" || event.kind === "agent" || event.kind === "thinking";
return filter === "agent" ? message : !message;
}

type ToolItem = Extract<TranscriptItem, { kind: "tool" }>;
Expand Down Expand Up @@ -93,13 +93,14 @@ function callParts(item: ToolItem): { input?: string; output?: string } {
export function turnEvents(items: readonly TranscriptItem[]): TurnEvent[] {
const events: TurnEvent[] = [];
for (const item of items) {
if (item.kind === "assistant") {
if (item.kind === "user" || item.kind === "assistant") {
if (item.kind === "user" && (item.wake || item.continued)) continue;
const text = stripHarnessMarkup(item.text).trim();
if (!text) continue;
events.push({
id: item.id,
kind: "agent",
badge: "Agent",
kind: item.kind === "user" ? "user" : "agent",
badge: item.kind === "user" ? "You" : "Agent",
line: firstLine(text),
body: text,
at: item.at,
Expand Down
105 changes: 69 additions & 36 deletions apps/desktop/src/ui/ThreadDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// branch), its uncommitted files, its pull requests, lineage, and activity (counts, tokens, cost,
// age, context). The full diff and pull list open from their sections (ui/RightPanel.tsx).

import { type ReactNode, useEffect, useMemo, useState } from "react";
import { type ReactNode, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { pullErrorTitle } from "../acp/rustcode";
import { modelName, projectName } from "../acp/types";
import { STATUS_LABEL } from "../acp/v2";
Expand Down Expand Up @@ -146,7 +146,7 @@ export function ThreadDetails() {
const openChanges = () => showPanel("changes");

return (
<div className="flex min-h-0 flex-1 flex-col overflow-y-auto pb-2">
<div className="flex min-h-0 flex-1 flex-col overflow-y-auto pb-2 [&>*]:shrink-0">
<div className="px-2">
<Property label="Status">
<StatusIcon status={status} size={13} />
Expand Down Expand Up @@ -244,7 +244,7 @@ export function ThreadDetails() {
</div>
)}
</Section>
<TurnsSection items={items ?? []} model={model} folded={isFolded("log")} onToggle={toggle} />
<TurnsSection key={id} items={items ?? []} model={model} folded={isFolded("log")} onToggle={toggle} />
</div>
);
}
Expand Down Expand Up @@ -312,11 +312,7 @@ const OUTCOME = {
failed: { icon: CircleX, tone: "text-danger", label: "Failed" },
} as const;

/**
* Every finished turn, newest first: what opened it, how long it ran, what it cost, and a Trace
* chip that opens its waterfall beside the card (ui/TurnTrace.tsx) where the app watched the turn.
* A press on the turn opens its event log: every message and call, laid flat (ui/TurnEvents.tsx).
*/
/** Finished turns, newest first. Open a row for its messages and calls. */
function TurnsSection({
items,
model,
Expand Down Expand Up @@ -352,13 +348,13 @@ function TurnsSection({
count={turns.length || undefined}
action={
turns.length > 1 ? (
<Tooltip label="Every turn's events in one log">
<Tooltip label="Open the transcript for all turns">
<button
type="button"
onClick={() => setOpen(ALL)}
className="flex h-6 items-center rounded-md px-2 text-caption text-fg-muted hover:bg-fill hover:text-fg"
>
View all
All turns
</button>
</Tooltip>
) : undefined
Expand All @@ -367,19 +363,20 @@ function TurnsSection({
onToggle={onToggle}
grow
>
{turns.length === 0 && (
<p className="flex min-h-7 items-center px-2 text-callout text-fg-muted">No turns yet.</p>
)}
{turns.map((turn) => {
const outcome = OUTCOME[turn.outcome];
const Icon = outcome.icon;
const end = ends.get(turn.id);
return (
<div key={turn.id} className="flex min-h-8 items-center gap-1 rounded-md hover:bg-fill-subtle">
<TurnScroll>
{turns.length === 0 && (
<p className="flex min-h-7 items-center px-2 text-callout text-fg-muted">No turns yet.</p>
)}
{turns.map((turn) => {
const outcome = OUTCOME[turn.outcome];
const Icon = outcome.icon;
return (
<button
key={turn.id}
type="button"
aria-haspopup="dialog"
onClick={() => setOpen(turn.id)}
className="flex min-h-8 min-w-0 flex-1 items-center gap-2 rounded-md pl-2 text-left"
className="flex min-h-8 w-full items-center gap-2 rounded-md px-2 text-left hover:bg-fill-subtle"
>
<span
role="img"
Expand All @@ -389,27 +386,25 @@ function TurnsSection({
<Icon size={13} />
</span>
<span className="min-w-0 flex-1 truncate text-callout">{turn.prompt}</span>
{turn.elapsedMs !== undefined && (
<span className="shrink-0 text-caption text-fg-muted tabular">
{formatDuration(turn.elapsedMs)}
</span>
)}
<span className="w-14 shrink-0 text-right text-caption text-fg-muted tabular">
{turn.elapsedMs === undefined ? "" : formatDuration(turn.elapsedMs)}
</span>
{turn.cost !== undefined ? (
<span className="shrink-0 text-caption text-fg-muted tabular">{formatCost(turn.cost)}</span>
<span className="w-14 shrink-0 text-right text-caption text-fg-muted tabular">
{formatCost(turn.cost)}
</span>
) : turn.tokens !== undefined ? (
<span className="shrink-0 text-caption text-fg-muted tabular">
<span className="w-14 shrink-0 text-right text-caption text-fg-muted tabular">
{formatTokens(turn.tokens)}
</span>
) : null}
</button>
<span className="flex shrink-0 pr-2">
{end && turnHasTrace(turn) && (
<TurnTrace end={end} items={byEnd[turn.id]} model={model} side="left" />
) : (
<span className="w-14 shrink-0" />
)}
</span>
</div>
);
})}
<ChevronRight size={14} className="shrink-0 text-fg-muted" />
</button>
);
})}
</TurnScroll>
{log && (
<TurnEvents
open
Expand All @@ -427,6 +422,44 @@ function TurnsSection({
);
}

function TurnScroll({ children }: { children: ReactNode }) {
const viewport = useRef<HTMLDivElement>(null);
const content = useRef<HTMLDivElement>(null);

useLayoutEffect(() => {
const node = viewport.current;
const rows = content.current;
if (!node || !rows) return;

const update = () => {
node.toggleAttribute("data-more-above", node.scrollTop > 1);
node.toggleAttribute("data-more-below", node.scrollHeight - node.clientHeight - node.scrollTop > 1);
};
const observer = new ResizeObserver(update);
observer.observe(node);
observer.observe(rows);
node.addEventListener("scroll", update, { passive: true });
update();
return () => {
observer.disconnect();
node.removeEventListener("scroll", update);
};
}, []);

return (
<div
ref={viewport}
role="region"
aria-label="Turn history"
className="turn-history min-h-0 flex-1 overflow-y-auto overscroll-y-contain scroll-py-5"
>
<div ref={content} className="py-1">
{children}
</div>
</div>
);
}

/** A section's way to its full view: the diff, the pull list. */
function OpenButton({ label, onClick }: { label: string; onClick: () => void }) {
return (
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/ui/TurnEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface LogTurn {

/** Each kind's badge and strip cell: commands in the accent, the agent's words in green. */
const TONE: Record<TurnEventKind, { badge: string; cell: string }> = {
user: { badge: "bg-fill-strong text-fg", cell: "bg-fg-muted" },
agent: { badge: "bg-success/15 text-success", cell: "bg-success/70" },
thinking: { badge: "bg-fill text-fg-muted", cell: "bg-fill-strong" },
run: { badge: "bg-accent/15 text-accent", cell: "bg-accent/70" },
Expand Down
Loading