fix(provider-acp): multi-line and scripted acp-mcp-call fallbacks render html_render inline #45060
Openericlitman(GitHub profile, opens in a new tab)wants to merge 13 commits into
main fromrefs/pull/45060/headopened View on GitHubericlitman(GitHub profile, opens in a new tab) linked this to fix #43699
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -1459,0 +1466,21 @@1466+function terminalMcpResult(rawOutput: unknown): Record<string, unknown> | undefined {1467+ const text = textFromUnknown(rawOutput);1468+ if (text === undefined) return undefined;1469+ const trimmed = text.trim();1470+ if (trimmed.length === 0) return undefined;1471+ if (trimmed.startsWith("{")) {1472+ try {1473+ const parsed = unknownRecord(JSON.parse(trimmed));1474+ if (parsed !== undefined) return parsed;1475+ } catch {1476+ // Multi-line output can start with `{` before the trailing JSON result line.1477+ }1478+ }1479+ const lines = trimmed.split(/\r?\n/u);1480+ for (let index = lines.length - 1; index >= 0; index--) {1481+ const line = lines[index]?.trim();1482+ if (line === undefined || !line.startsWith("{")) continue;1483+ try {1484+ return unknownRecord(JSON.parse(line));1485+ } catch {1486+ return undefined;@@ -5857 +5898,21 @@5898+ toolName: `t3-code.${HTML_RENDER_TOOL_NAME}`,5899+ output: terminalMcpResult(callRawOutput),5900+ });5901+ const page =5902+ reported === undefined5903+ ? undefined5904+ : yield* mcpSessions.takeHtmlRender(active.input.threadId, {}, reported);5905+ if (page === undefined) return undefined;5906+ active.terminalHtmlRenderCalls.add(call.toolCallId);5907+ return {5908+ ...HTML_RENDER_IDENTITY,5909+ input: { title: page.title, height: page.height },5910+ };58575911 });5912+ const mcpIdentity =5913+ extractMcpToolCallIdentity(toolCall, {5914+ embeddedTerminalCommands: embeddedTerminalCommands(5915+ context.nativeThreadId,5916+ toolCall.toolCallId,5917+ ),5918+ }) ?? (yield* terminalHtmlRenderIdentity(context, toolCall, status, rawOutput));@@ -5967,9 +6032,14 @@5967- const page = reportedPage5968- ? yield* mcpSessions.takeHtmlRender(context.input.threadId, input, reportedPage)5969- : (previousPage ??5970- (yield* mcpSessions.takeHtmlRender(context.input.threadId, input)));5971- if (reportedPage === undefined && page !== undefined) {5972- output = { htmlRender: page };6032+ if (reportedPage !== undefined) {6033+ yield* mcpSessions.takeHtmlRender(context.input.threadId, input, reportedPage);6034+ }6035+ const page =6036+ reportedPage ??6037+ previousPage ??6038+ (yield* mcpSessions.takeHtmlRender(context.input.threadId, input));6039+ if (page !== undefined) {6040+ if (reportedPage === undefined) {6041+ output = { htmlRender: page };6042+ }59736043 context.tools.set(toolCall.toolCallId, {59746044 ...toolCall,5975- data: { ...toolCall.data, rawOutput: output },6045+ data: { ...toolCall.data, rawOutput: { htmlRender: page } },@@ -1112,0 +1206,21 @@1206+ hasWord = true;1207+ start = index;1208+ }1209+ text += char;1210+ index += 1;1211+ }1212+ if (hasWord) {1213+ words.push({ text, start });1214+ }1215+ return words;1216+}1217+1218+function acpMcpFallbackCall(command: string, nested = false): AcpMcpToolCallIdentity | undefined {1219+ const words = shellWords(command);1220+ for (let index = 0; index < words.length; index++) {1221+ const word = words[index]!;1222+ const tool = words[index + 1]?.text;1223+ if (1224+ word.text === "acp-mcp-call" &&1225+ tool !== undefined &&1226+ (T3_MCP_TOOL_NAMES.has(tool) || tool === T3_MCP_TOOL_CALL_PROXY || tool === "tool_search")
juliusmarminge added labelstakeover:in-progress
Pushedab39c25
- @@ -1459,0 +1465,21 @@1465+1466+function terminalMcpResult(rawOutput: unknown): Record<string, unknown> | undefined {1467+ const text = textFromUnknown(rawOutput);1468+ if (text === undefined) return undefined;1469+ const trimmed = text.trim();1470+ if (trimmed.length === 0) return undefined;1471+ if (trimmed.startsWith("{")) {1472+ try {1473+ const parsed = unknownRecord(JSON.parse(trimmed));1474+ if (parsed !== undefined) return parsed;1475+ } catch {1476+ // Multi-line output can start with `{` before the trailing JSON result line.1477+ }1478+ }1479+ const lines = trimmed.split(/\r?\n/u);1480+ for (let index = lines.length - 1; index >= 0; index--) {1481+ const line = lines[index]?.trim();1482+ if (line === undefined || !line.startsWith("{")) continue;1483+ try {1484+ const parsed = unknownRecord(JSON.parse(line));1485+ if (parsed !== undefined) return parsed;@@ -5966,7 +6038,14 @@5966- });5967- const page = reportedPage5968- ? yield* mcpSessions.takeHtmlRender(context.input.threadId, input, reportedPage)5969- : (previousPage ??5970- (yield* mcpSessions.takeHtmlRender(context.input.threadId, input)));5971- if (reportedPage === undefined && page !== undefined) {5972- output = { htmlRender: page };6038+ const previousPage =6039+ htmlRenderFromToolItem({6040+ toolName,6041+ output: acpMcpToolCallOutput(previous?.data.rawOutput ?? previous?.data.content),6042+ }) ?? context.claimedHtmlRenders.get(toolCall.toolCallId);6043+ if (reportedPage !== undefined) {6044+ yield* mcpSessions.takeHtmlRender(context.input.threadId, input, reportedPage);6045+ }6046+ const page =6047+ reportedPage ??6048+ previousPage ??6049+ (yield* mcpSessions.takeHtmlRender(context.input.threadId, input));6050+ if (page !== undefined) {6051+ context.claimedHtmlRenders.set(toolCall.toolCallId, page);@@ -1112,0 +1199,21 @@1199+ if (next === "\r" && command[index + 2] === "\n") {1200+ index += 3;1201+ continue;1202+ }1203+ if (!hasWord) {1204+ hasWord = true;1205+ start = index;1206+ }1207+ if (next !== undefined) {1208+ text += next;1209+ index += 2;1210+ } else {1211+ text += "\\";1212+ index += 1;1213+ }1214+ continue;1215+ }1216+ if (ACP_MCP_SHELL_COMMAND_SEPARATOR.test(char)) {1217+ pushCommand();1218+ index += 1;1219+ continue;
Pushed3009f1e
- @@ -1112,0 +1246,21 @@1246+ index += 2;1247+ continue;1248+ }1249+ if (next === "\r" && command[index + 2] === "\n") {1250+ index += 3;1251+ continue;1252+ }1253+ if (!hasWord) {1254+ hasWord = true;1255+ start = index;1256+ }1257+ if (next !== undefined) {1258+ text += next;1259+ index += 2;1260+ } else {1261+ text += "\\";1262+ index += 1;1263+ }1264+ continue;1265+ }1266+ if (char === "<" && command[index + 1] === "<" && command[index + 2] !== "<") {
Pushed6fcb071
- @@ -1112,0 +1145,21 @@1145+ if (words.length === 0) return;1146+ commands.push(words);1147+ words = [];1148+ };1149+1150+ const readHeredocDelimiter = (): string => {1151+ while (index < command.length && (command[index] === " " || command[index] === "\t")) {1152+ index += 1;1153+ }1154+ let delimiter = "";1155+ while (index < command.length) {1156+ const ch = command[index]!;1157+ if (ACP_MCP_SHELL_COMMAND_SEPARATOR.test(ch) || ACP_MCP_SHELL_WORD_SEPARATOR.test(ch)) {1158+ break;1159+ }1160+ if (ch === "'" || ch === '"') {1161+ const quote = ch;1162+ index += 1;1163+ while (index < command.length && command[index] !== quote) {1164+ if (quote === '"' && command[index] === "\\" && index + 1 < command.length) {1165+ index += 1;@@ -1112,0 +1256,21 @@1256+ }1257+ if (next !== undefined) {1258+ text += next;1259+ index += 2;1260+ } else {1261+ text += "\\";1262+ index += 1;1263+ }1264+ continue;1265+ }1266+ if (char === "<" && command[index + 1] === "<") {1267+ pushWord();1268+ if (command[index + 2] === "<") {1269+ index += 3;1270+ continue;1271+ }1272+ index += 2;1273+ const stripTabs = command[index] === "-";1274+ if (stripTabs) index += 1;1275+ const delimiter = readHeredocDelimiter();1276+ if (delimiter.length > 0) {@@ -1112,0 +1261,21 @@1261+ text += "\\";1262+ index += 1;1263+ }1264+ continue;1265+ }1266+ if (char === "<" && command[index + 1] === "<") {1267+ pushWord();1268+ if (command[index + 2] === "<") {1269+ index += 3;1270+ continue;1271+ }1272+ index += 2;1273+ const stripTabs = command[index] === "-";1274+ if (stripTabs) index += 1;1275+ const delimiter = readHeredocDelimiter();1276+ if (delimiter.length > 0) {1277+ pendingHeredocs.push({ delimiter, stripTabs });1278+ }1279+ continue;1280+ }1281+ if (ACP_MCP_SHELL_COMMAND_SEPARATOR.test(char)) {@@ -1112,0 +1278,21 @@1278+ }1279+ continue;1280+ }1281+ if (ACP_MCP_SHELL_COMMAND_SEPARATOR.test(char)) {1282+ pushCommand();1283+ if (char === "\r" && command[index + 1] === "\n") {1284+ index += 2;1285+ } else {1286+ index += 1;1287+ }1288+ if ((char === "\n" || char === "\r") && pendingHeredocs.length > 0) {1289+ skipPendingHeredocs();1290+ }1291+ continue;1292+ }1293+ if (ACP_MCP_SHELL_WORD_SEPARATOR.test(char)) {1294+ pushWord();1295+ index += 1;1296+ continue;1297+ }1298+ if (!hasWord) {@@ -1112,0 +1342,21 @@1342+ if (1343+ word.text === "acp-mcp-call" &&1344+ tool !== undefined &&1345+ isAcpMcpCallInvocation(words, index) &&1346+ (T3_MCP_TOOL_NAMES.has(tool) || tool === T3_MCP_TOOL_CALL_PROXY || tool === "tool_search")1347+ ) {1348+ const arg = words[index + 2];1349+ const input =1350+ arg === undefined1351+ ? undefined1352+ : (acpMcpFallbackInput(arg.text) ?? acpMcpFallbackInput(command.slice(arg.start)));1353+ return unwrapT3ToolCallProxy(1354+ { server: "t3-code", tool, ...(input === undefined ? {} : { input }) },1355+ input,1356+ );1357+ }1358+ if (1359+ !nested &&1360+ tool !== undefined &&1361+ ACP_MCP_SHELL_COMMAND_FLAG.test(word.text) &&1362+ ACP_MCP_SHELL_EXECUTABLE.test(words[index - 1]?.text ?? "")@@ -1306,11 +1564,4 @@13061564 ...(options?.embeddedTerminalCommands ?? []),13071565 ];13081566 for (const command of commands) {1309- const match = ACP_MCP_FALLBACK_CALL.exec(command);1310- if (match?.[1] !== undefined) {1311- const input = acpMcpFallbackInput(match[2]);1312- return unwrapT3ToolCallProxy(1313- { server: "t3-code", tool: match[1], ...(input === undefined ? {} : { input }) },1314- input,1315- );1316- }1567+ const found = acpMcpFallbackCall(command);
Pushedffa5e1c
- @@ -5849,4 +5892,15 @@58495892 rawOutputRecord.type.trim().toLowerCase() === "bash" &&58505893 commandExitCode(rawOutput) !== undefined;58515894 const projectAsCommandExecution = inputVariant === "monitor" || outputIsBashResult;5852- const mcpIdentity = extractMcpToolCallIdentity(toolCall, {5895+ const terminalHtmlRenderIdentity = Effect.fnUntraced(function* (5896+ active: ActiveAcpTurn,5897+ call: AcpToolCallState,5898+ callStatus: OrchestrationV2TurnItem["status"],5899+ callRawOutput: unknown,5900+ ) {5901+ if (call.kind !== "execute") return undefined;5902+ if (active.terminalHtmlRenderCalls.has(call.toolCallId)) {5903+ return HTML_RENDER_IDENTITY;5904+ }5905+ if (callStatus !== "completed") return undefined;5906+ if (!textFromUnknown(callRawOutput)?.includes('"htmlRender"')) return undefined;@@ -5972,0 +6047,21 @@6047+ const previousPage =6048+ htmlRenderFromToolItem({6049+ toolName,6050+ output: acpMcpToolCallOutput(previous?.data.rawOutput ?? previous?.data.content),6051+ }) ?? context.claimedHtmlRenders.get(toolCall.toolCallId);6052+ const claimedReportedPage =6053+ reportedPage === undefined6054+ ? undefined6055+ : yield* mcpSessions.takeHtmlRender(context.input.threadId, input, reportedPage);6056+ const verifiedReportedPage =6057+ reportedPage === undefined6058+ ? undefined6059+ : (claimedReportedPage ??6060+ (toolCall.kind !== "execute" ||6061+ previousPage?.attachmentId === reportedPage.attachmentId6062+ ? reportedPage6063+ : undefined));6064+ const page =6065+ verifiedReportedPage ??6066+ previousPage ??6067+ (yield* mcpSessions.takeHtmlRender(context.input.threadId, input));@@ -5973,4 +6059,20 @@6059+ : (claimedReportedPage ??6060+ (toolCall.kind !== "execute" ||6061+ previousPage?.attachmentId === reportedPage.attachmentId6062+ ? reportedPage6063+ : undefined));6064+ const page =6065+ verifiedReportedPage ??6066+ previousPage ??6067+ (yield* mcpSessions.takeHtmlRender(context.input.threadId, input));6068+ if (page !== undefined) {6069+ context.claimedHtmlRenders.set(toolCall.toolCallId, page);6070+ if (verifiedReportedPage === undefined) {6071+ output = { htmlRender: page };6072+ }59736073 context.tools.set(toolCall.toolCallId, {59746074 ...toolCall,5975- data: { ...toolCall.data, rawOutput: output },6075+ data: { ...toolCall.data, rawOutput: { htmlRender: page } },59766076 });6077+ } else if (reportedPage !== undefined && toolCall.kind === "execute") {6078+ output = rawOutput === undefined ? undefined : acpMcpToolCallOutput(rawOutput);@@ -301,3 +303,5 @@301303 terminalId,302304 sessionId: request.sessionId,303305 commandLine: [request.command, ...(request.args ?? [])].join(" "),306+ commandArgv:307+ options.shellCommands !== true && (request.args?.length ?? 0) > 0@@ -411,3 +417,5 @@411417 const readCommandLine: AcpClientTerminals["readCommandLine"] = (terminalId) =>412418 terminals.get(terminalId)?.commandLine;413419420+ const readCommandArgv: NonNullable<AcpClientTerminals["readCommandArgv"]> = (terminalId) =>421+ terminals.get(terminalId)?.commandArgv;@@ -1112,0 +1263,21 @@1263+ }1264+ if (ACP_MCP_SHELL_COMMAND_SEPARATOR.test(char)) {1265+ pushCommand();1266+ index += char === "\r" && command[index + 1] === "\n" ? 2 : 1;1267+ if ((char === "\n" || char === "\r") && pendingHeredocs.length > 0) {1268+ skipPendingHeredocs();1269+ }1270+ continue;1271+ }1272+ if (char === "<" && command[index + 1] === "<") {1273+ if (command[index + 2] === "<") {1274+ index += 3;1275+ readWord();1276+ continue;1277+ }1278+ index += 2;1279+ const stripTabs = command[index] === "-";1280+ if (stripTabs) index += 1;1281+ const delimiter = readWord();1282+ if (delimiter !== undefined) {1283+ pendingHeredocs.push({ delimiter: delimiter.text, stripTabs });@@ -1112,0 +1362,21 @@1362+ isAcpMcpCallInvocation(words, commandStart, index) &&1363+ (T3_MCP_TOOL_NAMES.has(tool) || tool === T3_MCP_TOOL_CALL_PROXY || tool === "tool_search")1364+ ) {1365+ const arg = words[index + 2];1366+ const input =1367+ arg === undefined1368+ ? undefined1369+ : (acpMcpFallbackInput(arg.text) ??1370+ (rawSource !== undefined && arg.start >= 01371+ ? acpMcpFallbackInput(rawSource.slice(arg.start))1372+ : undefined));1373+ return unwrapT3ToolCallProxy(1374+ { server: "t3-code", tool, ...(input === undefined ? {} : { input }) },1375+ input,1376+ );1377+ }1378+ }1379+ if (!nested && ACP_MCP_SHELL_EXECUTABLE.test(words[commandStart]?.text ?? "")) {1380+ for (let index = commandStart + 1; index < words.length; index++) {1381+ const flag = words[index]!.text;1382+ if (!flag.startsWith("-") || flag === "--") break;
Pushed6bf9b69
- @@ -1459,0 +1463,21 @@1463+ tool: HTML_RENDER_TOOL_NAME,1464+};1465+1466+function isTerminalHtmlRenderMcpResult(record: Record<string, unknown>): boolean {1467+ return (1468+ htmlRenderFromToolItem({ toolName: `t3-code.${HTML_RENDER_TOOL_NAME}`, output: record }) !==1469+ undefined || compactDynamicToolOutput(record)?.isError === true1470+ );1471+}1472+1473+function terminalOutputTexts(value: unknown): ReadonlyArray<string> {1474+ if (typeof value === "string") {1475+ return value.length > 0 ? [value] : [];1476+ }1477+ const fromBytes = decodeByteText(value);1478+ if (fromBytes !== undefined) {1479+ return fromBytes.length > 0 ? [fromBytes] : [];1480+ }1481+ if (Array.isArray(value)) {1482+ const parts = value.flatMap((entry) => terminalOutputTexts(entry));1483+ return parts.length > 1 ? [...parts, parts.join("\n")] : parts;
- @@ -6026,20 +6190,3 @@60266190 }60276191 }6028- turnItem = {6029- ...base,6030- title: null,6031- ...mcpToolPresentation({6032- serverName: mcpIdentity.server,6033- toolName: mcpIdentity.tool,6034- source: unknownRecord(6035- (unknownRecord(rawOutputRecord?.result) ?? rawOutputRecord)?._meta,6036- )?.source,6037- }),6038- type: "dynamic_tool",6039- toolName,6040- input,6041- ...(output === undefined ? {} : { output }),6042- };6043- yield* emitProviderEvent({ type: "turn_item.updated", driver, turnItem });6044- yield* rearmDeferredFinalize(context);6045- return;6192+ if (!downgradeToStandardTool) {
Pushed0336c23
- @@ -5976,0 +6175,21 @@6175+ const verifiedIntermediatePage =6176+ reportedPage === undefined6177+ ? undefined6178+ : reportedPage.attachmentId === claimedPage.attachmentId6179+ ? reportedPage6180+ : yield* mcpSessions.takeHtmlRender(6181+ context.input.threadId,6182+ input,6183+ reportedPage,6184+ );6185+ const page = verifiedIntermediatePage ?? claimedPage;6186+ context.claimedHtmlRenders.set(toolCall.toolCallId, page);6187+ output = { htmlRender: page };6188+ } else if (reportedPage !== undefined) {6189+ const verifiedIntermediatePage = yield* mcpSessions.takeHtmlRender(6190+ context.input.threadId,6191+ input,6192+ reportedPage,6193+ );6194+ if (verifiedIntermediatePage !== undefined) {6195+ context.claimedHtmlRenders.set(toolCall.toolCallId, verifiedIntermediatePage);
Pushedbef32fe
Sign in to join this conversation.


Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
Walkthrough
The ACP runtime now identifies supported
acp-mcp-callinvocations across shell command forms. The ACP adapter parses terminal output and projects verified HTML-render pages. Tests cover wrapped, heredoc, proxy, and other output forms, including cases that remain command-execution items.Changes: ACP HTML-render fallback
packages/provider-acp/src/server/runtimeModel.ts,packages/provider-acp/src/server/runtimeModel.test.ts,packages/provider-acp/src/server/clientTerminals.ts,packages/provider-acp/src/server/clientTerminals.test.tspackages/provider-acp/src/server/adapter.tsapps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts,apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts,scripts/scenarios/acp-mcp-call-html-render-renders-inline.e2e.tsEstimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
Suggested reviewers:
eliblaubalto,sheetsync,juliusmarminge,gabrielelpidioMerge Risk:
Minimal · up to
bef32This change makes ACP terminal-fallback html_render calls render inline, and its review findings have been addressed. No concrete merge-blocking risk remains in the supplied evidence.
Pre-merge checks:
3 · 
1
#43699are not shown to be matched at head bef32fe9f1.#43699and reassess.#43699and the PR objectives. No unrelated code paths were identified in the change summary.Full details: Title check
Explanation
The title follows the conventional commit format and names the main change: acp-mcp-call fallbacks (multi-line and scripted) now render html_render inline. The changeset matches this. The title is specific and does not use vague terms.
Full details: Description check
Explanation
The description follows the template. It has Problem, Change, Scope, and Verification sections, and each section has substantive content. The Problem section states the bug, the reproduction cases, and the expected behavior. The Change section explains the matcher, the result recovery, and the tests. The Scope section links issue
#43699and lists exclusions. The Verification section reports focused test runs, check results, and a real-app before/after proof. The template's agent-model attribution line is present at the end.Finishing Touches
Generate unit tests (beta)