{
  "openapi": "3.1.0",
  "info": {
    "title": "ZeroDrive REST & MCP API",
    "description": "Complete REST API and 24/7 hosted Model Context Protocol (MCP) server for ZeroDrive Cloud Vault. Query, browse, stream, edit, and organize files across every connected device and AI agent.",
    "version": "1.2.0",
    "x-logo": {
      "url": "https://api.zerodrive.dev/app-icon.png",
      "altText": "ZeroDrive"
    },
    "contact": {
      "name": "ZeroDrive Support",
      "url": "https://zerodrive.dev",
      "email": "support@zerodrive.dev"
    }
  },
  "servers": [
    {
      "url": "https://api.zerodrive.dev",
      "description": "ZeroDrive Production Edge API"
    }
  ],
  "tags": [
    {
      "name": "Vault Files",
      "description": "Read, write, edit, slice, move, copy, and stream files"
    },
    {
      "name": "Search & Intelligence",
      "description": "Fast server-side filename searching and text grep"
    },
    {
      "name": "Duplicates",
      "description": "Find groups of files with exactly the same content. Read only: nothing here changes, moves or deletes a file"
    },
    {
      "name": "Streaming & Binaries",
      "description": "Direct pre-signed upload URLs and media streaming"
    },
    {
      "name": "Agent Skills",
      "description": "Reusable skills packaged into _SKILLS/ with strict naming rules"
    },
    {
      "name": "Multi-Device Fleet",
      "description": "Fleet telemetry, device heartbeats, and symlink management"
    },
    {
      "name": "Diagnostics & MCP",
      "description": "Vault health doctor and JSON-RPC 2.0 MCP interface"
    }
  ],
  "paths": {
    "/v1/tree": {
      "get": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Get Visual Folder Tree",
        "description": "Returns a visual directory tree hierarchy of the vault or subfolder.",
        "operationId": "getTree",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Subfolder path to inspect (e.g. '', 'MAIN', 'Course')"
          },
          {
            "name": "depth",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 2,
              "minimum": 1,
              "maximum": 4
            },
            "description": "Depth of tree traversal"
          }
        ],
        "responses": {
          "200": {
            "description": "Directory tree rendered cleanly"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/v1/files": {
      "get": {
        "tags": [
          "Vault Files"
        ],
        "summary": "List Files and Directories",
        "description": "List contents of any folder with file sizes, modified timestamps, MIME types, and optional cursor-based pagination.",
        "operationId": "listFiles",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Directory path"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 500,
              "minimum": 1,
              "maximum": 1000
            },
            "description": "Maximum items per page"
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque pagination cursor from previous response"
          },
          {
            "name": "recursive",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "List recursively"
          }
        ],
        "responses": {
          "200": {
            "description": "Folder listing with next_cursor and total_count"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      },
      "delete": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Delete File",
        "description": "Delete a file from the vault.",
        "operationId": "deleteFileQuery",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "File path to delete"
          }
        ],
        "responses": {
          "200": {
            "description": "File deleted"
          }
        }
      }
    },
    "/v1/files/stat": {
      "get": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Get Item Metadata (Stat)",
        "description": "Retrieve metadata (size, modification date, MIME type, ETag, and directory status) for a single item in sub-15ms.",
        "operationId": "statItem",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "File or directory path"
          }
        ],
        "responses": {
          "200": {
            "description": "Item metadata"
          },
          "404": {
            "description": "Item not found"
          }
        }
      }
    },
    "/v1/files/read": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Read File with Slicing",
        "description": "Read text contents with optional line range slicing (head/tail/lines) or retrieve binary metadata and download URL.",
        "operationId": "readFile",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "path"
                ],
                "properties": {
                  "path": {
                    "type": "string",
                    "description": "Vault file path (e.g. 'MAIN/notes.md')"
                  },
                  "head": {
                    "type": "integer",
                    "description": "Read first N lines"
                  },
                  "tail": {
                    "type": "integer",
                    "description": "Read last N lines"
                  },
                  "lines": {
                    "type": "string",
                    "description": "Line range (e.g. '1-100')"
                  },
                  "encoding": {
                    "type": "string",
                    "enum": [
                      "utf-8",
                      "base64"
                    ],
                    "default": "utf-8"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File content retrieved"
          }
        }
      }
    },
    "/v1/files/write": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Write or Append File",
        "description": "Create, overwrite, or append to any file in the vault via text, base64 binary, or remote source_url.",
        "operationId": "writeFile",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "path"
                ],
                "properties": {
                  "path": {
                    "type": "string",
                    "description": "Target vault path"
                  },
                  "content": {
                    "type": "string",
                    "description": "UTF-8 text content"
                  },
                  "content_base64": {
                    "type": "string",
                    "description": "Base64 data for binary files"
                  },
                  "source_url": {
                    "type": "string",
                    "description": "URL to download directly into vault"
                  },
                  "content_type": {
                    "type": "string",
                    "description": "MIME type (optional)"
                  },
                  "append": {
                    "type": "boolean",
                    "default": false,
                    "description": "Append to existing file"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File written successfully"
          }
        }
      }
    },
    "/v1/files/edit": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Surgical Text Replacement",
        "description": "Replace exact target string with replacement text in a file without re-uploading the entire document.",
        "operationId": "editFile",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "path",
                  "old_text",
                  "new_text"
                ],
                "properties": {
                  "path": {
                    "type": "string",
                    "description": "Vault path"
                  },
                  "old_text": {
                    "type": "string",
                    "description": "Exact string to find"
                  },
                  "new_text": {
                    "type": "string",
                    "description": "Replacement string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Text replaced"
          }
        }
      }
    },
    "/v1/files/move": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Move or Rename File or Folder",
        "description": "Move or rename a file or a folder within the vault. A shared item keeps its share link, its setting and its people at the new path. A file moved onto an existing file replaces it and the answer says replaced. A folder is never moved onto something that exists (409). A folder moves in steps of up to 200 files a call: while the answer says done false, call again with resume true and after set to the answer's next.",
        "operationId": "moveFile",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "source",
                  "destination"
                ],
                "properties": {
                  "source": {
                    "type": "string",
                    "description": "Current path of the file or folder."
                  },
                  "destination": {
                    "type": "string",
                    "description": "New path of the file or folder."
                  },
                  "resume": {
                    "type": "boolean",
                    "description": "Folders only: true on the calls that carry on a move the first call began."
                  },
                  "after": {
                    "type": "string",
                    "description": "Folders only: the cursor (next) the previous answer gave."
                  },
                  "client": {
                    "type": "string",
                    "description": "The command line sends zd; any other value is ignored."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Moved. Always ok, source and destination; also kind (file or folder), shares_followed (share rows that followed the item), move_id (the id of this move in the history, or null when none was written), references_checked (false: a move never looks for files that name the old path; call POST /v1/files/references to look), replaced (true only when a file was replaced) and, for a folder, done, moved, skipped and, while done is false, next and resume true.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "source": {
                      "type": "string"
                    },
                    "destination": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string",
                      "enum": [
                        "file",
                        "folder"
                      ]
                    },
                    "shares_followed": {
                      "type": "integer"
                    },
                    "references_checked": {
                      "type": "boolean"
                    },
                    "replaced": {
                      "type": "boolean"
                    },
                    "done": {
                      "type": "boolean"
                    },
                    "moved": {
                      "type": "integer"
                    },
                    "skipped": {
                      "type": "integer"
                    },
                    "next": {
                      "type": "string"
                    },
                    "resume": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Source file not found"
          },
          "409": {
            "description": "Destination already exists (a folder onto anything that exists)"
          }
        }
      }
    },
    "/v1/files/moves": {
      "get": {
        "tags": [
          "Vault Files"
        ],
        "summary": "What Moved",
        "description": "Read the move history. Without path: the account's most recent moves, newest first. With path: the chain of the item that is at that path now, oldest first, so a caller can see where an item has been; a path the item has moved away from, and the path of an item that was deleted, answer an empty chain. A file inside a folder that moved answers the folder's chain with via_folder true. It only reads.",
        "operationId": "listMoves",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "The path an item is at now."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "description": "How many moves to answer (clamped to 1 to 100)."
          }
        ],
        "responses": {
          "200": {
            "description": "ok, and moves (newest first) or, with path, path, chain (oldest first) and via_folder. A move has move_id, from, to, kind (file or folder), door (web, rest, ai, cli, undo or drive), certainty (sure, or looks for a move that was inferred and not confirmed), moved_at (UTC time), objects, shares_followed, replaced, ended and continues (the move_id it follows, or null). A move made through the drive has a note that it is not confirmed; those made together between two folders are one entry with objects and up to 50 move_ids.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "moves": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "path": {
                      "type": "string"
                    },
                    "chain": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "via_folder": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid path: or Invalid 'after' cursor"
          }
        }
      }
    },
    "/v1/files/undo-move": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Undo the Last Move of an Item",
        "description": "Move an item back to where its last move took it from. Name the move with move_id (from the move answer or from the history) or name the item by the path it is at now. The item's share link follows it back. It never overwrites or merges into what stands at the old path: when the old path is taken the answer is 409 and nothing changes. It does not restore a file that the original move replaced, and it never rewrites a file's content. A folder moves back as it is now, in steps of up to 200 files a call: while the answer says done false, call again with the same move_id or path, resume true and after set to the answer's next. An undo is one more move in the history and can itself be undone.",
        "operationId": "undoMove",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "move_id": {
                    "type": "string",
                    "description": "The id of the move to undo. Give this or path."
                  },
                  "path": {
                    "type": "string",
                    "description": "The path the item is at now. Give this or move_id."
                  },
                  "resume": {
                    "type": "boolean",
                    "description": "Folders only: true on the calls that carry on an undo the first call began."
                  },
                  "after": {
                    "type": "string",
                    "description": "Folders only: the cursor (next) the previous answer gave."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Moved back. ok, source, destination, kind, undone (the move that was undone), move_id (this undo's own id, or null), shares_followed, replaced_not_restored (true when the original move had replaced a file that is not restored), inferred (true when the original move was inferred and not confirmed) and, for a folder, done, moved, skipped and, while done is false, next and resume true.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "source": {
                      "type": "string"
                    },
                    "destination": {
                      "type": "string"
                    },
                    "kind": {
                      "type": "string",
                      "enum": [
                        "file",
                        "folder"
                      ]
                    },
                    "undone": {
                      "type": "string"
                    },
                    "move_id": {
                      "type": "string",
                      "nullable": true
                    },
                    "shares_followed": {
                      "type": "integer"
                    },
                    "replaced_not_restored": {
                      "type": "boolean"
                    },
                    "inferred": {
                      "type": "boolean"
                    },
                    "done": {
                      "type": "boolean"
                    },
                    "moved": {
                      "type": "integer"
                    },
                    "skipped": {
                      "type": "integer"
                    },
                    "next": {
                      "type": "string"
                    },
                    "resume": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Provide move_id or path; Invalid move_id; Invalid path; or Invalid 'after' cursor"
          },
          "404": {
            "description": "Nothing to undo for that move (a later move follows it, a delete or the Trash ended it, or it is not finished), or Item not found where the move put it"
          },
          "409": {
            "description": "Old path already exists: <path>. Nothing was changed."
          },
          "413": {
            "description": "File is over 5 GiB and cannot be moved"
          }
        }
      }
    },
    "/v1/files/references": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Find Text Files That Still Name an Old Path",
        "description": "On request only: list the lines of the vault's own small text files that still name an old path, for example after a move, starting with ROUTER.md at the vault root. A move never runs this. It only reads and never changes a file; changing a file that names the old path is an ordinary write the person asks for. The scan is bounded (files up to 256 KiB, at most 150 files and 8 MiB read, at most 5 pages of 1000 keys listed, at most 50 hits, snippets of at most 300 characters) and the answer says so: truncated true means a limit stopped the scan, so an empty list with truncated true does not mean that nothing names the path.",
        "operationId": "findPathReferences",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "path"
                ],
                "properties": {
                  "path": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 200,
                    "description": "The old path of a file or a folder."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "ok, path, references (each with file, line and snippet), checked_files (text files read), skipped_large (text files above 256 KiB, not read) and truncated.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "path": {
                      "type": "string"
                    },
                    "references": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "file": {
                            "type": "string"
                          },
                          "line": {
                            "type": "integer"
                          },
                          "snippet": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "checked_files": {
                      "type": "integer"
                    },
                    "skipped_large": {
                      "type": "integer"
                    },
                    "truncated": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON payload, or Invalid path: (empty, shorter than 2 or longer than 200 characters, or not a safe vault path)"
          }
        }
      }
    },
    "/v1/files/copy": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Copy File",
        "description": "Duplicate a file to a new destination in the vault.",
        "operationId": "copyFile",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "source",
                  "destination"
                ],
                "properties": {
                  "source": {
                    "type": "string"
                  },
                  "destination": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File copied"
          }
        }
      }
    },
    "/v1/files/delete": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Delete File via POST",
        "description": "Delete a file from the vault.",
        "operationId": "deleteFile",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "path"
                ],
                "properties": {
                  "path": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "File deleted"
          }
        }
      }
    },
    "/v1/files/batch": {
      "post": {
        "tags": [
          "Vault Files"
        ],
        "summary": "Batch File Operations",
        "description": "Execute up to 50 move, copy, and delete operations in one request. The operations run one after the other (not atomically) and the answer has one result per operation, in order. A move row carries shares_followed (and replaced true when a file was replaced); a folder of more than 200 files is an error row and moves nothing: move it with /v1/files/move.",
        "operationId": "batchOperations",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "operations"
                ],
                "properties": {
                  "operations": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "action"
                      ],
                      "properties": {
                        "action": {
                          "type": "string",
                          "enum": [
                            "delete",
                            "copy",
                            "move"
                          ]
                        },
                        "path": {
                          "type": "string"
                        },
                        "source": {
                          "type": "string"
                        },
                        "destination": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch results"
          }
        }
      }
    },
    "/v1/files/upload-urls": {
      "post": {
        "tags": [
          "Streaming & Binaries"
        ],
        "summary": "Create Pre-Signed Upload URLs",
        "description": "Generate 1-hour pre-signed direct HTTP PUT upload URLs for streaming large local files (screenshots, PDFs, MP4/MOV videos, ZIPs up to 5GB) with zero LLM token overhead.",
        "operationId": "createUploadUrls",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "paths": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "path": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pre-signed PUT URLs generated"
          }
        }
      }
    },
    "/v1/files/download-url": {
      "get": {
        "tags": [
          "Streaming & Binaries"
        ],
        "summary": "Get Pre-Signed Download URL",
        "description": "Get a 24-hour HTTPS download URL with HTTP Range (206) support for fast streaming of videos, PDFs, and archives.",
        "operationId": "getDownloadUrl",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Download URL returned"
          }
        }
      }
    },
    "/v1/size": {
      "get": {
        "tags": [
          "Search & Intelligence"
        ],
        "summary": "Get Folder Size & Item Count",
        "description": "Calculate exact byte size, GB formatted total, and file count for any folder.",
        "operationId": "getFolderSize",
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Folder path (leave blank for vault root)"
          }
        ],
        "responses": {
          "200": {
            "description": "Size summary"
          }
        }
      }
    },
    "/v1/search": {
      "get": {
        "tags": [
          "Search & Intelligence"
        ],
        "summary": "Search Filenames & Extensions",
        "description": "Fast server-side wildcard search across all files in vault.",
        "operationId": "searchFilenames",
        "parameters": [
          {
            "name": "query",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Keyword or extension to find"
          },
          {
            "name": "path",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Subfolder filter"
          }
        ],
        "responses": {
          "200": {
            "description": "Matching files"
          }
        }
      }
    },
    "/v1/duplicates/scan": {
      "post": {
        "tags": [
          "Duplicates"
        ],
        "summary": "Scan for Duplicate Files (one step)",
        "description": "Takes one step of a scan for files with exactly the same content, in the whole vault or in one folder. It only reads: it never changes, moves or deletes a file. Repeat the call with the scan_id of the answer until it says done is true, then read the groups with GET /v1/duplicates. To remove duplicates, a person uses Duplicates in the ZeroDrive web app or the Mac app or zd, which call POST /v1/duplicates/remove; this route never removes anything.",
        "operationId": "scanDuplicates",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "path": {
                    "type": "string",
                    "description": "Folder to scan. Leave out to scan the whole vault."
                  },
                  "scan_id": {
                    "type": "string",
                    "description": "The scan_id of an earlier answer, to take the next step of that scan."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The scan so far: state, progress, counts and done"
          },
          "400": {
            "description": "Invalid 'path' or Invalid request"
          },
          "404": {
            "description": "Scan not found"
          }
        }
      }
    },
    "/v1/duplicates/remove": {
      "post": {
        "tags": [
          "Duplicates"
        ],
        "summary": "Remove the Extra Copies of Duplicate Files",
        "description": "Keeps one file of each group and removes the others, following the account's web delete setting: Trash by default (the space comes back when Trash is emptied), or a real delete. The request must carry the person's confirm: true when the setting is Trash, the word DELETE when it is Delete right away; otherwise the answer is 400 confirm_required with the mode. It never trusts the scan: each file is read again and an extra moves only when its size and SHA-256 equal the kept file's. A request does a bounded amount of work: when the answer says done is false, repeat the call with groups.slice(next_group). Repeating a request is safe: removed files answer already_gone. This route is for the ZeroDrive apps and zd (a device token); an AI connector (an OAuth token) is refused with 403.",
        "operationId": "removeDuplicates",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "scan_id",
                  "groups",
                  "confirm"
                ],
                "properties": {
                  "scan_id": {
                    "type": "string",
                    "description": "The scan_id of a finished scan."
                  },
                  "groups": {
                    "type": "array",
                    "description": "At most 100 groups and 400 paths in all; no path twice.",
                    "items": {
                      "type": "object",
                      "required": [
                        "keep",
                        "remove"
                      ],
                      "properties": {
                        "keep": {
                          "type": "string",
                          "description": "The path that stays."
                        },
                        "remove": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "The paths to remove."
                        }
                      }
                    }
                  },
                  "confirm": {
                    "description": "true when the account's web delete setting is trash; the string DELETE when it is delete_now."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "done, mode, message, results (one for each group, with the status of each file), removed, shared_removed and next_group"
          },
          "400": {
            "description": "Invalid request, or confirm_required (with the mode)"
          },
          "403": {
            "description": "An AI connector token, or an account that can not write"
          },
          "404": {
            "description": "Scan not found"
          },
          "409": {
            "description": "scan_not_finished"
          }
        }
      }
    },
    "/v1/duplicates": {
      "get": {
        "tags": [
          "Duplicates"
        ],
        "summary": "List Duplicate Files",
        "description": "Groups of files with exactly the same content from a finished scan, the most wasted space first, with the counts, one plain message that says which files were not compared, delete_mode (trash or delete_now: what a delete does for this account), and for every file shared and suggested_keep (exactly one file in each group). It only reads. Without scan_id it answers the newest finished scan.",
        "operationId": "listDuplicates",
        "parameters": [
          {
            "name": "scan_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "The scan to read (default: the newest finished scan)"
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Where to start in the list of groups"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 25,
              "maximum": 100
            },
            "description": "Groups in a page"
          }
        ],
        "responses": {
          "200": {
            "description": "The groups, counts, message, delete_mode, total_groups and next_offset"
          },
          "400": {
            "description": "Invalid request"
          },
          "404": {
            "description": "Scan not found"
          }
        }
      }
    },
    "/v1/grep": {
      "post": {
        "tags": [
          "Search & Intelligence"
        ],
        "summary": "Grep Inside Text Files",
        "description": "Search text contents across markdown, code, and text files, returning line numbers and snippets.",
        "operationId": "grepVault",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "Search keyword or text"
                  },
                  "path": {
                    "type": "string",
                    "description": "Folder to restrict search to"
                  },
                  "max_results": {
                    "type": "integer",
                    "default": 30
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Grep results"
          }
        }
      }
    },
    "/v1/doctor": {
      "get": {
        "tags": [
          "Diagnostics & MCP"
        ],
        "summary": "Vault Doctor Health Check",
        "description": "Inspect root folders, installed skills, connected devices, and service capabilities.",
        "operationId": "getVaultDoctor",
        "responses": {
          "200": {
            "description": "Health diagnostics"
          }
        }
      }
    },
    "/v1/prompts": {
      "get": {
        "tags": [
          "Agent Skills"
        ],
        "summary": "List or Read Ready-Made Prompts",
        "description": "Without a name, lists the ready-made prompts (the same list the MCP prompts/list method answers, saved skills included). With a name, returns that prompt's text, the same text prompts/get answers. Needs a token and a plan; a read-only account can read it.",
        "operationId": "getPrompts",
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Prompt name (e.g. 'check-vault' or 'skill-create-substack-articles'). Exact match."
          },
          {
            "name": "path",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Optional folder for the prompts that take one (e.g. 'sort-intake'). Only with name."
          }
        ],
        "responses": {
          "200": {
            "description": "{ ok, count, prompts, skills_not_shown } without a name, { ok, name, description, text } with one"
          },
          "400": {
            "description": "The folder or the name is not valid"
          },
          "401": {
            "description": "No token"
          },
          "403": {
            "description": "plan_required: the account has no active plan"
          },
          "404": {
            "description": "No prompt has that name"
          }
        }
      }
    },
    "/v1/skills": {
      "get": {
        "tags": [
          "Agent Skills"
        ],
        "summary": "List or Inspect Skills",
        "description": "List all agent skills in _SKILLS/ or inspect a specific skill's SKILL.md.",
        "operationId": "getSkills",
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Specific skill name (e.g. 'create-substack-articles')"
          }
        ],
        "responses": {
          "200": {
            "description": "Skill details or list"
          }
        }
      },
      "post": {
        "tags": [
          "Agent Skills"
        ],
        "summary": "Package and Save Skill",
        "description": "Package a reusable Agent Skill into _SKILLS/<verb-noun-name>/SKILL.md enforcing naming rules and buzzword filters.",
        "operationId": "saveSkill",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "description",
                  "instructions"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Lowercase hyphenated verb-noun name (e.g. 'create-substack-articles')"
                  },
                  "description": {
                    "type": "string",
                    "description": "Short description"
                  },
                  "instructions": {
                    "type": "string",
                    "description": "Markdown instructions for SKILL.md"
                  },
                  "files": {
                    "type": "array",
                    "description": "Optional bundled scripts or files",
                    "items": {
                      "type": "object",
                      "required": [
                        "relative_path"
                      ],
                      "properties": {
                        "relative_path": {
                          "type": "string"
                        },
                        "content": {
                          "type": "string"
                        },
                        "content_base64": {
                          "type": "string"
                        },
                        "source_url": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Skill saved"
          }
        }
      }
    },
    "/v1/devices": {
      "get": {
        "tags": [
          "Multi-Device Fleet"
        ],
        "summary": "List Connected Devices",
        "description": "List all registered Mac computers, servers, and VMs connected to the vault.",
        "operationId": "getDevices",
        "responses": {
          "200": {
            "description": "Device fleet status"
          }
        }
      }
    },
    "/v1/devices/heartbeat": {
      "post": {
        "tags": [
          "Multi-Device Fleet"
        ],
        "summary": "Record Device Heartbeat",
        "description": "Record disk space, mount state, and heartbeat from a connected device.",
        "operationId": "recordDeviceHeartbeat",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "device_id"
                ],
                "properties": {
                  "device_id": {
                    "type": "string"
                  },
                  "hostname": {
                    "type": "string"
                  },
                  "os": {
                    "type": "string"
                  },
                  "free_gb": {
                    "type": "number"
                  },
                  "mount_status": {
                    "type": "string"
                  },
                  "mount_path": {
                    "type": "string"
                  },
                  "version": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Heartbeat acknowledged"
          }
        }
      }
    },
    "/v1/symlinks": {
      "get": {
        "tags": [
          "Multi-Device Fleet"
        ],
        "summary": "List Active Symlinks",
        "description": "List folder shortcuts created across user devices.",
        "operationId": "getSymlinks",
        "responses": {
          "200": {
            "description": "Symlink registry"
          }
        }
      },
      "post": {
        "tags": [
          "Multi-Device Fleet"
        ],
        "summary": "Register Local Symlink",
        "description": "Register a local symlink on a device mapping to a vault folder.",
        "operationId": "registerSymlink",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "local_path",
                  "vault_target"
                ],
                "properties": {
                  "device_id": {
                    "type": "string"
                  },
                  "local_path": {
                    "type": "string"
                  },
                  "vault_target": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Symlink registered"
          }
        }
      }
    },
    "/v1/events": {
      "get": {
        "tags": [
          "Real-Time Push & Events"
        ],
        "summary": "Server-Sent Events (SSE) Push Notifications",
        "description": "Streams live vault file mutations (write, edit, move, copy, delete) in real-time over a persistent HTTP SSE connection. Supports ping heartbeats and automatic reconnection.",
        "operationId": "getEventStream",
        "responses": {
          "200": {
            "description": "Text Event Stream",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/activity/stream": {
      "get": {
        "tags": [
          "Real-Time Push & Events"
        ],
        "summary": "Real-Time Activity SSE Stream (Alias)",
        "description": "Streams real-time activity and file change events over SSE.",
        "operationId": "getActivityStream",
        "responses": {
          "200": {
            "description": "Text Event Stream",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/activity": {
      "get": {
        "tags": [
          "Multi-Device Fleet"
        ],
        "summary": "Get Activity Ledger",
        "description": "Recent file migrations, sync events, and agent operations across devices.",
        "operationId": "getActivity",
        "responses": {
          "200": {
            "description": "Recent activity entries"
          }
        }
      },
      "post": {
        "tags": [
          "Multi-Device Fleet"
        ],
        "summary": "Log Custom Activity",
        "description": "Record a custom activity entry in the vault ledger.",
        "operationId": "logActivityEntry",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "action"
                ],
                "properties": {
                  "action": {
                    "type": "string"
                  },
                  "details": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Activity recorded"
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "tags": [
          "Diagnostics & MCP"
        ],
        "summary": "ZeroDrive MCP JSON-RPC 2.0 Endpoint",
        "operationId": "executeMCP",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jsonrpc": {
                    "type": "string",
                    "example": "2.0"
                  },
                  "id": {
                    "type": "string",
                    "example": "1"
                  },
                  "method": {
                    "type": "string",
                    "example": "tools/list"
                  },
                  "params": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "MCP JSON-RPC response"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "API_KEY / OAuth Token",
        "description": "ZeroDrive Personal API Key (zdk_), device token, or OAuth 2.0 Bearer token"
      },
      "OAuth2": {
        "type": "oauth2",
        "description": "ZeroDrive OAuth 2.0 flow with confidential & public clients, refresh tokens, and consent-screen scoping",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://api.zerodrive.dev/oauth/authorize",
            "tokenUrl": "https://api.zerodrive.dev/oauth/token",
            "refreshUrl": "https://api.zerodrive.dev/oauth/token",
            "scopes": {
              "mcp": "Full MCP and REST agent vault access",
              "vault:read": "Read files in vault",
              "vault:write": "Write, upload, edit, and move files in vault",
              "vault:delete": "Delete files in vault",
              "offline_access": "Issue rotating refresh token for long-lived public integrations"
            }
          }
        }
      }
    }
  },
  "security": [
    {
      "BearerAuth": []
    },
    {
      "OAuth2": [
        "mcp",
        "vault:read",
        "vault:write"
      ]
    }
  ]
}