# Reading the Forest index: a skill for AI agents

Forest is open software for people to offer, pay and review each other through profiles they own. A
market profile is one person's identity in one market and role, its label, such as `tutoring/tutor`;
each person also has People, their one profile in no market, label `people`, where they connect
with the people they know. A profile's address is its name. This index ranks what is public: it reads
the hosts it lists, keeps the profiles whose profile entry carries a verification that checks for a
verifier key it lists (a proof that the person behind the profile holds a stamp from a verifier this
index counts as checking one real person), works out each person's trust, rates each market
profile, and serves what it finds. A profile that does not count here still has a page, with what
this index made of each of its proofs.

## How to read

- Everything is a plain GET, so any AI that can read the web can read and browse these pages by
  links, with nothing to install and no login: no key, no sign-up, no cookies. The home page links
  each market, a market each of its listings, and a listing its profile.
- Every page has a JSON twin at the same address with `.json` on its path; the home page's is
  `/index.json`. The twin is the object the page is drawn from.
- A page may be cached for 30 seconds, and served for up to 5 minutes more while a cache fetches a
  new one. The index reads its hosts again 30 seconds after each pass ends.
- A listing's fields are as its market writes them
  ([the markets manual](https://github.com/foundationforest/markets/blob/main/build/README.md)): a
  field takes one answer, or a list of several, which mean any of them; a field may take several
  only from the roles it names. Numbers, amounts and degrees are decimal text: a score `"8.5"`, a
  number `"45"`, or a range `{ "from": "9", "to": "11" }`, an end left out for no limit,
  `{ "from": "18" }` for 18 and over. A price is one answer, `{ "amount": "40", "currency": "USD" }`
  for the whole deal, or `{ "amount": "30", "currency": "USD", "per": "hour" }` per hour where its
  field may be; in a listing by a role that spots is for, it is for one spot. A place is a circle,
  `{ "lat": "40.42", "lon": "-3.70", "radiusKm": 5 }`, with no name; radius 0 is an exact spot. These
  pages name it from this index's own place file, GeoNames' towns and city sections, by the name
  nearest its centre. A date is one day, `{ "on" }`, a weekly repeat, `{ "every": ["monday"] }`
  with a `from` and a `to` if wanted, or a span, `{ "from", "to" }`, and each may hold hours,
  `start` and an `end` if wanted, as clock times, with their `zone`, a time zone by name. A choice
  is one of its field's values, such as a language by its code, `es`. In this index's JSON, every
  number is a plain number; in its signed `statement`, a rating, connections and reports are text.

## What each profile shows

Two things say what people think of a person: a **connection**, two People profiles that each hold
one about the other, "we know each other"; and a **report**, "this profile is fake or a scam", from
a market profile that dealt with it. A review or a report counts only with a **handshake**, two
taps, one each way between its writer and its subject, each signed by its sender's main key, which
shows the two dealt; a vouch counts for nothing here. Four numbers come from them, each 0 to 100:

- **Badge:** how sure this index is that the profile is one real person, from the checks its
  verifications count for: 75 with a face check, 99 with a face check and an ID check.
- **Trust:** what the people who know the person, and those who dealt with them, make of them. A
  newcomer's is 50. Connections raise it, each by the other person's voice; reports lower it, each
  weighing three connections. A report reaches a person once they show a reports proof made after
  it, and it counts wherever its subject is, even once that profile drops its verification.
- **Judgment:** how well the people this person is connected to kept their trust against their
  reports. 100 until someone they are connected to is reported.
- **Voice:** badge times trust times Judgment: what the person's connections, reports and reviews
  weigh. A writer's reports share its voice, each its voice divided by how many it wrote.

A person is **New** while their connections add up to less than 5. Trust, voice and Judgment show
to the nearest 5. A market profile shows its person's trust, voice and New as its trust proof
copied them from this index's trust list; with no trust proof this index counts, it is
**Outdated**: `trust` is null and `voice` 0. What it already wrote still counts, at the last voice
it showed; what it writes while Outdated waits until it shows a proof again. A People profile with
no reports proof this index counts is Outdated too, and has no trust, voice or Judgment.

- **Ratings,** `{ "value", "count" }`, on a market profile: `value` is the profile's rating from 1 to
  10, to one decimal, and `count` is how many raters scored it. The rating is the plain weighted
  average of its scores, each weighed by its writer's voice, shown as it is: one 10 from one rater
  shows 10, with a count of 1, so read the count beside it. A review from a writer whose voice is 0
  does not count. `value` is null with no rating.

On the pages, a result shows its listing's first photo, its title (its `title`, else its
description's first line) and its first price, and its profile's rating with how many raters scored
it, "★ 9.2 (14)", and, near a place, its distance; nothing when no one has rated it. A profile's
page and a listing's show the profile's animal, the Forest app's for its address, and its badges,
"Verified with a selfie" for a face check and "Verified with ID" for an ID check. A profile's page
shows its trust, with New or Outdated beside it; its other numbers are in a fold, What these mean,
with what each means. A review's
date there is its entry's `time`, in UTC. Each field is under its market's label for it, and each
answer reads as the markets read it in English: a choice in words, `like-new` as "Like new", or by
its label, `xl` as "XL" or a language's code `es` as "Spanish"; a number in its field's unit, `"45"`
as "45 minutes", and a range so, "9 to 11 years", "18 years or more"; a date's days and hours, in
full on a listing's page, "Saturday, December 5 · 10:00 to 13:00", and as a line elsewhere, "Sat,
Dec 5 at 10:00", with no zone beside them: they are the hours where the listing's place is. A place
reads by its size and the name this index's place file gives its centre, "Within 5 km of Chamberí,
Madrid", "Exact spot near Sol, Madrid", or by its size alone with none, "Within 5 km", linked to its
point on a map. A price reads as the markets read it: "€40" for the whole deal, "$25 an hour", and
"€25 each" where it is for one spot; a request's under its market's label for that role, "Budget
€60". A listing's page shows each price, and a result its first. The JSON keeps each as written.

## The markets

    GET https://index.forest.foundation/index.json

`{ "index", "markets": [{ "name", "summary", "description", "status", "roles", "listed", "words" }], "lists" }`:
this index's address, every market in the markets directory it reads, with its `summary`, the one
line that says what the dealing is, its `description`, if it has one, what an AI needs to know of it
beyond that,
its `status`, `live` or `beta` (beta: it works, at your own risk, and may change; its tile and its
page say so), its roles, how many listings each role has `listed`, such as
`{ "tutor": 3, "student": 1 }`, and each role's word for its listings, `offers` or `requests`, such
as `{ "tutor": "offers", "student": "requests" }`, and the lists it reads by: `hosts`; `keys`, each
verifier key it counts with its `verifier`, its `label` (such as face check) and its `confidence`
from 0 to 1, that a profile it checked is one real person.

    GET https://index.forest.foundation/markets/<name>.json

`{ "index", "market", "listings": { "<role>": [<result>] }, "role", "query", "total", "results", "place", "currencies" }`:
the market's file as the directory holds it (its roles, its listing fields, each with its piece, its
rules and its words under `ask`, the fields a listing's preview shows first, after its title and
description, and the fields its reviews add), and every listing this index lists, by role, Top
rated first. A
market's page also takes search's filters below, but `market`: `role` is the side it shows, the one
asked or else the market's first; `query`, `total`, `results` and `place` are as search gives them,
for that side; `currencies` are the currencies that side's listings price in, most used first.

    GET https://index.forest.foundation/markets/<name>.json?role=<role>&where=madrid&sort=near

## Search

    GET https://index.forest.foundation/search.json?q=maths&market=tutoring&role=tutor
    GET https://index.forest.foundation/search.json?market=language-exchange&learns=es&languages=en
    GET https://index.forest.foundation/search.json?q=plumber&where=madrid&km=10&sort=near

`{ "index", "total", "results": [<result>], "query", "markets", "place", "found" }`: `query` is
each filter below as it was given, such as `{ "q": "maths", "market": "tutoring" }`, `markets` every
market's name, `place` the place the results are near, `{ "near", "name", "km" }`, or null with
none, and `found` how many results each market holds, every page of them, such as
`{ "tutoring": 9 }`. Every filter may be left out:

- `q`: words in the listing, each a word's start, all of them: what its writer wrote, and how its
  choices read, such as Spanish; never its places, dates, numbers or prices;
- `market`, `role`: only that market, only listings by that role;
- `where`, words for a place, such as a town's name: the first place this index's place file finds
  for them is the place, its point `near` and its name `near.name`; nothing found, no place, and
  `place` is null;
- `near=lat,lon`, a place by its point, and `near.name`, the name to show for it, which this index
  gives from its place file when it is left out; `where` with the same words as `near.name` is no
  new place, as a page's form sends it back, and an empty `where` beside them clears it;
- `km`, how far the searcher would go from the place (10 unless given): a listing whose place's
  circle touches that one, the distance between the two points at most `km` plus the place's
  `radiusKm`; each result then carries `km`, that distance between the two points, and a listing
  with no place, as one online only, is left out. A place narrows the results and never reorders
  them;
- `minRating`: a profile rated at least this, from 1 to 10; one with no rating is left out;
- `minReviews`: a profile scored by at least this many raters;
- with `market`, its listing fields, by their names in its file, each matched as the markets match
  it: a `choice` field as `<field>=<value>`, a listing whose field holds that value (for a field
  with several answers, one of them), such as `learns=es&languages=en`; a `number` field as
  `<field>.min` and `<field>.max`, in the field's `unit`, either one alone for an open end, such as
  `weeklyHours.max=20`: a listing whose number, or range, overlaps them, a range's missing end
  limiting nothing, so `weeklyHours.min=30` finds `{ "from": "20" }`; and `spots`, in a market whose
  listings hold it, as `spots=<n>`, a whole number from 1, room for that many by the listing's own
  spots: an offer whose spots are at least `n`, a request whose spots are at most `n`, a full one,
  `"0"`, left out, such as `spots=2`. A listing that leaves the field out is left out once it is
  filtered on. Without `market`, a field is no filter;
- `price.currency`, with `price.per`, `price.min` and `price.max`, in any market, once it gives an
  amount, `price.min` or `price.max`, or with `sort=price`: a listing with a price in that currency,
  per hour with `price.per=hour`, or for the whole deal when `price.per` is left out, whose amount is
  at least `price.min` and at most `price.max`, such as
  `price.currency=USD&price.per=hour&price.max=30`, which finds 20 USD an hour and leaves out 35 USD
  an hour and 30 USD for the whole deal. Prices compare only within one currency and one `per`, so
  without `price.currency` neither bound is a filter; a currency and a `per` with no amount filter
  nothing;
- `sort`: `rating`, Top rated, the default; `near`, with a place, nearest first; `price`, with
  `price.currency`, the cheapest first, by the least of those prices; ties in Top rated's order;
- `limit` (20 unless given, at most 100) and `offset`, for the next page.

A result is `{ "profile", "market", "role", "listing": { "address", "body", "url", "photos" },
"ratings", "badge", "trust", "new", "voice", "checks" }`: the listing, with what its profile shows
and its checks. The listing's body holds its market's fields; `url` is its page; `photos` links to each file
its fields name, at the first host its profile entry names, `<host>/v1/files/<sha256>`. This index
keeps no bytes. Top rated sorts by each profile's rating with one rater's worth of its market's
average added, so a profile with few scores sits near the average, then by the newest listing; a
profile no one has rated sorts at its market's average. With `sort=price`, results come cheapest
first, and with `sort=near` nearest first, results as cheap or as near in that order. That is the
order only: each result's `ratings` is as it is. To give a person a page, keep the place as `near`
and `near.name` in the link, so the page never asks for it again.

## A profile

    GET https://index.forest.foundation/profiles/<address>.json

- `kind`: `market` or `people`, by its profile entry's label; null for a label this index does
  not count.
- `profile`: its profile entry, as the hosts serve it: `label` (`<market>/<role>`, or `people`),
  `hosts` (where its folder is), `openKey` (what an inbox entry to it is locked to; with none, it
  takes no inbox entries), `keys` (the access keys it hands out, each with what it `can` do),
  `proofs`.
- `checks`: each verifier key it counts for here, `{ "verifier", "key", "label" }`, such as a face
  check. Its badge comes from these.
- `badge`, `ratings`, `trust`, `new`, `voice`: what it shows, as above; a People profile's ratings
  are always none. A profile that does not count has badge 0, no rating, trust null and voice 0. A
  profile whose market is no longer in the directory never counts, and its page, and each of its
  listings' pages, says so.
- `people`, for a counted People profile: `{ "judgment", "connections", "reports", "connected" }`,
  its Judgment (null when Outdated), its connections' total weight, its reports' total (null when
  Outdated), and each person it is connected to, `{ "profile", "kept" }`, `kept` how much of their
  trust they kept against their reports, 0 to 1, null when their numbers are not known.
- `statement` and `signature`, for a profile that counts: `statement` is what this index signed,
  canonical JSON of `{ index, profile, badge, ratings: { value, count }, trust, new, voice, time }`
  for a market profile, `{ index, profile, badge, trust, new, voice, judgment, connections,
  reports, time }` for a People profile, a rating's value, connections and reports as text; `signature` is its
  EdDSA-Poseidon signature over the statement's UTF-8 bytes, by the key whose address is `index`,
  which the standard's keys check (`checkBytes`).
- `listings`: each listing, `{ "address", "body", "time", "listed", "url", "photos" }`, with `why`
  when it is not listed (it does not fit its market, its profile does not count, or it was deleted:
  a deleted listing keeps its last body here, and that body's time, so a review that names it still
  finds it). `time` is its entry's own time, in ms since 1970, a plain number: its writer's word,
  not when this index read it.
- `reviews`: `received` and `given`, each `{ "reviewer", "address", "body", "time", "counted",
  "why", "weight", "market", "role", "checks" }`. A review's body holds its `subject`, its `score`,
  any `text`, the `listing` it is about, and the fields its market adds. `time` is as for a listing.
  A review counts only with a `handshake` in its body: two taps, one each way between its writer
  and its subject, each a message signed by its sender's main key.
  `counted` says whether it counts here; `why`, only when it does not, says why (its writer does not
  count, it gives no score, it is about another market or its own writer, it carries no handshake
  that holds, it waits until its writer shows a fresh trust proof, a later one by the same writer
  about the same profile and listing counts instead, or its writer's voice is 0). `weight` is how
  much its score weighs in the rating, its writer's voice from 0 to 1, the last its trust proofs
  showed, split equally across that rater's reviews of the profile. `market`, `role` and
  `checks` are the other profile's: its writer's on one received, its subject's on one given, as
  this index holds them, `checks` as above; `null`, `null` and `[]` for one with no profile entry
  here.
- `reports`, `connections` and `vouches`: `received` and `given`, each `{ "writer", "address",
  "body", "time", "counted", "why", "weight", "market", "role", "checks" }`. Each body holds its
  `subject`, and a report's and a vouch's any `text`. `time`, `counted`, `why`, `market`, `role` and
  `checks` as for a review; per writer and profile, the latest counts. A report counts as a review
  does, with a handshake and once its writer showed a fresh proof, from a market profile, about any
  profile but a People one; a report's `weight` is its writer's share of its last voice. A connection
  counts once both People profiles hold one about each other; its `weight` is its writer's voice. A
  vouch never counts, and says why.
- `proofs`: each proof on the profile entry, with what this index made of it, `result` `counts` or
  why not: a verification; a reports proof, on a People profile, with its `total`; a trust proof,
  on a market profile, with the `numbers` it copied, trust, voice and New.
- `message`: `[{ "name", "url" }]`, a link to message the profile from each app this index lists.
  A listing's page gives each app's link to message it about that listing instead.

## A listing

    GET https://index.forest.foundation/profiles/<address>/listing/<id>.json

A listing's own page, at its address under `/profiles`: `{ "index", "profile", "market", "role",
"listing", "checks", "badge", "ratings", "trust", "new", "voice", "fields", "pieces", "units",
"labels", "captions", "reviews", "message" }`. `listing` is as its profile's page gives it; `checks`,
`badge`, `ratings`, `trust`, `new` and `voice` are its profile's; `message` is a link to message its profile
about this listing from each app this index lists, the listing's full address in it; `fields` is the
fields its market asks its role's listings, in that order, `title` and `description` first, then
the market's preview, and `contact` last; `pieces` is each one's piece, as its market names it, a
`photo` field naming photos; `units` is each number field's unit, such as `{ "ages": "years" }`; `labels` is, for
each choice field it holds, how each value it holds reads, such as `{ "size": { "xl": "XL" },
"languages": { "es": "Spanish" } }`; `captions` is, for each place field it holds, the name the
place file gives each place's centre, in its answers' order, null where it gives none, such as
`{ "area": ["Chamberí, Madrid"] }`; `reviews` is the reviews its profile received that count, `{
"count", "latest" }`, the two newest as its profile's page gives them. The page shows its photos,
its fields, who posted it, their two latest reviews, and how to reach them: the `contact` its body
gives, in the writer's words, and `message`. A listing that is not listed has its page too, with
`why`.

## About

    GET https://index.forest.foundation/about.json

`{ "index", "lists", "credit" }`: this index's address and the lists it reads by, as `/index.json`
gives them, and the credit for the names of places on these pages, GeoNames'. Its page says what this index is, links to the JSON, its two lists, what it remembers, this file and the source, and lists
what it reads, its address and the credit.

## The two lists

    GET https://index.forest.foundation/v1/lists/reports
    GET https://index.forest.foundation/v1/lists/trust

Each whole, as this index last signed it, in the standard's format, so a person's app builds the
list itself and proves from it on their device, and this index never learns which profiles are one
person's: `{ "index", "root", "time", "signature", "proofDays", "readSeconds", "leaves" }`, the root
as 32 bytes in hex, signed with its time. The reports list adds `labels`, every label a reports proof on it must walk, each
once: every label the markets have had, but `people`. Its leaves are `{ "profile", "reports" }`,
each address with counted reports, whether or not its profile counts here, what they weigh in
hundredths of a report. The
trust list's are `{ "profile", "trust", "voice", "new" }`, each person with numbers, `new` 1 or 0,
the three numbers a trust proof copies, in that order. A proof counts here against a list's newest
signing, or one this index made within that list's `proofDays` days. `readSeconds` is the seconds
between the end of one pass, when this index reads the hosts, and the start of the next. 404 before
the first signing.

## What it remembers

    GET https://index.forest.foundation/v1/remembered

`{ "index", "voices", "fresh" }`, whole, so anyone can copy it and work this index's numbers out
again. `voices` is each market profile's last voice its trust proofs showed, `{ "profile", "voice",
"time" }`, 0 to 100, `time` the trust list's signing it was copied from: what that profile's reviews
and reports weigh, even once its trust proof ages out. `fresh` is each version of a review or a
report this index read while its writer showed a fresh trust proof, `{ "entry", "address", "time" }`,
`entry` its entry's id and `time` when: only such a version counts.

## To act

This index only reads. To message a profile, a person follows a `message` link to their app, or uses
the `contact` a listing gives. To post, review, report, connect or message, the person's app signs
with the profile's main key, or whoever holds an access key the profile entry lists signs with that
key, within what the profile entry says it `can` do, and writes to the profile's hosts. An AI acts
for the person with an access key their app hands it.
