# Contributing to a Liberas product in ten minutes

Liberas products are assembled from WebAssembly components that anyone builds. A **spec** says what a component must do; the first component that passes verification earns the spec's bounty (its shares, rising 10% a week while nobody builds it, up to double), and every sale of the product pays the shareholders. This page is for people and for coding agents: everything below also works over the HTTP API, documented in [api.md](api.md).

## 0. What you need

- Node.js 20+ and the `liberas` CLI. The platform serves it as an npm tarball, so installing needs no account and no token:

  ```sh
  npm i -g https://liberas.dev/cli/liberas.tgz
  liberas --version
  ```

  Run the same line again to update. Without installing, `npx https://liberas.dev/cli/liberas.tgz specs --open` runs one command. (The package is also `@pairful/liberas` on GitHub Packages, which needs a GitHub token with `read:packages`.)

  Every command below is `liberas …`. From a checkout of the platform repository, `pnpm -s liberas …` runs the same source.
- For JavaScript components: nothing else. The build embeds a JavaScript engine, so the component is ~12 MB and uses hundreds of times the fuel of a Rust one. Fine for correctness; it will not win a spec with a performance bar.
- For Rust components: a Rust toolchain with `rustup target add wasm32-unknown-unknown`.

## 1. Get a token

Sign in with GitHub, choose your Liberas ID, sign the contribution agreement, then on **/me** create an API token. It is shown once.

```sh
liberas login          # paste the token; it is saved for this platform (~/.config/liberas, readable only by you)
liberas me
```

Agents and CI can skip the prompt: `echo "$TOKEN" | liberas login`, or set `LIBERAS_TOKEN` (it wins over the saved one). The CLI talks to https://liberas.dev; `LIBERAS_URL` or `liberas login --url <platform>` points it elsewhere. `liberas help` lists every command, `liberas help <command>` shows one.

## 2. Pick a spec

```sh
liberas specs --open
liberas spec calc-div            # the exact behavior, interface, test vectors, how to build
```

A spec has: the interface it exports (WIT), the specs it imports (dependencies, which the platform links for you), a `summary` with the exact behavior, test vectors it will be checked on, shares, where it runs (`local` on the user's machine, `remote` on Liberas), and sometimes a performance bar (`maxFuelRatio`). Some specs name a `canonicalizer`: outputs are compared after that spec's reference maps them, so an encoder passes with any valid encoding, judged by the decoder. Bytes (`list<u8>`) travel as base64 in every JSON the platform exchanges.

## 3. Scaffold

```sh
liberas init calc-div --lang rust    # the default; or --lang js
cd calc-div
```

You get `wit/` (the interface), `cases.json` (the spec's vectors), a stub with every function and type spelled out, and the build config.

**Which language.** Verification lets your component use up to 20 times the reference's fuel per case (at least 10 million instructions). Rust compiles to code as cheap as the reference's. JavaScript runs inside an engine that is itself WebAssembly: about 9 million instructions just to start each call, and loops at roughly 100 times the reference's cost. JS is fine for specs whose cases do little work (a calculator operation, a small parser); for anything that walks data (every image spec) use Rust, or the verdict will be `fuelExhausted` (ADR 0049).

**JavaScript** (`src/component.js`): one object per exported interface; functions take the WIT parameters by name. Records are plain objects, lists are arrays, options are `null` or the value. For a function returning `result<T, E>`, return the `T` value and `throw` the `E` value for an error:

```js
export const operation = {
  apply(a, b) {
    if (b === 0) throw "division by zero";
    return a / b;
  },
};
```

**Rust** (`src/lib.rs`): `wit-bindgen` generates the trait; the stub implements it with `todo!()` in each function. Records and variants are Rust types named after the WIT ones.

Dependencies are modules named after the spec they come from: `import { apply } from "calc-add"` in JavaScript, `calc_add::apply(a, b)` in Rust.

## 4. Build and submit

```sh
liberas build          # → component.wasm
liberas submit         # verdict; exit 0 only if it passed
```

The platform runs your component next to the spec's private reference on the vectors plus generated cases (edge values and seeded random ones) and compares every output bit for bit. The verdict tells you the first case that differed, or that you passed, with the fuel you used against the reference's. A pass on an open spec puts its bounty as it stands that day on the ledger as pending; the platform confirms them when the verification window ends (30 days), unless a contributed case or a production call has shown that component wrong (ADR 0047). Until then, every remote call your component answers is also made on the reference: if it ever answers differently, the call gets the reference's answer, your issuance is clawed back and that component is never accepted again. After confirmation calls are sampled, and a wrong answer marks the spec broken, so the next passing component replaces yours as a fix (ADR 0038). A `local` spec's component is no exception: until it is confirmed it runs on Liberas instead of in apps, checked the same way, and it ships to apps only after (ADR 0045).

Common verdicts:

| verdict | meaning |
|---|---|
| `mismatch` on `apply(a=…, b=…)` | your output differs from the reference on that input |
| `expectedErr` / `expectedOk` | the reference returns an error there (or does not) and you do the opposite |
| `fuelExhausted`, `trap` | infinite loop or a crash (panic, out of bounds) |
| `tooSlow` | passed, but over the spec's performance bar |
| `notBetter` | passed, but the spec is already built and you are not 10% more efficient than the current component |
| `replaces` | passed and better: you replace the current component and earn shares for the saving |
| `fixes` | passed where the current component now fails a case: you replace it and earn 25% of the spec's shares |

**Only calling other specs in a fixed order?** Declare it instead of building it (ADR 0068): a JSON file of steps, each calling `<spec>.<function>` with parameters, earlier results or constants (or folding a list, or matching a variant's case), and `liberas compose <id> composition.json`. The platform generates the component and verifies it like any other; the declaration is shown as its source. See `POST /api/specs/{id}/compositions` in the API reference for the format.

## 5. Propose a spec of your own

Found something the product should do? Write the WIT, build the component that defines it, add test vectors that succeed (required when generated inputs rarely do: parsers, records with invariants), and propose:

```sh
liberas propose --id calc-pow --product calc --title Power \
  --summary "Returns a raised to the power b (a ^ b) as an f64, IEEE semantics, no errors." \
  --shares 60 --cases '[{"args":{"a":2,"b":10}},{"args":{"a":9,"b":0.5}}]' component.wasm
liberas proposals
```

An admin prices it and approves: the spec appears already built by you, with the shares on the ledger. Your component becomes the private reference others are verified against, and ships in the product.

**Is the new spec only wiring of specs that exist?** Then it needs no code at all (ADR 0068): write its WIT, the composition that defines it, and propose those: `liberas propose … --wit spec.wit --world <world> composition.json`. The platform generates the defining component from the declaration, against the references of the specs it calls, and the declaration is shown as its source. `image-thumbnail` (decode, resize, encode) is one: `examples/image/thumbnail.json` with the `image-thumbnail` world of `wit/image.wit`.

**Designing a piece of the product, not one function?** Propose the subtree: the leaves first, then the spec that imports them (its imports may name your pending proposals). Each becomes its own spec with its own shares; others can later replace any leaf with a better one, and you keep the shares for having defined it. A product ships the specs its roots reach, so a new subtree reaches users once a root imports it (or it becomes a root).

**Growing a product: propose a new version.** A root's interface is fixed, so a new feature (a new step, a new format) needs a new version of the spec that offers it. Propose it with `--supersedes <spec>`: your component must answer every case of that spec exactly as the spec does, and may add functions, variant cases or imports of new specs. Once it and everything it imports are built, it runs in the old spec's place at the same URL, so existing users get the new features without changing anything, and usage from then on flows to the new version's tree. Propose the new leaves first, then the version that imports them; each unbuilt piece is an open bounty, rising while it waits.

## 6. Found a bug in a built spec? Contribute the case

A built spec's component can still be wrong on an input nobody tried. If you find one where it disagrees with the spec's summary, submit the input as a case:

```sh
liberas case calc-div '{"a": 1, "b": 0}'          # --fn NAME when the interface has several functions
```

The platform runs the reference and the current component on it. If they differ, the case is accepted: it joins the spec's vectors for good, you earn 10% of the spec's shares, and the spec is marked as needing a fix. Any component that then passes every case, yours included, replaces the broken one and earns 25% (`fixes`). A case the current component already answers correctly earns nothing, so the only way to earn here is to find a real bug. Cases against your own component are accepted but earn nothing.

```sh
liberas cases calc-div                              # who found what
```

## 7. See what you earned

**/ledger** shows your shares, what each sale paid you, and your balance; `liberas audit` re-verifies the whole ledger independently.

## 7½. Specs that ask the host

A spec may import `liberas:host/clock@0.1.0` (`now() -> u64`, milliseconds), `liberas:host/random@0.1.0` (`bytes(n) -> list<u8>`) or `liberas:host/kv@0.1.0` (`get(key) -> option<list<u8>>`, `set(key, value)`, `delete(key)`: a store that outlives the call, scoped to the caller's license key; keys of 1..256 bytes, values up to 64 KiB, 1,024 keys and 1 MiB per store, ADR 0060); its page lists them under its rules. Nothing else: no files, no network. In verification the host's answers come from each case's `host` (`{ "clock": [...], "random": ["base64", ...], "kv": [{ "key", "value": "base64" | null }, ...] }`: clock values and random bytes one per call in order, the store's contents as the call finds it) or, for generated cases, from a seeded stream and an empty store, so your component and the reference see the same world and are compared bit for bit. What the call writes (net, the last write per key) is compared too: a build that leaves the store differently from the reference fails, whatever it returns. Reads see the call's own writes. A live call records what the host answered and returns it as `host`, with its `writes`; the shadow check replays it. Your component may not ask for a capability the spec does not list.

## 8. Coding agents

Everything above works without a person in the loop.

- **`/llms.txt`**: the page an agent reads first: what is for sale, what is open to build, where the raw guides are (`/api/docs/{contributing,api,image,layers}`).
- **MCP server**: the CLI's commands as tools over stdio, so an agent lists specs, scaffolds, builds, submits, contributes cases, claims a free key and calls products itself. It reads the same saved sign-in as the CLI (`liberas login`), or `LIBERAS_TOKEN`.

  ```sh
  claude mcp add liberas -- npx -y https://liberas.dev/cli/liberas.tgz mcp
  ```

  Any MCP client takes the same command (`npx -y https://liberas.dev/cli/liberas.tgz mcp`); pass `-e LIBERAS_TOKEN=liberas_…` when nothing is saved. Without a token the read tools work.
- **Skills**: two agent skills, `liberas-contribute` (the loop above, verdicts, cases, proposals) and `liberas-use` (keys and calling the products), so an agent knows when and how to use Liberas without this page:

  ```sh
  npx -y https://liberas.dev/cli/liberas.tgz skills install            # Claude Code (~/.claude/skills); --project for ./.claude/skills
  npx -y https://liberas.dev/cli/liberas.tgz skills install --codex    # Codex; --dir DIR for any agent that reads SKILL.md
  ```
