# acde RFC

acde RFC is the versioned standard for the TypeScript interface of the `acde:*` built-in modules: the modules the runtime injects into a page (`acde:fs`, `acde:window`, ...). It fixes which modules exist, what each one exports, the members of each export and their types, and which behavior a conformance test may check. Web standard APIs (the DOM, `fetch`, storage, ...) are not part of it: they follow the Web standards.

Each version is frozen in its own directory and ships with a runtime validator and a list of conformance tests, so a runtime (acdev runtime, the Dopame desktop, or any other implementation) can show that it implements a given version.

| | |
| --- | --- |
| Repository | `ssh://git@gitea.dopamine:2333/AC/acde-RFC.git` (`main` only) |
| Current version | [0.1](https://docs.dopame.ai/rfc/0-1.md), draft |
| Contract level of 0.1 | 1 (`acde:capabilities` `level`) |
| Source of the declarations | libacde `acde-api/` (`@dopame/acde-api`); the contract is still edited there, an RFC version freezes one commit of it |

## Versions

| Version | Status | Contract level | Source | Tests | Conformance on a real runtime |
| --- | --- | --- | --- | --- | --- |
| [0.1](https://docs.dopame.ai/rfc/0-1.md) | Draft (0.x) | 1 | libacde `acde-api/`, `@dopame/acde-api` 0.0.11, commit `09cf894` | 31 (3 marked `effects`) | Not run yet |

There is no 1.0 yet. The first stable version will be 1.0; from then on the compatibility rules below apply.

### Status values

| Status | Meaning |
| --- | --- |
| Draft (0.x) | Frozen as written, but the next minor version may change it incompatibly. Runtimes may target it; apps should not rely on it staying |
| Stable (x.y, x ≥ 1) | Frozen; later minor versions only extend it, so tests for x.0 still pass on x.y |
| Superseded | A newer version of the same major exists; still valid, no longer the target |

## Version rules

- A version is numbered `x.y`. It is independent of the runtime contract level (`api-level`, `capabilities.level`); each version names the level it targets in its `api-level` file. Version 0.1 targets level 1.
- **0.y (the draft series, now):** every minor version may make incompatible changes, and tests of an older version are not promised to pass on a newer one.
- **From 1.0:** a new `y` only extends the interface compatibly (new modules, new optional members, more values in a union, wider parameters); the tests of x.0 must still pass on x.y. Removing or renaming a member, narrowing a type, or changing specified behavior needs a new `x`.
- A published version's `api/`, `modules.json` and `RFC.md` never change. Errata go into the next minor version. A new version starts as a copy of the previous directory.

## Changes

All on 2026-11-21, in the acde-RFC repository:

| Commit | Change |
| --- | --- |
| `4dcf305` | First version, numbered 1.0: libacde `acde-api/` at `09cf894` (contract level 1) frozen as the declarations; `surface.json` generated from them; a plain-JS runtime validator; a test harness; the `runner/` app; the first tests (surface, capabilities, window, fs, terminal) |
| `111a78f` | Each test becomes a folder `tests/<name>-<x.y>/` with `index.js` as the entry, so a test can carry its own helpers and data |
| `bb24c6d` | Renumbered 1.0 → **0.1**: the RFC version no longer has to equal the contract level; 0.y becomes the draft series, compatibility rules start at 1.0. Test folders `-1.0` became `-0.1` |
| `3bbf237` | `surface.json` also records the awaited return type of each method and every exported interface, so tests check results deeply against the declarations (`t.call`, `t.conforms`) and subscribe to each declared event (`t.listen`). 22 new tests cover the remaining modules; tests that open windows or remember a default app are marked `effects` |

At each step `bun run check` and `bun run selftest` passed (selftest runs against fakes built from `surface.json`, which is not a conformance result). The runner has not been run on a real acde runtime yet.

## Repository layout

| Path | What |
| --- | --- |
| `rfc/<x.y>/RFC.md` | The rules the declarations cannot express (export shape, visibility, errors, versioning) |
| `rfc/<x.y>/api/` | TypeScript declarations: the source of truth for that version |
| `rfc/<x.y>/api-level` | The runtime contract level this version targets |
| `rfc/<x.y>/modules.json` | Visibility of each module: `capability`, `app` or `shell` |
| `rfc/<x.y>/surface.json` | Generated from `api/` (`bun run extract`), never edited: each module's members, each method's return type and every exported interface; read by the validator |
| `rfc/<x.y>/tests.json` | The tests that version requires |
| `tests/<name>-<x.y>/index.js` | Conformance tests, one folder each. `<name>` is `[A-Za-z0-9_]+`, `<x.y>` the version the test was written for; a later version may list the same test |
| `validator/surface.js` | Runtime validator: checks each `acde:` module against `surface.json` (plain JS, runs in a page) |
| `validator/harness.js` | The test runner used inside a page |
| `validator/check.ts` | Repository check: names, test lists, a fresh `surface.json`, level against version |
| `validator/selftest.ts` | Exercises the validator and the runner against fakes |
| `runner/` | An acde app that runs the validator and the tests on a real runtime |

When the declarations, the RFC text and `surface.json` disagree, `api/` wins, then `RFC.md`; `surface.json` is only derived.

## Running conformance

```sh
git clone ssh://git@gitea.dopamine:2333/AC/acde-RFC.git && cd acde-RFC
bun install
bun run extract        # regenerate rfc/*/surface.json from api/
bun run check          # repository check
bun run selftest       # validator self test (fakes, not a conformance result)
bun runner/prepare.ts  # copy specs and tests into runner/public
acdev dev runner       # run the runner app on a real runtime
```

The runner logs one line `acde-rfc {json}` and shows the same report in its window. Query parameters pick what runs: `?rfc=0.1&scope=shell` chooses the version and the scope (`app` or `shell`), and `&effects=1` also runs the tests marked `effects` (they open windows or change settings).

A runtime conforms to a version when the surface check and every applicable test of that version's `tests.json` pass. Tests skipped because a capability is unavailable are not failures, but the report lists them.

## Writing a test

`tests/fs_example-0.1/index.js`:

```js
export default async (t) => {
  const fs = await t.module('fs')
  t.type(await fs.roots(), 'array', 'fs.roots()')
}
```

`t` offers `module`, `load`, `call` (calls a method and checks the awaited result against its declared return type), `conforms` (checks a value against a named interface), `listen` (subscribes and unsubscribes each event), `surface`, `modules`, `available`, `ok`, `equal`, `type`, `oneOf`, `rejects`, `skip`, `rfc` and `level`.

- Other files sit next to `index.js` and are imported relatively; tests do not share files.
- List the folder (`{ "test": "fs_example-0.1", "scope": "app", "requires": ["fs"] }`) in the `tests.json` of every version it applies to, never one older than the version in its name.
- Assert only what `api/`, `RFC.md` or the libacde docs state. Check return values with `t.call` / `t.conforms` rather than by hand.
- Mark a test `"effects": true` when it changes visible state. Never call shutdown, logout, or methods that change network, Bluetooth or power settings.
