mirror of
https://github.com/openai/codex.git
synced 2026-11-17 14:58:36 +00:00
Include Node REPL results in Guardian reviews (#38397)
## What changed - Capture accepted, successful `node_repl` results from Code Mode and include them as bounded, untrusted evidence in Guardian review prompts. - Enable the enhanced transcript through `guardian_enhanced_node_repl_transcripts` or when the selected model requires automatic Node REPL review. - Keep this evidence out of the parent model history, exclude encrypted and failed results, and avoid resending admitted evidence when a Guardian session is reused. - Clear retained evidence and invalidate review sessions when a thread is rolled back. ## Testing - Add unit coverage for evidence ordering, escaping, truncation, and empty responses. - Add an integration test covering feature-disabled, feature-enabled, and model-required behavior, including filtering and review-session reuse. GitOrigin-RevId: edc3dca5d5b88d472a492f35531ec46889a89d72
This commit is contained in:
1 parent
779e9114ae
commit
053dda6b89
14 files changed
+757
-39
No files matched your search
@@ -124,6 +124,23 @@ impl TestToolServer {
|
||||
Self::image_scenario_tool(),
|
||||
sandbox_meta_tool,
|
||||
];
|
||||
if std::env::var_os("MCP_TEST_ENABLE_NODE_REPL_JS").is_some() {
|
||||
#[expect(clippy::expect_used)]
|
||||
let schema: JsonObject = serde_json::from_value(json!({
|
||||
"type": "object",
|
||||
"properties": { "code": { "type": "string" } },
|
||||
"required": ["code"],
|
||||
"additionalProperties": false
|
||||
}))
|
||||
.expect("js tool schema should deserialize");
|
||||
let mut tool = Tool::new(
|
||||
Cow::Borrowed("js"),
|
||||
Cow::Borrowed("Run JavaScript in the test Node REPL."),
|
||||
Arc::new(schema),
|
||||
);
|
||||
tool.annotations = Some(ToolAnnotations::new().read_only(true));
|
||||
tools.push(tool);
|
||||
}
|
||||
if let Some(process_label) = dynamic_server_process_label()
|
||||
&& let Some(echo) = tools.iter_mut().find(|tool| tool.name == "echo")
|
||||
{
|
||||
@@ -396,6 +413,11 @@ struct EchoArgs {
|
||||
env_var: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct JsArgs {
|
||||
code: String,
|
||||
}
|
||||
|
||||
const DEFAULT_SYNC_TIMEOUT_MS: u64 = 1_000;
|
||||
|
||||
static SYNC_BARRIERS: OnceLock<tokio::sync::Mutex<HashMap<String, SyncBarrierState>>> =
|
||||
@@ -597,6 +619,33 @@ impl ServerHandler for TestToolServer {
|
||||
context: rmcp::service::RequestContext<rmcp::service::RoleServer>,
|
||||
) -> Result<rmcp::model::CallToolResponse, McpError> {
|
||||
match request.name.as_ref() {
|
||||
"js" => {
|
||||
let args = Self::parse_call_args::<JsArgs>(&request, "js")?;
|
||||
if args.code == "nodeRepl.fail()" {
|
||||
Ok(CallToolResult::error(vec![
|
||||
rmcp::model::ContentBlock::text("guardian-hidden-failed-result"),
|
||||
]))
|
||||
} else if args.code == "nodeRepl.empty()" {
|
||||
Ok(CallToolResult::success(vec![
|
||||
rmcp::model::ContentBlock::text(" "),
|
||||
]))
|
||||
} else if let Some(text) = args.code.strip_prefix("nodeRepl.write(")
|
||||
&& let Some(text) = text.strip_suffix(')')
|
||||
{
|
||||
let text = serde_json::from_str::<String>(text)
|
||||
.map_err(|error| McpError::invalid_params(error.to_string(), None))?;
|
||||
let mut result =
|
||||
CallToolResult::success(vec![rmcp::model::ContentBlock::text(text)]);
|
||||
result.structured_content =
|
||||
Some(json!({ "text": "guardian-hidden-structured-override" }));
|
||||
let mut meta = MetaObject::new();
|
||||
meta.insert("ui".to_string(), json!("guardian-hidden-ui-preview"));
|
||||
result.meta = Some(meta);
|
||||
Ok(result)
|
||||
} else {
|
||||
Err(McpError::invalid_params("unsupported test js source", None))
|
||||
}
|
||||
}
|
||||
"client_capabilities" => Ok(Self::structured_result(json!({
|
||||
"supportsOpenaiFormElicitation": self
|
||||
.supports_openai_form_elicitation
|
||||
|
||||
Reference in new issue
Block a user