diff --git a/SPECS.md b/SPECS.md new file mode 100644 index 0000000..35168ef --- /dev/null +++ b/SPECS.md @@ -0,0 +1,218 @@ +# Allmende: project brief for agents + +Read this first. It says what the project is, what exists, what is left, and +the rules the owner has set. The protocol itself is in +[docs/PROTOCOL.md](docs/PROTOCOL.md) (the authority on formats and behaviour); +how to run a node is in [README.md](README.md); the Kubernetes setup is in +[k8s/README.md](k8s/README.md). This file does not repeat them. + +Status as of 2026-11-18. Check `git log` before trusting any "not built yet" +below. + +## The idea + +*Allmende* is German for "commons". It is a **free, distributed marketplace for +buying, selling and renting property**, with no central server and no company +in the middle. + +- Listings are replicated across the **nodes** of the people who take part. + Nobody owns the network, and it costs nothing to use. +- **Whoever lists runs a node** (a command-line program). **Searchers and + buyers need only a browser**: every node serves the web UI, a search API and + a message relay. +- The software is **AGPL-3.0** and must stay free for everyone. The owner does + not want a trademark or a company around it. +- It starts in **one region** (a German state or metro area; GDPR applies) and + grows from there. + +### Goals + +1. Anyone can search listings in a browser, with no account, and **verify every + listing themselves** (signatures are checked in the browser; a gateway + cannot forge anything). +2. Anyone can list a property by running one binary. Non-technical people must + be able to do it: the identity is a 12-word phrase, not a key file. +3. Buyers can contact sellers **privately** (end-to-end encrypted, anonymous + towards the network) from a browser, with no account. +4. **Nobody can switch it off or take it over.** No central index, no + network-wide moderation, no single bootstrap point (DNS is only a + convenience). +5. Abuse (scams, spam, illegal content) is **made expensive and locally + manageable**, not centrally banned. + +### Non-goals and settled decisions (do not reopen) + +- **The Go node is the product.** There is no phone app and no desktop app. A + Rust/Tauri rewrite was built, compared and **deleted** on purpose. Do not + revive it. +- Language: Go for the node, TypeScript for the web UI (embedded in the + binary; `web/dist/app.js` is committed). +- No account system, no payments, no ads, no tracking. +- Personal data stays off the network: a replicated listing has no name, + address, phone or email (location is a geohash of ~1 km). The exact address + is released only by the owner, inside an encrypted thread. +- Images, when built, are **origin-hosted only**: never replicated or cached + by third parties. + +## How it fits together + +``` + browser (any visitor) node (listers run one; everyone can use any node) + ─────────────────────── ───────────────────────────────────────────────── + search, verify listings ◄────► HTTP API + embedded web UI (internal/api, web/) + E2E-encrypted messages store: SQLite (internal/store) + tips about abuse libp2p: gossip, DHT, relay (internal/p2p) + identity + certificates (internal/identity) +``` + +- **Identity.** A 12-word phrase makes a root key, shown once, never stored. It + signs a **certificate** (at most 366 days) for a per-machine **device key**. + The device key signs listings and is the libp2p peer ID. Lose the machine: + `allmende recover` with the phrase signs a **revocation** and a new + certificate. Lose the phrase: start a new identity (listings expire in 30 + days anyway). `init --no-phrase` creates an identity that cannot be renewed + (used for the bootstrap node). +- **Listings.** Canonical JSON (RFC 8785), ed25519 signatures, proof-of-work, + geohash location, `seq`-based versions (higher wins), tombstones for + deletion, at most 30 days to live (the owner renews by hand, so abandoned + listings lapse). +- **Network.** libp2p. Gossipsub topics per **region** (a 3-character geohash + cell, ~150 km) plus global topics for revocations and reports. New + connections sync with **digests** (only what differs is transferred) and a + background **anti-entropy** round every 30 minutes repairs gossip lost while + connected. Peers are found through DNS (`_dnsaddr` TXT records), a seed + cache, a private Kademlia DHT, mDNS, and NAT traversal (port mapping, hole + punching, relays through `--public` nodes). +- **Messaging.** A buyer's browser makes a throwaway thread key per listing and + seals messages to the listing's device key. Envelopes are gossiped on the + region topic and held by relays for 14 days. Only the owner can read them; + the owner's replies (including a signed **address grant**) are signed so a + buyer can tell the real owner. Anti-spam: proof-of-work whose price **rises + as a listing's inbox fills**, first-message rules (short, no links), a daily + limit of new conversations, owner **block**. +- **Abuse reports.** Signed by node operators, gossiped, **never delete + anything**. Each node decides whose reports count (`--trust-reporter`, + `--hide-after`); a flagged listing is hidden from that node's search behind a + notice but stays reachable by link. Visitors can only send unsigned + proof-of-work **tips** to the node's operator, which hide nothing. + +## What exists + +| Area | State | +|---|---| +| Identity: phrase, certificates, revocation, recover | done, tested | +| Listings: format, signing, PoW, conflict rules, expiry | done | +| P2P: gossip, region sync, digest sync, anti-entropy, DHT, NAT traversal, DNS bootstrap, `--announce` | done | +| HTTP API + embedded web UI (search, detail, in-browser verification, en/de) | done | +| Owner UI: sign-in link, my listings, requests, conversation, release address, publish/edit/renew/delete, regions (by place name) | done | +| Messaging: E2E crypto, relay, queues, inbox, block, adaptive PoW, address grants | done | +| Abuse reports: record, gossip, sync, hide rule, tips, operator form and queue | done (phase 1) | +| Place names for `--region` (GeoNames, CC BY 4.0) | done | +| Expiry reminder in the terminal (≤5 days left) | done | +| Packaging: Dockerfile, Nix flake and module, `make image` | done | +| Kubernetes bootstrap node (`k8s/`, kustomize, Traefik IngressRoute) | written and **deployed by the owner**; running image is older than digest sync, anti-entropy, reports | +| Tests: Go (`-race`), web (`node:test` + jsdom), end-to-end with real binaries (`make e2e`) | all passing | + +The public bootstrap node is `bootstrap.allmende.stinnesbeck.com` (TCP and UDP +4001), found through `_dnsaddr.allmende.stinnesbeck.com`. It follows no region +and trusts no reporter. + +## What is left + +Roughly in the order the owner and I would take them. Ask the owner before +starting a design-heavy item; see "Working with the owner". + +**Technical, designed or small** +- **Fallback bootstrap list inside the binary**, for networks that block DNS + TXT lookups. Needs a stable address for the bootstrap node; its peer ID + changes when the no-phrase identity is recreated (every ≤366 days). +- **Vouching for reporters.** Today trust is a flag. Design: existing + operators sign "this key is a real operator"; a report counts if you trust + the voucher. Then **signed blocklists** subscribed to by curator key and + fetched over libp2p (decided: not URL files). +- **Owner's signed reply to a report**, and a **reputation** for reporters + whose reports are routinely overruled. +- **Forward secrecy for messages.** Today a leaked device key reads envelopes + still stored (≤14 days). Idea: rotating prekeys published in the listing. + Cost: a device recovered from the phrase can never read old messages. +- **Image storage.** Upload, re-encode, strip metadata, size caps, origin + hosting, gateways that stream without storing, hash-list matching where + access exists. Listings already have an `images` field of hashes. +- **Recovering listings onto an empty database** (after losing the data + directory but not the phrase). +- **Peer scoring and rate limits** beyond what the validators do now. +- **Message-sender abuse** (reports cover listings only). + +**Decisions and non-code work (the owner's)** +- **German legal review before any public launch**: GDPR erasure, §184b StGB + exposure for images, anti-discrimination law (AGG) content rules, and + messaging. Treat this as a launch blocker. +- **Reciprocity and incentives**: what nodes owe the network. +- A **project domain** (allmende.io and .de are taken). +- Run **a second bootstrap node** on another network; test the first from + outside the home network (phone on mobile data); recreate the no-phrase + identity before its certificate expires. + +**Deploy**: building and applying a new image to the cluster is the owner's +job (see rules below). + +## Working with the owner (rules) + +These come from the owner and are not negotiable. + +- **Never touch the Kubernetes cluster.** No `kubectl apply`, no changes to + live resources, ever. Write and render manifests only; the owner deploys by + hand. +- **Edit files with the Edit tool** (or Write for new files). Do not use + Python, `sed -i` or similar scripts to modify files. +- **Scratch files go in `.tmp/` in the project**, not `/tmp`. +- **Ask design decisions with the question tool**, but not routinely: pick the + conventional default for small things and say so. +- **Commit and push finished work to `main`** (allow rules for `git commit` and + `git push` are set). Add the attribution trailer the harness gives you. +- Report honestly: say when tests fail or something was skipped. Do not + discard errors to make a test pass; assert the exact outcome. + +## Developing + +``` +make check # go vet, go test -race, web typecheck + tests, end-to-end +make test # Go tests only +make web # rebuild web/dist after changing web/src (commit the result) +make e2e # real nodes end to end (needs Node.js, web/node_modules) +make image # build and push the container image (clean tree only) +``` + +- Go module: `git.stinnesbeck.com/nils/allmende`, binary `allmende` + (`cmd/allmende`). Remote: `ssh://git@git.stinnesbeck.com:2222/nils/allmende.git`. +- **Web tests run against the built bundle** (`web/dist/app.js`): run + `make web` (or `npm run build` in `web/`) before `npm test`. +- Nix: files must be `git add`ed for `nix build` to see them, and `vendorHash` + in `nix/package.nix` must be recomputed after `go.mod` or import changes. +- The container image is pinned in `k8s/base/kustomization.yaml` by tag **and** + registry digest (the local podman digest differs from the registry's; pull the + tag back to read the real one). +- Protocol changes must keep **old nodes working**: the deployed bootstrap node + runs an older version. New sync kinds fall back to the original full pull + when a peer does not know them. +- Tests are part of the job. Every feature so far has Go tests, web tests where + the UI changed, and an `e2e.sh` step where a real binary must be wired + correctly. + +## Map of the code + +| Path | What | +|---|---| +| `cmd/allmende` | CLI: `init`, `run`, `recover`, `version`; flags; terminal notices; shutdown | +| `internal/identity` | phrase → root key, certificates, device keys, revocations | +| `internal/listing` | the listing record: seal, check, regions, geohash | +| `internal/message` | encrypted envelopes, plaintext rules, sealing (mirrored in `web/src/message.ts`, checked against a golden fixture) | +| `internal/report` | the signed abuse report | +| `internal/store` | SQLite: listings, messages, inbox, reports, tips; conflict rules; hide rule | +| `internal/p2p` | libp2p node, topics, validators, sync, discovery | +| `internal/inbox` | the owner's conversations, replies, block | +| `internal/api` | HTTP API (public reads, relay, admin) | +| `internal/places`, `internal/jcs`, `internal/pow` | place names, canonical JSON, hashcash | +| `web/` | TypeScript UI (embedded), tests, build; `web/static/places.tsv` is generated | +| `k8s/`, `nix/`, `Dockerfile` | deployment | +| `scripts/e2e.sh`, `scripts/e2e/` | end-to-end with real binaries and jsdom |