MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / execute_command

Function execute_command

crates/opencode-server/src/routes.rs:2066–2106  ·  view source on GitHub ↗
(
    State(state): State<Arc<ServerState>>,
    Path(id): Path<String>,
    Json(req): Json<ExecuteCommandRequest>,
)

Source from the content-addressed store, hash-verified

2064}
2065
2066async fn execute_command(
2067 State(state): State<Arc<ServerState>>,
2068 Path(id): Path<String>,
2069 Json(req): Json<ExecuteCommandRequest>,
2070) -> Result<Json<serde_json::Value>> {
2071 let mut sessions = state.sessions.lock().await;
2072 let session = sessions
2073 .get_mut(&id)
2074 .ok_or_else(|| ApiError::SessionNotFound(id.clone()))?;
2075 let text = req
2076 .arguments
2077 .as_deref()
2078 .map(|args| format!("/{cmd} {args}", cmd = req.command))
2079 .unwrap_or_else(|| format!("/{}", req.command));
2080 session.add_user_message(text);
2081 let assistant = session.add_assistant_message();
2082 assistant.add_text(format!("Command queued: {}", req.command));
2083 let assistant_id = assistant.id.clone();
2084 let arguments = req
2085 .arguments
2086 .as_deref()
2087 .map(|value| {
2088 value
2089 .split_whitespace()
2090 .map(|item| item.to_string())
2091 .collect::<Vec<_>>()
2092 })
2093 .unwrap_or_default();
2094 sessions.publish_command_executed(&req.command, &id, arguments, &assistant_id);
2095 drop(sessions);
2096 persist_sessions_if_enabled(&state).await;
2097
2098 Ok(Json(serde_json::json!({
2099 "executed": true,
2100 "command": req.command,
2101 "arguments": req.arguments,
2102 "model": req.model,
2103 "agent": req.agent,
2104 "message_id": assistant_id,
2105 })))
2106}
2107
2108async fn get_session_diff(
2109 State(state): State<Arc<ServerState>>,

Callers

nothing calls this directly

Calls 7

add_textMethod · 0.80
get_mutMethod · 0.45
cloneMethod · 0.45
add_user_messageMethod · 0.45
add_assistant_messageMethod · 0.45

Tested by

no test coverage detected