[
 {
  "type": "function",
  "function": {
   "name": "filesystem",
   "description": "Operate the local filesystem: read, write, edit, search, and manage files. Editing policy — cheapest deterministic method first, smart_edit LAST: use 'edit' (exact text, the default) or 'edit_lines' (known line numbers); both are deterministic. Reach for 'smart_edit' ONLY when the change cannot be expressed as text or line numbers — it costs an LLM call and reads the whole file. Call 'info' before reading an unknown file. Full action list, argument rules and access limits: tool_manual(\"filesystem\").",
   "parameters": {
    "type": "object",
    "properties": {
     "action": {
      "type": "string",
      "enum": [
       "read",
       "write",
       "append",
       "edit",
       "edit_lines",
       "list",
       "find",
       "find_up",
       "info",
       "move",
       "copy",
       "delete",
       "exists",
       "mkdir",
       "query",
       "smart_edit",
       "grep",
       "diff"
      ],
      "description": "Operation to perform."
     },
     "path": {
      "type": "string",
      "description": "Absolute or relative file/directory path (~ is expanded)."
     },
     "content": {
      "type": "string",
      "description": "Text to write or append (required for write/append)."
     },
     "old": {
      "type": "string",
      "description": "Exact text to replace (required for edit). Must occur exactly once."
     },
     "new": {
      "type": "string",
      "description": "Replacement text for edit."
     },
     "operations": {
      "type": "array",
      "description": "Line-based edits (required for edit_lines). 1-based, inclusive. 'after' applies to insert.",
      "items": {
       "type": "object",
       "properties": {
        "op": {
         "type": "string",
         "enum": [
          "replace",
          "delete",
          "insert"
         ]
        },
        "start": {
         "type": "integer"
        },
        "end": {
         "type": "integer"
        },
        "after": {
         "type": "integer"
        },
        "content": {
         "type": "string"
        }
       },
       "required": [
        "op"
       ]
      }
     },
     "numbered": {
      "type": "boolean",
      "description": "Number the lines in read output (default true). Set false to copy text into 'edit'."
     },
     "destination": {
      "type": "string",
      "description": "Second path: the target for move/copy, or the file to compare against for diff."
     },
     "pattern": {
      "type": "string",
      "description": "Glob pattern for find (e.g. '*.log'), or exact filename for find_up."
     },
     "offset": {
      "type": "integer",
      "description": "First line to read, 1-based (for read action)."
     },
     "limit": {
      "type": "integer",
      "description": "Max lines to return (for read action)."
     },
     "recursive": {
      "type": "boolean",
      "description": "Full recursive directory tree (for list, default false)."
     },
     "regex": {
      "type": "boolean",
      "description": "Use regex matching for grep (default false = literal substring search)."
     },
     "question": {
      "type": "string",
      "description": "Natural language question about the file (for query) — the answer comes back instead of the file."
     },
     "instruction": {
      "type": "string",
      "description": "Natural language edit instruction (for smart_edit)."
     }
    },
    "required": [
     "action",
     "path"
    ]
   }
  }
 },
 {
  "type": "function",
  "function": {
   "name": "terminal",
   "description": "Run shell commands locally. Supports both one-shot execution (run) and persistent named terminal sessions (open/close/list/status/send_input). Use persistent terminals for long-running processes, dev servers, or interactive workflows where state (cwd, env) must be preserved.",
   "parameters": {
    "type": "object",
    "properties": {
     "action": {
      "type": "string",
      "enum": [
       "run",
       "open",
       "close",
       "list",
       "status",
       "send_input"
      ],
      "description": "Operation to perform."
     },
     "terminal_name": {
      "type": "string",
      "description": "Name for the persistent terminal (required for open, close, status, send_input)."
     },
     "description": {
      "type": "string",
      "description": "A short human-readable explanation of what this terminal will do (e.g. 'Local dev server', 'Build pipeline'). REQUIRED when action is 'open' — without it the open will fail."
     },
     "command": {
      "type": "string",
      "description": "Shell command to execute (required for run and open)."
     },
     "background": {
      "type": "boolean",
      "description": "action=open: start the persistent terminal detached (native mode). action=run: detach the whole call into a background task — returns a task_id immediately, result arrives via the tasks tool / completion note. Use for builds, tests, installs — anything slower than ~45-60s. Default false."
     },
     "working_dir": {
      "type": "string",
      "description": "Working directory (optional, defaults to home or sandbox)."
     },
     "timeout": {
      "type": "integer",
      "description": "Timeout in seconds (default 20, max 300)."
     },
     "input": {
      "type": "string",
      "description": "Text to send to the terminal's stdin (for send_input)."
     }
    },
    "required": [
     "action"
    ]
   }
  }
 },
 {
  "type": "function",
  "function": {
   "name": "ssh_exec",
   "description": "Run a command on a remote server over SSH. Required: command + host. Pass username and password (or key_path) directly — no config file needed. Use for any task on a remote VPS, server, or device. Host key verification is skipped by default for ad-hoc connections. Connections are reused within a session (20-minute TTL) — no reconnect overhead.",
   "parameters": {
    "type": "object",
    "properties": {
     "action": {
      "type": "string",
      "enum": [
       "exec",
       "scp"
      ],
      "description": "Action to perform: exec (run command, default) or scp (transfer file)."
     },
     "command": {
      "type": "string",
      "description": "Shell command to run on the remote host (required for action=exec)."
     },
     "host": {
      "type": "string",
      "description": "Hostname or IP address of the remote server"
     },
     "username": {
      "type": "string",
      "description": "SSH username"
     },
     "password": {
      "type": "string",
      "description": "SSH password (if using password authentication)"
     },
     "port": {
      "type": "integer",
      "description": "SSH port (default 22)"
     },
     "key_path": {
      "type": "string",
      "description": "Path to private key file, e.g. ~/.ssh/id_rsa (if using key authentication)"
     },
     "connection": {
      "type": "string",
      "description": "Named connection from ssh_hosts.json — shortcut that provides host/user/creds automatically"
     },
     "local_path": {
      "type": "string",
      "description": "Local file path (required for action=scp)."
     },
     "remote_path": {
      "type": "string",
      "description": "Remote file path (required for action=scp)."
     },
     "direction": {
      "type": "string",
      "enum": [
       "upload",
       "download"
      ],
      "description": "Transfer direction for scp: upload (local→remote) or download (remote→local)."
     },
     "timeout": {
      "type": "integer",
      "description": "Timeout in seconds (default 60)"
     },
     "background": {
      "type": "boolean",
      "description": "Detach the call into a background task — returns a task_id immediately, result arrives via the tasks tool / completion note. Use for long remote commands (builds, package installs, backups). Default false."
     }
    },
    "required": []
   }
  }
 },
 {
  "type": "function",
  "function": {
   "name": "code_exec",
   "description": "Run Python code and return output. Use for calculations, data parsing, text processing, or anything that benefits from a script. Each call is a fresh interpreter — import everything you need, no state persists. For shell-native tasks (pipes, system commands) prefer terminal instead. Timeout defaults to 30s (max 300s) — set the `timeout` param for long runs.",
   "parameters": {
    "type": "object",
    "properties": {
     "code": {
      "type": "string",
      "description": "Python code to execute"
     },
     "working_dir": {
      "type": "string",
      "description": "Working directory for the script (optional)."
     },
     "timeout": {
      "type": "number",
      "description": "Execution timeout in seconds (default 30, max 300). Raise it for long computations or test suites."
     },
     "background": {
      "type": "boolean",
      "description": "Detach the call into a background task — returns a task_id immediately, result arrives via the tasks tool / completion note. Use for long computations/test suites. Default false."
     }
    },
    "required": [
     "code"
    ]
   }
  }
 },
 {
  "type": "function",
  "function": {
   "name": "todo",
   "description": "Task plan tracker, already populated from the plan when a task starts — you do NOT need to call 'set'. Indexes are 1-based.\n\nCall 'update' with status='in_progress' when you start a step, and again immediately after completing or failing it, before starting the next. Marking a step 'done' REQUIRES a 'validation' field saying how you verified the result; 'failed' should carry one explaining what went wrong and what you tried. Before your final response, every completed step — the last one included — must be 'done' with validation.\n\n'add' appends steps discovered mid-task and keeps existing steps and their statuses; 'set' replaces the whole plan and discards them. 'view' re-orients you after a sub-agent run or a long tool chain.\n\nFull rules, statuses and examples: tool_manual(\"todo\").",
   "parameters": {
    "type": "object",
    "properties": {
     "op": {
      "type": "string",
      "enum": [
       "set",
       "view",
       "update",
       "add",
       "clear"
      ],
      "description": "set — create/replace the Master Plan with a list of task milestones; view — show the current state of the plan; update — change the status of a specific task; add — append new steps to the plan (preserves existing steps and their statuses); clear — reset the plan"
     },
     "tasks": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "description": "Ordered list of task descriptions (required for 'set' and 'add')."
     },
     "index": {
      "type": "integer",
      "description": "1-based task index (required for 'update')."
     },
     "status": {
      "type": "string",
      "enum": [
       "pending",
       "in_progress",
       "done",
       "failed",
       "skipped"
      ],
      "description": "New status for the task (required for 'update')."
     },
     "validation": {
      "type": "string",
      "description": "Required when status='done': briefly describe how you verified the result (e.g. 'ran test_tool — output matched expected', 'read the file and confirmed content'). Encouraged when status='failed': describe what went wrong and what you tried."
     }
    },
    "required": [
     "op"
    ]
   }
  }
 }
]