> ## Documentation Index
> Fetch the complete documentation index at: https://harisfazillah.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Reference: refactor_okf.py

> Batch refactoring script for Open Knowledge Format (OKF) frontmatter structures. Deep State of Mind framework. Deep State of Mind framework.

Batch refactoring script for Open Knowledge Format (OKF) frontmatter structures.

## Description

The `refactor_okf.py` tool processes files across the repository, strips leading UTF-8 Byte Order Marks (BOM), and enforces proper ordering of YAML variables (such as placing `topics` immediately after `description` in skill schemas).

## Script path

`tools/refactor_okf.py`

## CLI signature

```bash theme={null}

# Preview expected changes without executing in-place writes

uv run python tools/refactor_okf.py --dry-run

# Refactor and overwrite files with standardised compliance

uv run python tools/refactor_okf.py

```

## Internal Python API

This script imports logic from `tools/apply_okf_frontmatter.py` to preserve consistency:

* **`FRONTMATTER_RE`:** Pattern identifying Markdown fences.
* **`process_file(filepath, root_dir, dry_run)`:** Main orchestrator implementing parsing, normalisation, and atomic replacement.

## Excluded directories

The tool ignores these directories to prevent unnecessary modifications:

* `.git`
* `node_modules`
* `.pytest_cache`
* `.venv`

***

*Deep State of Mind (DSOM) For My AI Protocol | Harisfazillah Jamel (LinuxMalaysia) | 2026-08-14*
*Standard: UK English | DBP-standard Bahasa Melayu Malaysia (Piawai) | GNU General Public License v3.0*


## Related topics

- [Reference: apply_okf_frontmatter.py](/reference/apply_okf_frontmatter.md)
- [How-To: Check and Apply OKF Compliance](/how-to/audit-and-apply-frontmatter.md)
- [Reference Material Index](/reference/index.md)
- [How-To Guides Index](/how-to/index.md)
- [Automation & Script Audit Ledger](/governance/automation-audit-list.md)
