mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-08 09:04:49 +08:00
fix: post-merge clippy/fmt cleanup (9407-9410 integration)
This commit is contained in:
@@ -587,7 +587,7 @@ fn parse_mcp_command(args: &[&str]) -> Result<SlashCommand, SlashCommandParseErr
|
|||||||
"mcp",
|
"mcp",
|
||||||
"/mcp show <server>",
|
"/mcp show <server>",
|
||||||
)),
|
)),
|
||||||
["help"] | ["-h"] | ["--help"] => Ok(SlashCommand::Mcp {
|
["help" | "-h" | "--help"] => Ok(SlashCommand::Mcp {
|
||||||
action: Some("help".to_string()),
|
action: Some("help".to_string()),
|
||||||
target: None,
|
target: None,
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -437,30 +437,31 @@ impl McpServerManager {
|
|||||||
|
|
||||||
self.ensure_server_ready(&route.server_name).await?;
|
self.ensure_server_ready(&route.server_name).await?;
|
||||||
let request_id = self.take_request_id();
|
let request_id = self.take_request_id();
|
||||||
let response = {
|
let response =
|
||||||
let server = self.server_mut(&route.server_name)?;
|
{
|
||||||
let process = server.process.as_mut().ok_or_else(|| {
|
let server = self.server_mut(&route.server_name)?;
|
||||||
McpServerManagerError::InvalidResponse {
|
let process = server.process.as_mut().ok_or_else(|| {
|
||||||
server_name: route.server_name.clone(),
|
McpServerManagerError::InvalidResponse {
|
||||||
method: "tools/call",
|
server_name: route.server_name.clone(),
|
||||||
details: "server process missing after initialization".to_string(),
|
method: "tools/call",
|
||||||
}
|
details: "server process missing after initialization".to_string(),
|
||||||
})?;
|
}
|
||||||
Self::run_process_request(
|
})?;
|
||||||
&route.server_name,
|
Self::run_process_request(
|
||||||
"tools/call",
|
&route.server_name,
|
||||||
timeout_ms,
|
"tools/call",
|
||||||
process.call_tool(
|
timeout_ms,
|
||||||
request_id,
|
process.call_tool(
|
||||||
McpToolCallParams {
|
request_id,
|
||||||
name: route.raw_name,
|
McpToolCallParams {
|
||||||
arguments,
|
name: route.raw_name,
|
||||||
meta: None,
|
arguments,
|
||||||
},
|
meta: None,
|
||||||
),
|
},
|
||||||
)
|
),
|
||||||
.await
|
)
|
||||||
};
|
.await
|
||||||
|
};
|
||||||
|
|
||||||
if let Err(error) = &response {
|
if let Err(error) = &response {
|
||||||
if Self::should_reset_server(error) {
|
if Self::should_reset_server(error) {
|
||||||
@@ -507,12 +508,12 @@ impl McpServerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tool_call_timeout_ms(&self, server_name: &str) -> Result<u64, McpServerManagerError> {
|
fn tool_call_timeout_ms(&self, server_name: &str) -> Result<u64, McpServerManagerError> {
|
||||||
let server = self
|
let server =
|
||||||
.servers
|
self.servers
|
||||||
.get(server_name)
|
.get(server_name)
|
||||||
.ok_or_else(|| McpServerManagerError::UnknownServer {
|
.ok_or_else(|| McpServerManagerError::UnknownServer {
|
||||||
server_name: server_name.to_string(),
|
server_name: server_name.to_string(),
|
||||||
})?;
|
})?;
|
||||||
match &server.bootstrap.transport {
|
match &server.bootstrap.transport {
|
||||||
McpClientTransport::Stdio(transport) => Ok(transport.resolved_tool_call_timeout_ms()),
|
McpClientTransport::Stdio(transport) => Ok(transport.resolved_tool_call_timeout_ms()),
|
||||||
other => Err(McpServerManagerError::InvalidResponse {
|
other => Err(McpServerManagerError::InvalidResponse {
|
||||||
@@ -595,14 +596,13 @@ impl McpServerManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let result =
|
let result = response
|
||||||
response
|
.result
|
||||||
.result
|
.ok_or_else(|| McpServerManagerError::InvalidResponse {
|
||||||
.ok_or_else(|| McpServerManagerError::InvalidResponse {
|
server_name: server_name.to_string(),
|
||||||
server_name: server_name.to_string(),
|
method: "tools/list",
|
||||||
method: "tools/list",
|
details: "missing result payload".to_string(),
|
||||||
details: "missing result payload".to_string(),
|
})?;
|
||||||
})?;
|
|
||||||
|
|
||||||
for tool in result.tools {
|
for tool in result.tools {
|
||||||
let qualified_name = mcp_tool_name(server_name, &tool.name);
|
let qualified_name = mcp_tool_name(server_name, &tool.name);
|
||||||
@@ -1614,10 +1614,7 @@ mod tests {
|
|||||||
let script_path = write_jsonrpc_script();
|
let script_path = write_jsonrpc_script();
|
||||||
let transport = script_transport_with_env(
|
let transport = script_transport_with_env(
|
||||||
&script_path,
|
&script_path,
|
||||||
BTreeMap::from([(
|
BTreeMap::from([("MCP_LOWERCASE_CONTENT_LENGTH".to_string(), "1".to_string())]),
|
||||||
"MCP_LOWERCASE_CONTENT_LENGTH".to_string(),
|
|
||||||
"1".to_string(),
|
|
||||||
)]),
|
|
||||||
);
|
);
|
||||||
let mut process = McpStdioProcess::spawn(&transport).expect("spawn transport directly");
|
let mut process = McpStdioProcess::spawn(&transport).expect("spawn transport directly");
|
||||||
|
|
||||||
@@ -1657,10 +1654,7 @@ mod tests {
|
|||||||
let script_path = write_jsonrpc_script();
|
let script_path = write_jsonrpc_script();
|
||||||
let transport = script_transport_with_env(
|
let transport = script_transport_with_env(
|
||||||
&script_path,
|
&script_path,
|
||||||
BTreeMap::from([(
|
BTreeMap::from([("MCP_MISMATCHED_RESPONSE_ID".to_string(), "1".to_string())]),
|
||||||
"MCP_MISMATCHED_RESPONSE_ID".to_string(),
|
|
||||||
"1".to_string(),
|
|
||||||
)]),
|
|
||||||
);
|
);
|
||||||
let mut process = McpStdioProcess::spawn(&transport).expect("spawn transport directly");
|
let mut process = McpStdioProcess::spawn(&transport).expect("spawn transport directly");
|
||||||
|
|
||||||
@@ -1971,7 +1965,10 @@ mod tests {
|
|||||||
|
|
||||||
manager.discover_tools().await.expect("discover tools");
|
manager.discover_tools().await.expect("discover tools");
|
||||||
let error = manager
|
let error = manager
|
||||||
.call_tool(&mcp_tool_name("slow", "echo"), Some(json!({"text": "slow"})))
|
.call_tool(
|
||||||
|
&mcp_tool_name("slow", "echo"),
|
||||||
|
Some(json!({"text": "slow"})),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.expect_err("slow tool call should time out");
|
.expect_err("slow tool call should time out");
|
||||||
|
|
||||||
@@ -2036,7 +2033,9 @@ mod tests {
|
|||||||
} => {
|
} => {
|
||||||
assert_eq!(server_name, "broken");
|
assert_eq!(server_name, "broken");
|
||||||
assert_eq!(method, "tools/call");
|
assert_eq!(method, "tools/call");
|
||||||
assert!(details.contains("expected ident") || details.contains("expected value"));
|
assert!(
|
||||||
|
details.contains("expected ident") || details.contains("expected value")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
other => panic!("expected invalid response error, got {other:?}"),
|
other => panic!("expected invalid response error, got {other:?}"),
|
||||||
}
|
}
|
||||||
@@ -2047,7 +2046,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn given_child_exits_after_discovery_when_calling_twice_then_second_call_succeeds_after_reset() {
|
fn given_child_exits_after_discovery_when_calling_twice_then_second_call_succeeds_after_reset()
|
||||||
|
{
|
||||||
let runtime = Builder::new_current_thread()
|
let runtime = Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()
|
||||||
@@ -2062,10 +2062,7 @@ mod tests {
|
|||||||
&script_path,
|
&script_path,
|
||||||
"alpha",
|
"alpha",
|
||||||
&log_path,
|
&log_path,
|
||||||
BTreeMap::from([(
|
BTreeMap::from([("MCP_EXIT_AFTER_TOOLS_LIST".to_string(), "1".to_string())]),
|
||||||
"MCP_EXIT_AFTER_TOOLS_LIST".to_string(),
|
|
||||||
"1".to_string(),
|
|
||||||
)]),
|
|
||||||
),
|
),
|
||||||
)]);
|
)]);
|
||||||
let mut manager = McpServerManager::from_servers(&servers);
|
let mut manager = McpServerManager::from_servers(&servers);
|
||||||
@@ -2150,7 +2147,10 @@ mod tests {
|
|||||||
)]);
|
)]);
|
||||||
let mut manager = McpServerManager::from_servers(&servers);
|
let mut manager = McpServerManager::from_servers(&servers);
|
||||||
|
|
||||||
let tools = manager.discover_tools().await.expect("discover tools after retry");
|
let tools = manager
|
||||||
|
.discover_tools()
|
||||||
|
.await
|
||||||
|
.expect("discover tools after retry");
|
||||||
|
|
||||||
assert_eq!(tools.len(), 1);
|
assert_eq!(tools.len(), 1);
|
||||||
assert_eq!(tools[0].qualified_name, mcp_tool_name("alpha", "echo"));
|
assert_eq!(tools[0].qualified_name, mcp_tool_name("alpha", "echo"));
|
||||||
@@ -2166,7 +2166,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn given_tool_call_disconnects_once_when_calling_twice_then_manager_resets_and_next_call_succeeds() {
|
fn given_tool_call_disconnects_once_when_calling_twice_then_manager_resets_and_next_call_succeeds(
|
||||||
|
) {
|
||||||
let runtime = Builder::new_current_thread()
|
let runtime = Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()
|
.build()
|
||||||
@@ -2198,7 +2199,10 @@ mod tests {
|
|||||||
|
|
||||||
manager.discover_tools().await.expect("discover tools");
|
manager.discover_tools().await.expect("discover tools");
|
||||||
let first_error = manager
|
let first_error = manager
|
||||||
.call_tool(&mcp_tool_name("alpha", "echo"), Some(json!({"text": "first"})))
|
.call_tool(
|
||||||
|
&mcp_tool_name("alpha", "echo"),
|
||||||
|
Some(json!({"text": "first"})),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.expect_err("first tool call should fail when transport drops");
|
.expect_err("first tool call should fail when transport drops");
|
||||||
|
|
||||||
@@ -2216,7 +2220,10 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let response = manager
|
let response = manager
|
||||||
.call_tool(&mcp_tool_name("alpha", "echo"), Some(json!({"text": "second"})))
|
.call_tool(
|
||||||
|
&mcp_tool_name("alpha", "echo"),
|
||||||
|
Some(json!({"text": "second"})),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.expect("second tool call should succeed after reset");
|
.expect("second tool call should succeed after reset");
|
||||||
|
|
||||||
|
|||||||
@@ -1864,6 +1864,7 @@ impl LiveCli {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
fn handle_repl_command(
|
fn handle_repl_command(
|
||||||
&mut self,
|
&mut self,
|
||||||
command: SlashCommand,
|
command: SlashCommand,
|
||||||
@@ -3463,7 +3464,7 @@ fn build_runtime_plugin_state_with_loader(
|
|||||||
loader: &ConfigLoader,
|
loader: &ConfigLoader,
|
||||||
runtime_config: &runtime::RuntimeConfig,
|
runtime_config: &runtime::RuntimeConfig,
|
||||||
) -> Result<RuntimePluginState, Box<dyn std::error::Error>> {
|
) -> Result<RuntimePluginState, Box<dyn std::error::Error>> {
|
||||||
let plugin_manager = build_plugin_manager(&cwd, &loader, &runtime_config);
|
let plugin_manager = build_plugin_manager(cwd, loader, runtime_config);
|
||||||
let plugin_registry = plugin_manager.plugin_registry()?;
|
let plugin_registry = plugin_manager.plugin_registry()?;
|
||||||
let plugin_hook_config =
|
let plugin_hook_config =
|
||||||
runtime_hook_config_from_plugin_hooks(plugin_registry.aggregated_hooks()?);
|
runtime_hook_config_from_plugin_hooks(plugin_registry.aggregated_hooks()?);
|
||||||
|
|||||||
@@ -1014,6 +1014,7 @@ struct PlanModeState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
|
#[allow(clippy::struct_excessive_bools)]
|
||||||
struct PlanModeOutput {
|
struct PlanModeOutput {
|
||||||
success: bool,
|
success: bool,
|
||||||
operation: String,
|
operation: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user