{
  "id": "com.lattice.habits",
  "name": "Habits",
  "icon": "✓",
  "color": "#087f5b",
  "description": "Track scheduled habits, completions and streaks.",
  "requested_permissions": {
    "storage": [
      "sql"
    ],
    "network": {
      "allowlist": []
    },
    "events": {
      "habit-checked": {
        "description": "An eligible habit date was completed for the first time.",
        "schema": {
          "type": "object",
          "properties": {
            "habit_id": {
              "type": "string",
              "description": "Habit UUID.",
              "minLength": 1
            },
            "title": {
              "type": "string",
              "description": "Habit title."
            },
            "date": {
              "type": "string",
              "description": "Local check date, YYYY-MM-DD.",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "streak": {
              "type": "integer",
              "description": "Consecutive completed scheduled days or Monday–Sunday weeks through date, in streak_unit.",
              "minimum": 0
            },
            "streak_unit": {
              "type": "string",
              "description": "Unit for streak and milestone counts.",
              "enum": [
                "scheduled-days",
                "weeks"
              ]
            },
            "checked_at": {
              "type": "string",
              "description": "Completion time, UTC ISO 8601 timestamp.",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$"
            }
          },
          "required": [
            "habit_id",
            "title",
            "date",
            "streak",
            "streak_unit",
            "checked_at"
          ],
          "additionalProperties": false
        }
      },
      "habit-missed": {
        "description": "A closed scheduled period missed its completion target.",
        "schema": {
          "type": "object",
          "properties": {
            "habit_id": {
              "type": "string",
              "description": "Habit UUID.",
              "minLength": 1
            },
            "title": {
              "type": "string",
              "description": "Habit title."
            },
            "date": {
              "type": "string",
              "description": "Inclusive period end, local YYYY-MM-DD.",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "period_start": {
              "type": "string",
              "description": "First eligible local date in assessed period, YYYY-MM-DD.",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "target": {
              "type": "integer",
              "description": "Required checked dates; partial weeks cap the target at eligible days.",
              "minimum": 1,
              "maximum": 7
            },
            "completed": {
              "type": "integer",
              "description": "Distinct checked dates in the closed period.",
              "minimum": 0,
              "maximum": 7
            }
          },
          "required": [
            "habit_id",
            "title",
            "date",
            "period_start",
            "target",
            "completed"
          ],
          "additionalProperties": false
        }
      },
      "streak-milestone": {
        "description": "A check reached a new streak milestone.",
        "schema": {
          "type": "object",
          "properties": {
            "habit_id": {
              "type": "string",
              "description": "Habit UUID.",
              "minLength": 1
            },
            "title": {
              "type": "string",
              "description": "Habit title."
            },
            "date": {
              "type": "string",
              "description": "Local check date, YYYY-MM-DD.",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            },
            "streak": {
              "type": "integer",
              "description": "Consecutive completed scheduled days or Monday–Sunday weeks through date, in streak_unit.",
              "minimum": 0
            },
            "streak_unit": {
              "type": "string",
              "description": "Unit for streak and milestone counts.",
              "enum": [
                "scheduled-days",
                "weeks"
              ]
            },
            "checked_at": {
              "type": "string",
              "description": "Completion time, UTC ISO 8601 timestamp.",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$"
            },
            "milestone": {
              "type": "integer",
              "description": "Reached streak length, in streak_unit.",
              "enum": [
                7,
                14,
                30,
                60,
                100,
                365
              ]
            }
          },
          "required": [
            "habit_id",
            "title",
            "date",
            "streak",
            "streak_unit",
            "checked_at",
            "milestone"
          ],
          "additionalProperties": false
        }
      }
    },
    "listeners": {
      "check-habit": {
        "description": "Complete a habit on an eligible past or current date; duplicate checks are ignored.",
        "schema": {
          "type": "object",
          "properties": {
            "habit_id": {
              "type": "string",
              "description": "Exact habit UUID; takes precedence over title; supply either.",
              "minLength": 1
            },
            "title": {
              "type": "string",
              "description": "Unique case-insensitive habit title; used when habit_id is omitted.",
              "minLength": 1
            },
            "date": {
              "type": "string",
              "description": "Local YYYY-MM-DD; omitted defaults to local today; must be eligible, nonfuture date.",
              "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
            }
          },
          "required": [],
          "additionalProperties": false,
          "anyOf": [
            {
              "required": [
                "habit_id"
              ]
            },
            {
              "required": [
                "title"
              ]
            }
          ]
        }
      }
    }
  },
  "source": {
    "assets": [
      "index.html",
      "app.js",
      "app.css",
      "ui.css",
      "emits.js",
      "listens.js"
    ]
  }
}