MCPcopy Create free account
hub / github.com/AI45Lab/Code / build_command_context

Function build_command_context

core/src/agent_api/command_runtime.rs:71–101  ·  view source on GitHub ↗
(session: &AgentSession)

Source from the content-addressed store, hash-verified

69}
70
71fn build_command_context(session: &AgentSession) -> CommandContext {
72 let history = read_or_recover(&session.history);
73 let tool_names: Vec<String> = session
74 .tool_executor
75 .definitions()
76 .into_iter()
77 .map(|tool| tool.name)
78 .collect();
79
80 let mut mcp_map = std::collections::HashMap::new();
81 for name in &tool_names {
82 if let Some(rest) = name.strip_prefix("mcp__") {
83 if let Some((server, _)) = rest.split_once("__") {
84 *mcp_map.entry(server.to_string()).or_default() += 1;
85 }
86 }
87 }
88 let mut mcp_servers: Vec<(String, usize)> = mcp_map.into_iter().collect();
89 mcp_servers.sort_by(|a, b| a.0.cmp(&b.0));
90
91 CommandContext {
92 session_id: session.session_id.clone(),
93 workspace: session.workspace.display().to_string(),
94 model: session.model_name.clone(),
95 history_len: history.len(),
96 total_tokens: 0,
97 total_cost: 0.0,
98 tool_names,
99 mcp_servers,
100 }
101}
102
103async fn send_text_output(tx: &mpsc::Sender<AgentEvent>, text: String) {
104 let _ = tx.send(AgentEvent::TextDelta { text: text.clone() }).await;

Callers 2

dispatch_blockingFunction · 0.85
dispatch_streamingFunction · 0.85

Calls 4

read_or_recoverFunction · 0.85
definitionsMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected