{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://freehand.sh/docs/schemas/config.json",
  "title": "Freehand watch config",
  "description": "What `freehand watch` watches and what it does when something changes. One per person, at `~/.freehand/config.yml` (or any file named with `--config`). Each repo keeps its own `paper.yml`.",
  "type": "object",
  "properties": {
    "drive": {
      "type": "string",
      "description": "Where your synced drive is on disk, for example `~/Library/CloudStorage/GoogleDrive-<account>/My Drive`. Paths may start with `~/`. Needed for `repos`, and for any folder written from the top of the drive."
    },
    "settings": {
      "type": "string",
      "description": "The `settings.json` the freehand script reads, as a path from the top of the drive. Optional: it says where proofs, copies and records go when a repo is sent from this computer.",
      "examples": [
        "freehand/settings.json"
      ]
    },
    "notebooks": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Folders of notebooks to read when pages sync. A folder on the drive may be written from the top of the drive (Supernote/Note) instead of in full. Only the folder's own `.note` files count, not its subfolders."
    },
    "marks": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Folders of marked PDFs to read when marks sync, from the top of the drive or in full. Only the folder's own `.mark` files count."
    },
    "repos": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Repos whose `paper.yml` says `placed_by: local`. A new commit sends whatever its `paper.yml` has due, straight into the device's folders on disk. Needs `drive`."
    },
    "alive": {
      "type": "string",
      "description": "Your freehand inbox folder. While the watcher runs it keeps a small `freehand-watcher.json` there, and the freehand script leaves reading new pages to this computer. Optional.",
      "examples": [
        "freehand/inbox"
      ]
    },
    "on": {
      "type": "object",
      "description": "What to do when something arrives.",
      "properties": {
        "pages": {
          "type": "object",
          "description": "When new notebook pages have synced.",
          "properties": {
            "state": {
              "type": "string",
              "description": "The folder where every page is recorded: one small JSON file per notebook, with nothing about what the pages say. Safe to keep in your notes repo.",
              "default": "~/.freehand/pages"
            },
            "then": {
              "type": "string",
              "description": "A command to run after the pages are recorded and drawn, run by `/bin/sh`. `FREEHAND_PAGES` is the scratch folder of drawn pages waiting to be read (removed when the command ends), `FREEHAND_CHANGED` a JSON list of the notebooks that changed, and `FREEHAND_TEXT` the same in words. If it exits with anything but 0, the same pages are tried again after five minutes.",
              "examples": [
                "claude -p \"read my new pages in $FREEHAND_PAGES\""
              ]
            }
          }
        },
        "marks": {
          "type": "object",
          "description": "When new marks have synced.",
          "properties": {
            "then": {
              "type": "string",
              "description": "A command to run after the marks are read, run by `/bin/sh`. `FREEHAND_MARKS` is the scratch folder with a picture of each marked page (removed when the command ends), `FREEHAND_CHANGED` a JSON list of the changed files, and `FREEHAND_TEXT` the same in words. If it exits with anything but 0, the same marks are tried again after five minutes."
            }
          }
        }
      }
    },
    "quiet_minutes": {
      "type": "number",
      "exclusiveMinimum": 0,
      "default": 3,
      "description": "Wait this long after the newest change before reading, so a sync that is still uploading is never read half done."
    },
    "every_seconds": {
      "type": "number",
      "exclusiveMinimum": 0,
      "default": 30,
      "description": "How often to look at the folders. Freehand polls instead of waiting for file events, which sync apps lose while a laptop sleeps."
    },
    "exclude": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "File names never to read, such as a private notebook. Matched without regard to case."
    },
    "state": {
      "type": "string",
      "description": "Where this watcher remembers what it has handled.",
      "default": "~/.freehand/watch.json"
    }
  },
  "anyOf": [
    {
      "required": [
        "notebooks"
      ],
      "properties": {
        "notebooks": {
          "minItems": 1
        }
      }
    },
    {
      "required": [
        "marks"
      ],
      "properties": {
        "marks": {
          "minItems": 1
        }
      }
    },
    {
      "required": [
        "repos"
      ],
      "properties": {
        "repos": {
          "minItems": 1
        }
      }
    }
  ],
  "dependentRequired": {
    "repos": [
      "drive"
    ]
  },
  "examples": [
    {
      "drive": "~/Library/CloudStorage/GoogleDrive-you@example.com/My Drive",
      "notebooks": [
        "Supernote/Note"
      ],
      "marks": [
        "Supernote/Document/proofs"
      ],
      "repos": [
        "~/notes"
      ],
      "on": {
        "pages": {
          "state": "~/notes/freehand/pages",
          "then": "claude -p \"read my new pages in $FREEHAND_PAGES\""
        }
      }
    }
  ]
}
