Skip to content

Worked design: a resource-page note extension ​

Design a resource-note feature from its visible behavior through persistence, UI and retirement. This is a worked design: it distinguishes decisions and integration requirements from an already shipped extension.

Version scope: these source-level examples target v2.0.0.alpha.14. Use the Plugin SDK for current Wasm plugin authoring.

The goal is to submit a note on the resource page, show the last valid value, invalidate old operations after navigation, and restore current facts after activation. Resource search, downloads, and account policy stay outside this feature.

1. Write acceptance scenarios ​

text
Given an active session whose note is “Ready to test”
When the user submits “Alpha 14 tested”
Then the command succeeds, current-note state changes, and the card shows it

Given navigation away or a replaced module exposure
When a captured old submit arrives
Then it is not admitted as an operation on the new module

Given an oversized argument or a stopped session
When a request arrives
Then it fails explicitly and preserves the previous value

Choose a business limit below the Host input budget, for example 120 characters, and decide whether blank notes are allowed. The 512-character draft budget is a container limit, not your business rule.

2. Assign ownership ​

ConcernOwnerInput/output
Validate/save noteSidecar-private business logicString → success/stable error
Current value and action availabilitySidecar State, read-only Host mirrorSnapshot and deltas
Form and unsubmitted draftHost module projectionSchema 2, exposure, user input
Cancellation/exchange/session lifetimeHost Runtime and peer receive loopNumeric contract, correlation, CANCEL
AppearanceHost/NTPReadable presentation without behavior authority

Do not pass SidecarConnection to the renderer, keep control references in business objects, or let an unsubmitted draft become authoritative state.

3. Declare the minimal contracts ​

KindSemantic IDCodecPurpose
Commandexample.note.setArgument 0, result 0Submit text
Stateexample.note.current0Last valid note
Stateexample.note.enabled1Availability
Eventexample.note.changed0Successful change notification
UiModuleexample.note.panel0, flags 0Hashed finite form

The command is ordinal 1 in its kind; states are ordinals 1 and 2. UI and State do not share a numeric table. Include both states in the initial snapshot, even when the Boolean value is simply true.

4. Use an admitted module ​

csharp
var document = new SidecarUiDocument(
    "ui.resources.extension-card.v1", "Resource note", "Stores this extension's note only.",
    new SidecarUiNode[] {
        new(1, 0, SidecarUiNodeKind.Stack, "Note panel"),
        new(2, 1, SidecarUiNodeKind.Text, "Current note",
            ValueState: "example.note.current"),
        new(3, 1, SidecarUiNodeKind.TextInput, "Edit note",
            Command: "example.note.set", ValueState: "example.note.current",
            EnabledState: "example.note.enabled")
    });
byte[] bytes = document.Encode();

This registration-time fragment uses Nexa.Sidecar.Protocol. UI and extensions explains node fields, references, and hashed registration. TextInput uses the Host-owned submit control. Do not create another button that attempts to read a remote control's draft: button Argument is a registration-time literal, not an arbitrary binding expression.

5. Execute and publish facts ​

Check Active state, contract ID, codec, and argument before business validation. On success publish a current-note StateDelta, optionally emit changed Event, and return CommandResult with the original correlation. On failure preserve the prior value and return an explicit error.

When saving involves IO, keep receiving Health/CANCEL and track cancellable workers by correlation. Do not block the receive loop, or synchronously wait on async work with .Result/.Wait().

A timeout means the caller did not obtain a result before its deadline; it does not prove that no effect occurred. A retryable persistent operation needs operation IDs, deduplication, or idempotency. A fresh correlation is not an idempotency key.

6. Include retirement and failure ​

On deactivation stop admitting work, finish/cancel pending workers, and retire UI/subscriptions/signals. After restart register again, send a complete snapshot, and wait for ACTIVATE. Discard old numeric mappings and exposures.

An in-memory note disappears on exit. If persistence is required, implement it through Sidecar-owned storage with a format version and failure contract. This example does not gain arbitrary Host filesystem access or claim durable persistence merely because echo works.

7. Produce evidence ​

LayerRequired evidenceEntry
BusinessLength/blank rules and failure preservationPure business tests
CodecConsistent Command, State, Event, UI referencesMessage recipes
IPCChild bootstrap, registration, query, shutdownFirst Sidecar
UIDraft, submit, state projection, navigation cancellationExecution inside an admitted Host, recording OS/build
DistributionNative executable, publisher signature, discovery pathPackaging and discovery

The same design scales to a task panel: Command starts work, State owns progress/availability, Event announces completion, and Stream carries bounded continuous output. Confirm target authorization before broadening the feature.

Implementation references ​

Check your result ​

Check the proposed flow for edits during refresh, failed persistence, owner shutdown and a missing extension target. Keep unresolved Host capabilities explicit instead of presenting a diagram as implemented code.

Site documentation: CC BY-SA 4.0. Imported SDK documents: Apache-2.0 as marked.