Support cua_repl as a Node REPL-backed MCP server (#40257)

## What changed

- Recognize `cua_repl` alongside `node_repl` when collecting Guardian review evidence, applying computer-use policy, and capturing transcript images.
- Render `cua_repl.js` results with the compact REPL history and transcript views.
- Preserve failed MCP call status and result content when replaying app-server history.

## Testing

- Cover both REPL server names across Guardian policy, evidence, image capture, history rendering, and failed-call replay tests.

GitOrigin-RevId: 8c13a721f718add403b07e727c1634b59203c51a
This commit is contained in:
Ankush Gupta authored and copyberry committed 2026-08-23 17:02:21 +00:00
1 parent c9b19deb09
commit 2161ec272a
16 files changed
+260 -82

No files matched your search

+4 -2
View File
@@ -2,6 +2,8 @@
use super::*;
use codex_protocol::mcp::is_node_repl_backed_server;
#[path = "mcp_result.rs"]
mod result;
@@ -119,7 +121,7 @@ impl McpToolCallCell {
}
fn result_kind(&self) -> McpResultKind {
if self.invocation.server == "node_repl" && self.invocation.tool == "js" {
if is_node_repl_backed_server(&self.invocation.server) && self.invocation.tool == "js" {
McpResultKind::NodeRepl
} else {
McpResultKind::Standard
@@ -157,7 +159,7 @@ impl McpToolCallCell {
.map(|title| title.split_whitespace().collect::<Vec<_>>().join(" "))
.filter(|title| !title.is_empty())
.map(|title| title.graphemes(true).take(80).collect::<String>())
.unwrap_or_else(|| "node_repl.js".to_string());
.unwrap_or_else(|| format!("{}.{}", self.invocation.server, self.invocation.tool));
Line::from(title.cyan())
} else {
line_to_static(&format_mcp_invocation(&self.invocation))
+5 -3
View File
@@ -109,10 +109,12 @@ impl McpToolResult {
}
impl McpContentBlock {
/// Returns the untruncated top-level text used by node_repl's compact and transcript views.
/// Returns the untruncated top-level text used by node_repl and cua_repl's compact and
/// transcript views.
///
/// Valid text blocks reuse their display storage. Only node_repl retains this extra field on
/// malformed or non-text blocks, where it takes precedence over the usual display content.
/// Valid text blocks reuse their display storage. Only node_repl and cua_repl retain this extra
/// field on malformed or non-text blocks, where it takes precedence over the usual display
/// content.
pub(super) fn text(&self) -> Option<&str> {
match &self.display {
McpContentDisplay::Text(text) => Some(text),
+43 -7
View File
@@ -207,13 +207,11 @@ fn code_mode_preserves_text_fields_on_nontext_and_unknown_blocks() {
);
let unknown =
json!({"type": "future_block", "text": "Script completed\nOutput:\nunknown-side output"});
cell.complete(
Duration::ZERO,
Ok(result(vec![
json!({"type": "image", "mimeType": "image/png", "data": PNG, "text": "Script completed\nOutput:\nimage-side output"}),
unknown.clone(),
])),
);
let tool_result = result(vec![
json!({"type": "image", "mimeType": "image/png", "data": PNG, "text": "Script completed\nOutput:\nimage-side output"}),
unknown.clone(),
]);
cell.complete(Duration::ZERO, Ok(tool_result.clone()));
let display = cell
.display_lines(/*width*/ 200)
@@ -254,4 +252,42 @@ fn code_mode_preserves_text_fields_on_nontext_and_unknown_blocks() {
)),
],
);
let mut cua_cell = new_active_mcp_tool_call(
"call-cua-repl".to_string(),
McpInvocation {
server: "cua_repl".to_string(),
tool: "js".to_string(),
arguments: None,
},
/*animations_enabled*/ false,
);
cua_cell.complete(Duration::ZERO, Ok(tool_result));
let display = cua_cell
.display_lines(/*width*/ 200)
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("\n");
let transcript = cua_cell
.transcript_lines(/*width*/ 200)
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("\n");
insta::assert_snapshot!(format!("history:\n{display}\n\ntranscript:\n{transcript}"), @r"
history:
• Called cua_repl.js
└ image-side output
unknown-side output
transcript:
• Called cua_repl.js()
└ Script completed
Output:
image-side output
Script completed
Output:
unknown-side output
");
}