{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://capxule.ai/schemas/state.json",
  "title": "Journey state",
  "description": "Where the human is: position, mode, goal and gap lines, chosen way, practice counters, the sayable resume line, limits.",
  "version": "2026-10-11",
  "for_humans": "https://capxule.com",
  "produced_by": [
    "get_journey_progress"
  ],
  "type": "object",
  "properties": {
    "session": {
      "type": "string"
    },
    "capsule": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "title"
      ],
      "additionalProperties": false
    },
    "position": {
      "type": "object",
      "properties": {
        "node": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "title": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "id",
                "title"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "visited": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "total": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        }
      },
      "required": [
        "node",
        "visited",
        "total"
      ],
      "additionalProperties": false
    },
    "journey": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "toc": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "children": {
                    "type": "integer",
                    "minimum": -9007199254740991,
                    "maximum": 9007199254740991
                  },
                  "module": {
                    "type": "string"
                  },
                  "sequence": {
                    "type": "boolean",
                    "const": true
                  }
                },
                "required": [
                  "id",
                  "title",
                  "children"
                ],
                "additionalProperties": false
              }
            },
            "total_stops": {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            "map": {
              "type": "object",
              "properties": {
                "root": {
                  "type": "string"
                },
                "current": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "visited_count": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "total": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "nodes": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "Opaque structural id; no title, statement or question ever rides here."
                      },
                      "parent": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      },
                      "depth": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      },
                      "visited": {
                        "type": "boolean"
                      },
                      "current": {
                        "type": "boolean"
                      },
                      "detour": {
                        "type": "boolean",
                        "description": "A per-conversation side path (drawn dashed on capxule.com)."
                      },
                      "children": {
                        "type": "integer",
                        "minimum": -9007199254740991,
                        "maximum": 9007199254740991
                      }
                    },
                    "required": [
                      "id",
                      "parent",
                      "depth",
                      "visited",
                      "current",
                      "detour",
                      "children"
                    ],
                    "additionalProperties": false
                  }
                }
              },
              "required": [
                "root",
                "current",
                "visited_count",
                "total",
                "nodes"
              ],
              "additionalProperties": false,
              "description": "The label-free shape of the journey for drawing a map: every stop as an id with its parent, depth and state. Titles exist only for the top level, in toc."
            }
          },
          "required": [
            "toc",
            "total_stops",
            "map"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "mode": {
      "type": "string",
      "enum": [
        "guided",
        "drill",
        "simulation",
        "companion"
      ]
    },
    "goal_line": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "gap_line": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "chosen_way": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "index": {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            "summary": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "chosen_at": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "index",
            "summary",
            "chosen_at"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "practice": {
      "type": "object",
      "properties": {
        "drill": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "active": {
                  "type": "boolean"
                },
                "asked": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                },
                "correct": {
                  "type": "integer",
                  "minimum": -9007199254740991,
                  "maximum": 9007199254740991
                }
              },
              "required": [
                "active",
                "asked",
                "correct"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "simulation": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "active": {
                  "type": "boolean"
                },
                "scenario": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "active",
                "scenario"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "drill",
        "simulation"
      ],
      "additionalProperties": false
    },
    "check_in_count": {
      "anyOf": [
        {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        {
          "type": "null"
        }
      ]
    },
    "resume_line": {
      "type": "string",
      "description": "Sayable in the human's locale."
    },
    "remaining": {
      "type": "object",
      "properties": {
        "stops": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "percent_done": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "topics": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "visited": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              "total": {
                "type": "integer",
                "minimum": -9007199254740991,
                "maximum": 9007199254740991
              },
              "done": {
                "type": "boolean"
              }
            },
            "required": [
              "id",
              "title",
              "visited",
              "total",
              "done"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "stops",
        "percent_done",
        "topics"
      ],
      "additionalProperties": false,
      "description": "What is left overall and per top-level topic: answers how much more, how big, what remains."
    },
    "nudge": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "description": "Prep journeys: a sayable count line when points from earlier are still open; null otherwise."
    },
    "limits": {
      "type": "object",
      "properties": {
        "turns_remaining": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ],
          "description": "The binding allowance; null when only the per-journey budget applies."
        },
        "capsule_budget": {
          "anyOf": [
            {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            {
              "type": "null"
            }
          ],
          "description": "Lifetime budget on this journey for this principal (turns per stop x stops)."
        },
        "opens_remaining_today": {
          "type": "integer",
          "minimum": -9007199254740991,
          "maximum": 9007199254740991
        },
        "wall": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "code": {
                  "type": "string",
                  "enum": [
                    "trial_exhausted",
                    "premium_required",
                    "budget_exhausted",
                    "tokens_exhausted",
                    "rate_limited",
                    "stepped_down"
                  ]
                },
                "for_human": {
                  "anyOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "null"
                    }
                  ],
                  "description": "Say it as given."
                },
                "next": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {},
                  "description": "inform_url {url} (share the link; alt may name plan_upgrade on brokering hosts) | pay (machine principals) | wait {retry_after_ms}"
                }
              },
              "required": [
                "code",
                "for_human",
                "next"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ],
          "description": "UPCOMING wall, for warning the user in advance: the one this principal will meet once its binding allowance runs out. It is present on every healthy beat and is NOT a refusal. Whether THIS call was walled is beat.wall (null when the turn went through)."
        },
        "reset_at": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "ISO 8601 with offset."
        },
        "rate": {
          "type": "object",
          "properties": {
            "remaining": {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            },
            "reset_at": {
              "type": "string"
            }
          },
          "required": [
            "remaining",
            "reset_at"
          ],
          "additionalProperties": false
        },
        "pass": {
          "description": "Machine principals only: the live pass.",
          "type": "object",
          "properties": {
            "expires_at": {
              "type": "string"
            },
            "turns_remaining": {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            }
          },
          "required": [
            "expires_at",
            "turns_remaining"
          ],
          "additionalProperties": false
        },
        "allowance_used_pct": {
          "description": "Bound accounts on a capped monthly allowance: percent used. Absent when uncapped. At 100 the tokens_exhausted wall applies.",
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        }
      },
      "required": [
        "turns_remaining",
        "capsule_budget",
        "opens_remaining_today",
        "wall",
        "reset_at"
      ],
      "additionalProperties": false
    },
    "content_is_data": {
      "type": "boolean",
      "const": true
    },
    "ttl_ms": {
      "type": "number",
      "const": 60000
    }
  },
  "required": [
    "session",
    "capsule",
    "position",
    "journey",
    "mode",
    "goal_line",
    "gap_line",
    "chosen_way",
    "practice",
    "check_in_count",
    "resume_line",
    "remaining",
    "nudge",
    "limits",
    "content_is_data",
    "ttl_ms"
  ],
  "additionalProperties": false
}
