diff --git a/AGENTS.md b/AGENTS.md index 26cb9b92..eb1224a3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -112,8 +112,11 @@ agent's in-flight work. Say where the worktree is, and remove it once the work h - **Changelog**: anything that changes what the dashboard, the admin or a widget can do gets a line under `## Unreleased` in `CHANGELOG.md`, in the same commit, written for the person using Fremkit (not the commit subject). A release is its own commit: rename the section, - bump the four `version` fields (`package.json`, `server/`, `ui/`, `server/src/version.ts` — - the registry compares a widget's `sdk` against that one) and tag `vX.Y.Z`. + bump the four `version` fields (`package.json`, `server/`, `ui/`, `server/src/version.ts`) + and tag `vX.Y.Z`. A widget's `sdk` is compared against `SDK_VERSION` in + `server/src/bridge/sdk.ts`, not against the release: it goes up when the bridge gains a member + a widget may rely on, in the commit that adds it (`bridge.test.ts` refuses a member no + generation lists). - **Tests before done**: `pnpm typecheck` and `pnpm test` green, the UI rebuilt if touched, a rescan if a manifest changed, and — for anything visible — a look at `/admin` or `/` in a browser. The widget catalogue test in `server/test/` reads the real `widgets/` folder, so a diff --git a/CHANGELOG.md b/CHANGELOG.md index 760ce9ef..03727f47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,21 @@ What changed for the person using Fremkit, release by release. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow semver, and the -version is the one `FREMKIT_VERSION` carries — the registry compares a widget's `sdk` against it. +version is the one `FREMKIT_VERSION` carries. A widget's `sdk` is a separate number, +`SDK_VERSION` in `server/src/bridge/sdk.ts`, that moves only when the bridge grows. Anything that changes what the dashboard, the admin or a widget can do gets a line under -**Unreleased** in the same commit. A release renames that section, bumps the three `0.x.y` -(`package.json`, `server/package.json`, `server/src/version.ts`) and is tagged `vX.Y.Z`. +**Unreleased** in the same commit. A release renames that section, bumps the four `0.x.y` +(`package.json`, `server/package.json`, `ui/package.json`, `server/src/version.ts`) and is +tagged `vX.Y.Z`. ## Unreleased ### Added +- **Widget SDK 2.** For widget authors: `Fremkit.sdk` is now `2`, the generation that brought + `favicon()`, `image()`, `installedApps()` and `appIcon()`. A widget that calls them declares + `"sdk": 2`, and an older Fremkit then says it needs an update instead of installing it broken. + Widgets declaring `1` keep installing as before. - Add read-only Codex account quotas, token usage, selected local chats and observed turns. Enable account reads or select history sources in the admin screen privacy settings; both start off. History selection explains that titles and labels reach subscribed widgets. A chat opens only after exact-ID validation against the local desktop catalog. Account email is not sent to widgets. Removing a history source or disabling account reads also removes its cached fields if the next Codex read fails. ### Changed diff --git a/docs/marketplace.md b/docs/marketplace.md index a5ffe81f..b686dea5 100644 --- a/docs/marketplace.md +++ b/docs/marketplace.md @@ -161,8 +161,9 @@ whoever owns a DNS record. Neither trusts the other. - The package must be a plain folder: no dotfile, no symlink, no nested archive, no absolute or climbing path, at most 200 files, 5 MB packed, 20 MB unpacked. - The manifest must validate, its `id` must be the one you asked for, and its `sdk` must be one - this Fremkit speaks. A widget asking for a newer SDK says "needs a newer Fremkit" rather than - installing and half-working. + this Fremkit speaks — any generation up to its own, since a generation only adds to the bridge + (see [SDK generations](writing-widgets.md#sdk-generations)). A widget asking for a newer SDK + says "needs a newer Fremkit" rather than installing and half-working. - `permissions.network` may not name a private, loopback or link-local host — the same rule a built-in lives under, so a widget cannot use the proxy to read your own machine. diff --git a/docs/writing-widgets.md b/docs/writing-widgets.md index 02100555..675eb26c 100644 --- a/docs/writing-widgets.md +++ b/docs/writing-widgets.md @@ -58,7 +58,7 @@ dropped in by hand is reported as an error while the built-in keeps the id. | `commands` | no | The channels it may send commands to. Default `[]` | | `permissions.network` | no | Hosts `Fremkit.fetch` may reach. Default `[]` | | `settingsSchema` | no | The settings the admin offers — see below. Default `{}` | -| `sdk` | no | The bridge generation the widget needs (`Fremkit.sdk`). Default `1`; a widget asking for more than the server has is refused at install | +| `sdk` | no | The bridge generation the widget needs (`Fremkit.sdk`) — see [SDK generations](#sdk-generations). Default `1`; a widget asking for more than the server has is refused at install | | `homepage` | no | An `https` URL, shown in the admin. Never fetched, never executed | | `author` | no | A name, shown in the admin | | `license` | no | An [SPDX](https://spdx.org/licenses/) identifier — `MIT`, `Apache-2.0` | @@ -200,6 +200,24 @@ Fremkit.whenReady(() => { }) ``` +### SDK generations + +`Fremkit.sdk` and the manifest's `sdk` count *generations* of this bridge, not Fremkit releases. +A generation only adds members, so a widget declaring `1` keeps installing and running on every +Fremkit that speaks `2` or more. Declare the lowest generation that has every member you call; +a Fremkit older than that refuses the widget at install, with "needs a newer Fremkit", instead of +installing it and leaving the call to fail. + +| `sdk` | First Fremkit | What it adds | +|---|---|---| +| `1` | 0.2.0 | Everything not listed below | +| `2` | 0.3.0 | `favicon(url)`, `image(url)`, `installedApps()`, `appIcon(bundleId)` | + +A widget calling `installedApps()` with `"sdk": 1` would install on 0.2.0 and find the method +missing. Data channels are not generations: a channel the running Fremkit has no provider for +simply never sends anything, so a widget subscribing to one should show its empty state rather +than wait. + ### Properties | Name | What it is | diff --git a/server/src/bridge/fremkit.js b/server/src/bridge/fremkit.js index 1d5bbd67..4f30b862 100644 --- a/server/src/bridge/fremkit.js +++ b/server/src/bridge/fremkit.js @@ -129,7 +129,7 @@ * lowest generation it needs, and the server refuses to install one asking for more than it * has. Kept in step with `SDK_VERSION` in ./sdk.ts by bridge.test.ts. */ - sdk: 1, + sdk: 2, instanceId: null, settings: {}, /** diff --git a/server/src/bridge/sdk.ts b/server/src/bridge/sdk.ts index 00024f9b..3a774b2f 100644 --- a/server/src/bridge/sdk.ts +++ b/server/src/bridge/sdk.ts @@ -10,4 +10,24 @@ * The bridge repeats the number as a literal (`Fremkit.sdk`), because it is a plain browser * script with no imports; `bridge.test.ts` holds the two together. */ -export const SDK_VERSION = 1 +export const SDK_VERSION = 2 + +/** + * What each generation put on the `Fremkit` global, by name. + * + * Generations only add: a widget written for 1 still installs and runs on a build that speaks 2, + * because the comparison is `manifest.sdk > SDK_VERSION`. `bridge.test.ts` refuses a member of + * the bridge that no generation lists, so a new helper cannot ship without someone deciding + * whether it needs a new generation — the miss that let `installedApps` and `appIcon` reach a + * build still saying 1. + */ +export const SDK_GENERATIONS: Readonly> = { + 1: [ + 'ready', 'sdk', 'instanceId', 'settings', 'locale', 'tokens', + 'accentMode', 'accentColor', 'onSurface', 'showTitle', 'compact', 'slot', 'size', + 'whenReady', 'subscribe', 'sendCommand', 'fetch', + 'esc', 'el', 'color', 't', 'onResize', 'onSettings', 'onLocale', + ], + // Fremkit 0.3.0: images a sandboxed frame cannot load itself, fetched by the host. + 2: ['favicon', 'image', 'installedApps', 'appIcon'], +} diff --git a/server/test/bridge.test.ts b/server/test/bridge.test.ts index 08ce853e..e0c28129 100644 --- a/server/test/bridge.test.ts +++ b/server/test/bridge.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect } from 'vitest' import { readFile } from 'node:fs/promises' import { fileURLToPath } from 'node:url' -import { SDK_VERSION } from '../src/bridge/sdk.js' +import { SDK_GENERATIONS, SDK_VERSION } from '../src/bridge/sdk.js' /** * The bridge is a plain browser script, injected into every widget. It is evaluated here against @@ -94,6 +94,25 @@ describe('Fremkit.sdk', () => { // bridge cannot honour, which is exactly what the number exists to prevent. expect(F.sdk).toBe(SDK_VERSION) }) + + it('lists every member of the bridge under a generation this build speaks', () => { + // A helper added to the bridge without a generation is one a registry widget could call on + // an older Fremkit, which would install it and leave it broken. Listing it forces the call: + // a new generation (and a bump of SDK_VERSION), or a member nothing may rely on. + const generations = Object.keys(SDK_GENERATIONS).map(Number) + expect(Math.max(...generations)).toBe(SDK_VERSION) + const listed = new Set(Object.values(SDK_GENERATIONS).flat()) + expect(Object.keys(F).filter((name) => !listed.has(name))).toEqual([]) + }) + + it('exposes what each generation after the first added', () => { + // The first generation includes `tokens`, set only once a theme arrives; the later ones are + // methods, there from the start, and a widget asking for their generation calls them blind. + for (const [generation, names] of Object.entries(SDK_GENERATIONS)) { + if (Number(generation) === 1) continue + for (const name of names) expect(typeof (F as unknown as Record)[name], name).toBe('function') + } + }) }) describe('Fremkit.esc', () => { diff --git a/server/test/marketplace-install.test.ts b/server/test/marketplace-install.test.ts index 728d8fb4..f5fd8225 100644 --- a/server/test/marketplace-install.test.ts +++ b/server/test/marketplace-install.test.ts @@ -75,6 +75,15 @@ describe('readPackage', () => { expect(() => readPackage(zip, expected(zip))).toThrow(expect.objectContaining({ key: 'marketplace.idMismatch' })) }) + it('accepts every generation up to this build, the first included', () => { + // Generations only add to the bridge, so a widget published for an older one keeps working. + for (let sdk = 1; sdk <= SDK_VERSION; sdk++) { + const zip = packageOf({ sdk }) + const read = readPackage(zip, expected(zip)) + expect(read.kind === 'widget' && read.manifest.sdk).toBe(sdk) + } + }) + it('refuses an SDK newer than this build', () => { const zip = packageOf({ sdk: SDK_VERSION + 1 }) expect(() => readPackage(zip, expected(zip))).toThrow(expect.objectContaining({ key: 'marketplace.sdkTooNew' }))