Generator API
The generator module exports two public functions and the input interfaces needed to call them.
generateDocument(input)
Generates a DSCPDocument from the provided kernel state inputs.
ts
function generateDocument(input: GeneratorInput): DSCPDocumentInput interface
ts
interface GeneratorInput {
readonly tokenGraph: TokenGraphInput;
readonly componentRegistry: ComponentRegistryInput;
readonly deprecationLedger: DeprecationLedgerInput;
readonly ruleRegistry: RuleRegistryInput;
readonly violations: readonly ViolationInput[];
readonly snapshotHash: string;
}The input interfaces mirror the shape of a DSR KernelState without importing DSR directly, preserving the dependency boundary.
Sub-interfaces
ts
interface TokenGraphInput {
readonly tokens: ReadonlyMap<string, DtifFlattenedToken>;
readonly byType: ReadonlyMap<TokenType, readonly DtifFlattenedToken[]>;
}
interface ComponentRegistryInput {
readonly components: ReadonlyMap<string, ComponentInput>;
}
interface DeprecationLedgerInput {
readonly entries: ReadonlyMap<string, DeprecationEntryInput>;
}
interface RuleRegistryInput {
readonly rules: ReadonlyMap<string, RuleInput>;
}Return value
A fully-formed DSCPDocument with:
$schemaset toDSCP_SCHEMA_URIspecVersionset toDSCP_SPEC_VERSIONgeneratedAtset tonew Date().toISOString()kernelSnapshotHashset toinput.snapshotHash- All sections populated from the corresponding input fields
Token value serialisation
| Token value type | Serialised as |
|---|---|
string | Value as-is |
number | String(value) |
boolean | String(value) |
null / undefined | Empty string "" |
| Object / array | JSON.stringify(value) |
renderMarkdown(doc)
Renders a DSCPDocument as a DESIGN_SYSTEM.md string.
ts
function renderMarkdown(doc: DSCPDocument): stringOutput format
The rendered markdown includes:
- A
# DESIGN_SYSTEM.mdheading - A preamble with the spec version, generation timestamp, and snapshot hash
- One token section per token type (only active, non-deprecated tokens)
- A violations section (only if violations exist)
- A components section (only if components exist)
- An active rules section (only if enabled rules exist)
Each section is wrapped in typed HTML comment markers for agent parsing:
markdown
<!-- dscp:tokens:color -->
## Tokens: color
...
<!-- /dscp:tokens:color -->Omission rules
- Token types with no active (non-deprecated) tokens are omitted entirely.
- The violations section is omitted if
doc.violationsis empty. - The components section is omitted if
doc.componentRegistry.totalCount === 0. - The rules section is omitted if no rules have
enabled: true.
Constants
ts
export const DSCP_SCHEMA_URI = 'https://dscp.lapidist.net/schema/v1.json';
export const DSCP_SPEC_VERSION = '1.0.0';