Skip to content

PromptScript API


Class: FactoryFormatter

Defined in: formatters/src/formatters/factory.ts:118

Formatter for Factory AI instructions.

Factory AI uses AGENTS.md as its main configuration file and .factory/skills//SKILL.md for reusable skills.

Supports three versions: - simple: Single AGENTS.md file - multifile: AGENTS.md + .factory/skills/<name>/SKILL.md for each skill - full (default): Multifile + additional supporting files for skills

Example

targets:
  - factory  # uses full mode (default)
  - factory:
      version: multifile
  - factory:
      version: full

See

https://docs.factory.ai/cli/configuration

Extends

Constructors

Constructor

new FactoryFormatter(): FactoryFormatter

Defined in: formatters/src/formatters/factory.ts:119

Returns

FactoryFormatter

Overrides

MarkdownInstructionFormatter.constructor

Properties

config

protected readonly config: MarkdownFormatterConfig

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

Inherited from

MarkdownInstructionFormatter.config


defaultConvention

readonly defaultConvention: string

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

Default convention for this formatter

Inherited from

MarkdownInstructionFormatter.defaultConvention


description

readonly description: string

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

Human-readable description

Inherited from

MarkdownInstructionFormatter.description


name

readonly name: string

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

Unique formatter identifier

Inherited from

MarkdownInstructionFormatter.name


outputPath

readonly outputPath: string

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

Default output file path

Inherited from

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.standardsExtractor

Methods

addCommonSections()

protected addCommonSections(ast, renderer, sections): void

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

Parameters

ast

Program

renderer

ConventionRenderer

sections

string[]

Returns

void

Inherited from

MarkdownInstructionFormatter.addCommonSections


addSection()

protected addSection(sections, content): void

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

Parameters

sections

string[]

content

string | null

Returns

void

Inherited from

MarkdownInstructionFormatter.addSection


architecture()

protected architecture(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.architecture


codeStandards()

protected codeStandards(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.codeStandards


commands()

protected commands(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.commands


configFiles()

protected configFiles(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.configFiles


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

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.dedent


diagrams()

protected diagrams(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.diagrams


documentation()

protected documentation(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.documentation


examples()

protected examples(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.examples


extractAgents()

protected extractAgents(ast): FactoryDroidConfig[]

Defined in: formatters/src/formatters/factory.ts:363

Parameters

ast

Program

Returns

FactoryDroidConfig[]

Overrides

MarkdownInstructionFormatter.extractAgents


extractCommands()

protected extractCommands(ast): FactoryCommandConfig[]

Defined in: formatters/src/formatters/factory.ts:158

Parameters

ast

Program

Returns

FactoryCommandConfig[]

Overrides

MarkdownInstructionFormatter.extractCommands


extractExamples()

protected extractExamples(ast): object[]

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

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

MarkdownInstructionFormatter.extractExamples


extractRestrictionsItems()

protected extractRestrictionsItems(content): string[]

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

Parameters

content

BlockContent

Returns

string[]

Inherited from

MarkdownInstructionFormatter.extractRestrictionsItems


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

MarkdownInstructionFormatter.extractSectionWithCodeBlock


extractSkillExamples()

protected extractSkillExamples(skillProps): object[]

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

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

Parameters

skillProps

Record\<string, Value>

Returns

object[]

Inherited from

MarkdownInstructionFormatter.extractSkillExamples


extractSkills()

protected extractSkills(ast, options?): FactorySkillConfig[]

Defined in: formatters/src/formatters/factory.ts:248

Parameters

ast

Program

options?

FormatOptions

Returns

FactorySkillConfig[]

Overrides

MarkdownInstructionFormatter.extractSkills


extractTechStackFromContext()

protected extractTechStackFromContext(context): string[]

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

Parameters

context

Block | undefined

Returns

string[]

Inherited from

MarkdownInstructionFormatter.extractTechStackFromContext


extractTechStackFromStandards()

protected extractTechStackFromStandards(standards): string[]

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

Parameters

standards

Block | undefined

Returns

string[]

Inherited from

MarkdownInstructionFormatter.extractTechStackFromStandards


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

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.findBlock


format()

format(ast, options?): FormatterOutput

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

Transform AST to tool-specific format

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput

Inherited from

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.formatArray


formatFull()

protected formatFull(ast, options?): FormatterOutput

Defined in: formatters/src/formatters/factory.ts:564

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput

Overrides

MarkdownInstructionFormatter.formatFull


formatMultifile()

protected formatMultifile(ast, options?): FormatterOutput

Defined in: formatters/src/formatters/factory.ts:524

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput

Overrides

MarkdownInstructionFormatter.formatMultifile


formatSimple()

protected formatSimple(ast, options?): FormatterOutput

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

Parameters

ast

Program

options?

FormatOptions

Returns

FormatterOutput

Inherited from

MarkdownInstructionFormatter.formatSimple


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

MarkdownInstructionFormatter.formatStandardsList


generateAgentFile()

protected generateAgentFile(config): FormatterOutput

Defined in: formatters/src/formatters/factory.ts:392

Parameters

config

MarkdownAgentConfig

Returns

FormatterOutput

Overrides

MarkdownInstructionFormatter.generateAgentFile


generateCommandFile()

protected generateCommandFile(config): FormatterOutput

Defined in: formatters/src/formatters/factory.ts:203

Parameters

config

MarkdownCommandConfig

Returns

FormatterOutput

Overrides

MarkdownInstructionFormatter.generateCommandFile


generateSkillFile()

protected generateSkillFile(config, options?): FormatterOutput

Defined in: formatters/src/formatters/factory.ts:288

Parameters

config

MarkdownSkillConfig

options?

FormatOptions

Returns

FormatterOutput

Overrides

MarkdownInstructionFormatter.generateSkillFile


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

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.getProps


getSectionName()

protected getSectionName(key): string

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

Parameters

key

SectionNameKey

Returns

string

Inherited from

MarkdownInstructionFormatter.getSectionName


getSkillBasePath()

getSkillBasePath(): string | null

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

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

Returns

string | null

Inherited from

MarkdownInstructionFormatter.getSkillBasePath


getSkillFileName()

getSkillFileName(): string | null

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

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

Returns

string | null

Inherited from

MarkdownInstructionFormatter.getSkillFileName


gitCommits()

protected gitCommits(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.gitCommits


isSafeSkillName()

protected isSafeSkillName(name): boolean

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

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

Parameters

name

string

Returns

boolean

Inherited from

MarkdownInstructionFormatter.isSafeSkillName


knowledgeContent()

protected knowledgeContent(ast, _renderer): string | null

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

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().

Inherited from

MarkdownInstructionFormatter.knowledgeContent


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

MarkdownInstructionFormatter.normalizeMarkdownForPrettier


normalizeOutputDir()

protected normalizeOutputDir(dir): string

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

Normalize a user-provided output directory (from @use ... into "<path>" or skillTargets config) to a safe forward-slash relative path. Rejects .., . and leading slashes so the result can be appended to a target's dot-directory without escaping it.

Parameters

dir

string

Returns

string

Inherited from

MarkdownInstructionFormatter.normalizeOutputDir


postWork()

protected postWork(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.postWork


project()

protected project(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.project


referenceProvenance()

protected referenceProvenance(sourcePath): string

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

Generate a provenance comment for a reference file.

Parameters

sourcePath

string

Returns

string

Inherited from

MarkdownInstructionFormatter.referenceProvenance


referencesMode()

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

Defined in: formatters/src/formatters/factory.ts:150

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"

Overrides

MarkdownInstructionFormatter.referencesMode


renderCodeFence()

protected renderCodeFence(content, lang?): string

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

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

MarkdownInstructionFormatter.renderCodeFence


renderExamplesSection()

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

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

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

MarkdownInstructionFormatter.renderExamplesSection


resolveSkillDir()

protected resolveSkillDir(defaultSkillBasePath, skillName, outputDir?, options?): string

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

Resolve the directory for a generated skill, respecting per-target skill base overrides while preserving existing @use ... into behavior.

Parameters

defaultSkillBasePath

string

skillName

string

outputDir?

string

options?

FormatOptions

Returns

string

Inherited from

MarkdownInstructionFormatter.resolveSkillDir


resolveVersion()

protected resolveVersion(version?): MarkdownVersion

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

Parameters

version?

string

Returns

MarkdownVersion

Inherited from

MarkdownInstructionFormatter.resolveVersion


restrictions()

protected restrictions(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.restrictions


sanitizeResourceFiles()

protected sanitizeResourceFiles(resources, targetDir): FormatterOutput[]

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

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

MarkdownInstructionFormatter.sanitizeResourceFiles


shouldIncludeSkill()

protected shouldIncludeSkill(name, options?): boolean

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

Return true when the target configuration allows emitting the given skill.

Parameters

name

string

options?

FormatOptions

Returns

boolean

Inherited from

MarkdownInstructionFormatter.shouldIncludeSkill


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

MarkdownInstructionFormatter.stripAllIndent


techStack()

protected techStack(ast, renderer): string | null

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

Parameters

ast

Program

renderer

ConventionRenderer

Returns

string | null

Inherited from

MarkdownInstructionFormatter.techStack


transformRestrictionItem()

protected transformRestrictionItem(s): string

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

Parameters

s

string

Returns

string

Inherited from

MarkdownInstructionFormatter.transformRestrictionItem


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

MarkdownInstructionFormatter.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

MarkdownInstructionFormatter.valueToString


yamlString()

protected yamlString(value): string

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

Parameters

value

string

Returns

string

Inherited from

MarkdownInstructionFormatter.yamlString


getSupportedVersions()

static getSupportedVersions(): object

Defined in: formatters/src/formatters/factory.ts:146

Get supported versions for this formatter.

Returns

object

full

readonly full: object

full.description

readonly description: "Multifile + droids + additional supporting files" = 'Multifile + droids + additional supporting files'

full.name

readonly name: "full" = 'full'

full.outputPath

readonly outputPath: "AGENTS.md" = 'AGENTS.md'

multifile

readonly multifile: object

multifile.description

readonly description: "AGENTS.md + .factory/skills/<name>/SKILL.md" = 'AGENTS.md + .factory/skills/<name>/SKILL.md'

multifile.name

readonly name: "multifile" = 'multifile'

multifile.outputPath

readonly outputPath: "AGENTS.md" = 'AGENTS.md'

simple

readonly simple: object

simple.description

readonly description: "Single AGENTS.md file" = 'Single AGENTS.md file'

simple.name

readonly name: "simple" = 'simple'

simple.outputPath

readonly outputPath: "AGENTS.md" = 'AGENTS.md'