Composer plugins

From dxos/dxos · View interactive version

Composer plugins is an AI agent skill from the GitHub repository dxos/dxos. Use when working on files in packages/plugins/, adding new plugins, refactoring plugin components/containers, writing storybooks for plugins, or wiring capabilities like react-surface or operation-resolver. For the UI/design-system details of plugin components (layout, theming, forms, toolbars, list

How to use this skill

Skill file

Composer Plugins

Exemplar: packages/plugins/plugin-chess. Read its source files to understand every pattern below.

Companion skills. For building plugin UI with the design system — container layout, theme tokens,

forms, toolbars, lists/stacks, reactivity, storybook — use the composer-ui skill. For authoring

new @dxos/react-ui composite primitives (Foo.Root/Foo.Content), use composite-components. This

skill owns plugin _structure_ (capabilities, surfaces, schema, operations) and points at those two for UI.

Read MEMORY.md first (sibling of this file) for session-logged design/implementation learnings and prior corrections.

REQUIRED — keep MEMORY.md current: Whenever the user directs a correction (tells you to do something differently, rejects an approach, or specifies a pattern), record it in MEMORY.md as part of carrying out that correction — do not defer to session end. Also capture other non-obvious design/implementation details as you learn them.

Update it _appropriately_:

Discovery

Use the dxos-introspect MCP server (@dxos/introspect-mcp, served by the dx-introspect-mcp binary) as the source of truth for plugin metadata and reference examples — not directory listings.

A "plugin" is a package whose dx.config.ts default-exports a Plugin.config(...), so ls packages/plugins/ overcounts (e.g. plugin-generator is tooling, not a plugin).

Reach for these first when answering questions like "how many plugins", "which plugin contributes X surface", or "where is symbol Y defined".

Reading an operation's key and input shape

list_operations does not enumerate operations — it returns one row per

Capabilities.OperationHandler contribution, i.e. where each plugin's handler file lives. The

definitions live under a <Plugin>Operation symbol — a namespace in plugin-space, a module of

top-level exports in plugin-markdown — so go through the symbol tools:

  1. list_plugins({ id: 'space' }) → the exact plugin id, when you only have a loose name.
  2. find_symbol({ query: 'SpaceOperation' }) → @dxos/plugin-space#SpaceOperation.
  3. get_symbol({ ref: '@dxos/plugin-space#SpaceOperation', include: ['source'] }) → every

definition with its meta.key, input, output and services.

Read services while you are there: a definition listing Database.Service needs a spaceId at

invoke time, which is invisible from the key alone.

Search idioms before implementing

Required. Before writing or refactoring any container, capability, operation, skill, or schema, call mcp__dxos-introspect__list_idioms and scan for a slug that matches what you're about to build. An idiom is a JSDoc-tagged pinning of the canonical way to do one thing — when one exists, it is the answer, and you should get_symbol on the host artifact and follow the pattern rather than reinventing it.

Typical triggers:

If no idiom matches, proceed using the exemplar (plugin-chess); if you find yourself writing something that other plugins will copy, consider adding a new @idiom tag (see CODE2 for the format and slug rules).

Specification

A plugin's design is captured in two artifacts across its lifecycle — a

superpowers design doc during the initial build, then a durable

PLUGIN.mdl that outlives the first session.

Package docs go in `docs/`, never the package root

Every markdown file a plugin owns other than README.md lives under

packages/plugins/plugin-<name>/docs/ — docs/DESIGN.md, docs/AUDIT.md,

docs/TESTING.md, and so on (see plugin-assistant/docs/, plugin-inbox/docs/).

The package root holds only README.md, PLUGIN.mdl, and build config; a

DESIGN.md sitting beside package.json is a mistake to move, not a variant to

match. README.md links into docs/ rather than restating it.

This is about the package root staying scannable — a reader opening the plugin

should see config and src/, with prose one directory away.

Initial plugin creation (first session)

When creating a brand-new plugin, do NOT start with PLUGIN.mdl. Instead:

  1. Run the superpowers:brainstorming flow and write the approved design to

packages/plugins/plugin-<name>/docs/DESIGN.md, then add a short stub at

.agents/superpowers/specs/YYYY-MM-DD-<name>-design.md that links to it. The

doc ships with the package it describes and the specs index still finds it;

the stub carries a link and nothing else, so there is one source of truth.

(.agents/superpowers/specs/ is the DXOS override of the superpowers default

docs/superpowers/… path; a design doc that belongs to no package is written

there directly.)

  1. The user approves that design doc before any code is written.
  2. Implement Phase 1 against the design doc.
  3. At the end of Phase 1, before opening the PR, author

packages/plugins/plugin-<name>/PLUGIN.mdl from the design doc and the

as-built plugin. This is a required pre-PR step — the design doc drove the

build; PLUGIN.mdl is the hand-off spec that subsequent sessions consume.

`PLUGIN.mdl` — the durable spec

PLUGIN.mdl is written in the MDL (.mdl) language defined by @dxos/deus.

The authoritative references live under CODE0:

Use the template as the starting structure and packages/plugins/plugin-chess/PLUGIN.mdl

as a reference. PLUGIN.mdl is a **record of what has been built — not a

working document**. Design exploration for new features (in any session) happens

in a design doc under the plugin's docs/ (indexed from .agents/superpowers/specs/);

PLUGIN.mdl is updated only after the design AND implementation have settled. It must be:

Phase 1 as described above; never omitted.

brainstorm and implement against a design doc, then bring PLUGIN.mdl in

line with the as-built plugin before the PR (never edit it speculatively

up front).

the spec's feat, req, and test blocks.

Every new plugin ships a QA flow and a demo video

Two artifacts, both authored at the close of Phase 1 alongside PLUGIN.mdl and

both required before the plugin's first PR merges:

  1. A ## QA section in PLUGIN.mdl holding at least one flow QA-n block

in the QA dialect (CODE0;

plugin-chess/PLUGIN.mdl is the reference). One flow covering the plugin's

primary user journey end to end is the minimum. Its execution rules are not

style advice — read them before authoring, especially Rule 5 (assertions must

be falsifiable against a dirty fixture) and Rule 7 (before / test /

after).

  1. A recorded demo of that flow against the running app, per the

autocue skill: drive the flow's do: steps one gesture at a time,

caption each step with its do: text verbatim, and judge expect: from the

screen. Attach the .webm to the conversation and commit a contact sheet or

stills for the PR body — never the video.

Write the flow first, then record it. A demo improvised against the app

proves the app runs; a demo that executes a written flow proves the spec and the

app agree, and the recording is what sets the flow's status:. Where they

disagree, that is a finding — report it, and fix whichever is wrong.

Workflow

reviewer should not have to build it to see it. Record the flow or take the stills with

autocue, then attach them to the PR body per hosting-artifacts

(.agents/skills/hosting-artifacts/SKILL.md: gh --attach, R2 as the fallback) — never commit a

video or a screenshot to make it visible. For a fix to rendered output, a before/after pair from one build

(see composer-ui) beats a clip.

Creating a New Plugin

When asked to create a new plugin, first produce the superpowers design doc (see

Specification above), then start with a minimal skeleton before adding features.

PLUGIN.mdl is NOT part of the initial skeleton — it is authored at the end of

Phase 1, before the PR. The skeleton should include:

  1. README.md — brief description of the plugin's purpose, linking to docs/DESIGN.md.
  2. package.json — with "private": true, the #meta import alias and ./FooPlugin export subpath (both point at dx.config.ts; see package.json), and minimal dependencies.
  3. moon.yml — tags (check-module-structure itself is inherited).
  4. src/namespace.ts — export const FooNamespace = Plugin.namespace('org.dxos.plugin.foo'), a leaf both dx.config.ts and the capability tags derive from.
  5. src/translations.ts — initial translation resources.
  6. dx.config.ts — Plugin.config({ plugin, modules }) with key, name, author, description, icon, a quality tier tag (see below), surface and translations modules, and export const { meta, make } = config; export default config; (see Plugin Definition).
  7. src/index.ts — export * as FooPlugin from '#meta' plus types/operations. Never exports make directly.
  8. src/types/ — one schema type with make() factory.
  9. src/capabilities/react-surface.tsx — one surface for the article role, wired by AppCapability.surface(() => import('./src/capabilities/react-surface.ts', { with: { type: 'module-url' } }), { roles }) in dx.config.ts.
  10. src/containers/ — one container (e.g., FooArticle) with lazy export and basic storybook.
  11. src/components/ — empty barrel, ready for primitives.

Build and lint the skeleton before adding features.

Add capabilities incrementally as needed (operations, skills, settings, etc.).

Register the plugin with composer-app: import * as FooPlugin from '@dxos/plugin-foo/FooPlugin', then FooPlugin.make() in getPlugins, and its key in the isDev block of getDefaults unless the plugin hits a permission-gated API on activation (rule 5 under Activation waves).

Once the plugin contributes a navtree section, apply both rules under App graph below — gate the section on a non-empty query, and default the create-object targetNodeId to the node that lists the objects.

Quality tiers

Every plugin MUST declare exactly one quality tier as the FIRST entry of

plugin.tags in dx.config.ts. A new plugin defaults to labs — promotion is a

deliberate, separate decision, never the scaffold's default.

| Tier | Meaning |

| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| system | Core infrastructure. Force-enabled and not user-toggleable; derived in plugin-manager.ts from tags.includes('system'). Also omit the key from getDefaults in composer-app/src/plugin-defs.tsx — redundant once core. |

| beta | Stable enough to lead with. Shown in the registry's Recommended category. |

| alpha | A real feature, still moving. Also shown in Recommended. |

| labs | Experimental, thin, dev-only, or platform-gated. The default for a new plugin. |

tags: ['labs'],

Secondary tags (connector, game, assistant, travel) follow the tier:

tags: ['labs', 'connector']. Add alpha/beta/labs/system to

RegistryTagType in plugin-registry/src/types.ts — a new secondary tag needs

no change there, but an unlisted tag renders without a hue.

Do NOT leave a plugin untagged. getCategoryPredicate in

plugin-registry/src/categories.ts selects Recommended by an explicit

beta/alpha allowlist, so an untagged plugin silently appears in no category

but bundled.

Directory Structure

plugin-foo/
  package.json
  moon.yml
  dx.config.ts             # The whole plugin: identity, quality tier in `plugin.tags`, and the module list.
  PLUGIN.mdl
  README.md                # The only markdown at the root; links into docs/.
  docs/                    # Everything else the package documents.
    DESIGN.md
  src/
    index.ts                # Root entrypoint; exports `FooPlugin` (from '#meta'), types and operations.
    namespace.ts            # `Plugin.namespace(key)`: the key and tag makers; a leaf with no imports.
    translations.ts         # i18n resources keyed by typename and FooNamespace.key.
    paths.ts                # Canonical qualified graph paths (only if the plugin owns navtree nodes).
    skills/             # AI skill definitions.
      index.ts
    capabilities/           # Module bodies (one file each, default export), named in dx.config.ts.
      react-surface.tsx
      operation-handler.ts
      skill-definition.ts
      app-graph-builder.ts  # Navtree sections, child nodes, actions.
      create-object.ts      # SpaceCapabilities.CreateObjectEntry per type.
    components/             # Primitive UI components (no app-framework deps).
      index.ts
      MyComponent/
        index.ts
        MyComponent.tsx
        MyComponent.stories.tsx
    containers/             # Surface components (lazy-loaded, use capabilities).
      index.ts              # lazy(() => import('./X')) exports.
      FooArticle/
        index.ts            # Bridges named -> default export.
        FooArticle.tsx
        FooArticle.stories.tsx
    operations/             # Operation definitions and handlers.
      index.ts
      definitions.ts
    types/                  # ECHO schema definitions.
      index.ts              # Namespace re-export: export * as Foo from './Foo';
      Foo.ts

Concepts

Component (`src/components/`)

Low-level UI (plugin/src/components, react-ui-\*). Must NOT depend on @dxos/app-framework or @dxos/app-toolkit.

Each component lives in its own subdirectory with an index.ts barrel.

Use named exports; no default exports. Create a basic storybook for each.

Prefer composable Radix-style namespaces for non-trivial components. Mirror the Foo.Root / Foo.Toolbar / Foo.Content / Foo.Viewport pattern used by Panel.*, Card.*, Masonry.*, and ScrollArea.* in @dxos/react-ui and @dxos/react-ui-masonry. The Root provides shared context (data, callbacks, Tile component); subcomponents read it and slot into the outer Panel/ScrollArea structure. This lets containers plug in their own toolbar contents (e.g. MenuBuilder buttons) without forking the component, and keeps the component fully presentation-only.

// Pure component namespace — no app-framework deps.
export const FooMasonry = { Root: Root, Toolbar: Toolbar, Content: Content, Viewport: Viewport };

// Container composes:
<FooMasonry.Root items={items} onDelete={handleDelete}>
  <FooMasonry.Toolbar>
    <Menu.Root {...menuActions} attendableId={attendableId}>
      <Menu.Toolbar />
    </Menu.Root>
  </FooMasonry.Toolbar>
  <FooMasonry.Content>
    <FooMasonry.Viewport />
  </FooMasonry.Content>
</FooMasonry.Root>;

Sketch the namespace export first when designing a new component; only collapse to a single component if the surface really has no slots.

See: plugin-chess/src/components/Chessboard/, packages/ui/react-ui-masonry/src/Masonry.tsx

Container (`src/containers/`)

High-level surface component. Uses capabilities and is referenced by react-surface.

Each container lives in its own subdirectory. The subdirectory index.ts bridges named to default export (for React.lazy).

The top-level containers/index.ts uses lazy(() => import('./X')) with : ComponentType<any> annotation.

Surface components use suffixes matching their role: Article, Card, Dialog, Popover, Settings.

Create a basic storybook for each.

If a "component" needs useCapability/useCapabilities/useAppGraph/useOperationInvoker, it belongs in containers/. Storybooks won't have a PluginManager — calling capability hooks under components/ throws. Refactor: take the resolved value (URL, callback, Tile component) as a prop and move the hook one level up.

UI: forms, theming, toolbars, cards, layout

The detailed rules for building plugin UI with the design system live in the composer-ui skill

(.agents/skills/composer-ui/SKILL.md). Consult it whenever you write a container/component, reach for a

Tailwind color class, build a toolbar, edit an object with a form, or add a story. It covers: the

@dxos/react-ui* packages, verified theme tokens (never invent bg-input/text-primary), the standard

Panel + ScrollArea container layout (no wrapper divs), MenuBuilder + useMenuActions + Menu.Root

toolbar wiring (threading attendableId), schema-driven Form editing (no native inputs), the Card

3-slot subgrid, icons, attention/density, reactivity (useObject for ECHO objects passed into

components), translations, and storybook setup. For authoring brand-new @dxos/react-ui primitives, see

the composite-components skill.

Before committing UI, grep the diff for dead classes. The tailwindcss-logical dialect

(pis-*, pbs-*, pli-*, mis-*, is-*, bs-*, min-bs-*, …) was dropped in the Tailwind v4

migration and now compiles to nothing — silently, so nothing errors and nothing lints. It is the

highest-frequency UI regression in this repo, and worst when the dead class was load-bearing (a

min-bs-* height floor, a min-is-0 letting a grid child shrink), because the failure surfaces far

from its cause. Replacement table and the grep are in composer-ui § "Sizing vs logical utilities".

Capability (`src/capabilities/`)

Plugin modules that contribute functionality to the framework. Each is a single file with a default export using Capability.makeModule(). The barrel index.ts uses only makers (AppCapability.*) or Capability.lazyModule() exports. Do NOT add non-lazy exports.

See: plugin-chess/src/capabilities/

Cross-plugin capabilities (`src/types/XCapabilities.ts`)

Some plugins expose capability keys for other plugins to implement — a decoupled provider/extension

contract. See packages/plugins/AUDIT.md for the current registry.

Naming convention — use one of four suffixes depending on the role:

| Suffix | Use when | Example |

| -------------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |

| Provider | The contributor supplies data, a factory, or an array of extensions | MapCapabilities.MarkerProvider, GameCapabilities.VariantProvider, MarkdownCapabilities.ExtensionProvider |

| Service | The contributor performs active async work (search, routing, …) | TripCapabilities.BookingService, TripCapabilities.RoutingService |

| EventHandler | The contributor registers callbacks for host-plugin lifecycle events | CallsCapabilities.EventHandler |

| Config | The contributor supplies a declarative config object keyed by typename | AppCapabilities.CommentConfig (consumed by plugin-comments) |

When the contract is app-wide rather than owned by one plugin (e.g. comment support), the capability

key lives in AppCapabilities (@dxos/app-toolkit) instead of a plugin's src/types/XCapabilities.ts;

plugin-comments re-exports AppCapabilities.CommentConfig as CommentCapabilities.CommentConfig.

Where to define — add the Capability.make<T>() call in the defining plugin's

src/types/XCapabilities.ts, namespace-exported from src/types/index.ts:

// packages/plugins/plugin-foo/src/types/FooCapabilities.ts
export const BarProvider = FooNamespace.make<BarProvider>()('bar-provider');

Expose it via a ./types subpath in package.json (see plugin-game/package.json as a reference).

The --entryPoint=src/types/index.ts entry in moon.yml is typically already present.

Where to implement — the donor plugin places its contribution in a dedicated file in

src/capabilities/, named after the capability it implements (e.g. routing-service.ts,

markdown-extension.ts). Wire it as a Capability.lazyModule entry in dx.config.ts.

How to import the key — use the /types subpath, not the root entrypoint:

// ✓
import { FooCapabilities } from '@dxos/plugin-foo/types';
// ✗ — pulls in the full barrel (meta, hooks, operations, …)
import { FooCapabilities } from '@dxos/plugin-foo';

Reference implementations:

Worked example: comments (`AppCapabilities.CommentConfig`)

plugin-comments owns the comments companion + threads UI but knows nothing about which types are

commentable. A plugin opts a typename in by contributing a CommentConfig and wiring it with

AppPlugin.addCommentConfigModule({ activate: CommentConfig }):

(see plugin-sketch, plugin-table, plugin-bookmarks, plugin-video).

publish selections into AttentionCapabilities.Selection keyed by Obj.getURI(subject), plus

getAnchorLabel / scrollToAnchor in the config (see plugin-markdown, plugin-sheet). The

comment-sync CodeMirror extension (plugin-comments/src/extensions/threads.ts) is injected into

the markdown editor via MarkdownCapabilities.ExtensionProvider and currently only supports

Markdown.Document content — a custom editor (e.g. a Ref<Text> field rendered with

useTextEditor) cannot get anchored comments without equivalent plumbing.

plugin-comments resolves configs by typename (`getAll(AppCapabilities.CommentConfig).find(({ id }) =>

id === typename)`) in its app-graph builder, which offers the comments companion and the toolbar

"Add comment" action for matching nodes.

LayerSpec contributions (`src/capabilities/layer-specs.ts`)

Plugins that contribute Effect services to the process-manager runtime do so via Capabilities.LayerSpec entries (see plugin-client/src/capabilities/layer-specs.ts for a minimal reference).

Conventions:

Affinity and `LayerSpec.LayerContext`

A spec's affinity determines the slice it lives in and which fields of LayerContext are populated when its factory runs (see packages/core/compute/compute/src/LayerSpec.ts):

| Affinity | Lifetime | LayerContext fields available |

| ------------- | ----------------------------------------------- | ---------------------------------------- |

| application | Process-manager runtime | (none — {}) |

| space | Per space, reused across all processes in space | space |

| process | Per spawned process | space, conversation, process (pid) |

conversation and process are process-affinity only — a space-affinity factory cannot see them. If a service is keyed on conversation (e.g. AiContext.Service, AiSession.Service), it must be process-affinity even though it depends on space-affinity services like Database.Service. The LayerStack initialises lower-affinity slices first, so process specs can require space services without issue.

The LayerContext.conversation field is fed from the spawn environment.conversation, which in turn comes from Operation.invoke(..., { conversation }) or Operation.withInvocationOptions({ conversation }). Operations dispatched by TriggerDispatcher also inherit space/conversation from the parent spawn environment.

Handling missing context fields

LayerSpec.make's factory must return Layer<Provides, never, Requires> — the error channel is never, so the layer body cannot use typed Effect.fail to signal "this context is invalid". Use Effect.die(new ServiceNotAvailableError(tag.key)) inside the Layer.scoped body when a required LayerContext field is missing:

LayerSpec.make({ affinity: 'process', requires: [Database.Service], provides: [AiContext.Service] }, (context) =>
  Layer.scoped(
    AiContext.Service,
    Effect.gen(function* () {
      if (!context.conversation) {
        return yield* Effect.die(new ServiceNotAvailableError(AiContext.Service.key));
      }
      const feed = yield* Database.resolve(DXN.parse(context.conversation), Feed.Feed).pipe(Effect.orDie);
      const runtime = yield* Effect.runtime<Database.Service>();
      const binder = yield* acquireReleaseResource(() => new AiContext.Binder({ feed, runtime }));
      return { binder };
    }),
  ),
);

The die surfaces as a defect through LayerStack, and the dispatcher's causeToError extracts the original ServiceNotAvailableError message for logs. Do NOT widen the spec output type with as unknown as casts to return Layer.empty — that hides the fact that the slice failed to materialise.

`LayerStack` pruning of unsatisfiable specs

A slice contains every spec at its affinity, but the LayerStack prunes specs whose requires aren't satisfied by the parent slice (or by earlier specs in this slice). The slice still initialises with the surviving specs; lookups for tags from dropped specs fail with a precise ServiceNotAvailable at resolve time. This lets a conversation-scoped process spec (like AiContextSpec requiring Database.Service) coexist with process ops that spawn without a space/conversation context.

Practical consequences:

See the process slice initialises even when an unrelated process-affinity spec has unsatisfied requirements test in LayerStack.test.ts for the canonical scenario.

Inline `Effect.provideService` is not enough

Providing a service inline (Effect.provideService(AiContext.Service, …) or Layer.succeed(AiContext.Service, …) via Effect.provide(...)) only applies to the calling fiber. The moment Operation.invoke(child) crosses a process boundary, the child spawn uses its own ServiceResolver/LayerStack and the inline provider is invisible. If any code path can Operation.invoke (or schedule) an op that requires the service, register a production LayerSpec for it — don't rely on inline providers alone.

Schema (`src/types/`)

ECHO type definitions using Effect Schema with Type.makeObject(), LabelAnnotation, and Annotation.IconAnnotation. Use namespace re-exports (e.g., export * as Chess from './Chess'). Include a make() factory function using Obj.make().

See: plugin-chess/src/types/Chess.ts

Operations (`src/operations/`)

Operation definitions use Operation.make() with meta, input/output schemas, and services. Handlers use Operation.withHandler() with Effect generators. The barrel exports definitions and an OperationHandlerSet.lazy([...]) built from Def.pipe(Operation.lazyHandler(() => import('./handler'))) pairings, which type-check the definition against its handler module.

Handler file shape (mirror plugin-trip/src/operations/add-segment.ts):

See: plugin-chess/src/operations/, plugin-trip/src/operations/add-segment.ts, plugin-chess-com/src/operations/sync-games.ts

App graph (`src/capabilities/app-graph-builder.ts`)

Extensions contribute navtree sections, their child nodes, and actions on any node. Assemble with const extensions = yield* Effect.all([...]) then Capability.contribute(AppCapabilities.AppGraphBuilder, extensions) — the raw array fails the BuilderExtensions typecheck. Wire with AppCapability.appGraphBuilder.

Section hub: one extension matching AppNodeMatcher.whenNavTreeGroup(GraphPath.GroupTypes.<group>) → AppNode.makeSection({...}), a second matching node.type === SECTION_TYPE && isSpace(node.properties.space) → the child nodes. Use TypeSection.createTypeSectionExtension when the section is keyed by typename.

Gate the section on content — the connector queries the objects it lists and returns Effect.succeed([]) while there are none, so the section is absent from spaces that don't use the plugin. Its + action goes with it, so the type also needs a SpaceCapabilities.CreateObjectEntry (src/capabilities/create-object.ts) for the first create.

Create where the objects are listed, not in the database — SpaceOperation.AddObject navigates to targetNodeId, falling back to the database subtree when absent, so forwarding a bare options.targetNodeId strands the user under Database. Point it at the node whose children are the objects: the section, or its object-listing child when the hub nests one (plugin-studio's Artifacts hang off a virtual Artifacts node, not the Studio section):

targetNodeId: options.targetNodeId ?? getPublicationsPath(options.db.spaceId),

Declare paths once in src/paths.ts — GraphPath.getSpacePath(spaceId, GroupSegments.<group>, <segment>), or GraphPath.createTypeSectionPaths(Type, { groupId }) — and import them from both the graph builder and the create-object entries.

See: plugin-inbox/src/capabilities/app-graph-builder.ts, plugin-inbox/src/paths.ts

Plugin Definition

A plugin is defined entirely by its dx.config.ts: Plugin.config({ plugin: { key, name, … }, modules: [...] }).

export const { meta, make } = config; export default config; is the whole public surface. Annotate

const config: Plugin.PluginConfig (or PluginConfig<Options> for a plugin with options) because module

bodies read meta from here, so inferring it would be circular. Modules come from makers in AppCapability

(and other plugins' makers, e.g. SpaceCapability.createObject) or Capability.lazyModule(name, spec, loader) for

anything without a maker. See plugin-sample/dx.config.ts (the commented example), plugin-sheet/dx.config.ts, and

plugin-debug/dx.config.ts (a plugin with options). The build evaluates dx.config.ts into a static manifest

(pluginConfigPlugin), so the file is data plus loaders:

marks it as a body the build locates but never loads; an unmarked dynamic import, an inline module

(Capability.inlineModule, Plugin.addModule({ activate })) and a props mapper all fail the build. Bodies

receive the plugin options as-is — read what you need inside the body.

src/namespace.ts. Never import components, containers or a #types barrel there; it is evaluated in Node at

build time and loaded eagerly at boot.

FooNamespace.makeSingleton<T>()('name'), or an event id string ${FooNamespace.key}.event.start; never import

#meta (a cycle with the config). A source file that needs the key uses FooNamespace.key.

makers pair a loader with an adapter (SchemaAdapter, SpaceTemplatesAdapter, TranslationsAdapter,

PluginAssetAdapter, CommandsAdapter, SurfaceAdapter) that normalizes the body's default export; the body

default-exports plain data ([Sheet.Sheet], the resources), not a Capability.makeModule.

use Plugin.addModule(Plugin.getModule(FooConfig, 'ModuleName')).

| Maker | Contributes | Default wave |

| ----------------------------------------------------------------------------- | --------------------------- | ---------------------------------------------------- |

| AppCapability.surface | React surfaces | demand — SurfacesRequested(role) per declared role |

| AppCapability.reactContext | React context provider | Startup (mandatory — see below) |

| AppCapability.reactRoot | React root | Startup |

| AppCapability.settings | Plugin settings | Startup |

| AppCapability.operationHandler | Operation handlers | Startup |

| AppCapability.navigationResolver | Navigation target resolvers | Startup |

| AppCapability.navigationHandler | Navigation handlers | Startup |

| AppCapability.layerSpec | Effect layer specs | Startup (restart-scoped) |

| AppCapability.commands | CLI commands | Startup |

| AppCapability.appGraphBuilder | Graph builder extensions | Idle |

| AppCapability.skillDefinition | AI skills | the assistant's start event |

| AppCapability.schema | ECHO type registration | idle (ungated) |

| AppCapability.translations | i18n resources | idle (ungated) |

| AppCapability.undoMappings / commentConfig / textContent / anchorSort | as named | idle (ungated) |

Activation waves

Omitting activatesOn means idle, not startup. An ungated module runs in the idle wave after

the app is interactive, and is pullable earlier as a dependency. That is the right default for

almost everything; the exceptions are listed above and are baked into the makers.

Five rules, each learned from a shipped regression:

  1. Use the maker. A module that builds its spec by hand (`Capability.lazyModule({ provides:

[Capabilities.ReactContext] })`) bypasses the maker's gate and silently inherits the idle

default. A React context arriving at idle leaves roots already mounted _outside_ it — Radix

reports Tooltip.Trigger must be used within Tooltip.

  1. The gate belongs on the PROVIDER, not the reader. If a Startup module reads state on its

first render, gate the _state module_ activatesOn: ActivationEvents.Startup. Declaring it as

the reader's requires does the opposite of what it looks like: requires only pulls a

provider forward when the provider is ungated, so pointing it at an idle-gated provider demotes

the reader into the idle wave. Measured: the deck shell went blank for 6.3 s that way.

  1. Headless state is not gated on its plugin's UI. Comment sync, compute graphs and filesystem

state work in a markdown document with no review/sheet/filesystem surface ever rendered. Gating

them on <Plugin>Events.Start conflates "the UI is on screen" with "the state exists"; leave

them ungated and let consumers requires them.

  1. Cross-plugin contributions ride the CONSUMING plugin's start event — a skill rides the

assistant's, a markdown extension rides markdown's — so the contribution costs nothing until its

host is in use.

  1. Permission-gated APIs wait for a user action. A prompt raised from activate has no

context to justify it, so the user Blocks it and the block sticks for the whole origin. Covers

getUserMedia, getDisplayMedia, notifications, geolocation, clipboard reads,

bluetooth/usb/serial/hid/midi, storage.persist(), and any fetch or WebSocket to

localhost or a LAN address, which raises Chrome's local network prompt with no permission API in

the code. Such a plugin also stays out of getDefaults in every environment.

A plugin's own <Plugin>Events.Start fires on demand: the module loader fires it when one of the

plugin's modules contributes a ReactSurface. An unvisited feature never starts.

Module activation ordering

Modules do not activate in registration order. Each module declares an

event that triggers it (activatesOn), and ordering between modules is

expressed through shared activation events — modules never reference each

other directly. Two levers on Plugin.addModule({...}):

finishes, the framework fires Event; any module with activatesOn: Event

then runs. Use to publish "I'm ready" (e.g. ClientEvents.ClientReady).

the framework activates Event's contributors and waits for them. Use to

force a prerequisite (e.g. schema/migration setup) ahead of this module.

To run module B after module A: A declares firesAfterActivation: [E], B

declares activatesOn: E. To force setup before B: B declares

firesBeforeActivation: [E]. Combine events with ActivationEvent.oneOf(...)

/ allOf(...).

Canonical example (idiom org.dxos.app-framework.moduleActivationOrdering):

plugin-client/src/ClientPlugin.ts — the Client module fires

ClientEvents.ClientReady after activating; SchemaDefs/Migrations listen on

it and use firesBeforeActivation to sequence setup ahead of themselves.

Non-Browser Variants

A plugin that must load outside a DOM (the dx CLI, workerd) ships one build per runtime from the same

dx.config.ts: the ./FooPlugin export has workerd, node and default (import) conditions pointing at

dist/lib/FooPlugin.workerd.mjs, .node.mjs and .mjs, each built from dx.config.ts?dx-env=<runtime> so it

keeps only the modules whose environments name that runtime. There are no FooPlugin.node.ts /

FooPlugin.workerd.ts files. Only add a variant the plugin genuinely supports — a front-end-only

plugin declares environments: ['browser', 'tauri'] on its modules and has no node/workerd conditions.

lazy defers evaluation, not bundling. Capability.lazyModule, OperationHandlerSet.lazy and

React.lazy all postpone the import at runtime while a bundler still walks it. The per-runtime build keeps

a browser-only module out of the node/workerd bundle only if its environments list omits that runtime;

a body that merely _imports_ a React surface elsewhere still drags React in.

Operation handlers that differ per runtime use a conditioned barrel in package.json imports:

| Barrel | Node file | Holds |

| ------------- | ------------------------ | ----------------------------------------- |

| #operations | src/operations/node.ts | Only the operations a node host can serve |

Import the handler set through the alias, not a relative path — a module body or dx.config.ts must use

'#operations'. A relative './operations' bypasses the import map, so the node condition never applies and

the browser set is dragged in anyway.

What makes a contribution browser-only:

object factory with a React component, so CreateObject is omitted from the node barrel.

TypeScript resolves the types condition for every environment, so it always sees the full barrel —

derive the node barrel from the modules whose environments include node so the two agree.

Headless values in UI packages

Much of what an operation handler needs is headless but lives behind a UI package's root barrel.

Import the UI-free entrypoint instead of relocating the code:

| Need | Import from | Not |

| -------------------------------------------------- | -------------------------------- | ------------------------- |

| Attention / Selection / ViewState | @dxos/react-ui-attention/types | the package root |

| Cursor, cherryPickHunk, createComment | @dxos/ui-editor/headless | the package root |

| hues, Hue, toHue | @dxos/ui-theme/headless | the package root |

| The Table schema | @dxos/react-ui-table/types | the package root |

| getSpace, ConnectionState, InvitationEncoder | @dxos/client/* | @dxos/react-client/* |

| Atom, Registry, Result | @effect-atom/atom | @effect-atom/atom-react |

A package that reads its own files at runtime needs a bundler-friendly entry too: paths computed from

import.meta.url land inside the compiled binary's embedded filesystem, where its siblings do not exist.

Guarding it

Every composer plugin inherits check-module-structure (.moon/tasks/tag-composer-plugin.yml), and CI

runs moon run :check-module-structure. It traces every export that declares workerd against the workerd

lists of .config/import-bans.yml, and every export that declares node against the node lists (React and

@dxos/react-ui). Diagnose a failure by printing the chain:

pnpm exec dx-trace-imports --conditional-exports --bans ../../../.config/import-bans.yml \
  --conditions workerd,worker --max-chains 5

See: plugin-sheet/src/operations/node.ts,

plugin-sheet/package.json (conditioned ./SheetPlugin and #operations), plugin-sheet/moon.yml

Runtime conditions

environments on a module lists every runtime condition it loads in: browser, tauri, node,

workerd. The per-runtime build keeps a module when its list names the runtime or it has no list.

A call site that restates a list names every runtime it wants, tauri included.

node condition, so its plugin tests run in browser mode (plugin-mermaid).

The workerd ban list covers CodeMirror, React and the design system, Lit, defuddle's DOM build and the local

client stack and CLI. Fix a violation at its source: a module EDGE has no use for (editor extensions, CLI commands,

local-client layer specs) lists ['browser', 'node', 'tauri']; a UI-free subpath of a banned package (/types,

/translations) goes in that file's allow list, and the tracer still walks into it.

Only composer-app's native bundles resolve tauri (bundle with DX_TAURI=true, or tauri dev

via TAURI_ENV_PLATFORM).

See: plugin-sandbox/dx.config.ts (LocalLauncher), app-framework/src/vite-plugin/plugin-config/index.ts

React Surface

Surfaces are contributed via Capability.contribute(Capabilities.ReactSurface, [...]) with Surface.create().

Common roles: article, section, card--content, object-properties, form-input, dialog.

Common filters: AppSurface.object(AppSurface.Article, Type), AppSurface.object(AppSurface.Card, Type), AppSurface.objectProperties(Type).

See: plugin-chess/src/capabilities/react-surface.tsx

Skill Definition

Skills provide AI agents with tools and instructions for a domain. Define a skill key, gather operations, and use Skill.make() with Skill.toolDefinitions().

See: plugin-chess/src/skills/chess-skill.ts

Translations

Resources keyed by both typename (for object labels) and FooNamespace.key (for plugin-scoped strings). Use useTranslation(FooNamespace.key) in components.

See: plugin-chess/src/translations.ts

package.json

#meta and the ./FooPlugin export both point at dx.config.ts (source and types; built default →

dist/lib/FooPlugin.mjs).

(dist/lib/FooPlugin.workerd.mjs, .node.mjs) and, when needed, #operations a per-condition map.

See Non-Browser Variants.

See: plugin-chess/package.json

moon.yml

Each package.json export subpath needs a matching --entryPoint in the compile task args

(vite-built plugins: a matching entry in vite.config.ts, including capabilities/node).

The inherited check-module-structure traces the workerd and node variants — see Non-Browser Variants. A subpath that declares no condition but is

imported by a headless host is named with a local args: [--export, <subpath>] (plugin-tasks/moon.yml).

See: plugin-chess/moon.yml

Coding Style

anti-patterns in the reactivity skill.

Build & Test

moon run plugin-foo:build
moon run plugin-foo:lint -- --fix
moon run plugin-foo:test
moon run plugin-foo:test-storybook

General Rules

out of a bundle — they defer evaluation, not bundling. See Non-Browser Variants.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.