A-IForgeEngineDocsReference3. Patch Engine

Forge patches are structured bulk operations stored as markdown notes.

A patch contains a fenced YAML block describing the operations Forge should apply.

Before making changes, Forge:

  1. dry-runs the patch
  2. previews the changes
  3. shows a confirmation modal
  4. applies changes only after confirmation

This keeps patch workflows reviewable and safer than large manual edits.

Current patch note:

A-I/Forge/Engine/Patches/vault-patch.md

Patch Engine

Patch Note Structure

A Forge patch is a normal markdown note.

Forge only reads the fenced YAML block.

Everything else in the note exists for human explanation and operational context.

Example:

# Vault Patch

```yaml
meta:
  description: Normalize project notes
  schema_version: "1.0"

operations:
  - op: normalize_tags
    target_pattern: "Projects/**/*.md"
```

This makes patches:

  • reviewable
  • editable
  • searchable
  • syncable
  • auditable

inside the vault itself.


Targeting Files

Patch operations can target:

KeyUse
targetOne exact file path
target_patternMultiple files using a glob-like pattern

Example:

target_pattern: "Projects/**/*.md"

If no files match, Forge reports the operation as an error.


Scoped Targets

Any patch operation can add scope to narrow matched files before the operation runs.

Example:

- op: add_tag
  target_pattern: "Work/**/*.md"
  scope:
    updated_since: 2026-06-01
    missing_tag: context/work
  tag: context/work

This operation only applies to matched files whose frontmatter updated date is on or after the scoped date and which do not already have the tag.

Supported scope keys:

KeyMeaning
updated_sinceRequire frontmatter updated on or after this date
updated_beforeRequire frontmatter updated on or before this date
created_sinceRequire frontmatter created on or after this date
created_beforeRequire frontmatter created on or before this date
updated_fieldOverride the frontmatter field used by updated_since
file_modified_sinceRequire filesystem modified time on or after this date
file_modified_beforeRequire filesystem modified time on or before this date
file_created_sinceRequire filesystem created time on or after this date
file_created_beforeRequire filesystem created time on or before this date
field_equalsRequire frontmatter fields to match values
field_not_equalsRequire frontmatter fields not to match values
field_presentRequire frontmatter fields to be present and non-empty
field_missingRequire frontmatter fields to be missing or empty
has_tagRequire tags to be present
missing_tagRequire tags to be absent
path_inRequire the path to match one of these exact paths or glob patterns
path_not_inExclude exact paths or glob patterns
type_inShorthand for frontmatter type matching one of these values
status_inShorthand for frontmatter status matching one of these values
limitApply only to the first N files that pass scope

When multiple scope keys are set, all must match.

Date-only values use local time and are inclusive.

Examples:

scope:
  updated_since: 2026-06-01
  updated_before: 2026-07-01
  type_in:
    - note
    - project
  field_equals:
    status: active
  field_missing:
    - archived
  has_tag: work
  missing_tag: context/work
  path_not_in:
    - "Work/Archive/**"
  limit: 25

Supported Operations

OperationRequired KeysWhat It Does
set_fieldtarget/target_pattern, field, value or value_fromAdds or updates a frontmatter field
remove_fieldtarget/target_pattern, fieldRemoves a frontmatter field
add_tagtarget/target_pattern, tagAdds a tag if missing
remove_tagtarget/target_pattern, tagRemoves a tag if present
replace_tagtarget/target_pattern, old_tag, new_tagReplaces one tag with another
normalize_tagstarget/target_patternSorts and deduplicates tags
compute_fieldtarget/target_pattern, field, strategyComputes values from metadata or activity
sort_frontmattertarget/target_patternReorders frontmatter consistently
move_notetarget/target_pattern, source_root, destination_folderMoves notes while preserving relative paths

Patch operations are intentionally explicit.

Forge favors predictable behavior over hidden automation.


set_field Examples

Literal Values

Example:

- op: set_field
  target: "Notes/Home.md"
  field: status
  value: active

This writes:

status: active

into the note frontmatter.


Derived Values

Fields can also be generated dynamically from file metadata.

Example:

- op: set_field
  target_pattern: "Projects/**/*.md"
  field: domain
  value_from: path
  path_segment_index: 0
  lowercase: true

This can derive metadata automatically from vault structure.

Useful for:

  • domains
  • project groups
  • ownership
  • folder-based organization

Supported value_from Sources

ValueResult
filenameExample Note.md
basenameExample Note
folderImmediate parent folder
parent_folderParent of the immediate parent folder
pathPath segment using path_segment_index

Optional transforms include:

  • trim_prefix
  • trim_suffix
  • lowercase
  • uppercase

Conditional Operations

set_field supports:

  • when
  • only_if_missing

Example:

- op: set_field
  target_pattern: "Projects/**/*.md"
  field: status
  value: active
  only_if_missing: true
  when:
    field: type
    equals: project

This operation only applies when:

type: project

already exists.

Conditional logic helps patches remain safer and more targeted.


Compute Strategies

compute_field supports several built-in strategies.

StrategyOptionsMeaning
file_created_timeformatWrites file created date
file_modified_timeformatWrites file modified date
recent_activitydays, value_if_true, skip_ifWrites values based on recent activity

Date formatting currently uses:

yyyy-MM-dd

Moving Notes

move_note moves notes while preserving their structure below a source root.

Example use cases:

  • reorganizing projects
  • splitting vault areas
  • restructuring archives
  • moving operational systems

Optional keys:

KeyMeaning
frontmatterMerge frontmatter before moving
strip_frontmatterRemove frontmatter before moving

Do not combine:

  • frontmatter
  • strip_frontmatter

in the same operation.


Dry Runs and Safety

Patch execution always begins with a dry run.

Forge previews:

  • targeted files
  • planned changes
  • affected operations
  • backup locations

before writing anything.


Patch Preview

Backups, Reports, and Restore

Confirmed patch runs can generate:

  • backups
  • reports
  • restore manifests
  • applied patch copies

Typical locations:

A-I/Forge/Engine/Patches/Backups
A-I/Forge/Engine/Patches/Reports
A-I/Forge/Engine/Patches/Applied

Use:

Forge: Restore Patch Run

to restore files from a previous manifest.


Recommended Patch Workflow

A safe patch workflow usually looks like this:

  1. Run Vault Lint
  2. Review findings
  3. Build a small patch
  4. Dry-run the patch
  5. Review changes
  6. Apply the patch
  7. Re-run lint

Small patches are usually easier to review and safer to undo.


Why Patches Matter

Patches make vault maintenance repeatable.

Instead of manually editing hundreds of notes, you can:

  • standardize metadata
  • migrate structures
  • normalize tags
  • repair inconsistencies
  • reorganize folders
  • update workflows

using reviewable operational notes.

This becomes especially useful in:

  • long-lived vaults
  • shared systems
  • large project repositories
  • research systems
  • evolving templates

Related Notes

21 Notes link here
Built with LogoFlowershow