Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Polish chat activity groups and compact tool disclosures (#1354)

Regan Bell5239f7baa986
diff --git a/plugins/web-ui/src/activity-presentation.ts b/plugins/web-ui/src/activity-presentation.ts
new file mode 100644
index 000000000..3b1c6c551
--- /dev/null
+++ b/plugins/web-ui/src/activity-presentation.ts
@@ -0,0 +1,199 @@
+import { toolCategory, toolRowKind, type TimelineItem, type ToolPayload, type ToolRowModel } from "./timeline.ts";
+import type { WorkBlock } from "./core-bridge.ts";
+
+export type ActivityCategory = "read" | "search" | "execute" | "other";
+
+export function compactPath(path: string): string {
+ const parts = path.replace(/\/$/, "").split("/");
+ return parts.at(-1) === "SKILL.md" ? parts.slice(-2).join("/") : parts.at(-1) || path;
+}
+
+function shellWords(command: string): string[] | null {
+ if (command.includes("\n")) return null;
+ const pattern = /\s*(?:'([^']*)'|"([^"$`\\]*)"|([^\s'"\\;&|<>`$()]+))/gy;
+ const words: string[] = [];
+ while (pattern.lastIndex < command.length) {
+ if (!command.slice(pattern.lastIndex).trim()) break;
+ const match = pattern.exec(command);
+ if (!match) return null;
+ if (pattern.lastIndex < command.length && !/\s/.test(command[pattern.lastIndex]!)) return null;
+ words.push(match[1] ?? match[2] ?? match[3]!);
+ }
+ return words;
+}
+
+export function activityDescription(
+ call: ToolPayload,
+ result: ToolPayload = {},
+): {
+ category: ActivityCategory;
+ target: string;
+} {
+ const tool = toolCategory({ ...result, ...call });
+ if (tool === "read") return { category: "read", target: compactPath(call.path ?? result.path ?? "") };
+ if (tool !== "execute") return { category: "other", target: "" };
+ const command = call.command ?? "";
+ const words = shellWords(command);
+ if (words?.[0] === "cat" && words.length === 2 && !words[1]!.startsWith("-")) {
+ return { category: "read", target: compactPath(words[1]!) };
+ }
+ if (
+ words?.[0] === "sed" &&
+ words.length === 4 &&
+ words[1] === "-n" &&
+ /^\d+(?:,\d+)?p$/.test(words[2]!) &&
+ !words[3]!.startsWith("-")
+ ) {
+ return { category: "read", target: compactPath(words[3]!) };
+ }
+ if (words?.[0] === "rg" && words[1] === "--files" && words.length <= 3 && !words[2]?.startsWith("-")) {
+ return { category: "search", target: `files${words[2] ? ` in ${compactPath(words[2])}` : ""}` };
+ }
+ if (words && ["rg", "grep"].includes(words[0]!)) {
+ const args = words.slice(1);
+ const flags = new Set([
+ "-n",
+ "--line-number",
+ "-i",
+ "--ignore-case",
+ "-l",
+ "--files-with-matches",
+ "-F",
+ "--fixed-strings",
+ "-w",
+ "--word-regexp",
+ "--hidden",
+ ]);
+ while (args.length && flags.has(args[0]!)) args.shift();
+ if (args.length >= 1 && args.length <= 2 && !args.some((arg) => arg.startsWith("-"))) {
+ return { category: "search", target: `${args[0]}${args[1] ? ` in ${compactPath(args[1])}` : ""}` };
+ }
+ }
+ return { category: "execute", target: command.split("\n")[0] ?? "" };
+}
+
+export function activityLabel(row: ToolRowModel, status: WorkBlock["status"]): string | null {
+ const call = (row.call?.payload ?? {}) as ToolPayload;
+ const result = (row.result?.payload ?? {}) as ToolPayload;
+ const { category, target } = activityDescription(call, result);
+ const state = toolRowKind(row, status);
+ if (category === "other" || state === "approval") return null;
+ const verbs = {
+ read: { ok: "Read", running: "Reading", failed: "Failed to read", attempted: "Tried reading" },
+ search: {
+ ok: "Searched for",
+ running: "Searching for",
+ failed: "Failed searching for",
+ attempted: "Tried searching for",
+ },
+ execute: { ok: "Ran", running: "Running", failed: "Failed running", attempted: "Tried running" },
+ };
+ if (state === "ok" && (category === "read" || category === "execute") && target) return target;
+ return `${verbs[category][state]} ${target || (category === "execute" ? "command" : "file")}`;
+}
+
+export function activityGroupSummary(
+ items: TimelineItem[],
+ status: WorkBlock["status"],
+): {
+ label: string;
+ category: ActivityCategory;
+ attention: boolean;
+} {
+ const categories = new Set<ActivityCategory>();
+ let failed = 0;
+ let running = 0;
+ let approvals = 0;
+ let attempted = 0;
+ for (const item of items) {
+ if (item.kind === "approval") approvals++;
+ if (item.kind !== "tool") continue;
+ const state = toolRowKind(item.row, status);
+ if (state === "failed") failed++;
+ if (state === "running") running++;
+ if (item.row.pending) approvals++;
+ if (state === "attempted") attempted++;
+ categories.add(
+ activityDescription(
+ (item.row.call?.payload ?? {}) as ToolPayload,
+ (item.row.result?.payload ?? {}) as ToolPayload,
+ ).category,
+ );
+ }
+ const active = running > 0;
+ const phrases = [];
+ if (categories.has("read")) phrases.push(active ? "Reading files" : "Read files");
+ if (categories.has("search")) phrases.push(active ? "Searching files" : "Searched files");
+ if (categories.has("execute")) phrases.push(active ? "Running commands" : "Ran commands");
+ if (categories.has("other")) phrases.push(active ? "Using tools" : "Used tools");
+ const base = phrases.map((phrase, i) => (i ? phrase.toLowerCase() : phrase)).join(", ") || "Thought";
+ const notes = [
+ failed ? `${failed} failed` : "",
+ approvals ? "Approval needed" : "",
+ attempted ? `${attempted} unconfirmed` : "",
+ ].filter(Boolean);
+ return {
+ label: [base, ...notes].join(" · "),
+ category:
+ (["search", "read", "execute"] as ActivityCategory[]).find((category) => categories.has(category)) ?? "other",
+ attention: failed > 0 || approvals > 0,
+ };
+}
+
+export function thinkingPresentation(text: string): { title: string; body: string } {
+ const trimmed = text.trim();
+ const heading = /^(?:#{1,6} +([^\n]+)|\*\*([^\n]+?)\*\*|__([^\n]+?)__)(?:\r?\n|$)/.exec(trimmed);
+ if (!heading) return { title: "Thought process", body: trimmed };
+ const title = (heading[1] ?? heading[2] ?? heading[3]!).replace(/ +#+$/, "").trim();
+ return { title, body: trimmed.slice(heading[0].length).trim() };
+}
+
+export function sessionPresentation(
+ row: ToolRowModel,
+ status: WorkBlock["status"],
+): { label: string; target: string; preview: string } | null {
+ const call = (row.call?.payload ?? {}) as ToolPayload & {
+ target?: string;
+ text?: string;
+ task?: string;
+ interrupt?: boolean;
+ };
+ const result = (row.result?.payload ?? {}) as ToolPayload & { title?: string; sessionId?: string };
+ if ((call.tool ?? result.tool) !== "session") return null;
+ const action = call.interrupt === true ? "interrupt" : (call.action ?? result.action ?? "");
+ const actions: Record<string, [string, string, string]> = {
+ open: ["Created", "Creating", "create"],
+ write: ["Sent message to", "Sending message to", "send message to"],
+ send_message: ["Sent message to", "Sending message to", "send message to"],
+ followup_task: ["Continued", "Continuing", "continue"],
+ read: ["Read updates from", "Reading updates from", "read updates from"],
+ wait: ["Waited", "Waiting", "wait"],
+ interrupt: ["Interrupted", "Interrupting", "interrupt"],
+ close: ["Closed", "Closing", "close"],
+ list: ["Listed", "Listing", "list"],
+ };
+ const verbs = actions[action];
+ if (!verbs) return null;
+ const state = toolRowKind(row, status);
+ let label = verbs[0];
+ if (state === "running") label = verbs[1];
+ else if (state === "failed") label = `Failed to ${verbs[2]}`;
+ else if (state === "attempted") label = `Tried to ${verbs[2]}`;
+ else if (state === "approval") label = `${row.pending ? "Approval needed" : "Approval requested"} to ${verbs[2]}`;
+ const target =
+ result.title || call.name || call.target || result.sessionId || (action === "open" ? "subagent" : "subagents");
+ const preview = ["write", "send_message", "followup_task"].includes(action)
+ ? (call.text ?? call.task ?? "").replace(/\s+/g, " ").trim()
+ : "";
+ return { label, target, preview };
+}
+
+export function activityGroups(items: TimelineItem[]): TimelineItem[][] {
+ const groups: TimelineItem[][] = [];
+ for (const item of items) {
+ const last = groups.at(-1);
+ if (item.kind === "text" || !last || last[0]?.kind === "text") groups.push([item]);
+ else last.push(item);
+ }
+ return groups;
+}
diff --git a/plugins/web-ui/src/chat.ts b/plugins/web-ui/src/chat.ts
index 39c30878d..0c1e207f3 100644
--- a/plugins/web-ui/src/chat.ts
+++ b/plugins/web-ui/src/chat.ts
@@ -6,6 +6,14 @@ import { setupContent } from "./setup-widget";
import { isWelcomeConversation } from "./welcome-session";
import { ADMIN_BASE } from "./shell";
import { connectorCard } from "./connector-widget";
+import {
+ activityDescription,
+ activityLabel,
+ activityGroupSummary,
+ activityGroups,
+ thinkingPresentation,
+ sessionPresentation,
+} from "./activity-presentation";
import { loadGeneratedActivities } from "./generated-activities";
import { playgroundPath, playgroundsIn, type PlaygroundArtifact } from "./playground";
import { Agent } from "@earendil-works/pi-agent-core";
@@ -16,10 +24,13 @@ import type { UserMessageWithAttachments } from "@earendil-works/pi-web-ui";
import { markdown } from "./message-markdown";
import { html, nothing, render, type TemplateResult } from "lit";
import { repeat } from "lit/directives/repeat.js";
+import { ref } from "lit/directives/ref.js";
import {
Activity,
- Bot,
+ BookOpen,
+ Search,
Brain,
+ Bot,
Check,
ChevronDown,
ChevronRight,
@@ -41,7 +52,7 @@ import {
Target,
Rocket,
ScrollText,
- Terminal,
+ SquareTerminal as Terminal,
Wrench,
X,
type IconNode,
@@ -104,7 +115,6 @@ import {
postSpeechText,
toolCategory,
toolRowKind,
- toolExecutionOutput,
sessionToolView,
type TimelineItem,
type ToolPayload,
@@ -2283,7 +2293,7 @@ export function createChatSurface(
const active = activeToolRow(work);
const call = (active?.call?.payload ?? {}) as ToolPayload;
const tool = call.tool ?? "";
- const verb = active ? (TOOL_META[tool] ?? UNKNOWN_TOOL).active : null;
+ const verb = active ? (TOOL_META[toolCategory(call)] ?? UNKNOWN_TOOL).active : null;
return {
icon: RefreshCw,
label: verb ? `${verb} interrupted, resuming…` : "Interrupted, resuming…",
@@ -2307,7 +2317,7 @@ export function createChatSurface(
const call = (row.call?.payload ?? {}) as ToolPayload;
const result = (row.result?.payload ?? {}) as ToolPayload;
const tool = call.tool ?? result.tool ?? "unknown";
- const meta = TOOL_META[tool] ?? UNKNOWN_TOOL;
+ const meta = TOOL_META[toolCategory({ ...result, ...call })] ?? UNKNOWN_TOOL;
const secs = elapsedSeconds(row.call?.createdAt) || workSeconds(work);
const posting = postSpeechText(row, true);
if (posting) {
@@ -2342,6 +2352,12 @@ export function createChatSurface(
return workedLabel(work.status === "working" ? "Working" : "Worked", secs);
}
+ function timelineKey(item: TimelineItem): string {
+ if (item.kind === "tool") return `tool:${item.row.call?.seq ?? item.row.result?.seq ?? item.row.approval?.seq}`;
+ if (item.kind === "approval") return `approval:${item.approval.requestId}`;
+ return `${item.kind}:${item.activity.seq}`;
+ }
+
function workBlock(
work: WorkBlock,
isStreaming: boolean,
@@ -2371,19 +2387,27 @@ export function createChatSurface(
?open=${active || !!work.pendingApprovals?.length}
>
<summary class=${stopped ? "stopped-head" : "work-head"}>
- ${sheenLabel(label, active)}${icon(ChevronRight, 14)}
+ ${sheenLabel(label, active)}<span class="activity-chevron">${icon(ChevronRight, 14)}</span>
</summary>
${stopped ? nothing : html`<div class="work-divider"></div>`}
<div class="work-rows">
${repeat(
- timeline,
- (item) => {
- if (item.kind === "tool")
- return `tool:${item.row.call?.seq ?? item.row.result?.seq ?? item.row.approval?.seq}`;
- if (item.kind === "approval") return `approval:${item.approval.requestId}`;
- return `${item.kind}:${item.activity.seq}`;
+ activityGroups(timeline),
+ (items) => timelineKey(items[0]!),
+ (items) => {
+ if (items[0]?.kind === "text") return renderTimelineItem(items[0], work);
+ const summary = activityGroupSummary(items, work.status);
+ const groupIcon = { read: BookOpen, search: Search, execute: Terminal, other: Wrench }[
+ summary.category
+ ];
+ return html`<details class="activity-group work-fold" ?open=${active || summary.attention}>
+ <summary class="work-head">
+ ${icon(groupIcon, 15)}<span>${summary.label}</span
+ ><span class="activity-chevron">${icon(ChevronRight, 14)}</span>
+ </summary>
+ <div class="work-rows">${repeat(items, timelineKey, (item) => renderTimelineItem(item, work))}</div>
+ </details>`;
},
- (item) => renderTimelineItem(item, work),
)}
${tail.trim() ? html`<div class="work-said streaming-text live-stream">${markdown(tail, true, streamingTextTail(baseline, work.activity))}</div>` : nothing}
</div>
@@ -2442,25 +2466,21 @@ export function createChatSurface(
function renderTimelineItem(item: TimelineItem, work: WorkBlock): TemplateResult {
const status = work.status;
const stale = work.stale === true;
- if (item.kind === "thinking") return thinkingRow(item.activity);
+ if (item.kind === "thinking") {
+ const thought = thinkingPresentation((item.activity.payload as { thinking?: string }).thinking ?? "");
+ return html`<details class="thinking-row">
+ <summary class="thinking-summary">
+ <span class="tool-icon">${icon(Brain, 15)}</span><span class="thinking-title">${thought.title}</span>
+ <span class="activity-chevron">${icon(ChevronRight, 14)}</span>
+ </summary>
+ <div class="thinking-body">${markdown(thought.body)}</div>
+ </details>`;
+ }
if (item.kind === "text") return messageRow(item.activity);
if (item.kind === "approval") return approvalMarker(item.approval);
return toolRow(item.row, work, status, stale);
}
- function thinkingRow(activity: ToolActivity): TemplateResult {
- const text = (activity.payload as { thinking?: string } | null)?.thinking ?? "";
- const preview = firstLine(text.replace(/\s+/g, " ").trim());
- return html`<details class="thinking-row">
- <summary class="thinking-summary">
- <span class="tool-icon">${icon(Brain, 13)}</span>
- <span class="tool-label" title=${preview ? `Thinking: ${preview}` : "Thinking"}>${preview || "Thinking"}</span>
- ${icon(ChevronRight, 14)}
- </summary>
- <div class="thinking-body">${markdown(text)}</div>
- </details>`;
- }
-
function messageRow(activity: ToolActivity): TemplateResult {
const text = (activity.payload as { text?: string } | null)?.text ?? "";
return html`<div class="work-message">${markdown(text)}</div>`;
@@ -2468,7 +2488,7 @@ export function createChatSurface(
const TOOL_META: Record<string, { icon: IconNode; active: string; done: string; attempted: string }> = {
execute: { icon: Terminal, active: "Running command", done: "Ran command", attempted: "Tried command" },
- read: { icon: FileText, active: "Reading file", done: "Read file", attempted: "Tried reading file" },
+ read: { icon: BookOpen, active: "Reading file", done: "Read file", attempted: "Tried reading file" },
write: { icon: Pencil, active: "Writing file", done: "Wrote file", attempted: "Tried writing file" },
publish: { icon: Rocket, active: "Publishing", done: "Published", attempted: "Tried publishing" },
recall: { icon: Brain, active: "Searching memory", done: "Searched memory", attempted: "Tried searching memory" },
@@ -2499,20 +2519,6 @@ export function createChatSurface(
.join(" ");
}
- const SESSION_ACTION_LABELS: Record<string, { active: string; done: string; attempted: string }> = {
- open: { active: "Creating", done: "Created", attempted: "Tried creating" },
- write: { active: "Messaging", done: "Messaged", attempted: "Tried messaging" },
- send_message: { active: "Messaging", done: "Messaged", attempted: "Tried messaging" },
- followup_task: { active: "Assigning", done: "Assigned", attempted: "Tried assigning" },
- wait: { active: "Waiting", done: "Waited", attempted: "Tried waiting" },
- interrupt: {
- active: "Interrupting",
- done: "Interrupted",
- attempted: "Tried interrupting",
- },
- read: { active: "Checking", done: "Checked", attempted: "Tried checking" },
- };
-
const SUBAGENT_MAIL_NOTES: Record<string, string> = {
final_answer: "finished",
no_reply: "finished without a reply",
@@ -2627,8 +2633,8 @@ export function createChatSurface(
return {};
}
- function toolPayloadText(payload: ToolPayload, omitted: string[] = []): string {
- const hidden = new Set(["tool", "callId", "workStartedAt", "workFinishedAt", ...omitted]);
+ function toolPayloadText(payload: ToolPayload): string {
+ const hidden = new Set(["tool", "callId", "workStartedAt", "workFinishedAt", "isError"]);
const entries = Object.entries(payload as Record<string, unknown>).filter(
([key, value]) => !hidden.has(key) && value !== undefined,
);
@@ -2637,11 +2643,12 @@ export function createChatSurface(
return JSON.stringify(Object.fromEntries(entries), null, 2);
}
- function toolPayloadCard(label: string, text: string): TemplateResult | typeof nothing {
+ function toolPayloadCard(label: string | null, text: string, loadFull?: () => void): TemplateResult | typeof nothing {
if (!text) return nothing;
return html`<div class="tool-payload-card">
- <div class="tool-payload-label">${label}</div>
+ ${label ? html`<div class="tool-payload-label">${label}</div>` : nothing}
<pre class="tool-payload-body">${text}</pre>
+ ${loadFull ? html`<div class="code-card-foot"><button class="show-full-btn" type="button" @click=${loadFull}>Show full ${label?.toLowerCase() ?? "command"}</button></div>` : nothing}
</div>`;
}
@@ -2650,18 +2657,14 @@ export function createChatSurface(
call: ToolPayload,
result: ToolPayload,
work: WorkBlock,
- activity: ToolActivity | null,
+ row: ToolRowModel,
): TemplateResult {
- const input = toolPayloadText(call);
- const hasExecOutput =
- toolCategory({ ...result, ...call, tool }) === "execute" && toolExecutionOutput(result) !== null;
- const output = toolPayloadText(result, [
- "isError",
- ...(hasExecOutput ? ["stdout", "stderr", "code", "timedOut", "result"] : []),
- ]);
+ const execution = toolCategory({ ...result, ...call, tool }) === "execute";
+ const input = execution ? (call.command ?? "") : toolPayloadText(call);
+ const output = execution ? "" : toolPayloadText(result);
return html`<div class="tool-disclosure">
- ${toolPayloadCard("Input", input)} ${hasExecOutput ? execOutputCard(result, work, activity) : nothing}
- ${toolPayloadCard("Result", output)}
+ ${toolPayloadCard(execution ? null : "Input", input, row.call?.truncated ? () => void loadFullEntry(work, row.call!) : undefined)}
+ ${toolPayloadCard("Result", output, row.result?.truncated ? () => void loadFullEntry(work, row.result!) : undefined)}
</div>`;
}
@@ -2683,68 +2686,53 @@ export function createChatSurface(
const meta = knownMeta ?? UNKNOWN_TOOL;
const name = toolName(tool) || "Tool";
const kind = toolRowKind(row, status);
- if (tool === "session") {
- const view = sessionToolView(call, result, sessionsState.list);
- const labels = SESSION_ACTION_LABELS[view.action] ?? UNKNOWN_TOOL;
- let sessionLabel = labels.attempted;
- if (kind === "running") sessionLabel = stale ? `${labels.active} (interrupted)` : labels.active;
- else if (kind === "ok") sessionLabel = labels.done;
- const sessionWhy = kind === "failed" ? firstLine(result.error ?? result.reason ?? "", 90) : "";
- const sessionAttempts = row.attempts && row.attempts > 1 ? `${row.attempts} attempts` : "";
- const sessionDetail = [view.detail, sessionWhy, sessionAttempts].filter(Boolean).join(" · ");
- return html`<div class="tool-row tool-${kind} tool-session">
- <span class="tool-icon">${icon(Bot, 15)}</span>
- <span class="tool-label"
- >${sessionLabel}${view.chipTitle ? html` ${subagentChip(view.chipTitle, view.sessionId)}` : nothing}${
- sessionDetail ? html` <span class="tool-detail">${sessionDetail}</span>` : nothing
- }</span
- >
- </div>`;
- }
let label = knownMeta ? meta.attempted : `Tried ${name}`;
if (kind === "approval") label = row.pending ? "Approval needed" : "Approval requested";
else if (kind === "running") {
const active = knownMeta ? meta.active : name;
label = stale ? `${active} — interrupted` : active;
} else if (kind === "ok") label = knownMeta ? meta.done : name;
+ else if (kind === "failed") label = `Failed ${name}`;
let why = "";
if (kind === "approval") why = firstLine(result.reason ?? "", 90);
else if (kind === "failed") why = firstLine(result.error ?? result.reason ?? "", 90);
const base = kind === "approval" ? "" : toolDetail(tool, call, result);
const attempts = row.attempts && row.attempts > 1 ? `${row.attempts} attempts` : "";
const detail = [base, why, attempts].filter(Boolean).join(" · ");
- let statusLabel = "";
- if (kind === "failed") statusLabel = "Failed";
- else if (kind === "approval" && detail) statusLabel = label;
- const visible = [statusLabel, detail || label].filter(Boolean).join(" · ");
+ const semantic = activityLabel(row, status);
+ const visible = semantic
+ ? [semantic, why, attempts, stale && kind === "running" ? "interrupted" : ""].filter(Boolean).join(" · ")
+ : [label, detail].filter(Boolean).join(" ");
+ const description = activityDescription(call, result);
+ const session = sessionPresentation(row, status);
+ const sessionView = session ? sessionToolView(call, result, sessionsState.list) : null;
+ const sessionDetail = [sessionView?.detail, session?.preview].filter(Boolean).join(" · ");
+ const rowIcon = session
+ ? Bot
+ : { search: Search, read: BookOpen, execute: meta.icon, other: meta.icon }[description.category];
const classes = ["tool-row", `tool-${kind}`].join(" ");
- const head = html`<span class="tool-icon">${icon(meta.icon, 13)}</span>
- <span class="tool-label" title=${detail ? `${label}: ${detail}` : label}>${visible}</span>`;
+ const head = html`<span class="tool-icon">${icon(rowIcon, 15)}</span>
+ ${session ? html`<span class="session-action">${session.label}</span>${sessionView?.chipTitle ? subagentChip(sessionView.chipTitle, sessionView.sessionId) : nothing}${sessionDetail ? html`<span class="tool-label session-message" title=${sessionDetail}>${sessionDetail}</span>` : nothing}` : html`<span class="tool-label" title=${detail ? `${label}: ${detail}` : label}>${visible}</span>`}`;
if (!row.call && !row.result) return html`<div class="${classes}">${head}</div>`;
- return html`<details class="${classes} tool-expandable">
- <summary class="tool-summary">${head}${icon(ChevronRight, 14)}</summary>
- ${toolDisclosure(tool, call, result, work, row.result ?? null)}
+ const renderDisclosure = (details: HTMLDetailsElement): void => {
+ const host = details.querySelector<HTMLElement>(".tool-disclosure-host");
+ if (host) render(details.open ? toolDisclosure(tool, call, result, work, row) : nothing, host);
+ };
+ return html`<details
+ class="${classes} tool-expandable"
+ @toggle=${(event: Event) => renderDisclosure(event.currentTarget as HTMLDetailsElement)}
+ >
+ <summary class="tool-summary">${head}<span class="activity-chevron">${icon(ChevronRight, 14)}</span></summary>
+ <div
+ class="tool-disclosure-host"
+ ${ref((element) => {
+ const details = element?.closest<HTMLDetailsElement>("details");
+ if (details) renderDisclosure(details);
+ })}
+ ></div>
</details>`;
}
- function execOutputCard(result: ToolPayload, work: WorkBlock, activity: ToolActivity | null): TemplateResult {
- const out = toolExecutionOutput(result) ?? "";
- return html`<div class="code-card">
- <div class="code-card-head"><span class="code-card-lang">bash</span></div>
- <pre class="code-card-body">${out}</pre>
- <div class="code-card-foot">
- exit ${result.code ?? "unknown"}${result.timedOut ? " · timed out" : ""}
- ${
- activity?.truncated
- ? html`<button class="show-full-btn" type="button" @click=${() => void loadFullEntry(work, activity)}>
- Show full output
- </button>`
- : nothing
- }
- </div>
- </div>`;
- }
-
function redrawTranscript(): void {
if (readonlyRedraw) readonlyRedraw();
else drawActiveChat();
diff --git a/plugins/web-ui/src/shell.css b/plugins/web-ui/src/shell.css
index be72b5595..f0beca213 100644
--- a/plugins/web-ui/src/shell.css
+++ b/plugins/web-ui/src/shell.css
@@ -2221,7 +2221,7 @@ qm-markdown .tok-in {
margin: 10px 0;
}
.work-fold {
- margin: 2px 0;
+ margin: 18px 0;
}
.work-message {
color: color-mix(in srgb, var(--muted-foreground) 85%, var(--foreground));
@@ -2280,9 +2280,7 @@ qm-markdown .tok-in {
}
.work summary.work-head {
list-style: none;
- cursor: pointer;
- padding-bottom: 8px;
- border-bottom: 1px solid var(--border);
+ cursor: default;
}
.work summary.work-head::-webkit-details-marker {
display: none;
@@ -2297,21 +2295,27 @@ qm-markdown .tok-in {
color: var(--muted-foreground);
}
.work-head .icon {
- color: var(--muted-foreground);
- transition: transform 140ms ease;
+ color: inherit;
}
-.work[open] > summary.work-head .icon,
-.work-fold[open] > summary.work-head .icon {
+.activity-chevron {
+ display: inline-flex;
+ flex: 0 0 auto;
+}
+.work[open] > summary > .activity-chevron,
+.work-fold[open] > summary > .activity-chevron,
+.tool-expandable[open] > summary > .activity-chevron {
transform: rotate(90deg);
}
.work-divider {
- height: 0;
- margin: 0 0 10px;
+ height: 1px;
+ background: var(--border);
+ margin: 8px 0 10px;
}
.work-rows {
display: flex;
flex-direction: column;
- gap: 5px;
+ gap: 2px;
+ margin-top: 8px;
}
.tool-row,
@@ -2320,16 +2324,16 @@ qm-markdown .tok-in {
align-items: center;
gap: 6px;
min-width: 0;
- font-size: 13px;
+ font-size: 14px;
line-height: 1.35;
- color: color-mix(in srgb, var(--muted-foreground) 80%, var(--background));
+ color: var(--muted-foreground);
}
.tool-row.tool-running {
color: var(--muted-foreground);
}
.tool-row .tool-summary {
- cursor: pointer;
- min-height: 24px;
+ cursor: default;
+ min-height: 26px;
}
.tool-icon {
display: inline-flex;
@@ -2356,12 +2360,12 @@ qm-markdown .tok-in {
display: flex;
align-items: center;
gap: 6px;
- min-height: 24px;
+ min-height: 26px;
min-width: 0;
list-style: none;
- cursor: pointer;
- color: color-mix(in srgb, var(--muted-foreground) 80%, var(--background));
- font-size: 13px;
+ cursor: default;
+ color: var(--muted-foreground);
+ font-size: 14px;
line-height: 1.35;
}
.thinking-summary::-webkit-details-marker {
@@ -2369,9 +2373,9 @@ qm-markdown .tok-in {
}
.thinking-summary > .icon:last-child {
flex: 0 0 auto;
- transition: transform 140ms ease;
}
-.thinking-row[open] > .thinking-summary > .icon:last-child {
+.thinking-row[open] > .thinking-summary > .icon:last-child,
+.thinking-row[open] > .thinking-summary > .activity-chevron {
transform: rotate(90deg);
}
.thinking-body {
@@ -2379,9 +2383,38 @@ qm-markdown .tok-in {
padding-left: 10px;
border-left: 2px solid var(--border);
color: var(--muted-foreground);
- font-size: 13px;
+ font-size: 14px;
line-height: 1.55;
}
+.thinking-title {
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.session-action {
+ flex: 0 1 auto;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.subagent-chip {
+ flex: 0 0 auto;
+ min-width: 0;
+ max-width: 55%;
+ padding: 2px 9px;
+ border-radius: 999px;
+ background: var(--secondary);
+ color: var(--foreground);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.session-message {
+ flex: 1 1 0;
+ margin-left: 4px;
+}
.tool-row.tool-approval {
color: var(--foreground);
}
@@ -2561,11 +2594,26 @@ qm-markdown .tok-in {
.tool-expandable > summary::-webkit-details-marker {
display: none;
}
-.tool-expandable > summary .icon:last-child {
- transition: transform 140ms ease;
+.work-head:hover,
+.tool-row .tool-summary:hover,
+.thinking-summary:hover {
+ color: var(--foreground);
+ text-shadow: 0 0 12px color-mix(in srgb, var(--foreground) 12%, transparent);
}
-.tool-expandable[open] > summary .icon:last-child {
- transform: rotate(90deg);
+.work-head:focus-visible,
+.tool-summary:focus-visible,
+.thinking-summary:focus-visible {
+ outline: 1px solid var(--muted-foreground);
+ outline-offset: 3px;
+ border-radius: 3px;
+}
+.tool-summary > .activity-chevron {
+ opacity: 0;
+}
+.tool-summary:hover > .activity-chevron,
+.tool-summary:focus-visible > .activity-chevron,
+.tool-expandable[open] > .tool-summary > .activity-chevron {
+ opacity: 1;
}
.tool-disclosure {
display: grid;
@@ -2598,8 +2646,12 @@ qm-markdown .tok-in {
white-space: pre-wrap;
word-break: break-word;
}
-.tool-disclosure .code-card {
- margin: 0;
+.tool-disclosure .code-card-foot {
+ font-family: var(--font-sans, inherit);
+ font-size: 11px;
+}
+.tool-disclosure .code-card-foot {
+ padding: 0 10px 7px;
}
.code-card {
@@ -11893,3 +11945,23 @@ body.app-edit-embed .custom-chat-shell.app-edit-chat > .chat-bottom-dock {
color: var(--muted-foreground);
overflow-wrap: anywhere;
}
+
+.dark .custom-chat {
+ --background: #181818;
+ --foreground: #eeeeee;
+ --muted-foreground: #a1a1a1;
+ --secondary: #232323;
+ --border: #303030;
+ background: var(--background);
+}
+
+:is(markdown-block, qm-markdown).markdown-content table {
+ font-size: 13px;
+ line-height: 1.65;
+}
+.activity-group > .work-head {
+ font-size: 14px;
+}
+.stopped-work[open] > .stopped-head > .activity-chevron {
+ transform: rotate(90deg);
+}
diff --git a/plugins/web-ui/test/activity-presentation.test.ts b/plugins/web-ui/test/activity-presentation.test.ts
new file mode 100644
index 000000000..7529c48c7
--- /dev/null
+++ b/plugins/web-ui/test/activity-presentation.test.ts
@@ -0,0 +1,123 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import {
+ activityDescription,
+ activityGroupSummary,
+ activityGroups,
+ activityLabel,
+ compactPath,
+ thinkingPresentation,
+ sessionPresentation,
+} from "../src/activity-presentation.ts";
+import type { ToolRowModel, ToolPayload, TimelineItem } from "../src/timeline.ts";
+
+function row(command: string, result: ToolPayload | null = { code: 0 }): ToolRowModel {
+ return {
+ call: {
+ seq: 1,
+ parentSeq: null,
+ type: "tool_call",
+ payload: { tool: "sandbox", action: "exec", command },
+ createdAt: 1,
+ },
+ result: result ? { seq: 2, parentSeq: null, type: "tool_result", payload: result, createdAt: 2 } : null,
+ };
+}
+
+test("simple shell reads and searches get semantic labels, compound commands stay exact", () => {
+ assert.equal(activityLabel(row("cat /workspace/src/main.ts"), "complete"), "main.ts");
+ assert.equal(activityLabel(row("rg -n 'gateway' src/main.ts"), "complete"), "Searched for gateway in main.ts");
+ for (const command of [
+ "cat file; rm file",
+ "rg foo src | head -10",
+ "cat $(find .)",
+ "rg -g '*.ts' foo src",
+ "python3 <<'PY'\nprint(1)\nPY",
+ ]) {
+ assert.equal(activityDescription({ tool: "execute", command }).category, "execute");
+ }
+ assert.equal(
+ activityLabel(row("rg -n 'gateway|secret' src/main.ts"), "complete"),
+ "Searched for gateway|secret in main.ts",
+ );
+ assert.equal(activityLabel(row("sed -n '1,120p' src/main.ts"), "complete"), "main.ts");
+ assert.equal(activityLabel(row("rg --files src"), "complete"), "Searched for files in src");
+ assert.equal(compactPath("skill://publish/SKILL.md"), "publish/SKILL.md");
+});
+
+test("status labels never report missing or failed results as successful", () => {
+ assert.equal(activityLabel(row("npm test", null), "working"), "Running npm test");
+ assert.equal(activityLabel(row("npm test", null), "complete"), "Tried running npm test");
+ assert.equal(activityLabel(row("cat missing", { code: 1 }), "complete"), "Failed to read missing");
+ assert.equal(activityLabel(row("npm test", { blocked: "needs_approval" }), "working"), null);
+});
+
+test("groups describe categories and surface errors and approvals", () => {
+ const items: TimelineItem[] = [
+ { kind: "tool", row: row("cat README.md") },
+ { kind: "tool", row: row("npm test") },
+ ];
+ assert.deepEqual(activityGroupSummary(items, "complete"), {
+ label: "Read files, ran commands",
+ category: "read",
+ attention: false,
+ });
+ items.push({ kind: "tool", row: row("false", { code: 1 }) });
+ assert.equal(activityGroupSummary(items, "complete").attention, true);
+ assert.match(activityGroupSummary(items, "complete").label, /1 failed/);
+ items.push({ kind: "tool", row: row("run", { blocked: "needs_approval" }) });
+ assert.doesNotMatch(activityGroupSummary(items, "working").label, /Approval needed/);
+});
+
+test("thinking titles become disclosure labels without repeating the heading", () => {
+ for (const heading of ["**Organizing the setup**", "## Organizing the setup", "__Organizing the setup__"]) {
+ assert.deepEqual(thinkingPresentation(`${heading}\n\nBody text`), {
+ title: "Organizing the setup",
+ body: "Body text",
+ });
+ }
+ assert.deepEqual(thinkingPresentation("A thought without a heading"), {
+ title: "Thought process",
+ body: "A thought without a heading",
+ });
+ assert.equal(thinkingPresentation("**Bold** inside a sentence").title, "Thought process");
+});
+
+test("session actions identify their recipient and retain failure state", () => {
+ const tool = row("");
+ tool.call!.payload = {
+ tool: "session",
+ action: "send_message",
+ target: "compaction-exact",
+ text: "Check the remaining tests",
+ };
+ assert.deepEqual(sessionPresentation(tool, "complete"), {
+ label: "Sent message to",
+ target: "compaction-exact",
+ preview: "Check the remaining tests",
+ });
+ tool.result!.payload = { isError: true };
+ assert.equal(sessionPresentation(tool, "complete")?.label, "Failed to send message to");
+ tool.call!.payload = { tool: "session", action: "open", name: "worker" };
+ tool.result!.payload = { title: "Named worker", sessionId: "id" };
+ assert.equal(sessionPresentation(tool, "complete")?.target, "Named worker");
+});
+
+test("activity grouping preserves speech boundaries and chronological item identity", () => {
+ const tool: TimelineItem = { kind: "tool", row: row("npm test") };
+ const speech: TimelineItem = {
+ kind: "text",
+ activity: { seq: 8, parentSeq: null, type: "text", payload: { text: "Checking" }, createdAt: 2 },
+ };
+ const thought: TimelineItem = {
+ kind: "thinking",
+ activity: { seq: 9, parentSeq: null, type: "thinking", payload: { thinking: "**Check**\nDetails" }, createdAt: 3 },
+ };
+ assert.deepEqual(activityGroups([tool, speech, thought, tool]), [[tool], [speech], [thought, tool]]);
+ assert.deepEqual(activityGroups([]), []);
+});
+
+test("resolved approval history does not mark a group as needing action", () => {
+ const blocked = row("npm test", { blocked: "needs_approval" });
+ assert.equal(activityGroupSummary([{ kind: "tool", row: blocked }], "complete").attention, false);
+});
diff --git a/plugins/web-ui/test/css-vars.test.ts b/plugins/web-ui/test/css-vars.test.ts
index 5b8203b99..5941c858e 100644
--- a/plugins/web-ui/test/css-vars.test.ts
+++ b/plugins/web-ui/test/css-vars.test.ts
@@ -32,7 +32,7 @@ test("every drop zone the canvas renders has a positioning rule in shell.css", (
assert.deepEqual(missing, [], "drop zones rendered with no .zone-<edge> rule (they collapse to 0×0)");
});
-test("only the elevated chat surfaces paint a shadow", () => {
+test("chat shadows stay limited to elevated surfaces and subtle activity hover glow", () => {
const elevated = [".pinned-strip", ".message-stack .user-row.stuck > .user-bubble"];
const rules = shellCss.replace(/\/\*[\s\S]*?\*\//g, "");
const painted = [...rules.matchAll(/([^{}]+)\{([^{}]*)\}/g)].flatMap((rule) =>
@@ -44,9 +44,14 @@ test("only the elevated chat surfaces paint a shadow", () => {
painted,
[
...elevated.map((selector) => [selector, "box", "var(--chat-surface-shadow)"]),
+ [
+ ".work-head:hover,\n.tool-row .tool-summary:hover,\n.thinking-summary:hover",
+ "text",
+ "0 0 12px color-mix(in srgb, var(--foreground) 12%, transparent)",
+ ],
[".composer-wrap", "box", "0 2px 5px rgb(0 0 0 / 0.05), 0 8px 24px rgb(0 0 0 / 0.06)"],
],
- "only pinned surfaces use the shared shadow; the composer keeps its softer shadow",
+ "pinned surfaces and the composer retain their shadows; activity glow appears only on hover",
);
const inlineShadows = [...tsSource.matchAll(/(?:box|text)-shadow\s*:\s*([^;}]+)/g)]
.map((m) => m[1].trim())
diff --git a/plugins/web-ui/test/work-fold-source.test.ts b/plugins/web-ui/test/work-fold-source.test.ts
index 72c05571e..202624b58 100644
--- a/plugins/web-ui/test/work-fold-source.test.ts
+++ b/plugins/web-ui/test/work-fold-source.test.ts
@@ -25,23 +25,24 @@ test("a demoted post-delivery self-log remains auditable but is omitted from the
});
test("the fold chevron rotates when a work-fold is open", () => {
- assert.match(css, /\.work-fold\[open\] > summary\.work-head \.icon \{[\s\S]{0,80}?transform: rotate\(90deg\);/);
+ assert.match(css, /\.work-fold\[open\] > summary > \.activity-chevron[\s\S]{0,160}?transform: rotate\(90deg\);/);
});
test("expanded tool activity uses a compact log rhythm", () => {
- assert.match(css, /\.work-divider \{[\s\S]{0,120}?margin: 0 0 10px;/);
- assert.match(css, /\.work-rows \{[\s\S]{0,120}?gap: 5px;/);
- assert.match(css, /\.tool-row,[\s\S]{0,220}?font-size: 13px;[\s\S]{0,80}?line-height: 1\.35;/);
- assert.match(css, /\.tool-row \.tool-summary \{[\s\S]{0,80}?min-height: 24px;/);
- assert.match(chat, /icon\(meta\.icon, 13\)/);
+ assert.match(css, /\.work-divider \{[\s\S]{0,120}?margin: 8px 0 10px;/);
+ assert.match(css, /\.work-rows \{[\s\S]{0,120}?gap: 2px;/);
+ assert.match(css, /\.tool-row,[\s\S]{0,220}?font-size: 14px;[\s\S]{0,80}?line-height: 1\.35;/);
+ assert.match(css, /\.tool-row \.tool-summary \{[\s\S]{0,80}?min-height: 26px;/);
+ assert.match(chat, /icon\(rowIcon, 15\)/);
assert.match(chat, /icon\(Wrench, 13\)/);
});
-test("every recorded tool can disclose its complete input and result", () => {
+test("execution shows only its command while other tools disclose input and result", () => {
assert.match(chat, /function toolDisclosure\(/);
- assert.match(chat, /toolPayloadCard\("Input", input\)/);
- assert.match(chat, /toolPayloadCard\("Result", output\)/);
- assert.match(chat, /<details class="\$\{classes\} tool-expandable">/);
+ assert.match(chat, /const output = execution \? "" : toolPayloadText\(result\);/);
+ assert.match(chat, /toolPayloadCard\(execution \? null : "Input", input,/);
+ assert.match(chat, /toolPayloadCard\("Result", output,/);
+ assert.match(chat, /<details\s+class="\$\{classes\} tool-expandable"/);
assert.match(css, /\.tool-payload-body \{[\s\S]{0,300}?white-space: pre-wrap;/);
});
@@ -59,8 +60,8 @@ test("thinking stays in sequence but is independently collapsible", () => {
});
test("dense activity rows let their icons carry repeated type labels", () => {
- assert.match(chat, /\$\{preview \|\| "Thinking"\}/);
- assert.match(chat, /if \(kind === "failed"\) statusLabel = "Failed";/);
+ assert.match(chat, /thinkingPresentation\(/);
+ assert.match(chat, /activityLabel\(row, status\)/);
assert.match(chat, />\$\{visible\}<\/span>/);
assert.doesNotMatch(chat, />Thinking\$\{preview/);
assert.doesNotMatch(chat, />\$\{label\}\$\{detail/);
@@ -68,7 +69,6 @@ test("dense activity rows let their icons carry repeated type labels", () => {
test("activity previews use the row width before ellipsizing", () => {
assert.match(chat, /function firstLine\(s: string, max\?: number\)/);
- assert.match(chat, /const preview = firstLine\(text\.replace\(\/\\s\+\/g, " "\)\.trim\(\)\);/);
assert.match(css, /\.tool-label \{[\s\S]{0,80}?flex: 1 1 auto;/);
assert.match(css, /\.tool-label \{[\s\S]{0,180}?text-overflow: ellipsis;/);
});
@@ -81,3 +81,11 @@ test("stopped work shares posted reply rendering and shows one status without ac
assert.match(block, /if \(stopped && fold === nothing\) fold = html`<div class="stopped-head">/);
assert.doesNotMatch(chat, /stopped-note|function stoppedWork/);
});
+
+test("session rows preserve aggregate details and only render named target chips", () => {
+ assert.match(
+ chat,
+ /sessionView\?\.chipTitle \? subagentChip\(sessionView.chipTitle, sessionView.sessionId\) : nothing/,
+ );
+ assert.match(chat, /const sessionDetail = \[sessionView\?\.detail, session\?\.preview\]/);
+});