Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ go.work
go.work.sum
.claude/
.dev-modules
wittymodule.exe
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# WittyModule

What a WittyMediaServer plugin needs to be a project of its own: the manifest, the rules for version ranges, the protocol a helper process speaks, and the tool that builds and signs a release. It's for people who make modules.
What a [WittyMediaServer](https://github.com/wittywilla/WittyMediaServer) module needs to be a project of its own: the manifest, the rules for version ranges, the protocol a helper process speaks, what a module adds to a server and to every app, and the tool that builds and signs a release. It's for people who make modules. WittyMediaServer's site is https://wittymediaserver.com.

**The specification** of a module, everything one is held to at module API 4 (and where API 3 differs), is [docs/SPEC.md](docs/SPEC.md): its manifest, delivery kinds, permissions, the helper protocol, its SDUI, releases and signing, catalogues and stores, withdrawals, forks, its status, and the overrides a server allows.
**The specification** of a module, everything one is held to at module API 5, is [docs/SPEC.md](docs/SPEC.md): its manifest, delivery kinds, permissions, the helper protocol, its SDUI, releases and signing, catalogues and stores, withdrawals, forks, its status, and the overrides a server allows.

<!-- pictures -->

Expand All @@ -16,6 +16,12 @@ What a WittyMediaServer plugin needs to be a project of its own: the manifest, t

<!-- /pictures -->

## How it fits

WittyMediaServer 0.8.0-alpha takes module API 5 only, with no backwards compatibility: a module built for an older API is refused and needs a new release. This version of WittyModule is module API 5 (`api: 5` in [module.json](module.json)). Every module in the store is built with it, and the server uses the same code to read and check what a module says about itself.

It's a library, not a module you install: a server gets it inside the modules built with it, so there's nothing to add from the store. Its own manifest gives WittyMediaServer 0.6.0-alpha through 0.8.x as its range, and a module built with it runs on a server that takes module API 5, which is 0.8.0-alpha and later in the 0.8 series. People add the modules themselves in **Settings → Modules → Browse the store → Add**.

## What it does

- **The manifest:** `module.json`, parsed and checked here.
Expand All @@ -30,23 +36,25 @@ func main() {
}
```

- **The module's SDUI (module API 4):** `sdui/` writes and checks the `sdui.json` every module carries: what it adds to every app, as data the server checks and every app draws. `kit/sdui/` is the same for web bundles in TypeScript. WittyMediaServer's docs/SDUI-MODULES.md describes it.
- **What a module adds to a server:** `integration.json`, which every installed module carries from module API 5: its routes, its web part, its own data, its lifecycle calls and its scan hooks. WittyMediaServer's docs/MODULES-API5.md describes it.
- **The module's SDUI:** `sdui/` writes and checks the `sdui.json` every installed module carries: what it adds to every app, as data the server checks and every app draws. `kit/sdui/` is the same for web bundles in TypeScript. WittyMediaServer's docs/SDUI-MODULES.md describes it.
- **Services:** `service/` is both ends of a helper that takes calls that overlap and connections a browser makes straight to it.
- **The catalogue:** the code that reads and checks a store's signed list of modules.
- **Withdrawing a version:** the signed list that takes a version back.
- **The `wittymodule` tool:**

| Command | What it does |
|---|---|
| `check` | Checks a folder's manifest and `sdui.json`, listing every problem by file and field |
| `check` | Checks a folder's manifest, `sdui.json` and `integration.json`, listing every problem by file and field |
| `pack` | Builds a release: a program for every system, or a browser bundle with `-web` |
| `sign`, `keygen` | Signs a checksum list, and makes a key |
| `bump`, `needs-bump` | Raises the version everywhere it's written, and fails if code changed since the last tag with no new version |
| `withdraw`, `restore` | Takes a version back, and undoes that |
| `catalog-add`, `catalog-check`, `catalog-sign` | Works on a store's catalogue |

- **`kit/`:** `kit/module-kit.sh` writes a module's workflows and the Releasing section of its README, and `kit/facade` writes the stubs a server uses to call a module.
- **`kit/`:** `kit/module-kit.sh` writes a module's workflows and the Releasing section of its README, `kit/facade` writes the stubs a server uses to call a module, and `kit/web` builds a module's web part.

The specification is [docs/SPEC.md](docs/SPEC.md). The reasoning behind it, including what each version range means, is in Making a module, in **Help** inside WittyMediaServer.
The reasoning behind the specification, including what each version range means, is in Making a module, in **Help** inside WittyMediaServer, and in the server's docs/MODULES.md.

## How to get it

Expand All @@ -60,18 +68,22 @@ go get github.com/wittywilla/wittymodule
go run github.com/wittywilla/wittymodule/cmd/wittymodule check .
```

A server gets it inside the modules built with it, so there's nothing to add from the store. Modules built with this version work with WittyMediaServer 0.6.0-alpha or later, through **Settings → Modules**, and nothing older.

## What it needs

Go 1.26 or newer. It has no dependencies, and no cgo.
Go 1.26 or newer. It has no dependencies, and no cgo. The TypeScript kit's tests need Node.js (CI uses 24).

## Platforms

It's plain Go, and CI builds it for Windows, macOS, Linux and FreeBSD. Its tests have been run on Linux, and `pack` has built modules for all four from there, including FreeBSD on amd64 and arm64. Those have not been run on a real Mac or on FreeBSD. `kit/module-kit.sh` needs bash.

## Building and testing

What CI runs:

```bash
go run ./cmd/wittymodule check .
```

```bash
go vet ./...
```
Expand All @@ -81,7 +93,7 @@ go test ./... -count=1
```

```bash
go run ./cmd/wittymodule check .
node --test kit/sdui/tests/*.test.mjs
```

A module's own `pack` and `sign` go like this:
Expand Down
43 changes: 21 additions & 22 deletions docs/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ is how an older server reads a newer manifest. `wittymodule.ParseManifest` reads
"license": "AGPL-3.0-or-later",
"delivery": "helper",
"entry": "wittyphotos-module",
"api": 4,
"api": 5,
"minServer": "0.8.0-alpha",
"maxServer": "0.8.x",
"group": "photos",
Expand All @@ -159,8 +159,8 @@ is how an older server reads a newer manifest. `wittymodule.ParseManifest` reads
| `style` | string | no | A web bundle's stylesheet, a file in the bundle; same pattern. |
| `programs` | list of strings | no | More programs that come with a helper or program, each built from `cmd/<name>`, same pattern, at most 64. Not for other deliveries. |
| `webEntry`, `webStyle` | string | no | The script and stylesheet of a helper's or program's part in the browser, in `web/` inside each archive. Same pattern. Not for other deliveries. |
| `api` | int | yes | The module API it was built for: at least 1 to parse; 3 or 4 to be released or run. |
| `minServer` | string | yes | The oldest server it fits, a version. At least `0.6.0-alpha` (`wittymodule.FirstServer`); for API 4, `0.8.0-alpha` in practice, the first server that reads `sdui.json`. |
| `api` | int | yes | The module API it was built for: at least 1 to parse; 5 to be released or run. |
| `minServer` | string | yes | The oldest server it fits, a version. At least `0.6.0-alpha` (`wittymodule.FirstServer`); for API 5, `0.8.0-alpha` in practice, the first server that takes it. |
| `maxServer` | string | yes | The newest server it fits: an exact version, or a series such as `0.8.x` or `0.x`. A lone `x` is refused. Must not be below `minServer`. See [section 6](#6-compatibility). |
| `capabilities` | object of string lists | no | Facts a server needs without starting the program, such as `rawExtensions` and `logTopics` ([section 15](#15-logging-and-capabilities)). Keys, values and lengths together at most 4,096 bytes. |
| `permissions` | list of strings | no | `network`, `programs`, `devices`, `data` ([section 7](#7-permissions-and-limits)); at most 64 entries. Any other word is refused by `wittymodule`; a server that doesn't know a permission won't run the version. |
Expand All @@ -172,7 +172,7 @@ is how an older server reads a newer manifest. `wittymodule.ParseManifest` reads
| `libraries` | list of strings | no | Kinds of library that need it, at most 64. Only the kinds a signed catalogue lists for a module count. |
| `requires` | list of strings | no | Module IDs it is built on, installed first; at most 64. |
| `core` | bool | no | Other modules can't do without it, so it can't be taken off a server. |
| `pages` | list | no | Pages its web part draws in the web app (API 3's way): at most 16, only with a part in the browser. Each: `id` (`^[a-z][a-z0-9-]{0,63}$`, unique), `title` (one line of plain text, 1 to 64 bytes), `where` (`main` or `settings`), `icon` (a word, optional), `admin` (bool). |
| `pages` | list | no | Pages its web part draws in the web app ([section 10](#10-web-parts)): at most 16, only with a part in the browser. Each: `id` (`^[a-z][a-z0-9-]{0,63}$`, unique), `title` (one line of plain text, 1 to 64 bytes), `where` (`main` or `settings`), `icon` (a word, optional), `admin` (bool). |
| `status` | string | no | `stable` (the same as leaving it out), `beta`, `experimental` or `incomplete` ([section 4](#4-status-saying-a-version-is-unfinished)). |
| `statusNote` | string | for `experimental`, `incomplete` | One line of plain text, at most 500 characters, with no control characters: what isn't done or may break. |

Expand All @@ -196,15 +196,15 @@ what doesn't work yet, what may break, and what is safe.

The status is the release's own: a server goes by the signed manifest it downloaded, never by what
a catalogue says. A catalogue entry carries a copy ([section 18](#18-the-catalogue)) so a store can
show it before anything is downloaded. A server older than module API 4 ignores both fields.
show it before anything is downloaded.

`wittymodule check` passes an `experimental` or `incomplete` module and prints a warning naming its
status and note. `Manifest.Unfinished()` says whether a version is one of those two, and
`StatusOrStable()` gives `stable` for a version that says nothing.

## 5. Delivery kinds

| `delivery` | A release holds | How it runs | `sdui.json` from API 4 |
| `delivery` | A release holds | How it runs | `sdui.json` |
|---|---|---|---|
| `helper` | An archive per system: the program `entry`, any `programs`, an optional part in the browser under `web/`, `module.json`, `sdui.json`, `LICENSE`, `NOTICE`, `THIRD-PARTY-NOTICES.txt`, `README.md` if there is one | A separate process the server starts on first use and talks to over pipes ([section 8](#8-the-helper-protocol)). It may also be a [service](#9-services). The only kind that may answer SDUI data sources | Required |
| `program` | The same as a helper | The server starts it for one job, in that job's own protocol. It must also answer the hello when started as a helper, so an install can check it runs | Required |
Expand Down Expand Up @@ -236,8 +236,8 @@ A version fits a server when all of these hold (`Manifest.Supports`, with the se

**How a server reads `0.N.x`.** `wittymodule` reads a range exactly as above. A server reads any
pre-1.0 series `0.N.x` as `0.x` (`internal/modules/widen.go`), because before 1.0 the module API
number decides whether a version fits: a module released beside 0.6 for API 3, with `maxServer:
0.6.x`, runs on 0.8.0-alpha, which takes API 3 and 4, and a store offers it there. An exact
number decides whether a version fits: a module released for API 5 with `maxServer: 0.8.x` can run
on a later 0.N server that still takes API 5, as a version made for an older server. An exact
`maxServer` is kept as written, and a 1.x server is another line. So set `maxServer` to the series
you tested with; on a pre-1.0 server it is advice, and the API is the rule.

Expand Down Expand Up @@ -299,7 +299,7 @@ A helper (and a program, for its hello) speaks this over its standard input and
|---|---|
| `WITTYMODULE_LOG` | `debug`, `info`, `warn`, `error` or `off` |
| `WITTYMODULE_LOG_TOPICS` | The log topics that are on, comma-separated |
| `WITTYMODULE_SETTINGS` | The module's server settings with defaults, secrets included, as a JSON object (API 4, [section 12](#12-settings)) |
| `WITTYMODULE_SETTINGS` | The module's server settings with defaults, secrets included, as a JSON object ([section 12](#12-settings)) |
| `WITTYMODULE_DATA` | Its own folder to write in, with `data` |
| `WITTYMODULE_WRITE` | Other folders it may write in, with `data` |

Expand Down Expand Up @@ -343,7 +343,7 @@ wrong — the process ending, an unreadable line, a size out of range, a wrong `
— is a **failure**. A panic in a `Serve` handler becomes a call error with code `panic`. A method the
helper doesn't know should be answered with a call error (a service answers `unknown-method`).

**Notifications** (API 3). A helper may say things unasked, at any time while it is serving, from
**Notifications.** A helper may say things unasked, at any time while it is serving, from
any goroutine (`wittymodule.Notify`). A notification has `notify` and no `id`, and nothing answers it:

```
Expand Down Expand Up @@ -400,7 +400,7 @@ connections a browser makes straight to it. Its manifest says `delivery: helper`
A request with no `X-Witty-User` didn't come from a signed-in person and should be refused.
6. It answers `service.busy` with whether it has work going on (`Config.Busy`). It is stopped about
five minutes after its last use unless busy, and one that dies is started again on the next call.
7. From API 4 it answers the SDUI calls of [section 11](#11-the-sdui-contribution) on the helper
7. It answers the SDUI calls of [section 11](#11-the-sdui-contribution) on the helper
protocol through `Config.UI`.

A service is held to a helper's limits, except where its permissions and the server's list allow
Expand All @@ -416,19 +416,19 @@ the module API; removing anything from it breaks bundles already released.
A bundle that fails to load or crashes is reported to the server. Three reports in a day from an
administrator's browser take that version out of use; anyone else's go in the module's log.

API 3's manifest `pages` are drawn by the bundle at `/m/<module>/<page>`, in the web app only. Each
The manifest's `pages` are drawn by the bundle at `/m/<module>/<page>`, in the web app only. Each
page component gets `host`: `request(method, path, body?)` to this server's API with the viewer's
access (any other address is refused), `user` (`{admin}`), `store` (`get`, `set`: at most 64 KB a key
and 32 keys, per person and module), and `token()` and `base()` for a stream. `admin: true` only hides
a page; what it calls must check for itself. From API 4 a module should describe its pages in
a page; what it calls must check for itself. A module should rather describe its pages in
`sdui.json` instead, which every app draws, and use a `NativeView` where only its web part can draw
something.

## 11. The SDUI contribution

From module API 4, **every module a server installs** (`helper`, `program`, `web`) **must carry
`sdui.json`**: what it adds to every app, as data the server checks against its catalogue and every
app draws with its own components. A version built for API 4 without one is refused, and one whose
**Every module a server installs** (`helper`, `program`, `web`) **must carry `sdui.json`**: what it
adds to every app, as data the server checks against its catalogue and every app draws with its own
components. A version without one is refused, and one whose
file fails the server's checks is refused, unless an administrator agrees to run it without its SDUI
([section 22](#22-overrides), kind `incomplete`). The full format is WittyMediaServer's
**`docs/SDUI-MODULES.md`**; the code is `pkg/sdui/module.go` there, and WittyModule's `sdui` package
Expand Down Expand Up @@ -603,7 +603,7 @@ version didn't.
256 MiB).
3. Unpack it to a work folder, refusing links, devices, absolute paths and climbing paths.
4. Check every file against the list, refusing any extra or missing file; then read `sdui.json` and
check it against the server's SDUI catalogue (required from API 4).
check it against the server's SDUI catalogue (required).
5. Start the program once with `--wms-helper`; its hello must name the same module, version and API.
6. Move the folder to `versions/V` in the module's data folder, and save the state atomically.
7. Switch over: the next call uses the new version, with no restart.
Expand Down Expand Up @@ -784,7 +784,7 @@ simply refuses as before). This section is the contract a module and a store can

| Kind | When | Severity |
|---|---|---|
| `incomplete` | `status` is `experimental` or `incomplete`; or an API-4 version has no `sdui.json`, or one that fails the server's catalogue (the module then runs **without** its SDUI) | 1 |
| `incomplete` | `status` is `experimental` or `incomplete`; or a version has no `sdui.json`, or one that fails the server's catalogue (the module then runs **without** its SDUI) | 1 |
| `out-of-range` | This server is outside `minServer`..`maxServer` while the API is within the server's range ("compatibility mode": the range is ignored) | 2 |
| `local-file` | Installed from an uploaded file rather than a catalogue | 2 |
| `custom` | A module ID this server doesn't know | 3 |
Expand Down Expand Up @@ -842,14 +842,13 @@ warning: module.json: status: this version says it is incomplete: No settings pa
It checks the manifest on its own (`Manifest.Problems`), that the folder is named for the module, that
`api` is one this WittyModule knows and `minServer` isn't older than `0.6.0-alpha`, that a helper's
`cmd/<entry>` exists (or `CMakeLists.txt` for a program built otherwise), that `package.json`'s
version matches, `sdui.json` exactly as a server checks it (required from API 4; data sources only on
a helper), and with `-server` that the version fits that server under the strict reading of
version matches, `sdui.json` exactly as a server checks it (required; data sources only on a helper), and with `-server` that the version fits that server under the strict reading of
[section 6](#6-compatibility). The SDUI checker's warnings are printed and don't fail it, and nor does
an unfinished status, which is printed as a warning. `pack` runs the same checks first.

For a catalogue: `wittymodule catalog-check [-pub key] catalog.json`, and in WittyModuleCatalog
`scripts/check-api.mjs`, which checks what a server decides: the module API, an API-4 version's
`minServer`, and `status` with its note.
`scripts/check-api.mjs`, which checks what a server decides: the module API, a version's
`minServer`, `integration.json`, and `status` with its note.

## 24. Older module APIs

Expand Down
Binary file removed wittymodule.exe
Binary file not shown.
Loading