# CodeLens MCP — declarative tool registry source-of-truth.
#
# This file is read by `scripts/regen-tool-defs.py` to produce the
# generated Rust modules under `src/tool_defs/generated/`. It is the
# single hand-edited source for tool registration data; the Rust
# generated files exist only so reviewers and rust-analyzer can grep
# the actual Tool::new lines.
#
# Add a new tool by appending a `[[tool]]` table and running:
#
#     python3 scripts/regen-tool-defs.py --write
#
# CI runs the script with `--check`; a drift fails the workflow with
# a one-line "run --write" hint. See ADR-0013 for the full rationale.
#
# ── Migration status (ADR-0013 §Decision §4) ─────────────────────────
# Each PR migrates one tool category from the hand-rolled `build.rs`
# block to this file. Categories already in TOML:
#
#   ✓ file_io          — PR-A
#   ✓ symbol           — PR-B
#   ✓ lsp              — PR-B
#   ✓ editing          — PR-C
#   ✓ analysis         — PR-C
#   ✓ composite        — PR-D
#   ✓ workflow_first   — PR-E
#   ✓ session          — PR-E
#   ✓ rule_corpus      — PR-F (this PR)
#   ✓ memory           — PR-F (this PR)
#   ✓ semantic         — PR-F (this PR; cfg-gated via feature_gate)
#
# All categories are now migrated. `build.rs` retains only the
# annotation-binding locals and per-tool postprocessing (namespace,
# title, estimated_tokens) — the Tool registry itself is fully
# declarative.

schema_version = "v1"

# ── File I/O ─────────────────────────────────────────────────────────

[[tool]]
name = "get_current_config"
category = "file_io"
description = "[CodeLens:Session] Project config and index stats. Use to verify project is active."
annotations = "ro_p"
output_schema = "get_current_config_output_schema"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "read_file"
category = "file_io"
description = "[CodeLens:File] Read file contents with optional line range."
annotations = "ro_p"
output_schema = "file_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path"]
properties = { relative_path = { type = "string" }, start_line = { type = "integer" }, end_line = { type = "integer" } }

# ─────

[[tool]]
name = "list_dir"
category = "file_io"
description = "[CodeLens:File] List directory contents, optionally recursive."
annotations = "ro_p"

[tool.input_schema]
type = "object"
required = ["relative_path"]
properties = { relative_path = { type = "string" }, recursive = { type = "boolean" } }

# ─────

[[tool]]
name = "find_file"
category = "file_io"
description = "[CodeLens:File] Find files by wildcard pattern."
annotations = "ro_p"

[tool.input_schema]
type = "object"
required = ["wildcard_pattern"]
properties = { wildcard_pattern = { type = "string" }, relative_dir = { type = "string" } }

# ─────

[[tool]]
name = "search_for_pattern"
category = "file_io"
description = "[CodeLens:File] Regex search across files. Use smart=true for enclosing symbol context."
annotations = "ro_p"
output_schema = "search_for_pattern_output_schema"

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
pattern = { type = "string" }
substring_pattern = { type = "string" }
file_glob = { type = "string" }
max_results = { type = "integer" }
smart = { type = "boolean", description = "Include enclosing symbol context for each match" }
context_lines = { type = "integer", description = "Number of context lines before and after each match (default 0)" }
context_lines_before = { type = "integer", description = "Context lines before each match (overrides context_lines)" }
context_lines_after = { type = "integer", description = "Context lines after each match (overrides context_lines)" }

# ─────

[[tool]]
name = "find_annotations"
category = "file_io"
description = "[CodeLens:File] Find TODO/FIXME/HACK comments across the project."
annotations = "ro_p"
output_schema = "find_annotations_output_schema"

[tool.input_schema]
type = "object"
properties = { tags = { type = "string" }, max_results = { type = "integer" } }

# ─────

[[tool]]
name = "find_tests"
category = "file_io"
description = "[CodeLens:File] Find test functions and test modules."
annotations = "ro_p"
output_schema = "find_tests_output_schema"

[tool.input_schema]
type = "object"
properties = { path = { type = "string" }, max_results = { type = "integer" } }

# ── Symbol Lookup ────────────────────────────────────────────────────

[[tool]]
name = "get_symbols_overview"
category = "symbol"
description = "[CodeLens:Symbol] List all symbols in a file — structural map. Use first to understand a file."
annotations = "ro_p"
output_schema = "symbol_output_schema"

[tool.input_schema]
type = "object"
required = ["path"]
properties = { path = { type = "string" }, depth = { type = "integer" } }

# ─────

[[tool]]
name = "find_symbol"
category = "symbol"
description = "[CodeLens:Symbol] Find function/class by exact name. Returns signature + body."
annotations = "ro_p"
output_schema = "symbol_output_schema"

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
name = { type = "string", description = "Symbol name to search for" }
symbol_id = { type = "string", description = "Stable symbol ID (file#kind:name_path). Overrides name." }
file_path = { type = "string" }
include_body = { type = "boolean" }
exact_match = { type = "boolean" }
max_matches = { type = "integer" }

# ─────

[[tool]]
name = "get_ranked_context"
category = "symbol"
description = "[CodeLens:Symbol] Smart context retrieval — best symbols for a query within token budget. For natural-language queries, set expand_query=false to skip n-gram expansion; for partial-identifier search use the default."
annotations = "ro_a"
output_schema = "ranked_context_output_schema"
max_response_tokens = 32768

[tool.input_schema]
type = "object"
required = ["query"]
[tool.input_schema.properties]
query = { type = "string" }
path = { type = "string" }
max_tokens = { type = "integer", description = "Token budget for the retrieval payload. Defaults to max(active surface budget, 16384) — raised in v1.10.1 from the surface budget alone to avoid Stage 5 truncation on hybrid retrieval." }
include_body = { type = "boolean" }
depth = { type = "integer" }
disable_semantic = { type = "boolean", description = "Disable semantic/hybrid ranking and use structural signals only" }
expand_query = { type = "boolean", description = "When true (default), expand the query with snake_case / camelCase / cartesian-token derivatives. Set to false for natural-language queries that don't benefit from expansion." }

# ─────

[[tool]]
name = "bm25_symbol_search"
category = "symbol"
description = "[CodeLens:Symbol] Sparse BM25-F symbol retrieval — best for identifiers, signatures, path tokens, and short lexical phrases."
annotations = "ro_a"
output_schema = "bm25_symbol_search_output_schema"

[tool.input_schema]
type = "object"
required = ["query"]
[tool.input_schema.properties]
query = { type = "string" }
max_results = { type = "integer", description = "Maximum number of results to return (default 10)" }
include_tests = { type = "boolean", description = "Include test symbols in the candidate pool" }
include_generated = { type = "boolean", description = "Include generated symbols in the candidate pool" }

# ─────

[[tool]]
name = "search_symbols_fuzzy"
category = "symbol"
description = "[CodeLens:Symbol] Fuzzy symbol search — tolerates typos and partial names."
annotations = "ro_a"

[tool.input_schema]
type = "object"
required = ["query"]
[tool.input_schema.properties]
query = { type = "string", description = "Symbol name to search for" }
max_results = { type = "integer", description = "Maximum number of results to return (default 30)" }
fuzzy_threshold = { type = "number", description = "Minimum jaro_winkler similarity 0.0-1.0 for fuzzy matches (default 0.6)" }
disable_semantic = { type = "boolean", description = "Disable semantic score blending and use lexical search only" }

# ─────

[[tool]]
name = "get_complexity"
category = "symbol"
description = "[CodeLens:Analysis] Cyclomatic complexity for functions. Use to find code needing refactoring."
annotations = "ro_a"

[tool.input_schema]
type = "object"
required = ["path"]
properties = { path = { type = "string" }, symbol_name = { type = "string" } }

# ─────

[[tool]]
name = "refresh_symbol_index"
category = "symbol"
description = "[CodeLens:Symbol] Rebuild the symbol database. Use if index is stale."
annotations = "mut_w"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "get_project_structure"
category = "symbol"
description = "[CodeLens:Symbol] Directory-level overview — file counts and symbol density per directory."
annotations = "ro_p"
output_schema = "get_project_structure_output_schema"

[tool.input_schema]
type = "object"
properties = {}

# ── LSP (type-aware operations) ──────────────────────────────────────

[[tool]]
name = "find_referencing_symbols"
category = "lsp"
description = "[CodeLens:Symbol] Find all usages of a symbol. use_lsp=true for type-aware precision."
annotations = "ro_p"
output_schema = "references_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path"]
[tool.input_schema.properties]
file_path = { type = "string", description = "File containing or declaring the symbol" }
symbol_name = { type = "string", description = "Symbol name (default: tree-sitter search)" }
line = { type = "integer", description = "Line number (triggers LSP path)" }
column = { type = "integer", description = "Column number (triggers LSP path)" }
use_lsp = { type = "boolean", description = "Force LSP lookup (slower but type-aware, requires LSP server)" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }
max_results = { type = "integer" }

# ─────

[[tool]]
name = "get_file_diagnostics"
category = "lsp"
description = "[CodeLens:Symbol] Type errors and lint issues via LSP. Use after editing code."
annotations = "ro_p"
output_schema = "diagnostics_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path"]
[tool.input_schema.properties]
file_path = { type = "string" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }
max_results = { type = "integer" }

# ─────

[[tool]]
name = "search_workspace_symbols"
category = "lsp"
description = "[CodeLens:Symbol] LSP workspace symbol search. Use when you need type-system-aware results. Requires an LSP server binary via `command` (e.g. rust-analyzer / pyright); the handler returns a structured hint toward `bm25_symbol_search` when omitted."
annotations = "ro_p"

[tool.input_schema]
type = "object"
required = ["query"]
[tool.input_schema.properties]
query = { type = "string" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }
max_results = { type = "integer" }

# ─────

[[tool]]
name = "get_type_hierarchy"
category = "lsp"
description = "[CodeLens:Symbol] Inheritance hierarchy — supertypes and subtypes of a class/interface."
annotations = "ro_a"
output_schema = "get_type_hierarchy_output_schema"

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
name_path = { type = "string" }
fully_qualified_name = { type = "string" }
relative_path = { type = "string" }
hierarchy_type = { type = "string", enum = ["super", "sub", "both"] }
depth = { type = "integer" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }

# ─────

[[tool]]
name = "resolve_symbol_target"
category = "lsp"
description = "[CodeLens:Symbol] Resolve declaration/definition/implementation/type target through LSP. Use when edit-grade navigation authority is required."
annotations = "ro_a"
output_schema = "resolve_symbol_target_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "line", "column"]
[tool.input_schema.properties]
file_path = { type = "string" }
line = { type = "integer", description = "1-based source line" }
column = { type = "integer", description = "1-based byte column; converted to LSP UTF-16 internally" }
target = { type = "string", enum = ["declaration", "definition", "implementation", "type_definition"], description = "Target kind (default: definition)" }
semantic_backend = { type = "string", enum = ["lsp"], description = "Only lsp is authoritative for this tool" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }
max_results = { type = "integer" }

# ─────

[[tool]]
name = "plan_symbol_rename"
category = "lsp"
description = "[CodeLens:Symbol] Preview rename refactoring via LSP — check before applying."
annotations = "ro_a"

[tool.input_schema]
type = "object"
required = ["file_path", "line", "column"]
[tool.input_schema.properties]
file_path = { type = "string" }
line = { type = "integer" }
column = { type = "integer" }
new_name = { type = "string" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }

# ─────

[[tool]]
name = "check_lsp_status"
category = "lsp"
description = "[CodeLens:Session] Check installed LSP servers with install commands."
annotations = "ro_p"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "get_lsp_recipe"
category = "lsp"
description = "[CodeLens:Session] Get LSP server install instructions for a file extension."
annotations = "ro_p"

[tool.input_schema]
type = "object"
required = ["extension"]
properties = { extension = { type = "string", description = "File extension (e.g. 'py', 'rs')" } }

# ── Analysis (architecture & dependencies) ───────────────────────────

[[tool]]
name = "get_changed_files"
category = "analysis"
description = "[CodeLens:Analysis] Files changed since a git ref with symbol counts. Use for diff review."
annotations = "ro_p"
output_schema = "changed_files_output_schema"

[tool.input_schema]
type = "object"
properties = { ref = { type = "string" }, include_untracked = { type = "boolean" } }

# ─────

[[tool]]
name = "get_callers"
category = "analysis"
description = "[CodeLens:Analysis] Find functions that call a function. Returns bounded call-graph edges with backend/confidence metadata."
annotations = "ro_a"
output_schema = "get_callers_output_schema"

[tool.input_schema]
type = "object"
required = ["function_name"]
[tool.input_schema.properties]
function_name = { type = "string" }
file_path = { type = "string", description = "Optional file scope for caller search" }
max_results = { type = "integer" }

# ─────

[[tool]]
name = "get_callees"
category = "analysis"
description = "[CodeLens:Analysis] Find functions called by a function. Use file_path when duplicate function names exist."
annotations = "ro_a"
output_schema = "get_callees_output_schema"

[tool.input_schema]
type = "object"
required = ["function_name"]
properties = { function_name = { type = "string" }, file_path = { type = "string" }, max_results = { type = "integer" } }

# ─────

[[tool]]
name = "find_scoped_references"
category = "analysis"
description = "[CodeLens:Analysis] Classify each reference as definition/read/write/import."
annotations = "ro_a"
output_schema = "references_output_schema"

[tool.input_schema]
type = "object"
required = ["symbol_name"]
[tool.input_schema.properties]
symbol_name = { type = "string", description = "Symbol name to find references for" }
file_path = { type = "string", description = "Declaration file (for sorting, optional)" }
max_results = { type = "integer", description = "Max results (default 50)" }

# ─────

[[tool]]
name = "get_symbol_importance"
category = "analysis"
description = "[CodeLens:Analysis] PageRank file importance — find the most critical files in the project."
annotations = "ro_a"

[tool.input_schema]
type = "object"
properties = { top_n = { type = "integer" } }

# ─────

[[tool]]
name = "find_circular_dependencies"
category = "analysis"
description = "[CodeLens:Analysis] Detect circular imports using Tarjan SCC algorithm."
annotations = "ro_a"

[tool.input_schema]
type = "object"
properties = { max_results = { type = "integer" } }

# ─────

[[tool]]
name = "get_change_coupling"
category = "analysis"
description = "[CodeLens:Analysis] Files that frequently change together in git history."
annotations = "ro_a"

[tool.input_schema]
type = "object"
properties = { months = { type = "integer" }, min_strength = { type = "number" }, min_commits = { type = "integer" }, max_results = { type = "integer" } }

# ── Editing (code mutations) ─────────────────────────────────────────

[[tool]]
name = "rename_symbol"
category = "editing"
description = "[CodeLens:Edit] Rename across project — safe multi-file refactoring. Use dry_run=true to preview."
annotations = "dest_a"
output_schema = "rename_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "new_name"]
[tool.input_schema.properties]
file_path = { type = "string", description = "File containing the symbol declaration" }
symbol_name = { type = "string", description = "Current symbol name" }
name = { type = "string", description = "Alias for symbol_name" }
new_name = { type = "string", description = "Desired new name" }
name_path = { type = "string", description = "Qualified name path (e.g. 'Class/method')" }
scope = { type = "string", enum = ["file", "project"], description = "Rename scope (default: project; tree-sitter backend only)" }
semantic_edit_backend = { type = "string", enum = ["tree-sitter", "lsp", "jetbrains", "roslyn"], description = "Opt-in precise edit backend. lsp uses inspectable WorkspaceEdit APIs; jetbrains/roslyn are fail-closed adapter boundaries until a local adapter is configured." }
line = { type = "integer", description = "1-based declaration line for semantic_edit_backend=lsp; derived from symbol index when omitted" }
column = { type = "integer", description = "1-based declaration column for semantic_edit_backend=lsp; derived from symbol index when omitted" }
command = { type = "string", description = "Optional LSP server command for semantic_edit_backend=lsp" }
args = { type = "array", items = { type = "string" }, description = "Optional LSP server args for semantic_edit_backend=lsp" }
dry_run = { type = "boolean", description = "Preview changes without modifying files" }

# ─────

[[tool]]
name = "replace_symbol_body"
category = "editing"
description = "[CodeLens:Edit] Replace function/class body by name — tree-sitter finds boundaries. No line numbers needed."
annotations = "mut_w"
output_schema = "file_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "symbol_name", "new_body"]
properties = { relative_path = { type = "string" }, symbol_name = { type = "string" }, name_path = { type = "string" }, new_body = { type = "string" } }

# ─────

[[tool]]
name = "replace_content"
category = "editing"
description = "[CodeLens:Edit] Find-and-replace text in a file — literal or regex mode."
annotations = "mut_p"
output_schema = "replace_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "old_text", "new_text"]
properties = { relative_path = { type = "string" }, old_text = { type = "string" }, new_text = { type = "string" }, regex_mode = { type = "boolean" } }

# ─────

[[tool]]
name = "replace_lines"
category = "editing"
description = "[CodeLens:Edit] Replace a line range (1-indexed). Use when you know exact line numbers."
annotations = "mut_p"
output_schema = "file_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "start_line", "end_line", "new_content"]
properties = { relative_path = { type = "string" }, start_line = { type = "integer" }, end_line = { type = "integer" }, new_content = { type = "string" } }

# ─────

[[tool]]
name = "delete_lines"
category = "editing"
description = "[CodeLens:Edit] Delete a line range (1-indexed, end exclusive)."
annotations = "destructive"
output_schema = "file_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "start_line", "end_line"]
properties = { relative_path = { type = "string" }, start_line = { type = "integer" }, end_line = { type = "integer" } }

# ─────

[[tool]]
name = "insert_at_line"
category = "editing"
description = "[CodeLens:Edit] Insert content at a line number. Use when you know the exact position."
annotations = "mut_p"
output_schema = "file_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "line", "content"]
properties = { relative_path = { type = "string" }, line = { type = "integer" }, content = { type = "string" } }

# ─────

[[tool]]
name = "insert_before_symbol"
category = "editing"
description = "[CodeLens:Edit] Insert code before a named symbol — tree-sitter finds position."
annotations = "mut_p"
output_schema = "file_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "symbol_name", "content"]
properties = { relative_path = { type = "string" }, symbol_name = { type = "string" }, name_path = { type = "string" }, content = { type = "string" } }

# ─────

[[tool]]
name = "insert_after_symbol"
category = "editing"
description = "[CodeLens:Edit] Insert code after a named symbol — tree-sitter finds position."
annotations = "mut_p"
output_schema = "file_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "symbol_name", "content"]
properties = { relative_path = { type = "string" }, symbol_name = { type = "string" }, name_path = { type = "string" }, content = { type = "string" } }

# ─────

[[tool]]
name = "insert_content"
category = "editing"
description = "[CodeLens:Edit] Insert code at position='line'|'before_symbol'|'after_symbol'."
annotations = "mut_p"
output_schema = "file_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "content"]
[tool.input_schema.properties]
relative_path = { type = "string" }
content = { type = "string" }
position = { type = "string", enum = ["line", "before_symbol", "after_symbol"], description = "Insertion position type (default: line)" }
line = { type = "integer", description = "Line number (for position=line)" }
symbol_name = { type = "string", description = "Symbol name (for position=before_symbol or after_symbol)" }
name_path = { type = "string", description = "Qualified name path" }

# ─────

[[tool]]
name = "replace"
category = "editing"
description = "[CodeLens:Edit] Replace text or line range. Set mode='text' (find-replace) or mode='lines' (line range)."
annotations = "mut_p"
output_schema = "replace_content_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path"]
[tool.input_schema.properties]
relative_path = { type = "string" }
mode = { type = "string", enum = ["text", "lines"], description = "Replace mode (default: text)" }
old_text = { type = "string", description = "Text to find (mode=text)" }
new_text = { type = "string", description = "Replacement text (mode=text)" }
regex_mode = { type = "boolean", description = "Use regex (mode=text)" }
start_line = { type = "integer", description = "Start line (mode=lines)" }
end_line = { type = "integer", description = "End line (mode=lines)" }
new_content = { type = "string", description = "New content (mode=lines)" }

# ─────

[[tool]]
name = "create_text_file"
category = "editing"
description = "[CodeLens:Edit] Create a new file. Fails if exists unless overwrite=true."
annotations = "mut_p"
output_schema = "create_text_file_output_schema"

[tool.input_schema]
type = "object"
required = ["relative_path", "content"]
properties = { relative_path = { type = "string" }, content = { type = "string" }, overwrite = { type = "boolean" } }

# ─────

[[tool]]
name = "analyze_missing_imports"
category = "editing"
description = "[CodeLens:Edit] Detect unresolved symbols and suggest imports."
annotations = "mutating"

[tool.input_schema]
type = "object"
required = ["file_path"]
properties = { file_path = { type = "string", description = "File to analyze" } }

# ─────

[[tool]]
name = "add_import"
category = "editing"
description = "[CodeLens:Edit] Insert an import statement at the correct position."
annotations = "mut_p"
output_schema = "add_import_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "import_statement"]
properties = { file_path = { type = "string" }, import_statement = { type = "string", description = "Import statement to add" } }

# ─────

[[tool]]
name = "refactor_extract_function"
category = "editing"
description = "[CodeLens:Edit] Extract line range into new function with automatic call-site replacement."
annotations = "mut_w"
output_schema = "semantic_refactor_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "start_line", "end_line", "new_name"]
[tool.input_schema.properties]
file_path = { type = "string" }
start_line = { type = "integer" }
start_column = { type = "integer" }
end_line = { type = "integer" }
end_column = { type = "integer" }
new_name = { type = "string", description = "Name for the new function" }
semantic_edit_backend = { type = "string", enum = ["tree-sitter", "lsp", "jetbrains", "roslyn"], description = "lsp applies only concrete WorkspaceEdit codeAction results; jetbrains/roslyn fail closed until a local adapter exists." }
code_action_kind = { type = "string", description = "Optional LSP code action kind override" }
code_action_kinds = { type = "array", items = { type = "string" }, description = "Optional LSP code action kind list override" }
action_id = { type = "string", description = "Title, kind, or index to select when multiple code actions match" }
command = { type = "string", description = "Optional LSP server command" }
args = { type = "array", items = { type = "string" }, description = "Optional LSP server args" }
dry_run = { type = "boolean", description = "Preview without modifying (default true)" }

# ─────

[[tool]]
name = "refactor_inline_function"
category = "editing"
description = "[CodeLens:Edit] Inline a function: replace all call sites with body, remove definition."
annotations = "mut_w"
output_schema = "semantic_refactor_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "function_name"]
[tool.input_schema.properties]
file_path = { type = "string", description = "File containing the function definition" }
function_name = { type = "string", description = "Function to inline" }
name_path = { type = "string", description = "Qualified name path (e.g. Class/method)" }
line = { type = "integer", description = "1-based symbol line for semantic_edit_backend=lsp" }
column = { type = "integer", description = "1-based symbol byte column for semantic_edit_backend=lsp" }
semantic_edit_backend = { type = "string", enum = ["tree-sitter", "lsp", "jetbrains", "roslyn"], description = "lsp applies only concrete WorkspaceEdit codeAction results; jetbrains/roslyn fail closed until a local adapter exists." }
code_action_kind = { type = "string" }
code_action_kinds = { type = "array", items = { type = "string" } }
action_id = { type = "string" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }
dry_run = { type = "boolean", description = "Preview without modifying (default true)" }

# ─────

[[tool]]
name = "refactor_move_to_file"
category = "editing"
description = "[CodeLens:Edit] Move a symbol to another file, updating imports across the project."
annotations = "dest_a"
output_schema = "semantic_refactor_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "symbol_name", "target_file"]
[tool.input_schema.properties]
file_path = { type = "string", description = "Source file" }
symbol_name = { type = "string", description = "Symbol to move" }
target_file = { type = "string", description = "Destination file" }
name_path = { type = "string", description = "Qualified name path" }
line = { type = "integer", description = "1-based symbol line for semantic_edit_backend=lsp" }
column = { type = "integer", description = "1-based symbol byte column for semantic_edit_backend=lsp" }
semantic_edit_backend = { type = "string", enum = ["tree-sitter", "lsp", "jetbrains", "roslyn"], description = "lsp applies only concrete WorkspaceEdit codeAction results; jetbrains/roslyn fail closed until a local adapter exists." }
code_action_kind = { type = "string" }
code_action_kinds = { type = "array", items = { type = "string" } }
action_id = { type = "string" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }
dry_run = { type = "boolean", description = "Preview without modifying (default true)" }

# ─────

[[tool]]
name = "refactor_change_signature"
category = "editing"
description = "[CodeLens:Edit] Change function parameters and update all call sites."
annotations = "dest_a"
output_schema = "semantic_refactor_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "function_name", "new_parameters"]
[tool.input_schema.properties]
file_path = { type = "string", description = "File containing the function" }
function_name = { type = "string", description = "Function to modify" }
name_path = { type = "string", description = "Qualified name path" }
new_parameters = { type = "array", items = { type = "object", properties = { name = { type = "string" }, type = { type = "string" }, default = { type = "string" } } }, description = "New parameter list" }
line = { type = "integer", description = "1-based symbol line for semantic_edit_backend=lsp" }
column = { type = "integer", description = "1-based symbol byte column for semantic_edit_backend=lsp" }
semantic_edit_backend = { type = "string", enum = ["tree-sitter", "lsp", "jetbrains", "roslyn"], description = "lsp applies only concrete WorkspaceEdit codeAction results; jetbrains/roslyn fail closed until a local adapter exists." }
code_action_kind = { type = "string" }
code_action_kinds = { type = "array", items = { type = "string" } }
action_id = { type = "string" }
command = { type = "string" }
args = { type = "array", items = { type = "string" } }
dry_run = { type = "boolean", description = "Preview without modifying (default true)" }

# ─────

[[tool]]
name = "propagate_deletions"
category = "editing"
description = "[CodeLens:Edit] Analyze what breaks if a symbol is deleted and list affected references/imports for cleanup."
annotations = "mut_w"
output_schema = "safe_delete_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "symbol_name"]
[tool.input_schema.properties]
file_path = { type = "string", description = "File containing the symbol" }
symbol_name = { type = "string", description = "Symbol to analyze for deletion" }
semantic_edit_backend = { type = "string", enum = ["tree-sitter", "lsp", "jetbrains", "roslyn"], description = "Opt-in precise safe-delete check. lsp uses textDocument/references; jetbrains/roslyn fail closed until a local adapter exists." }
line = { type = "integer", description = "1-based declaration line for semantic_edit_backend=lsp; derived from symbol index when omitted" }
column = { type = "integer", description = "1-based declaration column for semantic_edit_backend=lsp; derived from symbol index when omitted" }
command = { type = "string", description = "Optional LSP server command for semantic_edit_backend=lsp" }
args = { type = "array", items = { type = "string" }, description = "Optional LSP server args for semantic_edit_backend=lsp" }
max_results = { type = "integer", description = "Maximum LSP references to inspect (default 200)" }
dry_run = { type = "boolean", description = "Preview without modifying (default true)" }

# ── Composite (multi-step workflows, excl. workflow-first aliases) ───
# The 7 workflow_alias_output_schema entrypoints (explore_codebase,
# trace_request_path, review_architecture, plan_safe_refactor,
# cleanup_duplicate_logic, review_changes, diagnose_issues) stay in
# the legacy `build.rs` block until PR-E.

[[tool]]
name = "explain_code_flow"
category = "composite"
description = "[CodeLens:Analysis] Summarize how a function fits in the call graph: callers, callees, and a one-line flow summary. Lighter than trace_request_path."
annotations = "ro_a"

[tool.input_schema]
type = "object"
required = ["function_name"]
properties = { function_name = { type = "string" }, max_depth = { type = "integer" }, max_results = { type = "integer" } }

# ─────

[[tool]]
name = "onboard_project"
category = "composite"
description = "[CodeLens:Session] One-shot onboarding: structure, key files, cycles, stats."
annotations = "ro_w"
output_schema = "onboard_output_schema"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "analyze_change_request"
category = "composite"
description = "[CodeLens:Workflow] Compress a change request into ranked files, key symbols, risk, and next actions."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"
max_response_tokens = 2048

[tool.input_schema]
type = "object"
required = ["task"]
[tool.input_schema.properties]
task = { type = "string" }
changed_files = { type = "array", items = { type = "string" } }
profile_hint = { type = "string", enum = ["planner-readonly", "builder-minimal", "reviewer-graph", "refactor-full", "ci-audit"] }

# ─────

[[tool]]
name = "verify_change_readiness"
category = "composite"
description = "[CodeLens:Workflow] Verifier-first preflight: blockers, readiness, and next evidence before editing."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"
max_response_tokens = 2048

[tool.input_schema]
type = "object"
required = ["task"]
[tool.input_schema.properties]
task = { type = "string" }
changed_files = { type = "array", items = { type = "string" } }
profile_hint = { type = "string", enum = ["planner-readonly", "builder-minimal", "reviewer-graph", "refactor-full", "ci-audit"] }

# ─────

[[tool]]
name = "find_minimal_context_for_change"
category = "composite"
description = "[CodeLens:Workflow] Return the smallest useful file and symbol context needed to start a change."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"
max_response_tokens = 2048

[tool.input_schema]
type = "object"
required = ["task"]
properties = { task = { type = "string" } }

# ─────

[[tool]]
name = "summarize_symbol_impact"
category = "composite"
description = "[CodeLens:Workflow] Summarize callers, references, and affected files for one symbol."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"

[tool.input_schema]
type = "object"
required = ["symbol"]
properties = { symbol = { type = "string" }, file_path = { type = "string" }, depth = { type = "integer" } }

# ─────

[[tool]]
name = "module_boundary_report"
category = "composite"
description = "[CodeLens:Workflow] Summarize dependency boundaries, coupling, and cycle risk for a module or path."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"

[tool.input_schema]
type = "object"
required = ["path"]
properties = { path = { type = "string" } }

# ─────

[[tool]]
name = "mermaid_module_graph"
category = "composite"
description = "[CodeLens:Workflow] Render upstream/downstream module dependencies as a Mermaid flowchart ready to embed in GitHub/GitLab Markdown."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"

[tool.input_schema]
type = "object"
required = ["path"]
properties = { path = { type = "string" }, max_nodes = { type = "integer", description = "Max nodes rendered per side (default 10)" } }

# ─────

[[tool]]
name = "safe_rename_report"
category = "composite"
description = "[CodeLens:Workflow] Assess rename safety, blockers, and preview edits before refactoring."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path", "symbol"]
properties = { file_path = { type = "string" }, symbol = { type = "string" }, new_name = { type = "string" } }

# ─────

[[tool]]
name = "unresolved_reference_check"
category = "composite"
description = "[CodeLens:Workflow] Lightweight unresolved or ambiguous reference guard before rename or broad edits."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"

[tool.input_schema]
type = "object"
required = ["file_path"]
properties = { file_path = { type = "string" }, symbol = { type = "string" }, changed_files = { type = "array", items = { type = "string" } } }

# ─────

[[tool]]
name = "dead_code_report"
category = "composite"
description = "[CodeLens:Workflow] Summarize dead-code candidates with bounded evidence and deletion risk."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"

[tool.input_schema]
type = "object"
properties = { scope = { type = "string" }, max_results = { type = "integer" } }

# ─────

[[tool]]
name = "impact_report"
category = "composite"
description = "[CodeLens:Workflow] Summarize changed-file impact, references, and blast radius with a bounded report."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"
max_response_tokens = 2048

[tool.input_schema]
type = "object"
properties = { path = { type = "string" }, changed_files = { type = "array", items = { type = "string" } } }

# ─────

[[tool]]
name = "refactor_safety_report"
category = "composite"
description = "[CodeLens:Workflow] Combine boundary, symbol impact, and test cues into a preview-first refactor report."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"
max_response_tokens = 2048

[tool.input_schema]
type = "object"
properties = { task = { type = "string" }, symbol = { type = "string" }, path = { type = "string" }, file_path = { type = "string" } }

# ─────

[[tool]]
name = "diff_aware_references"
category = "composite"
description = "[CodeLens:Workflow] Compress references for changed files into a bounded reviewer/CI report."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"
max_response_tokens = 2048

[tool.input_schema]
type = "object"
properties = { changed_files = { type = "array", items = { type = "string" } } }

# ─────

[[tool]]
name = "semantic_code_review"
category = "composite"
description = "[CodeLens:Workflow] Semantic code review — analyze changed symbols via references, embedding similarity, and risk assessment."
annotations = "ro_w"
output_schema = "analysis_handle_output_schema"
max_response_tokens = 2048

[tool.input_schema]
type = "object"
properties = { changed_files = { type = "array", items = { type = "string" } } }

# ─────

[[tool]]
name = "start_analysis_job"
category = "composite"
description = "[CodeLens:Workflow] Start a durable analysis job and return a job handle for polling."
annotations = "ro_w"
output_schema = "analysis_job_output_schema"

[tool.input_schema]
type = "object"
required = ["kind"]
[tool.input_schema.properties]
kind = { type = "string", enum = ["impact_report", "dead_code_report", "refactor_safety_report", "semantic_code_review", "eval_session_audit"] }
task = { type = "string" }
symbol = { type = "string" }
path = { type = "string" }
file_path = { type = "string" }
changed_files = { type = "array", items = { type = "string" } }
profile_hint = { type = "string", enum = ["planner-readonly", "builder-minimal", "reviewer-graph", "refactor-full", "ci-audit"] }

# ─────

[[tool]]
name = "get_analysis_job"
category = "composite"
description = "[CodeLens:Workflow] Poll a durable analysis job by job_id."
annotations = "ro_p"
output_schema = "analysis_job_output_schema"

[tool.input_schema]
type = "object"
required = ["job_id"]
properties = { job_id = { type = "string" } }

# ─────

[[tool]]
name = "cancel_analysis_job"
category = "composite"
description = "[CodeLens:Workflow] Cancel a queued or running analysis job by job_id."
annotations = "mut_w"
output_schema = "analysis_job_output_schema"

[tool.input_schema]
type = "object"
required = ["job_id"]
properties = { job_id = { type = "string" } }

# ─────

[[tool]]
name = "retry_analysis_job"
category = "composite"
description = "[CodeLens:Workflow] Retry a failed or cancelled analysis job by job_id; reuses the original kind and profile_hint."
annotations = "mut_w"
output_schema = "analysis_job_output_schema"

[tool.input_schema]
type = "object"
required = ["job_id"]
properties = { job_id = { type = "string" } }

# ─────

[[tool]]
name = "list_analysis_jobs"
category = "composite"
description = "[CodeLens:Workflow] List durable analysis jobs with status counts and any attached analysis handles."
annotations = "ro_p"
output_schema = "analysis_job_list_output_schema"

[tool.input_schema]
type = "object"
properties = { status = { type = "string", enum = ["queued", "running", "completed", "cancelled", "error"] } }

# ─────

[[tool]]
name = "list_analysis_artifacts"
category = "composite"
description = "[CodeLens:Workflow] List stored analysis artifacts with summary resource handles for reuse."
annotations = "ro_p"
output_schema = "analysis_artifact_list_output_schema"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "get_analysis_section"
category = "composite"
description = "[CodeLens:Workflow] Expand a stored analysis section by analysis_id."
annotations = "ro_p"
output_schema = "analysis_section_output_schema"

[tool.input_schema]
type = "object"
required = ["analysis_id", "section"]
properties = { analysis_id = { type = "string" }, section = { type = "string" } }

# ── Workflow-first aliases (problem-first entrypoints) ───────────────

[[tool]]
name = "explore_codebase"
category = "workflow_first"
description = "[CodeLens:Workflow] Problem-first entrypoint for codebase exploration. Use query for targeted context, or call without arguments for onboarding."
annotations = "ro_w"
output_schema = "workflow_alias_output_schema"
max_response_tokens = 16384

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
query = { type = "string" }
path = { type = "string" }
max_tokens = { type = "integer" }
include_body = { type = "boolean" }
depth = { type = "integer" }
disable_semantic = { type = "boolean" }

# ─────

[[tool]]
name = "trace_request_path"
category = "workflow_first"
description = "[CodeLens:Workflow] Trace a request or execution path from a function, symbol, or entrypoint."
annotations = "ro_w"
output_schema = "workflow_alias_output_schema"
max_response_tokens = 3072

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
function_name = { type = "string" }
symbol = { type = "string" }
entrypoint = { type = "string" }
max_depth = { type = "integer" }
max_results = { type = "integer" }

# ─────

[[tool]]
name = "review_architecture"
category = "workflow_first"
description = "[CodeLens:Workflow] Review project or module architecture, boundaries, coupling, and optionally render a diagram."
annotations = "ro_w"
output_schema = "workflow_alias_output_schema"
max_response_tokens = 3072

[tool.input_schema]
type = "object"
properties = { path = { type = "string" }, include_diagram = { type = "boolean" }, max_nodes = { type = "integer" } }

# ─────

[[tool]]
name = "plan_safe_refactor"
category = "workflow_first"
description = "[CodeLens:Workflow] Preview a safe refactor plan. Uses rename safety when file_path+symbol are given; otherwise falls back to broader refactor safety analysis."
annotations = "ro_w"
output_schema = "workflow_alias_output_schema"
max_response_tokens = 3072

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
task = { type = "string" }
symbol = { type = "string" }
path = { type = "string" }
file_path = { type = "string" }
new_name = { type = "string" }

# ─────

[[tool]]
name = "cleanup_duplicate_logic"
category = "workflow_first"
description = "[CodeLens:Workflow] Surface duplicate or removable logic before cleanup. Uses semantic duplicate search when available, otherwise bounded dead-code evidence."
annotations = "ro_w"
output_schema = "workflow_alias_output_schema"
max_response_tokens = 3072

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
threshold = { type = "number" }
max_pairs = { type = "integer" }
scope = { type = "string" }
max_results = { type = "integer" }

# ─────

[[tool]]
name = "review_changes"
category = "workflow_first"
description = "[CodeLens:Workflow] Pre-merge review: diff-aware references or impact analysis for changed files."
annotations = "ro_w"
output_schema = "workflow_alias_output_schema"
max_response_tokens = 3072

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
changed_files = { type = "array", items = { type = "string" }, description = "File paths that changed" }
task = { type = "string", description = "Review focus description" }
path = { type = "string", description = "Scope path" }

# ─────

[[tool]]
name = "diagnose_issues"
category = "workflow_first"
description = "[CodeLens:Workflow] Diagnostics: file-level issues or unresolved reference check."
annotations = "ro_w"
output_schema = "workflow_alias_output_schema"
max_response_tokens = 3072

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
file_path = { type = "string", description = "File to diagnose" }
path = { type = "string", description = "Directory scope" }
symbol = { type = "string", description = "Symbol to check references for" }

# ── Session ──────────────────────────────────────────────────────────

[[tool]]
name = "activate_project"
category = "session"
description = "[CodeLens:Session] Activate project — auto-detect preset, index, frameworks."
annotations = "ro_p"
output_schema = "activate_project_output_schema"

[tool.input_schema]
type = "object"
properties = { project = { type = "string", description = "Optional project name or path" } }

# ─────

[[tool]]
name = "prepare_harness_session"
category = "session"
description = "[CodeLens:Session] Official bootstrap/status entrypoint for harnesses — activate project, summarize surface, capabilities, visible tools, and optionally auto-recover a small stale index in one call."
annotations = "mutating"
output_schema = "prepare_harness_session_output_schema"

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
project = { type = "string", description = "Optional project name or path" }
profile = { type = "string", enum = ["planner-readonly", "builder-minimal", "reviewer-graph", "refactor-full", "ci-audit"] }
preset = { type = "string", enum = ["minimal", "balanced", "full"] }
token_budget = { type = "integer", description = "Optional explicit token budget override after activation" }
file_path = { type = "string", description = "Optional file path for language-specific capability checks" }
detail = { type = "string", enum = ["compact", "full"], description = "compact returns the harness preflight essentials only; full also includes the heavier config snapshot" }
host_context = { type = "string", enum = ["claude-code", "codex", "cursor", "cline", "windsurf", "vscode", "jetbrains", "api-agent"], description = "Optional host/runtime hint used to compile advisory bootstrap routing without changing the active tool surface" }
task_overlay = { type = "string", enum = ["planning", "editing", "review", "onboarding", "batch-analysis", "interactive"], description = "Optional task-mode hint used to compile advisory bootstrap routing without changing the active tool surface" }
preferred_entrypoints = { type = "array", items = { type = "string" }, description = "Optional ordered entrypoints so the server can report which are immediately visible" }
auto_refresh_stale = { type = "boolean", description = "When true (default), bootstrap auto-refreshes a small stale symbol index before reporting capabilities" }
auto_refresh_stale_threshold = { type = "integer", description = "Maximum stale file count eligible for automatic refresh during bootstrap (default 32)" }

# ─────

[[tool]]
name = "register_agent_work"
category = "session"
description = "[CodeLens:Session] Register the current agent intent, branch, and worktree for advisory multi-agent coordination."
annotations = "mut_coord"
output_schema = "register_agent_work_output_schema"

[tool.input_schema]
type = "object"
required = ["agent_name", "branch", "worktree", "intent"]
[tool.input_schema.properties]
session_id = { type = "string", description = "Optional logical session id. Defaults to the active _session_id." }
agent_name = { type = "string" }
branch = { type = "string" }
worktree = { type = "string" }
intent = { type = "string" }
ttl_secs = { type = "integer", description = "Optional advisory TTL in seconds (default 300, clamped to 30-3600)." }

# ─────

[[tool]]
name = "list_active_agents"
category = "session"
description = "[CodeLens:Session] List active agent registrations and their claimed paths for the current project scope."
annotations = "ro_p"
output_schema = "list_active_agents_output_schema"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "claim_files"
category = "session"
description = "[CodeLens:Session] Advisory file claim for the active session. Claims downgrade readiness to caution for overlapping sessions but never hard-block writes."
annotations = "mut_coord"
output_schema = "claim_files_output_schema"

[tool.input_schema]
type = "object"
required = ["paths", "reason"]
[tool.input_schema.properties]
session_id = { type = "string", description = "Optional logical session id. Defaults to the active _session_id." }
paths = { type = "array", items = { type = "string" }, description = "Project-relative paths to claim" }
reason = { type = "string" }
ttl_secs = { type = "integer", description = "Optional advisory TTL in seconds (default 300, clamped to 30-3600)." }

# ─────

[[tool]]
name = "release_files"
category = "session"
description = "[CodeLens:Session] Release previously claimed files for the active session."
annotations = "mut_coord"
output_schema = "release_files_output_schema"

[tool.input_schema]
type = "object"
required = ["paths"]
[tool.input_schema.properties]
session_id = { type = "string", description = "Optional logical session id. Defaults to the active _session_id." }
paths = { type = "array", items = { type = "string" }, description = "Project-relative paths to release" }

# ─────

[[tool]]
name = "prepare_for_new_conversation"
category = "session"
description = "[CodeLens:Session] Project context summary for a new conversation."
annotations = "ro_p"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "summarize_changes"
category = "session"
description = "[CodeLens:Session] Summarize recent git changes with symbol context."
annotations = "ro_p"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "get_watch_status"
category = "session"
description = "[CodeLens:Session] File watcher status: running, events, reindexed files."
annotations = "ro_p"
output_schema = "watch_status_output_schema"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "prune_index_failures"
category = "session"
description = "[CodeLens:Session] Remove stale index-failure records for deleted files."
annotations = "mut_p"
output_schema = "prune_index_failures_output_schema"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "add_queryable_project"
category = "session"
description = "[CodeLens:Session] Register external project for cross-project queries."
annotations = "mutating"

[tool.input_schema]
type = "object"
required = ["path"]
properties = { path = { type = "string", description = "Absolute path to the project directory" } }

# ─────

[[tool]]
name = "remove_queryable_project"
category = "session"
description = "[CodeLens:Session] Unregister an external project."
annotations = "mutating"

[tool.input_schema]
type = "object"
required = ["name"]
properties = { name = { type = "string", description = "Project name to remove" } }

# ─────

[[tool]]
name = "query_project"
category = "session"
description = "[CodeLens:Session] Search symbols in a registered external project."
annotations = "ro_a"

[tool.input_schema]
type = "object"
required = ["project_name", "symbol_name"]
[tool.input_schema.properties]
project_name = { type = "string", description = "Name of the registered project" }
symbol_name = { type = "string", description = "Symbol name to search for" }
max_results = { type = "integer", description = "Max results (default 20)" }

# ─────

[[tool]]
name = "list_queryable_projects"
category = "session"
description = "[CodeLens:Session] List all registered projects (active + external)."
annotations = "ro_p"

[tool.input_schema]
type = "object"
properties = {}

# ─────

[[tool]]
name = "set_preset"
category = "session"
description = "[CodeLens:Session] Switch tool preset at runtime. Auto-adjusts token budget."
annotations = "mutating"

[tool.input_schema]
type = "object"
required = ["preset"]
[tool.input_schema.properties]
preset = { type = "string", enum = ["minimal", "balanced", "full"], description = "Target preset" }
token_budget = { type = "integer", description = "Override token budget (default: auto per preset)" }

# ─────

[[tool]]
name = "set_profile"
category = "session"
description = "[CodeLens:Session] Switch the active role profile. Preferred for harness-oriented workflows."
annotations = "mutating"

[tool.input_schema]
type = "object"
required = ["profile"]
[tool.input_schema.properties]
profile = { type = "string", enum = ["planner-readonly", "builder-minimal", "reviewer-graph", "refactor-full", "ci-audit"] }
token_budget = { type = "integer", description = "Override token budget for the active profile" }

# ─────

[[tool]]
name = "get_capabilities"
category = "session"
description = "[CodeLens:Session] Check LSP, embeddings, index freshness. Use before advanced tools."
annotations = "ro_a"
output_schema = "get_capabilities_output_schema"

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
file_path = { type = "string", description = "Optional file path to check language-specific capabilities" }
detail = { type = "string", enum = ["compact", "full"], description = "compact returns 12 core fields (~1K); full returns all 38 fields including CoreML runtime, SCIP counts, build_info (~5K). Default: full (backward-compatible)." }

# ─────

[[tool]]
name = "get_tool_metrics"
category = "session"
description = "[CodeLens:Session] Per-tool call counts, latency, errors. Use for self-diagnosis."
annotations = "ro_p"
output_schema = "tool_metrics_output_schema"

[tool.input_schema]
type = "object"
properties = { session_id = { type = "string", description = "Optional logical session id. When present, return only that session's metrics." } }

# ─────

[[tool]]
name = "audit_builder_session"
category = "session"
description = "[CodeLens:Session] Audit a builder/refactor session for preflight, diagnostics, and coordination discipline."
annotations = "ro_a"
output_schema = "builder_session_audit_output_schema"
max_response_tokens = 4096

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
session_id = { type = "string", description = "Optional logical session id. Defaults to the active _session_id." }
detail = { type = "string", enum = ["compact", "full"], description = "compact returns the ordered audit checks only; full also includes session metrics and coordination snapshot." }

# ─────

[[tool]]
name = "audit_planner_session"
category = "session"
description = "[CodeLens:Session] Audit a planner/reviewer session for bootstrap, workflow-first routing, and read-side evidence discipline."
annotations = "ro_a"
output_schema = "planner_session_audit_output_schema"
max_response_tokens = 4096

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
session_id = { type = "string", description = "Optional logical session id. Defaults to the active _session_id." }
detail = { type = "string", enum = ["compact", "full"], description = "compact returns the ordered audit checks only; full also includes session metrics." }

# ─────

[[tool]]
name = "export_session_markdown"
category = "session"
description = "[CodeLens:Session] Export session telemetry as markdown report."
annotations = "ro_p"
output_schema = "session_markdown_output_schema"
max_response_tokens = 4096

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
name = { type = "string", description = "Session name for the report header" }
session_id = { type = "string", description = "Optional logical session id. When present, the markdown includes the role-appropriate builder or planner audit summary." }

# ─────

[[tool]]
name = "audit_log_query"
category = "session"
description = "[CodeLens:Admin] Query the durable mutation audit log (`<project>/.codelens/audit/audit_log.sqlite`). Filter by transaction_id and/or since_ms; default limit 100 rows. Requires Admin role."
annotations = "ro_a"

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
transaction_id = { type = "string", description = "Stable id from a mutation response (payload.data.transaction_id). Returns the rows for that one call." }
since_ms = { type = "integer", description = "Earliest timestamp_ms (epoch millis) to include." }
limit = { type = "integer", description = "Max rows (default 100, capped at 1000)." }

# ─────

[[tool]]
name = "summarize_file"
category = "session"
description = "[CodeLens:Session] Get AI-generated summary of a file's purpose and structure."
annotations = "ro_w"

[tool.input_schema]
type = "object"
required = ["path"]
properties = { path = { type = "string", description = "File path to summarize" } }

# ── Rule corpus retrieval ────────────────────────────────────────────

[[tool]]
name = "find_relevant_rules"
category = "rule_corpus"
description = "[CodeLens:Workflow] BM25 search over CLAUDE.md + project memory for policy snippets matching a query. Separate corpus from code retrieval — rule text never pollutes semantic_search results."
annotations = "ro_a"
max_response_tokens = 2048

[tool.input_schema]
type = "object"
required = ["query"]
properties = { query = { type = "string", description = "Natural-language query; identifier tokens are preserved" }, top_k = { type = "integer", description = "Top-K results (1-20, default 3)" } }

# ── Memory ───────────────────────────────────────────────────────────

[[tool]]
name = "list_memories"
category = "memory"
description = "[CodeLens:Memory] List project memory files under .codelens/memories."
annotations = "ro_p"
output_schema = "memory_list_output_schema"

[tool.input_schema]
type = "object"
properties = { topic = { type = "string", description = "Optional topic to filter" } }

# ─────

[[tool]]
name = "read_memory"
category = "memory"
description = "[CodeLens:Memory] Read a named project memory file."
annotations = "ro_p"

[tool.input_schema]
type = "object"
required = ["memory_name"]
properties = { memory_name = { type = "string" } }

# ─────

[[tool]]
name = "write_memory"
category = "memory"
description = "[CodeLens:Memory] Create or overwrite a project memory file."
annotations = "mutating"

[tool.input_schema]
type = "object"
required = ["memory_name", "content"]
properties = { memory_name = { type = "string" }, content = { type = "string" } }

# ─────

[[tool]]
name = "delete_memory"
category = "memory"
description = "[CodeLens:Memory] Delete a project memory file."
annotations = "destructive"

[tool.input_schema]
type = "object"
required = ["memory_name"]
properties = { memory_name = { type = "string" } }

# ─────

[[tool]]
name = "rename_memory"
category = "memory"
description = "[CodeLens:Memory] Rename a project memory file."
annotations = "mut_p"

[tool.input_schema]
type = "object"
required = ["old_name", "new_name"]
properties = { old_name = { type = "string" }, new_name = { type = "string" } }

# ── Semantic (cfg-gated by `feature = "semantic"`) ──────────────────

[[tool]]
name = "semantic_search"
category = "semantic"
description = "[CodeLens:Symbol] Natural language code search via embeddings — find code by meaning."
annotations = "ro_p"
output_schema = "semantic_search_output_schema"
feature_gate = "semantic"

[tool.input_schema]
type = "object"
required = ["query"]
properties = { query = { type = "string", description = "Natural language search query" }, max_results = { type = "integer", description = "Max results (default 20)" } }

# ─────

[[tool]]
name = "index_embeddings"
category = "semantic"
description = "[CodeLens:Symbol] Build semantic embedding index and optionally prewarm query embeddings. Required before semantic_search."
annotations = "ro"
feature_gate = "semantic"

[tool.input_schema]
type = "object"
[tool.input_schema.properties]
background = { type = "boolean", description = "Run as a durable background job and poll with get_analysis_job" }
prewarm_queries = { type = "array", items = { type = "string" }, description = "Representative semantic_search queries to warm immediately after indexing" }
prewarm_limit = { type = "integer", description = "Maximum prewarm query count (default 128, max 1024)" }

# ─────

[[tool]]
name = "find_similar_code"
category = "semantic"
description = "[CodeLens:Analysis] Find semantically similar code to a given symbol — clone detection, reuse opportunities."
annotations = "ro_a"
output_schema = "find_similar_code_output_schema"
feature_gate = "semantic"

[tool.input_schema]
type = "object"
required = ["file_path", "symbol_name"]
[tool.input_schema.properties]
file_path = { type = "string", description = "File containing the symbol" }
symbol_name = { type = "string", description = "Symbol to find similar code for" }
max_results = { type = "integer", description = "Max results (default 10)" }

# ─────

[[tool]]
name = "find_code_duplicates"
category = "semantic"
description = "[CodeLens:Analysis] Find near-duplicate code pairs across the codebase — DRY violations."
annotations = "ro_a"
output_schema = "find_code_duplicates_output_schema"
feature_gate = "semantic"

[tool.input_schema]
type = "object"
properties = { threshold = { type = "number", description = "Cosine similarity threshold (default 0.85)" }, max_pairs = { type = "integer", description = "Max pairs to return (default 20)" } }

# ─────

[[tool]]
name = "classify_symbol"
category = "semantic"
description = "[CodeLens:Analysis] Zero-shot classify a symbol into categories — e.g. error handling, auth, database."
annotations = "ro_a"
output_schema = "classify_symbol_output_schema"
feature_gate = "semantic"

[tool.input_schema]
type = "object"
required = ["file_path", "symbol_name", "categories"]
properties = { file_path = { type = "string" }, symbol_name = { type = "string" }, categories = { type = "array", items = { type = "string" }, description = "Category labels to classify against" } }

# ─────

[[tool]]
name = "find_misplaced_code"
category = "semantic"
description = "[CodeLens:Analysis] Find symbols that are semantic outliers in their file — possible misplacement."
annotations = "ro"
output_schema = "find_misplaced_code_output_schema"
feature_gate = "semantic"

[tool.input_schema]
type = "object"
properties = { max_results = { type = "integer", description = "Max outliers to return (default 10)" } }
