> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leverine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# The Leverine Module Contract

> Leverine File Handler — the mobile file manager: an encrypted vault, browsing, and real background transfers between your devices.

# The Leverine Module Contract

Working paper for the roadmap (TASKS.md Task 1), written 2026-11-23. Status: draft for Kev’s review. Companion to `docs/core.md`, which defines what the core owns. This document defines what a module is: what it must declare, what it may expect from the core, and the rules it lives under. Section 7 validates the contract against Bifrost, the demo module.

Design stance: the contract is written for the paid modules first — Terminal, Discover, Sync & Automate, Media are the business. Demo and future modules must fit the same contract, not bend it.

***

## 1. What a module is

A module is a compiled-in, entitlement-gated feature pack that:

* declares itself in a **manifest** (§2),
* contributes UI and behaviour through defined **entry points** (§3),
* may register **host types and file providers** (§4),
* works only through **core APIs** (§5),
* and follows the **rules** (§6) — no exceptions, including for the demo module.

A module is independently enable-able and removable. Removing or disabling a module never breaks the core or the user’s Vault data (§6.4).

## 2. The manifest

Every module ships a manifest the registry reads before loading it:

| Field | Meaning |
| - | - |
| `id` | Stable reverse-domain id, e.g. `com.leverine.module.terminal`. Never changes. |
| `name` | Display name shown in the shell, settings, and store listing. |
| `version` | The module’s own semantic version. |
| `moduleApi` | Range of core Module API versions it supports (see core.md §4). |
| `entitlement` | `free`, a store SKU for this module, or `pro-bundle`. |
| `capabilities` | The capabilities it requests (§5.2). Anything not declared is denied. |
| `hostTypes` | Host types it registers, if any (§4). |
| `endpoints` | Network endpoints it will contact, by host pattern — `none` is a valid, encouraged answer. |
| `background` | Whether it needs background execution, and why (shown to the user). |
| `dataExport` | What user data it stores outside the Vault, so export and module removal can account for it. |

An invalid manifest, an unsupported Module API range, or a failed entitlement check means the module does not load — and the core says why, in plain language (core.md §2.5).

## 3. Entry points — how a module appears

A module may contribute only through these slots, rendered and navigated by the shell:

1. **Screen** — a full screen in the app’s navigation (Terminal’s console, Media’s player).
2. **Host action** — an action on a Vault host (“Open terminal”, “Connect via bridge”), shown only for host types the module supports.
3. **File action** — an action on files/folders in Browse (“Play”, “Sync this folder”).
4. **Settings section** — its own settings, rendered by the shell from the module’s declaration.
5. **Background service** — declared in the manifest, visible in settings, stoppable from the per-module kill switch.

There is no “run arbitrary UI anywhere” entry point. If a real module needs a sixth slot, the contract grows by decision, not by workaround.

## 4. Registering host types & providers

* A module may register a **host type**: a named kind of Vault entry with its own configuration fields (no secrets inline — secrets are keystore references held by the Vault) and its own connection test.
* A module that registers a host type and wants file browsing must also register a **file provider** implementing the core’s provider interface (list, stat, read, write, rename, delete, mkdir, size/hash confirmation on writes). All transfers for that provider go through the core Transfer Engine.
* Host types outlive their module: if the module is disabled or unentitled, its hosts remain visible in the Vault, marked unavailable, with their configuration intact. The user’s data is never held hostage by a module’s state.

## 5. What the core gives a module (APIs)

### 5.1 Services

* **Vault API** — read hosts of the types the module supports; request a connection session for a host. The module receives a live session, not credentials: authentication happens inside the core.
* **Transfer API** — enqueue transfers, receive progress/completion.
* **Shell API** — present screens, actions, approval sheets, and prompts (rendered by the core, requested by the module).
* **Storage API** — a private per-module storage namespace (settings, caches). Modules cannot read each other’s namespaces.
* **Log API** — append to the core audit log.
* **Entitlement API** — ask “am I entitled?” only. Receipts and store interaction are core-only.

### 5.2 Capabilities

Capabilities are the unit of permission. Examples: `network`, `network.tailscale`, `host.connect`, `host.command` (run commands on a host), `files.read`, `files.write`, `background`, `discovery.lan` (mDNS/Bonjour), `media.playback`.

* Declared in the manifest; anything undeclared is denied at runtime.
* Sensitive capabilities (`host.command`, `files.write`, `background`) trigger a first-use consent prompt from the core, naming the module.
* A capability is granted to a module, never ambient in the app: the core can report, per module, exactly what it is allowed to do — this list is shown in the module’s settings section.

## 6. The rules

1. **No raw secrets.** A module never sees a private key or a stored password/token. It gets sessions and scoped handles from the core.
2. **No side channels.** No network except declared endpoints, no file movement except the Transfer Engine, no persistence except its storage namespace and the Vault (through registration).
3. **Approval before action.** Running a command, deleting, or overwriting requires a core-rendered approval sheet. A module cannot pre-approve, batch-approve silently, or render its own lookalike.
4. **Removable without damage.** Disabling a module stops its background work, removes its entry points, and leaves Vault data intact (§4). Uninstalling its entitlement (refund) behaves the same way.
5. **Failure is contained.** A crashing module is disabled by the registry and reported; the core and other modules keep running.
6. **Honesty in the manifest.** Capabilities, endpoints, and background needs are declared up front. A module found using more than it declared is a contract violation and a release blocker.
7. **No ads hooks.** Modules have no advertising surface. (Free-tier ads, if any, are a shell concern and never appear in the terminal.)
8. **First-party only (decided 2026-11-23, Kev).** Modules are Leverine’s monetization: proprietary, closed, and sold, never an open platform. The core loads only modules bundled with the app and built by us; integrity is verified at load (core.md §2.5), and any foreign, unsigned, or modified module is refused and logged. There is no sideloading mechanism, no module store for others, and no public module SDK — and the contract deliberately provides no hooks from which one could be improvised.

## 7. Validation: the contract against the real modules

### 7.1 Terminal (paid)

Manifest: `host.command`, screen + host action entry points, no network of its own (it rides Vault sessions). Fits cleanly — this is the module the contract was shaped by.

### 7.2 Discover (paid)

Manifest: `discovery.lan`, `network.tailscale`, host actions that add found machines to the Vault. Needs the core to accept module-proposed hosts — covered by Vault registration (§4) plus a user confirmation before a discovered host is saved.

### 7.3 Sync & Automate (paid)

Manifest: `background`, Transfer API scheduling, storage for rules. Manual export stays core and free (core.md §2.9); this module sells automation, not access to the user’s own data. Fits.

### 7.4 Media (paid)

Manifest: `media.playback`, file actions on Browse, read-only file access through providers. Fits.

### 7.5 Bifrost — the demo module (bundled free with the core)

Purpose: demonstrate the module system end-to-end with a real, working feature — connecting Leverine to machines that run the Bifrost bridge (the Termux/Tailscale HTTP command bridge from Kev’s homelab), instead of or in addition to SSH.

Against the contract:

* **Host type:** registers a `bridge` host type in the Vault — fields: bridge URL (Tailscale address), port; the bridge token is a Vault secret (keystore reference), never inline. ✔ §4
* **Capabilities:** `network.tailscale`, `host.connect`, `host.command`. `host.command` is sensitive → first-use consent prompt names Bifrost and says plainly that it can run commands on the machine. ✔ §5.2
* **Entry points:** host action (“Connect via bridge”) and a screen showing bridge health, reachable peers (the bridge’s getvirtualaddress / getvirtualsubnet data), and a command pane. ✔ §3 — no new slot needed.
* **Approval:** every command goes through a core approval sheet until the user grants a standing approval — granted per host + module, core-stored, revocable in settings, and re-asked after 30 days (decided 2026-11-23, §8 Q2). ✔ §6.3
* **Files:** v1 of the demo does not register a file provider (the bridge is a command channel, not a file system). If a later version adds file access, it must implement the provider interface and use the Transfer Engine like everyone else. ✔ §4, §6.2
* **Entitlement:** `free`, bundled with the core as the demo of what a module is. ✔ §2

**Verdict:** the contract expresses Bifrost without bending. The one strain it reveals is worth noting: Bifrost’s value is mostly *command* execution, while the paid modules are mostly *file* features — the capability list and approval flow carry that difference, which is what they are for.

**Store-policy note (resolved 2026-11-23):** remote commands on the user’s own machines are permitted on both stores — every SSH client does this; Apple guideline 2.5.2 restricts code executed *inside the app*, not commands sent to a remote host. Expect review questions, so the Launch phase includes review notes and a demo bridge endpoint for the reviewer. **Decided (Kev, 2026-11-23):** Bifrost ships in the store build, free, behind a disclosed “show demo modules” toggle — see core.md §5 for the full distribution model.

## 8. Open questions for Kev

1. ~~First-party only at launch, or third parties later~~ — decided 2026-11-23 (Kev): **first-party only, permanently.** Modules are the monetization strategy, proprietary and closed; effort goes into enforcement (§6 rule 8), not an ecosystem.
2. ~~Standing approvals for `host.command`~~ — decided 2026-11-23 (Kev): **per host + module**, core-stored, revocable in settings, re-asked after 30 days.
3. ~~Demo modules enable-by-default or opt-in~~ — decided 2026-11-23: opt-in, behind the “show demo modules” toggle (core.md §5).
4. Module API versioning starts at 1 with the MVP — confirm the Terminal module ships against API 1 so the contract gets its first real test in the MVP phase, not the Pro phase. *(Still open.)*

***

*Source: Leverine/Leverine-File-Handler\@3c51ed8 — `docs/module-contract.md`.*


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.