{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/kthilagarajan/mrterminal/main/schema/config.schema.json",
  "title": "MrTerminal configuration",
  "description": "~/.mrterminal/config.json: projects, their open terminals, layouts, presets and commands, and app settings. While MrTerminal runs it owns this file and rewrites it within a second of any change, so edit it only while the app is closed; with the app running, use the `mrt` command instead. Missing fields get defaults and unknown fields are dropped on load.",
  "type": "object",
  "required": ["version", "projects"],
  "properties": {
    "$schema": { "type": "string" },
    "version": { "const": 1, "description": "Format version." },
    "settings": { "$ref": "#/$defs/Settings" },
    "projects": {
      "type": "array",
      "description": "Projects in sidebar order.",
      "items": { "$ref": "#/$defs/Project" }
    },
    "activeProjectId": {
      "type": ["string", "null"],
      "description": "Id of the project on screen."
    },
    "sidebarWidth": { "type": "number", "default": 280, "description": "Sidebar width in pixels." },
    "sidebarHidden": { "type": "boolean", "default": false },
    "sidebarCompact": {
      "type": "boolean",
      "default": false,
      "description": "Project cards show only their name, without the folder path."
    },
    "globalCommands": {
      "type": "array",
      "description": "Commands offered in every project from the arrow next to + Terminal, such as coding agents. Seeded with the agents found on first launch (claude, codex, cursor-agent, agy, grok).",
      "items": { "$ref": "#/$defs/GlobalCommand" }
    },
    "window": {
      "type": "object",
      "description": "Window position and size; written by the app.",
      "properties": {
        "x": { "type": "number" },
        "y": { "type": "number" },
        "width": { "type": "number" },
        "height": { "type": "number" },
        "maximized": { "type": "boolean" }
      },
      "required": ["width", "height"]
    }
  },
  "$defs": {
    "Settings": {
      "type": "object",
      "properties": {
        "restoreOnLaunch": {
          "enum": ["ask", "resume", "layout", "fresh"],
          "default": "ask",
          "description": "What happens to the previous session's terminals at start: ask every time; resume (reopen and re-run every command); layout (reopen, leave commands typed at the prompt); fresh (start empty)."
        },
        "shell": {
          "type": ["string", "null"],
          "default": null,
          "description": "Absolute path of the shell to launch; null for the user's login shell."
        },
        "fontSize": { "type": "number", "default": 13 },
        "showRunning": {
          "type": "boolean",
          "default": true,
          "description": "List what is running under each project in the sidebar."
        },
        "editor": {
          "type": ["string", "null"],
          "default": null,
          "description": "Editor the top bar's Open button uses: cursor, vscode, vscode-insiders, windsurf, zed, sublime, webstorm, idea, pycharm, goland, rider, android-studio or fleet. null = the first one installed."
        },
        "terminalCommand": {
          "type": ["string", "null"],
          "default": null,
          "description": "Id of the global command the top bar's terminal button starts (the one picked last from its menu). null = a plain shell."
        },
        "fontFamily": {
          "type": ["string", "null"],
          "default": null,
          "description": "Terminal font family; null for the built-in monospace font."
        },
        "theme": {
          "enum": ["midnight", "dracula", "nord", "solarized-dark", "daylight", "solarized-light"],
          "default": "midnight"
        }
      }
    },
    "Project": {
      "type": "object",
      "description": "A folder whose scripts MrTerminal offers to run.",
      "required": ["id", "path"],
      "properties": {
        "id": { "type": "string", "description": "Stable id, e.g. 8 random hex characters." },
        "name": { "type": "string", "description": "Name in the sidebar; defaults to the path." },
        "path": { "type": "string", "description": "Absolute path of the project folder. Projects whose folder no longer exists are dropped." },
        "terminals": {
          "type": "array",
          "description": "Terminals open right now, in no particular order. This is what is restored at the next start.",
          "items": { "$ref": "#/$defs/Terminal" }
        },
        "layout": {
          "description": "Dockview layout (splits, tabs, sizes) referring to terminal ids. Optional: terminals missing from it are tiled automatically, so null is always safe.",
          "type": ["object", "null"]
        },
        "customCommands": {
          "type": "array",
          "description": "Commands the user added that are not in any script file.",
          "items": { "$ref": "#/$defs/CustomCommand" }
        },
        "presets": {
          "type": "array",
          "description": "Saved sets of terminals that open together in one click.",
          "items": { "$ref": "#/$defs/Preset" }
        },
        "aliases": {
          "type": "object",
          "description": "Names given to detected scripts. Key: the folder relative to the project ('' for the root), a newline, then the command line, e.g. \"\\nnpm run dev\" or \"web\\npnpm run dev\".",
          "additionalProperties": { "type": "string" }
        },
        "expanded": { "type": "boolean", "default": true, "description": "The project's card is unfolded in the sidebar." },
        "color": { "type": "string", "pattern": "^#[0-9a-fA-F]{6}$", "description": "The project's colour; assigned automatically when missing." }
      }
    },
    "GlobalCommand": {
      "type": "object",
      "description": "A command run in a new terminal in the project's folder, or typed into the terminal on screen.",
      "required": ["id", "name", "command"],
      "properties": {
        "id": { "type": "string", "description": "Unique among global commands. Built-in agents use claude, codex, cursor, antigravity, grok." },
        "name": { "type": "string", "description": "Shown in the menu and as the tab title." },
        "command": { "type": "string", "description": "The command line: a program name or full path, and any arguments, e.g. \"claude --resume\"." },
        "hidden": { "type": "boolean", "default": false, "description": "Kept in Settings but left out of the menu." }
      }
    },
    "Terminal": {
      "type": "object",
      "description": "A terminal: the user's shell started in `cwd`, with `command` typed into it. A command's identity is command + cwd; that is how sidebar entries, presets and aliases find their terminal.",
      "required": ["id", "title", "cwd"],
      "properties": {
        "id": { "type": "string", "description": "Unique among all terminals; also its id for `mrt` and its MRT_TERMINAL_ID." },
        "title": { "type": "string", "description": "Tab title." },
        "cwd": { "type": "string", "description": "Absolute folder the shell starts in." },
        "command": { "type": "string", "description": "Command line typed into the shell on start. Absent for a plain shell." },
        "resume": { "type": "string", "description": "Command line that was running in the terminal (typed by hand or not) when the app quit; it runs again on the next launch in place of `command`. Kept up to date by the app." },
        "last": { "type": "string", "description": "The last command line that ran in the terminal long enough to show as running (typed by hand, from the sidebar or by an agent through mrt). Kept after it stops: restarting a terminal opened without `command`, the project's play button and the next launch run it again. Kept up to date by the app." },
        "lastCwd": { "type": "string", "description": "The folder `last` started in, which can differ from `cwd` (a command line that does `cd web && ...`, or a command typed in a terminal opened for another script). Running `last` again starts there. Kept up to date by the app." }
      }
    },
    "CustomCommand": {
      "type": "object",
      "required": ["id", "name", "command"],
      "properties": {
        "id": { "type": "string" },
        "name": { "type": "string" },
        "command": { "type": "string" },
        "cwd": { "type": "string", "description": "Folder to run in: relative to the project, absolute, or starting with ~. Absent for the project root." }
      }
    },
    "Preset": {
      "type": "object",
      "required": ["id", "name", "terminals"],
      "properties": {
        "id": { "type": "string" },
        "name": { "type": "string" },
        "terminals": {
          "type": "array",
          "description": "Terminals to open. Ids only need to be unique within the preset; launching gives each a fresh id, and reuses an open terminal with the same command and cwd.",
          "items": { "$ref": "#/$defs/Terminal" }
        },
        "layout": {
          "type": ["object", "null"],
          "description": "Dockview layout referring to the ids in `terminals`; null tiles them automatically."
        }
      }
    }
  }
}
