# Audit log

> A tamper-evident, hash-chained record of what agents did, what Lanekeeper checked and what they were told, with lk audit verify and lk audit export.

Availability: Local log in the CLI; the organization log on the Team plan.

Every Lanekeeper daemon keeps an append-only log of what happened in the repository on that machine. Each event
is chained to the one before it: its hash covers the previous hash and the event itself (SHA-256 over canonical
JSON). So an edited, removed or reordered event breaks the chain from that point on.

## What's recorded

- `session.start`, `session.end` — an agent session in a lane.
- `edit.checked` — an edit was checked before it happened: the decision (allow, warn, deny), the clashes it would
  introduce (ids, rules, severities), and the policy rules that fired. Never the edit's content.
- `claim.create`, `claim.release`, `claim.conflict`, `claim.revoked` — claims and refused claims.
- `clash.open`, `clash.resolve`, `clash.ack`, `clash.suppress` — clashes appearing, going away, or being
  acknowledged or suppressed.

## Commands

```sh
lk audit verify                       # recompute the chain; exit 1 at the first broken link
lk audit export > audit.jsonl         # every event, one JSON object per line
lk audit export --format csv          # CSV for spreadsheets
lk audit export --after 1200          # only events after sequence number 1200
```

The log lives in the repository's Git directory (`.git/lanekeeper/`), next to the rest of the daemon's state.

## The organization's log

The team service keeps a second chain per organization, built the same way. It records:

- members invited, joining and removed;
- API tokens created and revoked (tokens scoped to the organization);
- repositories linked;
- changes to Slack, single sign-on (never the client secret), budgets, billing and audit retention;
- pull-request verdicts from the GitHub Action;
- clashes the team's room opened, acknowledged and resolved.

Owners and admins see it on the dashboard's **Audit log** page, with whether the chain still verifies, and export
it as JSONL or CSV with field names SIEMs map without setup (`sequence`, `timestamp`, `event_type`, `actor_id`,
`details`, `prev_hash`, `hash`). The API has the same: `GET /v1/orgs/<org>/audit`, `/audit/verify` and
`/audit/export?format=jsonl|csv`.

Events are kept for 90 days (365 on Enterprise); an owner can choose 30 to 3,650 days. Once a day, each finished day
is archived as one JSONL file (an R2 bucket on the hosted service, `audit/` beside the database on a self-hosted
server), then events past the retention period are removed. The chain then starts from the last removed event's
hash, so what remains still verifies, and the archived files continue it backwards.
