# Capabilities and limits

A plugin starts with nothing: it computes, and every capability beyond that is one the manifest asks for and the user grants.

![Blossom plugin sandbox and permission gates](/docs/sandbox.jpg)

> [!IMPORTANT]
> **Zero access by default.** A module runs inside an Extism WebAssembly sandbox with no WASI, so it cannot start a process, write a file, read the clipboard or draw a random number. A plugin in JavaScript runs in the QuickJS engine Blossom embeds, pinned by hash, under the same permissions and limits. Until a capability is granted, every function of the host answers `not_granted`.

## Capabilities

| Capability | The manifest asks with | What the plugin gets | Limits |
|---|---|---|---|
| **Network** | `network.hosts`, and `network.sends` for the hosts it posts to | `network::get` and `network::post` over `https` to a granted host | A body of 1 MiB, a posted body of 64 KiB of JSON, a redirect never followed, no proxy, only public addresses |
| **Credentials** | `network.credentials`, one per host, and `network.sendsWithCredential` | The header of the token the user typed, added by Blossom after every check | Kept in the Keychain, never readable by the plugin, joined to a `POST` only once *Sending with its token* is on |
| **Files** | `files.paths` under the home folder, written `~/…`, and `files.folders` the user chooses, read as `@name/…` | `files::read_text`, `files::read_window`, `files::entries` | Read-only: 1 MiB of text per file, 4 096 entries per folder, no writes and no clipboard |
| **Alerts**, version 2 | `permissions.alerts: true` | One alarm with `alarm::set`, then `wake` answering one alert | 60 seconds to a day ahead, 12 wakes and 6 alerts an hour |
| **Timers**, version 2 | nothing | A `timer` on the indicator and a block `timers` | Whole seconds since 1970; Blossom counts down without asking again |
| **A kept text**, version 2 | nothing | `storage::remember` and `storage::recall` | 4 096 bytes, kept across calls and restarts |
| **Settings** | `settings` | `settings::values()`, every declared key | Eight at most, 256 characters each, never a widening of what the plugin may reach |
| **The clock** | nothing | `clock::now()`, seconds since 1970 and the offset of the Mac | Whole seconds, standing still within a call |

## Every refusal is an answer

A function of the host never fails the call: it answers the value, or one of four refusals — `not_granted`, `not_allowed`, `too_large`, `failed`. Turn each into words of your own, as `status` turns `not_granted` into "Needs the network".

> [!WARNING]
> A call that panics, runs out of time or breaks the contract leaves the plugin **unavailable** until it answers well, and the host loads the module again, so whatever it remembered is gone.

## What a call may spend

| Limit | Value |
|---|---|
| Time | 2 seconds, shared by every request it sends |
| Work | 2 000 000 000 units of fuel |
| Memory | 256 pages, 16 MiB |
| Size of an answer, and of a module | 64 KiB, and 32 MiB |
| A name, a title, a label, a value | 128 characters |
| The label and the value of an indicator | 32 characters each |
| Commands, blocks, and the items of one block | 32 |

Every text is one plain line: nothing that reorders or hides. Pass what you read from a file or a server through `blossom_plugin::text::line(text, length)`.

> [!TIP]
> A plugin with both the network and files can send what it reads to the hosts it asked for, and the pane says so: ask for the least of each.
