Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

gui: categorize + make in-chat tool cards readable

Pranav Pea99e7d70bb0
diff --git a/gui/src/components/chat/ChatActivityRow.tsx b/gui/src/components/chat/ChatActivityRow.tsx
index bfa3dabf..b7809e61 100644
--- a/gui/src/components/chat/ChatActivityRow.tsx
+++ b/gui/src/components/chat/ChatActivityRow.tsx
@@ -5,6 +5,7 @@ import {
ChevronDown,
ChevronRight,
FileText,
+ GitPullRequest,
Globe,
ListTodo,
Loader2,
@@ -32,8 +33,10 @@ import type {
ActivityOperationRowProps,
ChatActivityRowProps,
} from "./types/chatComponents";
+import type { ActivityOperation } from "./types/chatThread";
import { ChatMarkdown } from "./ChatMarkdown";
import { formatOperationLabel } from "./utils/chatActivity";
+import { classifyUnknownToolName } from "./utils/classifyActivityResult";
import { ChatInlineText } from "./ChatInlineText";
import { ChatStatusLabel } from "./ChatStatusLabel";
import { ActivityResultRenderer } from "./activity-results/ActivityResultRenderer";
@@ -49,8 +52,21 @@ const activityTextClassName = cn(
CHAT_MUTED_TEXT_CLASS,
);
-function operationIcon(kind: string): ComponentType<{ className?: string }> {
- switch (kind) {
+function unknownToolIcon(name: string): ComponentType<{ className?: string }> {
+ switch (classifyUnknownToolName(name)) {
+ case "web":
+ return Globe;
+ case "github":
+ return GitPullRequest;
+ default:
+ return Activity;
+ }
+}
+
+function operationIcon(
+ operation: ActivityOperation,
+): ComponentType<{ className?: string }> {
+ switch (operation.detail.kind) {
case "file_read":
return FileText;
case "file_update":
@@ -73,6 +89,8 @@ function operationIcon(kind: string): ComponentType<{ className?: string }> {
case "todo_read":
case "todo_write":
return ListTodo;
+ case "unknown":
+ return unknownToolIcon(operation.name);
default:
return Activity;
}
@@ -107,7 +125,7 @@ function ActivityOperationRow({
const isExpandable = result != null;
const label = formatOperationLabel(operation, workspacePath);
const isCommand = operation.detail.kind === "shell";
- const Icon = operationIcon(operation.detail.kind);
+ const Icon = operationIcon(operation);
const content = (
<>
diff --git a/gui/src/components/chat/activity-results/ActivityResultCard.tsx b/gui/src/components/chat/activity-results/ActivityResultCard.tsx
index a45af6f9..807b7b32 100644
--- a/gui/src/components/chat/activity-results/ActivityResultCard.tsx
+++ b/gui/src/components/chat/activity-results/ActivityResultCard.tsx
@@ -1,40 +1,105 @@
-import { Check, Copy } from "lucide-react";
+import { Fragment, useMemo } from "react";
+import { AlertTriangle, Check, Copy } from "lucide-react";
import { Button } from "@/components/ui/Button";
+import { cn } from "@/utils/cn";
import { useCopyToClipboard } from "@/hooks/useCopyToClipboard";
import { CHAT_BODY_TEXT_CLASS } from "../constants/chatStyles";
+import { ChatMarkdown } from "../ChatMarkdown";
+import { tokenizeCode } from "../markdown/highlight";
import type {
ActivityResultCardProps,
- ActivityResultPreformattedBodyProps,
+ CodeBodyProps,
+ ProseBodyProps,
+ TerminalBodyProps,
} from "../types/chatComponents";
-export function ActivityResultPreformattedBody({
- text,
-}: ActivityResultPreformattedBodyProps) {
+const SCROLL_BODY_CLASS =
+ "block max-h-72 w-full max-w-full overflow-y-auto px-3.5 py-2.5";
+
+/** Shell / terminal output: monospace, preserves spacing, but wraps long lines. */
+export function TerminalBody({ text }: TerminalBodyProps) {
+ return (
+ <pre
+ className={cn(
+ SCROLL_BODY_CLASS,
+ "whitespace-pre-wrap break-words font-mono text-foreground",
+ CHAT_BODY_TEXT_CLASS,
+ )}
+ >
+ {text}
+ </pre>
+ );
+}
+
+/** Code / JSON output: syntax-highlighted via the shared `.sh-*` token classes. */
+export function CodeBody({ text }: CodeBodyProps) {
+ const tokens = useMemo(() => tokenizeCode(text), [text]);
return (
- <pre className={`block max-h-72 w-full max-w-full overflow-x-auto overflow-y-auto whitespace-pre px-3.5 py-2.5 ${CHAT_BODY_TEXT_CLASS} text-foreground`}>
- <code className="inline-block min-w-full w-max align-top whitespace-pre">
- {text}
- </code>
+ <pre
+ className={cn(
+ SCROLL_BODY_CLASS,
+ "whitespace-pre-wrap break-words font-mono text-foreground",
+ CHAT_BODY_TEXT_CLASS,
+ )}
+ >
+ {tokens.map((token, index) => {
+ if (token.className === "sh-break" || token.className === "sh-space") {
+ return <Fragment key={index}>{token.value}</Fragment>;
+ }
+ return (
+ <span key={index} className={token.className}>
+ {token.value}
+ </span>
+ );
+ })}
</pre>
);
}
+/** Prose / fetched docs: rendered as Markdown so it wraps and formats links. */
+export function ProseBody({ text, workspacePath, className }: ProseBodyProps) {
+ return (
+ <div className="max-h-72 overflow-y-auto px-3.5 py-2.5">
+ <ChatMarkdown
+ text={text}
+ workspacePath={workspacePath}
+ className={className}
+ />
+ </div>
+ );
+}
+
export function ActivityResultCard({
children,
copyText,
footer,
title,
+ tone = "default",
}: ActivityResultCardProps) {
const { copied, copy } = useCopyToClipboard();
const canCopy = copyText != null && copyText.length > 0;
+ const isError = tone === "error";
return (
- <div className="min-w-0 max-w-full overflow-hidden rounded-2xl border border-border bg-card shadow-[var(--elevation-sm)]">
- <div className="flex items-center gap-2 border-b border-border px-3.5 py-2.5 text-xs/relaxed text-foreground">
- <div className="min-w-0 flex-1 truncate text-foreground">
- {title}
- </div>
+ <div
+ className={cn(
+ "min-w-0 max-w-full overflow-hidden rounded-2xl border shadow-[var(--elevation-sm)]",
+ isError
+ ? "border-destructive/40 bg-destructive/5"
+ : "border-border bg-card",
+ )}
+ >
+ <div
+ className={cn(
+ "flex items-center gap-2 border-b px-3.5 py-2.5 text-xs/relaxed",
+ isError
+ ? "border-destructive/30 text-destructive"
+ : "border-border text-foreground",
+ )}
+ >
+ {isError ? <AlertTriangle className="size-3.5 shrink-0" /> : null}
+ <div className="min-w-0 flex-1 truncate">{title}</div>
{canCopy ? (
<Button
variant="ghost"
@@ -50,7 +115,12 @@ export function ActivityResultCard({
) : null}
</div>
{children}
- <div className="flex items-center justify-between gap-3 border-t border-border px-3.5 py-2.5 text-xs/relaxed text-foreground">
+ <div
+ className={cn(
+ "flex items-center justify-between gap-3 border-t px-3.5 py-2.5 text-xs/relaxed",
+ isError ? "border-destructive/30 text-destructive" : "border-border text-foreground",
+ )}
+ >
<span className="min-w-0 flex-1 truncate">{footer.leading}</span>
<span className="shrink-0">{footer.trailing}</span>
</div>
diff --git a/gui/src/components/chat/activity-results/ActivityResultRenderer.tsx b/gui/src/components/chat/activity-results/ActivityResultRenderer.tsx
index 44cefcda..e8e905b7 100644
--- a/gui/src/components/chat/activity-results/ActivityResultRenderer.tsx
+++ b/gui/src/components/chat/activity-results/ActivityResultRenderer.tsx
@@ -1,6 +1,5 @@
import { FileDiffResult } from "./FileDiffResult";
-import { ShellOutputResult } from "./ShellOutputResult";
-import { TextResult } from "./TextResult";
+import { ContentResult } from "./ContentResult";
import type { ActivityResultRendererProps } from "../types/chatComponents";
export function ActivityResultRenderer({
@@ -10,10 +9,8 @@ export function ActivityResultRenderer({
switch (result.kind) {
case "file_diff":
return <FileDiffResult result={result} workspacePath={workspacePath} />;
- case "shell":
- return <ShellOutputResult result={result} />;
- case "text":
- return <TextResult result={result} />;
+ case "content":
+ return <ContentResult result={result} workspacePath={workspacePath} />;
default:
return null;
}
diff --git a/gui/src/components/chat/activity-results/ContentResult.tsx b/gui/src/components/chat/activity-results/ContentResult.tsx
new file mode 100644
index 00000000..406fd8ce
--- /dev/null
+++ b/gui/src/components/chat/activity-results/ContentResult.tsx
@@ -0,0 +1,45 @@
+import {
+ ActivityResultCard,
+ CodeBody,
+ ProseBody,
+ TerminalBody,
+} from "./ActivityResultCard";
+import { CHAT_MUTED_TEXT_CLASS } from "../constants/chatStyles";
+import { ChatMarkdown } from "../ChatMarkdown";
+import type { ContentResultProps } from "../types/chatComponents";
+
+export function ContentResult({ result, workspacePath }: ContentResultProps) {
+ // Short, non-error prose renders inline with no card chrome — just a light,
+ // muted block sitting under the operation row.
+ if (result.presentation === "inline") {
+ return (
+ <div className="py-0.5">
+ <ChatMarkdown
+ text={result.text}
+ workspacePath={workspacePath}
+ className={CHAT_MUTED_TEXT_CLASS}
+ />
+ </div>
+ );
+ }
+
+ const body =
+ result.format === "terminal" ? (
+ <TerminalBody text={result.text} />
+ ) : result.format === "code" ? (
+ <CodeBody text={result.text} />
+ ) : (
+ <ProseBody text={result.text} workspacePath={workspacePath} />
+ );
+
+ return (
+ <ActivityResultCard
+ title={result.title}
+ copyText={result.copyText}
+ footer={result.footer}
+ tone={result.tone}
+ >
+ {body}
+ </ActivityResultCard>
+ );
+}
diff --git a/gui/src/components/chat/activity-results/ShellOutputResult.tsx b/gui/src/components/chat/activity-results/ShellOutputResult.tsx
deleted file mode 100644
index 4ee0ef73..00000000
--- a/gui/src/components/chat/activity-results/ShellOutputResult.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import { ActivityResultCard, ActivityResultPreformattedBody } from "./ActivityResultCard";
-import type { ShellOutputResultProps } from "../types/chatComponents";
-
-export function ShellOutputResult({ result }: ShellOutputResultProps) {
- return (
- <ActivityResultCard
- title={result.title}
- copyText={result.copyText}
- footer={result.footer}
- >
- <ActivityResultPreformattedBody text={result.text} />
- </ActivityResultCard>
- );
-}
diff --git a/gui/src/components/chat/activity-results/TextResult.tsx b/gui/src/components/chat/activity-results/TextResult.tsx
deleted file mode 100644
index 4e681c68..00000000
--- a/gui/src/components/chat/activity-results/TextResult.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import { ActivityResultCard, ActivityResultPreformattedBody } from "./ActivityResultCard";
-import type { TextResultProps } from "../types/chatComponents";
-
-export function TextResult({ result }: TextResultProps) {
- return (
- <ActivityResultCard
- title={result.title}
- copyText={result.copyText}
- footer={result.footer}
- >
- <ActivityResultPreformattedBody text={result.text} />
- </ActivityResultCard>
- );
-}
diff --git a/gui/src/components/chat/activity-results/types/activityResult.ts b/gui/src/components/chat/activity-results/types/activityResult.ts
index f0431be5..b2cd87e2 100644
--- a/gui/src/components/chat/activity-results/types/activityResult.ts
+++ b/gui/src/components/chat/activity-results/types/activityResult.ts
@@ -7,17 +7,16 @@ export interface ActivityResultFooter {
trailing: ReactNode;
}
-interface ActivityResultBase {
- copyText: string;
-}
+/** How the body text should be rendered. Diffs are a separate result kind. */
+export type ActivityResultFormat = "terminal" | "code" | "prose";
+
+/** Visual category of the result. */
+export type ActivityResultTone = "default" | "error";
+
+/** Whether the result gets full card chrome or renders inline under the row. */
+export type ActivityResultPresentation = "inline" | "card";
export type ActivityResultModel =
- | (ActivityResultBase & {
- kind: "shell";
- footer: ActivityResultFooter;
- text: string;
- title: "Shell";
- })
| {
kind: "file_diff";
copyText: string;
@@ -25,9 +24,15 @@ export type ActivityResultModel =
patch: string;
operation?: FileOperation;
}
- | (ActivityResultBase & {
- kind: "text";
- footer: ActivityResultFooter;
+ | {
+ kind: "content";
+ format: ActivityResultFormat;
+ tone: ActivityResultTone;
+ presentation: ActivityResultPresentation;
+ /** Display label for code outputs, e.g. "json". */
+ language?: string;
+ title: string;
text: string;
- title: "Output";
- });
+ copyText: string;
+ footer: ActivityResultFooter;
+ };
diff --git a/gui/src/components/chat/event-rows/ChatStatusEventRow.tsx b/gui/src/components/chat/event-rows/ChatStatusEventRow.tsx
index dfdc657f..427b49f1 100644
--- a/gui/src/components/chat/event-rows/ChatStatusEventRow.tsx
+++ b/gui/src/components/chat/event-rows/ChatStatusEventRow.tsx
@@ -52,8 +52,8 @@ function StatusRow({
function StatusOutputRow({ text }: StatusOutputRowProps) {
return (
- <article className={`max-w-3xl min-w-0 select-text overflow-x-auto ${CHAT_BODY_TEXT_CLASS} text-muted-foreground`}>
- <pre className="m-0 max-w-full overflow-x-auto whitespace-pre font-mono leading-6">
+ <article className={`max-w-3xl min-w-0 select-text ${CHAT_BODY_TEXT_CLASS} text-muted-foreground`}>
+ <pre className="m-0 max-w-full whitespace-pre-wrap break-words font-mono leading-6">
{text}
</pre>
</article>
diff --git a/gui/src/components/chat/types/chatComponents.ts b/gui/src/components/chat/types/chatComponents.ts
index 79a24d99..1a92ca54 100644
--- a/gui/src/components/chat/types/chatComponents.ts
+++ b/gui/src/components/chat/types/chatComponents.ts
@@ -8,7 +8,10 @@ import type {
TranscriptMessage,
} from "@/services/desktop/types/contracts";
-import type { ActivityResultModel } from "../activity-results/types/activityResult";
+import type {
+ ActivityResultModel,
+ ActivityResultTone,
+} from "../activity-results/types/activityResult";
import type {
ActivityItem,
ActivityOperation,
@@ -33,12 +36,28 @@ export interface ActivityResultCardProps {
trailing: ReactNode;
};
title: ReactNode;
+ tone?: ActivityResultTone;
+}
+
+export interface TerminalBodyProps {
+ text: string;
}
-export interface ActivityResultPreformattedBodyProps {
+export interface CodeBodyProps {
text: string;
}
+export interface ProseBodyProps {
+ text: string;
+ workspacePath?: string | null;
+ className?: string;
+}
+
+export interface ContentResultProps {
+ result: Extract<ActivityResultModel, { kind: "content" }>;
+ workspacePath: string | null;
+}
+
export interface ActivityResultRendererProps {
result: ActivityResultModel;
workspacePath: string | null;
@@ -167,10 +186,6 @@ export interface RenderChatThreadItemOptions {
itemCount: number;
}
-export interface ShellOutputResultProps {
- result: Extract<ActivityResultModel, { kind: "shell" }>;
-}
-
export interface StatusOutputRowProps {
text: string;
}
@@ -185,10 +200,6 @@ export interface TextOnlyMessageProps {
text: string;
}
-export interface TextResultProps {
- result: Extract<ActivityResultModel, { kind: "text" }>;
-}
-
export interface ToolEndRowProps {
isError: boolean;
name: string;
diff --git a/gui/src/components/chat/utils/chatActivity.ts b/gui/src/components/chat/utils/chatActivity.ts
index 095fea8e..3123e0a9 100644
--- a/gui/src/components/chat/utils/chatActivity.ts
+++ b/gui/src/components/chat/utils/chatActivity.ts
@@ -1,4 +1,18 @@
import type { ActivityOperation } from "../types/chatThread";
+import { classifyUnknownToolName } from "./classifyActivityResult";
+
+// Turn a raw tool name like "webfetch" / "web_fetch" into a readable verb
+// phrase, e.g. "Fetched web content".
+function formatUnknownToolLabel(name: string): string {
+ switch (classifyUnknownToolName(name)) {
+ case "web":
+ return "Fetched web content";
+ case "github":
+ return `Ran ${name} on GitHub`;
+ default:
+ return `Ran ${name}`;
+ }
+}
function formatPath(path: string, workspacePath: string | null): string {
if (workspacePath == null || path.startsWith(workspacePath) === false) {
@@ -59,7 +73,7 @@ export function formatOperationLabel(
case "todo_write":
return `Updated ${operation.detail.count} todo item${operation.detail.count === 1 ? "" : "s"}`;
case "unknown":
- return `Ran ${operation.detail.name}`;
+ return formatUnknownToolLabel(operation.detail.name);
default:
return operation.name;
}
diff --git a/gui/src/components/chat/utils/classifyActivityResult.test.ts b/gui/src/components/chat/utils/classifyActivityResult.test.ts
new file mode 100644
index 00000000..e7604ad4
--- /dev/null
+++ b/gui/src/components/chat/utils/classifyActivityResult.test.ts
@@ -0,0 +1,107 @@
+import { describe, expect, test } from "bun:test";
+
+import {
+ classifyUnknownToolName,
+ detectContentFormat,
+ resolvePresentation,
+} from "./classifyActivityResult";
+
+describe("classifyUnknownToolName", () => {
+ test("maps webfetch-like names to web", () => {
+ expect(classifyUnknownToolName("webfetch")).toBe("web");
+ expect(classifyUnknownToolName("web_fetch")).toBe("web");
+ expect(classifyUnknownToolName("http_get")).toBe("web");
+ });
+
+ test("maps github-like names to github", () => {
+ expect(classifyUnknownToolName("github_create_pr")).toBe("github");
+ expect(classifyUnknownToolName("gh_issue")).toBe("github");
+ });
+
+ test("falls back to generic", () => {
+ expect(classifyUnknownToolName("do_thing")).toBe("generic");
+ });
+});
+
+describe("detectContentFormat", () => {
+ test("shell output is terminal", () => {
+ const actual = detectContentFormat({
+ detailKind: "shell",
+ name: "shell",
+ isShellOutput: true,
+ text: "ok",
+ });
+ expect(actual.format).toBe("terminal");
+ });
+
+ test("unknown web tool is prose", () => {
+ const actual = detectContentFormat({
+ detailKind: "unknown",
+ name: "webfetch",
+ isShellOutput: false,
+ text: "Some fetched page body that is plain text.",
+ });
+ expect(actual.format).toBe("prose");
+ });
+
+ test("JSON output is code with json language", () => {
+ const actual = detectContentFormat({
+ detailKind: "unknown",
+ name: "lookup",
+ isShellOutput: false,
+ text: '{"a": 1, "b": [2, 3]}',
+ });
+ expect(actual.format).toBe("code");
+ expect(actual.language).toBe("json");
+ });
+
+ test("code-dense output is code", () => {
+ const actual = detectContentFormat({
+ detailKind: "unknown",
+ name: "gen",
+ isShellOutput: false,
+ text: "const x = 1;\nfunction f() {\n return x;\n}",
+ });
+ expect(actual.format).toBe("code");
+ });
+
+ test("plain prose stays prose", () => {
+ const actual = detectContentFormat({
+ detailKind: "unknown",
+ name: "summarize",
+ isShellOutput: false,
+ text: "This is a normal sentence describing the result.",
+ });
+ expect(actual.format).toBe("prose");
+ });
+});
+
+describe("resolvePresentation", () => {
+ test("short non-error prose renders inline", () => {
+ expect(
+ resolvePresentation({ text: "Done.", tone: "default", format: "prose" }),
+ ).toBe("inline");
+ });
+
+ test("errors always get a card", () => {
+ expect(
+ resolvePresentation({ text: "boom", tone: "error", format: "prose" }),
+ ).toBe("card");
+ });
+
+ test("terminal and code always get a card", () => {
+ expect(
+ resolvePresentation({ text: "x", tone: "default", format: "terminal" }),
+ ).toBe("card");
+ expect(
+ resolvePresentation({ text: "x", tone: "default", format: "code" }),
+ ).toBe("card");
+ });
+
+ test("long prose gets a card", () => {
+ const longText = Array.from({ length: 8 }, () => "line").join("\n");
+ expect(
+ resolvePresentation({ text: longText, tone: "default", format: "prose" }),
+ ).toBe("card");
+ });
+});
diff --git a/gui/src/components/chat/utils/classifyActivityResult.ts b/gui/src/components/chat/utils/classifyActivityResult.ts
new file mode 100644
index 00000000..f498f0b7
--- /dev/null
+++ b/gui/src/components/chat/utils/classifyActivityResult.ts
@@ -0,0 +1,124 @@
+import type {
+ ActivityResultFormat,
+ ActivityResultPresentation,
+ ActivityResultTone,
+} from "../activity-results/types/activityResult";
+
+/**
+ * Coarse category for a tool, used to pick an icon/label and a sensible body
+ * format. The backend collapses many real tools (webfetch, gh, MCP servers)
+ * into `ToolCallDetail.kind: "unknown"`, so for those we fall back to matching
+ * the tool's name.
+ */
+export type ToolCategory = "web" | "github" | "generic";
+
+const WEB_NAME = /fetch|web|http|url|browse|crawl|scrape/i;
+const GITHUB_NAME = /github|(^|[_-])gh($|[_-])|gitlab|\bpr\b|pull[_-]?request/i;
+
+/** Classify an `unknown`-kind tool by its name. */
+export function classifyUnknownToolName(name: string): ToolCategory {
+ if (WEB_NAME.test(name)) {
+ return "web";
+ }
+ if (GITHUB_NAME.test(name)) {
+ return "github";
+ }
+ return "generic";
+}
+
+function looksLikeJson(text: string): boolean {
+ const trimmed = text.trim();
+ if (trimmed.length < 2) {
+ return false;
+ }
+ const first = trimmed[0];
+ const last = trimmed[trimmed.length - 1];
+ const bracketed =
+ (first === "{" && last === "}") || (first === "[" && last === "]");
+ if (!bracketed) {
+ return false;
+ }
+ try {
+ JSON.parse(trimmed);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+// Cheap structural signal: code tends to use these tokens densely, prose does
+// not. Kept conservative so ordinary tool text falls through to prose (which
+// wraps and reads fine) rather than being mis-highlighted as code.
+const CODE_SIGNAL = /[;{}]|=>|\bfunction\b|\bconst\b|\blet\b|\bimport\b|\bdef\b|\bclass\b|<\/?[a-z][\w-]*>/;
+
+function looksLikeCode(text: string): boolean {
+ const lines = text.split("\n");
+ if (lines.length < 2) {
+ return false;
+ }
+ const signalLines = lines.filter((line) => CODE_SIGNAL.test(line)).length;
+ return signalLines / lines.length >= 0.4;
+}
+
+interface DetectFormatInput {
+ /** ToolCallDetail.kind of the originating call. */
+ detailKind: string;
+ /** The originating tool name (used for `unknown` tools). */
+ name: string;
+ /** Whether the structured result is shell output. */
+ isShellOutput: boolean;
+ text: string;
+}
+
+/** Pick how to render a result body, plus an optional display language. */
+export function detectContentFormat({
+ detailKind,
+ name,
+ isShellOutput,
+ text,
+}: DetectFormatInput): { format: ActivityResultFormat; language?: string } {
+ if (isShellOutput || detailKind === "shell") {
+ return { format: "terminal" };
+ }
+
+ const isWeb =
+ detailKind === "fetch" ||
+ (detailKind === "unknown" && classifyUnknownToolName(name) === "web");
+ if (isWeb) {
+ return { format: "prose" };
+ }
+
+ if (looksLikeJson(text)) {
+ return { format: "code", language: "json" };
+ }
+ if (looksLikeCode(text)) {
+ return { format: "code" };
+ }
+ return { format: "prose" };
+}
+
+const INLINE_MAX_LINES = 3;
+const INLINE_MAX_CHARS = 240;
+
+/**
+ * Short, non-error prose renders inline (no card chrome). Errors, terminals,
+ * code, and longer output keep the full card so they stay scannable.
+ */
+export function resolvePresentation({
+ text,
+ tone,
+ format,
+}: {
+ text: string;
+ tone: ActivityResultTone;
+ format: ActivityResultFormat;
+}): ActivityResultPresentation {
+ if (tone === "error" || format !== "prose") {
+ return "card";
+ }
+ const lineCount = text.split("\n").length;
+ if (lineCount <= INLINE_MAX_LINES && text.length < INLINE_MAX_CHARS) {
+ return "inline";
+ }
+ return "card";
+}
diff --git a/gui/src/components/chat/utils/getActivityResultModel.ts b/gui/src/components/chat/utils/getActivityResultModel.ts
index 1526521b..21d896a8 100644
--- a/gui/src/components/chat/utils/getActivityResultModel.ts
+++ b/gui/src/components/chat/utils/getActivityResultModel.ts
@@ -7,8 +7,13 @@ import { buildRenderableFileDiffPatch } from "../activity-results/utils/fileDiff
import type {
ActivityResultFooter,
ActivityResultModel,
+ ActivityResultTone,
} from "../activity-results/types/activityResult";
import type { ActivityOperation } from "../types/chatThread";
+import {
+ detectContentFormat,
+ resolvePresentation,
+} from "./classifyActivityResult";
function buildShellPreviewText(
command: string,
@@ -55,15 +60,20 @@ export function getActivityResultModel(
return null;
}
+ const tone: ActivityResultTone = operation.isError ? "error" : "default";
const detail = operation.resultDetail;
+
if (detail?.kind === "shell_output") {
const text = buildShellPreviewText(detail.command, detail.stdout, detail.stderr);
return text.length === 0
? null
: {
- kind: "shell",
- title: "Shell",
+ kind: "content",
+ format: "terminal",
+ tone,
+ presentation: "card",
+ title: "Terminal",
text,
copyText: text,
footer: buildResultFooter(operation, detail),
@@ -107,13 +117,33 @@ export function getActivityResultModel(
operation.summary;
const trimmedText = text?.trim();
- return trimmedText
- ? {
- kind: "text",
- title: "Output",
- text: trimmedText,
- copyText: trimmedText,
- footer: buildResultFooter(operation),
- }
- : null;
+ if (!trimmedText) {
+ return null;
+ }
+
+ const { format, language } = detectContentFormat({
+ detailKind: operation.detail.kind,
+ name: operation.name,
+ isShellOutput: false,
+ text: trimmedText,
+ });
+ const presentation = resolvePresentation({ text: trimmedText, tone, format });
+ const title =
+ tone === "error"
+ ? "Error"
+ : format === "code"
+ ? (language ?? "Output")
+ : "Output";
+
+ return {
+ kind: "content",
+ format,
+ tone,
+ presentation,
+ language,
+ title,
+ text: trimmedText,
+ copyText: trimmedText,
+ footer: buildResultFooter(operation),
+ };
}