# 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.

