Skip to content
Fragments — Reusable Content Fragments
AutoXXS (320px)XS (375px)SM (640px)MD (768px)LG (1024px)XL (1280px)XXL (1536px)
SketchMaterialiOSTamagui
DataInjectionKeyPatternsServiceTransactionProcessResearchProductQualityPerformanceSpecDomainFunctionTechnologyArchitectureConfigMiddlewareDataDatabaseDrizzleMigrationModelop-sqliteSchemaSQLState ManagementDraftKeystoneMergePatchPatchesPersistenceReactiveRedoStoreUndoTestingDeviceFactoryIsolationTypeScriptZodTopicsCommunicationBidsNVCDesignDesign ImplicationsEducationPedagogyFoundationsPsychologyAttachmentFloodingRelatingAuthentic RelatingUIEditorReact Native

Fragments — Reusable Content Fragments

Fragments are reusable content files stored in instructions/. They eliminate duplication across instruction documents: a piece of information that is true in multiple contexts (the compiler layout, the test commands, the TagProcessor interface) lives in exactly one file and is inlined at compile time wherever it is needed.

Each fragment file carries structured frontmatter — id, type: fragment, tags — in addition to the standard title and description fields.

How to embed a fragment

Use a self-closing include tag anywhere in an .mdoc instruction file:

Every compiler change must pass all three checks before it is considered done. Run them in order — each builds on the previous.
### Step 1 — Type check and unit tests
```bash
# From starspec/
pnpm --filter @starspec/compiler build # TypeScript compile — zero errors required
pnpm test # agent-pass, public-pass, instructions-pass tests

All tests must pass. Do not proceed if any test fails.

Step 2 — End-to-end compile

Terminal window
# From starspec/
pnpm compile

Builds the compiler then runs it against content/. Inspect at least one generated file for the affected type:

  • Agent bundle: dist/bundles/{type}/{id}.toon — verify the new or changed field is present and correct
  • Public page: src/content/docs/{type}/{id}.md — verify the rendered section looks right
  • Aggregate page (if applicable): src/content/docs/{aggregate-name}.md

Step 3 — Regression check

Terminal window
# From starspec/
pnpm build

Confirm:

  • src/summary.json reports zero validation issues (or only pre-existing ones known before your change)
  • The Starlight site builds without errors

For changes affecting the Component Gallery or Screenshot Export, run the automated E2E agent. (These tests use the *.e2e.ts naming convention and are excluded from standard unit tests).

Terminal window
# From starspec/
pnpm test:e2e

This agent verifies:

  • All download buttons have deterministic IDs
  • Every component variant in the gallery can be successfully captured
  • Grouped component tabs are correctly handled
  • Both “Chrome” and “Clean” export modes function as expected

For interactive debugging of visual regressions:

Terminal window
pnpm test:e2e:ui

Do’s and Don’ts

Do:

  • Run all steps in order — each builds on the previous
  • Inspect at least one generated file for the affected type after end-to-end compile
  • Run the E2E agent when changes affect the Component Gallery or Screenshot Export

Don’t:

  • Skip a step or proceed if any test fails
  • Treat a passing TypeScript compile as sufficient without running end-to-end compile and site build

Definition of Done

  • TypeScript compile and unit tests pass
  • End-to-end compile produces correct output
  • Starlight site builds without errors
The `source` path is relative to `instructions/` and omits the `.mdoc` extension. At compile time, the instructions pass replaces the directive with the body of the referenced fragment file. Both the JSON bundle and the rendered Starlight page receive the fully-resolved content — there is no runtime indirection.
### The `frontmatter` attribute
| Value | Behaviour |
|---|---|
| `frontmatter=false` (default) | Frontmatter is stripped; only the body is inlined |
| `frontmatter=true` | The raw `---` frontmatter block is prepended to the inlined body |
Use `frontmatter=true` when the consuming context is an agent bundle and you need the fragment's `id`, `type`, or `tags` metadata alongside its prose. Do **not** use `frontmatter=true` in files that feed the public Starlight site — the injected `---` block is not valid inside an already-frontmatted MDX page.
Fragments can be placed inline within prose or under a section heading:
```markdoc
## Verification
Every compiler change must pass all three checks before it is considered done. Run them in order — each builds on the previous.
### Step 1 — Type check and unit tests
```bash
# From starspec/
pnpm --filter @starspec/compiler build # TypeScript compile — zero errors required
pnpm test # agent-pass, public-pass, instructions-pass tests

All tests must pass. Do not proceed if any test fails.

Step 2 — End-to-end compile

Terminal window
# From starspec/
pnpm compile

Builds the compiler then runs it against content/. Inspect at least one generated file for the affected type:

  • Agent bundle: dist/bundles/{type}/{id}.toon — verify the new or changed field is present and correct
  • Public page: src/content/docs/{type}/{id}.md — verify the rendered section looks right
  • Aggregate page (if applicable): src/content/docs/{aggregate-name}.md

Step 3 — Regression check

Terminal window
# From starspec/
pnpm build

Confirm:

  • src/summary.json reports zero validation issues (or only pre-existing ones known before your change)
  • The Starlight site builds without errors

For changes affecting the Component Gallery or Screenshot Export, run the automated E2E agent. (These tests use the *.e2e.ts naming convention and are excluded from standard unit tests).

Terminal window
# From starspec/
pnpm test:e2e

This agent verifies:

  • All download buttons have deterministic IDs
  • Every component variant in the gallery can be successfully captured
  • Grouped component tabs are correctly handled
  • Both “Chrome” and “Clean” export modes function as expected

For interactive debugging of visual regressions:

Terminal window
pnpm test:e2e:ui

Do’s and Don’ts

Do:

  • Run all steps in order — each builds on the previous
  • Inspect at least one generated file for the affected type after end-to-end compile
  • Run the E2E agent when changes affect the Component Gallery or Screenshot Export

Don’t:

  • Skip a step or proceed if any test fails
  • Treat a passing TypeScript compile as sufficient without running end-to-end compile and site build

Definition of Done

  • TypeScript compile and unit tests pass
  • End-to-end compile produces correct output
  • Starlight site builds without errors
**One level only.** Nested includes (a fragment referencing another fragment) are not resolved. This prevents cycles and keeps the mechanism predictable.
## Available fragments
| Path | Title | What it contains |
|---|---|---|
| `fragments/compiler/content-layout` | Content Layout | `content/` directory tree with all 8 doc types |
| `fragments/compiler/source-layout` | Compiler Layout | `packages/compiler/src/` annotated file tree |
| `fragments/tags/inventory` | Tag Inventory | Full table of every Markdoc tag with parent and description |
| `fragments/compiler/processor-api` | TagProcessor Interface | `TagProcessor<T>` interface, `render()` signature, `merge()` rules |
| `fragments/compiler/scope-rules` | Scope Rules | Scope propagation, values, and filtering checklist |
| `fragments/compiler/tag-documentation` | Documenting a Tag | How to write a `*.tag.mdoc` file — structure, conventions, and checklist |
| `agents/starspec/test-suite` | Test Suite | Three-step build / test / compile verification sequence |
| `agents/starspec/update-checklist` | Documentation Update Checklist | Pre-close checklist for any compiler modification task |
| `agents/conventions/naming-standards` | Naming Conventions | Id naming rules for all StarSpec documents and tags |
| `agents/conventions/memo-naming` | Memo Naming | Naming conventions for memo-to-prespec extraction |
| `agents/common/mcp-policy` | MCP Server Policy | Fail-early rules for MCP availability and tool call errors |
| `agents/common/command-routing` | Command Routing | Maps agent user commands to instruction paths |
| `agents/common/bundle-paths` | Aggregate Bundle Paths | Index of system-wide data bundles for agents |
| `agents/common/tutorial` | Agent Tutorial | User-facing guide for the Starscribe agent |
| `fragments/uidsl/layout` | Layout Components | Structural primitives: stack, row, grid |
| `fragments/uidsl/display` | Display Components | Presentational: text, badge, icon, qrcode, button |
| `fragments/uidsl/forms` | Form Components | Inputs: select, radio, colorpicker, datepicker |
| `fragments/uidsl/navigation` | Navigation Components | Wayfinding: tabs, nav, menu, modal |
| `fragments/uidsl/utilities` | Utility Components | Helpers: divider, placeholder |
| `fragments/wireframe/theme-variables` | Theme Variables | Required `--wf-*` CSS variables for wireframe themes (brand, semantic, geometry, font) |
| `fragments/wireframe/css-conventions` | CSS Conventions | BEM naming and selector structure for wireframe CSS |
| `fragments/wireframe/theme-selector-pattern` | Theme Selector Pattern | Copy-paste compound CSS selector template with specificity notes |
Each fragment is also queryable as a standalone bundle: `get_instructions("starspec/agents/starspec/test-suite")`.
## When to create a new fragment
Extract a new fragment when:
- The same block of content (table, code example, list) must appear in two or more instruction docs
- The content is a fact about the system (a file path, a command, an interface) that will drift over time and require synchronised updates
Do **not** extract:
- Content that is only used once — inline it
- Worked examples that are context-specific (e.g. a fixture showing how a domain file looks)
- Short phrases or single sentences — the overhead of a file is not worth it
## Adding a fragment
1. Create `instructions/fragments/{name}.mdoc` with frontmatter (`id`, `type: fragment`, `tags`, `title`, `description`) and body content
2. Add a row to the table in this file (`instructions/fragments.mdoc`)
3. Add a row to `instructions/fragments/tags/inventory.mdoc` if the fragment documents a new tag
4. Embed it in consumer docs with `\{% include source="fragments/{name}" /%\}` (omit the backslash)
5. Run `pnpm compile` — verify the include resolves correctly in the rendered output
## How it is implemented
`resolveIncludes(content, instructionsDir)` in `passes/instructions.ts` scans content for `\{% include source="..." frontmatter=... /%\}` with a regex, reads the referenced `.mdoc` file, and either strips or injects the frontmatter based on the `frontmatter` attribute. It is called once per file in both the agent bundle loop and the public render loop. If the referenced file does not exist, a visible HTML comment is emitted and a warning is logged — the build continues.
<RelatedTable links={[{"label":"architecture","url":"/starspec/architecture"},{"label":"adding-a-tag","url":"/starspec/adding-a-tag"}]} />