From 4fcf27f4260589ce8a37336ac2ce704e9e359f9b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 21 Jul 2026 04:53:20 -0700 Subject: [PATCH] Unify T3 MCP tool presentation across clients - Extract shared T3 MCP tool label resolution - Show T3 Code branding for matched tool activity rows - Add tests for shared resolution and mobile feed output --- apps/mobile/src/components/BrandMark.tsx | 9 +-- apps/mobile/src/components/brandAssets.ts | 10 +++ .../src/features/threads/thread-work-log.tsx | 44 ++++++++++--- apps/mobile/src/lib/threadActivity.test.ts | 18 +++++ apps/mobile/src/lib/threadActivity.ts | 26 ++++++-- .../components/chat/MessagesTimeline.logic.ts | 66 ++----------------- .../src/components/chat/MessagesTimeline.tsx | 3 +- packages/shared/package.json | 4 ++ .../shared/src/t3McpToolPresentation.test.ts | 30 +++++++++ packages/shared/src/t3McpToolPresentation.ts | 66 +++++++++++++++++++ 10 files changed, 195 insertions(+), 81 deletions(-) create mode 100644 apps/mobile/src/components/brandAssets.ts create mode 100644 packages/shared/src/t3McpToolPresentation.test.ts create mode 100644 packages/shared/src/t3McpToolPresentation.ts diff --git a/apps/mobile/src/components/BrandMark.tsx b/apps/mobile/src/components/BrandMark.tsx index c8f1d43855..1643f3f6fd 100644 --- a/apps/mobile/src/components/BrandMark.tsx +++ b/apps/mobile/src/components/BrandMark.tsx @@ -3,14 +3,9 @@ import { Image } from "expo-image"; import { View } from "react-native"; import { AppText as Text } from "./AppText"; +import { T3_CODE_BRAND_MARK_SOURCE } from "./brandAssets"; const appVariant = Constants.expoConfig?.extra?.appVariant; -const BRAND_MARK_SOURCE = - appVariant === "development" - ? require("../../../../assets/dev/blueprint-ios-1024.png") - : appVariant === "preview" - ? require("../../../../assets/nightly/nightly-ios-1024.png") - : require("../../../../assets/prod/black-ios-1024.png"); const DEFAULT_STAGE_LABEL = appVariant === "development" ? "Dev" : appVariant === "preview" ? "Preview" : "Alpha"; @@ -22,7 +17,7 @@ export function BrandMark(props: { readonly compact?: boolean; readonly stageLab return ( + ); + } + + return ( + + ); +} + function ThreadActivityThreadLink(props: { readonly activity: ThreadFeedActivity; readonly environmentId: EnvironmentId; @@ -174,7 +206,7 @@ export function ThreadWorkLog(props: { const canExpand = row.fullDetail !== null; const detail = compactActivityDetail(row.detail); const displayText = detail ? `${row.summary} ${detail}` : row.summary; - const iconIsDestructive = row.icon === "alert" || row.icon === "warning"; + const textIsDestructive = row.icon === "alert" || row.icon === "warning"; return ( - + {row.summary} diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts index ea8acdec5e..feef9efefe 100644 --- a/apps/mobile/src/lib/threadActivity.test.ts +++ b/apps/mobile/src/lib/threadActivity.test.ts @@ -250,6 +250,7 @@ describe("buildThreadFeed", () => { fullDetail: null, copyText: id, icon: "command", + logo: null, toolLike: true, prominent: false, status, @@ -282,4 +283,21 @@ describe("buildThreadFeed", () => { : [], ).toEqual(["activity-1", "activity-neutral", "activity-2", "activity-3"]); }); + + it("pretty prints T3 MCP dynamic tool activities and attaches the product logo", () => { + const toolItem: OrchestrationV2TurnItem = { + ...base("item-t3-tool", "2026-06-20T00:00:04.000Z", 3), + type: "dynamic_tool", + toolName: "mcp__t3-code__t3_thread_read", + input: { threadId: "thread-child" }, + output: { messages: [] }, + }; + + const feed = buildThreadFeed([projected(toolItem, 0)]); + const activity = feed[0]?.type === "activity-group" ? feed[0].activities[0] : null; + + expect(activity?.summary).toBe("Read a T3 thread"); + expect(activity?.logo).toBe("t3-code"); + expect(activity?.copyText.split("\n")[0]).toBe("Read a T3 thread"); + }); }); diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts index 56d52c91f7..eb13de63d1 100644 --- a/apps/mobile/src/lib/threadActivity.ts +++ b/apps/mobile/src/lib/threadActivity.ts @@ -3,6 +3,11 @@ import type { ThreadPendingUserInput, ThreadUserInputQuestion, } from "@t3tools/client-runtime/state/thread-requests"; +import { + resolveT3McpToolPresentation, + type T3McpToolLogo, + type T3McpToolPresentation, +} from "@t3tools/shared/t3McpToolPresentation"; import type { ChatAttachment, MessageId, @@ -47,6 +52,7 @@ export interface ThreadFeedActivity { | "warning" | "wrench" | "zap"; + readonly logo: T3McpToolLogo | null; readonly toolLike: boolean; readonly prominent: boolean; readonly status: "success" | "failure" | "neutral" | null; @@ -192,9 +198,19 @@ function itemIcon(item: OrchestrationV2TurnItem): ThreadFeedActivity["icon"] { } } -function itemSummary(item: OrchestrationV2TurnItem): string { +function itemToolPresentation(item: OrchestrationV2TurnItem): T3McpToolPresentation | null { + if (item.type !== "dynamic_tool") { + return null; + } + return resolveT3McpToolPresentation(item.toolName) ?? resolveT3McpToolPresentation(item.title); +} + +function itemSummary( + item: OrchestrationV2TurnItem, + toolPresentation: T3McpToolPresentation | null = null, +): string { const title = item.title?.trim(); - if (title) return capitalizePhrase(title); + if (title) return toolPresentation?.displayName ?? capitalizePhrase(title); switch (item.type) { case "reasoning": return "Thinking"; @@ -229,7 +245,7 @@ function itemSummary(item: OrchestrationV2TurnItem): string { case "subagent": return "Subagent"; case "dynamic_tool": - return item.toolName ?? "Tool call"; + return toolPresentation?.displayName ?? item.toolName ?? "Tool call"; case "proposed_plan": return "Proposed plan"; case "todo_list": @@ -288,7 +304,8 @@ function itemPreview(item: OrchestrationV2TurnItem): string | null { function toFeedActivity(row: OrchestrationV2ProjectedTurnItem): ThreadFeedActivity { const item = row.item; - const summary = itemSummary(item); + const toolPresentation = itemToolPresentation(item); + const summary = itemSummary(item, toolPresentation); const detail = itemPreview(item); const fullDetail = JSON.stringify( { @@ -308,6 +325,7 @@ function toFeedActivity(row: OrchestrationV2ProjectedTurnItem): ThreadFeedActivi detail, fullDetail, icon: itemIcon(item), + logo: toolPresentation?.logo ?? null, copyText: [summary, detail, fullDetail] .filter( (value, index, values): value is string => diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index f69e25242c..a57c402671 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -13,6 +13,10 @@ import { type RunId, } from "@t3tools/contracts"; import type { ThreadRunSummary } from "@t3tools/client-runtime/state/shell"; +import { + resolveT3McpToolPresentation, + type T3McpToolPresentation, +} from "@t3tools/shared/t3McpToolPresentation"; export const MAX_VISIBLE_WORK_LOG_ENTRIES = 1; export const TIMELINE_MINIMAP_ITEM_SPACING = 8; @@ -217,66 +221,8 @@ export function normalizeCompactToolLabel(value: string): string { return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim(); } -export interface TimelineToolPresentation { - readonly displayName: string; - readonly logo: "t3-code"; -} - -const T3_MCP_SERVER_ALIASES = new Set(["t3-code", "t3_code", "t3code"]); - -const T3_MCP_TOOL_DISPLAY_NAMES: Record = { - orchestrator_capabilities: "Get orchestration capabilities", - delegate_task: "Delegate a child task", - task_status: "Get delegated task status", - task_cancel: "Cancel delegated task", - schedule_task: "Schedule a recurring task", - list_scheduled_tasks: "List scheduled tasks", - update_scheduled_task: "Update a scheduled task", - delete_scheduled_task: "Delete a scheduled task", - create_threads: "Create T3 threads", - t3_thread_start: "Start a T3 thread", - t3_thread_list: "List T3 threads", - t3_thread_read: "Read a T3 thread", - t3_thread_send: "Send to a T3 thread", - t3_thread_wait: "Wait for a T3 thread", - t3_thread_interrupt: "Interrupt a T3 thread", -}; - -function resolveT3McpToolName(value: string): string | null { - const label = normalizeCompactToolLabel(value); - const mcpMatch = /^mcp__(?.+?)__(?.+)$/.exec(label); - if (mcpMatch?.groups) { - const { server, tool } = mcpMatch.groups; - return server !== undefined && tool !== undefined && T3_MCP_SERVER_ALIASES.has(server) - ? tool - : null; - } - - const namespaceMatch = /^(?t3-code|t3_code|t3code)[.:/](?.+)$/.exec(label); - if (namespaceMatch?.groups) { - return namespaceMatch.groups.tool ?? null; - } - - return Object.hasOwn(T3_MCP_TOOL_DISPLAY_NAMES, label) ? label : null; -} - -export function resolveTimelineToolPresentation( - toolName: string | null | undefined, -): TimelineToolPresentation | null { - const resolvedToolName = - toolName === undefined || toolName === null ? null : resolveT3McpToolName(toolName); - if (resolvedToolName === null) { - return null; - } - const displayName = T3_MCP_TOOL_DISPLAY_NAMES[resolvedToolName]; - if (displayName === undefined) { - return null; - } - return { - displayName, - logo: "t3-code", - }; -} +export type TimelineToolPresentation = T3McpToolPresentation; +export const resolveTimelineToolPresentation = resolveT3McpToolPresentation; export function resolveAssistantMessageCopyState({ text, diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index 466f4b6d5d..cbfa33b8d6 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -2230,6 +2230,7 @@ function WorkEntryIconSvg({ name, className }: { name: WorkEntryIconName; classN } function T3CodeToolLogo({ className }: { className?: string }) { + const logoUrl = `${import.meta.env.BASE_URL}apple-touch-icon.png`; return ( - + ); } diff --git a/packages/shared/package.json b/packages/shared/package.json index b5f9ccf21f..4dc794bf62 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -75,6 +75,10 @@ "types": "./src/toolActivity.ts", "import": "./src/toolActivity.ts" }, + "./t3McpToolPresentation": { + "types": "./src/t3McpToolPresentation.ts", + "import": "./src/t3McpToolPresentation.ts" + }, "./Struct": { "types": "./src/Struct.ts", "import": "./src/Struct.ts" diff --git a/packages/shared/src/t3McpToolPresentation.test.ts b/packages/shared/src/t3McpToolPresentation.test.ts new file mode 100644 index 0000000000..cc5a503529 --- /dev/null +++ b/packages/shared/src/t3McpToolPresentation.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { resolveT3McpToolPresentation } from "./t3McpToolPresentation.ts"; + +describe("resolveT3McpToolPresentation", () => { + it("pretty prints Claude and Cursor T3 MCP tool names", () => { + expect(resolveT3McpToolPresentation("mcp__t3-code__t3_thread_read")).toEqual({ + displayName: "Read a T3 thread", + logo: "t3-code", + }); + }); + + it("pretty prints Codex T3 MCP tool names", () => { + expect(resolveT3McpToolPresentation("t3-code.create_threads")).toEqual({ + displayName: "Create T3 threads", + logo: "t3-code", + }); + }); + + it("pretty prints bare T3 MCP toolkit names", () => { + expect(resolveT3McpToolPresentation("list_scheduled_tasks")).toEqual({ + displayName: "List scheduled tasks", + logo: "t3-code", + }); + }); + + it("keeps unknown MCP tools on the generic renderer path", () => { + expect(resolveT3McpToolPresentation("mcp__github__search_issues")).toBeNull(); + }); +}); diff --git a/packages/shared/src/t3McpToolPresentation.ts b/packages/shared/src/t3McpToolPresentation.ts new file mode 100644 index 0000000000..0a92fc990c --- /dev/null +++ b/packages/shared/src/t3McpToolPresentation.ts @@ -0,0 +1,66 @@ +export type T3McpToolLogo = "t3-code"; + +export interface T3McpToolPresentation { + readonly displayName: string; + readonly logo: T3McpToolLogo; +} + +const T3_MCP_SERVER_ALIASES = new Set(["t3-code", "t3_code", "t3code"]); + +const T3_MCP_TOOL_DISPLAY_NAMES: Record = { + orchestrator_capabilities: "Get orchestration capabilities", + delegate_task: "Delegate a child task", + task_status: "Get delegated task status", + task_cancel: "Cancel delegated task", + schedule_task: "Schedule a recurring task", + list_scheduled_tasks: "List scheduled tasks", + update_scheduled_task: "Update a scheduled task", + delete_scheduled_task: "Delete a scheduled task", + create_threads: "Create T3 threads", + t3_thread_start: "Start a T3 thread", + t3_thread_list: "List T3 threads", + t3_thread_read: "Read a T3 thread", + t3_thread_send: "Send to a T3 thread", + t3_thread_wait: "Wait for a T3 thread", + t3_thread_interrupt: "Interrupt a T3 thread", +}; + +function normalizeT3McpToolLabel(value: string): string { + return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim(); +} + +function resolveT3McpToolName(value: string): string | null { + const label = normalizeT3McpToolLabel(value); + const mcpMatch = /^mcp__(?.+?)__(?.+)$/.exec(label); + if (mcpMatch?.groups) { + const { server, tool } = mcpMatch.groups; + return server !== undefined && tool !== undefined && T3_MCP_SERVER_ALIASES.has(server) + ? tool + : null; + } + + const namespaceMatch = /^(?t3-code|t3_code|t3code)[.:/](?.+)$/.exec(label); + if (namespaceMatch?.groups) { + return namespaceMatch.groups.tool ?? null; + } + + return Object.hasOwn(T3_MCP_TOOL_DISPLAY_NAMES, label) ? label : null; +} + +export function resolveT3McpToolPresentation( + toolName: string | null | undefined, +): T3McpToolPresentation | null { + const resolvedToolName = + toolName === undefined || toolName === null ? null : resolveT3McpToolName(toolName); + if (resolvedToolName === null) { + return null; + } + const displayName = T3_MCP_TOOL_DISPLAY_NAMES[resolvedToolName]; + if (displayName === undefined) { + return null; + } + return { + displayName, + logo: "t3-code", + }; +}