Skip to content

Commit 1c50d6f

Browse files
t3dotggclaude
andcommitted
fix(server): preview_act shows each action in the work log and points agents at aria-refs
The beebox preview_act test found two regressions against main. Every preview_act call showed as "Used the preview browser", and agents guessed Playwright locators for type and select, because the shared description said "Prefer a Playwright locator". Action tools now resolve to the labels of the tool their action replaced, on web and mobile, and the description points at aria-refs from preview_snapshot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c5607fe commit 1c50d6f

5 files changed

Lines changed: 65 additions & 46 deletions

File tree

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,10 @@ function itemToolPresentation(item: OrchestrationV2TurnItem): T3McpToolPresentat
643643
if (item.type !== "dynamic_tool") {
644644
return null;
645645
}
646-
return resolveT3McpToolPresentation(item.toolName) ?? resolveT3McpToolPresentation(item.title);
646+
return (
647+
resolveT3McpToolPresentation(item.toolName, item.input) ??
648+
resolveT3McpToolPresentation(item.title, item.input)
649+
);
647650
}
648651

649652
function itemSummary(

‎apps/server/src/mcp/toolkits/preview/tools.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const PreviewSnapshotTool = safeBrowserTool(
153153
const PreviewActTool = browserTool(
154154
Tool.make("preview_act", {
155155
description:
156-
"Act on the chosen tab. Prefer a Playwright `locator`; `x` and `y` go together. `timeoutMs` defaults to 15000. click: `button`, `clickCount` 1 to 3. type: literal `text`, `clear=true` replaces it. hover: shows menus or tooltips. select: `values` in one native <select>, by value or label; for a custom dropdown, click it open, then click the option. drag: `source` onto `target`. upload: absolute `paths` answer the file picker `preview_status` reports, [] cancels it, or a `locator` sets an <input type=file>. press: one `key`, such as 'Enter', with `modifiers`. scroll: the tab, or one container with a locator; positive `deltaY` scrolls down, positive `deltaX` right.",
156+
"Act on the chosen tab. Target with `locator='aria-ref=<ref>'` from `preview_snapshot`; `x` and `y` go together. `timeoutMs` defaults to 15000. click: `button`, `clickCount` 1 to 3. type: literal `text`, `clear=true` replaces it. hover: shows menus or tooltips. select: `values` in one native <select>, by value or label; for a custom dropdown, click it open, then click the option. drag: `source` onto `target`. upload: absolute `paths` answer the file picker `preview_status` reports, [] cancels it, or a `locator` sets an <input type=file>. press: one `key`, such as 'Enter', with `modifiers`, to the focused element; click a field first to focus it. scroll: the tab, or one container with a locator; positive `deltaY` scrolls down, positive `deltaX` right.",
157157
parameters: PreviewAutomationActInput,
158158
success: Schema.Union([
159159
Schema.Struct({ ...PreviewAutomationSelectResult.fields, ...presentationFields }),

‎packages/client-runtime/src/work-log/presentation.ts‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ function workEntryToolName(
144144
return resolveT3McpToolDefinition(entry.toolTitle) ? entry.toolTitle : entry.label;
145145
}
146146

147+
function workEntryToolInput(
148+
entry: Pick<WorkLogPresentationEntry, "toolData" | "structuredPayload">,
149+
): unknown {
150+
const item = entry.structuredPayload;
151+
const data = asRecord(entry.toolData);
152+
return item?.type === "dynamic_tool"
153+
? item.input
154+
: (data?.arguments ?? data?.input ?? data?.rawInput);
155+
}
156+
147157
function workEntryToolOutput(
148158
entry: Pick<WorkLogPresentationEntry, "toolData" | "structuredPayload">,
149159
): unknown {
@@ -220,7 +230,10 @@ export function resolveWorkEntryToolPresentation(
220230
>,
221231
fallbackStatus?: "inProgress" | "completed",
222232
) {
223-
const definition = resolveT3McpToolDefinition(workEntryToolName(entry));
233+
const definition = resolveT3McpToolDefinition(
234+
workEntryToolName(entry),
235+
workEntryToolInput(entry),
236+
);
224237
const status = entry.toolLifecycleStatus ?? fallbackStatus;
225238
return resolveT3McpToolPresentation(
226239
definition,
@@ -455,16 +468,8 @@ function toolGroupActionLabel(action: ToolGroupAction, count: number): string {
455468
}
456469

457470
function t3ToolSummaryCall(entry: WorkLogPresentationEntry): T3ToolSummaryCall {
458-
const item = entry.structuredPayload;
459-
const data =
460-
entry.toolData !== null && typeof entry.toolData === "object"
461-
? (entry.toolData as Record<string, unknown>)
462-
: undefined;
463471
return {
464-
input:
465-
item?.type === "dynamic_tool"
466-
? item.input
467-
: (data?.arguments ?? data?.input ?? data?.rawInput),
472+
input: workEntryToolInput(entry),
468473
output: workEntryToolOutput(entry),
469474
outcome:
470475
entry.toolLifecycleStatus === "failed" ||

‎packages/shared/src/t3McpToolPresentation.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vite-plus/test";
33
import {
44
T3_MCP_TOOL_NAMES,
55
resolveT3McpSummaryAction,
6+
resolveT3McpToolDefinition,
67
resolveT3McpToolPresentation,
78
} from "./t3McpToolPresentation.ts";
89

@@ -37,6 +38,20 @@ describe("resolveT3McpToolPresentation", () => {
3738
});
3839
});
3940

41+
describe("resolveT3McpToolDefinition", () => {
42+
it("labels an action tool call as the action it ran", () => {
43+
expect(
44+
resolveT3McpToolDefinition("mcp__t3-code__preview_act", { action: "type" })?.labels,
45+
).toEqual(resolveT3McpToolDefinition("preview_type")?.labels);
46+
expect(resolveT3McpToolDefinition("t3_thread_transfer", { action: "fork" })?.displayName).toBe(
47+
resolveT3McpToolDefinition("t3_thread_fork")?.displayName,
48+
);
49+
expect(resolveT3McpToolDefinition("preview_act", { action: "unknown" })?.labels[2]).toBe(
50+
"Used",
51+
);
52+
});
53+
});
54+
4055
describe("resolveT3McpSummaryAction", () => {
4156
it("summarizes an action tool by the action each call ran", () => {
4257
expect(resolveT3McpSummaryAction("mcp__t3-code__t3_queue", { action: "list" })).toBe(

‎packages/shared/src/t3McpToolPresentation.ts‎

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -388,42 +388,40 @@ export function resolveT3McpToolId(toolName: string | null | undefined): string
388388
return name !== null && Object.hasOwn(T3_MCP_TOOLS, name) ? name : null;
389389
}
390390

391+
type SummaryInput = Readonly<Record<string, unknown>>;
392+
393+
const asSummaryInput = (input: unknown): SummaryInput | undefined =>
394+
typeof input === "object" && input !== null ? (input as SummaryInput) : undefined;
395+
396+
/** Action tools present each call as the single-purpose tool its action replaced. */
397+
const ACTION_TOOLS: Readonly<Record<string, (action: string) => string | undefined>> = {
398+
preview_act: (action) => `preview_${action}`,
399+
t3_queue: (action) => `t3_queue_${action}`,
400+
t3_pending_request: (action) => `t3_pending_request_${action}`,
401+
t3_thread_transfer: (action) =>
402+
({ fork: "t3_thread_fork", merge_back: "t3_thread_merge_back", status: "t3_thread_transfers" })[
403+
action
404+
],
405+
};
406+
407+
/** Pass the call's input so an action tool resolves to the labels and summary of its action. */
391408
export function resolveT3McpToolDefinition(
392409
toolName: string | null | undefined,
410+
input?: unknown,
393411
): T3McpToolDefinition | null {
394412
const name = toolName == null ? null : resolveT3McpToolName(toolName);
395-
return name !== null && Object.hasOwn(T3_MCP_TOOLS, name) ? T3_MCP_TOOLS[name]! : null;
413+
if (name === null || !Object.hasOwn(T3_MCP_TOOLS, name)) return null;
414+
const action = asSummaryInput(input)?.action;
415+
const actionTool = typeof action === "string" ? ACTION_TOOLS[name]?.(action) : undefined;
416+
return actionTool !== undefined && Object.hasOwn(T3_MCP_TOOLS, actionTool)
417+
? T3_MCP_TOOLS[actionTool]!
418+
: T3_MCP_TOOLS[name]!;
396419
}
397420

398-
type SummaryInput = Readonly<Record<string, unknown>>;
399-
400-
const byAction =
401-
(summaries: Readonly<Record<string, T3McpToolSummaryAction>>) =>
402-
({ action }: SummaryInput) =>
403-
typeof action === "string" ? summaries[action] : undefined;
404-
405-
/** Action tools summarize each call by the action it ran, not by the tool name. */
421+
/** Tools whose summary depends on which fields a call sets. */
406422
const ACTION_SUMMARIES: Readonly<
407423
Record<string, (input: SummaryInput) => T3McpToolSummaryAction | undefined>
408424
> = {
409-
t3_queue: byAction({
410-
list: "queue-list",
411-
read: "queue-read",
412-
edit: "queue-edit",
413-
cancel: "queue-cancel",
414-
reorder: "queue-reorder",
415-
promote_to_steer: "queue-steer",
416-
}),
417-
t3_pending_request: byAction({
418-
list: "question-list",
419-
read: "question-read",
420-
respond: "question-respond",
421-
}),
422-
t3_thread_transfer: byAction({
423-
fork: "thread-fork",
424-
merge_back: "thread-merge",
425-
status: "thread-transfers",
426-
}),
427425
t3_thread_configure: ({ modelSelection }) =>
428426
modelSelection === undefined ? "thread-configuration" : "thread-configure",
429427
schedule_task: ({ scheduledTaskId }) =>
@@ -434,19 +432,17 @@ export function resolveT3McpSummaryAction(
434432
toolName: string | null | undefined,
435433
input: unknown,
436434
): T3McpToolSummaryAction | null {
437-
const definition = resolveT3McpToolDefinition(toolName);
435+
const definition = resolveT3McpToolDefinition(toolName, input);
438436
if (definition === null) return null;
439437
const summarize = ACTION_SUMMARIES[resolveT3McpToolName(toolName!) ?? ""];
440-
const fromInput =
441-
summarize !== undefined && typeof input === "object" && input !== null
442-
? summarize(input as SummaryInput)
443-
: undefined;
444-
return fromInput ?? definition.summaryAction;
438+
const fields = asSummaryInput(input);
439+
return (fields && summarize?.(fields)) ?? definition.summaryAction;
445440
}
446441

447442
export function resolveT3McpToolPresentation(
448443
toolName: string | null | undefined,
444+
input?: unknown,
449445
): T3McpToolPresentation | null {
450-
const definition = resolveT3McpToolDefinition(toolName);
446+
const definition = resolveT3McpToolDefinition(toolName, input);
451447
return definition === null ? null : { displayName: definition.displayName, logo: "t3-code" };
452448
}

0 commit comments

Comments
 (0)