trusty-mpm 0.8.0

trusty-mpm: unified multi-agent orchestration platform (core, daemon, CLI, TUI, Telegram)
//! Console-facing MCP tool descriptors (#1222 / P2).
//!
//! Why: trusty-console renders the Sessions tab by polling the daemon over MCP
//! (#1104 keeps HTTP only in the console). It needs three tools the original
//! catalog lacked: the service-agnostic `console_metrics` report, a
//! `supervisor_status` fleet snapshot, and `auto_resume_set` — the non-CLI
//! control for enabling/disabling supervisor auto-resume (RFC §6 Q6). Keeping
//! their descriptors here keeps `tools/core.rs` and `tools/session.rs` each well
//! under the 500-SLOC cap.
//! What: [`console_tools`] returns the three `{ name, description, inputSchema }`
//! descriptors in catalog order. The shared [`tool`] builder is re-exported from
//! the parent module.
//! Test: `super::tests::console_tools_present`,
//! `super::tests::catalog_names_match_constant`.

use serde_json::{Value, json};

use super::tool;

/// Build the five console-facing tool descriptors.
///
/// Why: the console poller (`console_metrics`), the Sessions supervisor widget
/// (`supervisor_status`), the auto-resume toggle (`auto_resume_set`), and the
/// #1220 Config tab (`config_read` / `config_write`) each map to one descriptor
/// here; a dedicated builder keeps the catalog modular.
/// What: returns the five descriptors. `console_metrics`, `supervisor_status`, and
/// `config_read` take no arguments; `auto_resume_set` requires a boolean `enabled`;
/// `config_write` takes an optional `workspace_root_template`/`default_model`
/// string and an optional `auto_resume` boolean. All schemas set
/// `additionalProperties: false`.
/// Test: `super::tests::console_tools_present`.
pub(super) fn console_tools() -> Vec<Value> {
    vec![
        tool(
            "console_metrics",
            "Return the standard trusty-console metrics report for trusty-mpm: \
             service id, display name, version, coarse health status, and a \
             `metrics` payload carrying the managed-session fleet snapshot \
             (counts by lifecycle state) and the supervisor auto-resume control \
             state. Polled uniformly by trusty-console for the dashboard.",
            json!({
                "type": "object",
                "properties": {},
                "additionalProperties": false
            }),
        ),
        tool(
            "supervisor_status",
            "Return the managed-session fleet snapshot and the supervisor \
             auto-resume control state as `{ fleet, auto_resume }`. `fleet` carries \
             counts by lifecycle state (provisioning/active/stopped/errored/\
             decommissioned), pending decisions, and last activity; `auto_resume` \
             carries the persisted desired flag, the supervisor's boot-time env \
             flag, and whether a restart is pending.",
            json!({
                "type": "object",
                "properties": {},
                "additionalProperties": false
            }),
        ),
        tool(
            "auto_resume_set",
            "Enable or disable supervisor auto-resume by persisting the operator's \
             desired flag to `~/.trusty-mpm/auto_resume`. The 24/7 supervisor reads \
             this on its next sweep; the env var the supervisor booted with stays \
             in force until then (the response's `pending_restart` flags the \
             difference). This is the console's non-CLI auto-resume control.",
            json!({
                "type": "object",
                "properties": {
                    "enabled": {
                        "type": "boolean",
                        "description": "True to enable auto-resume of stopped sessions; false to disable."
                    }
                },
                "required": ["enabled"],
                "additionalProperties": false
            }),
        ),
        tool(
            "config_read",
            "Read trusty-mpm's `~/.trusty-tools/trusty-mpm/config.yaml` (the #1220 \
             cross-crate config convention) and return its current settings as JSON: \
             `workspace_root_template`, `auto_resume`, and `default_model`. An absent \
             file returns the defaults (all null). Backs the trusty-console Config tab.",
            json!({
                "type": "object",
                "properties": {},
                "additionalProperties": false
            }),
        ),
        tool(
            "config_write",
            "Write trusty-mpm's `~/.trusty-tools/trusty-mpm/config.yaml` (#1220). \
             Supplied fields replace the corresponding settings; omitted fields are \
             left unchanged. `workspace_root_template` sets the managed-session \
             workspace root (a leading `~` is expanded); `auto_resume` sets the \
             supervisor default; `default_model` sets the launch model. Returns the \
             merged config that was persisted.",
            json!({
                "type": "object",
                "properties": {
                    "workspace_root_template": {
                        "type": "string",
                        "description": "Template dir for session workspaces (e.g. `~/trusty-mpm-projects`)."
                    },
                    "auto_resume": {
                        "type": "boolean",
                        "description": "Default supervisor auto-resume preference."
                    },
                    "default_model": {
                        "type": "string",
                        "description": "Default model id or tier alias for launched sessions."
                    }
                },
                "additionalProperties": false
            }),
        ),
    ]
}