Skip to main content

lean_ctx/
tool_defs.rs

1use std::sync::Arc;
2
3use rmcp::model::*;
4use serde_json::{json, Map, Value};
5
6pub fn tool_def(name: &'static str, description: &'static str, schema_value: Value) -> Tool {
7    let schema: Map<String, Value> = match schema_value {
8        Value::Object(map) => map,
9        _ => Map::new(),
10    };
11    Tool::new(name, description, Arc::new(schema))
12}
13
14pub fn granular_tool_defs() -> Vec<Tool> {
15    vec![
16        tool_def(
17            "ctx_read",
18            "Read file (cached, compressed). Re-reads ~13 tok. Auto-selects optimal mode. \
19Modes: full|map|signatures|diff|aggressive|entropy|task|reference|lines:N-M. fresh=true re-reads.",
20            json!({
21                "type": "object",
22                "properties": {
23                    "path": { "type": "string", "description": "Absolute file path to read" },
24                    "mode": {
25                        "type": "string",
26                        "description": "Compression mode (default: full). Use 'map' for context-only files. For line ranges: 'lines:N-M' (e.g. 'lines:400-500')."
27                    },
28                    "start_line": {
29                        "type": "integer",
30                        "description": "Read from this line number to end of file. Bypasses cache stub — always returns actual content."
31                    },
32                    "fresh": {
33                        "type": "boolean",
34                        "description": "Bypass cache and force a full re-read. Use when running as a subagent that may not have the parent's context."
35                    }
36                },
37                "required": ["path"]
38            }),
39        ),
40        tool_def(
41            "ctx_multi_read",
42            "Batch read files in one call. Same modes as ctx_read.",
43            json!({
44                "type": "object",
45                "properties": {
46                    "paths": {
47                        "type": "array",
48                        "items": { "type": "string" },
49                        "description": "Absolute file paths to read, in order"
50                    },
51                    "mode": {
52                        "type": "string",
53                        "enum": ["full", "signatures", "map", "diff", "aggressive", "entropy"],
54                        "description": "Compression mode (default: full)"
55                    }
56                },
57                "required": ["paths"]
58            }),
59        ),
60        tool_def(
61            "ctx_tree",
62            "Directory listing with file counts.",
63            json!({
64                "type": "object",
65                "properties": {
66                    "path": { "type": "string", "description": "Directory path (default: .)" },
67                    "depth": { "type": "integer", "description": "Max depth (default: 3)" },
68                    "show_hidden": { "type": "boolean", "description": "Show hidden files" }
69                }
70            }),
71        ),
72        tool_def(
73            "ctx_shell",
74            "Run shell command (compressed output, 90+ patterns). Use raw=true to skip compression. cwd sets working directory (persists across calls via cd tracking).",
75            json!({
76                "type": "object",
77                "properties": {
78                    "command": { "type": "string", "description": "Shell command to execute" },
79                    "raw": { "type": "boolean", "description": "Skip compression, return full uncompressed output. Use for small outputs or when full detail is critical." },
80                    "cwd": { "type": "string", "description": "Working directory for the command. If omitted, uses last cd target or project root." }
81                },
82                "required": ["command"]
83            }),
84        ),
85        tool_def(
86            "ctx_search",
87            "Regex code search (.gitignore aware, compact results).",
88            json!({
89                "type": "object",
90                "properties": {
91                    "pattern": { "type": "string", "description": "Regex pattern" },
92                    "path": { "type": "string", "description": "Directory to search" },
93                    "ext": { "type": "string", "description": "File extension filter" },
94                    "max_results": { "type": "integer", "description": "Max results (default: 20)" },
95                    "ignore_gitignore": { "type": "boolean", "description": "Set true to scan ALL files including .gitignore'd paths (default: false)" }
96                },
97                "required": ["pattern"]
98            }),
99        ),
100        tool_def(
101            "ctx_compress",
102            "Context checkpoint for long conversations.",
103            json!({
104                "type": "object",
105                "properties": {
106                    "include_signatures": { "type": "boolean", "description": "Include signatures (default: true)" }
107                }
108            }),
109        ),
110        tool_def(
111            "ctx_benchmark",
112            "Benchmark compression modes for a file or project.",
113            json!({
114                "type": "object",
115                "properties": {
116                    "path": { "type": "string", "description": "File path (action=file) or project directory (action=project)" },
117                    "action": { "type": "string", "description": "file (default) or project", "default": "file" },
118                    "format": { "type": "string", "description": "Output format for project benchmark: terminal, markdown, json", "default": "terminal" }
119                },
120                "required": ["path"]
121            }),
122        ),
123        tool_def(
124            "ctx_metrics",
125            "Session token stats, cache rates, per-tool savings.",
126            json!({
127                "type": "object",
128                "properties": {}
129            }),
130        ),
131        tool_def(
132            "ctx_analyze",
133            "Entropy analysis — recommends optimal compression mode for a file.",
134            json!({
135                "type": "object",
136                "properties": {
137                    "path": { "type": "string", "description": "File path to analyze" }
138                },
139                "required": ["path"]
140            }),
141        ),
142        tool_def(
143            "ctx_cache",
144            "Cache ops: status|clear|invalidate.",
145            json!({
146                "type": "object",
147                "properties": {
148                    "action": {
149                        "type": "string",
150                        "enum": ["status", "clear", "invalidate"],
151                        "description": "Cache operation to perform"
152                    },
153                    "path": {
154                        "type": "string",
155                        "description": "File path (required for 'invalidate' action)"
156                    }
157                },
158                "required": ["action"]
159            }),
160        ),
161        tool_def(
162            "ctx_discover",
163            "Find missed compression opportunities in shell history.",
164            json!({
165                "type": "object",
166                "properties": {
167                    "limit": {
168                        "type": "integer",
169                        "description": "Max number of command types to show (default: 15)"
170                    }
171                }
172            }),
173        ),
174        tool_def(
175            "ctx_smart_read",
176            "Auto-select optimal read mode for a file.",
177            json!({
178                "type": "object",
179                "properties": {
180                    "path": { "type": "string", "description": "Absolute file path to read" }
181                },
182                "required": ["path"]
183            }),
184        ),
185        tool_def(
186            "ctx_delta",
187            "Incremental diff — sends only changed lines since last read.",
188            json!({
189                "type": "object",
190                "properties": {
191                    "path": { "type": "string", "description": "Absolute file path" }
192                },
193                "required": ["path"]
194            }),
195        ),
196        tool_def(
197            "ctx_edit",
198            "Edit a file via search-and-replace. Works without native Read/Edit tools. Use this when the IDE's Edit tool requires Read but Read is unavailable.",
199            json!({
200                "type": "object",
201                "properties": {
202                    "path": { "type": "string", "description": "Absolute file path" },
203                    "old_string": { "type": "string", "description": "Exact text to find and replace (must be unique unless replace_all=true)" },
204                    "new_string": { "type": "string", "description": "Replacement text" },
205                    "replace_all": { "type": "boolean", "description": "Replace all occurrences (default: false)", "default": false },
206                    "create": { "type": "boolean", "description": "Create a new file with new_string as content (ignores old_string)", "default": false }
207                },
208                "required": ["path", "new_string"]
209            }),
210        ),
211        tool_def(
212            "ctx_dedup",
213            "Cross-file dedup: analyze or apply shared block references.",
214            json!({
215                "type": "object",
216                "properties": {
217                    "action": {
218                        "type": "string",
219                        "description": "analyze (default) or apply (register shared blocks for auto-dedup in ctx_read)",
220                        "default": "analyze"
221                    }
222                }
223            }),
224        ),
225        tool_def(
226            "ctx_fill",
227            "Budget-aware context fill — auto-selects compression per file within token limit.",
228            json!({
229                "type": "object",
230                "properties": {
231                    "paths": {
232                        "type": "array",
233                        "items": { "type": "string" },
234                        "description": "File paths to consider"
235                    },
236                    "budget": {
237                        "type": "integer",
238                        "description": "Maximum token budget to fill"
239                    }
240                },
241                "required": ["paths", "budget"]
242            }),
243        ),
244        tool_def(
245            "ctx_intent",
246            "Intent detection — auto-reads relevant files based on task description.",
247            json!({
248                "type": "object",
249                "properties": {
250                    "query": { "type": "string", "description": "Natural language description of the task" },
251                    "project_root": { "type": "string", "description": "Project root directory (default: .)" }
252                },
253                "required": ["query"]
254            }),
255        ),
256        tool_def(
257            "ctx_response",
258            "Compress LLM response text (remove filler, apply TDD).",
259            json!({
260                "type": "object",
261                "properties": {
262                    "text": { "type": "string", "description": "Response text to compress" }
263                },
264                "required": ["text"]
265            }),
266        ),
267        tool_def(
268            "ctx_context",
269            "Session context overview — cached files, seen files, session state.",
270            json!({
271                "type": "object",
272                "properties": {}
273            }),
274        ),
275        tool_def(
276            "ctx_graph",
277            "Code dependency graph. Actions: build (index project), related (find files connected to path), \
278symbol (lookup definition/usages as file::name), impact (blast radius of changes to path), status (index stats).",
279            json!({
280                "type": "object",
281                "properties": {
282                    "action": {
283                        "type": "string",
284                        "enum": ["build", "related", "symbol", "impact", "status"],
285                        "description": "Graph operation: build, related, symbol, impact, status"
286                    },
287                    "path": {
288                        "type": "string",
289                        "description": "File path (related/impact) or file::symbol_name (symbol)"
290                    },
291                    "project_root": {
292                        "type": "string",
293                        "description": "Project root directory (default: .)"
294                    }
295                },
296                "required": ["action"]
297            }),
298        ),
299        tool_def(
300            "ctx_session",
301            "Cross-session memory (CCP). Actions: load (restore previous session ~400 tok), \
302save, status, task (set current task), finding (record discovery), decision (record choice), \
303reset, list (show sessions), cleanup.",
304            json!({
305                "type": "object",
306                "properties": {
307                    "action": {
308                        "type": "string",
309                        "enum": ["status", "load", "save", "task", "finding", "decision", "reset", "list", "cleanup"],
310                        "description": "Session operation to perform"
311                    },
312                    "value": {
313                        "type": "string",
314                        "description": "Value for task/finding/decision actions"
315                    },
316                    "session_id": {
317                        "type": "string",
318                        "description": "Session ID for load action (default: latest)"
319                    }
320                },
321                "required": ["action"]
322            }),
323        ),
324        tool_def(
325            "ctx_knowledge",
326            "Persistent project knowledge (survives sessions). Actions: remember (store fact with temporal tracking + contradiction detection), \
327recall (search), pattern (record convention), consolidate (extract session findings), \
328gotcha (record a bug/mistake to never repeat — trigger+resolution required), \
329timeline (view fact history for a category), rooms (list knowledge categories), \
330search (cross-session search across ALL projects), wakeup (compact AAAK briefing), \
331status (list all), remove, export.",
332            json!({
333                "type": "object",
334                "properties": {
335                    "action": {
336                        "type": "string",
337                        "enum": ["remember", "recall", "pattern", "consolidate", "gotcha", "status", "remove", "export", "timeline", "rooms", "search", "wakeup"],
338                        "description": "Knowledge operation. remember: auto-detects contradictions + tracks temporal validity. timeline: view version history. rooms: list categories. search: cross-project search. wakeup: compact AAAK briefing."
339                    },
340                    "trigger": {
341                        "type": "string",
342                        "description": "For gotcha action: what triggers the bug (e.g. 'cargo build fails with E0507 on match arms')"
343                    },
344                    "resolution": {
345                        "type": "string",
346                        "description": "For gotcha action: how to fix/avoid it (e.g. 'Use .clone() or ref pattern')"
347                    },
348                    "severity": {
349                        "type": "string",
350                        "enum": ["critical", "warning", "info"],
351                        "description": "For gotcha action: severity level (default: warning)"
352                    },
353                    "category": {
354                        "type": "string",
355                        "description": "Fact category (architecture, api, testing, deployment, conventions, dependencies)"
356                    },
357                    "key": {
358                        "type": "string",
359                        "description": "Fact key/identifier (e.g. 'auth-method', 'db-engine', 'test-framework')"
360                    },
361                    "value": {
362                        "type": "string",
363                        "description": "Fact value or pattern description"
364                    },
365                    "query": {
366                        "type": "string",
367                        "description": "Search query for recall action (matches against category, key, and value)"
368                    },
369                    "pattern_type": {
370                        "type": "string",
371                        "description": "Pattern type for pattern action (naming, structure, testing, error-handling)"
372                    },
373                    "examples": {
374                        "type": "array",
375                        "items": { "type": "string" },
376                        "description": "Examples for pattern action"
377                    },
378                    "confidence": {
379                        "type": "number",
380                        "description": "Confidence score 0.0-1.0 for remember action (default: 0.8)"
381                    }
382                },
383                "required": ["action"]
384            }),
385        ),
386        tool_def(
387            "ctx_agent",
388            "Multi-agent coordination (shared message bus + persistent diaries). Actions: register (join with agent_type+role), \
389post (broadcast or direct message with category), read (poll messages), status (update state: active|idle|finished), \
390handoff (transfer task to another agent with summary), sync (overview of all agents + pending messages + shared contexts), \
391diary (log discovery/decision/blocker/progress/insight — persisted across sessions), \
392recall_diary (read agent diary), diaries (list all agent diaries), \
393list, info.",
394            json!({
395                "type": "object",
396                "properties": {
397                    "action": {
398                        "type": "string",
399                        "enum": ["register", "list", "post", "read", "status", "info", "handoff", "sync", "diary", "recall_diary", "diaries"],
400                        "description": "Agent operation. diary: persistent log (category=discovery|decision|blocker|progress|insight). recall_diary: read diary. diaries: list all."
401                    },
402                    "agent_type": {
403                        "type": "string",
404                        "description": "Agent type for register (cursor, claude, codex, gemini, crush, subagent)"
405                    },
406                    "role": {
407                        "type": "string",
408                        "description": "Agent role (dev, review, test, plan)"
409                    },
410                    "message": {
411                        "type": "string",
412                        "description": "Message text for post action, or status detail for status action"
413                    },
414                    "category": {
415                        "type": "string",
416                        "description": "Message category for post (finding, warning, request, status)"
417                    },
418                    "to_agent": {
419                        "type": "string",
420                        "description": "Target agent ID for direct message (omit for broadcast)"
421                    },
422                    "status": {
423                        "type": "string",
424                        "enum": ["active", "idle", "finished"],
425                        "description": "New status for status action"
426                    }
427                },
428                "required": ["action"]
429            }),
430        ),
431        tool_def(
432            "ctx_share",
433            "Share cached file contexts between agents. Actions: push (share files from your cache to another agent), \
434pull (receive files shared by other agents), list (show all shared contexts), clear (remove your shared contexts).",
435            json!({
436                "type": "object",
437                "properties": {
438                    "action": {
439                        "type": "string",
440                        "enum": ["push", "pull", "list", "clear"],
441                        "description": "Share operation to perform"
442                    },
443                    "paths": {
444                        "type": "string",
445                        "description": "Comma-separated file paths to share (for push action)"
446                    },
447                    "to_agent": {
448                        "type": "string",
449                        "description": "Target agent ID (omit for broadcast to all agents)"
450                    },
451                    "message": {
452                        "type": "string",
453                        "description": "Optional context message explaining what was shared"
454                    }
455                },
456                "required": ["action"]
457            }),
458        ),
459        tool_def(
460            "ctx_overview",
461            "Task-relevant project map — use at session start.",
462            json!({
463                "type": "object",
464                "properties": {
465                    "task": {
466                        "type": "string",
467                        "description": "Task description for relevance scoring (e.g. 'fix auth bug in login flow')"
468                    },
469                    "path": {
470                        "type": "string",
471                        "description": "Project root directory (default: .)"
472                    }
473                }
474            }),
475        ),
476        tool_def(
477            "ctx_preload",
478            "Proactive context loader — caches task-relevant files, returns L-curve-optimized summary (~50-100 tokens vs ~5000 for individual reads).",
479            json!({
480                "type": "object",
481                "properties": {
482                    "task": {
483                        "type": "string",
484                        "description": "Task description (e.g. 'fix auth bug in validate_token')"
485                    },
486                    "path": {
487                        "type": "string",
488                        "description": "Project root (default: .)"
489                    }
490                },
491                "required": ["task"]
492            }),
493        ),
494        tool_def(
495            "ctx_wrapped",
496            "Savings report card. Periods: week|month|all.",
497            json!({
498                "type": "object",
499                "properties": {
500                    "period": {
501                        "type": "string",
502                        "enum": ["week", "month", "all"],
503                        "description": "Report period (default: week)"
504                    }
505                }
506            }),
507        ),
508        tool_def(
509            "ctx_semantic_search",
510            "Semantic code search (BM25 + optional embeddings/hybrid). action=reindex to rebuild.",
511            json!({
512                "type": "object",
513                "properties": {
514                    "query": { "type": "string", "description": "Natural language search query" },
515                    "path": { "type": "string", "description": "Project root to search (default: .)" },
516                    "top_k": { "type": "integer", "description": "Number of results (default: 10)" },
517                    "action": { "type": "string", "description": "reindex to rebuild index" },
518                    "mode": {
519                        "type": "string",
520                        "enum": ["bm25", "dense", "hybrid"],
521                        "description": "Search mode (default: hybrid). bm25=lexical only, dense=embeddings only, hybrid=BM25+embeddings"
522                    },
523                    "languages": {
524                        "type": "array",
525                        "items": { "type": "string" },
526                        "description": "Optional: restrict to languages/extensions (e.g. [\"rust\",\"ts\",\"py\"] or [\"rs\",\"tsx\"])"
527                    },
528                    "path_glob": {
529                        "type": "string",
530                        "description": "Optional: glob over relative file paths (e.g. \"rust/src/**\" or \"**/*.rs\")"
531                    }
532                },
533                "required": ["query"]
534            }),
535        ),
536        tool_def(
537            "ctx_execute",
538            "Run code in sandbox (11 languages). Only stdout enters context. Raw data never leaves subprocess. Languages: javascript, typescript, python, shell, ruby, go, rust, php, perl, r, elixir.",
539            json!({
540                "type": "object",
541                "properties": {
542                    "language": {
543                        "type": "string",
544                        "description": "Language: javascript|typescript|python|shell|ruby|go|rust|php|perl|r|elixir"
545                    },
546                    "code": {
547                        "type": "string",
548                        "description": "Code to execute in sandbox"
549                    },
550                    "intent": {
551                        "type": "string",
552                        "description": "What you want from the output (triggers intent-driven filtering for large results)"
553                    },
554                    "timeout": {
555                        "type": "integer",
556                        "description": "Timeout in seconds (default: 30)"
557                    },
558                    "action": {
559                        "type": "string",
560                        "description": "batch — execute multiple scripts. Provide items as JSON array [{language, code}]"
561                    },
562                    "items": {
563                        "type": "string",
564                        "description": "JSON array of [{\"language\": \"...\", \"code\": \"...\"}] for batch execution"
565                    },
566                    "path": {
567                        "type": "string",
568                        "description": "For action=file: process a file in sandbox (auto-detects language)"
569                    }
570                },
571                "required": ["language", "code"]
572            }),
573        ),
574        tool_def(
575            "ctx_symbol",
576            "Read a specific symbol (function, struct, class) by name. Returns only the symbol \
577code block instead of the entire file. 90-97% fewer tokens than full file read.",
578            json!({
579                "type": "object",
580                "properties": {
581                    "name": { "type": "string", "description": "Symbol name (function, struct, class, method)" },
582                    "file": { "type": "string", "description": "Optional: file path to narrow search" },
583                    "kind": { "type": "string", "description": "Optional: fn|struct|class|method|trait|enum" }
584                },
585                "required": ["name"]
586            }),
587        ),
588        tool_def(
589            "ctx_graph_diagram",
590            "Generate a Mermaid diagram of the dependency or call graph. Useful for understanding architecture.",
591            json!({
592                "type": "object",
593                "properties": {
594                    "file": { "type": "string", "description": "Optional: scope to dependencies of a specific file" },
595                    "depth": { "type": "integer", "description": "Max depth (default: 2)" },
596                    "kind": { "type": "string", "description": "deps (file dependencies) or calls (symbol call graph)" }
597                }
598            }),
599        ),
600        tool_def(
601            "ctx_routes",
602            "List HTTP routes/endpoints extracted from the project. Supports Express, Flask, FastAPI, Actix, Spring, Rails, Next.js.",
603            json!({
604                "type": "object",
605                "properties": {
606                    "method": { "type": "string", "description": "Optional: GET, POST, PUT, DELETE" },
607                    "path": { "type": "string", "description": "Optional: path prefix filter, e.g. /api/users" }
608                }
609            }),
610        ),
611        tool_def(
612            "ctx_compress_memory",
613            "Compress a memory/config file (CLAUDE.md, .cursorrules, etc.) to save tokens on every session start. \
614Preserves code blocks, URLs, paths, headings, tables. Creates .original.md backup.",
615            json!({
616                "type": "object",
617                "properties": {
618                    "path": { "type": "string", "description": "Path to memory file" }
619                },
620                "required": ["path"]
621            }),
622        ),
623        tool_def(
624            "ctx_callers",
625            "Find all symbols that call a given function/method. Returns caller file, symbol, and line.",
626            json!({
627                "type": "object",
628                "properties": {
629                    "symbol": { "type": "string", "description": "Symbol name to find callers of" },
630                    "file": { "type": "string", "description": "Optional: scope to a specific file" }
631                },
632                "required": ["symbol"]
633            }),
634        ),
635        tool_def(
636            "ctx_callees",
637            "Find all functions/methods called by a given symbol. Returns callee name, file, and line.",
638            json!({
639                "type": "object",
640                "properties": {
641                    "symbol": { "type": "string", "description": "Symbol name to find callees of" },
642                    "file": { "type": "string", "description": "Optional: scope to a specific file" }
643                },
644                "required": ["symbol"]
645            }),
646        ),
647        tool_def(
648            "ctx_outline",
649            "List all symbols in a file (functions, structs, classes, methods) with signatures. \
650Much fewer tokens than reading the full file.",
651            json!({
652                "type": "object",
653                "properties": {
654                    "path": { "type": "string", "description": "File path" },
655                    "kind": { "type": "string", "description": "Optional filter: fn|struct|class|all" }
656                },
657                "required": ["path"]
658            }),
659        ),
660    ]
661}
662
663pub fn unified_tool_defs() -> Vec<Tool> {
664    vec![
665        tool_def(
666            "ctx_read",
667            "Read file (cached, compressed). Modes: full|map|signatures|diff|aggressive|entropy|task|reference|lines:N-M. fresh=true re-reads.",
668            json!({
669                "type": "object",
670                "properties": {
671                    "path": { "type": "string", "description": "File path" },
672                    "mode": { "type": "string" },
673                    "start_line": { "type": "integer" },
674                    "fresh": { "type": "boolean" }
675                },
676                "required": ["path"]
677            }),
678        ),
679        tool_def(
680            "ctx_shell",
681            "Run shell command (compressed output). raw=true skips compression. cwd sets working directory.",
682            json!({
683                "type": "object",
684                "properties": {
685                    "command": { "type": "string", "description": "Shell command" },
686                    "raw": { "type": "boolean", "description": "Skip compression for full output" },
687                    "cwd": { "type": "string", "description": "Working directory (defaults to last cd or project root)" }
688                },
689                "required": ["command"]
690            }),
691        ),
692        tool_def(
693            "ctx_search",
694            "Regex code search (.gitignore aware).",
695            json!({
696                "type": "object",
697                "properties": {
698                    "pattern": { "type": "string", "description": "Regex pattern" },
699                    "path": { "type": "string" },
700                    "ext": { "type": "string" },
701                    "max_results": { "type": "integer" },
702                    "ignore_gitignore": { "type": "boolean" }
703                },
704                "required": ["pattern"]
705            }),
706        ),
707        tool_def(
708            "ctx_tree",
709            "Directory listing with file counts.",
710            json!({
711                "type": "object",
712                "properties": {
713                    "path": { "type": "string" },
714                    "depth": { "type": "integer" },
715                    "show_hidden": { "type": "boolean" }
716                }
717            }),
718        ),
719        tool_def(
720            "ctx",
721            "Meta-tool: set tool= to sub-tool name. Sub-tools: compress (checkpoint), metrics (stats), \
722analyze (entropy), cache (status|clear|invalidate), discover (missed patterns), smart_read (auto-mode), \
723delta (incremental diff), dedup (cross-file), fill (budget-aware batch read), intent (auto-read by task), \
724response (compress LLM text), context (session state), graph (build|related|symbol|impact|status), \
725session (load|save|task|finding|decision|status|reset|list|cleanup), \
726knowledge (remember|recall|pattern|consolidate|timeline|rooms|search|wakeup|status|remove|export), \
727agent (register|post|read|status|list|info|diary|recall_diary|diaries), overview (project map), \
728wrapped (savings report), benchmark (file|project), multi_read (batch), semantic_search (BM25).",
729            json!({
730                "type": "object",
731                "properties": {
732                    "tool": {
733                        "type": "string",
734                        "description": "compress|metrics|analyze|cache|discover|smart_read|delta|dedup|fill|intent|response|context|graph|session|knowledge|agent|overview|wrapped|benchmark|multi_read|semantic_search"
735                    },
736                    "action": { "type": "string" },
737                    "path": { "type": "string" },
738                    "paths": { "type": "array", "items": { "type": "string" } },
739                    "query": { "type": "string" },
740                    "value": { "type": "string" },
741                    "category": { "type": "string" },
742                    "key": { "type": "string" },
743                    "budget": { "type": "integer" },
744                    "task": { "type": "string" },
745                    "mode": { "type": "string" },
746                    "text": { "type": "string" },
747                    "message": { "type": "string" },
748                    "session_id": { "type": "string" },
749                    "period": { "type": "string" },
750                    "format": { "type": "string" },
751                    "agent_type": { "type": "string" },
752                    "role": { "type": "string" },
753                    "status": { "type": "string" },
754                    "pattern_type": { "type": "string" },
755                    "examples": { "type": "array", "items": { "type": "string" } },
756                    "confidence": { "type": "number" },
757                    "project_root": { "type": "string" },
758                    "include_signatures": { "type": "boolean" },
759                    "limit": { "type": "integer" },
760                    "to_agent": { "type": "string" },
761                    "show_hidden": { "type": "boolean" }
762                },
763                "required": ["tool"]
764            }),
765        ),
766    ]
767}
768
769pub fn list_all_tool_defs() -> Vec<(&'static str, &'static str, Value)> {
770    vec![
771        ("ctx_read", "Read file (cached, compressed). Re-reads ~13 tok. Auto-selects optimal mode. \
772Modes: full|map|signatures|diff|aggressive|entropy|task|reference|lines:N-M. fresh=true re-reads.", json!({"type": "object", "properties": {"path": {"type": "string"}, "mode": {"type": "string"}, "start_line": {"type": "integer"}, "fresh": {"type": "boolean"}}, "required": ["path"]})),
773        ("ctx_multi_read", "Batch read files in one call. Same modes as ctx_read.", json!({"type": "object", "properties": {"paths": {"type": "array", "items": {"type": "string"}}, "mode": {"type": "string"}}, "required": ["paths"]})),
774        ("ctx_tree", "Directory listing with file counts.", json!({"type": "object", "properties": {"path": {"type": "string"}, "depth": {"type": "integer"}, "show_hidden": {"type": "boolean"}}})),
775        ("ctx_shell", "Run shell command (compressed output, 90+ patterns). cwd sets working directory.", json!({"type": "object", "properties": {"command": {"type": "string"}, "cwd": {"type": "string", "description": "Working directory"}}, "required": ["command"]})),
776        ("ctx_search", "Regex code search (.gitignore aware, compact results).", json!({"type": "object", "properties": {"pattern": {"type": "string"}, "path": {"type": "string"}, "ext": {"type": "string"}, "max_results": {"type": "integer"}}, "required": ["pattern"]})),
777        ("ctx_compress", "Context checkpoint for long conversations.", json!({"type": "object", "properties": {"include_signatures": {"type": "boolean"}}})),
778        ("ctx_benchmark", "Benchmark compression modes for a file or project.", json!({"type": "object", "properties": {"path": {"type": "string"}, "action": {"type": "string"}, "format": {"type": "string"}}, "required": ["path"]})),
779        ("ctx_metrics", "Session token stats, cache rates, per-tool savings.", json!({"type": "object", "properties": {}})),
780        ("ctx_analyze", "Entropy analysis — recommends optimal compression mode for a file.", json!({"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]})),
781        ("ctx_cache", "Cache ops: status|clear|invalidate.", json!({"type": "object", "properties": {"action": {"type": "string"}, "path": {"type": "string"}}, "required": ["action"]})),
782        ("ctx_discover", "Find missed compression opportunities in shell history.", json!({"type": "object", "properties": {"limit": {"type": "integer"}}})),
783        ("ctx_smart_read", "Auto-select optimal read mode for a file.", json!({"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]})),
784        ("ctx_delta", "Incremental diff — sends only changed lines since last read.", json!({"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]})),
785        ("ctx_edit", "Edit a file via search-and-replace. Works without native Read/Edit tools. Use when Edit requires Read but Read is unavailable.", json!({"type": "object", "properties": {"path": {"type": "string"}, "old_string": {"type": "string"}, "new_string": {"type": "string"}, "replace_all": {"type": "boolean"}, "create": {"type": "boolean"}}, "required": ["path", "new_string"]})),
786        ("ctx_dedup", "Cross-file dedup: analyze or apply shared block references.", json!({"type": "object", "properties": {"action": {"type": "string"}}})),
787        ("ctx_fill", "Budget-aware context fill — auto-selects compression per file within token limit.", json!({"type": "object", "properties": {"paths": {"type": "array", "items": {"type": "string"}}, "budget": {"type": "integer"}}, "required": ["paths", "budget"]})),
788        ("ctx_intent", "Intent detection — auto-reads relevant files based on task description.", json!({"type": "object", "properties": {"query": {"type": "string"}, "project_root": {"type": "string"}}, "required": ["query"]})),
789        ("ctx_response", "Compress LLM response text (remove filler, apply TDD).", json!({"type": "object", "properties": {"text": {"type": "string"}}, "required": ["text"]})),
790        ("ctx_context", "Session context overview — cached files, seen files, session state.", json!({"type": "object", "properties": {}})),
791        ("ctx_graph", "Code dependency graph. Actions: build (index project), related (find files connected to path), \
792symbol (lookup definition/usages as file::name), impact (blast radius of changes to path), status (index stats).", json!({"type": "object", "properties": {"action": {"type": "string"}, "path": {"type": "string"}, "project_root": {"type": "string"}}, "required": ["action"]})),
793        ("ctx_session", "Cross-session memory (CCP). Actions: load (restore previous session ~400 tok), \
794save, status, task (set current task), finding (record discovery), decision (record choice), \
795reset, list (show sessions), cleanup, snapshot (build compaction snapshot ~2KB), \
796restore (rebuild state from snapshot after context compaction).", json!({"type": "object", "properties": {"action": {"type": "string"}, "value": {"type": "string"}, "session_id": {"type": "string"}}, "required": ["action"]})),
797        ("ctx_knowledge", "Persistent project knowledge with temporal facts + contradiction detection. Actions: remember (auto-tracks validity + detects contradictions), recall, pattern, consolidate, \
798gotcha (record a bug to never repeat — trigger+resolution), timeline (fact version history), rooms (list knowledge categories), \
799search (cross-session/cross-project), wakeup (compact AAAK briefing), status, remove, export.", json!({"type": "object", "properties": {"action": {"type": "string"}, "category": {"type": "string"}, "key": {"type": "string"}, "value": {"type": "string"}, "query": {"type": "string"}, "trigger": {"type": "string"}, "resolution": {"type": "string"}, "severity": {"type": "string"}}, "required": ["action"]})),
800        ("ctx_agent", "Multi-agent coordination with persistent diaries. Actions: register, \
801post, read, status, handoff, sync, diary (log discovery/decision/blocker/progress/insight — persisted), \
802recall_diary (read diary), diaries (list all), list, info.", json!({"type": "object", "properties": {"action": {"type": "string"}, "agent_type": {"type": "string"}, "role": {"type": "string"}, "message": {"type": "string"}, "to_agent": {"type": "string"}, "status": {"type": "string"}}, "required": ["action"]})),
803        ("ctx_share", "Share cached file contexts between agents. Actions: push (share files from cache), \
804pull (receive shared files), list (show all shared contexts), clear (remove your shared contexts).", json!({"type": "object", "properties": {"action": {"type": "string"}, "paths": {"type": "string"}, "to_agent": {"type": "string"}, "message": {"type": "string"}}, "required": ["action"]})),
805        ("ctx_overview", "Task-relevant project map — use at session start.", json!({"type": "object", "properties": {"task": {"type": "string"}, "path": {"type": "string"}}})),
806        ("ctx_preload", "Proactive context loader — reads and caches task-relevant files, returns compact L-curve-optimized summary with critical lines, imports, and signatures. Costs ~50-100 tokens instead of ~5000 for individual reads.", json!({"type": "object", "properties": {"task": {"type": "string", "description": "Task description (e.g. 'fix auth bug in validate_token')"}, "path": {"type": "string", "description": "Project root (default: .)"}}, "required": ["task"]})),
807        ("ctx_wrapped", "Savings report card. Periods: week|month|all.", json!({"type": "object", "properties": {"period": {"type": "string"}}})),
808        ("ctx_semantic_search", "Semantic code search (BM25 + optional embeddings/hybrid). action=reindex to rebuild.", json!({"type": "object", "properties": {"query": {"type": "string"}, "path": {"type": "string"}, "top_k": {"type": "integer"}, "action": {"type": "string"}, "mode": {"type": "string", "enum": ["bm25","dense","hybrid"]}, "languages": {"type": "array", "items": {"type": "string"}}, "path_glob": {"type": "string"}}, "required": ["query"]})),
809        ("ctx_execute", "Run code in sandbox (11 languages). Only stdout enters context. Languages: javascript, typescript, python, shell, ruby, go, rust, php, perl, r, elixir. Actions: batch (multiple scripts), file (process file in sandbox).", json!({"type": "object", "properties": {"language": {"type": "string"}, "code": {"type": "string"}, "intent": {"type": "string"}, "timeout": {"type": "integer"}, "action": {"type": "string"}, "items": {"type": "string"}, "path": {"type": "string"}}, "required": ["language", "code"]})),
810        ("ctx_symbol", "Read a specific symbol (function, struct, class) by name. Returns only the symbol code block instead of the entire file. 90-97% fewer tokens than full file read.", json!({"type": "object", "properties": {"name": {"type": "string"}, "file": {"type": "string"}, "kind": {"type": "string"}}, "required": ["name"]})),
811        ("ctx_outline", "List all symbols in a file with signatures. Much fewer tokens than reading the full file.", json!({"type": "object", "properties": {"path": {"type": "string"}, "kind": {"type": "string"}}, "required": ["path"]})),
812        ("ctx_compress_memory", "Compress a memory/config file (CLAUDE.md, .cursorrules) preserving code, URLs, paths. Creates .original.md backup.", json!({"type": "object", "properties": {"path": {"type": "string"}}, "required": ["path"]})),
813        ("ctx_callers", "Find all symbols that call a given function/method.", json!({"type": "object", "properties": {"symbol": {"type": "string"}, "file": {"type": "string"}}, "required": ["symbol"]})),
814        ("ctx_callees", "Find all functions/methods called by a given symbol.", json!({"type": "object", "properties": {"symbol": {"type": "string"}, "file": {"type": "string"}}, "required": ["symbol"]})),
815        ("ctx_routes", "List HTTP routes/endpoints extracted from the project. Supports Express, Flask, FastAPI, Actix, Spring, Rails, Next.js.", json!({"type": "object", "properties": {"method": {"type": "string"}, "path": {"type": "string"}}})),
816        ("ctx_graph_diagram", "Generate a Mermaid diagram of the dependency or call graph.", json!({"type": "object", "properties": {"file": {"type": "string"}, "depth": {"type": "integer"}, "kind": {"type": "string"}}})),
817    ]
818}