# Quickstart: a client that asks

You are building a personal agent, a memory screen, a chat client or a voice assistant, and you want a
"forget this" that really happens and shows what happened. This quickstart takes you from one element
on a page to the five host methods from Node or Python against this demo, then to verifying the
receipts that come back, then to asking a company as a Poppy agent.

Status: not yet on npm or PyPI; this site serves the button and the verifier, and this page says where.

ForgetMe is the button a person presses beside a memory; ForgetProof is the engine behind it that
erases and signs receipts. The server behind the button is the **host**: on this page, your server. A
**reference** is the opaque token your agent issued for a memory when it stored it; the button sends
that, never the memory's value. A **receipt** is one holder's signed statement of what it did, and a
**holder** is one store that keeps the memory. The [glossary](/docs/glossary) has the rest.

## Before you begin

- You need a page you control, served over HTTPS or from `localhost`.
- For the Node steps you need Node 18 or later and `curl`. For the Python step you need Python 3.11 or
  later with `httpx`.
- You need a server behind the button. The element calls four routes under the `endpoint` you give it,
  and this demo's host is one such server. Your own page needs your own server behind it, or it shows
  an error when pressed. [The host contract](/docs/button#the-host-contract-forget-mev1)
  lists the four routes; the two sample hosts, [a memory list](/hosts/memory-list)
  and [a chat](/hosts/chat), are complete pages against this demo's host.

## Embed the button

The element is three files with no build step, no dependencies, no key, no account and no telemetry.
Fetch them into one folder your page serves; `forget-me-button.js` imports the other two by relative
path, so they stay side by side:

```sh
mkdir -p forget-me/button
for f in forget-me-button.js http-host.js outcomes.js; do curl -s -o forget-me/button/$f https://forget.stellarminds.ai/forget-me/button/$f; done
```

Then put one element beside each memory your page shows:

```html
<script type="module" src="/forget-me/button/forget-me-button.js"></script>

<forget-me-button reference="fmr_…" endpoint="/forget-me/v1" label="Home address">Forget this</forget-me-button>
```

The page now shows a blue button that reads "Forget this". Pressing it sends `POST /forget-me/v1/preview`
to your server with the reference. Until your server serves that route, the press opens a dialog that
reads "Could not continue", names the HTTP status, and ends "Nothing was changed"; that is the expected
state, not a broken page.

To see the whole flow before you have a server, you have two choices. Open one of the two sample hosts
on this site, [a memory list](/hosts/memory-list) or [a chat](/hosts/chat), which are this snippet
served behind this demo's host. Or run your own small server that proxies the four routes under
`/forget-me/v1` to this demo and adds the Bearer credential below; this demo's host answers only requests
from its own origin with its own session, so a page on another origin cannot call it directly. A
reference to try comes from the demo's synthetic session: `POST /pim/sessions` answers a `credential`,
and `GET /pim/memory` with it as a Bearer token lists items that each carry a `reference`. The listing
answers 503 for a few seconds while the scenario builds; ask again until it answers 200.

The complete example page is at [`/docs/embed`](/docs/embed). The element's attributes, events, slots
and parts are in the [button guide](/docs/button). A missing reference never means "everything about
this person"; that is a separate scope your server sets on purpose.

## Drive the five methods from Node

The headless host interface has exactly five methods: `reference`, `preview`, `submit`, `status` and
`evidence`. The walkthrough drives them against this demo the way a chat or voice client would. It
imports the host adapter from a sibling folder, so fetch both files into that layout:

```sh
mkdir -p src example
curl -s -o src/http-host.js https://forget.stellarminds.ai/forget-me/button/http-host.js
curl -s -o example/walkthrough.mjs https://forget.stellarminds.ai/docs/walkthrough.mjs
node example/walkthrough.mjs https://forget.stellarminds.ai            # keep the lease note
```

It prints one line per step, in this order: `session`, `Pim`, `reference`, `preview`, one `exception`
per choice, `approval` for a company that stated its terms, `submit`, `outcome`, one `holder` row per
store, `evidence` and `courier`. The last lines look like this:

```
submit     fmo_… accepted
outcome    intentionally-retained: Home address, saved in March removed from Pim. One lease note kept, as you chose. …
  holder   Pim's long-term memory: inspected-and-clear (every byte scanned, the exact text is in none of them)
  …
evidence   8 portable receipts (memory: inspected-and-clear, …) signed by Pim (this demo) and Bay Parcel (reference Company); Pim's key at …
courier    Bay Parcel books to 2240 Pine Ridge Rd, Berkeley CA 94704 (new address; Pim holds 1)
```

Run it again with `delete` as the second argument to delete the lease note too; the note's holder then
ends `inspected-and-clear`. If it stops at once with `Error: no session`, the demo is at its scenario
limit; wait a minute and run it again.

Each run starts a fresh synthetic scenario for the demo's fictional user, previews the stale address,
shows the companies the agent shared it with and the Company's exact terms, confirms with the person's
approval of those terms, polls, fetches the evidence and verifies every receipt.

## Drive the same routes from Python

The contract is plain JSON over HTTPS, so `httpx` is enough. The session is a cookie or a Bearer token
your server issued; the demo issues a synthetic one:

```python
import httpx, uuid
c = httpx.Client(base_url="https://forget.stellarminds.ai", timeout=30)
s = c.post("/pim/sessions").json()                      # the demo's synthetic session; your host has its own sign-in
c.headers["authorization"] = f"Bearer {s['credential']}"
while (m := c.get("/pim/memory")).status_code == 503: pass
old = next(i for i in m.json()["items"] if "118 Harbor" in i["text"])
pv = c.post("/forget-me/v1/preview", json={"reference": old["reference"], "scope": "item"}).json()
terms = {**pv["terms"], "idempotency_key": str(uuid.uuid4()),
         "approvals": {x["id"]: {"operation_id": x["approval"]["operation_id"], "revision": x["approval"]["revision"], "input_type": "keyboard"}
                       for x in pv["exceptions"] if x.get("approval") and pv["terms"]["exceptions"][x["id"]] == "delete"}}
op = c.post("/forget-me/v1/submit", json=terms).json()  # 202 accepted; the same key again answers 200, the same operation
while (st := c.get(f"/forget-me/v1/operations/{op['operation']}").json())["state"] in ("accepted", "running"): pass
print(st["outcome"]["sentence"]); ev = c.get(f"/forget-me/v1/operations/{op['operation']}/evidence").json()
```

It prints one sentence, such as "Home address, saved in March removed from Pim. One lease note kept,
as you chose." `ev["receipts"]` then holds one signed receipt per holder. On Windows, set
`PYTHONIOENCODING=utf-8` first, or the sentence's punctuation fails to print. The shapes (`Preview`,
`Operation`, `Evidence`) and the errors are in the
[button guide](/docs/button#the-host-contract-forget-mev1) and the [spec](/docs/spec); every shape has
a schema and fixtures under [`/schemas/forget-me/v1/`](/schemas/).

## Verify what came back

Each receipt is a `forget-me-receipt/1`: an Ed25519 signature over canonical JSON of counts and
vocabulary words only. The verifier is one ES module for browsers and Node 18+, served at
[`/static/index.js`](/static/index.js) with `canonical.js` and `ed25519.js` beside it:

```js
import { fetchIndex, verifyEvidence } from "https://forget.stellarminds.ai/static/index.js";
const index = await fetchIndex("https://forget.stellarminds.ai/forget-me/v1");       // the expected issuer's own origin
for (const r of ev.receipts) {
  const report = await verifyEvidence(r.receipt, { issuer: { doc: index, url: "https://forget.stellarminds.ai/forget-me/v1" } });
  console.log(report.summary.join("\n"));
}
```

For each receipt it prints four lines: the signature, the issuer, the declared outcome, and the file
hashes. A good one begins "Signature valid: key … signed exactly this receipt", then "Issuer confirmed",
then "Declared by the issuer: outcome inspected-and-clear …", then "A portable receipt carries no file
hashes". The three verdicts never stand in for one another: the **signature**
says the bytes are what the key signed; the **issuer** is confirmed only when that key is in the index
you fetched from the issuer's own origin, since a key embedded in the receipt confirms nobody; the
**declared outcome** is the issuer's statement, which no signature makes true. A Company's receipt in
the host's evidence carries the Company's own `issuer_key_url`; fetch the Company's index from where
you expect it, not from that string. Try it by hand at [`/verify`](/verify).

## Ask a Company as a Poppy agent

A host that shared a memory with a Company asks it through the same contract on the Company's origin,
as a Poppy 1.0 Personal Agent. Poppy is the Personal Agent Protocol: a signed Session header per
request and OAuth for the account. This takes an afternoon rather than ten minutes.

[Spec section 12.2](/docs/spec#122-a-minimal-client-pim-or-any-agent) is the list of steps. The
complete, dependency-light client is `tests/test_wire.py` ([served here](/docs/src/tests/test_wire.py)):
it publishes its client metadata document, discovers the Company through `poppy.json`, the two OAuth
metadata documents and the index, exchanges a refresh token for an access token with a client
assertion, signs a Session JWT per request, is told the exact terms through `403 approval_required`,
sends the person's approval as `Poppy-Approval`, withdraws one record, polls, and verifies every
receipt against the Company's published keys. The demo's own agent is `demo/recipients.py` and
`demo/poppy_agent.py` ([source](/docs/src/demo/recipients.py)), written with `cryptography` only.

## Rules a client keeps

- Never send a Session header to a discovery document, an index or a token endpoint.
- Keep `Poppy-Version` and `Poppy-Extensions` identical for the life of a Session.
- Never approve a revision the person has not seen.
- A Company that lists no ForgetMe entry is an observation of yours, never a receipt.
- Never point at a record by email, phone or address; there is no route that takes a value.
- Never treat a missing reference as "everything", invent an approval or a Company's receipt, or read
  `unsupported` or `queued` as clean.

## Next steps

- [The embed snippet](/docs/embed): a complete page with one element on it.
- [forgetme-button](/docs/button): every attribute, event, slot and part, and the host contract behind the element.
- [forgetproof-verify](/docs/verifier): the verifier's full API, key rotation and offline verification.
- [ForgetMe v1, the wire contract](/docs/spec): the contract your server implements.
