Skip to content

Theme integration

MySTRA emits readable MyST fallback nodes and a versioned publication payload. A rich theme can replace a recognized carrier with shared ASTRA UI, retaining the fallback when it cannot decode the publication or resolve a record.

Record identity

Placed blocks carry an astra-<kind> class and data.astra:

{
  kind: 'output',
  id: 'fit',
  ref: 'stage.outputs.fit', // the SDK element ref
  universe: 'universes.baseline',    // optional context for this placement
}

ref is an SDK ref, independent of a MyST label or HTML identifier. An option uses its decision's ref and its option id. Evidence uses its insight's ref and evidenceIndex, the zero-based index in the insight's evidence array. Analysis cards and navigation references use analysisKey, the SDK analysis key; the root key is "". Analysis keys and element refs are distinct lookup domains.

Inline references use astra-ref and astra-ref--<kind> classes. Values also carry their output/decision ref, selected universe and display metadata (type, col, filter, unit, or decision selection as applicable). The neutral label is in the node's children. Keep those children when a rich lookup fails.

The block classes are astra-decision, astra-output, astra-input, astra-finding, astra-prior-insight, astra-option, astra-subanalysis, and astra-inputs / astra-outputs for the input and output registries. Output classes also include astra-output--<type>. Custom :label: and :class: options do not change SDK identity. Finding and decision tags remain in node.data.tags.

Every placed element of a block carries the block's universe, including each record of a registry and each registry row, so a carrier can be rendered without its siblings.

Publication transport v2

Every successfully transformed page receives a hidden div.astra-publication-bundle with node.data.astraPublication:

interface AstraPublicationData {
  schemaVersion: 'astra-publication-bundle.v2';
  activeAnalysisKey: string;
  universe?: string;
  analysis: ResolvedAnalysis;
  status: StatusReport;
  resources: Readonly<Record<string, { cacheToken: string }>>;
}

analysis and status are the unchanged SDK reports, with their own schema_version markers. They contain the complete declaration graph and all planned results across universes. activeAnalysisKey and universe are page presentation context. A placement's data.astra.universe overrides the page's universe. No re-resolution is needed when a browser switches universes.

Decode it with the contract module MySTRA publishes on npm. It depends only on the SDK, so a theme can import it without MyST's build-time packages:

import {
  astraNodeMetadata,
  findAstraPublication,
  type AstraPublication,
} from '@astra-spec/mystra/publication';

// The first valid carrier in document order, decoded with the SDK's parsers and
// indexed; resource links are joined back to result IDs; undefined otherwise.
const publication = findAstraPublication(mdast);
const placed = astraNodeMetadata(node); // a node's data.astra, fields still unknown

The decoder validates the outer version, the context fields and the resource metadata, checks that the active key and universe exist in the index, and does not accept pre-v2 payloads. The module also exports the payload, placement and artifact types (AstraPublicationData, AstraNodeData, AstraArtifactData) and the carrier class names, so a theme never restates them.

Analyses form a graph: use the SDK's cycle-safe graph walkers and indexes rather than recursive tree assumptions. A varying result belongs to the analysis owning its universe, which can differ from the output's declaring analysis. Use the SDK's result selectors to apply that relationship.

Browser asset URLs

The envelope's resources is keyed by opaque Result.id, not output ref. A result ID can identify a particular universe or pinned result. Its cacheToken is the SHA-256 of the actual bytes read by the native SDK.

MySTRA separately emits hidden div.astra-publication-resources links:

{
  type: 'link',
  static: true,
  url: '<source-page-relative immutable resource path>',
  data: { astraArtifact: { resultId: string, cacheToken: string } },
  children: [{ type: 'text', value: '<result ID>' }],
}

MyST copies these resources into the site and rewrites the URLs. findAstraPublication accepts a URL only when the link immediately follows the carrier, the result ID is known, its token matches resources[resultId], and the URL is site-relative or HTTP(S); the result is publication.artifactUrls. The report's Place.file_path describes a repository or commit tree and is not a browser URL. Never construct an asset URL from it.

The plugin reads actual content with the SDK's lazy resultResources handles, trying the result's places until bytes are available. It streams chunks into a temporary file while hashing, then atomically publishes content-hashed files under _build/astra-resources/. This handles historical commit trees and large-file stand-ins without reading the wrong worktree file.

Results of data outputs never have a resource: no page displays a dataset, so its bytes are neither read nor published. The result remains in analysis.results, and its places' file_path values name where the file lives. Show that path as text if useful, not as a link.

Resource availability and provenance are independent. A file without a record can be published even while its status is missing and its recorded-byte state is absent. Use the verified resource map for display availability and the status report for provenance indicators.

Evidence and citations

Evidence identity is an insight ref plus array index. Use getEvidenceBindings(index, insightRef, evidenceIndex, universe) to select the SDK's effective bindings for the evaluation universe. Each binding retains its concrete output, optional planned result, evaluation universe and target_universe where applicable. Explicitly pinned evidence remains selected regardless of the page universe. A once-built target can be selected by a switch in one universe and a different once-built target in another.

Use binding.output for record lookup and binding.result for resource lookup. An unplanned output can remain addressable without a result. The aggregate Evidence.cites list is retained in the raw report, but does not determine contextual rendering. No authored switch or pin grammar needs reimplementation.

MySTRA registers literature DOIs with MyST in a hidden astra-cites carrier for both narrative and parenthetical citations. The host's citation/reference data provides bibliography labels and paper URLs; the SDK does not fetch papers.

Fallbacks

A theme should decode once per document, keep its index and verified asset map in context, and override only recognized carriers. On a missing record or malformed transport, render the original children. Pure MyST output remains usable without ASTRA theme code or a Python service.