"""Tool schemas exposed to the models.""" from __future__ import annotations from typing import Any def _fn(name: str, description: str, properties: dict[str, Any], required: list[str]) -> dict[str, Any]: return { "type": "function", "function": { "name": name, "description": description, "parameters": { "type": "object", "properties": properties, "required": required, "additionalProperties": False, }, }, } WORKER_TOOLS: list[dict[str, Any]] = [ _fn( "read_file", "Read a UTF-8 text file inside the workspace. Returns numbered lines. " "Use offset/limit for large files.", { "path": {"type": "string", "description": "Path relative to the workspace root."}, "offset": {"type": "integer", "description": "First line (1-based). Default 1."}, "limit": {"type": "integer", "description": "Max lines to return. Default 400."}, }, ["path"], ), _fn( "write_file", "Create or overwrite a text file inside the workspace. Parent directories are created. " "Prefer edit_file for small changes to existing files.", { "path": {"type": "string", "description": "Path relative to the workspace root."}, "content": {"type": "string", "description": "Full new file content."}, }, ["path", "content"], ), _fn( "edit_file", "Replace an exact text fragment in a file. old_string must match exactly, including " "indentation. If the fragment occurs more than once, add context or set replace_all.", { "path": {"type": "string"}, "old_string": {"type": "string"}, "new_string": {"type": "string"}, "replace_all": {"type": "boolean", "description": "Replace every occurrence."}, }, ["path", "old_string", "new_string"], ), _fn( "list_files", "List files and directories in the workspace. Hidden build directories are skipped.", { "path": {"type": "string", "description": "Directory path. Default '.'."}, "depth": {"type": "integer", "description": "Recursion depth. Default 2."}, "limit": {"type": "integer", "description": "Max entries. Default 300."}, }, [], ), _fn( "search_files", "Search file contents with a regular expression (ripgrep if available).", { "pattern": {"type": "string", "description": "Regular expression."}, "path": {"type": "string", "description": "Directory or file. Default '.'."}, "glob": {"type": "string", "description": "Optional file glob, e.g. '*.py'."}, "max_results": {"type": "integer", "description": "Default 80."}, }, ["pattern"], ), _fn( "bash", "Run a shell command with the workspace as cwd. Use it for tests, builds, git, package " "managers and inspecting command output. Do not run interactive commands. Timeout is " "enforced; output is truncated.", { "command": {"type": "string", "description": "Shell command."}, "timeout_seconds": { "type": "integer", "description": "Timeout in seconds. Default from config, max 3600.", }, }, ["command"], ), ] ORCHESTRATOR_TOOLS: list[dict[str, Any]] = [ _fn( "spawn_worker", "Delegate a self-contained task to a new worker. The worker starts immediately and runs " "in its own isolated context. Returns a worker id. Spawn all independent tasks before " "calling wait_for_workers. The worker's context exists only for this task; write the task " "brief in full (goal, constraints, acceptance criteria, files, verification).", { "task": { "type": "string", "description": "Complete, self-contained task brief for the worker.", }, "role": { "type": "string", "description": "Worker role configured in roles, e.g. coder, reviewer, tester, researcher.", }, "workspace": { "type": "string", "description": "Directory for the worker (absolute or relative to the session cwd). " "Use different directories for independent work; defaults to the session workspace.", }, "name": { "type": "string", "description": "Short human-readable name, e.g. 'frontend' or 'api-tests'.", }, "model": { "type": "string", "description": "Optional explicit model override. Use provider-id/model-id to route across providers.", }, "provider": { "type": "string", "description": "Optional configured provider id, e.g. openrouter or ollama.", }, "intelligence": { "type": "string", "enum": ["low", "medium", "high"], "description": "Task complexity / model tier: low for mechanical work, " "medium for normal coding tasks, high for architecture, hard debugging " "or critical review. The low/medium/high -> model mapping is in config.", }, }, ["task"], ), _fn( "update_plan", "Create or replace the user-visible task plan shown in the right-hand TODO panel. " "Call this when you first plan the work, then update statuses as workers start and finish. " "Every top-level task may have subtasks. Statuses: pending, in_progress, done, blocked, " "skipped. Keep worker_id on tasks delegated to a worker.", { "tasks": { "type": "array", "description": "Full plan (replaces the previous plan).", "items": { "type": "object", "properties": { "id": {"type": "string"}, "title": {"type": "string"}, "status": { "type": "string", "enum": [ "pending", "in_progress", "done", "blocked", "skipped", ], }, "worker_id": {"type": "string"}, "subtasks": { "type": "array", "items": { "type": "object", "properties": { "id": {"type": "string"}, "title": {"type": "string"}, "status": { "type": "string", "enum": [ "pending", "in_progress", "done", "blocked", "skipped", ], }, }, "required": ["title"], }, }, }, "required": ["title"], }, } }, ["tasks"], ), _fn( "wait_for_workers", "Suspend yourself until delegated work finishes. This is the required way to wait: do not " "poll in a loop. mode='any' wakes on the first completed worker and returns its report; " "mode='all' waits for every listed worker. You spend no tokens while waiting.", { "worker_ids": { "type": "array", "items": {"type": "string"}, "description": "Workers to wait for. Default: all workers with unreported results.", }, "mode": { "type": "string", "enum": ["any", "all"], "description": "Wake on first completion or wait for all. Default 'any'.", }, "timeout_seconds": { "type": "integer", "description": "Safety timeout. Default from config; max 3600.", }, }, [], ), _fn( "check_workers", "Read current worker statuses and any unreported results without blocking. Use sparingly; " "prefer wait_for_workers when you need results.", { "worker_ids": { "type": "array", "items": {"type": "string"}, "description": "Optional subset. Default: all workers.", } }, [], ), _fn( "message_worker", "Send a follow-up instruction to a finished or failed worker. It keeps the same task " "context, so this is cheaper than spawning a new worker. The worker starts immediately; " "call wait_for_workers afterwards. Cannot be used while the worker is running.", { "worker_id": {"type": "string"}, "message": {"type": "string", "description": "Follow-up instruction or correction."}, }, ["worker_id", "message"], ), _fn( "cancel_worker", "Cancel a running worker and stop its process. Its partial report is kept in the transcript.", { "worker_id": {"type": "string"}, "reason": {"type": "string"}, }, ["worker_id"], ), _fn( "get_worker_transcript", "Inspect the tail of a worker's full message history when its report is not enough. " "Returns the most recent messages, including tool calls and results.", { "worker_id": {"type": "string"}, "tail": {"type": "integer", "description": "Number of recent messages. Default 40."}, }, ["worker_id"], ), _fn( "read_file", "Read a text file for inspection. Paths may be absolute or relative to the session cwd. " "Read-only; delegate modifications to workers.", { "path": {"type": "string"}, "offset": {"type": "integer"}, "limit": {"type": "integer"}, }, ["path"], ), _fn( "list_files", "List a directory tree for inspection. Read-only.", { "path": {"type": "string"}, "depth": {"type": "integer"}, "limit": {"type": "integer"}, }, [], ), _fn( "search_files", "Search file contents with a regular expression. Read-only; delegate changes to workers.", { "pattern": {"type": "string"}, "path": {"type": "string"}, "glob": {"type": "string"}, "max_results": {"type": "integer"}, }, ["pattern"], ), ]