# Quickstart: a Company that serves ForgetMe

You work at a company that a personal agent shared a record with, such as a courier, a pharmacy or a
utility, and you want to be asked to withdraw that record through the ForgetMe button. This quickstart
reads the documents of a Company that works, runs the reference Company on your machine, lists the five
things you implement, and checks your answers against the schemas.

Status: a third-party extension proposal targeting Poppy 1.0, not approved, adopted or reviewed by
anyone; no package is published yet, and this site serves everything you need.

A **Company** is an organisation a personal agent shared a record with, and it serves the ForgetMe
contract on its own origin with its own key. **Poppy** is the Personal Agent Protocol, version 1.0: the
agent signs a Session header on every request and holds an OAuth token for the person's account at
your company. A **reference** is the opaque token you issued for one record when the agent shared it;
the agent asks by reference, never by a value. Each store of yours is a **holder**; each holder ends
with one **outcome** word and one signed **receipt**. The [glossary](/docs/glossary) has the rest.

## Before you begin

- You need `curl` and `jq` to read the documents and check your own. On Windows `winget install jqlang.jq`
  installs jq; on a Mac, `brew install jq`.
- You need Node 18 or later for the schema check with ajv.
- To run the reference Company on your machine you need Python 3.11 or later, `uv` and its source tree.
  The source is not published yet; until it is, the live Company above answers the same documents.

## Read a Company that works

The reference Company, Bay Parcel, runs at `https://company.forget.stellarminds.ai`. Read its documents
in the order a client reads them. None of these needs a Session header or a token.

```sh
curl -s https://company.forget.stellarminds.ai/.well-known/poppy.json | jq .extensions
```

You see one `stellarminds.ai/forget-me` entry with `"version": "1"`, its `endpoint` and the two OAuth
scope names, and an `operations` entry with `"version": "3"`:

```json
{
  "stellarminds.ai/forget-me": [{"version": "1", "endpoint": "https://company.forget.stellarminds.ai/forget-me/v1",
                                 "scopes": {"item": "forget-me:item", "account": "forget-me:account"}}],
  "operations": [{"version": "3"}]
}
```

```sh
curl -s https://company.forget.stellarminds.ai/.well-known/oauth-protected-resource
curl -s https://company.forget.stellarminds.ai/.well-known/oauth-authorization-server | jq '{issuer, token_endpoint, grant_types_supported, scopes_supported}'
```

The first names the issuer (`authorization_servers`) and the three scopes. The second is the issuer's
own metadata: `token_endpoint` ends in `/oauth/token`, the only grant is `refresh_token`, and the
scopes are `forget-me:item`, `forget-me:account` and `addresses`.

```sh
curl -s https://company.forget.stellarminds.ai/forget-me/v1 | jq '{issuer, keys, routes, approval, identity}'
```

This is the **index**: `issuer` is the exact string your receipts carry, `keys` the public keys they
verify against, `routes` the five routes derived from the endpoint, `approval.approver` is `user`, and
`identity` names Poppy 1.0 and the issuer. If any of these returns 404, the host does not serve ForgetMe
at that endpoint; check its `poppy.json` first.

Everything behind the routes needs a Poppy 1.0 Personal Agent: a Session header, the negotiation
headers and an access token. Driving that by hand is long. The [client quickstart](/docs/quickstart-client)
does it with a script, and `tests/test_wire.py` ([served here](/docs/src/tests/test_wire.py)) is a
complete client in about 350 lines of Python that uses nothing but `httpx` and `cryptography`.

## Run the reference Company locally

From the source tree:

```sh
uv sync --all-extras
COMPANY_DEV_CLIENTS=1 COMPANY_ORIGIN=http://127.0.0.1:8090 uv run python -m company
```

The second command ends with `Uvicorn running on http://0.0.0.0:8090`. Then
`curl -s http://127.0.0.1:8090/forget-me/v1 | jq .issuer` prints `"Bay Parcel (reference Company)"`.

Each server listens on `PORT`: 8090 for the Company and 8080 for Pim by default. `COMPANY_ORIGIN` must
name the port the Company listens on, and `PIM_ORIGIN` below the port Pim listens on; if another program
holds 8080, start Pim with `PORT=8081` and `PIM_ORIGIN=http://127.0.0.1:8081`. `COMPANY_DEV_CLIENTS=1`
lets the Company fetch a personal agent's client metadata from `http://` and loopback addresses, which the
spec forbids in production; never set it on a public deployment. `COMPANY_DATA`, default `company/data`,
is where its Ed25519 key and SQLite files live.

Run the demo's agent, Pim, against it to see a whole withdrawal, button included:

```sh
FORGETME_COMPANY_URL=http://127.0.0.1:8090 PIM_ORIGIN=http://127.0.0.1:8080 uv run python -m demo.server
```

It ends with `Uvicorn running on http://0.0.0.0:8080`, and `curl -s http://127.0.0.1:8080/health` answers
JSON with `"cross_provider": true`. If that reads `false`, Pim did not see `FORGETME_COMPANY_URL`. Open
`http://127.0.0.1:8080/hosts/chat`: the page's heading reads "Say it in chat. The same button answers."
If you see any other page, another program answers on that port; move Pim as above.

1. Press **Start a fresh Pim**. Pim builds its stores and opens a synthetic account for its fictional
   user at your Company, with an old address already shared.
2. Type "Who did you share my address with?". Pim's reply quotes the address it holds; the companies it
   shared it with appear in the **Pim's own log** panel beside the chat.
3. Type "Forget my old address". The reply names the recipients, Bay Parcel among them, and carries a
   **Forget this** button.
4. Press **Forget this**. The dialog lists Pim's own holders, then one choice per recipient: Bay Parcel,
   with your Company's exact terms quoted word for word, and two recipients Pim simulates inside its own
   process, Harbor Pharmacy and Oakland Utilities, labelled as simulated.
5. Press **Forget it**. Confirming with Bay Parcel chosen is the approval your Company performs on. The
   result shows one row per holder of every party; Bay Parcel's rows read "inspected and clear" for the
   address book and "intentionally retained" for the invoice kept under tax law.

Watch the Company's terminal while this runs. You see the lifecycle you are about to implement, in
order: the four discovery and index reads, `POST /fixture/accounts 201` and `POST /oauth/token 200`,
then `POST /forget-me/v1/preview 200`, `POST /forget-me/v1/submit 403`, `POST /forget-me/v1/submit 202`,
and the two reads of the operation and its evidence. The 403 is deliberate: it is the Company stating its
exact terms, which Pim shows the person and then approves. `POST /fixture/accounts` is a demo-only route
that creates the synthetic account and stands in for a sign-in; it is not part of the contract.

Your Company's receipts for the run are in Pim's evidence, since Pim re-serves them as received. The
operation id, `fmo_…`, is in the result's receipt links; in the chat page's own browser session,
`http://127.0.0.1:8080/forget-me/v1/operations/<fmo_…>/evidence` answers JSON whose `receipts` with
`"issuer": "Bay Parcel (reference Company)"` are yours. The Company's own evidence route answers only the
agent's Poppy session, so `curl` without one gets 400.

## What you implement

The five steps of [spec section 12.1](/docs/spec#121-a-minimal-provider-company), with the reference
Company's file for each:

The **Session header** is `Poppy-Session`, a signed JWT the agent sends on every request; the
**negotiation headers** are `Poppy-Version` and `Poppy-Extensions`, which say which protocol version and
extensions the agent speaks. **Residue** is what a deletion leaves on disk: the bytes of a deleted record
in write logs, free pages and old versions. The reference Company's files are served on this site, so
the third column links to them.

| Step | What | In the reference Company |
|---|---|---|
| References | An opaque `fmr_…` per record and account, issued when the record is stored; the map stays private. | [`company/core.py`](/docs/src/company/core.py), `Company.add_address` |
| Poppy | `poppy.json` with your organization and issuer, the two OAuth metadata documents, `private_key_jwt` client assertions (a signed JWT that proves the agent's identity at the token endpoint), refresh and access tokens with your two scopes, Session header verification in front of every route but the index. [Spec section 4.1](/docs/spec#41-at-a-company-poppy-10) lists every check. | [`company/poppy.py`](/docs/src/company/poppy.py) (the verifier), [`company/app.py`](/docs/src/company/app.py) `_caller()` |
| Index | `GET {endpoint}`: issuer, keys, routes, scopes, limits, `approval`, `identity`. | `Company.index` |
| Preview | Resolve the account from the token, the record from the reference (404 for anyone else's), list holders, exceptions, exact terms. No side effects. | `Company.preview` |
| Submit | Refuse unless `Poppy-Extensions` declares `"operations";v="3"`; without `Poppy-Approval` answer `403 approval_required` with terms a person can read and perform nothing; with one, make the checks of [spec section 6.1](/docs/spec#61-at-a-company-the-approval-exchange-operations-version-3) in order, then at most once: stop retrieval, delete by id, rebuild derived items, erase residue, inspect, sign one portable receipt per holder. | `Company.submit`, `Company.execute` |
| Reads | Owner-scoped `operations/{id}` and `…/evidence`; on start, settle any operation a restart interrupted by scanning again, never erasing again ([spec section 7](/docs/spec#7-operations-and-polling)). | `Company.operation`, `Company.evidence`, `Company.reconcile` |

An **exception** is a place the exact value also lives that the person decides about before
confirming, such as an invoice you keep under a disclosed retention. The outcome words, worst first:
`error`, `bytes-still-found`, `queued`, `unsupported`, `intentionally-retained`, `inspected-and-clear`.
One clean holder never overrides an outstanding one.

## Check your answers against the schemas

Nine JSON Schemas with valid and invalid fixtures are at [`/schemas/forget-me/v1/`](/schemas/). With
ajv on any stack:

```sh
v1=https://forget.stellarminds.ai/schemas/forget-me/v1
curl -sO $v1/common.schema.json -O $v1/index.schema.json
curl -s https://company.forget.stellarminds.ai/forget-me/v1 > index.json
npx --yes -p ajv-cli@5 -p ajv-formats@3 ajv validate -c ajv-formats --spec=draft2020 --strict=false \
  -s index.schema.json -r common.schema.json -d index.json
```

The last command prints `index.json valid`. Replace the URL with your own index to check yours; an
invalid document prints `index.json invalid` followed by the failing path. The same works for every
other shape with its schema. In Python, `jsonschema` validates the same documents; [the schemas
page](/docs/schemas) has both.

Your Poppy documents should also validate against the protocol kit's schemas, vendored unmodified under
[`/schemas/poppy-1.0-kit/`](/schemas/poppy-1.0-kit/README.md).

## Sign portable receipts

A `forget-me-receipt/1` is an Ed25519 signature over the canonical JSON of the receipt without
`signature`: keys sorted by code point, no whitespace, non-ASCII raw, UTF-8. It carries counts,
timestamps and vocabulary words only: no path, no filename, no value, no value hash. A sample is at
[`/docs/sample-receipt.json`](/docs/sample-receipt.json); signed fixtures are under
[`/schemas/forget-me/v1/fixtures/receipt/valid/`](/schemas/forget-me/v1/fixtures/receipt/valid/).

Check your own at [`/verify`](/verify): paste one of the receipts your Company signed in the run above,
taken from Pim's evidence, and give your index URL, `http://127.0.0.1:8090/forget-me/v1`, as the expected
issuer. The page reports three things apart: "Signature valid", "Issuer confirmed" when your key is in the
index it fetched from your origin, and the declared outcome, `inspected-and-clear` for the address book.

## Not required of a Company

You do not have to install ForgetProof, adopt StellarMinds identity, or give anyone access to your
storage. The engine, the `forgetproof` Python package, is one way to erase residue and inspect a store;
the contract only asks for honest outcomes and a signed statement of them.

## Next steps

- [ForgetMe v1, the wire contract](/docs/spec): the contract in full, with section 12.1 as your checklist.
- [Bay Parcel, the reference Company](/docs/company): the holders, the routes and the fixtures of the Company you just read.
- [The schemas](/docs/schemas): what each of the nine schemas describes and how to validate in Python.
- [forgetproof-verify](/docs/verifier): how a verifier checks your receipts, so you know what it expects.
