1use crate::agent::inference::{tool_metadata_for_name, ToolDefinition, ToolFunction};
2use serde_json::Value;
3
4fn make_tool(name: &str, description: &str, parameters: Value) -> ToolDefinition {
5 ToolDefinition {
6 tool_type: "function".into(),
7 function: ToolFunction {
8 name: name.into(),
9 description: description.into(),
10 parameters,
11 },
12 metadata: tool_metadata_for_name(name),
13 }
14}
15
16pub fn get_tools() -> Vec<ToolDefinition> {
18 let os = std::env::consts::OS;
19 let mut tools = vec![
20 make_tool(
21 "shell",
22 &format!(
23 "Execute a command in the host shell ({os}). \
24 Use this for building, testing, or system operations. \
25 Output is capped at 64KB. Prefer non-interactive commands."
26 ),
27 serde_json::json!({
28 "type": "object",
29 "properties": {
30 "command": {
31 "type": "string",
32 "description": "The command to run"
33 },
34 "reason": {
35 "type": "string",
36 "description": "For risky shell calls, explain what this command is verifying or changing."
37 },
38 "timeout_secs": {
39 "type": "integer",
40 "description": "Optional timeout in seconds (default 60)"
41 }
42 },
43 "required": ["command"]
44 }),
45 ),
46 make_tool(
47 "run_code",
48 "Execute a short JavaScript/TypeScript or Python snippet in a sandboxed subprocess. \
49 No network access, no filesystem escape, hard 10-second timeout. \
50 Use this to verify logic, test algorithms, compute values, or test functions \
51 when you need real output rather than a guess. \
52 ALWAYS include the `language` field — there is no default. \
53 \
54 JAVASCRIPT/TYPESCRIPT (language: \"javascript\"): \
55 Runs via Deno, NOT Node.js. `require()` does not exist — never use it. \
56 URL imports (e.g. from 'https://deno.land/...') are blocked — network is off. \
57 Use built-in Web APIs only: `crypto.subtle`, `TextEncoder`, `URL`, `atob`/`btoa`, etc. \
58 SHA-256 example: \
59 const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode('hello')); \
60 console.log([...new Uint8Array(buf)].map(b=>b.toString(16).padStart(2,'0')).join('')); \
61 \
62 PYTHON (language: \"python\"): \
63 Standard library is available. `hashlib`, `json`, `math`, `datetime`, `re`, `itertools` all work. \
64 `subprocess`, `socket`, `urllib`, `requests` are blocked. \
65 SHA-256 example: import hashlib; print(hashlib.sha256(b'hello').hexdigest()) \
66 \
67 Do NOT fall back to shell to run deno, python, or node — use this tool directly.",
68 serde_json::json!({
69 "type": "object",
70 "properties": {
71 "language": {
72 "type": "string",
73 "enum": ["javascript", "typescript", "python"],
74 "description": "The language to run. javascript/typescript requires Deno; python requires Python 3."
75 },
76 "code": {
77 "type": "string",
78 "description": "The code to execute. Keep it short and self-contained. Print results to stdout."
79 },
80 "timeout_seconds": {
81 "type": "integer",
82 "description": "Max execution time in seconds (default 10, max 60). Use higher values for longer computations."
83 }
84 },
85 "required": ["language", "code"]
86 }),
87 ),
88 make_tool(
89 "map_project",
90 "Compact architecture-aware map of the project structure, key configuration files, \
91 likely entrypoints, and core owner files. Use this at the start of a task to gain \
92 spatial awareness before deeper file reads or LSP inspection.",
93 serde_json::json!({
94 "type": "object",
95 "properties": {
96 "focus": {
97 "type": "string",
98 "description": "Optional relative subpath to focus the map on instead of the whole workspace."
99 },
100 "include_symbols": {
101 "type": "boolean",
102 "description": "Whether to extract a small set of top symbols from core files. Defaults to true."
103 },
104 "max_depth": {
105 "type": "integer",
106 "description": "Optional tree depth cap for the directory section. Defaults to 4 and is capped internally."
107 }
108 }
109 }),
110 ),
111 make_tool(
112 "trace_runtime_flow",
113 "Return an authoritative read-only trace of Hematite runtime flow. \
114 Use this for architecture questions about keyboard input to final output, \
115 reasoning/specular separation, startup wiring, runtime subsystems, \
116 voice synthesis and Ctrl+T toggle, or \
117 session reset commands like /clear, /new, and /forget. Prefer this over guessing.",
118 serde_json::json!({
119 "type": "object",
120 "properties": {
121 "topic": {
122 "type": "string",
123 "enum": ["user_turn", "session_reset", "reasoning_split", "runtime_subsystems", "startup", "voice"],
124 "description": "Which verified runtime report to return. Use 'voice' for any question about Ctrl+T, voice toggle, or TTS pipeline. Use 'user_turn' for keyboard-to-output flow. Use 'session_reset' for /clear, /forget, /new. Use 'startup' for startup wiring. Use 'reasoning_split' for specular/thought routing. Use 'runtime_subsystems' for background subsystem overview."
125 },
126 "input": {
127 "type": "string",
128 "description": "Optional user input to label a normal user-turn trace"
129 },
130 "command": {
131 "type": "string",
132 "enum": ["/clear", "/new", "/forget", "all"],
133 "description": "Optional reset command when topic=session_reset"
134 }
135 },
136 "required": ["topic"]
137 }),
138 ),
139 make_tool(
140 "describe_toolchain",
141 "Return an authoritative read-only description of Hematite's actual tool surface and investigation strategy. \
142 Use this for tooling-discipline questions, best-tool selection, or read-only plans for tracing runtime behavior. \
143 Prefer this over improvising tool names or investigation steps from memory.",
144 serde_json::json!({
145 "type": "object",
146 "properties": {
147 "topic": {
148 "type": "string",
149 "enum": ["read_only_codebase", "user_turn_plan", "voice_latency_plan", "host_inspection_plan", "all"],
150 "description": "Which authoritative toolchain report to return"
151 },
152 "question": {
153 "type": "string",
154 "description": "Optional user question to label or tailor the read-only investigation plan"
155 }
156 }
157 }),
158 ),
159 make_tool(
160 "inspect_host",
161 "Return a structured read-only inspection of the current machine and environment. \
162 Prefer this over raw shell for questions about installed developer tools, PATH issues, desktop items, Downloads size, open listening ports, repo health, or directory/disk summaries. \
163 Use topic=summary for a compact host snapshot, topic=toolchains for common dev tool versions, topic=path for PATH analysis, \
164 topic=desktop or topic=downloads for known folders, topic=ports for listening endpoints, topic=repo_doctor for a structured workspace health report, \
165 and topic=directory or topic=disk for arbitrary paths.",
166 serde_json::json!({
167 "type": "object",
168 "properties": {
169 "topic": {
170 "type": "string",
171 "enum": ["summary", "toolchains", "path", "desktop", "downloads", "directory", "disk", "ports", "repo_doctor"],
172 "description": "Which structured host inspection to run."
173 },
174 "path": {
175 "type": "string",
176 "description": "Required when topic=directory. Optional for topic=disk or topic=repo_doctor. Absolute or relative path to inspect."
177 },
178 "port": {
179 "type": "integer",
180 "description": "Optional when topic=ports. Filter the result to one listening TCP port."
181 },
182 "max_entries": {
183 "type": "integer",
184 "description": "Optional cap for listed entries. Defaults to 10 and is capped internally."
185 }
186 }
187 }),
188 ),
189 make_tool(
190 "read_file",
191 "Read the contents of a file. For large files, use 'offset' and 'limit' to navigate.",
192 serde_json::json!({
193 "type": "object",
194 "properties": {
195 "path": {
196 "type": "string",
197 "description": "Path to the file, relative to the project root"
198 },
199 "offset": {
200 "type": "integer",
201 "description": "Starting line number (0-indexed)"
202 },
203 "limit": {
204 "type": "integer",
205 "description": "Number of lines to read"
206 }
207 },
208 "required": ["path"]
209 }),
210 ),
211 make_tool(
212 "lsp_definitions",
213 "Get the precise definition location (file:line:char) for a symbol at a specific position. \
214 Use this to jump to function/struct source code accurately.",
215 serde_json::json!({
216 "type": "object",
217 "properties": {
218 "path": { "type": "string", "description": "File path" },
219 "line": { "type": "integer", "description": "0-indexed line" },
220 "character": { "type": "integer", "description": "0-indexed character" }
221 },
222 "required": ["path", "line", "character"]
223 }),
224 ),
225 make_tool(
226 "lsp_references",
227 "Find all locations where a symbol is used across the entire workspace. \
228 Use this to understand the impact of a refactor or discover internal API users.",
229 serde_json::json!({
230 "type": "object",
231 "properties": {
232 "path": { "type": "string", "description": "File path" },
233 "line": { "type": "integer", "description": "0-indexed line" },
234 "character": { "type": "integer", "description": "0-indexed character" }
235 },
236 "required": ["path", "line", "character"]
237 }),
238 ),
239 make_tool(
240 "lsp_hover",
241 "Get hover information (documentation, function signature, type details) for a symbol. \
242 Use this for rapid spatial awareness without opening every file.",
243 serde_json::json!({
244 "type": "object",
245 "properties": {
246 "path": { "type": "string", "description": "File path" },
247 "line": { "type": "integer", "description": "0-indexed line" },
248 "character": { "type": "integer", "description": "0-indexed character" }
249 },
250 "required": ["path", "line", "character"]
251 }),
252 ),
253 make_tool(
254 "lsp_rename_symbol",
255 "Rename a symbol project-wide using the Language Server. Ensures all references are updated safely.",
256 serde_json::json!({
257 "type": "object",
258 "properties": {
259 "path": { "type": "string", "description": "File path" },
260 "line": { "type": "integer", "description": "0-indexed line" },
261 "character": { "type": "integer", "description": "0-indexed character" },
262 "new_name": { "type": "string", "description": "The new name for the symbol" }
263 },
264 "required": ["path", "line", "character", "new_name"]
265 }),
266 ),
267 make_tool(
268 "lsp_get_diagnostics",
269 "Get a list of current compiler errors and warnings for a specific file. \
270 Use this to verify your code compiles and and to find exactly where errors are located.",
271 serde_json::json!({
272 "type": "object",
273 "properties": {
274 "path": { "type": "string", "description": "File path" }
275 },
276 "required": ["path"]
277 }),
278 ),
279 make_tool(
280 "vision_analyze",
281 "Send an image file (screenshot, diagram, or UI mockup) to the multimodal vision model for technical analysis. \
282 Use this to identify UI bugs, confirm visual states, or understand architectural diagrams.",
283 serde_json::json!({
284 "type": "object",
285 "properties": {
286 "path": { "type": "string", "description": "Absolute or relative path to the image file." },
287 "prompt": { "type": "string", "description": "The specific question or analysis request for the vision model." }
288 },
289 "required": ["path", "prompt"]
290 }),
291 ),
292 make_tool(
293 "patch_hunk",
294 "Replace a specific line range [start_line, end_line] with new content. \
295 This is the most precise way to edit code and avoids search string failures.",
296 serde_json::json!({
297 "type": "object",
298 "properties": {
299 "path": { "type": "string", "description": "File path" },
300 "start_line": { "type": "integer", "description": "Starting line (1-indexed)" },
301 "end_line": { "type": "integer", "description": "Ending line (inclusive)" },
302 "replacement": { "type": "string", "description": "The new content for this range" }
303 },
304 "required": ["path", "start_line", "end_line", "replacement"]
305 }),
306 ),
307 make_tool(
308 "multi_search_replace",
309 "Replace multiple existing code blocks in a single file with new content. \
310 Each hunk specifies an EXACT 'search' string and a 'replace' string. \
311 The 'search' string MUST exactly match the existing file contents (including whitespace). \
312 This is the safest and most reliable way to make multiple structural edits.",
313 serde_json::json!({
314 "type": "object",
315 "properties": {
316 "path": { "type": "string", "description": "File path" },
317 "hunks": {
318 "type": "array",
319 "items": {
320 "type": "object",
321 "properties": {
322 "search": { "type": "string", "description": "Exact existing text to find and replace" },
323 "replace": { "type": "string", "description": "The new replacement text" }
324 },
325 "required": ["search", "replace"]
326 }
327 }
328 },
329 "required": ["path", "hunks"]
330 }),
331 ),
332 make_tool(
333 "write_file",
334 "Write content to a file, creating it (and any parent dirs) if needed. \
335 Overwrites existing files.",
336 serde_json::json!({
337 "type": "object",
338 "properties": {
339 "path": { "type": "string", "description": "File path" },
340 "content": { "type": "string", "description": "Full file content to write" }
341 },
342 "required": ["path", "content"]
343 }),
344 ),
345 make_tool(
346 "research_web",
347 "Perform a zero-cost technical search using DuckDuckGo. \
348 Use this to find documentation, latest API changes, or solutions to complex errors \
349 when your internal knowledge is insufficient. Returns snippets and URLs.",
350 serde_json::json!({
351 "type": "object",
352 "properties": {
353 "query": { "type": "string", "description": "The technical search query" }
354 },
355 "required": ["query"]
356 }),
357 ),
358 make_tool(
359 "fetch_docs",
360 "Fetch a URL and convert it to clean Markdown. Use this to 'read' the documentation \
361 links found via research_web. This tool uses a proxy to bypass IP blocks.",
362 serde_json::json!({
363 "type": "object",
364 "properties": {
365 "url": { "type": "string", "description": "The URL of the documentation to fetch" }
366 },
367 "required": ["url"]
368 }),
369 ),
370 make_tool(
371 "edit_file",
372 "Edit a file by replacing an exact string with another. \
373 The 'search' string does NOT need perfectly matching indentation (it is fuzzy), \
374 but the non-whitespace text must match exactly. Use this for targeted edits.",
375 serde_json::json!({
376 "type": "object",
377 "properties": {
378 "path": { "type": "string", "description": "File path" },
379 "search": {
380 "type": "string",
381 "description": "The exact text to find (must match whitespace/indentation precisely)"
382 },
383 "replace": {
384 "type": "string",
385 "description": "The replacement text"
386 }
387 },
388 "required": ["path", "search", "replace"]
389 }),
390 ),
391 make_tool(
392 "auto_pin_context",
393 "Select 1-3 core files to 'Lock' into high-fidelity memory. \
394 Use this after map_project to ensure the most important architecture files \
395 are always visible during complex refactorings.",
396 serde_json::json!({
397 "type": "object",
398 "properties": {
399 "paths": {
400 "type": "array",
401 "items": { "type": "string" }
402 },
403 "reason": { "type": "string" }
404 },
405 "required": ["paths", "reason"]
406 }),
407 ),
408 make_tool(
409 "list_pinned",
410 "List all files currently pinned in the model's active context.",
411 serde_json::json!({
412 "type": "object",
413 "properties": {}
414 }),
415 ),
416 make_tool(
417 "list_files",
418 "List files in a directory, optionally filtered by extension.",
419 serde_json::json!({
420 "type": "object",
421 "properties": {
422 "path": {
423 "type": "string",
424 "description": "Directory to list (default: current dir)"
425 },
426 "extension": {
427 "type": "string",
428 "description": "Only return files with this extension, e.g. 'rs', 'toml' (no dot)"
429 }
430 },
431 "required": []
432 }),
433 ),
434 make_tool(
435 "grep_files",
436 "Search file contents for a regex pattern. Supports context lines, files-only mode, \
437 and pagination. Returns file:line:content format by default.",
438 serde_json::json!({
439 "type": "object",
440 "properties": {
441 "pattern": {
442 "type": "string",
443 "description": "Regex pattern to search for (case-insensitive by default)"
444 },
445 "path": {
446 "type": "string",
447 "description": "Directory to search (default: current dir)"
448 },
449 "extension": {
450 "type": "string",
451 "description": "Only search files with this extension, e.g. 'rs'"
452 },
453 "mode": {
454 "type": "string",
455 "enum": ["content", "files_only"],
456 "description": "'content' (default) returns matching lines; 'files_only' returns only filenames"
457 },
458 "context": {
459 "type": "integer",
460 "description": "Lines of context before AND after each match (like rg -C)"
461 },
462 "before": {
463 "type": "integer",
464 "description": "Lines of context before each match (overrides context)"
465 },
466 "after": {
467 "type": "integer",
468 "description": "Lines of context after each match (overrides context)"
469 },
470 "head_limit": {
471 "type": "integer",
472 "description": "Max hunks (or files in files_only) to return (default: 50)"
473 },
474 "offset": {
475 "type": "integer",
476 "description": "Skip first N hunks/files - for pagination (default: 0)"
477 }
478 },
479 "required": ["pattern"]
480 }),
481 ),
482 make_tool(
483 "git_commit",
484 "Stage all changes (git add -A) and create a commit. You MUST use 'Conventional Commits' (e.g. 'feat: description').",
485 serde_json::json!({
486 "type": "object",
487 "properties": {
488 "message": { "type": "string", "description": "Commit message (Conventional Commit style)" }
489 },
490 "required": ["message"]
491 }),
492 ),
493 make_tool(
494 "git_push",
495 "Push current branched changes to the remote origin. Requires an existing remote connection.",
496 serde_json::json!({
497 "type": "object",
498 "properties": {},
499 "required": []
500 }),
501 ),
502 make_tool(
503 "git_remote",
504 "View or manage git remotes. Use this for onboarding to GitHub/GitLab services.",
505 serde_json::json!({
506 "type": "object",
507 "properties": {
508 "action": {
509 "type": "string",
510 "enum": ["list", "add", "remove"],
511 "description": "Operation to perform"
512 },
513 "name": { "type": "string", "description": "Remote name (e.g. origin)" },
514 "url": { "type": "string", "description": "Remote URL (for 'add' action)" }
515 },
516 "required": ["action"]
517 }),
518 ),
519 make_tool(
520 "git_onboarding",
521 "High-level wizard to connect this repository to a remote host (GitHub/GitLab). \
522 Handles adding the remote and performing the initial tracking push in one step.",
523 serde_json::json!({
524 "type": "object",
525 "properties": {
526 "url": { "type": "string", "description": "The remote repository URL (HTTPS or SSH)" },
527 "name": { "type": "string", "description": "The remote name (default: origin)" },
528 "push": { "type": "boolean", "description": "Whether to perform an initial push to establish tracking (default: false)" }
529 },
530 "required": ["url"]
531 }),
532 ),
533 make_tool(
534 "verify_build",
535 "Run project verification for build, test, lint, or fix workflows. \
536 Prefer per-project verify profiles from `.hematite/settings.json`, and fall back to \
537 auto-detected defaults when no profile is configured. Returns BUILD OK or BUILD FAILED \
538 with command output. ALWAYS call this after scaffolding a new project or making structural changes.",
539 serde_json::json!({
540 "type": "object",
541 "properties": {
542 "action": {
543 "type": "string",
544 "enum": ["build", "test", "lint", "fix"],
545 "description": "Which verification action to run. Defaults to build."
546 },
547 "profile": {
548 "type": "string",
549 "description": "Optional named verify profile from `.hematite/settings.json`."
550 },
551 "timeout_secs": {
552 "type": "integer",
553 "description": "Optional timeout override for this verification run."
554 }
555 }
556 }),
557 ),
558 make_tool(
559 "git_worktree",
560 "Manage Git worktrees - isolated working directories on separate branches. \
561 Use 'add' to create a safe sandbox for risky/experimental work, \
562 'list' to see all worktrees, 'remove' to clean up, 'prune' to remove stale entries.",
563 serde_json::json!({
564 "type": "object",
565 "properties": {
566 "action": {
567 "type": "string",
568 "enum": ["list", "add", "remove", "prune"],
569 "description": "Worktree operation to perform"
570 },
571 "path": {
572 "type": "string",
573 "description": "Directory path for the new worktree (required for add/remove)"
574 },
575 "branch": {
576 "type": "string",
577 "description": "Branch name for the worktree (add only; defaults to path basename)"
578 }
579 },
580 "required": ["action"]
581 }),
582 ),
583 make_tool(
584 "clarify",
585 "Ask the user a clarifying question when you genuinely cannot proceed without \
586 more information. Use this ONLY when you are blocked and cannot make a \
587 reasonable assumption. Do NOT use it to ask permission - just act.",
588 serde_json::json!({
589 "type": "object",
590 "properties": {
591 "question": {
592 "type": "string",
593 "description": "The specific question to ask the user"
594 }
595 },
596 "required": ["question"]
597 }),
598 ),
599 make_tool(
600 "manage_tasks",
601 "Manage the persistent task ledger in .hematite/TASK.md. Use this to track long-term goals across restarts.",
602 crate::tools::tasks::get_tasks_params(),
603 ),
604 make_tool(
605 "maintain_plan",
606 "Document the architectural strategy and session blueprint in .hematite/PLAN.md. Use this to maintain context across restarts.",
607 crate::tools::plan::get_plan_params(),
608 ),
609 make_tool(
610 "generate_walkthrough",
611 "Generate a final session report in .hematite/WALKTHROUGH.md including achievements and verification results.",
612 crate::tools::plan::get_walkthrough_params(),
613 ),
614 make_tool(
615 "swarm",
616 "Delegate high-volume parallel tasks to a swarm of background workers. \
617 Use this for large-scale refactors, multi-file research, or parallel documentation updates. \
618 You must provide a 'tasks' array where each task has an 'id', 'target' (file), and 'instruction'.",
619 serde_json::json!({
620 "type": "object",
621 "properties": {
622 "tasks": {
623 "type": "array",
624 "items": {
625 "type": "object",
626 "properties": {
627 "id": { "type": "string" },
628 "target": { "type": "string", "description": "Target file or directory" },
629 "instruction": { "type": "string", "description": "Specific task for this worker" }
630 },
631 "required": ["id", "target", "instruction"]
632 }
633 },
634 "max_workers": {
635 "type": "integer",
636 "description": "Max parallel workers (default 3, auto-throttled by hardware)",
637 "default": 3
638 }
639 },
640 "required": ["tasks"]
641 }),
642 ),
643 ];
644
645 let lsp_defs = crate::tools::lsp_tools::get_lsp_definitions();
646 tools.push(make_tool(
647 "lsp_search_symbol",
648 "Find the location (file/line) of any function, struct, or variable in the entire project workspace. \
649 This is the fastest 'Golden Path' for navigating to a symbol by name.",
650 serde_json::json!({
651 "type": "object",
652 "properties": {
653 "query": { "type": "string", "description": "The name of the symbol to find (e.g. 'initialize_mcp')" }
654 },
655 "required": ["query"]
656 }),
657 ));
658 for def in lsp_defs {
659 let name = def["name"].as_str().unwrap();
660 tools.push(ToolDefinition {
661 tool_type: "function".into(),
662 function: ToolFunction {
663 name: name.into(),
664 description: def["description"].as_str().unwrap().into(),
665 parameters: def["parameters"].clone(),
666 },
667 metadata: tool_metadata_for_name(name),
668 });
669 }
670
671 tools
672}
673
674pub async fn dispatch_builtin_tool(name: &str, args: &Value) -> Result<String, String> {
675 match name {
676 "shell" => crate::tools::shell::execute(args).await,
677 "run_code" => crate::tools::code_sandbox::execute(args).await,
678 "map_project" => crate::tools::project_map::map_project(args).await,
679 "trace_runtime_flow" => crate::tools::runtime_trace::trace_runtime_flow(args).await,
680 "describe_toolchain" => crate::tools::toolchain::describe_toolchain(args).await,
681 "inspect_host" => crate::tools::host_inspect::inspect_host(args).await,
682 "read_file" => crate::tools::file_ops::read_file(args).await,
683 "inspect_lines" => crate::tools::file_ops::inspect_lines(args).await,
684 "write_file" => crate::tools::file_ops::write_file(args).await,
685 "edit_file" => crate::tools::file_ops::edit_file(args).await,
686 "patch_hunk" => crate::tools::file_ops::patch_hunk(args).await,
687 "multi_search_replace" => crate::tools::file_ops::multi_search_replace(args).await,
688 "list_files" => crate::tools::file_ops::list_files(args).await,
689 "grep_files" => crate::tools::file_ops::grep_files(args).await,
690 "git_commit" => crate::tools::git::execute(args).await,
691 "git_push" => crate::tools::git::execute_push(args).await,
692 "git_remote" => crate::tools::git::execute_remote(args).await,
693 "git_onboarding" => crate::tools::git_onboarding::execute(args).await,
694 "verify_build" => crate::tools::verify_build::execute(args).await,
695 "git_worktree" => crate::tools::git::execute_worktree(args).await,
696 "health" => crate::tools::health::execute(args).await,
697 "research_web" => crate::tools::research::execute_search(args).await,
698 "fetch_docs" => crate::tools::research::execute_fetch(args).await,
699 "manage_tasks" => crate::tools::tasks::manage_tasks(args).await,
700 "maintain_plan" => crate::tools::plan::maintain_plan(args).await,
701 "generate_walkthrough" => crate::tools::plan::generate_walkthrough(args).await,
702 "clarify" => {
703 let q = args.get("question").and_then(|v| v.as_str()).unwrap_or("?");
704 Ok(format!("[clarify] {q}"))
705 }
706 "vision_analyze" => Err(
707 "Tool 'vision_analyze' must be dispatched by ConversationManager (it requires hardware engine access)."
708 .into(),
709 ),
710 other => {
711 if other.contains('.') || other.contains('/') || other.contains('\\') {
712 Err(format!(
713 "'{}' is a PATH, not a tool. You correctly identified the location, but you MUST use `read_file` or `list_files` (internal) or `powershell` (external) to access it.",
714 other
715 ))
716 } else if matches!(other.to_lowercase().as_str(), "hematite" | "assistant" | "ai") {
717 Err(format!(
718 "'{}' is YOUR IDENTITY, not a tool. Use list_files or read_file to explore the codebase.",
719 other
720 ))
721 } else if matches!(
722 other.to_lowercase().as_str(),
723 "thought" | "think" | "reasoning" | "thinking" | "internal"
724 ) {
725 Err(format!(
726 "'{}' is NOT a tool - it is a reasoning tag. Output your answer as plain text after your <think> block.",
727 other
728 ))
729 } else {
730 Err(format!("Unknown tool: '{}'", other))
731 }
732 }
733 }
734}