# Backscroll export and context schema

## JSON

Schema version 1 is an object with `schema_version`, `channel`, `channel_id`, optional `guild_id`, `exported_at`, `count`, `partial`, `date_range`, and `messages`.

Each message includes string `id`, ISO-8601 `timestamp`, `author`, string `author_id`, `content`, `edited`, `attachments`, `embeds`, `reactions`, `reply_to`, `reply`, `pinned` and `type`. IDs must remain strings; JavaScript numbers cannot precisely represent Discord snowflakes.

`partial: false` means the exporter completed its chosen scope. Date/message limits and missing permissions can still limit what was exported. `date_range.before_exclusive` is an exclusive upper bound in epoch milliseconds.

## JSONL

One message per line. Each line includes `schema_version: 1`, `channel_id`, and the message fields. Recent exports also include `guild_id`, `citation`, `export_partial` and `export_date_range`. Older JSONL may not have coverage metadata; treat it as unknown.

The preparation helper accepts only Backscroll-shaped JSON or JSONL, not HTML, CSV or arbitrary Discord API dumps. It validates string IDs, timestamps, field types and duplicate identities before creating an output directory.

## Prepared records

`messages.jsonl` preserves message/channel IDs, timestamp, stable citation, text, reply target, and selected attachment/embed/reaction details. Authors are pseudonyms by default; author IDs and attachment/embed URLs are omitted. It does not remove every possible identifier or secret from prose.

Chunk records are fenced as JSONL. Normal entries contain `citation` and `record`. Large entries contain the same `citation`, numbered `part` and `parts`, and `record_fragment`. Concatenate all fragments for that citation to recover the normalized record JSON, or read the full record from `messages.jsonl`.

Manifest `coverage` is `partial`, `export-range-complete` or `unknown`. `message_count` counts unique messages, not fragments. `duplicate_count` counts identical repeated records. `chunk_count` counts context files. `max_chunk_chars` is a hard character limit including chunk headers, not a tokenizer measurement.
