The platform has had a complete story for one module using another's
*backend* since ADR 0006 — capabilities, versioned ranges, provider
registration. It has had none at all for one module using another's *browser*
code, and every workaround is wrong in a way that matters: a consumer cannot
import a peer module, it cannot re-implement a renderer for a domain it does
not own, and a second `entrypoints` role would put the platform in charge of
deciding when a slot inside someone else's screen should be filled.
Add a generic browser contribution. `manifestVersion: 7` declares one:
namespaced id, its own version, a target capability, a compatible range, and
one artifact. That is the complete list, and the omissions are the decision —
no payload schema, slot, ordering, or rendering hint exists anywhere, so Core
cannot learn what a slide is because the declaration cannot express it.
Discovery resolves a contribution artifact through the *identical* loop every
other compiled entrypoint uses, inheriting the path, containment, symlink,
extension, and file-kind checks rather than getting a weaker copy of them. The
registry publishes one only when another eligible module provides the target
capability within the declared range; otherwise it is absent rather than
mounted and broken. `apps/api` serves it as a sibling of the artifact and
display routes, with the same policy: three lookup keys, one exact match, one
already-validated path, and one indistinguishable 404 for unknown, undeclared,
stale, and incompatible alike.
A consumer discovers through the host, never through a URL. Its descriptor
carries identity, version, and capability; the URL stays server-side and is
resolved exactly as `api.request("records")` is. A module can only ever see
contributions aimed at a capability it itself provides, and cannot name its
way to anything else — a mount for a withheld id fails without fetching.
The consumer owns the domain contract entirely. Input is opaque JSON, checked
structurally so a Date, a function, a cycle, or `undefined` fails at the
boundary rather than vanishing somewhere far from the mistake, and checked for
nothing else. A contributed renderer receives its own id and that input: no
API client, realtime, principal, configuration, database, storage, or
credential. Loading one grants its module nothing.
The contribution ABI is versioned separately from the module UI ABI, because
the two have different shapes and lifecycles and coupling them would force
every module to rebuild whenever either moved. It supports asynchronous
readiness, update-without-remount (a screen that remounted per tick would
restart animations and reload media), deterministic cleanup in a `finally`,
and sanitized failure that never carries the consumer's domain data. Each
renderer mounts in its own isolated root with its own stylesheet.
The template now declares a contribution, so `pnpm build` exercises the whole
authoring path, and the shell suite drives the full relationship — one module
discovering, mounting, updating, and unmounting another's React renderer with
neither importing the other.
Co-Authored-By: Claude Opus 5 <[email protected]>
67 lines
3.5 KiB
TypeScript
67 lines
3.5 KiB
TypeScript
import { z } from "zod";
|
|
import { capabilityIdSchema, packageRelativePathSchema } from "./identifiers.js";
|
|
import { semanticVersionRangeSchema, semanticVersionSchema } from "./versions.js";
|
|
|
|
/**
|
|
* A **browser contribution**: one module's compiled renderer, declared for a capability another
|
|
* module provides, and mounted by that other module inside a container it owns (ADR 0041).
|
|
*
|
|
* This is deliberately not a third UI role. `entrypoints.ui` and `entrypoints.display` are artifacts
|
|
* *the platform* mounts, in surfaces the platform owns. A contribution is mounted by a **consumer
|
|
* module**, at a moment and in a place only that module understands — a slot in its own layout —
|
|
* and the platform never renders one on its own.
|
|
*
|
|
* ## What the platform knows, and the complete list of it
|
|
*
|
|
* Identity, version, target capability, compatible range, and one compiled artifact. That is all,
|
|
* and the omissions are the point: nothing here says what the renderer draws, what shape its input
|
|
* has, when it should be mounted, or what any of it means. Core could not learn what a "slide" or a
|
|
* "timeline slot" is from this declaration, because the declaration cannot express it — the
|
|
* domain contract belongs entirely to the consumer's own versioned input.
|
|
*
|
|
* Inert, like every other manifest declaration: reading one causes no import, no evaluation, and no
|
|
* network or database access.
|
|
*/
|
|
|
|
/** `<module-id>.<local-name>` — exactly two segments. The prefix is checked against the declaring
|
|
* module in `moduleManifestSchema`, which is what makes a contribution id globally unique without a
|
|
* registry: module ids are already unique, so two modules cannot produce the same contribution id. */
|
|
export const contributionIdSchema = z
|
|
.string()
|
|
.min(3)
|
|
.max(160)
|
|
.regex(
|
|
/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*\.[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u,
|
|
"Must be <module-id>.<local-name>, both lowercase kebab-case.",
|
|
);
|
|
|
|
export const moduleContributionDeclarationSchema = z
|
|
.object({
|
|
id: contributionIdSchema,
|
|
/** This contribution's own version, independent of the module's. A consumer sees it and a host
|
|
* verifies the artifact claims it, so a stale bundle is caught exactly as it is for a module
|
|
* UI artifact. */
|
|
version: semanticVersionSchema,
|
|
/** The capability this renderer plugs into — owned by whichever module provides it, never by
|
|
* the contributing module. */
|
|
capability: capabilityIdSchema,
|
|
/** The provider capability versions this renderer is compatible with. A provider outside this
|
|
* range makes the contribution unpublishable rather than mounted and broken. */
|
|
capabilityRange: semanticVersionRangeSchema,
|
|
/** The compiled browser artifact, resolved and validated during discovery exactly like every
|
|
* other declared entrypoint: package-relative, inside the package before and after symlink
|
|
* resolution, and a real `.js`/`.mjs` file. */
|
|
artifact: packageRelativePathSchema,
|
|
description: z.string().trim().min(1).max(240).optional(),
|
|
})
|
|
.strict();
|
|
|
|
export type ModuleContributionDeclaration = z.output<typeof moduleContributionDeclarationSchema>;
|
|
|
|
/** The local segment of a contribution id — the part after the declaring module's own id. Used by
|
|
* the canonical builder to locate the fixed source directory, so a module author configures no
|
|
* paths and cannot point the build somewhere else. */
|
|
export function contributionLocalName(contributionId: string): string {
|
|
return contributionId.slice(contributionId.indexOf(".") + 1);
|
|
}
|