Skip to content

Adopt ADR-082's contribution contract: ids, when() predicates, keyed and isolated outlets #3310

Closed

Description

@mstomar125

Summary

Switch the UI-extension registry from Pro variants to ADR-082's (proposed) contribution contract. Neither app changes visibly.

  • The contract. A NodespaceExtension carries apiVersion. Each contribution is { id, when?, priority?, load }, and hosts key it by <extension id>/<contribution id>.
  • Registration rules. A duplicate extension id, a version mismatch or a duplicate contribution id is logged and dropped, never thrown.
  • The built-in Pro extension (pro-plugin.ts):
  • Hosts:
    • ChromeSlotOutlet replaces the app shell's inline slot loops.
    • ExtensionOutlet gains a load-failure path and a <svelte:boundary>.
    • The collection viewer keys its tabs by contribution key.
  • Tests. A test fixture extension, plus generic registry and outlet tests that import nothing Pro.

Context

Paths are under packages/desktop-app/. Line hints are at af8ddb61; after #3309, locate code by symbol.

Registry files:

  • src/lib/plugins/ui-extensions.ts:
    • ChromeContribution and ViewerExtension both have variant and lazyLoad;
    • ViewerExtension has tab: { appliesTo, id, label };
    • UiExtensionDefinition is { id, name, version, chrome?, viewerExtensions? };
    • UiExtensionRegistry.register() replaces by id.
  • src/lib/plugins/ui-extensions.svelte.ts: the getActive* accessors filter with c.variant === resolveProSyncVariant().

src/lib/plugins/pro-plugin.ts:

  • proSyncUiExtension, which nothing else imports: 3 modal contributions (consent, relogin, connected) and 4 collaboration tab contributions (sign-in, consent, relogin, connected).
  • The tabs all share tab.id: 'collaboration', so the selected tab survives a variant change.
  • It registers itself as a side effect.

Hosts:

  • src/lib/components/layout/app-shell.svelte:
    • L37-38: imports;
    • L692-702: the overlay slot <div class=pro-sync-pill-slot>, keyed by c.variant. No extension contributes to it today.
    • L732-736: the modal slot, keyed by c.variant;
    • CSS: L804 and L807-815.
  • src/lib/components/viewers/collection-node-viewer.svelte:
    • L26-38: imports, Pro comments and collabExtensions;
    • L262-285: the tab strip, keyed by tab.id;
    • L287-291: {#key activeExtension.variant}.
  • src/lib/plugins/extension-outlet.svelte: {#await load() then mod} with no failure path.

Pro wrapper components:

  • src/lib/components/collaboration/collaboration-tab.svelte wraps CollaborationView.
  • collaboration-locked.svelte is the placeholder.
  • pro-relogin-slot.svelte already tolerates being remounted on a variant change; see its header.

ADR-082 rules:

  • §2.1: a duplicate extension id logs an error and keeps the first registration. An apiVersion mismatch is logged and the extension is not registered.
  • §2.3: hosts key by <extension id>/<contribution id>. Order is descending priority, then registration order.
  • §2.4: a throwing when() counts as false and is logged once. A rejected load() renders nothing and is logged. A throwing component removes only its own outlet.

Scope

1. The contract, in src/lib/plugins/ui-extensions.ts

export const EXTENSION_API_VERSION = { major: 1, minor: 0 } as const;

export interface Contribution<P extends Record<string, unknown> = Record<string, never>> {
  id: string;              // unique within its extension, across all contribution lists
  when?: () => boolean;    // reactive and pure; absent = always shown
  priority?: number;       // higher renders first; default 0
  load: () => Promise<{ default: Component<P> }>;
}
export type ChromeSlot = 'app-shell-overlay' | 'app-shell-modal';
export type ChromeContribution = Contribution & { slot: ChromeSlot };
export type ViewerTabContribution = Contribution<{ nodeId: string }> & { nodeType: string; label: string };

export interface NodespaceExtension {
  id: string;
  apiVersion: typeof EXTENSION_API_VERSION.major;
  chrome?: ChromeContribution[];
  viewerTabs?: ViewerTabContribution[];
}

// A contribution as a host sees it; key = `${extensionId}/${id}`
export type Keyed<C> = C & { extensionId: string; key: string };
  • Remove:

    • the ProSyncVariant type import and every variant field;
    • UiExtensionDefinition, together with its name and version;
    • ViewerExtension and lazyLoad;
    • tab.appliesTo, tab.id and tab.label.
  • Rewrite the module doc (L1-21). It describes the registry behind ADR-082's frontend extension API:

    • what an extension is;
    • how it is registered: registerExtensions(), called from the build entry;
    • how keys and ordering work;
    • that lookups never evaluate when.

    No Pro wording.

2. Registration

This covers UiExtensionRegistry, the uiExtensionRegistry singleton, and a new registerExtensions.

register(ext):

  • The identical object is already registered: a no-op, logged with log.debug. This is needed while pro-plugin.ts registers itself and a build also injects the same object through the build entry (Add the virtual:nodespace-extensions build entry and the extension-api import alias #3311).
  • A different object has the same id: log.error naming the id, and the first registration is kept.
  • ext.apiVersion !== EXTENSION_API_VERSION.major: log.error, and the extension is not registered.
  • A contribution id repeats within the extension (across all of its lists): log.error, and the later one is dropped.
  • It never throws, because a throw during registration would blank the app.

export function registerExtensions(extensions: readonly NodespaceExtension[]): void registers each extension in order. A non-array argument is logged and ignored.

Other methods:

  • Keep unregister(id), has(id) and all(), which returns extensions in registration order. Tests use unregister.
  • chromeFor(slot) and viewerTabsFor(nodeType) return Keyed<…>[] across all extensions. They sort by descending priority, break ties by registration order (extension first, then contribution), and never evaluate when.

3. src/lib/plugins/ui-extensions.svelte.ts

  • Remove the resolveProSyncVariant import.
  • Keep import './pro-plugin';, with a one-line comment: it is transitional, and is removed once builds inject extensions through virtual:nodespace-extensions (ADR-082 §2.1).
  • Add isContributionActive(c):
    • when absent: true;
    • a throwing when: false, logged with log.warn once per key until it next returns normally (ADR-082 §2.4).
  • getActiveChromeContributions(slot) and getActiveViewerTabs(nodeType) (renamed from getActiveViewerExtensions) filter through it.
  • Module doc: reactivity comes from whatever the predicates read, so hosts call these accessors inside a $derived or a template (ADR-049).

4. src/lib/plugins/pro-plugin.ts: a one-to-one translation

  • Add a helper that imports from ./pro-sync-variant.svelte:

    const whenVariant = (...variants: ProSyncVariant[]) => () => variants.includes(resolveProSyncVariant());
  • Declare export const proSyncExtension: NodespaceExtension = { id: 'pro-sync', apiVersion: 1, chrome: […], viewerTabs: […] }. It is renamed from proSyncUiExtension, which nothing else imports. Its contributions:

Contribution id Kind when load
consent-modal chrome, app-shell-modal whenVariant('consent') first-pro-consent-slot.svelte
relogin-modal-relogin chrome, app-shell-modal whenVariant('relogin') pro-relogin-slot.svelte
relogin-modal-connected chrome, app-shell-modal whenVariant('connected') pro-relogin-slot.svelte
collaboration viewer tab, nodeType: 'collection', label: 'Collaboration' whenVariant('sign-in', 'consent', 'relogin', 'connected') collaboration/collaboration-tab.svelte
  • Why two relogin contributions: they keep today's remount of the relogin slot when the variant changes between relogin and connected.
  • Why one Collaboration contribution: today, four variant contributions share the tab id collaboration, so the selected tab survives a variant change (for example, "Turn on sync", then consent accepted, then connected). Under ADR-082 the host keys a tab by its contribution key. Four contributions would therefore drop the selection back to Contents.
  • Add export default [proSyncExtension]; so that a build can set NODESPACE_EXTENSIONS to this file. The interim Pro build does this after Stop importing the Pro extension in core; register it only through the build entry #3316.
  • Keep uiExtensionRegistry.register(proSyncExtension); with a one-line transitional comment. Stop importing the Pro extension in core; register it only through the build entry #3316 deletes it.
  • Reword the doc table (L1-40) for the new shape.

5. src/lib/components/collaboration/collaboration-tab.svelte

This component becomes the variant switch that the four tab contributions used to express:

const variant = $derived(resolveProSyncVariant());
const live = $derived(variant === 'relogin' || variant === 'connected');
{#key variant}
  {#if live}<CollaborationView collectionId={nodeId} />{:else}<CollaborationLocked {nodeId} />{/if}
{/key}
  • {#key variant} keeps today's remount on every variant change.
  • collaboration-locked.svelte itself is unchanged, so its design-token baseline entries stay valid.

6. Hosts

New src/lib/plugins/chrome-slot-outlet.svelte:

  • Prop name: ChromeSlot. It is not called slot, because Svelte reserves that attribute.
  • Body: {#each getActiveChromeContributions(name) as c (c.key)}<ExtensionOutlet load={c.load} />{/each}.

src/lib/plugins/extension-outlet.svelte:

  • Load with const loaded = $derived(load().catch((error) => { log.error(…); return null; })), and render nothing for null. A rejected load() is retried only on the next mount; nothing loops.
  • Wrap the render in <svelte:boundary onerror={…}> with an empty failed snippet. A component that throws while rendering, or in an effect, then removes only its own outlet, and the error is logged through createLogger('ExtensionOutlet').
  • Doc: the outlet is part of the extension API, and callers key it by contribution key (ADR-082 §2.4).

src/lib/components/layout/app-shell.svelte:

  • The overlay slot (L692-702) becomes <div class=extension-overlay-slot><ChromeSlotOutlet name=app-shell-overlay /></div>, with a neutral comment: a generic overlay slot, to which core contributes nothing.
  • The modal slot (L732-736) becomes <ChromeSlotOutlet name=app-shell-modal />, with a neutral comment.
  • CSS: rename .pro-sync-pill-slot to .extension-overlay-slot (L804, L807-815).
  • Imports (L37-38): ChromeSlotOutlet replaces getActiveChromeContributions and ExtensionOutlet.

src/lib/components/viewers/collection-node-viewer.svelte:

  • const tabs = $derived(getActiveViewerTabs('collection')). activeView holds 'contents' or a tab's key, and activeTab = tabs.find((t) => t.key === activeView).
  • The tab strip (L262-285) becomes {#each tabs as t (t.key)}, showing t.label.
  • The outlet (L287-291) becomes {#key activeTab.key}<ExtensionOutlet load={activeTab.load} props={{ nodeId }} />{/key}.
  • Make the comments at L29-37 and L263-265 neutral ("registry-contributed tabs"), with no Pro wording.

7. Test fixture: src/tests/fixtures/test-extension/

  • flags.svelte.ts: export const testExtensionFlags = $state({ overlay: false, modal: false, tab: false, throwingWhen: false, throwingComponent: false }).

  • index.ts: createTestExtension(overrides?) returns a NodespaceExtension with id test-extension, whose contributions are each gated by a flag:

    • an overlay;
    • a modal;
    • a collection tab;
    • a contribution whose when throws while throwingWhen is set;
    • a contribution that loads a throwing component.

    Later sub-issues extend this fixture.

  • Components, none with a <style> block:

    • test-chrome.svelte;
    • test-viewer-tab.svelte, which renders its nodeId;
    • test-throwing.svelte, which throws while rendering.

8. Pro-boundary ratchet

  • Paste the printed BASELINES.
  • Markers that go down: the generic files lose the variant filter, ProSyncVariant and the Pro wording in their docs. Lower those baselines.
  • Markers that go up: pro-plugin.ts and collaboration-tab.svelte gain a few proSyncModule lines, because the variant comparison moves out of the generic filter and into the Pro extension. Declare them under Add the Pro-boundary ratchet check and the CLAUDE.md Pro/sync placement rule #3299's relocation rule. The whenVariant helper limits them to the import and helper lines.

Out of scope

Steps

  1. Start up as core's CLAUDE.md describes: a worktree named issue-<N>-extension-contract, bun install, and self-assign at pickup.
  2. The types and the registry, with the generic registry tests.
  3. The wrapper accessors.
  4. ExtensionOutlet and ChromeSlotOutlet, with their tests.
  5. Translate pro-plugin.ts and collaboration-tab.svelte, and update pro-sync-variant.test.ts.
  6. The app shell and the collection viewer, with the viewer test.
  7. The ratchet, the verification and quality:fix, then the PR.

Acceptance criteria

Contract

  • ui-extensions.ts exports, as specified above: EXTENSION_API_VERSION, Contribution, ChromeSlot, ChromeContribution, ViewerTabContribution, NodespaceExtension, Keyed, registerExtensions and the registry. No variant field remains.
  • grep -rnE 'pro-sync-pill|lazyLoad|viewerExtensions|UiExtensionDefinition|getActiveViewerExtensions' packages/desktop-app/src returns nothing.
  • None of proSync, labsFlags, ProSyncVariant, resolveProSyncVariant or DATABASE_SETTINGS_NODE_ID appears in ui-extensions.ts, ui-extensions.svelte.ts, extension-outlet.svelte or chrome-slot-outlet.svelte. The one exception is the transitional import './pro-plugin' line and its comment.
  • Registration follows section 2 and never throws.

No behaviour change

  • For each of teaser, sign-in, consent, relogin and connected, the same modal component and the same Collaboration content (locked or live) render as before (pro-sync-variant.test.ts, collaboration-tab.test.ts).
  • The Collaboration tab stays selected across a change from consent to connected.
  • test:free-users passes, and the manual smoke test of the free app shows no change.

Isolation

  • A rejected load() and a throwing component each remove only their own outlet, and each is logged. Sibling outlets still render.

Checks

  • bun run test:changed passes, and quality:fix is clean with no change to the design-token baseline.
  • bun run scripts/check-pro-boundary.ts exits 0 and BASELINES equal the printed counts. Reductions are lowered, and the PR description declares the relocation raise.

Tests and verification

Rewritten src/tests/plugins/pro-sync-variant.test.ts ('registry registration', 'active contribution filtering' and the Labs gate), with the same variant matrix as before:

  • Registration:
    • uiExtensionRegistry.has('pro-sync') is true;
    • chromeFor('app-shell-modal') has 3 entries, and viewerTabsFor('collection') has 1;
    • the overlay slot has none.
  • What each variant shows:
    • teaser: nothing;
    • sign-in: no modal, and the tab pro-sync/collaboration;
    • consent: the modal pro-sync/consent-modal, and the tab;
    • relogin: pro-sync/relogin-modal-relogin, and the tab;
    • connected: pro-sync/relogin-modal-connected, and the tab.
  • Build the keys with a helper from proSyncExtension.id, so the assertions do not repeat marker strings.
  • import proExtensions from '$lib/plugins/pro-plugin' returns [proSyncExtension]: the same object that is registered.

New src/tests/plugins/ui-extensions.test.ts. It is generic and imports nothing Pro. It registers the fixture, and unregisters it in afterEach.

  • Registration:
    • register, unregister, has and all;
    • re-registering the identical object is a silent no-op;
    • a different object with the same id keeps the first and logs;
    • an apiVersion mismatch is not registered, and logs;
    • a duplicate contribution id is dropped, and logs;
    • registerExtensions with a non-array argument logs.
  • Lookups: chromeFor and viewerTabsFor by slot and by node type, in descending priority with ties in registration order, with keys of the form <extension id>/<contribution id>.
  • Predicates:
    • when absent: active;
    • when false: filtered out;
    • when throws: filtered out and warned once, and warned again only if it has returned normally in between.

New src/tests/plugins/chrome-slot-outlet.test.ts:

  • It renders the fixture chrome only while its flag is on, in priority order.
  • It renders nothing for an empty slot.
  • Turning one contribution off unmounts only that outlet: a mount counter on the other one stays at 1.

New src/tests/plugins/extension-outlet.test.ts:

  • Props reach the component.
  • A rejecting loader renders nothing, and logs.
  • A throwing component renders nothing, and logs, while a sibling outlet still renders.

New src/tests/components/collection-node-viewer-extensions.test.ts. Mock the collection reads: $lib/services/collection-service, and whatever else loadCollectionData calls. Then check:

  • no tab strip while the fixture tab is hidden;
  • Contents plus the fixture tab while it is shown;
  • clicking the tab mounts the fixture component with nodeId;
  • hiding the selected tab falls back to Contents.

New src/tests/components/collaboration-tab.test.ts. Stub collaboration-view.svelte with a fixture component, and drive the variant through the real stores, as pro-sync-variant.test.ts does.

  • sign-in and consent render the locked placeholder.
  • relogin and connected render the live view.
  • A change from relogin to connected remounts it.

Updated: free-user-guardrail.test.ts uses getActiveViewerTabs.

bun run test:changed
bun run --cwd packages/desktop-app test src/tests/plugins src/tests/components/collection-node-viewer-extensions.test.ts src/tests/components/collaboration-tab.test.ts
bun run --cwd packages/desktop-app test:free-users
bun run --cwd packages/desktop-app quality:fix
bun run --cwd packages/desktop-app build
bun run scripts/check-pro-boundary.ts

Manual smoke test of the free app. Run bun run --cwd packages/desktop-app dev:tauri with an isolated NODESPACE_HOME, then check:

  • a collection shows no tab strip;
  • Settings is unchanged;
  • switching databases works.

Dependencies

Risks and rollback

  • The Collaboration tab translation. It uses one contribution plus a switch inside collaboration-tab.svelte, instead of four contributions. The tests pin both the content shown for each variant and the kept selection.
  • The relogin slot's remount. Kept by the two per-variant contributions.
  • Registration now keeps the first extension instead of replacing by id. Only tests re-register, and they unregister first.
  • Rollback. Revert the PR. It changes no data, no schema and no Rust code.

Plan key: C3.1b (pro-boundary DAG).

🤖 Generated with Claude Code

Activity

  1. self-assigned this
    on Sep 30, 2026
  2. added
    pro-boundary
    on Sep 30, 2026
  3. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Completed in #3374 (merged). Auto-close did not fire; closing manually.

  4. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Correction to the closing comment above: this issue was completed in #3384 (merged), not the PR named there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions