# History

Most services report what's true now and forget the rest. Parcel lists the deliveries on the way and a short list of recent ones, so a page that reads it can't say how long deliveries took last quarter. Other services report a reading only as it is now.

History keeps what you choose from those answers, on this Mac. The source that fetches from the service gets a `collect`, which says which items to keep, which of their fields, under what key and for how long. Any page it names as a reader can then add a `dataset` source, which answers with the kept rows for the period showing.

`sample` keeps a reading of every item at a set interval, such as each monitor's state every 5 minutes, and a page for one item reads its own. An agent or a script can add rows too, for data that reaches the Mac some other way.

The rows stay on this Mac and don't sync. **Settings → History** shows each history, exports it and deletes it.

## Start here

- [Collect and samples](https://legatobar.com/docs/history-collect.md): What `collect` and `sample` keep, with every setting, and when a page needs neither.
- [Reading history](https://legatobar.com/docs/history-reading.md): The source a reader page uses and the answer it gets.
- [Parcel example](https://legatobar.com/docs/history-parcel.md): Two complete pages, one that keeps deliveries and one that reports how long they took.

## What a history holds

- [Dates and retention](https://legatobar.com/docs/history-dates.md): Which date a row counts under, and how long rows stay.
- [Accounts and readers](https://legatobar.com/docs/history-accounts.md): Whose data a history holds, which pages may read it, and what happens when its page goes away.
- [Coverage and local storage](https://legatobar.com/docs/history-coverage.md): The dates a history has rows for, the gaps in it, and where the data is kept.
- [Rows from outside](https://legatobar.com/docs/history-rows.md): Rows added by an agent or a script.


---

# Collect and samples

Some services only tell you what's happening now. Parcel lists the deliveries on the way and a short list of recent ones, then forgets them, so a page that reads it can't say how long deliveries took last quarter. History fixes that: a page keeps the rows it chooses from each answer, on this Mac, and other pages you allow read them later, with a period row like any other page.

- **One page collects.** A source with `collect` keeps chosen fields of chosen items, as rows in a named history (a dataset), each time it fetches.
- **Other pages read.** A source with `{ "dataset": "name" }` answers with the rows kept, filtered to the page's period, and cards use the usual [rules](https://legatobar.com/docs/mapping.md#mapping) on them.
- **Or samples over time.** With `sample`, a page keeps one row per item per interval, such as each monitor's state every 5 minutes, and a page for each item reads its own with `key`. See [Samples](https://legatobar.com/docs/history-collect.md#samples).
- **Nothing leaves the Mac.** The rows are in Legato's folder on this Mac, they don't sync between Macs, and **Settings → History** shows, exports and deletes them.
- **Rows can also come from outside,** from an agent or a script, with `legato rows add` or the MCP tool `add_rows`.

## When you don't need it

Many services keep their own history and answer for a range of dates. Ask them for the period showing, with `{period.start}` and `{period.end}` in the request (see [Periods](https://legatobar.com/docs/periods.md#periods)), and the page works from the first fetch, with nothing kept on the Mac:

- **Tesla, through Tessie:** the charges request takes `from` and `to`, so a charging page asks for the period's sessions.
- **Lunch Money:** `balance_history` gives monthly balances for a range of months. History is only worth it for daily points.
- **GitHub:** a repository's pull requests carry `created_at` and `merged_at`, so open-to-merge times come from the list itself.
- **Pi-hole:** its long-term database answers for a range of days, 91 by default. Keep a history only to look further back than that.

Use History for services that forget: Parcel's deliveries, readings a service only reports as they are now, or rows an agent supplies. For a single number over time on one sparkline, a [history rule](https://legatobar.com/docs/mapping-sparklines.md#sparkline-readings) is simpler: it shows the newest configured readings (up to 60) for that card, with no `collect` and no readers. Its readings are listed in [Settings → History](https://legatobar.com/docs/history-coverage.md#settings-history) too.

## Collect on the page that fetches

Add `collect` to the source whose answer has the items. This is the Packages page's Parcel source; the complete page is in the [Parcel example](https://legatobar.com/docs/history-parcel.md#a-complete-example-parcel).

```json
"parcel": {
  "url": "https://api.parcel.app", "secret": "parcel", "auth": { "type": "header", "name": "api-key" },
  "every": "30m",
  "requests": { "active": "/external/deliveries/?filter_mode=active",
                "recent": "/external/deliveries/?filter_mode=recent" },
  "collect": {
    "dataset": "parcel-deliveries",
    "each": ["active.deliveries", "recent.deliveries"],
    "key": "{carrier_code}:{tracking_number}",
    "fields": ["carrier_code", "tracking_number", "description", "status_code",
               "events[].date", "events[].event", "events[].location"],
    "remove_after": { "events[].event": { "markers": ["Received By:", "Delivered:"],
                                          "keep_exact": ["Signature Not Req", "Signature Required"] } },
    "date": { "date": { "first": "date", "of": "events", "where": { "path": "event", "contains": "Delivered" },
                        "sort": { "by": "date", "order": "desc", "as": "date" } } },
    "keep": { "for": "400d" },
    "readers": ["delivery-times"]
  }
}
```

Each time the source answers, Legato takes the items at `each`, keeps only `fields` of each, removes text after the `remove_after` markers, works out the row's `date`, and stores the row under its `key`. A row whose key comes again replaces the one kept. The cards on the page use the answer as they always do: collecting changes nothing they show and adds no request. A source with `collect` that no card uses is fetched all the same, on its `every`. A fetch that fails keeps nothing, including an answer the source's [`fail`](https://legatobar.com/docs/source-polling.md#when-the-answer-reports-an-error) turns down; adding `fail` to a source that collects keeps its history as it is.

**Records and measurements are kept differently.** A record history keeps the latest complete record for each key; it does not append a new version on every poll. A delivery uses its tracking identifier, so a later answer updates that delivery. For measurements over time, each monitor's state or each host's load, add `sample` and History keeps one row per item per interval, timed by Legato's own clock: see [Samples](https://legatobar.com/docs/history-collect.md#samples).

A sparkline's `history` rule is simpler: one number per card over time, with its own `every` and `keep` settings. Its readings are kept in the same database and listed in Settings → History by page, where you can export or delete them, but they aren't a dataset: there's no `collect`, no key and no readers. See [Sparkline readings](https://legatobar.com/docs/mapping-sparklines.md#sparkline-readings).


| `collect` field | Required? | Meaning |
| --- | --- | --- |
| `dataset` | yes | The history's name, which readers use: 1–64 lowercase letters, digits and `-`, starting with a letter or digit, like `parcel-deliveries`. |
| `each` | yes | A [path](https://legatobar.com/docs/mapping.md#mapping) to the list of items to keep, or a list of 2 to 4 paths read in order. When a key comes up more than once in one answer, the item where it first appears is kept. |
| `key` | yes | A template of the item's own fields that names it, the same next time: `{carrier_code}:{tracking_number}`. Up to 256 characters, with at least one `{…}`. Each field it uses must be text; an item whose key is missing, blank, longer than 256 characters or made from a number isn't kept, and is counted as rejected. |
| `fields` | yes | The only fields kept of each item: 1 to 64 different paths. Write `[]` after a list for every item of it: `events[].date`. Everything else in the answer is left out before anything is stored. |
| `keep` | yes | `{ "for": "400d", "clock": … }`: how long a row is kept, `1d` to `9999d`, and what its age counts from. See [How long rows are kept](https://legatobar.com/docs/history-dates.md#how-long-rows-are-kept). |
| `remove_after` | no | For 1 to 16 kept fields, text removed after a marker before the row is stored. See [Removing text](https://legatobar.com/docs/history-collect.md#removing-text). |
| `date` | no | A [rule](https://legatobar.com/docs/mapping.md#mapping), read on the row as it's kept, giving the row's date. See [Dates](https://legatobar.com/docs/history-dates.md#dates). |
| `time_zone` | no | The zone the service's times without one are in, like `America/Los_Angeles`. Needs `date`. |
| `date_range` | no | `{ "from", "to" }`: the dates kept as dates. Needs `date`. |
| `readers` | no | Up to 32 ids of other pages that may read the history. See [Readers](https://legatobar.com/docs/history-accounts.md#readers-and-grants). |
| `accepts_rows` | no | `true` lets `legato rows add` and `add_rows` add rows. `false` by default. |
| `account` | no | A template from the answer saying whose data it is, like `{account.id}`. When its value changes, a new history starts. See [Accounts](https://legatobar.com/docs/history-accounts.md#accounts-and-histories). |

- **Keep complete records.** A row is replaced whole, so an item must carry everything you want kept each time. Parcel sends every event of a delivery each time, which suits it. A service that sends only the newest events of a record would replace the older ones.
- **Keep only what a reader needs.** `fields` is the promise of what's stored: a page with `fields` of three names keeps three names, whatever else the service sends.
- **One source per history.** A page can collect several histories from different sources, but two sources on one page can't collect the same `dataset`.
- **What can collect:** an `http` source, or a source of `collect` alone that only [receives rows](https://legatobar.com/docs/history-rows.md#rows-from-outside-legato). Not a `calendar`, `reminders` or `dataset` source.
- **What can't:** a source that uses `{period.…}` or `{compare.…}`, since one history can't change with the period row; and any source on a page with [params](https://legatobar.com/docs/detail-pages.md#one-page-for-every-item), or `{param.…}` anywhere in `collect`. Collect on the page that lists every item, and let the page with params read the history.

Legato checks `collect` with the rest of the page, whether or not a card uses the source. A mistake stops the page loading, with a message after the file's name (`packages.json: sources.parcel.collect: …`) such as:

| Message | Cause |
| --- | --- |
| `sources.parcel.collect: key is a template of the item's fields, like {carrier_code}:{tracking_number}, of up to 256 characters` | `key` has no `{…}`, or is too long |
| `sources.parcel.collect: fields lists 1 to 64 different fields to keep` | `fields` is empty, too long, or names a field twice |
| `sources.parcel.collect: keep is { "for": days like 400d, "clock": date, last_seen or date_or_last_seen }` | `keep` is missing or wrong |
| `sources.parcel.collect: time_zone reads the date rule's times, so it needs a date` | `time_zone` without `date` |
| `sources.parcel.collect: date_range bounds the date rule's dates, so it needs a date` | `date_range` without `date` |
| `sources.parcel.collect: collect has no setting "readres" (it takes accepts_rows, account, dataset, date, date_range, each, fields, keep, key, readers, remove_after, time_zone)` | A misspelled setting |
| `sources.archive and sources.parcel both collect parcel-deliveries; a page keeps a dataset from one source` | Two sources, one history (named in alphabetical order) |
| `sources.parcel: a source that collects can't use {period.…}` | A collecting source follows the period row (`{period.…}` or `{compare.…}`) |
| `sources.parcel: a page with params can't collect; collect on the page that lists every item, and read its dataset here` | `collect` on a page with `params` |
| `sources.daily: only an http source can collect` | `collect` on a calendar or reminders source |
| `sources.daily: a source that only receives rows has collect and nothing else` | A source with no `url` that has more than `collect` |
| `sources.daily: with no url to fetch, collect needs "accepts_rows": true` | A source of `collect` alone without `accepts_rows` |

### Removing text

Carriers put names in delivery events: "Delivered. Received By: Pat Example". `remove_after` keeps the first marker in the field and replaces everything after it with ` [removed]`, before the row is stored:

```json
"remove_after": { "events[].event": { "markers": ["Received By:", "Delivered:"],
                                      "keep_exact": ["Signature Not Req", "Signature Required"] } }
```

| Kept as | From |
| --- | --- |
| Delivered. Received By: [removed] | Delivered. Received By: Pat Example |
| Delivered: [removed] | Delivered: P.EXAMPLE |
| Delivered: Signature Not Req | Delivered: Signature Not Req |
| Delivered, Front Door/Porch | Delivered, Front Door/Porch (no marker) |

- A marker is literal text, and case matters. 1 to 16 markers, each 1–64 characters, for each of up to 16 fields.
- When several markers are in the text, the one that comes first is kept.
- `keep_exact` lists up to 32 phrases (1–64 characters each) that may follow a marker and stay, matched whole once the spaces around them are trimmed. "Delivered: Signature Not Req, P. Example" becomes "Delivered: [removed]".
- Nothing after the marker, or only spaces, leaves the text as it is.
- It applies to text fields only, and it runs on rows added from outside too.

This removes text at a marker you name. It isn't anonymization: a name the service puts somewhere else stays, so read a few answers in **Preview Source…** before choosing the markers.

## Samples

Some services only say how things are now: a monitor is up and answered in 41 ms, a host is at 12% CPU, a container is running. With `sample`, the page that lists them keeps one row per item per interval, so a page for each item can show its last day, or its last quarter, from what the overview fetched.

```json
"kuma": {
  "url": "https://status.example.com/metrics", "every": "1m",
  "collect": {
    "dataset": "kuma-samples", "each": "monitors", "key": "{monitor_id}",
    "sample": { "every": "5m" },
    "fields": { "state": { "path": "monitor_status", "values": { "1": "ok", "0": "critical", "3": "off" }, "default": "unknown" },
                "ms": "monitor_response_time" },
    "readers": ["uptime-monitor"]
  }
}
```

- **One row per item per interval.** `sample.every` is the interval: minutes that divide an hour, `1m` to `1h` (`1m`, `2m`, `3m`, `4m`, `5m`, `6m`, `10m`, `12m`, `15m`, `20m`, `30m`, `60m` or `1h`), `5m` by default. It's apart from the source's own `every`, and can't be shorter than it: with a `5m` source and `1m` samples, four intervals in five would be empty.
- **Timed by Legato's clock.** Intervals start on the clock: at 14:06 with `5m`, the sample is the 14:05 one. A later answer in the same interval replaces that interval's row, whole, so each holds the last answer in it. A one-minute outage between two answers in the same interval isn't kept; sample more often to catch shorter ones.
- **`fields` are rules.** An object of 1 to 16 names (lowercase letters, digits and `_`) and the [rules](https://legatobar.com/docs/mapping.md#mapping) that fill them from the item; a list of such names keeps those fields as they are. What's stored is each rule's result: text of up to 256 characters, a number, or true or false. Anything else, or nothing, leaves the name out of that sample. A sample is at most 512 bytes of JSON.
- **What a sample's rules can't use:** `{param.…}`, `{period.…}`, `{ "answer": … }`, `lookup`, `match` or `in_list`. A kept value has to mean the same thing later, whichever link opened the page, whatever period shows and whatever Settings → Lists holds.
- **Kept a year.** `keep` is optional: a sample is kept 365 days unless `"keep": { "for": "90d" }` says otherwise. Its age is its own time, so there's no `clock`.
- **Not with** `remove_after`, `date`, `time_zone`, `date_range` or `accepts_rows`: a sample's time is Legato's, its values are rule results, and nothing adds samples from outside.
- `key`, `each`, `account` and `readers` are as for records. An item whose key is missing, blank or a number isn't kept, and is counted as rejected. A service that numbers its items, as Proxmox numbers guests, gets a text id in `derive`: give the list a field `"id": { "template": "{vmid|raw}" }`, collect from that list, and key by `{id}`.

### Reading one item

A page for every item reads its own samples with `key`, which its link fills:

```json
"sources": { "samples": { "dataset": "kuma-samples", "key": "{param.id}" } }
```

- **`key` is compared as text on both sides.** Kept keys are always text, and `key` is the text the link filled in, so `"7"` reads the item kept as `7`, and `"07"` doesn't. It works on a record history too, for that one row.
- **Without a period row, the last 24 hours.** More exactly, the last 24 hours of intervals with the one in progress last: at 14:06 with `5m`, from 14:10 yesterday to 14:10 today. "Now" is the end of the interval in progress, at most one interval ahead of the clock. The page reads again at each interval's end, even when nothing new has been kept, so a quiet hour shows as one.
- **With a [period](https://legatobar.com/docs/periods.md#periods), the period's.** From the start of its first day to midnight after its last, in the Mac's time zone, up to the interval in progress when it includes today. A [strip](https://legatobar.com/docs/card-time.md#strip) follows the period row; it isn't one of the cards that always read the default choice.
- **Without `key`,** a read takes every item's samples, up to 100,000 of them; more says "This period holds more samples than a page reads at once; read one item with key". Thirty items over 24 hours are 8,640.
- `row` is for records: a sample is small already.

The answer:

```json
{ "kept": {
    "rows": [ { "key": "git", "at": "2026-11-08T14:05:00Z", "row": { "state": "ok", "ms": 41 } } ],
    "selected_count": 288, "total_count": 105120, "undated_count": 0,
    "span": { "from": "2026-11-07T14:10:00Z", "until": "2026-11-08T14:10:00Z" },
    "sample": { "every": "5m", "seconds": 300 },
    "epoch": { … }, "coverage": { "recording_since": …, "last_success": …, "interruptions": [ … ] } } }
```

| Field | Meaning |
| --- | --- |
| `rows` | The samples in the span, oldest first: each with its item's `key`, `at` (the start of its interval, ISO 8601 in UTC) and `row` (its fields). |
| `selected_count`, `total_count` | How many `rows` has, and how many the item (or, without `key`, the history) keeps in all. |
| `span` | The span read, `from` and `until`, for [`by_time`](https://legatobar.com/docs/mapping-expiry.md#slices-of-time). |
| `sample` | The interval, as written and in seconds. |
| `epoch`, `coverage` | As for records. An interval with no sample is a time nothing was kept: the Mac asleep, the service not answering. |

The strip and a response-time sparkline on one item's page:

```json
{ "id": "history", "type": "strip", "label": "Last 24 hours", "start_label": "24 hours ago", "end_label": "Now", "segments": [],
  "source": { "ref": "samples", "map": {
    "segments": { "each": "kept.rows", "by_time": { "at": "at", "span": "kept.span" },
                  "fields": { "state": { "worst": "row.state", "of": "rows" }, "label": { "template": "{from|time}" } } } } } },
{ "id": "ms", "type": "sparkline", "label": "Response time", "unit": "ms", "points": [],
  "source": { "ref": "samples", "map": {
    "points": { "each": "kept.rows", "by_time": { "at": "at", "span": "kept.span" }, "value": { "path": "row.ms", "round": 0 } } } } }
```

`by_time` cuts the span into 144 slices unless `buckets` says, and `worst` gives each slice its worst state; see [Slices of time](https://legatobar.com/docs/mapping-expiry.md#slices-of-time).

### What changes, and what pauses

- **A rule changing** keeps old samples as they were measured, and new ones follow the new rule. A change of `sample.every` starts at the next interval; old samples keep their spacing.
- **A name taken out of `fields`** leaves every read, export and `rows list` at once, then is removed from the samples on disk in the background, a batch at a time, which carries on after Legato restarts. Collecting doesn't wait. A name put back shows new values only; old ones stay gone.
- **A changed key** pauses with "Paused: the page now keys its samples differently", and the choice is **Start new history**: a sample keeps its fields' results, not the item, so there's nothing to re-key from.
- **A history keeps its kind.** A page that collects a history of records as samples, or one of samples as records, keeps nothing and Settings says so. Delete the history to start one of the other kind, collect under another name, or change the page back.
- A changed secret, a new `account` and a missing page behave as for records.

### Limits for samples

Samples have their own limits, apart from records', so a history of samples never stops Parcel's deliveries from being kept:

| | Limit |
| --- | --- |
| One sample | 512 bytes of JSON |
| One answer | 2,000 items |
| One history of samples | 10,000 items, and 200 MB |
| Every history of samples together | 400 MB |
| A read without `key` | 100,000 samples |

- **At a limit, a history makes room in itself:** its oldest day of samples goes, across all its items, then the next, until it fits, counted as pruned for space. It never takes room from another history, and never the interval being written. Only when a history has nothing older to give does its batch wait, and Settings says History storage is full, as for records.
- A new item past 10,000 isn't kept and is counted as rejected; it never pushes another out.
- Thirty items every 5 minutes for a year are about 3.15 million samples: about 80 MB of row data, and more on disk with the database's indexes.



---

# Reading history

## Read the history on another page

A reader page names the history in a source of its own:

```json
"sources": { "kept": { "dataset": "parcel-deliveries" } }
```

It takes `derive`, as an http source does, and its cards use `ref`, `map`, `empty` and `when` as usual. There's no `every`: the source is refreshed when the history changes, without asking the service. A quiet page scan does not trigger a new read. The previously shown value stays visible while its replacement is prepared. The answer:

```json
{ "kept": {
    "rows": [
      { "key": "ups:EX10000001", "date": "2026-11-04", "date_kind": "wall", "time": "14:12:00",
        "first_seen": "2026-11-01T09:30:00Z", "last_seen": "2026-11-05T09:30:00Z",
        "row": { "carrier_code": "ups", "tracking_number": "EX10000001", "description": "Desk lamp",
                 "status_code": 0, "events": [ … ] } } ],
    "selected_count": 18, "total_count": 120, "undated_count": 3,
    "epoch": { "number": 1, "started": "2026-08-14T16:02:11Z", "label": "parcel · api.parcel.app" },
    "coverage": { "recording_since": "2026-08-14T16:02:11Z", "last_success": "2026-11-07T15:30:02Z",
                  "earliest_row_date": "2026-06-02",
                  "interruptions": [ { "from": "2026-09-20T22:00:04Z", "to": "2026-09-23T07:41:55Z" } ],
                  "imported": [ { "at": "2026-08-14T16:10:40Z", "rows": 32, "earliest": "2026-06-02" } ],
                  "imports_omitted": 0 } } }
```

| Field | Meaning |
| --- | --- |
| `rows` | The rows of the current history, in date order with undated rows last. On a page with a [period](https://legatobar.com/docs/periods.md#periods), only those dated in it. |
| `rows[].key` | The row's key. |
| `rows[].date`, `date_kind` | The row's date and its kind, `day`, `wall` or `moment` (see [Dates](https://legatobar.com/docs/history-dates.md#dates)). Undated rows have neither. |
| `rows[].time` | A `wall` date's printed time, `14:12:00`. Only on `wall` dates. |
| `rows[].first_seen`, `last_seen` | When Legato first kept the row, and when it last saw it in an answer (or had it added). |
| `rows[].row` | The item as kept: its `fields`, after `remove_after`. A field is at `row.carrier_code`, not `carrier_code`. |
| `selected_count` | How many rows `rows` has. |
| `total_count`, `undated_count` | All the rows in the current history, whatever the period, and how many of them are undated. |
| `epoch` | The current history: its `number`, when it `started`, and its `label`. |
| `coverage` | What the history covers. See [Coverage](https://legatobar.com/docs/history-coverage.md#coverage). |

Times Legato recorded (`first_seen`, `started`, `recording_since` and the rest) are ISO 8601 in UTC; the [`ago` and `day` filters](https://legatobar.com/docs/mapping.md#mapping) show them in the Mac's time.

- **The period filters the rows, not the collecting.** Picking 365 days on the reader reads more of what's kept; it doesn't change what the owner keeps. Status, gauge and fleet cards read the default choice, as with any source.
- **Every row in the period is read.** Counts, sums and averages cover all of them. A card's `limit` only shortens what it shows, and the 500-row limit of `rows list` doesn't apply to pages.
- **Undated rows come only without a period.** A reader page with no period row gets every row of the current history, undated ones included.
- **Only readers read.** A page that isn't the owner or a reader gets "This page can't read the history parcel-deliveries; the page that keeps it lists its readers" on its cards. A history nothing keeps yet gives "No page keeps the history parcel-deliveries on this Mac".
- **A reader is a page with a card on the dataset source.** Being listed in `readers`, or granted in Settings, lets a page read; it reads once a card uses the source.
- A page with [params](https://legatobar.com/docs/detail-pages.md#one-page-for-every-item) can read a history.

Cards on a dataset source can also say:

| Message | Cause |
| --- | --- |
| History is updating; trying again | The history or the page's rules changed while it was being read, often just after a page is saved. The card keeps its answer and tries again in 2 seconds. |
| History couldn't open: … | Legato couldn't open its history database, for example on a full disk. Settings → History shows the same reason. |
| Can't read history | Any other failure to read. |

### Only what the page needs: `row`

A history of large rows (a delivery with a hundred events) is slow to read whole: every card waits while Legato reads every event of every row in the period. When a page needs only a few values from each row, it says which, with `row`:

```json
"sources": { "kept": {
  "dataset": "parcel-deliveries",
  "row": {
    "carrier": "row.carrier_code",
    "description": "row.description",
    "days": { "days_between": [
      { "date": { "first": "date", "of": "row.events", "where": { "path": "event", "contains": "Picked up" },
                  "sort": { "by": "date", "as": "date" } } },
      "date" ] } },
  "derive": [ { "name": "mean", "value": { "avg": "row.days", "of": "kept.rows", "round": 1 } } ] } }
```

- **Each name is a rule read on the kept row,** as a rule on `kept.rows` would read it: `row.…` for the item as kept, and `key`, `date`, `date_kind` and `time`. Each row's `row` in the answer then holds only those values: `row.carrier`, `row.description`, `row.days`.
- **Nothing else changes.** Every row in the period is still read, so counts, sums, averages, groups and lists are what they'd be without `row`. `key`, `date`, `first_seen`, `last_seen`, the counts, `epoch` and `coverage` are as before.
- **Why it's fast:** a row's values depend on nothing but the row, so Legato keeps them on this Mac beside it and reads them instead of the whole row. They're made again when the row changes, when the page's `row` changes, and after an update of Legato or a change of the Mac's time zone, language, region, calendar or 12/24-hour setting. Each read makes values in the settings it started with, whatever changes while it runs. Until then a read makes the missing ones itself, so a page's first read after one of those is as slow as without `row`, once.
- **What a row rule can't use.** Each is an error on the cards that use the source (`delivery-times.json: cards/…/source.row.days: …`); the page itself loads, except for `{param.…}`, which stops it:
  - `first_seen` and `last_seen`, which change on every fetch: read them in `derive`, beside `row`;
  - `{ "answer": … }` and `lookup`, which read outside the row;
  - `{param.…}` and `{period.…}`: filter by them in `where` or `derive`;
  - templates, anywhere in a rule (`template`, and templates in `values` or `default`): a missing value reads as "—" on a stat or facts card and as a dash inside other text, which a kept value can't know. Name the template's inputs in `row` and write the template in `derive` or the card's `map`; it then reads exactly as it did over whole rows;
  - `match`, whose search runs under a time limit: a value kept after a timeout would stay wrong;
  - `in_list`, which reads a [list](https://legatobar.com/docs/lists.md#lists) from Settings → Lists: the list can change there, which a kept value can't know. Test it in `derive`.
- **Up to 16 names.** `row` is worked out before `derive`, so it can't read derived values; `derive` and the cards read `row`'s.
- **Limits of the kept values, never of the history:** up to 4 different `row`s for a history; a row's values up to 1 KB; 32 MB of values for one history and 128 MB for all of them. Over a limit, the values of the `row` read longest ago go first, and what still doesn't fit is made on each read, still complete. Kept values never take space from History's own limits, and when History storage is full they're all removed first.
- **In the background,** Legato makes missing values in small batches, and gives way to a page that's reading. A value it hasn't made yet is worked out from the whole row when a page reads it, so the answer is always complete.
- **They aren't history.** Export and `rows list` show rows as kept; deleting a row or a history deletes its values, a new history (another account) starts without any, and values no page uses any more are removed. Removal overwrites them on disk as History's other deletions do.

**Details** shows "Keeps history on this Mac (parcel-deliveries)" on the source that collects and "Reads the history parcel-deliveries, kept on this Mac" on a reader's. A collecting source no card uses is listed as a source of its own, with no cards.



---

# Dates and retention

## Dates

`date` makes a history readable by period. It's a rule, read on the row as it's kept, so it can use only what `fields` keeps (after `remove_after`). Its value becomes the row's `date`. A plain path works (`"date": "date"`), and so does any rule that gives a date, such as the newest Delivered event's date in the [Parcel source](https://legatobar.com/docs/history-collect.md#collect-on-the-page-that-fetches).

A date is one of three kinds:

| Kind | Written like | Kept as | In a period |
| --- | --- | --- | --- |
| `day` | `2026-10-26`, "November 6, 2026", `02.11.2026`, `11/02/2026` | The date | When it's one of the period's days |
| `wall`, a time with no zone | `2026-11-06 10:05:00`, "Friday, November 6, 2026 10:05 AM" | The printed date and time, as printed | By its printed date, as a `day` |
| `moment`, an instant | `2026-11-06T16:46:00-08:00`, `…Z`, "November 2, 2026 03:14 PM EST", Unix seconds | The instant, in UTC | From midnight at the start of the period's first day to midnight after its last, in the Mac's time zone |

- **A wall time is never moved to the Mac's zone.** "November 6, 2026 4:46 PM" is in the 6th whichever Mac reads it, wherever it is. Parcel's dates are wall times.
- **Carriers' own words are read with fixed rules,** not the Mac's language settings: a date with slashes is month first (`11/02/2026` is November 2) and one with dots is day first (`02.11.2026` is November 2). Times like "3:14pm" and "3:14 p.m." are read as "3:14 PM".
- **A number is Unix time:** seconds, or milliseconds from 100,000,000,000 up. Digits in text aren't read as one.
- **A date that can't be read** (words like "next Tuesday", or text over 80 characters) leaves the row undated. So does an item where the rule finds nothing.

### `time_zone`

When the service's times have no zone but you know which zone they're in, say so, and they're kept as moments:

```json
"date": "reading_time", "time_zone": "America/Los_Angeles"
```

- A time the clocks pass twice when they go back (1:30 AM on the night daylight saving time ends) is the first one.
- A time the clocks skip when they go forward (2:30 AM on the night it starts) moves forward by the gap: 2:30 becomes 3:30.
- `time_zone` is a zone name from the IANA list. An unknown one stops the page loading: `time_zone is a zone name like America/Los_Angeles`.

### `date_range`

A service that sends placeholder dates, like `1970-01-01` or a year far ahead, can put rows in the wrong period. `date_range` keeps only dates within it as dates, inclusive:

```json
"date_range": { "from": "2000-01-01", "to": "+1y" }
```

Each bound is a day, or days or years from today: `+30d`, `-10y` (a sign, 1 to 4 digits, and `d` or `y`). A date outside the range leaves the row undated; the row is still kept.

### Dates in cards

Three rules work on any source, kept rows or not:

- **`{ "date": rule }`** gives the rule's value as a date, written one way: `2026-11-04` for a day, `2026-11-06T16:46:00` for a wall time (no zone), `2026-11-07T00:46:00Z` for a moment. Words it can't read leave the result missing, so `default` applies.
- **`{ "days_between": [rule, rule] }`** counts whole calendar days from the first date to the second, negative when the second is earlier. Days and wall times count by their printed date; moments by the day they fall on in the Mac's time zone. From "Picked up" on October 26 to "Delivered" on November 4 is 9.
- **`"as": "date"`** in a `sort` compares values as dates, so "November 10" comes after "November 9". Values that aren't dates go last, in either order.

```json
{ "days_between": [
  { "date": { "first": "date", "of": "row.events", "where": { "path": "event", "contains": "Picked up" },
              "sort": { "by": "date", "as": "date" } } },
  "date" ] }
```

Read on each of `kept.rows`, this is the days from a package's first "Picked up" event to the row's own date. Inside `kept.rows`, the item's fields are under `row.`, and the row's date is `date`.

## How long rows are kept

`keep.for` is how long a row stays, from what `keep.clock` counts:

| `clock` | A row's age counts from |
| --- | --- |
| `date_or_last_seen` (the default) | The later of its date and the last time an answer had it. A row stays while the service keeps sending it, and for `for` after both. |
| `date` | Its date. An undated row counts from when it was last seen. A row already older than `for` when it arrives isn't kept: it's counted as already past retention. |
| `last_seen` | The last time an answer had it, or it was added. |

- Legato removes rows past their time each time it keeps an answer, and at launch and once a day for every history, whether or not anything is collecting.
- **Rows added from outside count from when they're added,** unless the clock is `date`. To import old rows and have them age by their own dates, use `"clock": "date"`.
- Changing `keep` applies to every row from the next cleanup, old histories included.

### Limits

| | Limit |
| --- | --- |
| One row | 16 KB (16,384 bytes) of JSON, as kept. A larger one isn't kept, and is counted as rejected. |
| One answer, or one `rows add` | 2,000 items and 8 MB (8,388,608 bytes). A larger answer isn't kept at all; a larger `rows add` is refused. |
| The current history of one dataset | 20,000 rows and 50 MB (52,428,800 bytes) |
| Every history on the Mac, together | 500 MB (524,288,000 bytes) |

- **At a history's limit,** the oldest rows by its clock make way, in the same step, and are counted as pruned for space. The rows arriving always land. A batch that doesn't fit by itself is refused.
- **At the limit for every history,** a batch that would make storage grow isn't kept at all, including its updates to rows already kept. A batch that doesn't grow storage still is. Settings shows “History storage is full. This collection batch is paused, including updates to existing records. Delete old history to resume.” Delete old histories, or a history you don't need, to make room; the note clears after a successful collection.
- Sizes are the rows' JSON. The database, its indexes and its journal take more space on disk than that.

The other limits are in [Limits](https://legatobar.com/docs/limits.md#history).



---

# Accounts and readers

## Accounts and histories

A dataset holds one history at a time for its readers. A new one starts when the data is someone else's, and the old one is kept, out of readers' sight, until it's deleted or ages out.

- **By host.** Without `account`, whose data it is means the source's host: `api.parcel.app`. Point the source at another host and a new history starts.
- **By `account`.** For a service where one secret reaches several accounts, cars or workspaces, name the field that says which: `"account": "{account.id}"`. A value that changes starts a new history with that answer. An answer with no value there isn't kept.
- **By secret.** Legato notices when the value of the source's secret changes, without keeping it: it keeps a fingerprint (an HMAC made with a key of this Mac's own, in the Keychain). Renaming the secret in Settings → Secrets changes nothing.

### What pauses

Some changes need you to say what they mean. Until you do, the page's cards keep updating from each answer, but nothing is kept:

| Settings → History says | Because | Your choice |
| --- | --- | --- |
| Paused: the secret changed. Is this the same account's history? | The secret's value changed | **Continue this history** if it's the same account with a new key or token; **Start new history** if it's someone else's |
| Paused: the page now keys its rows differently. Re-key keeps this history under the new key; rows it can't key are left out. | `key` changed, with rows already kept | **Re-key this history** recomputes keys from the stored fields; **Start new history** starts an empty current history |
| Updating what's kept to the page's new rules… | Retained fields, text removal or date rules changed | Collection waits while all retained histories are updated |
| Paused: what's kept couldn't be updated to the page's new rules. Nothing was changed. | A migration failed | **Try again** retries the required changes; **Start new history** starts an empty current history; the older histories are still updated to the new rules |

- **A lost Keychain key doesn't pause.** If Legato's own key is gone or replaced, it starts checking again from the next answer, and Settings says "The check that the secret hasn't changed started again once, after Legato's key for it was replaced. Nothing was paused."
- **An unreadable key doesn't pause either.** Settings says "Can't check whether this history's secret changed right now: Legato can't read its key for that. History keeps collecting."
- **Changed rules apply to what's already kept.** A change to `fields` or `remove_after` cuts the stored rows to the new rules, and a change to `date`, `time_zone` or `date_range` works their dates out again, in every history. Collecting waits while it does. A field already left out doesn't come back by adding it to `fields`. If the update fails, nothing is changed and collecting stays paused.
- **Re-key works from the rows as kept.** A row the new key can't be made from is removed. When two rows get the same key, the one seen most recently stays, with the earlier first-seen time. Settings says how many were merged and removed. A re-key that fails is tried again, even after Legato restarts.
- **A changed secret is asked about first.** If the secret and the key both changed, continuing the same account's history still leaves the key question to answer. Starting a new history skips re-keying the old rows, but not updating them to new rules.

`legato rows add` into a paused history is refused (`paused`), with the reason.

## Readers and grants

Grants are kept on the Mac, not in page files, so editing a page can't take over someone else's history.

- **The owner** is the page that first collected the dataset, by its id (its file name without `.json`). Rewriting its file, with `legato set`, an agent or an editor, keeps it the owner.
- **Its `readers`** may read the history while it's the owner. Take a page out of the list and it can't read from the next scan, unless it was also granted in Settings → History.
- **Settings → History → Grant** lets another page read too, from a menu of the folder's pages, and **Revoke** takes that back. A grant is for the page with that id: a page saved under another id needs its own.
- **The owner can read its own history** with a dataset source, without listing itself.

### Renaming the owner, and transfer

Renaming the owner's file looks to Legato like the owner going and a new page arriving that wants the same history. The new page doesn't get it:

- Settings → History shows "Also claimed by" with "Delivery log declares it too. It may be Packages, renamed." and **Transfer to this page**. Only that button changes the owner.
- A transfer keeps the readers already granted. After it, a page added to the new owner's `readers` can read only once you grant it in Settings → History.
- The claim goes once the other page stops declaring the dataset.

### The 30-day countdown

When no page in the folder collects a dataset any more (its owner was deleted, renamed, or lost its `collect`), Settings says "The page isn't collecting it any more. Deleted in 30 days unless it comes back or it's transferred." It counts down by the day:

- **It comes back:** the owner page declares `collect` for it again. The countdown stops.
- **It's transferred,** to a page that claims it. The countdown stops.
- **Otherwise,** after 30 days the dataset is deleted, every history in it.

A page that's in the folder but can't be read (a typo, or a file half written) doesn't start the countdown: its histories wait. Nor does a license that has ended; nothing is collected without one, and the history stays.



---

# Coverage and local storage

## Coverage

A history knows when it was listening. `coverage` in the reader's answer:

| Field | Meaning |
| --- | --- |
| `recording_since` | When this history first kept an answer, or null before then |
| `last_success` | When it last kept one |
| `earliest_row_date` | The earliest row date in it, which can be older than `recording_since`: Parcel's recent list, or imported rows |
| `interruptions` | Gaps in collecting, each `{ "from", "to" }`: more than twice the source's `every`, plus 2 minutes, between two kept answers. The last 200. |
| `imported` | The newest 200 import details in this history: each `{ "at", "rows", "earliest" }` |
| `imports_omitted` | How many older import details were removed from this history's coverage list; zero when the list is complete. The imported rows follow their own retention rules. |

Legato collects only while it's running, the Mac is awake and unlocked, and the service answers, so there are gaps. Show them on the reader, so a quiet week isn't read as no deliveries. A "Recording since" fact is the simplest:

```json
"items[2].key": { "template": "Recording since" },
"items[2].value": { "template": "{kept.coverage.recording_since|day}" }
```

Before the first answer is kept, it shows a dash. Imported rows give `earliest_row_date` and `imported`, never `recording_since`: an old row from an export doesn't show that nothing was missed since.

## Settings → History

**Settings → History** lists everything pages keep on this Mac: each history, under the page that keeps it, and each page's sparkline readings. The row at the top shows the space it uses. Anything that needs you comes first, and **Show** narrows the list to histories, sparkline readings or what needs attention.

A history's status is one of:

| Status | Means |
| --- | --- |
| Collecting | Rows are kept from each answer |
| Updating… | Kept rows are being changed to the page's new rules |
| Paused | The secret or the key changed, or an update failed. Select it for the choice: **Continue this history**, **Re-key this history**, **Try again** or **Start new history** |
| Storage full | Every history together is at its limit. **Delete old history** makes room |
| Deleted in N days | The page that kept it is gone. It comes back if the page does |
| Claimed by 2 pages | Another page declares the same dataset. **Transfer to this page** picks the owner |

Selecting a row shows when it started, when it last collected, which pages read it and any gaps. A page with [params](https://legatobar.com/docs/detail-pages.md#one-page-for-every-item) is named by its title without the params, or by its file name. A history of samples says its interval, items and samples in place of a row count: "Every 5 min · 30 items · 1.2M samples".

- **Export…** saves the selection as JSON: every history with its coverage and rows as kept, and the sparkline readings of the page that keeps it. For a sparkline page, just its readings. A history of samples asks where to save first, then writes its samples there a batch at a time (a year of 30 items is about 250 MB), and saves nothing if it's stopped or the history is deleted meanwhile.
- **Delete…** asks first ("Everything in it is removed from this Mac. This can't be undone.") and deletes the dataset with every history, row and grant, or a page's sparkline readings. If a page still declares `collect`, it starts a new history at its next fetch; to stop, remove `collect` from the page. A history of samples leaves every read at once, and its samples are overwritten on disk in the background, a batch at a time, within minutes.
- **Details…** opens the rest:
  - the readers, "listed by the page" or "granted here", with **Revoke** for a grant made here and **Grant…** to let another page read;
  - each history, with **Delete old histories**;
  - what was left out (pruned for space, rejected, already past retention);
  - notes such as a secret that can't be checked.

A page that starts collecting shows "Keeps history on this Mac. Settings → History" once at its foot, under every card, so nothing moves.

## On this Mac only

- **Where:** `~/Library/Application Support/Legato/Kept.sqlite`, beside the Pages folder, with sparklines' [readings](https://legatobar.com/docs/mapping-sparklines.md#sparkline-readings). Only Legato opens it. A sparkline's readings are removed five minutes after its page leaves the Pages folder, not after the 30-day countdown a dataset has. The `legato` tool hands rows to the app through short-lived files in `Pages/.rows`, already cut to the owner's `fields`; the app removes each one once it has answered, and drops any it hasn't reached in two minutes.
- **Deletion:** deleted rows are overwritten in the database, and Legato empties its journal file as soon as nothing is reading it. That's not a guarantee no trace is left on the disk. For 7 days Legato remembers a `rows` request's id and counts, so it can answer it again; never the rows themselves. Samples deleted or past their time leave every read at once and are overwritten in the background, in batches.
- **No sync.** Each Mac keeps its own histories. Legato doesn't send them to its servers, to iCloud or between Macs. Two Macs with the same pages collect two histories.
- **Copies you make.** Export history, backups of your Mac such as Time Machine, and anything you share hold their own copies. Deleting a history in Legato removes it from Legato's store, not from those.
- **Removing Legato.** Deleting the `~/Library/Application Support/Legato` folder removes every history with the pages.



---

# Rows from outside

## Rows from outside Legato

An agent or a script can add rows to a history whose owner says `"accepts_rows": true`. The rows go through the owner's rules, exactly as fetched ones do: its key, `fields`, `remove_after` and `date`.

### A history that only receives rows

A source of `collect` alone, with no `url` and no `kind`, keeps a history with nothing to fetch, for data that reaches the Mac some other way, such as a health export:

```json
"sources": {
  "daily": { "collect": { "dataset": "health-daily", "each": "days", "key": "{date}", "fields": ["date", "steps"],
                          "date": "date", "keep": { "for": "400d", "clock": "date" }, "accepts_rows": true,
                          "readers": ["health-steps"] } },
  "kept": { "dataset": "health-daily" }
}
```

- It needs `"accepts_rows": true`, and nothing beside `collect`.
- Cards read it through a dataset source, as here. A card that uses it directly says it "only receives rows; read them with a source of { "dataset": "health-daily" }".
- Details lists it as "Rows added from outside Legato", "Nothing fetched", "Keeps history on this Mac (health-daily), added with legato rows add".

### `legato rows`

The `legato` tool is in `/Applications/Legato.app/Contents/Helpers/`. It asks the app, which opens if it isn't running; only Legato itself opens the history's database.

```bash
legato rows add parcel-deliveries old-deliveries.json   # or from stdin
legato rows list parcel-deliveries --limit 20
legato rows delete parcel-deliveries --key ups:EX10000001 --key usps:EX20000002
legato rows delete parcel-deliveries --epoch 1
legato rows delete parcel-deliveries --all
```

**`rows add <dataset> [file] [--request-id id]`** reads a JSON array of items (or `{ "rows": [ … ] }`) shaped like the items of the owner source's answer: up to 2,000 items and 8 MB of them, in a file of up to 32 MB. Before anything is written to disk, the tool keeps only the owner's `fields`, with text removed after its markers; Legato then checks and cuts each row again itself, and dates it with the owner's `date` rule. It answers:

```json
{ "dataset": "parcel-deliveries", "accepted": 30, "rejected": 2, "expired": 0, "pruned": 0, "epoch": 1,
  "request_id": "5b0c6d1e-…" }
```

- `accepted` rows are in the history; `rejected` ones had no usable key or were over 16 KB; `expired` ones were already past retention; `pruned` rows made way for them.
- Rows land in the current history. They don't change `recording_since`, and they're listed in `coverage.imported`.
- **If Legato doesn't answer in time** (30 seconds, more while it opens), the request is withdrawn, but it may have been carried out. Run the same command again with `--request-id` and the id it named: a request that was carried out answers the same again and adds nothing. Use the id for the same operation on the same dataset within 7 days; reusing it for another dataset or operation is refused (`invalid_rows`, "Request id belongs to another history"). The original result, rejected counts included, comes back even if the owner's rules have changed since. After 7 days the id is forgotten.
- If the page's rules or history changed while the rows were being prepared, the tool prepares them again from your items, once.

**`rows list <dataset> [--limit n]`** gives up to 500 rows of the current history, the newest dated rows first, then undated ones: each with `key`, `date`, `date_kind`, `time`, `first_seen`, `last_seen` and `row`, with `epoch`, `total_count`, `undated_count` and `truncated`.

**`rows delete <dataset>`** takes one of:
- `--key k`, one or more: those rows of the current history;
- `--epoch n`: an earlier history, whole, or the current one's rows (the history itself stays);
- `--all`: every row. Earlier histories are removed and the current one stays, empty. The dataset, its owner and its readers stay.

Given more than one, `--all` wins, then `--epoch`.

It answers `{ "dataset", "deleted" }`. Deleting can't be undone, and the page goes on collecting. If the app commits a deletion but cannot publish its answer, retrying that same queued request returns its original count; it does not delete rows collected afterward.

### Over MCP

An agent connected with `legato mcp` has the same three as tools: `add_rows` (`dataset`, `rows`, and `request_id` to run again after a timeout), `list_rows` (`dataset`, `limit` up to 500) and `delete_rows` (`dataset` and one of `keys`, `epoch` or `all`). They answer as the commands do.

`get_history` (or `legato history`) says what Settings → History says about every history: its status, whether it needs you, why, and what to do in Settings. Use it when a history page is empty. It never returns rows. See [Lists and History](https://legatobar.com/docs/mcp-tools.md#lists-and-history).

### Refusals

A refusal is `{ "error": { "code", "message", "details" } }`, with exit status 1. `details` can hold the `request_id` to run again with, and `"retryable": "true"` when trying again may work:

| `code` | Message, or cause |
| --- | --- |
| `not_found` | "No page keeps the history parcel-deliveries. Its page declares it with collect." For `list` and `delete`: "This Mac keeps no history named parcel-deliveries." |
| `rows_not_accepted` | "The page that keeps parcel-deliveries doesn't take rows from outside: its collect needs "accepts_rows": true." |
| `claimed` | "Another page keeps parcel-deliveries; Settings → History can transfer it." |
| `stale` | "The page's history changed while the rows were prepared; prepare them again." Retryable; the tool tries once more by itself. |
| `paused` | A changed secret or key needs a choice in Settings; a migration in progress asks to try again shortly (retryable); a failed migration asks to resolve it in Settings |
| `storage_full` | "History storage is full. Delete old history in Settings → History, then try again." |
| `too_large` | More than 2,000 items or 8 MB in one request: "Batch exceeds 2,000 items", "Batch exceeds 8 MB", "At most 8 MB of rows at a time." or "That's more than one request can carry: send at most 2000 rows and 8 MB at a time."; from stdin, "The rows file is larger than 32 MB." |
| `invalid_rows` | "Rows are a JSON array of objects, like the items the page's source answers with." (or "Rows are a JSON array of objects."), "Batch alone exceeds dataset capacity" for a batch larger than a history can hold, or "Request id belongs to another history" |
| `invalid_arguments` | "Name the history by its dataset, like parcel-deliveries."; a request id that isn't 1–64 letters, digits and `-`; "delete takes --key k (one or more), --epoch n or --all."; a file named on the command line that can't be read or is over 32 MB: "Couldn't read old-deliveries.json, or it's larger than 32 MB." |
| `not_answered` | For `add`: "Legato didn't answer in time, so whether the rows were added is unknown. Run it again with request id … to find out: if they were, nothing is added twice." For `delete`: "Legato didn't answer in time, so whether the rows were deleted is unknown. Inspect the history before making another delete request." For `list`: "Legato didn't answer in time. Try again." |
| `failed` | "History couldn't do that." |
| `write_failed` | The request couldn't be written to the Pages folder |



---

# Parcel example

## A complete example: Parcel

**Packages** watches deliveries and keeps them; **Delivery times** reads them for the period showing. Save them as `packages.json` and `delivery-times.json` in the Pages folder, with a Parcel API key saved as the `parcel` secret.

These two are cut down to show how History works. The complete pages, with a page per carrier and only deliveries in your area counted, are the downloads on [Parcel](https://legatobar.com/services/parcel#download-the-pages).

```json
{
  "$schema": "./.schemas/page.schema.json",
  "title": "Packages",
  "icon": "shippingbox",
  "sources": {
    "parcel": {
      "url": "https://api.parcel.app",
      "secret": "parcel",
      "auth": { "type": "header", "name": "api-key" },
      "every": "30m",
      "requests": {
        "active": "/external/deliveries/?filter_mode=active",
        "recent": "/external/deliveries/?filter_mode=recent"
      },
      "collect": {
        "dataset": "parcel-deliveries",
        "each": ["active.deliveries", "recent.deliveries"],
        "key": "{carrier_code}:{tracking_number}",
        "fields": ["carrier_code", "tracking_number", "description", "status_code",
                   "events[].date", "events[].event", "events[].location"],
        "remove_after": {
          "events[].event": { "markers": ["Received By:", "Delivered:"],
                              "keep_exact": ["Signature Not Req", "Signature Required"] }
        },
        "date": { "date": { "first": "date", "of": "events",
                            "where": { "path": "event", "contains": "Delivered" },
                            "sort": { "by": "date", "order": "desc", "as": "date" } } },
        "keep": { "for": "400d" },
        "readers": ["delivery-times"],
        "accepts_rows": true
      }
    }
  },
  "cards": [
    { "id": "on-the-way", "type": "list", "label": "On the way", "items": [],
      "source": { "ref": "parcel",
        "map": { "items": { "each": "active.deliveries", "limit": 20,
                            "fields": { "text": "description", "detail": "carrier_code" } } },
        "empty": { "when": { "path": "active.deliveries", "equals": [] }, "text": "Nothing on the way" } } }
  ]
}
```

- Every 30 minutes, both lists are fetched once; the card shows what's on the way, and each delivery in either list is kept under its carrier and tracking number.
- A delivery's date is its newest Delivered event. Parcel's dates are wall times, so a package delivered at 9:15 PM on the 4th is in the 4th wherever the Mac is. A package not delivered yet is undated: it's kept, and gets its date the first time an answer shows it delivered.
- Names after "Received By:" and "Delivered:" are removed before anything is stored.
- `accepts_rows` lets you add deliveries from before the page existed (below).

```json
{
  "$schema": "./.schemas/page.schema.json",
  "title": "Delivery times",
  "icon": "clock",
  "sidebar": false,
  "period": {
    "choices": [
      { "id": "30d", "label": "30 days", "last_days": 30 },
      { "id": "90d", "label": "90 days", "last_days": 90 },
      { "id": "365d", "label": "365 days", "last_days": 365 }
    ]
  },
  "sources": {
    "kept": {
      "dataset": "parcel-deliveries",
      "derive": [
        { "name": "times", "value": { "each": "kept.rows", "fields": {
            "carrier": "row.carrier_code",
            "item": "row.description",
            "delivered": "date",
            "days": { "days_between": [
              { "date": { "first": "date", "of": "row.events",
                          "where": { "path": "event", "contains": "Picked up" },
                          "sort": { "by": "date", "as": "date" } } },
              "date" ] } } } },
        { "name": "average", "value": { "avg": "days", "of": "times", "where": { "path": "days", "gte": 0 }, "round": 1 } }
      ]
    }
  },
  "cards": [
    { "id": "summary", "type": "facts", "label": "Delivered", "items": [],
      "source": { "ref": "kept", "map": {
        "items[0].key": { "template": "Delivered" },
        "items[0].value": { "template": "{kept.selected_count}" },
        "items[1].key": { "template": "Pickup to delivery" },
        "items[1].value": { "template": "{average} days" },
        "items[2].key": { "template": "Recording since" },
        "items[2].value": { "template": "{kept.coverage.recording_since|day}" } } } },
    { "id": "by-carrier", "type": "bars", "label": "Days, by carrier", "unit": "days", "items": [],
      "source": { "ref": "kept", "map": { "items": { "each": "times", "where": { "path": "days", "gte": 0 },
        "group": "carrier", "fields": { "label": "key", "value": { "avg": "days", "of": "rows", "round": 1 } } } } } },
    { "id": "recent", "type": "list", "label": "Recent", "items": [],
      "source": { "ref": "kept",
        "map": { "items": { "each": "times", "sort": { "by": "delivered", "order": "desc", "as": "date" }, "limit": 4,
                            "fields": { "text": "item", "detail": { "template": "{days} days" } } } },
        "empty": { "when": { "path": "kept.selected_count", "equals": 0 }, "text": "Nothing delivered in these days" } } }
  ]
}
```

- With a period, the reader gets only dated rows in it: here, the packages delivered in the last 30, 90 or 365 days.
- `times` gives each delivered package its carrier, its name and the days from its first "Picked up" event to its delivery. A package with no "Picked up" event has no `days`, and `"gte": 0` leaves it out of the average and the bars.
- `"sidebar": false` makes it a [detail page](https://legatobar.com/docs/detail-pages.md#detail-pages): link to it from a card on Packages with `legato://page/delivery-times`.
- "Recording since" says how far back the history goes. Until then, the page shows what Parcel's recent list held when it started.

**Deliveries from before.** Write the ones you have as Parcel-shaped items, with the carriers' dates exactly as they wrote them:

```json
[
  { "carrier_code": "ups", "tracking_number": "EX10000001", "description": "Desk lamp", "status_code": 0,
    "events": [
      { "date": "October 30, 2026 2:12 PM", "event": "Delivered", "location": "Fernhollow" },
      { "date": "October 27, 2026 6:40 PM", "event": "Picked up", "location": "Kestrel Bay" } ] },
  { "carrier_code": "usps", "tracking_number": "EX20000002", "description": "Book stand", "status_code": 0,
    "events": [
      { "date": "October 21, 2026 11:03 AM", "event": "Delivered, Front Door/Porch", "location": "Fernhollow" },
      { "date": "October 18, 2026 9:20 AM", "event": "Picked up", "location": "Millbrook Junction" } ] }
]
```

```bash
legato rows add parcel-deliveries old-deliveries.json
```

They join the current history with the same key, fields, removal and dates as fetched ones. A delivery Parcel still lists replaces its imported row the next time Packages fetches. Imported rows count from when they're added for retention; with `"clock": "date"` in `keep`, they'd age by their delivery dates instead.

