---
name: manage-operations
description: Submit and manage operational tasks (e.g., restarts, scale, upgrades). Uses operations.yaml to understand required parameters.
---

<critical_safety_rule>
DO NOT under any circumstances send a POST request to `/operation/instances` before showing the full JSON payload to the user and receiving explicit approval.
Executing the API call without user confirmation is a SEVERE security violation.
</critical_safety_rule>

# Overview

This sub-skill allows you to submit operational tasks (like restarting clusters, scaling resource pools) to the DevOps backend via the `/operation/instances` endpoint.

It integrates deeply with `manage-operations/operations.yaml` and `manage-operations/supported_operations.md` to understand:
1. What operations are supported.
2. What parameters are required versus optional.
3. How to construct the `actions` pipeline (it sets all `start_policy` to `manual` and `start_schedule_at` to `null` by default).
4. The `type` (target) of the operation (e.g., `cluster`, `tenant`, `resource_pool`).

# Workflow

1.  **Understand the Request**: Identify that the user wants to perform an operational task (e.g., "帮我重启tidb 集群123").
2.  **Gather Context**: Read `manage-operations/supported_operations.md` and `manage-operations/operations.yaml` to find the exact operation name and its required parameters.
3.  **Fetch Missing Details**: If you need cluster or tenant info to fill parameters (e.g., `tenant_id`, `tenant_region`), use the `query-clusters` and `query-tenants` sub-skills first.
4.  **Confirm with User**:
    * Construct a simulated request body (JSON) containing **all** parameters (both required and optional).
    * **CRITICAL**: Present this simulated payload to the user and ask: "这是即将发起的操作参数，是否需要修改？请确认是否符合需求并继续提交。"
    * Iterate until the user explicitly confirms (e.g., says "确认提交", "没问题", "执行", "sure", "ok"). DO NOT PROCEED TO STEP 5 WITHOUT THIS EXPLICIT CONFIRMATION.
5.  **Execute**: Send the POST request to the API ONLY AFTER user confirmation.
6.  **Return Link**: The API returns an `instance_id`. Construct the URL `{DEVOPS_FRONTEND}/operations/{instance_id}` and present it to the user.

# Available Actions

## Create Operation Instance

Create an operation instance based on the gathered and confirmed parameters.

### API Path & Method

API Path: `/operation/instances`

Method: `POST`

### Request Body (JSON)

Construct the JSON body based on the `operations.yaml` definition:
```json
{
  "type": "cluster",             // From operations.yaml (target)
  "operation": "RestartTiDBComponents", // From operations.yaml (name)
  "reason": "User requested...", // Reason for the operation
  "params": {                    // Key-value map (values must be strings if API expects map[string]string, unless backend supports mixed types. usually strings/ints depending on API definition, check schema)
    "cluster_id": "123",
    "tenant_id": "456",
    // ... other params ...
  },
  "actions": [                   // Constructed from operations.yaml
    {
      "name": "Restart",
      "start_policy": "manual",
      "start_schedule_at": null
    }
  ],
  "is_draft": false
}
```