Add code_mode experimental feature (#13418)

A much narrower and more isolated (no node features) version of js_repl
This commit is contained in:
pakrym-oai
2026-03-09 20:56:27 -07:00
committed by GitHub
parent a3cd9f16f5
commit da616136cc
14 changed files with 958 additions and 0 deletions
@@ -0,0 +1,55 @@
use async_trait::async_trait;
use crate::features::Feature;
use crate::function_tool::FunctionCallError;
use crate::tools::code_mode;
use crate::tools::context::ContentToolOutput;
use crate::tools::context::ToolInvocation;
use crate::tools::context::ToolOutputBox;
use crate::tools::context::ToolPayload;
use crate::tools::registry::ToolHandler;
use crate::tools::registry::ToolKind;
pub struct CodeModeHandler;
#[async_trait]
impl ToolHandler for CodeModeHandler {
fn kind(&self) -> ToolKind {
ToolKind::Function
}
fn matches_kind(&self, payload: &ToolPayload) -> bool {
matches!(payload, ToolPayload::Custom { .. })
}
async fn handle(&self, invocation: ToolInvocation) -> Result<ToolOutputBox, FunctionCallError> {
let ToolInvocation {
session,
turn,
tracker,
payload,
..
} = invocation;
if !session.features().enabled(Feature::CodeMode) {
return Err(FunctionCallError::RespondToModel(
"code_mode is disabled by feature flag".to_string(),
));
}
let code = match payload {
ToolPayload::Custom { input } => input,
_ => {
return Err(FunctionCallError::RespondToModel(
"code_mode expects raw JavaScript source text".to_string(),
));
}
};
let content_items = code_mode::execute(session, turn, tracker, code).await?;
Ok(Box::new(ContentToolOutput {
content: content_items,
success: Some(true),
}))
}
}
+2
View File
@@ -1,6 +1,7 @@
pub(crate) mod agent_jobs;
pub mod apply_patch;
mod artifacts;
mod code_mode;
mod dynamic;
mod grep_files;
mod js_repl;
@@ -32,6 +33,7 @@ use crate::sandboxing::merge_permission_profiles;
use crate::sandboxing::normalize_additional_permissions;
pub use apply_patch::ApplyPatchHandler;
pub use artifacts::ArtifactsHandler;
pub use code_mode::CodeModeHandler;
use codex_protocol::models::PermissionProfile;
use codex_protocol::protocol::AskForApproval;
pub use dynamic::DynamicToolHandler;