Frontmatter Schema

This document describes the YAML frontmatter schema used by DocProcessor to process markdown documentation files and manage relationships between documentation and source code.

Overview

DocProcessor processes markdown files that contain YAML frontmatter blocks. The frontmatter specifies how the documentation relates to source files — either as specifications that drive code generation, as documentation that should be updated based on source files, or as transformation rules between files. The processor also supports fetching and caching URL-based related resources, allowing documentation to reference external web content as context.

Frontmatter Format

Frontmatter must be enclosed between --- delimiters at the start of the markdown file:

---
key: value
list_key:
- item1
- item2
---

# Document content starts here

Supported Keys

specifiesString | List<String>

Defines glob patterns for files that this documentation specifies. The matched files will be created or updated based on the documentation content.

# Single file
specifies: ../src/utils/helper.kt

# Single glob pattern
specifies: ../src/**/*.kt

# Multiple patterns
specifies:
  - ../src/models/*.kt
  - ../src/utils/*.kt

Glob Pattern Support:

documentsString | List<String>

Defines glob patterns for source files that this documentation describes. This is the inverse of specifies — the documentation file itself becomes the target to be updated based on the matched source files.

# Single file
documents: ../src/main/kotlin/MyClass.kt

# Multiple source files
documents:
  - ../src/**/*.kt
  - ../src/**/*.java

Use Case: Keep documentation in sync with source code changes. When source files change, the documentation can be automatically updated to reflect the current implementation.

transformsString | List<String>

Defines regex-based transformation rules that map source files to destination files. Uses regex capture groups and backreferences for flexible file mapping.

Format: sourcePattern -> destinationPattern

# Single transform
transforms: src/(.+)\.java -> generated/$1.kt

# Multiple transforms
transforms:
  - src/models/(.+)\.java -> kotlin/models/$1.kt
  - src/utils/(.+)\.java -> kotlin/utils/$1.kt

Backreference Support:

Note: Transform source patterns use Java regex syntax (not glob patterns). The regex is matched against file paths relative to the documentation file's parent directory. When rebasing, transform patterns are preserved as-is since they are resolved relative to the doc file at usage time.

Data File Detection: If a transform matches a JSON source file, it can be automatically used as a data source for template processing (see data_file).

generatesMap | List<Map>

Defines explicit output files to generate from specified input files. Unlike transforms, this doesn't use pattern matching — it explicitly lists the output file and its input sources.

Structure:

generates:
  output: path/to/output/file
  inputs:
    - input/pattern/*.kt
    - another/input.kt
# Single generate spec
generates:
  output: ../generated/combined.kt
  inputs:
    - ../src/models/*.kt
    - ../src/utils/*.kt

# Multiple generate specs
generates:
  - output: ../generated/models.kt
    inputs:
      - ../src/models/**/*.kt
  - output: ../generated/utils.kt
    inputs:
      - ../src/utils/**/*.kt

Input Pattern Support:

Validation: A generate spec requires both output and inputs fields. Specs missing either field are skipped with a warning.

Use Case: Generate aggregate files, combined outputs, or files that depend on multiple input sources.

relatedString | List<String>

Specifies additional files or URLs to include as context when processing modification tasks. These resources are not targets but provide supplementary information.

# Single related file
related: ../shared/constants.kt

# Multiple related files and URLs
related:
  - ../shared/constants.kt
  - ../config/settings.yaml
  - ./helper-docs.md
  - https://example.com/api-spec

URL Support: Related resources can be URLs (http:// or https://). URLs are automatically fetched, cached locally (with a 1-hour cache TTL), and their HTML content is simplified before being included as context. The URL cache is stored in .doc-processor-cache/url-cache within the root directory.

Use Case: Include configuration files, shared constants, related documentation, or external web resources that provide context for the AI when processing the target files.

task_typeString

Specifies which task type to use for processing the target files. This allows customization of how the AI processes the modification task.

Default: FileModification

# Use default file modification task
task_type: FileModification
# Use a different task type
task_type: CodeReview

Resolution Priority (when multiple specifications apply to a single target file):

  1. specifies frontmatter (first non-null)
  2. transforms frontmatter (first non-null)
  3. documents frontmatter (first non-null)
  4. generates frontmatter (first non-null)
  5. Default: FileModification

Task Type Resolution: The task type name is resolved using TaskType.valueOf() with spaces removed. Unknown task type names log a warning and fall back to FileModification.

task_config_jsonString

Specifies a relative file path to a JSON file containing additional task type configuration. This allows for more complex configuration that would be unwieldy in YAML frontmatter.

# Reference a JSON config file
task_config_json: ./config/my-task-config.json
# Config file in parent directory
task_config_json: ../shared/task-settings.json

Use Case: Provide detailed task configuration without cluttering the frontmatter. Useful for complex task types that require many parameters or when sharing configuration across multiple documentation files.

overwriteString

Specifies the overwrite mode for this documentation file's targets. This controls how existing files are handled during processing.

Value Description
SkipExisting Skip files that already exist (no processing)
OverwriteExisting Always overwrite existing files with full replacement
OverwriteToUpdate Overwrite only if source/related files are newer than target
PatchExisting Always apply fuzzy patch to existing files
PatchToUpdate Apply fuzzy patch only if source/related files are newer than target (default)
# Always apply patches to existing files
overwrite: PatchExisting
# Skip processing if target exists
overwrite: SkipExisting
# Always fully overwrite
overwrite: OverwriteExisting

Use Case: Control how the processor handles existing target files. Use PatchExisting or PatchToUpdate for incremental updates that preserve manual changes. Use OverwriteExisting or OverwriteToUpdate for complete regeneration. Use SkipExisting to prevent accidental overwrites.

promptString

Specifies a custom prompt string to use as the task description instead of the auto-generated one. Only used when there is exactly one spec for the target file.

# Custom prompt for the AI
specifies: ../src/Main.kt
prompt: Refactor this file to use coroutines instead of callbacks

template_fileString

Specifies a template file to use when processing the target. The path is resolved relative to the markdown file's directory.

specifies: ../src/Generated.kt
template_file: ./templates/class-template.kt

data_fileString

Specifies a JSON data file to use as structured data input for template processing. The path is resolved relative to the markdown file's directory.

specifies: ../src/Generated.kt
template_file: ./templates/class-template.kt
data_file: ./data/model-config.json

Implicit Detection: If no explicit data_file is specified and a transform matches a JSON source file, that JSON file is automatically used as the data source.

Complete Example

api-documentation.md

---
specifies:
  - ../src/api/*.kt
  - ../src/models/*.kt
documents:
  - ../src/core/Engine.kt
transforms:
  - src/legacy/(.+)\.java -> src/modern/$1.kt
generates:
  output: ../generated/api-index.md
  inputs:
    - ../src/api/**/*.kt
related:
  - ../config/api-config.yaml
  - ./api-conventions.md
  - https://example.com/api-spec
overwrite: PatchExisting
task_type: FileModification
task_config_json: ./config/api-task-config.json
prompt: Update the API layer to conform to the latest specification
---

# API Documentation

This document specifies the API layer implementation...

Processing Behavior

File Modification Time Checking

For OverwriteToUpdate and PatchToUpdate modes, the processor compares the target file's last modified time against:

If any of these are newer than the target, the target will be processed.

Task Description Generation

The processor automatically generates appropriate task descriptions based on the frontmatter type:

URL Fetching and Caching

Related resources specified as URLs (http:// or https://) are automatically fetched and cached locally:

Rebasing

Both DocSpec and ModificationTask support rebasing from one root directory to another. This is used when the IntelliJ action needs to adjust paths for a different working directory. URL-based related resources are preserved as-is during rebasing.

Primary Source Resolution

When determining the primary source file for overwrite mode checks, the priority is:

  1. First transform's source file
  2. First spec's doc file
  3. First document match's first supporting file (or doc file if no supporting files)
  4. First generate match's first input file (or doc file if no input files)

Error Handling

Data Structures

The frontmatter is parsed into a DocSpec containing:

Field Type Description
docFile File The markdown file itself
specifies List<String> Glob patterns for files this doc specifies
documents List<String> Glob patterns for files this doc describes
transforms List<TransformSpec> Source-to-destination transformation rules
generates List<GenerateSpec> Explicit generation specifications
related List<String> Additional context files or URLs
taskType String? Task type to use for processing (nullable, defaults to FileModification)
taskConfigJson String? Path to JSON file with additional task configuration (nullable)
content String The markdown body (after frontmatter)
frontmatter Map<String, Any> Raw parsed frontmatter

Note: The overwrite mode is not stored in DocSpec — it is configured at the DocProcessor level and applies to all targets processed by that instance.

TransformSpec

Field Type Description
sourcePattern String Regex pattern to match source files
destinationPattern String Destination pattern with backreferences

GenerateSpec

Field Type Description
output String The output file path (relative to doc file)
inputs List<String> Glob patterns for input files

ModificationTaskConfig

Represents the configuration for a single modification task:

Field Type Description
files List<String>? Target file paths (relative to root)
related_files List<String>? Related/context file paths (relative to root)
task_description String Generated or custom task description
template_file String? Path to template file (nullable)
data Map<String, Any>? Structured data from data_file or JSON source (nullable)

ModificationTask

Represents a complete modification task ready for execution:

Field Type Description
data ModificationTaskConfig Task configuration
message String Message content (context files or execute command)
patchProcessor PatchProcessors Patch processing strategy (default: Fuzzy)
shouldDeleteTarget Boolean Whether to delete the target file (default: false)
taskType TaskType<*, *> The resolved task type (default: FileModification)

Additional Processing Classes

TransformMatch — Represents a matched transformation from source to destination:

Field Type Description
sourceFile File The matched source file
destinationFile File The computed destination file
spec DocSpec The originating doc specification

GenerateMatch — Represents a matched generation specification:

Field Type Description
outputFile File The output file to generate
inputFiles List<File> The resolved input files
spec DocSpec The originating doc specification

DocumentMatch — Represents a documentation update specification:

Field Type Description
docSpec DocSpec The doc specification (target is the doc file itself)
supportingFiles List<File> Source files that provide context

Implementation Notes

Frontmatter Parsing: The frontmatter is parsed using a custom simple YAML parser (not SnakeYAML). The parser handles string values, list values, and map values (for generates).

Transform Pattern Matching: Transform patterns use Java regex syntax. The source pattern is matched against file paths relative to the documentation file's directory. When a match is found:

  1. The regex is applied to the relative file path
  2. Capture groups are extracted from the match
  3. Backreferences ($0, $1, etc.) in the destination pattern are replaced with the captured values
  4. The destination path is resolved relative to the documentation file's directory

IntelliJ Integration

The DocProcessorAction provides an IntelliJ IDE action that:

  1. Filters selected files to markdown files (.md or .markdown extensions)
  2. Creates a DocProcessor instance with the configured fast and smart models
  3. Calls getAll() to collect all modification tasks from the selected files
  4. Shows a DocProcessorTaskDialog with a checklist of tasks for user selection
  5. Executes the first selected task via SingleTaskApp in a browser session

The action is available through the DocProcessorActionGroup which provides a submenu with all overwrite mode options:

Label Mode
🚫 Skip Existing Files SkipExisting
🔄 Overwrite All Files OverwriteExisting
📅 Overwrite Outdated Files OverwriteToUpdate
🩹 Patch Existing Files PatchExisting
📝 Patch Outdated Files PatchToUpdate

The dialog includes an "Auto-fix issues" checkbox and displays task details including target files and related files.