MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / execute

Method execute

crates/opencode-tool/src/plan.rs:79–148  ·  view source on GitHub ↗
(
        &self,
        _args: serde_json::Value,
        ctx: ToolContext,
    )

Source from the content-addressed store, hash-verified

77 }
78
79 async fn execute(
80 &self,
81 _args: serde_json::Value,
82 ctx: ToolContext,
83 ) -> Result<ToolResult, ToolError> {
84 let plan_path = get_plan_path(&ctx);
85 let plan_display = plan_path.display();
86
87 let questions = vec![QuestionDef {
88 question: format!(
89 "Would you like to switch to the plan agent and create a plan saved to {}?",
90 plan_display
91 ),
92 header: Some("Plan Mode".to_string()),
93 options: vec![
94 QuestionOption {
95 label: "Yes".to_string(),
96 description: Some("Switch to plan agent for research and planning".to_string()),
97 },
98 QuestionOption {
99 label: "No".to_string(),
100 description: Some(
101 "Stay with build agent to continue making changes".to_string(),
102 ),
103 },
104 ],
105 multiple: false,
106 }];
107
108 let answers = ctx.question(questions).await?;
109
110 let answer = answers
111 .first()
112 .and_then(|a| a.first())
113 .map(|s| s.as_str())
114 .unwrap_or("No");
115
116 if answer == "No" {
117 return Err(ToolError::QuestionRejected(
118 "User rejected plan mode switch".to_string(),
119 ));
120 }
121
122 let model = ctx.do_get_last_model().await;
123
124 // Create a user message + synthetic part (mirrors TS Session.updateMessage + updatePart)
125 let synthetic_text =
126 "User has requested to enter plan mode. Switch to plan mode and begin planning.";
127 create_user_message_with_part(&ctx, "plan", &model, synthetic_text).await?;
128
129 ctx.do_switch_agent("plan".to_string(), model.clone())
130 .await?;
131
132 let mut metadata = Metadata::new();
133 metadata.insert("agent".to_string(), serde_json::json!("plan"));
134 metadata.insert("session_id".to_string(), serde_json::json!(ctx.session_id));
135 if let Some(ref m) = model {
136 metadata.insert("model".to_string(), serde_json::json!(m));

Callers

nothing calls this directly

Calls 8

get_plan_pathFunction · 0.85
newFunction · 0.85
questionMethod · 0.80
do_get_last_modelMethod · 0.80
do_switch_agentMethod · 0.80
as_strMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected