Files
g3/crates/g3-core/src/tool_dispatch.rs
Dhanji R. Prasanna a63950d8f5 Add Plan Mode to replace TODO system
Plan Mode is a cognitive forcing system that requires reasoning about:
- Happy path
- Negative case
- Boundary condition

New tools:
- plan_read: Read current plan for session
- plan_write: Create/update plan with YAML content (validates structure)
- plan_approve: Mark current revision as approved

New command:
- /feature <description>: Start Plan Mode for a new feature

Plan schema requires:
- plan_id, revision, approved_revision
- items with id, description, state, touches, checks (happy/negative/boundary)
- evidence and notes required when marking items done

Verification:
- plan_verify() called automatically when all items are done/blocked

Removed:
- todo_read, todo_write tools
- todo.rs module and related tests
2026-02-02 14:38:25 +11:00

79 lines
3.8 KiB
Rust

//! Tool dispatch module - routes tool calls to their implementations.
//!
//! This module provides a clean dispatch mechanism that routes tool calls
//! to the appropriate handler in the `tools/` module.
use anyhow::Result;
use tracing::{debug, warn};
use crate::tools::executor::ToolContext;
use crate::tools::{acd, file_ops, memory, misc, plan, research, shell, webdriver};
use crate::ui_writer::UiWriter;
use crate::ToolCall;
/// Dispatch a tool call to the appropriate handler.
///
/// This function routes tool calls to their implementations in the `tools/` module,
/// providing a single point of dispatch for all tool execution.
pub async fn dispatch_tool<W: UiWriter>(
tool_call: &ToolCall,
ctx: &mut ToolContext<'_, W>,
) -> Result<String> {
debug!("Dispatching tool: {}", tool_call.tool);
match tool_call.tool.as_str() {
// Shell tools
"shell" => shell::execute_shell(tool_call, ctx).await,
"background_process" => shell::execute_background_process(tool_call, ctx).await,
// File operations
"read_file" => file_ops::execute_read_file(tool_call, ctx).await,
"read_image" => file_ops::execute_read_image(tool_call, ctx).await,
"write_file" => file_ops::execute_write_file(tool_call, ctx).await,
"str_replace" => file_ops::execute_str_replace(tool_call, ctx).await,
// Plan Mode
"plan_read" => plan::execute_plan_read(tool_call, ctx).await,
"plan_write" => plan::execute_plan_write(tool_call, ctx).await,
"plan_approve" => plan::execute_plan_approve(tool_call, ctx).await,
// Miscellaneous tools
"screenshot" => misc::execute_take_screenshot(tool_call, ctx).await,
"coverage" => misc::execute_code_coverage(tool_call, ctx).await,
"code_search" => misc::execute_code_search(tool_call, ctx).await,
// Research tool
"research" => research::execute_research(tool_call, ctx).await,
"research_status" => research::execute_research_status(tool_call, ctx).await,
// Workspace memory tools
"remember" => memory::execute_remember(tool_call, ctx).await,
// ACD (Aggressive Context Dehydration) tools
"rehydrate" => acd::execute_rehydrate(tool_call, ctx).await,
// WebDriver tools
"webdriver_start" => webdriver::execute_webdriver_start(tool_call, ctx).await,
"webdriver_navigate" => webdriver::execute_webdriver_navigate(tool_call, ctx).await,
"webdriver_get_url" => webdriver::execute_webdriver_get_url(tool_call, ctx).await,
"webdriver_get_title" => webdriver::execute_webdriver_get_title(tool_call, ctx).await,
"webdriver_find_element" => webdriver::execute_webdriver_find_element(tool_call, ctx).await,
"webdriver_find_elements" => webdriver::execute_webdriver_find_elements(tool_call, ctx).await,
"webdriver_click" => webdriver::execute_webdriver_click(tool_call, ctx).await,
"webdriver_send_keys" => webdriver::execute_webdriver_send_keys(tool_call, ctx).await,
"webdriver_execute_script" => webdriver::execute_webdriver_execute_script(tool_call, ctx).await,
"webdriver_get_page_source" => webdriver::execute_webdriver_get_page_source(tool_call, ctx).await,
"webdriver_screenshot" => webdriver::execute_webdriver_screenshot(tool_call, ctx).await,
"webdriver_back" => webdriver::execute_webdriver_back(tool_call, ctx).await,
"webdriver_forward" => webdriver::execute_webdriver_forward(tool_call, ctx).await,
"webdriver_refresh" => webdriver::execute_webdriver_refresh(tool_call, ctx).await,
"webdriver_quit" => webdriver::execute_webdriver_quit(tool_call, ctx).await,
// Unknown tool
_ => {
warn!("Unknown tool: {}", tool_call.tool);
Ok(format!("❓ Unknown tool: {}", tool_call.tool))
}
}
}