Skip to content

PromptScript API


Abstract Class: MarkdownInstructionFormatter

Defined in: formatters/src/markdown-instruction-formatter.ts:120

Abstract base class for markdown-based instruction formatters.

Provides shared section extraction logic (project, tech stack, architecture, code standards, git commits, config files, commands, post-work, documentation, diagrams, restrictions) and standard simple/multifile/full mode implementations.

Subclasses configure behavior via MarkdownFormatterConfig and can override specific methods for format-specific customization.

Extends

Extended by

Constructors

Constructor

new MarkdownInstructionFormatter(config): MarkdownInstructionFormatter

Defined in: formatters/src/markdown-instruction-formatter.ts:128

Parameters

config

MarkdownFormatterConfig

Returns

MarkdownInstructionFormatter

Overrides

BaseFormatter.constructor

Properties

config

protected readonly config: MarkdownFormatterConfig

Defined in: formatters/src/markdown-instruction-formatter.ts:126


defaultConvention

readonly defaultConvention: string

Defined in: formatters/src/markdown-instruction-formatter.ts:124

Default convention for this formatter

Overrides

BaseFormatter.defaultConvention


description

readonly description: string

Defined in: formatters/src/markdown-instruction-formatter.ts:123

Human-readable description

Overrides

BaseFormatter.description


name

readonly name: string

Defined in: formatters/src/markdown-instruction-formatter.ts:121

Unique formatter identifier

Overrides

BaseFormatter.name


outputPath

readonly outputPath: string

Defined in: formatters/src/markdown-instruction-formatter.ts:122

Default output file path

Overrides

BaseFormatter.outputPath


standardsExtractor

protected readonly standardsExtractor: StandardsExtractor

Defined in: formatters/src/base-formatter.ts:28

Shared standards extractor for consistent extraction across all formatters.

Inherited from

BaseFormatter.standardsExtractor

Methods

addCommonSections()

protected addCommonSections(ast, renderer, sections): void

Defined in: formatters/src/markdown-instruction-formatter.ts:525

Parameters

ast

Program

renderer

ConventionRenderer

sections

string[]

Returns

void


addSection()

protected addSection(sections, content): void

Defined in: formatters/src/markdown-instruction-formatter.ts:545

Parameters

sections

string[]

content

string | null

Returns

void


architecture()

protected architecture(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:644

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


codeStandards()

protected codeStandards(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:657

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


commands()

protected commands(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:713

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


configFiles()

protected configFiles(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:695

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


createRenderer()

protected createRenderer(options?): ConventionRenderer

Defined in: formatters/src/base-formatter.ts:34

Create a convention renderer for this formatter. Uses the provided convention from options or falls back to the default.

Parameters

options?

FormatOptions

Returns

ConventionRenderer

Inherited from

BaseFormatter.createRenderer


dedent()

protected dedent(text): string

Defined in: formatters/src/base-formatter.ts:452

Remove common leading whitespace from all lines (dedent). Handles the case where trim() was already called, causing the first line to lose its indentation while subsequent lines retain theirs. Calculates minimum indent from lines 2+ only.

Parameters

text

string

Returns

string

Inherited from

BaseFormatter.dedent


diagrams()

protected diagrams(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:776

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


documentation()

protected documentation(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:757

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


examples()

protected examples(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:848

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


extractAgents()

protected extractAgents(ast): MarkdownAgentConfig[]

Defined in: formatters/src/markdown-instruction-formatter.ts:446

Parameters

ast

Program

Returns

MarkdownAgentConfig[]


extractCommands()

protected extractCommands(ast): MarkdownCommandConfig[]

Defined in: formatters/src/markdown-instruction-formatter.ts:288

Parameters

ast

Program

Returns

MarkdownCommandConfig[]


extractExamples()

protected extractExamples(ast): object[]

Defined in: formatters/src/base-formatter.ts:532

Extract examples from the

Parameters

ast

Program

Returns

object[]

Examples

block. Returns an array of example definitions with name, input, output, and optional description.

Inherited from

BaseFormatter.extractExamples


extractRestrictionsItems()

protected extractRestrictionsItems(content): string[]

Defined in: formatters/src/markdown-instruction-formatter.ts:852

Parameters

content

BlockContent

Returns

string[]


extractSectionWithCodeBlock()

protected extractSectionWithCodeBlock(text, header): string | null

Defined in: formatters/src/base-formatter.ts:176

Safe extraction of a section that contains a header + content + code block + content Avoids ReDoS by using string search instead of backtracking regex. Matches pattern: Header ... ...

Parameters

text

string

string

Returns

string | null

Inherited from

BaseFormatter.extractSectionWithCodeBlock


extractSkillExamples()

protected extractSkillExamples(skillProps): object[]

Defined in: formatters/src/base-formatter.ts:545

Extract examples from a skill's nested examples property. Returns the same shape as extractExamples.

Parameters

skillProps

Record\<string, Value>

Returns

object[]

Inherited from

BaseFormatter.extractSkillExamples


extractSkills()

protected extractSkills(ast): MarkdownSkillConfig[]

Defined in: formatters/src/markdown-instruction-formatter.ts:354

Parameters

ast

Program

Returns

MarkdownSkillConfig[]


extractTechStackFromContext()

protected extractTechStackFromContext(context): string[]

Defined in: formatters/src/markdown-instruction-formatter.ts:602

Parameters

context

Block | undefined

Returns

string[]


extractTechStackFromStandards()

protected extractTechStackFromStandards(standards): string[]

Defined in: formatters/src/markdown-instruction-formatter.ts:628

Parameters

standards

Block | undefined

Returns

string[]


extractText()

protected extractText(content): string

Defined in: formatters/src/base-formatter.ts:69

Extract text from block content.

Parameters

content

BlockContent

Returns

string

Inherited from

BaseFormatter.extractText


findBlock()

protected findBlock(ast, name): Block | undefined

Defined in: formatters/src/base-formatter.ts:62

Find a block by name, ignoring internal blocks (starting with __).

Parameters

ast

Program

name

string

Returns

Block | undefined

Inherited from

BaseFormatter.findBlock


format()

format(ast, options?): FormatterOutput

Defined in: formatters/src/markdown-instruction-formatter.ts:145

Transform AST to tool-specific format

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput

Overrides

BaseFormatter.format


formatArray()

protected formatArray(arr): string

Defined in: formatters/src/base-formatter.ts:120

Format an array as comma-separated string.

Parameters

arr

unknown[]

Returns

string

Inherited from

BaseFormatter.formatArray


formatFull()

protected formatFull(ast, options?): FormatterOutput

Defined in: formatters/src/markdown-instruction-formatter.ts:229

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput


formatMultifile()

protected formatMultifile(ast, options?): FormatterOutput

Defined in: formatters/src/markdown-instruction-formatter.ts:193

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput


formatSimple()

protected formatSimple(ast, options?): FormatterOutput

Defined in: formatters/src/markdown-instruction-formatter.ts:173

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput


formatStandardsList()

protected formatStandardsList(items): string[]

Defined in: formatters/src/base-formatter.ts:112

Format standards list from array of values (pass-through). Returns array of strings for rendering as bullet list.

Parameters

items

Value

Returns

string[]

Inherited from

BaseFormatter.formatStandardsList


generateAgentFile()

protected generateAgentFile(config): FormatterOutput

Defined in: formatters/src/markdown-instruction-formatter.ts:470

Parameters

config

MarkdownAgentConfig

Returns

FormatterOutput


generateCommandFile()

protected generateCommandFile(config): FormatterOutput

Defined in: formatters/src/markdown-instruction-formatter.ts:327

Parameters

config

MarkdownCommandConfig

Returns

FormatterOutput


generateSkillFile()

protected generateSkillFile(config): FormatterOutput

Defined in: formatters/src/markdown-instruction-formatter.ts:387

Parameters

config

MarkdownSkillConfig

Returns

FormatterOutput


getArrayElements()

protected getArrayElements(content): Value[]

Defined in: formatters/src/base-formatter.ts:144

Extract array elements from block content.

Parameters

content

BlockContent

Returns

Value[]

Inherited from

BaseFormatter.getArrayElements


getMetaField()

protected getMetaField(ast, key): string | undefined

Defined in: formatters/src/base-formatter.ts:134

Get meta field value as string.

Parameters

ast

Program

key

string

Returns

string | undefined

Inherited from

BaseFormatter.getMetaField


getOutputPath()

protected getOutputPath(options?): string

Defined in: formatters/src/base-formatter.ts:55

Get the output path, respecting options override.

Parameters

options?

FormatOptions

Returns

string

Inherited from

BaseFormatter.getOutputPath


getPrettierOptions()

protected getPrettierOptions(options?): Required\<PrettierMarkdownOptions>

Defined in: formatters/src/base-formatter.ts:45

Get resolved Prettier options, merging provided options with defaults.

Parameters

options?

FormatOptions

Returns

Required\<PrettierMarkdownOptions>

Inherited from

BaseFormatter.getPrettierOptions


getProp()

protected getProp(content, key): Value | undefined

Defined in: formatters/src/base-formatter.ts:83

Get a specific property from block content.

Parameters

content

BlockContent

key

string

Returns

Value | undefined

Inherited from

BaseFormatter.getProp


getProps()

protected getProps(content): Record\<string, Value>

Defined in: formatters/src/base-formatter.ts:97

Get all properties from block content.

Parameters

content

BlockContent

Returns

Record\<string, Value>

Inherited from

BaseFormatter.getProps


getSectionName()

protected getSectionName(key): string

Defined in: formatters/src/markdown-instruction-formatter.ts:272

Parameters

key

SectionNameKey

Returns

string


getSkillBasePath()

getSkillBasePath(): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:137

Base path for skills, or null if formatter has no skill support.

Returns

string | null

Overrides

BaseFormatter.getSkillBasePath


getSkillFileName()

getSkillFileName(): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:141

Skill file name, or null if formatter has no skill support.

Returns

string | null

Overrides

BaseFormatter.getSkillFileName


gitCommits()

protected gitCommits(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:673

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


isSafeSkillName()

protected isSafeSkillName(name): boolean

Defined in: formatters/src/base-formatter.ts:622

Check if a skill name is safe for use in file paths.

Parameters

name

string

Returns

boolean

Inherited from

BaseFormatter.isSafeSkillName


knowledgeContent()

protected knowledgeContent(ast, _renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:801

Render remaining

Parameters

ast

Program

_renderer

ConventionRenderer

Returns

string | null

Knowledge

text content that isn't consumed by other sections. Strips "## Development Commands" and "## Post-Work Verification" sub-sections since those are already rendered by commands() and postWork().


normalizeMarkdownForPrettier()

protected normalizeMarkdownForPrettier(content): string

Defined in: formatters/src/base-formatter.ts:204

Normalize markdown content to match Prettier formatting. - Strips common leading indentation from lines - Trims trailing whitespace from lines - Normalizes markdown table formatting - Adds blank lines before lists when preceded by text - Adds blank lines before code blocks when preceded by text - Escapes markdown special characters in paths

Parameters

content

string

Returns

string

Inherited from

BaseFormatter.normalizeMarkdownForPrettier


postWork()

protected postWork(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:744

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


project()

protected project(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:549

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


referenceProvenance()

protected referenceProvenance(sourcePath): string

Defined in: formatters/src/base-formatter.ts:615

Generate a provenance comment for a reference file.

Parameters

sourcePath

string

Returns

string

Inherited from

BaseFormatter.referenceProvenance


referencesMode()

referencesMode(): "none" | "directory" | "inline"

Defined in: formatters/src/base-formatter.ts:608

How this formatter handles skill references. - 'directory': emit as separate files in references/ subdirectory - 'inline': append as sections in the main output file - 'none': references not supported

Returns

"none" | "directory" | "inline"

Inherited from

BaseFormatter.referencesMode


renderCodeFence()

protected renderCodeFence(content, lang?): string

Defined in: formatters/src/base-formatter.ts:630

Render content inside a code fence, using a longer fence if the content itself contains triple backticks (prevents code fence injection).

Parameters

content

string

lang?

string = ''

Returns

string

Inherited from

BaseFormatter.renderCodeFence


renderExamplesSection()

protected renderExamplesSection(ast, renderer, sectionName?): string | null

Defined in: formatters/src/base-formatter.ts:561

Render an examples section from the

Parameters

ast

Program

renderer

ConventionRenderer

sectionName?

string = 'Examples'

Custom section heading name (default: 'Examples')

Returns

string | null

Examples

block. Shared rendering logic used by Claude, GitHub, and MarkdownInstructionFormatter.

Inherited from

BaseFormatter.renderExamplesSection


resolveVersion()

protected resolveVersion(version?): MarkdownVersion

Defined in: formatters/src/markdown-instruction-formatter.ts:163

Parameters

version?

string

Returns

MarkdownVersion


restrictions()

protected restrictions(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:838

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


sanitizeResourceFiles()

protected sanitizeResourceFiles(resources, targetDir): FormatterOutput[]

Defined in: formatters/src/base-formatter.ts:483

Filter resource files to only include safe paths. Rejects paths with traversal, absolute paths, and unsafe names.

Parameters

resources

object[] | undefined

targetDir

string

Returns

FormatterOutput[]

Inherited from

BaseFormatter.sanitizeResourceFiles


stripAllIndent()

protected stripAllIndent(content): string

Defined in: formatters/src/base-formatter.ts:348

Strip all leading indentation from markdown content. Used for AGENTS.md where content from multiple sources has inconsistent indentation. Preserves indentation inside code blocks.

Parameters

content

string

Returns

string

Inherited from

BaseFormatter.stripAllIndent


techStack()

protected techStack(ast, renderer): string | null

Defined in: formatters/src/markdown-instruction-formatter.ts:582

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null


transformRestrictionItem()

protected transformRestrictionItem(s): string

Defined in: formatters/src/markdown-instruction-formatter.ts:280

Parameters

s

string

Returns

string


truncate()

protected truncate(str, max): string

Defined in: formatters/src/base-formatter.ts:127

Truncate string to max length with ellipsis.

Parameters

str

string

max

number

Returns

string

Inherited from

BaseFormatter.truncate


valueToString()

protected valueToString(value): string

Defined in: formatters/src/base-formatter.ts:154

Convert value to string representation.

Parameters

value

Value

Returns

string

Inherited from

BaseFormatter.valueToString


yamlString()

protected yamlString(value): string

Defined in: formatters/src/markdown-instruction-formatter.ts:496

Parameters

value

string

Returns

string