# Bay Parcel, the reference Company

Bay Parcel is the reference Company for ForgetMe v1: a fictional courier that serves the contract on
its own origin, with its own Ed25519 key and its own SQLite files, so a personal agent holding an
opaque reference can ask it to withdraw a record and receive the Company's own signed receipts. This
page shows you what Bay Parcel is made of, how to run and test it, and which parts of it are fixtures;
its routes and its three holders are in the tables below.

Status: deployed at `company.forget.stellarminds.ai` as the second party of the demo; not a product,
and every account on it is a synthetic fixture that expires.

A **Company** is an organisation a personal agent shared a record with. Bay Parcel holds the delivery
addresses that Pim, the demo's fictional agent, shared with it. It is a **Poppy** 1.0 Company: Poppy is
the Personal Agent Protocol, and Bay Parcel verifies the agent's Session header on every request but
the index, issues and checks OAuth access tokens from its own issuer, and performs a withdrawal only
through the Operations extension, version 3, on the person's **approval** of the exact terms it states.
Each of its stores is a **holder** that ends with one **outcome** word and one **receipt**. The
[glossary](/docs/glossary) has the rest; the [wire contract](/docs/spec) is what it
implements.

## The parts

- **Its own process and origin.** `python -m company` serves it on port 8090 (`COMPANY_PORT` or
  `PORT`). On Railway it is the `company` service with its own volume and domain. It never shares a
  process, a database or a key with the demo site.
- **Its own stores**, under `COMPANY_DATA` (default `company/data`): `records.db` (address book,
  delivery summaries derived from addresses, provenance), `invoices.db` (invoices kept 90 days under a
  disclosed retention), `archive.jsonl` (a legacy export made before provenance tracking), `company.db`
  (accounts, fixture credentials, references, operations, portable receipts), `signing_key.pem`, and
  `receipts/` (the engine's full receipts, private; only their digests go on the wire).
- **The full lifecycle**, implemented here, not imported: references issued when a record is stored;
  preview; at-most-once submit keyed by account and idempotency key; retrieval stopped before `202`;
  deletion by id; derived summaries rebuilt from provenance; residue erased and inspected with the
  engine; one restore attempt through its own undo path, which must be refused; one portable receipt
  per holder; a queued step that re-checks its authority; reconciliation after a restart by scanning
  again, never erasing again.
- **What it takes from ForgetProof:** `forget()` and `scan()` for the erase and the inspection,
  `receipt` for the key and canonical JSON, `forgetme` for the portable receipt and the vocabulary. It
  does not import `forgetproof.agent.Provider`. A Company on another stack needs none of this: the
  contract, the schemas and the fixtures are enough.

## Routes

| Route | What |
|---|---|
| `GET /.well-known/poppy.json` | Discovery (spec 3.1): `protocol_version`, `organization`, `auth` (the issuer is this origin; `disabled`, see Fixtures; scope descriptions and hints), `apis` (the OpenAPI description below), `extensions`: the `stellarminds.ai/forget-me` entry with its scope names, and `operations` version 3. |
| `GET /.well-known/oauth-protected-resource`, `GET /.well-known/oauth-authorization-server` | The two OAuth metadata documents of spec 3.2: the resource names the issuer, the issuer lists the resource, the token and revocation endpoints, `refresh_token` as its only grant, `private_key_jwt` with ES256 and PS384. |
| `GET /openapi.json` | The APIs `poppy.json` lists, with the scope each needs and which operation can answer `approval_required`. |
| `POST /oauth/token`, `POST /oauth/revoke` | The synthetic issuer: `grant_type=refresh_token` with a client assertion (RFC 7523; `aud` exactly the issuer, five minutes at most, a fresh `jti`), optional `scope` (narrowing) and `resource` (this origin only); RFC 7009 revocation, which ends the access tokens too. OAuth errors: `invalid_client`, `invalid_grant`, `invalid_scope`, `invalid_target`, `unsupported_grant_type`. |
| `GET /forget-me/v1` | The index: issuer, keys, routes, scopes, limits, status, `approval` (Operations 3, user approvals only), `identity` (Poppy 1.0, the issuer, the OAuth scope names). Public, tenant-neutral, no Session header. |
| `POST /forget-me/v1/preview`, `POST …/submit`, `GET …/operations/{id}`, `GET …/operations/{id}/evidence` | The contract, as Poppy resources: `Poppy-Session` (verified as spec 5.3 says), `Poppy-Version`, `Poppy-Extensions`, `Authorization: Bearer <access token>` with scope `forget-me:item` (or `forget-me:account` for `{"scope": "account"}`); submit also needs `"operations";v="3"` declared and, to perform anything, `Poppy-Approval` of the exact terms it stated (the contract's section 6.1). |
| `GET /forget-me/v{n}/…` for n ≠ 1 | `404 unsupported_version`. |
| `GET/POST /api/addresses`, `POST /api/deliveries`, `GET /api/lookup`, `POST /api/addresses/{id}/restore` | The Company's own API (scope `addresses`), as Poppy resources too: what an agent uses when it shares an address (it gets a reference back), what the courier reads, and the undo path the withdrawal must defeat. |
| `POST /fixture/accounts`, `POST /fixture/revoke` | Labelled fixtures, not protocol endpoints: a synthetic account, optionally seeded (`addresses`, `deliveries`, `records_busy_seconds`, `archive_copy`, `scopes`, `neighbour`), with a refresh token for the `client_id` named (`grant`); and signing the account out (every refresh token and access token of it), which is what a queued step sees as lost authority. Rate limited per visitor; accounts expire after `COMPANY_ACCOUNT_TTL` seconds (30 minutes). |

## Holders

| Holder | Kind | Outcome in the usual run |
|---|---|---|
| `records` | sqlite | `inspected-and-clear`: the record deleted by id, its delivery summaries rebuilt from provenance, the residue erased, every byte scanned, a restore attempt refused. |
| `invoices` | sqlite | `intentionally-retained` while an invoice carrying the address is inside its 90-day retention (disclosed in the preview as an exception with the single option `keep`, with `retained_until`); invoices past retention are deleted and the residue erased. |
| `archive` | files | `inspected-and-clear` when the legacy export does not carry the exact text, with a coverage limit saying why the export can only be searched; `bytes-still-found` with "a person reviews it" when it does. Nothing in it is ever deleted on a guess. |

A `records_busy_seconds` fixture makes the address book busy: the `records` step ends `queued`, the
operation is `done` with `outstanding: 1`, and a later poll of the same id (or the Company's next start)
runs the step and shows the new outcome. A credential revoked in between makes the queued step end
`error` with "nothing done: the request lost its authority before this step ran".

Two accounts may hold the same address line; the `neighbour` fixture creates the current tenant at the
same address. A withdrawal touches only the caller's record, and the receipt's counts are about the
caller's records and their residue. It says nothing about other accounts.

## Run it

```bash
uv run python -m company
```

It ends with `Uvicorn running on http://0.0.0.0:8090`, and `curl -s http://localhost:8090/forget-me/v1`
answers the index with `"issuer": "Bay Parcel (reference Company)"`. Variables:

| Variable | Meaning |
|---|---|
| `COMPANY_ORIGIN=http://localhost:8090` | The Company's identifier and the base of every URL it publishes; else `RAILWAY_PUBLIC_DOMAIN`, else the request's host. |
| `COMPANY_DEV_CLIENTS=1` | Accept `http://` and loopback client ids, such as a Pim on localhost. Development and tests only, never in production. |
| `COMPANY_TOKEN_TTL=3600` | Access token lifetime in seconds. `COMPANY_APPROVAL_TTL=900` is how long an offered revision can be approved. |

The demo site asks this Company when `FORGETME_COMPANY_URL` points at it ([the demo site](/docs/demo)).
The Company fetches the site's client metadata document at `PIM_ORIGIN/poppy/agent.json`, so the site
must be reachable from the Company under that origin. On Railway it is; locally set `COMPANY_DEV_CLIENTS=1`.

## Tests

```bash
uv run pytest tests/test_company.py          # the conformance set, in-process, over Poppy
uv run pytest tests/test_poppy.py            # negotiation, identity and the approval exchange; documents checked against the Poppy kit's schemas
uv run pytest tests/test_wire.py             # a public-contract client over real HTTP, two processes
```

Each ends with a `passed` count and no failures. What `poppy.py` checks, and the upstream section each
check comes from, is written beside each check in the code; the kit's own schemas for every document
are in `schemas/poppy-1.0-kit/`.

## Fixtures

The issuer offers Personal Agents no sign-in type (`auth.disabled: true`): its only account holders are
fictional. `POST /fixture/accounts` creates a synthetic account for the demo's fictional user and mints
the refresh token a sign-in would have produced, for the one Personal Agent named. From there on
everything is the protocol, and that fixture is the one thing a real Company replaces with Direct or
Device Sign-In. Accounts expire after thirty minutes.

## Limits

- Nobody signs in. A real Company replaces the account fixture with its own sign-in and changes nothing else.
- The Poppy kit's own validator has not been run against the deployed Company; it needs Node 22.18 or later and an HTTPS deployment of the test agent's documents.
- The legacy export is searched for the exact text only. Nothing in it is deleted on a guess.

## Next steps

- [Quickstart: a Company that serves ForgetMe](/docs/quickstart-company): read Bay Parcel's documents from outside, then implement your own.
- [ForgetMe v1, the wire contract](/docs/spec): the contract Bay Parcel implements; section 12.1 is the checklist.
- [The schemas](/docs/schemas): validate your answers against the same schemas Bay Parcel's tests use.
- [The demo site](/docs/demo): how Pim, the host, talks to this Company.
